base.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. * @driver_data - private pointer for driver specific info. Will turn into a
  62. * list soon.
  63. * @device - pointer back to the struct class that this structure is
  64. * associated with.
  65. *
  66. * Nothing outside of the driver core should ever touch these fields.
  67. */
  68. struct device_private {
  69. struct klist klist_children;
  70. struct klist_node knode_parent;
  71. struct klist_node knode_driver;
  72. struct klist_node knode_bus;
  73. struct list_head deferred_probe;
  74. void *driver_data;
  75. struct device *device;
  76. };
  77. #define to_device_private_parent(obj) \
  78. container_of(obj, struct device_private, knode_parent)
  79. #define to_device_private_driver(obj) \
  80. container_of(obj, struct device_private, knode_driver)
  81. #define to_device_private_bus(obj) \
  82. container_of(obj, struct device_private, knode_bus)
  83. extern int device_private_init(struct device *dev);
  84. /* initialisation functions */
  85. extern int devices_init(void);
  86. extern int buses_init(void);
  87. extern int classes_init(void);
  88. extern int firmware_init(void);
  89. #ifdef CONFIG_SYS_HYPERVISOR
  90. extern int hypervisor_init(void);
  91. #else
  92. static inline int hypervisor_init(void) { return 0; }
  93. #endif
  94. extern int platform_bus_init(void);
  95. extern int system_bus_init(void);
  96. extern void cpu_dev_init(void);
  97. extern int bus_add_device(struct device *dev);
  98. extern void bus_probe_device(struct device *dev);
  99. extern void bus_remove_device(struct device *dev);
  100. extern int bus_add_driver(struct device_driver *drv);
  101. extern void bus_remove_driver(struct device_driver *drv);
  102. extern void driver_detach(struct device_driver *drv);
  103. extern int driver_probe_device(struct device_driver *drv, struct device *dev);
  104. extern void driver_deferred_probe_del(struct device *dev);
  105. static inline int driver_match_device(struct device_driver *drv,
  106. struct device *dev)
  107. {
  108. return drv->bus->match ? drv->bus->match(dev, drv) : 1;
  109. }
  110. extern char *make_class_name(const char *name, struct kobject *kobj);
  111. extern int devres_release_all(struct device *dev);
  112. /* /sys/devices directory */
  113. extern struct kset *devices_kset;
  114. #if defined(CONFIG_MODULES) && defined(CONFIG_SYSFS)
  115. extern void module_add_driver(struct module *mod, struct device_driver *drv);
  116. extern void module_remove_driver(struct device_driver *drv);
  117. #else
  118. static inline void module_add_driver(struct module *mod,
  119. struct device_driver *drv) { }
  120. static inline void module_remove_driver(struct device_driver *drv) { }
  121. #endif
  122. #ifdef CONFIG_DEVTMPFS
  123. extern int devtmpfs_init(void);
  124. #else
  125. static inline int devtmpfs_init(void) { return 0; }
  126. #endif