1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 2ba33162aSPaul Gortmaker #include <linux/notifier.h> 3a1bdc7aaSBen Dooks 4c6f7e72aSGreg Kroah-Hartman /** 56b6e39a6SKay Sievers * struct subsys_private - structure to hold the private to the driver core portions of the bus_type/class structure. 6c6f7e72aSGreg Kroah-Hartman * 76b6e39a6SKay Sievers * @subsys - the struct kset that defines this subsystem 8ca22e56dSKay Sievers * @devices_kset - the subsystem's 'devices' directory 9ca22e56dSKay Sievers * @interfaces - list of subsystem interfaces associated 10ca22e56dSKay Sievers * @mutex - protect the devices, and interfaces lists. 116b6e39a6SKay Sievers * 126b6e39a6SKay Sievers * @drivers_kset - the list of drivers associated 13c6f7e72aSGreg Kroah-Hartman * @klist_devices - the klist to iterate over the @devices_kset 14c6f7e72aSGreg Kroah-Hartman * @klist_drivers - the klist to iterate over the @drivers_kset 15c6f7e72aSGreg Kroah-Hartman * @bus_notifier - the bus notifier list for anything that cares about things 16c6f7e72aSGreg Kroah-Hartman * on this bus. 17c6f7e72aSGreg Kroah-Hartman * @bus - pointer back to the struct bus_type that this structure is associated 18c6f7e72aSGreg Kroah-Hartman * with. 19c6f7e72aSGreg Kroah-Hartman * 206b6e39a6SKay Sievers * @glue_dirs - "glue" directory to put in-between the parent device to 216b6e39a6SKay Sievers * avoid namespace conflicts 226b6e39a6SKay Sievers * @class - pointer back to the struct class that this structure is associated 236b6e39a6SKay Sievers * with. 246b6e39a6SKay Sievers * 25c6f7e72aSGreg Kroah-Hartman * This structure is the one that is the actual kobject allowing struct 266b6e39a6SKay Sievers * bus_type/class to be statically allocated safely. Nothing outside of the 276b6e39a6SKay Sievers * driver core should ever touch these fields. 28c6f7e72aSGreg Kroah-Hartman */ 296b6e39a6SKay Sievers struct subsys_private { 30c6f7e72aSGreg Kroah-Hartman struct kset subsys; 31c6f7e72aSGreg Kroah-Hartman struct kset *devices_kset; 32ca22e56dSKay Sievers struct list_head interfaces; 33ca22e56dSKay Sievers struct mutex mutex; 346b6e39a6SKay Sievers 356b6e39a6SKay Sievers struct kset *drivers_kset; 36c6f7e72aSGreg Kroah-Hartman struct klist klist_devices; 37c6f7e72aSGreg Kroah-Hartman struct klist klist_drivers; 38c6f7e72aSGreg Kroah-Hartman struct blocking_notifier_head bus_notifier; 39c6f7e72aSGreg Kroah-Hartman unsigned int drivers_autoprobe:1; 40c6f7e72aSGreg Kroah-Hartman struct bus_type *bus; 416b6e39a6SKay Sievers 426b6e39a6SKay Sievers struct kset glue_dirs; 436b6e39a6SKay Sievers struct class *class; 44c6f7e72aSGreg Kroah-Hartman }; 456b6e39a6SKay Sievers #define to_subsys_private(obj) container_of(obj, struct subsys_private, subsys.kobj) 46a1bdc7aaSBen Dooks 47e5dd1278SGreg Kroah-Hartman struct driver_private { 48e5dd1278SGreg Kroah-Hartman struct kobject kobj; 49e5dd1278SGreg Kroah-Hartman struct klist klist_devices; 50e5dd1278SGreg Kroah-Hartman struct klist_node knode_bus; 51e5dd1278SGreg Kroah-Hartman struct module_kobject *mkobj; 52e5dd1278SGreg Kroah-Hartman struct device_driver *driver; 53e5dd1278SGreg Kroah-Hartman }; 54e5dd1278SGreg Kroah-Hartman #define to_driver(obj) container_of(obj, struct driver_private, kobj) 55c6f7e72aSGreg Kroah-Hartman 56fb069a5dSGreg Kroah-Hartman /** 57fb069a5dSGreg Kroah-Hartman * struct device_private - structure to hold the private to the driver core portions of the device structure. 58fb069a5dSGreg Kroah-Hartman * 59f791b8c8SGreg Kroah-Hartman * @klist_children - klist containing all children of this device 60f791b8c8SGreg Kroah-Hartman * @knode_parent - node in sibling list 618940b4f3SGreg Kroah-Hartman * @knode_driver - node in driver list 62ae1b4171SGreg Kroah-Hartman * @knode_bus - node in bus list 63570d0200SWei Yang * @knode_class - node in class list 64ef8a3fd6SGreg Kroah-Hartman * @deferred_probe - entry in deferred_probe_list which is used to retry the 65ef8a3fd6SGreg Kroah-Hartman * binding of drivers which were unable to get all the resources needed by 66ef8a3fd6SGreg Kroah-Hartman * the device; typically because it depends on another driver getting 67ef8a3fd6SGreg Kroah-Hartman * probed first. 6882b2c3c5STomeu Vizoso * @device - pointer back to the struct device that this structure is 69fb069a5dSGreg Kroah-Hartman * associated with. 703451a495SAlexander Duyck * @dead - This device is currently either in the process of or has been 713451a495SAlexander Duyck * removed from the system. Any asynchronous events scheduled for this 723451a495SAlexander Duyck * device should exit without taking any action. 73fb069a5dSGreg Kroah-Hartman * 74fb069a5dSGreg Kroah-Hartman * Nothing outside of the driver core should ever touch these fields. 75fb069a5dSGreg Kroah-Hartman */ 76fb069a5dSGreg Kroah-Hartman struct device_private { 77f791b8c8SGreg Kroah-Hartman struct klist klist_children; 78f791b8c8SGreg Kroah-Hartman struct klist_node knode_parent; 798940b4f3SGreg Kroah-Hartman struct klist_node knode_driver; 80ae1b4171SGreg Kroah-Hartman struct klist_node knode_bus; 81570d0200SWei Yang struct klist_node knode_class; 82ef8a3fd6SGreg Kroah-Hartman struct list_head deferred_probe; 83fb069a5dSGreg Kroah-Hartman struct device *device; 843451a495SAlexander Duyck u8 dead:1; 85fb069a5dSGreg Kroah-Hartman }; 86f791b8c8SGreg Kroah-Hartman #define to_device_private_parent(obj) \ 87f791b8c8SGreg Kroah-Hartman container_of(obj, struct device_private, knode_parent) 888940b4f3SGreg Kroah-Hartman #define to_device_private_driver(obj) \ 898940b4f3SGreg Kroah-Hartman container_of(obj, struct device_private, knode_driver) 90ae1b4171SGreg Kroah-Hartman #define to_device_private_bus(obj) \ 91ae1b4171SGreg Kroah-Hartman container_of(obj, struct device_private, knode_bus) 92570d0200SWei Yang #define to_device_private_class(obj) \ 93570d0200SWei Yang container_of(obj, struct device_private, knode_class) 94fb069a5dSGreg Kroah-Hartman 95c6f7e72aSGreg Kroah-Hartman /* initialisation functions */ 96a1bdc7aaSBen Dooks extern int devices_init(void); 97a1bdc7aaSBen Dooks extern int buses_init(void); 98a1bdc7aaSBen Dooks extern int classes_init(void); 99a1bdc7aaSBen Dooks extern int firmware_init(void); 1004039483fSMichael Holzheu #ifdef CONFIG_SYS_HYPERVISOR 1014039483fSMichael Holzheu extern int hypervisor_init(void); 1024039483fSMichael Holzheu #else 1034039483fSMichael Holzheu static inline int hypervisor_init(void) { return 0; } 1044039483fSMichael Holzheu #endif 105a1bdc7aaSBen Dooks extern int platform_bus_init(void); 106024f7846SBen Hutchings extern void cpu_dev_init(void); 107caa73ea1SRafael J. Wysocki extern void container_dev_init(void); 108a1bdc7aaSBen Dooks 109d73ce004STejun Heo struct kobject *virtual_device_parent(struct device *dev); 110d73ce004STejun Heo 1111da177e4SLinus Torvalds extern int bus_add_device(struct device *dev); 1122023c610SAlan Stern extern void bus_probe_device(struct device *dev); 1131da177e4SLinus Torvalds extern void bus_remove_device(struct device *dev); 1141da177e4SLinus Torvalds 1154a3ad20cSGreg Kroah-Hartman extern int bus_add_driver(struct device_driver *drv); 1164a3ad20cSGreg Kroah-Hartman extern void bus_remove_driver(struct device_driver *drv); 1179ed98953SRafael J. Wysocki extern void device_release_driver_internal(struct device *dev, 1189ed98953SRafael J. Wysocki struct device_driver *drv, 1199ed98953SRafael J. Wysocki struct device *parent); 1201da177e4SLinus Torvalds 12107e4a3e2Smochel@digitalimplant.org extern void driver_detach(struct device_driver *drv); 1224a3ad20cSGreg Kroah-Hartman extern int driver_probe_device(struct device_driver *drv, struct device *dev); 123d1c3414cSGrant Likely extern void driver_deferred_probe_del(struct device *dev); 12449b420a1SMing Lei static inline int driver_match_device(struct device_driver *drv, 12549b420a1SMing Lei struct device *dev) 12649b420a1SMing Lei { 1275247aecfSMing Lei return drv->bus->match ? drv->bus->match(dev, drv) : 1; 12849b420a1SMing Lei } 129765230b5SDmitry Torokhov extern bool driver_allows_async_probing(struct device_driver *drv); 13007e4a3e2Smochel@digitalimplant.org 131ed0617b5SGreg Kroah-Hartman extern int driver_add_groups(struct device_driver *drv, 132ed0617b5SGreg Kroah-Hartman const struct attribute_group **groups); 133ed0617b5SGreg Kroah-Hartman extern void driver_remove_groups(struct device_driver *drv, 134ed0617b5SGreg Kroah-Hartman const struct attribute_group **groups); 135ed0617b5SGreg Kroah-Hartman 136aa49b913SGreg Kroah-Hartman extern char *make_class_name(const char *name, struct kobject *kobj); 1371da177e4SLinus Torvalds 1382a013455SAdrian Bunk extern int devres_release_all(struct device *dev); 139013c074fSStrashko, Grygorii extern void device_block_probing(void); 140013c074fSStrashko, Grygorii extern void device_unblock_probing(void); 141823bccfcSGreg Kroah-Hartman 142ca22e56dSKay Sievers /* /sys/devices directory */ 143881c6cfdSGreg Kroah-Hartman extern struct kset *devices_kset; 14452cdbdd4SGrygorii Strashko extern void devices_kset_move_last(struct device *dev); 145c63469a3SGreg Kroah-Hartman 14692b42141SRandy Dunlap #if defined(CONFIG_MODULES) && defined(CONFIG_SYSFS) 147c63469a3SGreg Kroah-Hartman extern void module_add_driver(struct module *mod, struct device_driver *drv); 148c63469a3SGreg Kroah-Hartman extern void module_remove_driver(struct device_driver *drv); 149c63469a3SGreg Kroah-Hartman #else 150c63469a3SGreg Kroah-Hartman static inline void module_add_driver(struct module *mod, 151c63469a3SGreg Kroah-Hartman struct device_driver *drv) { } 152c63469a3SGreg Kroah-Hartman static inline void module_remove_driver(struct device_driver *drv) { } 153c63469a3SGreg Kroah-Hartman #endif 1542b2af54aSKay Sievers 1552b2af54aSKay Sievers #ifdef CONFIG_DEVTMPFS 1562b2af54aSKay Sievers extern int devtmpfs_init(void); 1572b2af54aSKay Sievers #else 1582b2af54aSKay Sievers static inline int devtmpfs_init(void) { return 0; } 1592b2af54aSKay Sievers #endif 1609ed98953SRafael J. Wysocki 1619ed98953SRafael J. Wysocki /* Device links support */ 1629ed98953SRafael J. Wysocki extern int device_links_read_lock(void); 1639ed98953SRafael J. Wysocki extern void device_links_read_unlock(int idx); 1649ed98953SRafael J. Wysocki extern int device_links_check_suppliers(struct device *dev); 1659ed98953SRafael J. Wysocki extern void device_links_driver_bound(struct device *dev); 1669ed98953SRafael J. Wysocki extern void device_links_driver_cleanup(struct device *dev); 1679ed98953SRafael J. Wysocki extern void device_links_no_driver(struct device *dev); 1689ed98953SRafael J. Wysocki extern bool device_links_busy(struct device *dev); 1699ed98953SRafael J. Wysocki extern void device_links_unbind_consumers(struct device *dev); 170494fd7b7SFeng Kan 171494fd7b7SFeng Kan /* device pm support */ 172494fd7b7SFeng Kan void device_pm_move_to_tail(struct device *dev); 173