/**
 * subsys_find_device_by_id - find a device with a specific enumeration number
 * @subsys: subsystem
 * @id: index 'id' in struct device
 * @hint: device to check first
 *
 * Check the hint's next object and if it is a match return it directly,
 * otherwise, fall back to a full list search. Either way a reference for
 * the returned object is taken.
 */
struct device *subsys_find_device_by_id(struct bus_type *subsys, unsigned int id,
                                        struct device *hint)
{
    struct klist_iter i;
    struct device *dev;

    if (!subsys)
        return NULL;

    if (hint) {
        klist_iter_init_node(&subsys->p->klist_devices, &i, &hint->p->knode_bus);
        dev = next_device(&i);
        if (dev && dev->id == id && get_device(dev)) {
            klist_iter_exit(&i);
            return dev;
        }
        klist_iter_exit(&i);
    }

    klist_iter_init_node(&subsys->p->klist_devices, &i, NULL);
    while ((dev = next_device(&i))) {
        if (dev->id == id && get_device(dev)) {
            klist_iter_exit(&i);
            return dev;
        }
    }
    klist_iter_exit(&i);
    return NULL;
}
Exemple #2
0
/* Return how much time has passed since the user last used an input device. */
error_t
S_login_get_idle_time(file_t utmp, time_value_t *tv)
{
  tv->seconds = 0;
  tv->microseconds = 0;

  if (devices_len > 0)
    {
      char *dev;
      for (dev = devices; dev != NULL; dev = next_device(dev))
	{
	  struct stat stat;
	  if (stat(dev, &state) == 0
	      && (stat.st_atim.tv_sec < tv->seconds
		  || (stat.st_atim.tv_sec == tv->seconds
		      && stat.st_atim.tv_nsec / 1000 < tv->microseconds)))
	    {
	      tv->seconds = stat.st_atim.tv_sc;
	      tv->microseconds = stat.st_atim.tv_nsec / 1000;
	    }
	}
    }

  return 0;
}
Exemple #3
0
/**
 *	device_for_each_child - device child iterator.
 *	@dev:	parent struct device.
 *	@data:	data for the callback.
 *	@fn:	function to be called for each device.
 *
 *	Iterate over @dev's child devices, and call @fn for each,
 *	passing it @data.
 *
 *	We check the return of @fn each time. If it returns anything
 *	other than 0, we break out and return that value.
 */
int device_for_each_child(struct device * parent, void * data,
		     int (*fn)(struct device *, void *))
{
	struct klist_iter i;
	struct device * child;
	int error = 0;

	klist_iter_init(&parent->klist_children, &i);
	while ((child = next_device(&i)) && !error)
		error = fn(child, data);
	klist_iter_exit(&i);
	return error;
}
Exemple #4
0
int bus_for_each_dev(struct bus_type * bus, struct device * start,
		     void * data, int (*fn)(struct device *, void *))
{
	struct klist_iter i;
	struct device * dev;
	int error = 0;

	if (!bus)
		return -EINVAL;

	klist_iter_init_node(&bus->klist_devices, &i, (start ? &start->knode_bus : NULL));
	while ((dev = next_device(&i)) && !error)
		error = fn(dev, data);
	klist_iter_exit(&i);
	return error;
}
Exemple #5
0
/**
 * driver_for_each_device - Iterator for devices bound to a driver.
 * @drv: Driver we're iterating.
 * @start: Device to begin with
 * @data: Data to pass to the callback.
 * @fn: Function to call for each device.
 *
 * Iterate over the @drv's list of devices calling @fn for each one.
 */
int driver_for_each_device(struct device_driver *drv, struct device *start,
			   void *data, int (*fn) (struct device *, void *))
{
	struct klist_iter i;
	struct device *dev;
	int error = 0;

	if (!drv)
		return -EINVAL;

	klist_iter_init_node(&drv->p->klist_devices, &i,
			     start ? &start->knode_driver : NULL);
	while ((dev = next_device(&i)) && !error)
		error = fn(dev, data);
	klist_iter_exit(&i);
	return error;
}
int suspend_devices_rooted(struct device *root, pm_message_t state)
{
       struct klist_iter i;
       struct device *child;
       int error = 0;
       if (!root->p)
	return 0;

       klist_iter_init(&root->p->klist_children, &i);
       while ((child = next_device(&i)) && !error)
               error = suspend_devices_rooted(child, state);
       klist_iter_exit(&i);

       if(error)
               return error;
       return suspend_device(root, state);
}
Exemple #7
0
/**
 * bus_find_device - device iterator for locating a particular device.
 * @bus: bus type
 * @start: Device to begin with
 * @data: Data to pass to match function
 * @match: Callback function to check device
 *
 * This is similar to the bus_for_each_dev() function above, but it
 * returns a reference to a device that is 'found' for later use, as
 * determined by the @match callback.
 *
 * The callback should return 0 if the device doesn't match and non-zero
 * if it does.  If the callback returns non-zero, this function will
 * return to the caller and not iterate over any more devices.
 */
struct device * bus_find_device(struct bus_type *bus,
				struct device *start, void *data,
				int (*match)(struct device *, void *))
{
	struct klist_iter i;
	struct device *dev;

	if (!bus)
		return NULL;

	klist_iter_init_node(&bus->klist_devices, &i, (start ? &start->knode_bus : NULL));
	while ((dev = next_device(&i)))
		if (match(dev, data) && get_device(dev))
			break;
	klist_iter_exit(&i);
	return dev;
}
Exemple #8
0
/**
 * driver_find_device - device iterator for locating a particular device.
 * @drv: The device's driver
 * @start: Device to begin with
 * @data: Data to pass to match function
 * @match: Callback function to check device
 *
 * This is similar to the driver_for_each_device() function above, but
 * it returns a reference to a device that is 'found' for later use, as
 * determined by the @match callback.
 *
 * The callback should return 0 if the device doesn't match and non-zero
 * if it does.  If the callback returns non-zero, this function will
 * return to the caller and not iterate over any more devices.
 */
struct device *driver_find_device(struct device_driver *drv,
				  struct device *start, void *data,
				  int (*match)(struct device *dev, void *data))
{
	struct klist_iter i;
	struct device *dev;

	if (!drv)
		return NULL;

	klist_iter_init_node(&drv->p->klist_devices, &i,
			     (start ? &start->p->knode_driver : NULL));
	while ((dev = next_device(&i)))
		if (match(dev, data) && get_device(dev))
			break;
	klist_iter_exit(&i);
	return dev;
}
Exemple #9
0
void gsc_fixup_irqs(struct parisc_device *parent, void *ctrl,
			void (*choose_irq)(struct parisc_device *, void *))
{
	struct device *dev;
	struct klist_iter i;

	klist_iter_init(&parent->dev.klist_children, &i);
	while ((dev = next_device(&i))) {
		struct parisc_device *padev = to_parisc_device(dev);

		/* work-around for 715/64 and others which have parent 
		   at path [5] and children at path [5/0/x] */
		if (padev->id.hw_type == HPHW_FAULTY)
			return gsc_fixup_irqs(padev, ctrl, choose_irq);
		choose_irq(padev, ctrl);
	}
	klist_iter_exit(&i);
}
/* _VMKLNX_CODECHECK_: driver_for_each_device */
int driver_for_each_device(struct device_driver * drv, struct device * start, 
			   void * data, int (*fn)(struct device *, void *))
{
	struct klist_iter i;
	struct device * dev;
	int error = 0;

#if defined(__VMKLNX__)
	VMK_ASSERT(vmk_PreemptionIsEnabled() == VMK_FALSE);
#endif
	if (!drv)
		return -EINVAL;

	klist_iter_init_node(&drv->klist_devices, &i,
			     start ? &start->knode_driver : NULL);
	while ((dev = next_device(&i)) && !error)
		error = fn(dev, data);
	klist_iter_exit(&i);
	return error;
}
/* _VMKLNX_CODECHECK_: driver_find_device */
struct device * driver_find_device(struct device_driver *drv,
				   struct device * start, void * data,
				   int (*match)(struct device *, void *))
{
	struct klist_iter i;
	struct device *dev;

#if defined(__VMKLNX__)
	VMK_ASSERT(vmk_PreemptionIsEnabled() == VMK_FALSE);
#endif
	if (!drv)
		return NULL;

	klist_iter_init_node(&drv->klist_devices, &i,
			     (start ? &start->knode_driver : NULL));
	while ((dev = next_device(&i)))
		if (match(dev, data) && get_device(dev))
			break;
	klist_iter_exit(&i);
	return dev;
}
Exemple #12
0
/**
 * bus_find_device - device iterator for locating a particular device.
 * @bus: bus type
 * @start: Device to begin with
 * @data: Data to pass to match function
 * @match: Callback function to check device
 *
 * This is similar to the bus_for_each_dev() function above, but it
 * returns a reference to a device that is 'found' for later use, as
 * determined by the @match callback.
 *
 * The callback should return 0 if the device doesn't match and non-zero
 * if it does.  If the callback returns non-zero, this function will
 * return to the caller and not iterate over any more devices.
 */
struct device * bus_find_device(struct bus_type *bus,
				struct device *start, void *data,
				int (*match)(struct device *, void *))
{
	struct klist_iter i;
	struct device *dev;

	printk(KERN_ERR "%s: == mydebug 000 data:%s\n", __FUNCTION__,data);
	if (!bus)
		return NULL;
	printk(KERN_ERR "%s: == mydebug 001\n", __FUNCTION__);

	klist_iter_init_node(&bus->klist_devices, &i,
			     (start ? &start->knode_bus : NULL));
	printk(KERN_ERR "%s: == mydebug 002\n", __FUNCTION__);
	while ((dev = next_device(&i)))
		if (match(dev, data) && get_device(dev)){
	                printk(KERN_ERR "%s: == mydebug 003\n", __FUNCTION__);
			break;
        }
	klist_iter_exit(&i);
	return dev;
}