base.h 5.3 KB

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