core.c File Reference

Go to the source code of this file.

Classes

struct  root_device

Defines

#define to_dev(obj)   container_of(obj, struct device, kobj)
#define to_dev_attr(_attr)   container_of(_attr, struct device_attribute, attr)
#define to_root_device(dev)   container_of(dev, struct root_device, dev)

Functions

static int device_is_not_partition (struct device *dev)
const char * dev_driver_string (const struct device *dev)
 dev_driver_string - Return a device's driver name, if at all possible : struct device to get the name of
 EXPORT_SYMBOL (dev_driver_string)
static ssize_t dev_attr_show (struct kobject *kobj, struct attribute *attr, char *buf)
static ssize_t dev_attr_store (struct kobject *kobj, struct attribute *attr, const char *buf, size_t count)
static void device_release (struct kobject *kobj)
 device_release - free device structure.
static int dev_uevent_filter (struct kset *kset, struct kobject *kobj)
static const char * dev_uevent_name (struct kset *kset, struct kobject *kobj)
static int dev_uevent (struct kset *kset, struct kobject *kobj, struct kobj_uevent_env *env)
static ssize_t show_uevent (struct device *dev, struct device_attribute *attr, char *buf)
static ssize_t store_uevent (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
static int device_add_attributes (struct device *dev, struct device_attribute *attrs)
static void device_remove_attributes (struct device *dev, struct device_attribute *attrs)
static int device_add_groups (struct device *dev, struct attribute_group **groups)
static void device_remove_groups (struct device *dev, struct attribute_group **groups)
static int device_add_attrs (struct device *dev)
static void device_remove_attrs (struct device *dev)
static ssize_t show_dev (struct device *dev, struct device_attribute *attr, char *buf)
int device_create_file (struct device *dev, struct device_attribute *attr)
 device_create_file - create sysfs attribute file for device.
void device_remove_file (struct device *dev, struct device_attribute *attr)
 device_remove_file - remove sysfs attribute file.
int device_create_bin_file (struct device *dev, struct bin_attribute *attr)
 device_create_bin_file - create sysfs binary attribute file for device.
 EXPORT_SYMBOL_GPL (device_create_bin_file)
void device_remove_bin_file (struct device *dev, struct bin_attribute *attr)
 device_remove_bin_file - remove sysfs binary attribute file : device.
 EXPORT_SYMBOL_GPL (device_remove_bin_file)
int device_schedule_callback_owner (struct device *dev, void(*func)(struct device *), struct module *owner)
 device_schedule_callback_owner - helper to schedule a callback for a device : device.
 EXPORT_SYMBOL_GPL (device_schedule_callback_owner)
static void klist_children_get (struct klist_node *n)
static void klist_children_put (struct klist_node *n)
void device_initialize (struct device *dev)
 device_initialize - init device structure.
static struct kobject * virtual_device_parent (struct device *dev)
static struct kobject * get_device_parent (struct device *dev, struct device *parent)
static void cleanup_glue_dir (struct device *dev, struct kobject *glue_dir)
static void cleanup_device_parent (struct device *dev)
static void setup_parent (struct device *dev, struct device *parent)
static int device_add_class_symlinks (struct device *dev)
static void device_remove_class_symlinks (struct device *dev)
int dev_set_name (struct device *dev, const char *fmt,...)
 dev_set_name - set a device name : device : format string for the device's name
 EXPORT_SYMBOL_GPL (dev_set_name)
static struct kobject * device_to_dev_kobj (struct device *dev)
 device_to_dev_kobj - select a /sys/dev/ directory for the device : device
static int device_create_sys_dev_entry (struct device *dev)
static void device_remove_sys_dev_entry (struct device *dev)
int device_add (struct device *dev)
 device_add - add device to device hierarchy.
int device_register (struct device *dev)
 device_register - register a device with the system.
struct device * get_device (struct device *dev)
 get_device - increment reference count for device.
void put_device (struct device *dev)
 put_device - decrement reference count.
void device_del (struct device *dev)
 device_del - delete device from system.
void device_unregister (struct device *dev)
 device_unregister - unregister device from system.
static struct device * next_device (struct klist_iter *i)
int device_for_each_child (struct device *parent, void *data, int(*fn)(struct device *dev, void *data))
struct device * device_find_child (struct device *parent, void *data, int(*match)(struct device *dev, void *data))
 device_find_child - device iterator for locating a particular device.
int __init devices_init (void)
 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)
static void root_device_release (struct device *dev)
: root device name
__root_device_register - allocate and register a root device

: owner module of the root device, usually THIS_MODULE

This function allocates a root device and registers it using device_register(). In order to free the returned device, use root_device_unregister().

Root devices are dummy devices which allow other devices to be grouped under /sys/devices. Use this function to allocate a root device and then use it as the parent of any device which should appear under /sys/devices/{name}

The /sys/devices/{name} directory will also contain a 'module' symlink which points to the directory in sysfs.

Note: You probably want to use root_device_register().

struct device * __root_device_register (const char *name, struct module *owner)
 EXPORT_SYMBOL_GPL (__root_device_register)
void root_device_unregister (struct device *dev)
 root_device_unregister - unregister and free a root device : device going away
 EXPORT_SYMBOL_GPL (root_device_unregister)
static void device_create_release (struct device *dev)
struct device * device_create_vargs (struct class *class, struct device *parent, dev_t devt, void *drvdata, const char *fmt, va_list args)
 EXPORT_SYMBOL_GPL (device_create_vargs)
struct device * device_create (struct class *class, struct device *parent, dev_t devt, void *drvdata, const char *fmt,...)
 EXPORT_SYMBOL_GPL (device_create)
static int __match_devt (struct device *dev, void *data)
void device_destroy (struct class *class, dev_t devt)
 EXPORT_SYMBOL_GPL (device_destroy)
int device_rename (struct device *dev, char *new_name)
 device_rename - renames a device : the pointer to the struct device to be renamed : the new name of the device
 EXPORT_SYMBOL_GPL (device_rename)
static int device_move_class_links (struct device *dev, struct device *old_parent, struct device *new_parent)
int device_move (struct device *dev, struct device *new_parent)
 device_move - moves a device to a new parent : the pointer to the struct device to be moved : the new parent of the device (can by NULL)
 EXPORT_SYMBOL_GPL (device_move)
void device_shutdown (void)
 device_shutdown - call ->shutdown() on each device to shutdown.

Variables

int(* platform_notify )(struct device *dev) = NULL
int(* platform_notify_remove )(struct device *dev) = NULL
static struct kobject * dev_kobj
struct kobject * sysfs_dev_char_kobj
struct kobject * sysfs_dev_block_kobj
static struct sysfs_ops dev_sysfs_ops
static struct kobj_type device_ktype
static struct kset_uevent_ops device_uevent_ops
static struct device_attribute uevent_attr
static struct device_attribute devt_attr
struct kset * devices_kset


Define Documentation

#define to_dev ( obj   )     container_of(obj, struct device, kobj)

Definition at line 68 of file core.c.

#define to_dev_attr ( _attr   )     container_of(_attr, struct device_attribute, attr)

Definition at line 69 of file core.c.

#define to_root_device ( dev   )     container_of(dev, struct root_device, dev)

Definition at line 1220 of file core.c.


Function Documentation

static int __match_devt ( struct device *  dev,
void *  data 
) [static]

Definition at line 1405 of file core.c.

struct device* __root_device_register ( const char *  name,
struct module *  owner 
) [read]

Definition at line 1247 of file core.c.

static void cleanup_device_parent ( struct device *  dev  )  [static]

Definition at line 649 of file core.c.

static void cleanup_glue_dir ( struct device *  dev,
struct kobject *  glue_dir 
) [static]

Definition at line 639 of file core.c.

static ssize_t dev_attr_show ( struct kobject *  kobj,
struct attribute *  attr,
char *  buf 
) [static]

Definition at line 71 of file core.c.

static ssize_t dev_attr_store ( struct kobject *  kobj,
struct attribute *  attr,
const char *  buf,
size_t  count 
) [static]

Definition at line 87 of file core.c.

const char* dev_driver_string ( const struct device *  dev  ) 

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 device, 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.

Definition at line 60 of file core.c.

int dev_set_name ( struct device *  dev,
const char *  fmt,
  ... 
)

dev_set_name - set a device name : device : format string for the device's name

Definition at line 783 of file core.c.

static int dev_uevent ( struct kset *  kset,
struct kobject *  kobj,
struct kobj_uevent_env *  env 
) [static]

Definition at line 162 of file core.c.

static int dev_uevent_filter ( struct kset *  kset,
struct kobject *  kobj 
) [static]

Definition at line 135 of file core.c.

static const char* dev_uevent_name ( struct kset *  kset,
struct kobject *  kobj 
) [static]

Definition at line 151 of file core.c.

int device_add ( struct device *  dev  ) 

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.

NOTE: _Never_ directly free after calling this function, even if it returned an error! Always use put_device() to give up your reference instead.

Definition at line 863 of file core.c.

static int device_add_attributes ( struct device *  dev,
struct device_attribute *  attrs 
) [static]

Definition at line 311 of file core.c.

static int device_add_attrs ( struct device *  dev  )  [static]

Definition at line 370 of file core.c.

static int device_add_class_symlinks ( struct device *  dev  )  [static]

Definition at line 663 of file core.c.

static int device_add_groups ( struct device *  dev,
struct attribute_group **  groups 
) [static]

Definition at line 340 of file core.c.

struct device* device_create ( struct class *  class,
struct device *  parent,
dev_t  devt,
void *  drvdata,
const char *  fmt,
  ... 
) [read]

Definition at line 1392 of file core.c.

int device_create_bin_file ( struct device *  dev,
struct bin_attribute *  attr 
)

device_create_bin_file - create sysfs binary attribute file for device.

: device. : device binary attribute descriptor.

Definition at line 460 of file core.c.

int device_create_file ( struct device *  dev,
struct device_attribute *  attr 
)

device_create_file - create sysfs attribute file for device.

: device. : device attribute descriptor.

Definition at line 436 of file core.c.

static void device_create_release ( struct device *  dev  )  [static]

Definition at line 1306 of file core.c.

static int device_create_sys_dev_entry ( struct device *  dev  )  [static]

Definition at line 823 of file core.c.

struct device* device_create_vargs ( struct class *  class,
struct device *  parent,
dev_t  devt,
void *  drvdata,
const char *  fmt,
va_list  args 
) [read]

Definition at line 1335 of file core.c.

void device_del ( struct device *  dev  ) 

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.

Definition at line 1037 of file core.c.

void device_destroy ( struct class *  class,
dev_t  devt 
)

Definition at line 1420 of file core.c.

struct device* device_find_child ( struct device *  parent,
void *  data,
int(*)(struct device *dev, void *data)  match 
) [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.

Definition at line 1156 of file core.c.

int device_for_each_child ( struct device *  parent,
void *  data,
int(*)(struct device *dev, void *data)  fn 
)

Definition at line 1127 of file core.c.

void device_initialize ( struct device *  dev  ) 

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.

NOTE: Use put_device() to give up your reference instead of freeing directly once you have called this function.

Definition at line 543 of file core.c.

static int device_is_not_partition ( struct device *  dev  )  [inline, static]

Definition at line 45 of file core.c.

int device_move ( struct device *  dev,
struct device *  new_parent 
)

device_move - moves a device to a new parent : the pointer to the struct device to be moved : the new parent of the device (can by NULL)

Definition at line 1555 of file core.c.

static int device_move_class_links ( struct device *  dev,
struct device *  old_parent,
struct device *  new_parent 
) [static]

Definition at line 1509 of file core.c.

int device_register ( struct device *  dev  ) 

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.

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.

Definition at line 994 of file core.c.

static void device_release ( struct kobject *  kobj  )  [static]

device_release - free device structure.

: device's kobject.

This is called once the reference count for the object reaches 0. We forward the call to the device's release method, which should handle actually freeing the structure.

Definition at line 113 of file core.c.

static void device_remove_attributes ( struct device *  dev,
struct device_attribute *  attrs 
) [static]

Definition at line 330 of file core.c.

static void device_remove_attrs ( struct device *  dev  )  [static]

Definition at line 404 of file core.c.

void device_remove_bin_file ( struct device *  dev,
struct bin_attribute *  attr 
)

device_remove_bin_file - remove sysfs binary attribute file : device.

: device binary attribute descriptor.

Definition at line 474 of file core.c.

static void device_remove_class_symlinks ( struct device *  dev  )  [static]

Definition at line 747 of file core.c.

void device_remove_file ( struct device *  dev,
struct device_attribute *  attr 
)

device_remove_file - remove sysfs attribute file.

: device. : device attribute descriptor.

Definition at line 449 of file core.c.

static void device_remove_groups ( struct device *  dev,
struct attribute_group **  groups 
) [static]

Definition at line 360 of file core.c.

static void device_remove_sys_dev_entry ( struct device *  dev  )  [static]

Definition at line 837 of file core.c.

int device_rename ( struct device *  dev,
char *  new_name 
)

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.

Definition at line 1442 of file core.c.

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.

Definition at line 506 of file core.c.

void device_shutdown ( void   ) 

device_shutdown - call ->shutdown() on each device to shutdown.

Definition at line 1616 of file core.c.

static struct kobject* device_to_dev_kobj ( struct device *  dev  )  [static, read]

device_to_dev_kobj - select a /sys/dev/ directory for the device : device

By default we select char/ for new entries. Setting class->dev_obj to NULL prevents an entry from being created. class->dev_kobj must be set (or cleared) before any devices are registered to the class otherwise device_create_sys_dev_entry() and device_remove_sys_dev_entry() will disagree about the the presence of the link.

Definition at line 811 of file core.c.

void device_unregister ( struct device *  dev  ) 

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.

Definition at line 1102 of file core.c.

int __init devices_init ( void   ) 

Definition at line 1173 of file core.c.

EXPORT_SYMBOL ( dev_driver_string   ) 

EXPORT_SYMBOL_GPL ( device_move   ) 

EXPORT_SYMBOL_GPL ( device_rename   ) 

EXPORT_SYMBOL_GPL ( device_destroy   ) 

EXPORT_SYMBOL_GPL ( device_create   ) 

EXPORT_SYMBOL_GPL ( device_create_vargs   ) 

EXPORT_SYMBOL_GPL ( root_device_unregister   ) 

EXPORT_SYMBOL_GPL ( __root_device_register   ) 

EXPORT_SYMBOL_GPL ( device_remove_file   ) 

EXPORT_SYMBOL_GPL ( device_create_file   ) 

EXPORT_SYMBOL_GPL ( put_device   ) 

EXPORT_SYMBOL_GPL ( get_device   ) 

EXPORT_SYMBOL_GPL ( device_unregister   ) 

EXPORT_SYMBOL_GPL ( device_del   ) 

EXPORT_SYMBOL_GPL ( device_register   ) 

EXPORT_SYMBOL_GPL ( device_add   ) 

EXPORT_SYMBOL_GPL ( device_initialize   ) 

EXPORT_SYMBOL_GPL ( device_find_child   ) 

EXPORT_SYMBOL_GPL ( device_for_each_child   ) 

EXPORT_SYMBOL_GPL ( dev_set_name   ) 

EXPORT_SYMBOL_GPL ( device_schedule_callback_owner   ) 

EXPORT_SYMBOL_GPL ( device_remove_bin_file   ) 

EXPORT_SYMBOL_GPL ( device_create_bin_file   ) 

struct device* get_device ( struct device *  dev  )  [read]

get_device - increment reference count for device.

: device.

This simply forwards the call to kobject_get(), though we do take care to provide for the case that we get a NULL pointer passed in.

Definition at line 1008 of file core.c.

static struct kobject* get_device_parent ( struct device *  dev,
struct device *  parent 
) [static, read]

Definition at line 587 of file core.c.

static void klist_children_get ( struct klist_node *  n  )  [static]

Definition at line 514 of file core.c.

static void klist_children_put ( struct klist_node *  n  )  [static]

Definition at line 521 of file core.c.

static struct device* next_device ( struct klist_iter *  i  )  [static, read]

Definition at line 1109 of file core.c.

void put_device ( struct device *  dev  ) 

put_device - decrement reference count.

: device in question.

Definition at line 1017 of file core.c.

static void root_device_release ( struct device *  dev  )  [static]

Definition at line 1222 of file core.c.

void root_device_unregister ( struct device *  dev  ) 

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().

Definition at line 1294 of file core.c.

static void setup_parent ( struct device *  dev,
struct device *  parent 
) [static]

Definition at line 655 of file core.c.

static ssize_t show_dev ( struct device *  dev,
struct device_attribute *  attr,
char *  buf 
) [static]

Definition at line 419 of file core.c.

static ssize_t show_uevent ( struct device *  dev,
struct device_attribute *  attr,
char *  buf 
) [static]

Definition at line 248 of file core.c.

static ssize_t store_uevent ( struct device *  dev,
struct device_attribute *  attr,
const char *  buf,
size_t  count 
) [static]

Definition at line 291 of file core.c.

static struct kobject* virtual_device_parent ( struct device *  dev  )  [static, read]

Definition at line 576 of file core.c.


Variable Documentation

struct kobject* dev_kobj [static]

Definition at line 31 of file core.c.

struct sysfs_ops dev_sysfs_ops [static]

Initial value:

 {
        .show   = dev_attr_show,
        .store  = dev_attr_store,
}

Definition at line 99 of file core.c.

struct kobj_type device_ktype [static]

Initial value:

 {
        .release        = device_release,
        .sysfs_ops      = &dev_sysfs_ops,
}

Definition at line 129 of file core.c.

struct kset_uevent_ops device_uevent_ops [static]

Initial value:

 {
        .filter =       dev_uevent_filter,
        .name =         dev_uevent_name,
        .uevent =       dev_uevent,
}

Definition at line 242 of file core.c.

struct kset* devices_kset

Definition at line 429 of file core.c.

struct device_attribute devt_attr [static]

Initial value:

        __ATTR(dev, S_IRUGO, show_dev, NULL)

Definition at line 425 of file core.c.

int(* platform_notify)(struct device *dev) = NULL

int(* platform_notify_remove)(struct device *dev) = NULL

struct kobject* sysfs_dev_block_kobj

Definition at line 33 of file core.c.

struct kobject* sysfs_dev_char_kobj

Definition at line 32 of file core.c.

struct device_attribute uevent_attr [static]

Initial value:

        __ATTR(uevent, S_IRUGO | S_IWUSR, show_uevent, store_uevent)

Definition at line 308 of file core.c.


Generated on Wed Apr 11 06:39:15 2012 for DDE - The L4 Device Driver Environment by  doxygen 1.5.6