예제 #1
0
파일: banker.c 프로젝트: Jelb/BOSC
/* Threads starts here */
void *process_thread(void *param)
{
    /* Process number */
    int i = (int) (long) param, j;
    /* Allocate request vector */
    int *request = malloc(n*sizeof(int));
    while (1) {
        /* Generate request */
        generate_request(i, request);
        while (!resource_request(i, request)) {
            /* Wait */
            Sleep(100);
        }
        /* Generate release */
        generate_release(i, request);
        /* Release resources */
        resource_release(i, request);
        /* Wait */
        Sleep(1000);
    }
    free(request);
}
예제 #2
0
파일: banker.c 프로젝트: Madsen90/BOSC
/* Threads starts here */
void *process_thread(void *param)
{
  /* Process number */
  int i = (int) (long) param, j;
 
  printf("PROC %d\n", i);
 
  /* Allocate request vector */
  int *request = malloc(n*sizeof(int));
  int q;
  for(q = 0; q < n; q++){
    request[q] = 0;
  }
 
  int legal = 0;
  while (1) {
   
    /* Generate request */
    generate_request(i, request);
 
    while (!resource_request(i, request)) {
      printf("%s\n", "Waiting");
      /* Wait */
      Sleep(1000);
    }
   
 
 
 
    /* Generate release */
    generate_release(i, request);
    /* Release resources */
    resource_release(i, request);
    /* Wait */
 
    Sleep(1000);
  }
  free(request);
}
예제 #3
0
void omap_pm_set_min_bus_tput(struct device *dev, u8 agent_id, unsigned long r)
{
#if 1 // Archer-Froyo, KERNEL PANIC in update_resource_level() after EnableSGXClocks()  	
    return; 
#endif // Archer-Froyo 
 	
	if (!dev || (agent_id != OCP_INITIATOR_AGENT &&
	    agent_id != OCP_TARGET_AGENT)) {
		WARN_ON(1);
		return;
	};

	if (r == 0) {
		pr_debug("OMAP PM: remove min bus tput constraint: "
			 "dev %s for agent_id %d\n", dev_name(dev), agent_id);
		resource_release("vdd2_opp", dev);
	} else {
		pr_debug("OMAP PM: add min bus tput constraint: "
			 "dev %s for agent_id %d: rate %ld KiB\n",
			 dev_name(dev), agent_id, r);
		resource_request("vdd2_opp", dev, r);
	}
}
예제 #4
0
void task_i2c_get_temp_func(const struct task_item *task)
{
        uint8_t temp[2];
        int t_out, fract;

        /*
         * Wait in OS friendly way for request to run.
         */
        if (!read_temp_enabled) {
                OS_EVENT_WAIT(event, OS_EVENT_FOREVER);
        }

        /*
         * Require I2C for exclusively reading temperature from FM75 and release it after operation.
         */
        resource_acquire(RES_MASK(RES_ID_I2C1), RES_WAIT_FOREVER);

        set_target_address(FM75_ADDRESS);

        /*
         * Read actual temperature values from FM75.
         */
        fm75_read_reg(FM75_REG_TEMP, temp, sizeof(temp));

        resource_release(RES_MASK(RES_ID_I2C1));

        /*
         * Send results to UART.
         */
        t_out = convert_temp(temp, &fract);
        printf("current temperature: %d.%04d C" NEWLINE, t_out, fract);

        /*
         * Wait 1 second to get temperature again.
         */
        OS_DELAY(1000);
}
예제 #5
0
/**
 * resource_test_1 - Tests the resource framework basic APIs for
 *                   "opp/freq" resources
 * @res_name: Name of the resource requested
 * @req_lvl: Requested level for the resource
 *
 * Requests the "opp/freq" resource for the given level,
 * verifies if the resource's current level is same as the requested level
 * and releases the resource
 *
 * Returns 0 on success, -1 on failure
 */
static int resource_test_1(const char *res_name, unsigned long req_lvl)
{
	int ret, cur_lvl, result = TEST_PASS;
	struct device dev;

	printk(KERN_INFO "Entry resource_test_1 \n");

	if (!strcmp(res_name, "vdd2_opp"))
		ret = request_vdd2_opp(&dev, req_lvl);
	else
		ret = resource_request(res_name, &dev, req_lvl);

	if (ret) {
		printk(KERN_ERR "FAILED!!!! dev resource request for "
			"%s failed with value %d\n", res_name, ret);
		return TEST_FAIL;
	}

	cur_lvl = resource_get_level(res_name);
	if (cur_lvl != req_lvl) {
		printk(KERN_ERR "FAILED!!!! resource %s current level:%d"
			" req lvl:%d\n", res_name, cur_lvl, (int)req_lvl);
		result = TEST_FAIL;
	}

	ret = resource_release(res_name, &dev);
	if (ret) {
		printk(KERN_ERR "FAILED!!!! resource release for %s failed"
			" with value %d\n", res_name, ret);
		result = TEST_FAIL;
	}

	if (!result)
		printk(KERN_INFO "resource_test_1 PASSED for %s\n", res_name);
	return result;
}
예제 #6
0
void menu_i2c_read_from_eeprom_func(const struct menu_item *m, bool checked)
{
        size_t rd_status, wr_status;
        HW_I2C_ABORT_SOURCE abrt_src = HW_I2C_ABORT_NONE;
        uint8_t addr[2] = {0x00, 0x00};
        static uint8_t read_buffer[65];        // 64 bytes of data + '\0'

        set_target_address(EEPROM_ADDRESS);
        /*
         * Acquire I2C resource and read data back from EEPROM and release it after operation.
         * Before reading data we need to set address from which reading will start. This is done
         * by writing two bytes indicating address in EEPROM before reading from it. I2C controller
         * will automatically generate proper write and read commands on I2C bus.
         */
        resource_acquire(RES_MASK(RES_ID_I2C1), RES_WAIT_FOREVER);

        wr_status = hw_i2c_write_buffer_sync(HW_I2C1, addr, sizeof(addr), &abrt_src, HW_I2C_F_NONE);
        if ((wr_status < sizeof(addr)) || (abrt_src != HW_I2C_ABORT_NONE)) {
                printf("EEPROM address write during read failed: %u" NEWLINE, abrt_src);
        }
        else {
                rd_status = hw_i2c_read_buffer_sync(HW_I2C1, read_buffer, sizeof(read_buffer) - 1, &abrt_src, HW_I2C_F_NONE);

                /*
                 * Print on UART what was read from EEPROM.
                 */
                if ((rd_status < sizeof(read_buffer)) || (abrt_src != HW_I2C_ABORT_NONE)) {
                        printf("EEPROM read failure: %u" NEWLINE, abrt_src);
                }
                else {
                        printf("read from EEPROM:  %s" NEWLINE, read_buffer);
                }
        }

        resource_release(RES_MASK(RES_ID_I2C1));
}
예제 #7
0
/**
 * resource_test_7 - Tests the resource_refresh API
 * @res_name: Name of the resource requested ("vdd1_opp"/"vdd2_opp")
 * @req_lvl1: Requested lower level for the resource
 * @req_lvl2: Requested higher level for the resource
 *
 * Device 1 requests the resource for the given lower level,
 * locks the resource. Meanwhile device 2 requests the reource for a
 * higher level.
 * Verifies if the resource's current level is same as the requested
 * higher level after device 1 unlocks the resource
 *
 * Returns 0 on success, -1 on failure
 */
static int resource_test_7(const char *res_name, unsigned long req_lvl1,
			unsigned long req_lvl2)
{
	int ret, cur_lvl, result = TEST_PASS;
	int lock_val;
	struct device dev1, dev2;

	printk(KERN_INFO "Entry resource_test_7 \n");

	if (!strcmp(res_name, "vdd1_opp"))
		lock_val = VDD1_OPP;
	else if (!strcmp(res_name, "vdd2_opp"))
		lock_val = VDD2_OPP;
	else {
		printk(KERN_ERR "FAILED!!!! invalid resource name\n");
		return TEST_FAIL;
	}

	ret = resource_request(res_name, &dev1, req_lvl1);
	if (ret) {
		printk(KERN_ERR "FAILED!!!! resource1 request for %s failed"
			" with value %d\n", res_name, ret);
		return TEST_FAIL;
	}

	cur_lvl = resource_get_level(res_name);
	if (cur_lvl != req_lvl1) {
		printk(KERN_ERR "FAILED!!!! resource %s current level:%d"
			" req lvl:%d\n", res_name, cur_lvl, (int)req_lvl1);
		result = TEST_FAIL;
	}

	if (result == TEST_PASS) {
		ret = resource_access_opp_lock(lock_val, 1);
		if (ret < 0) {
			printk(KERN_ERR "FAILED!!!! resource %s lock failed"
				" with value %d\n", res_name, ret);
			result = TEST_FAIL;
		}
	}

	if (result == TEST_PASS) {
		ret = resource_request(res_name, &dev2, req_lvl2);
		if (ret) {
			printk(KERN_ERR "FAILED!!!! resource2 request %s failed"
				" with value %d\n", res_name, ret);
			ret = resource_access_opp_lock(lock_val, -1);
			if (ret < 0)
				printk(KERN_ERR "FAILED!!!! resource unlock"
					"for %s failed\n", res_name);
			result = TEST_FAIL;
		}
	}

	if (result == TEST_PASS) {
		cur_lvl = resource_get_level(res_name);
		if (cur_lvl != req_lvl1) {
			printk(KERN_ERR "FAILED!!!! %s current level:%d"
				" req lvl:%d\n", res_name, cur_lvl,
				(int)req_lvl1);
			result = TEST_FAIL;
		}

		ret = resource_access_opp_lock(lock_val, -1);
		if (ret < 0) {
			printk(KERN_ERR "FAILED!!!! resource unlock %s failed"
				" with value %d\n", res_name, ret);
			result = TEST_FAIL;
		}

		ret = resource_refresh();
		if (ret) {
			printk(KERN_ERR "FAILED!!!! resource refresh failed"
				" with value %d\n", ret);
			result = TEST_FAIL;
		}

		cur_lvl = resource_get_level(res_name);
		if (cur_lvl != req_lvl2) {
			printk(KERN_ERR "FAILED!!!! %s current level:%d"
				" req lvl:%d\n", res_name, cur_lvl,
				(int)req_lvl2);
			result = TEST_FAIL;
		}
	}

	ret = resource_release(res_name, &dev1);
	if (ret) {
		printk(KERN_ERR "FAILED!!!! resource1 release for %s failed"
			" with value %d\n", res_name, ret);
		result = TEST_FAIL;
	}
	ret = resource_release(res_name, &dev2);
	if (ret) {
		printk(KERN_ERR "FAILED!!!! resource2 release for %s failed"
			" with value %d\n", res_name, ret);
		result = TEST_FAIL;
	}

	if (!result)
		printk(KERN_INFO "resource_test_7 PASSED for %s\n", res_name);
	return result;
}
예제 #8
0
/**
 * resource_test_6 - Tests resource framework APIs when four devices requests
 *                   the same "latency" resource for same or different levels
 * @res_name: Name of the resource requested
 * @req_lat1: Device 1 level requested for the resource
 * @req_lat2: Device 2 level requested for the resource
 * @req_lat4: Device 3 level requested for the resource
 * @req_lat4: Device 4 level requested for the resource
 * @ref_table: Pointer to the reference latency table for the given resource
 *
 * Four devices requests the "lat" resource for the specified levels,
 * verifies if the resource's current level is same as that of the
 * closest lower reference level to the lowest level requested among the
 * four devices and releases the resource
 *
 * Returns 0 on success, -1 on failure
 */
static int resource_test_6(const char *res_name, unsigned long req_lat1,
			unsigned long req_lat2, unsigned long req_lat3,
			unsigned long req_lat4, unsigned long *ref_table)
{
	int ret, result = TEST_PASS, i;
	struct device dev1, dev2, dev3, dev4;
	int cur_lvl, req_lat;

	printk(KERN_INFO "Entry resource_test_6 \n");

	ret = resource_request(res_name, &dev1, req_lat1);
	if (ret) {
		printk(KERN_ERR "FAILED!!!! dev1 resource request for %s failed"
			" with value %d\n", res_name, ret);
		return TEST_FAIL;
	}

	ret = resource_request(res_name, &dev2, req_lat2);
	if (ret) {
		printk(KERN_ERR "FAILED!!!! dev2 resource request for %s failed"
			" with value %d\n", res_name, ret);
		resource_release(res_name, &dev1);
		return TEST_FAIL;
	}

	ret = resource_request(res_name, &dev3, req_lat3);
	if (ret) {
		printk(KERN_ERR "FAILED!!!! dev3 resource request for %s failed"
			" with value %d\n", res_name, ret);
		resource_release(res_name, &dev1);
		resource_release(res_name, &dev2);
		return TEST_FAIL;
	}

	ret = resource_request(res_name, &dev4, req_lat4);
	if (ret) {
		printk(KERN_ERR "FAILED!!!! dev4 resource request for %s failed"
			" with value %d\n", res_name, ret);
		resource_release(res_name, &dev1);
		resource_release(res_name, &dev2);
		resource_release(res_name, &dev3);
		return TEST_FAIL;
	}

	cur_lvl = resource_get_level(res_name);
	req_lat = (int)min_level_1(req_lat1, req_lat2, req_lat3, req_lat4);

	/* using the ref table to find the appropriate PD state */
	for (i = 0; i < 3; i++) {
		if (ref_table[i] < req_lat)
			break;
	}
	if (!enable_off_mode && i == PD_LATENCY_OFF)
		i = PD_LATENCY_RET;
	/* Inactive state is not being tested */
	else if (i == 2)
		i = PD_LATENCY_ON;

	if (cur_lvl != i) {
		printk(KERN_ERR "FAILED!!!! resource %s current level:%d"
			" req lvl:%d\n", res_name, cur_lvl, i);
		result = TEST_FAIL;
	}

	ret = resource_release(res_name, &dev1);
	if (ret) {
		printk(KERN_ERR "FAILED!!!! dev1 resource release for %s failed"
			" with value %d\n", res_name, ret);
		result = TEST_FAIL;
	}
	ret = resource_release(res_name, &dev2);
	if (ret) {
		printk(KERN_ERR "FAILED!!!! dev2 resource release for %s failed"
			" with value %d\n", res_name, ret);
		result = TEST_FAIL;
	}
	ret = resource_release(res_name, &dev3);
	if (ret) {
		printk(KERN_ERR "FAILED!!!! dev3 resource release for %s failed"
			" with value %d\n", res_name, ret);
		result = TEST_FAIL;
	}
	ret = resource_release(res_name, &dev4);
	if (ret) {
		printk(KERN_ERR "FAILED!!!! dev4 resource release for %s failed"
			" with value %d\n", res_name, ret);
		result = TEST_FAIL;
	}

	if (!result)
		printk(KERN_INFO "resource_test_6 PASSED for %s\n", res_name);
	return result;
}
예제 #9
0
/**
 * resource_test_3 - Tests resource framework APIs when three devices requests
 *                   the same "opp/freq" resource for same or different levels
 * @res_name: Name of the resource requested
 * @req_lvl1: Device 1 level requested for the resource
 * @req_lvl2: Device 2 level requested for the resource
 * @req_lvl3: Device 3 level requested for the resource
 *
 * Three devices requests the "opp/freq" resource for the specified levels,
 * verifies if the resource's current level is same as the maximum of
 * requested levels and releases the resource
 *
 * Returns 0 on success, -1 on failure
 */
static int resource_test_3(const char *res_name, unsigned long req_lvl1,
		unsigned long req_lvl2, unsigned long req_lvl3)
{
	int ret, result = TEST_PASS;
	int cur_lvl, req_lvl;
	struct device dev1, dev2, dev3;

	printk(KERN_INFO "Entry resource_test_3 \n");

	if (!strcmp(res_name, "vdd2_opp"))
		ret = request_vdd2_opp(&dev1, req_lvl1);
	else
		ret = resource_request(res_name, &dev1, req_lvl1);
	if (ret) {
		printk(KERN_ERR "FAILED!!!! dev1 resource request for %s failed"
			" with value %d\n", res_name, ret);
		return TEST_FAIL;
	}

	if (!strcmp(res_name, "vdd2_opp"))
		ret = request_vdd2_opp(&dev2, req_lvl2);
	else
		ret = resource_request(res_name, &dev2, req_lvl2);
	if (ret) {
		printk(KERN_ERR "FAILED!!!! dev2 resource request for %s failed"
			" with value %d\n", res_name, ret);
		resource_release(res_name, &dev1);
		return TEST_FAIL;
	}

	if (!strcmp(res_name, "vdd2_opp"))
		ret = request_vdd2_opp(&dev3, req_lvl3);
	else
		ret = resource_request(res_name, &dev3, req_lvl3);
	if (ret) {
		printk(KERN_ERR "FAILED!!!! dev3 resource request for %s failed"
			" with value %d\n", res_name, ret);
		resource_release(res_name, &dev1);
		resource_release(res_name, &dev2);
		return TEST_FAIL;
	}

	cur_lvl = resource_get_level(res_name);
	req_lvl = (int) max_level_1(req_lvl1, req_lvl2, req_lvl3);
	if (cur_lvl != req_lvl) {
		printk(KERN_ERR "FAILED!!!! resource %s current level:%d"
			" req lvl:%d\n", res_name, cur_lvl, req_lvl);
		result = TEST_FAIL;
	}

	ret = resource_release(res_name, &dev1);
	if (ret) {
		printk(KERN_ERR "FAILED!!!! dev1 resource release for %s failed"
			" with value %d\n", res_name, ret);
	result = TEST_FAIL;
	}
	ret = resource_release(res_name, &dev2);
	if (ret) {
		printk(KERN_ERR "FAILED!!!! dev2 resource release for %s failed"
			" with value %d\n", res_name, ret);
	result = TEST_FAIL;
	}
	ret = resource_release(res_name, &dev3);
	if (ret) {
		printk(KERN_ERR "FAILED!!!! dev3 resource release for %s failed"
			" with value %d\n", res_name, ret);
		result = TEST_FAIL;
	}

	if (!result)
		printk(KERN_INFO "resource_test_3 PASSED for %s\n", res_name);
	return result;
}
예제 #10
0
JNIEXPORT void JNICALL Java_quickeye_JNI_1QuickEye_free_1jni
(JNIEnv *, jclass){

	resource_release();
}
예제 #11
0
static int hsmmc_set_power(struct device *dev, int slot, int power_on,
				int vdd)
{
	u32 vdd_sel = 0, devconf = 0, reg = 0;
	int ret = 0;

	/* REVISIT: Using address directly till the control.h defines
	 * are settled.
	 */
#if defined(CONFIG_ARCH_OMAP2430)
	#define OMAP2_CONTROL_PBIAS 0x490024A0
#else
	#define OMAP2_CONTROL_PBIAS 0x48002520
#endif

	if (power_on) {
		if (cpu_is_omap24xx())
			devconf = omap_readl(OMAP2_CONTROL_DEVCONF1);
		else
			devconf = omap_readl(OMAP3_CONTROL_DEVCONF0);

		switch (1 << vdd) {
		case MMC_VDD_33_34:
		case MMC_VDD_32_33:
			vdd_sel = VSEL_3V;
			if (cpu_is_omap24xx())
				devconf |= OMAP2_CONTROL_DEVCONF1_ACTOV;
			break;
		case MMC_VDD_165_195:
			vdd_sel = VSEL_18V;
			if (cpu_is_omap24xx())
				devconf &= ~OMAP2_CONTROL_DEVCONF1_ACTOV;
		}

		if (cpu_is_omap24xx())
			omap_writel(devconf, OMAP2_CONTROL_DEVCONF1);
		else
			omap_writel(devconf | OMAP2_CONTROL_DEVCONF0_LBCLK,
				    OMAP3_CONTROL_DEVCONF0);

		reg = omap_readl(OMAP2_CONTROL_PBIAS);
		reg |= OMAP2_CONTROL_PBIAS_SCTRL;
		omap_writel(reg, OMAP2_CONTROL_PBIAS);

		reg = omap_readl(OMAP2_CONTROL_PBIAS);
		reg &= ~OMAP2_CONTROL_PBIAS_PWRDNZ;
		omap_writel(reg, OMAP2_CONTROL_PBIAS);

		reg = omap_readl(OMAP2_CONTROL_PBIAS);
		reg |= OMAP2_CONTROL_PBIAS_SCTRL1;
		omap_writel(reg, OMAP2_CONTROL_PBIAS);

		reg = omap_readl(OMAP2_CONTROL_PBIAS);
		reg &= ~OMAP2_CONTROL_PBIAS_PWRDNZ1;
		omap_writel(reg, OMAP2_CONTROL_PBIAS);

		ret = resource_request(rhandlemmc1, (vdd_sel == VSEL_3V ?
			T2_VMMC1_3V00 : T2_VMMC1_1V85));
		if (ret != 0)
			goto err;

		/* Enable VSIM to support MMC 8-bit on ES2 */
		if (is_sil_rev_greater_than(OMAP3430_REV_ES1_0)) {
			ret = resource_request(rhandlevsim,
				(vdd_sel == VSEL_3V ?
				T2_VSIM_3V00 : T2_VSIM_1V80));
			if (ret != 0)
				return ret;
		}
		msleep(100);
		reg = omap_readl(OMAP2_CONTROL_PBIAS);
		reg = (vdd_sel == VSEL_18V) ?
			(((reg | 0x0606) & ~0x1) & ~(1<<8))
			: (reg | 0x0707);
		omap_writel(reg, OMAP2_CONTROL_PBIAS);

		return ret;

	} else {
		/* Power OFF */

		/* For MMC1, Toggle PBIAS before every power up sequence */
		reg = omap_readl(OMAP2_CONTROL_PBIAS);
		reg &= ~OMAP2_CONTROL_PBIAS_PWRDNZ;
		omap_writel(reg, OMAP2_CONTROL_PBIAS);

		if (rhandlemmc1 != NULL) {
			ret = resource_release(rhandlemmc1);
			if (ret != 0)
				goto err;
		}

		if (is_sil_rev_greater_than(OMAP3430_REV_ES1_0)
					 && (rhandlevsim != NULL)) {
			ret = resource_release(rhandlevsim);
			if (ret != 0)
				goto err;
		}

		if (is_sil_rev_equal_to(OMAP3430_REV_ES3_0)) {
			ret = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
				LDO_CLR, VSIM_DEV_GRP);
			if (ret)
				goto err;
			ret = twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
				LDO_CLR, VSIM_DEDICATED);
			if (ret)
				goto err;
		}

		/* 100ms delay required for PBIAS configuration */
		msleep(100);
		reg = omap_readl(OMAP2_CONTROL_PBIAS);
		reg |= (OMAP2_CONTROL_PBIAS_VMODE |
			OMAP2_CONTROL_PBIAS_VMODE1 |
			OMAP2_CONTROL_PBIAS_PWRDNZ |
			OMAP2_CONTROL_PBIAS_PWRDNZ1 |
			OMAP2_CONTROL_PBIAS_SCTRL |
			OMAP2_CONTROL_PBIAS_SCTRL1);
		omap_writel(reg, OMAP2_CONTROL_PBIAS);
	}

	return 0;

err:
	return 1;
}