base.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**
  2. * struct subsys_private - structure to hold the private to the driver core portions of the bus_type/class structure.
  3. *
  4. * @subsys - the struct kset that defines this subsystem
  5. * @devices_kset - the list of devices associated
  6. *
  7. * @drivers_kset - the list of drivers associated
  8. * @klist_devices - the klist to iterate over the @devices_kset
  9. * @klist_drivers - the klist to iterate over the @drivers_kset
  10. * @bus_notifier - the bus notifier list for anything that cares about things
  11. * on this bus.
  12. * @bus - pointer back to the struct bus_type that this structure is associated
  13. * with.
  14. *
  15. * @class_interfaces - list of class_interfaces associated
  16. * @glue_dirs - "glue" directory to put in-between the parent device to
  17. * avoid namespace conflicts
  18. * @class_mutex - mutex to protect the children, devices, and interfaces lists.
  19. * @class - pointer back to the struct class that this structure is associated
  20. * with.
  21. *
  22. * This structure is the one that is the actual kobject allowing struct
  23. * bus_type/class to be statically allocated safely. Nothing outside of the
  24. * driver core should ever touch these fields.
  25. */
  26. struct subsys_private {
  27. struct kset subsys;
  28. struct kset *devices_kset;
  29. struct kset *drivers_kset;
  30. struct klist klist_devices;
  31. struct klist klist_drivers;
  32. struct blocking_notifier_head bus_notifier;
  33. unsigned int drivers_autoprobe:1;
  34. struct bus_type *bus;
  35. struct list_head class_interfaces;
  36. struct kset glue_dirs;
  37. struct mutex class_mutex;
  38. struct class *class;
  39. };
  40. #define to_subsys_private(obj) container_of(obj, struct subsys_private, subsys.kobj)
  41. struct driver_private {
  42. struct kobject kobj;
  43. struct klist klist_devices;
  44. struct klist_node knode_bus;
  45. struct module_kobject *mkobj;
  46. struct device_driver *driver;
  47. };
  48. #define to_driver(obj) container_of(obj, struct driver_private, kobj)
  49. /**
  50. * struct device_private - structure to hold the private to the driver core portions of the device structure.
  51. *
  52. * @klist_children - klist containing all children of this device
  53. * @knode_parent - node in sibling list
  54. * @knode_driver - node in driver list
  55. * @knode_bus - node in bus list
  56. * @driver_data - private pointer for driver specific info. Will turn into a
  57. * list soon.
  58. * @device - pointer back to the struct class that this structure is
  59. * associated with.
  60. *
  61. * Nothing outside of the driver core should ever touch these fields.
  62. */
  63. struct device_private {
  64. struct klist klist_children;
  65. struct klist_node knode_parent;
  66. struct klist_node knode_driver;
  67. struct klist_node knode_bus;
  68. void *driver_data;
  69. struct device *device;
  70. };
  71. #define to_device_private_parent(obj) \
  72. container_of(obj, struct device_private, knode_parent)
  73. #define to_device_private_driver(obj) \
  74. container_of(obj, struct device_private, knode_driver)
  75. #define to_device_private_bus(obj) \
  76. container_of(obj, struct device_private, knode_bus)
  77. extern int device_private_init(struct device *dev);
  78. /* initialisation functions */
  79. extern int devices_init(void);
  80. extern int buses_init(void);
  81. extern int classes_init(void);
  82. extern int firmware_init(void);
  83. #ifdef CONFIG_SYS_HYPERVISOR
  84. extern int hypervisor_init(void);
  85. #else
  86. static inline int hypervisor_init(void) { return 0; }
  87. #endif
  88. extern int platform_bus_init(void);
  89. extern int system_bus_init(void);
  90. extern int cpu_dev_init(void);
  91. extern int bus_add_device(struct device *dev);
  92. extern void bus_probe_device(struct device *dev);
  93. extern void bus_remove_device(struct device *dev);
  94. extern int bus_add_driver(struct device_driver *drv);
  95. extern void bus_remove_driver(struct device_driver *drv);
  96. extern void driver_detach(struct device_driver *drv);
  97. extern int driver_probe_device(struct device_driver *drv, struct device *dev);
  98. static inline int driver_match_device(struct device_driver *drv,
  99. struct device *dev)
  100. {
  101. return drv->bus->match ? drv->bus->match(dev, drv) : 1;
  102. }
  103. extern char *make_class_name(const char *name, struct kobject *kobj);
  104. extern int devres_release_all(struct device *dev);
  105. extern struct kset *devices_kset;
  106. #if defined(CONFIG_MODULES) && defined(CONFIG_SYSFS)
  107. extern void module_add_driver(struct module *mod, struct device_driver *drv);
  108. extern void module_remove_driver(struct device_driver *drv);
  109. #else
  110. static inline void module_add_driver(struct module *mod,
  111. struct device_driver *drv) { }
  112. static inline void module_remove_driver(struct device_driver *drv) { }
  113. #endif
  114. #ifdef CONFIG_DEVTMPFS
  115. extern int devtmpfs_init(void);
  116. #else
  117. static inline int devtmpfs_init(void) { return 0; }
  118. #endif