http://blog.chinaunix.net/uid-20672257-id-3146976.html
- struct device {
- struct klist klist_children;
- struct klist_node knode_parent; /* node in sibling list */
- struct klist_node knode_driver;
- struct klist_node knode_bus;
- struct device *parent;
- struct kobject kobj;
- char bus_id[BUS_ID_SIZE]; /* 在總線上唯一標識該設備的字符串position on parent bus */
- unsigned uevent_suppress:1;
- const char *init_name; /* initial name of the device */
- struct device_type *type;
- struct semaphore sem; /* semaphore to synchronize calls to
- * its driver.
- */
- struct bus_type *bus; /*設備所在總線 type of bus device is on */
- struct device_driver *driver; /* 管理該設備的驅動which driver has allocated this
- device */
- void *driver_data; /* 該設備驅動使用的私有數據成員data private to the driver */
- void *platform_data; /* Platform specific data, device
- core doesn't touch it */
- struct dev_pm_info power;
- #ifdef CONFIG_NUMA
- int numa_node; /* NUMA node this device is close to */
- #endif
- u64 *dma_mask; /* dma mask (if dma'able device) */
- u64 coherent_dma_mask;/* Like dma_mask, but for
- alloc_coherent mappings as
- not all hardware supports
- 64 bit addresses for consistent
- allocations such descriptors. */
- struct device_dma_parameters *dma_parms;
- struct list_head dma_pools; /* dma pools (if dma'ble) */
- struct dma_coherent_mem *dma_mem; /* internal for coherent mem
- override */
- /* arch specific additions */
- struct dev_archdata archdata;
- dev_t devt; /* dev_t, creates the sysfs "dev" */
- spinlock_t devres_lock;
- struct list_head devres_head;
- struct klist_node knode_class;
- struct class *class;
- struct attribute_group **groups; /* optional groups */
- void (*release)(struct device *dev);
- };
- struct device_private {
- struct klist klist_children;
- struct klist_node knode_parent;
- struct klist_node knode_driver;
- struct klist_node knode_bus;
- struct device *device;
-
};
設備屬性由device_attribute描述 - struct device_attribute {
- struct attribute attr;
- ssize_t (*show)(struct device *dev, struct device_attribute *attr,
- char *buf);
- ssize_t (*store)(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t count);
- };
註冊一個設備
int device_register(struct device *dev)
刪除一個設備
void device_unregister(struct device *dev)
注意:一條總線本身也是一個設備,也必須按設備註冊,見上篇Linux設備模型--總線
添加設備例子,添加到前面創建的my_bus總線上: