base.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2001-2003 Patrick Mochel <[email protected]>
  4. * Copyright (c) 2004-2009 Greg Kroah-Hartman <[email protected]>
  5. * Copyright (c) 2008-2012 Novell Inc.
  6. * Copyright (c) 2012-2019 Greg Kroah-Hartman <[email protected]>
  7. * Copyright (c) 2012-2019 Linux Foundation
  8. *
  9. * Core driver model functions and structures that should not be
  10. * shared outside of the drivers/base/ directory.
  11. *
  12. */
  13. #include <linux/notifier.h>
  14. /**
  15. * struct subsys_private - structure to hold the private to the driver core portions of the bus_type/class structure.
  16. *
  17. * @subsys - the struct kset that defines this subsystem
  18. * @devices_kset - the subsystem's 'devices' directory
  19. * @interfaces - list of subsystem interfaces associated
  20. * @mutex - protect the devices, and interfaces lists.
  21. *
  22. * @drivers_kset - the list of drivers associated
  23. * @klist_devices - the klist to iterate over the @devices_kset
  24. * @klist_drivers - the klist to iterate over the @drivers_kset
  25. * @bus_notifier - the bus notifier list for anything that cares about things
  26. * on this bus.
  27. * @bus - pointer back to the struct bus_type that this structure is associated
  28. * with.
  29. *
  30. * @glue_dirs - "glue" directory to put in-between the parent device to
  31. * avoid namespace conflicts
  32. * @class - pointer back to the struct class that this structure is associated
  33. * with.
  34. *
  35. * This structure is the one that is the actual kobject allowing struct
  36. * bus_type/class to be statically allocated safely. Nothing outside of the
  37. * driver core should ever touch these fields.
  38. */
  39. struct subsys_private {
  40. struct kset subsys;
  41. struct kset *devices_kset;
  42. struct list_head interfaces;
  43. struct mutex mutex;
  44. struct kset *drivers_kset;
  45. struct klist klist_devices;
  46. struct klist klist_drivers;
  47. struct blocking_notifier_head bus_notifier;
  48. unsigned int drivers_autoprobe:1;
  49. struct bus_type *bus;
  50. struct kset glue_dirs;
  51. struct class *class;
  52. };
  53. #define to_subsys_private(obj) container_of(obj, struct subsys_private, subsys.kobj)
  54. struct driver_private {
  55. struct kobject kobj;
  56. struct klist klist_devices;
  57. struct klist_node knode_bus;
  58. struct module_kobject *mkobj;
  59. struct device_driver *driver;
  60. };
  61. #define to_driver(obj) container_of(obj, struct driver_private, kobj)
  62. /**
  63. * struct device_private - structure to hold the private to the driver core portions of the device structure.
  64. *
  65. * @klist_children - klist containing all children of this device
  66. * @knode_parent - node in sibling list
  67. * @knode_driver - node in driver list
  68. * @knode_bus - node in bus list
  69. * @knode_class - node in class list
  70. * @deferred_probe - entry in deferred_probe_list which is used to retry the
  71. * binding of drivers which were unable to get all the resources needed by
  72. * the device; typically because it depends on another driver getting
  73. * probed first.
  74. * @async_driver - pointer to device driver awaiting probe via async_probe
  75. * @device - pointer back to the struct device that this structure is
  76. * associated with.
  77. * @dead - This device is currently either in the process of or has been
  78. * removed from the system. Any asynchronous events scheduled for this
  79. * device should exit without taking any action.
  80. *
  81. * Nothing outside of the driver core should ever touch these fields.
  82. */
  83. struct device_private {
  84. struct klist klist_children;
  85. struct klist_node knode_parent;
  86. struct klist_node knode_driver;
  87. struct klist_node knode_bus;
  88. struct klist_node knode_class;
  89. struct list_head deferred_probe;
  90. struct device_driver *async_driver;
  91. char *deferred_probe_reason;
  92. struct device *device;
  93. u8 dead:1;
  94. };
  95. #define to_device_private_parent(obj) \
  96. container_of(obj, struct device_private, knode_parent)
  97. #define to_device_private_driver(obj) \
  98. container_of(obj, struct device_private, knode_driver)
  99. #define to_device_private_bus(obj) \
  100. container_of(obj, struct device_private, knode_bus)
  101. #define to_device_private_class(obj) \
  102. container_of(obj, struct device_private, knode_class)
  103. /* initialisation functions */
  104. extern int devices_init(void);
  105. extern int buses_init(void);
  106. extern int classes_init(void);
  107. extern int firmware_init(void);
  108. #ifdef CONFIG_SYS_HYPERVISOR
  109. extern int hypervisor_init(void);
  110. #else
  111. static inline int hypervisor_init(void) { return 0; }
  112. #endif
  113. extern int platform_bus_init(void);
  114. extern void cpu_dev_init(void);
  115. extern void container_dev_init(void);
  116. #ifdef CONFIG_AUXILIARY_BUS
  117. extern void auxiliary_bus_init(void);
  118. #else
  119. static inline void auxiliary_bus_init(void) { }
  120. #endif
  121. struct kobject *virtual_device_parent(struct device *dev);
  122. extern int bus_add_device(struct device *dev);
  123. extern void bus_probe_device(struct device *dev);
  124. extern void bus_remove_device(struct device *dev);
  125. extern int bus_add_driver(struct device_driver *drv);
  126. extern void bus_remove_driver(struct device_driver *drv);
  127. extern void device_release_driver_internal(struct device *dev,
  128. struct device_driver *drv,
  129. struct device *parent);
  130. extern void driver_detach(struct device_driver *drv);
  131. extern void driver_deferred_probe_del(struct device *dev);
  132. extern void device_set_deferred_probe_reason(const struct device *dev,
  133. struct va_format *vaf);
  134. static inline int driver_match_device(struct device_driver *drv,
  135. struct device *dev)
  136. {
  137. return drv->bus->match ? drv->bus->match(dev, drv) : 1;
  138. }
  139. extern bool driver_allows_async_probing(struct device_driver *drv);
  140. extern int driver_add_groups(struct device_driver *drv,
  141. const struct attribute_group **groups);
  142. extern void driver_remove_groups(struct device_driver *drv,
  143. const struct attribute_group **groups);
  144. void device_driver_detach(struct device *dev);
  145. extern int devres_release_all(struct device *dev);
  146. extern void device_block_probing(void);
  147. extern void device_unblock_probing(void);
  148. extern void deferred_probe_extend_timeout(void);
  149. extern void driver_deferred_probe_trigger(void);
  150. /* /sys/devices directory */
  151. extern struct kset *devices_kset;
  152. extern void devices_kset_move_last(struct device *dev);
  153. #if defined(CONFIG_MODULES) && defined(CONFIG_SYSFS)
  154. extern void module_add_driver(struct module *mod, struct device_driver *drv);
  155. extern void module_remove_driver(struct device_driver *drv);
  156. #else
  157. static inline void module_add_driver(struct module *mod,
  158. struct device_driver *drv) { }
  159. static inline void module_remove_driver(struct device_driver *drv) { }
  160. #endif
  161. #ifdef CONFIG_DEVTMPFS
  162. extern int devtmpfs_init(void);
  163. #else
  164. static inline int devtmpfs_init(void) { return 0; }
  165. #endif
  166. /* Device links support */
  167. extern int device_links_read_lock(void);
  168. extern void device_links_read_unlock(int idx);
  169. extern int device_links_read_lock_held(void);
  170. extern int device_links_check_suppliers(struct device *dev);
  171. extern void device_links_force_bind(struct device *dev);
  172. extern void device_links_driver_bound(struct device *dev);
  173. extern void device_links_driver_cleanup(struct device *dev);
  174. extern void device_links_no_driver(struct device *dev);
  175. extern bool device_links_busy(struct device *dev);
  176. extern void device_links_unbind_consumers(struct device *dev);
  177. extern void fw_devlink_drivers_done(void);
  178. extern void fw_devlink_probing_done(void);
  179. /* device pm support */
  180. void device_pm_move_to_tail(struct device *dev);
  181. #ifdef CONFIG_DEVTMPFS
  182. int devtmpfs_create_node(struct device *dev);
  183. int devtmpfs_delete_node(struct device *dev);
  184. #else
  185. static inline int devtmpfs_create_node(struct device *dev) { return 0; }
  186. static inline int devtmpfs_delete_node(struct device *dev) { return 0; }
  187. #endif
  188. void software_node_notify(struct device *dev);
  189. void software_node_notify_remove(struct device *dev);