Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions
bus.c File Reference
#include <linux/device.h>
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/string.h>
#include <linux/mutex.h>
#include "base.h"
#include "power/power.h"

Go to the source code of this file.

Macros

#define to_bus_attr(_attr)   container_of(_attr, struct bus_attribute, attr)
 
#define to_drv_attr(_attr)   container_of(_attr, struct driver_attribute, attr)
 

Functions

int bus_create_file (struct bus_type *bus, struct bus_attribute *attr)
 
 EXPORT_SYMBOL_GPL (bus_create_file)
 
void bus_remove_file (struct bus_type *bus, struct bus_attribute *attr)
 
 EXPORT_SYMBOL_GPL (bus_remove_file)
 
int bus_for_each_dev (struct bus_type *bus, struct device *start, void *data, int(*fn)(struct device *, void *))
 
 EXPORT_SYMBOL_GPL (bus_for_each_dev)
 
struct devicebus_find_device (struct bus_type *bus, struct device *start, void *data, int(*match)(struct device *dev, void *data))
 
 EXPORT_SYMBOL_GPL (bus_find_device)
 
: name of the device to match

bus_find_device_by_name - device iterator for locating a particular device of a specific name : bus type : Device to begin with

This is similar to the bus_find_device() function above, but it handles searching by a name automatically, no need to write another strcmp matching function.

struct devicebus_find_device_by_name (struct bus_type *bus, struct device *start, const char *name)
 
 EXPORT_SYMBOL_GPL (bus_find_device_by_name)
 
struct devicesubsys_find_device_by_id (struct bus_type *subsys, unsigned int id, struct device *hint)
 
 EXPORT_SYMBOL_GPL (subsys_find_device_by_id)
 
int bus_for_each_drv (struct bus_type *bus, struct device_driver *start, void *data, int(*fn)(struct device_driver *, void *))
 
 EXPORT_SYMBOL_GPL (bus_for_each_drv)
 
int bus_add_device (struct device *dev)
 
void bus_probe_device (struct device *dev)
 
void bus_remove_device (struct device *dev)
 
int bus_add_driver (struct device_driver *drv)
 
void bus_remove_driver (struct device_driver *drv)
 
int bus_rescan_devices (struct bus_type *bus)
 
 EXPORT_SYMBOL_GPL (bus_rescan_devices)
 
int device_reprobe (struct device *dev)
 
 EXPORT_SYMBOL_GPL (device_reprobe)
 
: name of bus.

find_bus - locate bus by name.

Call kset_find_obj() to iterate over list of buses to find a bus by name. Return bus if found.

Note that kset_find_obj increments bus' reference count.

int __bus_register (struct bus_type *bus, struct lock_class_key *key)
 
 EXPORT_SYMBOL_GPL (__bus_register)
 
void bus_unregister (struct bus_type *bus)
 
 EXPORT_SYMBOL_GPL (bus_unregister)
 
int bus_register_notifier (struct bus_type *bus, struct notifier_block *nb)
 
 EXPORT_SYMBOL_GPL (bus_register_notifier)
 
int bus_unregister_notifier (struct bus_type *bus, struct notifier_block *nb)
 
 EXPORT_SYMBOL_GPL (bus_unregister_notifier)
 
struct ksetbus_get_kset (struct bus_type *bus)
 
 EXPORT_SYMBOL_GPL (bus_get_kset)
 
struct klistbus_get_device_klist (struct bus_type *bus)
 
 EXPORT_SYMBOL_GPL (bus_get_device_klist)
 
void bus_sort_breadthfirst (struct bus_type *bus, int(*compare)(const struct device *a, const struct device *b))
 
 EXPORT_SYMBOL_GPL (bus_sort_breadthfirst)
 
void subsys_dev_iter_init (struct subsys_dev_iter *iter, struct bus_type *subsys, struct device *start, const struct device_type *type)
 
 EXPORT_SYMBOL_GPL (subsys_dev_iter_init)
 
struct devicesubsys_dev_iter_next (struct subsys_dev_iter *iter)
 
 EXPORT_SYMBOL_GPL (subsys_dev_iter_next)
 
void subsys_dev_iter_exit (struct subsys_dev_iter *iter)
 
 EXPORT_SYMBOL_GPL (subsys_dev_iter_exit)
 
int subsys_interface_register (struct subsys_interface *sif)
 
 EXPORT_SYMBOL_GPL (subsys_interface_register)
 
void subsys_interface_unregister (struct subsys_interface *sif)
 
 EXPORT_SYMBOL_GPL (subsys_interface_unregister)
 
int subsys_system_register (struct bus_type *subsys, const struct attribute_group **groups)
 
 EXPORT_SYMBOL_GPL (subsys_system_register)
 
int __init buses_init (void)
 

Macro Definition Documentation

#define to_bus_attr (   _attr)    container_of(_attr, struct bus_attribute, attr)

Definition at line 26 of file bus.c.

#define to_drv_attr (   _attr)    container_of(_attr, struct driver_attribute, attr)

Definition at line 32 of file bus.c.

Function Documentation

int __bus_register ( struct bus_type bus,
struct lock_class_key key 
)

__bus_register - register a driver-core subsystem : bus to register : lockdep class key

Once we have that, we register the bus with the kobject infrastructure, then register the children subsystems it has: the devices and drivers that belong to the subsystem.

Definition at line 923 of file bus.c.

int bus_add_device ( struct device dev)

bus_add_device - add device to bus : device being added

  • Add device's bus attributes.
  • Create links to device's bus.
  • Add the device to its bus's list of devices.

Definition at line 495 of file bus.c.

int bus_add_driver ( struct device_driver drv)

bus_add_driver - Add a driver to the bus. : driver.

Definition at line 691 of file bus.c.

int bus_create_file ( struct bus_type bus,
struct bus_attribute attr 
)

Definition at line 127 of file bus.c.

struct device* bus_find_device ( struct bus_type bus,
struct device start,
void data,
int(*)(struct device *dev, void *data match 
)
read

bus_find_device - device iterator for locating a particular device. : bus type : Device to begin with : Data to pass to match function : 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 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.

Definition at line 323 of file bus.c.

struct device* bus_find_device_by_name ( struct bus_type bus,
struct device start,
const char name 
)
read

Definition at line 360 of file bus.c.

int bus_for_each_dev ( struct bus_type bus,
struct device start,
void data,
int(*)(struct device *, void *)  fn 
)

Definition at line 289 of file bus.c.

int bus_for_each_drv ( struct bus_type bus,
struct device_driver start,
void data,
int(*)(struct device_driver *, void *)  fn 
)

Definition at line 439 of file bus.c.

struct klist* bus_get_device_klist ( struct bus_type bus)
read

Definition at line 1041 of file bus.c.

struct kset* bus_get_kset ( struct bus_type bus)
read

Definition at line 1035 of file bus.c.

void bus_probe_device ( struct device dev)

bus_probe_device - probe drivers for a new device : device to probe

  • Automatically probe for a driver if the bus allows it.

Definition at line 532 of file bus.c.

int bus_register_notifier ( struct bus_type bus,
struct notifier_block nb 
)

Definition at line 1023 of file bus.c.

void bus_remove_device ( struct device dev)

bus_remove_device - remove device from bus : device to be removed

  • Remove device from all interfaces.
  • Remove symlink from bus' directory.
  • Delete device from bus's list.
  • Detach from its driver.
  • Drop reference taken in bus_add_device().

Definition at line 563 of file bus.c.

void bus_remove_driver ( struct device_driver drv)

bus_remove_driver - delete driver from bus's knowledge. : driver.

Detach the driver from the devices it controls, and remove it from its bus's list of drivers. Finally, we drop the reference to the bus we took in bus_add_driver().

Definition at line 765 of file bus.c.

void bus_remove_file ( struct bus_type bus,
struct bus_attribute attr 
)

Definition at line 139 of file bus.c.

int bus_rescan_devices ( struct bus_type bus)

bus_rescan_devices - rescan devices on the bus for possible drivers : the bus to scan.

This function will look for devices on the bus with no driver attached and rescan it against existing drivers to see if it matches any by calling device_attach() for the unbound devices.

Definition at line 806 of file bus.c.

void bus_sort_breadthfirst ( struct bus_type bus,
int(*)(const struct device *a, const struct device *b compare 
)

Definition at line 1076 of file bus.c.

void bus_unregister ( struct bus_type bus)

bus_unregister - remove a bus from the system : bus.

Unregister the child subsystems and the bus itself. Finally, we call bus_put() to release the refcount

Definition at line 1007 of file bus.c.

int bus_unregister_notifier ( struct bus_type bus,
struct notifier_block nb 
)

Definition at line 1029 of file bus.c.

int __init buses_init ( void  )

Definition at line 1282 of file bus.c.

int device_reprobe ( struct device dev)

device_reprobe - remove driver for a device and probe for a new driver : the device to reprobe

This function detaches the attached driver (if any) for the given device and restarts the driver probing process. It is intended to use if probing criteria changed during a devices lifetime and driver attachment should change accordingly.

Definition at line 821 of file bus.c.

EXPORT_SYMBOL_GPL ( bus_create_file  )
EXPORT_SYMBOL_GPL ( bus_remove_file  )
EXPORT_SYMBOL_GPL ( bus_for_each_dev  )
EXPORT_SYMBOL_GPL ( bus_find_device  )
EXPORT_SYMBOL_GPL ( bus_find_device_by_name  )
EXPORT_SYMBOL_GPL ( subsys_find_device_by_id  )
EXPORT_SYMBOL_GPL ( bus_for_each_drv  )
EXPORT_SYMBOL_GPL ( bus_rescan_devices  )
EXPORT_SYMBOL_GPL ( device_reprobe  )
EXPORT_SYMBOL_GPL ( __bus_register  )
EXPORT_SYMBOL_GPL ( bus_unregister  )
EXPORT_SYMBOL_GPL ( bus_register_notifier  )
EXPORT_SYMBOL_GPL ( bus_unregister_notifier  )
EXPORT_SYMBOL_GPL ( bus_get_kset  )
EXPORT_SYMBOL_GPL ( bus_get_device_klist  )
EXPORT_SYMBOL_GPL ( bus_sort_breadthfirst  )
EXPORT_SYMBOL_GPL ( subsys_dev_iter_init  )
EXPORT_SYMBOL_GPL ( subsys_dev_iter_next  )
EXPORT_SYMBOL_GPL ( subsys_dev_iter_exit  )
EXPORT_SYMBOL_GPL ( subsys_interface_register  )
EXPORT_SYMBOL_GPL ( subsys_interface_unregister  )
EXPORT_SYMBOL_GPL ( subsys_system_register  )
void subsys_dev_iter_exit ( struct subsys_dev_iter iter)

subsys_dev_iter_exit - finish iteration : subsys iterator to finish

Finish an iteration. Always call this function after iteration is complete whether the iteration ran till the end or not.

Definition at line 1160 of file bus.c.

void subsys_dev_iter_init ( struct subsys_dev_iter iter,
struct bus_type subsys,
struct device start,
const struct device_type type 
)

subsys_dev_iter_init - initialize subsys device iterator : subsys iterator to initialize : the subsys we wanna iterate over : the device to start iterating from, if any : device_type of the devices to iterate over, NULL for all

Initialize subsys iterator such that it iterates over devices of . If is set, the list iteration will start there, otherwise if it is NULL, the iteration starts at the beginning of the list.

Definition at line 1113 of file bus.c.

struct device* subsys_dev_iter_next ( struct subsys_dev_iter iter)
read

subsys_dev_iter_next - iterate to the next device : subsys iterator to proceed

Proceed to the next device and return it. Returns NULL if iteration is complete.

The returned device is referenced and won't be released till iterator is proceed to the next device or exited. The caller is free to do whatever it wants to do with the device including calling back into subsys code.

Definition at line 1137 of file bus.c.

struct device* subsys_find_device_by_id ( struct bus_type subsys,
unsigned int  id,
struct device hint 
)
read

subsys_find_device_by_id - find a device with a specific enumeration number : subsystem : index 'id' in struct device : 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.

Definition at line 377 of file bus.c.

int subsys_interface_register ( struct subsys_interface sif)

Definition at line 1166 of file bus.c.

void subsys_interface_unregister ( struct subsys_interface sif)

Definition at line 1193 of file bus.c.

int subsys_system_register ( struct bus_type subsys,
const struct attribute_group **  groups 
)

subsys_system_register - register a subsystem at /sys/devices/system/ : system subsystem : default attributes for the root device

All 'system' subsystems have a /sys/devices/system/<name> root device with the name of the subsystem. The root device can carry subsystem- wide attributes. All registered devices are below this single root device and are named after the subsystem with a simple enumeration number appended. The registered devices are not explicitely named; only 'id' in the device needs to be set.

Do not use this interface for anything new, it exists for compatibility with bad ideas only. New subsystems should use plain subsystems; and add the subsystem-wide attributes should be added to the subsystem directory itself and not some create fake root-device placed in /sys/devices/system/<name>.

Definition at line 1240 of file bus.c.