Linux Kernel
3.7.1
|
#include <linux/device.h>
#include <linux/err.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/kdev_t.h>
#include <linux/notifier.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/genhd.h>
#include <linux/kallsyms.h>
#include <linux/mutex.h>
#include <linux/async.h>
#include <linux/pm_runtime.h>
#include <linux/netdevice.h>
#include "base.h"
#include "power/power.h"
Go to the source code of this file.
Data Structures | |
struct | class_dir |
struct | root_device |
Macros | |
#define | to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr) |
#define | to_ext_attr(x) container_of(x, struct dev_ext_attribute, attr) |
#define | to_class_dir(obj) container_of(obj, struct class_dir, kobj) |
Variables | |
int(* | platform_notify )(struct device *dev) = NULL |
int(* | platform_notify_remove )(struct device *dev) = NULL |
struct kobject * | sysfs_dev_char_kobj |
struct kobject * | sysfs_dev_block_kobj |
struct kset * | devices_kset |
#define to_class_dir | ( | obj | ) | container_of(obj, struct class_dir, kobj) |
#define to_dev_attr | ( | _attr | ) | container_of(_attr, struct device_attribute, attr) |
#define to_ext_attr | ( | x | ) | container_of(x, struct dev_ext_attribute, attr) |
dev_driver_string - Return a device's driver name, if at all possible : struct device to get the name of
Will return the device's driver's name if it is bound to a device. If the device is not bound to a driver, it will return the name of the bus it is attached to. If it is not attached to a bus either, an empty string will be returned.
device_add - add device to device hierarchy. : device.
This is part 2 of device_register(), though may be called separately iff device_initialize() has been called separately.
This adds to the kobject hierarchy via kobject_add(), adds it to the global and sibling lists for the device, then adds it to the other relevant subsystems of the driver model.
Do not call this routine or device_register() more than once for any device structure. The driver model core is not designed to work with devices that get unregistered and then spring back to life. (Among other things, it's very hard to guarantee that all references to the previous incarnation of have been dropped.) Allocate and register a fresh new struct device instead.
NOTE: Never directly free after calling this function, even if it returned an error! Always use put_device() to give up your reference instead.
device_del - delete device from system. : device.
This is the first part of the device unregistration sequence. This removes the device from the lists we control from here, has it removed from the other driver model subsystems it was added to in device_add(), and removes it from the kobject hierarchy.
NOTE: this should be called manually iff device_add() was also called manually.
|
read |
device_find_child - device iterator for locating a particular device. : parent struct device : Data to pass to match function : Callback function to check device
This is similar to the device_for_each_child() 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 and a reference to the current device can be obtained, this function will return to the caller and not iterate over any more devices.
device_initialize - init device structure. : device.
This prepares the device for use by other layers by initializing its fields. It is the first half of device_register(), if called by that function, though it can also be called separately, so one may use 's fields. In particular, get_device()/put_device() may be used for reference counting of after calling this function.
All fields in must be initialized by the caller to 0, except for those explicitly set to some other value. The simplest approach is to use kzalloc() to allocate the structure containing .
NOTE: Use put_device() to give up your reference instead of freeing directly once you have called this function.
device_register - register a device with the system. : pointer to the device structure
This happens in two clean steps - initialize the device and add it to the system. The two steps can be called separately, but this is the easiest and most common. I.e. you should only call the two helpers separately if have a clearly defined need to use and refcount the device before it is added to the hierarchy.
For more information, see the kerneldoc for device_initialize() and device_add().
NOTE: Never directly free after calling this function, even if it returned an error! Always use put_device() to give up the reference initialized in this function instead.
device_rename - renames a device : the pointer to the struct device to be renamed : the new name of the device
It is the responsibility of the caller to provide mutual exclusion between two different calls of device_rename on the same device to ensure that new_name is valid and won't conflict with other devices.
Note: Don't call this function. Currently, the networking layer calls this function, but that will change. The following text from Kay Sievers offers some insight:
Renaming devices is racy at many levels, symlinks and other stuff are not replaced atomically, and you get a "move" uevent, but it's not easy to connect the event to the old and new device. Device nodes are not renamed at all, there isn't even support for that in the kernel now.
In the meantime, during renaming, your target name might be taken by another driver, creating conflicts. Or the old name is taken directly after you renamed it – then you get events for the same DEVPATH, before you even see the "move" event. It's just a mess, and nothing new should ever rely on kernel device renaming. Besides that, it's not even implemented now for other things than (driver-core wise very simple) network devices.
We are currently about to change network renaming in udev to completely disallow renaming of devices in the same namespace as the kernel uses, because we can't solve the problems properly, that arise with swapping names of multiple interfaces without races. Means, renaming of eth[0-9]* will only be allowed to some other name than eth[0-9]*, for the aforementioned reasons.
Make up a "real" name in the driver before you register anything, or add some other attributes for userspace to find the device, or use udev to add symlinks – but never rename kernel devices later, it's a complete mess. We don't even want to get into that and try to implement the missing pieces in the core. We really have other pieces to fix in the driver core mess. :)
int device_schedule_callback_owner | ( | struct device * | dev, |
void(*)(struct device *) | func, | ||
struct module * | owner | ||
) |
device_schedule_callback_owner - helper to schedule a callback for a device : device. : callback function to invoke later. : module owning the callback routine
Attribute methods must not unregister themselves or their parent device (which would amount to the same thing). Attempts to do so will deadlock, since unregistration is mutually exclusive with driver callbacks.
Instead methods can call this routine, which will attempt to allocate and schedule a workqueue request to call back with as its argument in the workqueue's process context. will be pinned until returns.
This routine is usually called via the inline device_schedule_callback(), which automatically sets to THIS_MODULE.
Returns 0 if the request was submitted, -ENOMEM if storage could not be allocated, -ENODEV if a reference to isn't available.
NOTE: This routine won't work if CONFIG_SYSFS isn't set! It uses an underlying sysfs routine (since it is intended for use by attribute methods), and if sysfs isn't available you'll get nothing but -ENOSYS.
device_unregister - unregister device from system. : device going away.
We do this in two parts, like we do device_register(). First, we remove it from all the subsystems with device_del(), then we decrement the reference count via put_device(). If that is the final reference count, the device will be cleaned up via device_release() above. Otherwise, the structure will stick around until the final reference to the device is dropped.
EXPORT_SYMBOL | ( | dev_driver_string | ) |
EXPORT_SYMBOL_GPL | ( | device_store_ulong | ) |
EXPORT_SYMBOL_GPL | ( | device_show_ulong | ) |
EXPORT_SYMBOL_GPL | ( | device_store_int | ) |
EXPORT_SYMBOL_GPL | ( | device_show_int | ) |
EXPORT_SYMBOL_GPL | ( | device_create_bin_file | ) |
EXPORT_SYMBOL_GPL | ( | device_remove_bin_file | ) |
EXPORT_SYMBOL_GPL | ( | device_schedule_callback_owner | ) |
EXPORT_SYMBOL_GPL | ( | dev_set_name | ) |
EXPORT_SYMBOL_GPL | ( | device_for_each_child | ) |
EXPORT_SYMBOL_GPL | ( | device_find_child | ) |
EXPORT_SYMBOL_GPL | ( | device_initialize | ) |
EXPORT_SYMBOL_GPL | ( | device_add | ) |
EXPORT_SYMBOL_GPL | ( | device_register | ) |
EXPORT_SYMBOL_GPL | ( | device_del | ) |
EXPORT_SYMBOL_GPL | ( | device_unregister | ) |
EXPORT_SYMBOL_GPL | ( | get_device | ) |
EXPORT_SYMBOL_GPL | ( | put_device | ) |
EXPORT_SYMBOL_GPL | ( | device_create_file | ) |
EXPORT_SYMBOL_GPL | ( | device_remove_file | ) |
EXPORT_SYMBOL_GPL | ( | __root_device_register | ) |
EXPORT_SYMBOL_GPL | ( | root_device_unregister | ) |
EXPORT_SYMBOL_GPL | ( | device_create_vargs | ) |
EXPORT_SYMBOL_GPL | ( | device_create | ) |
EXPORT_SYMBOL_GPL | ( | device_destroy | ) |
EXPORT_SYMBOL_GPL | ( | device_rename | ) |
EXPORT_SYMBOL_GPL | ( | device_move | ) |
root_device_unregister - unregister and free a root device : device going away
This function unregisters and cleans up a device that was created by root_device_register().
|
read |