1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 25367601bSGreg Kroah-Hartman /* 35367601bSGreg Kroah-Hartman * Copyright (c) 2001-2003 Patrick Mochel <mochel@osdl.org> 45367601bSGreg Kroah-Hartman * Copyright (c) 2004-2009 Greg Kroah-Hartman <gregkh@suse.de> 55367601bSGreg Kroah-Hartman * Copyright (c) 2008-2012 Novell Inc. 65367601bSGreg Kroah-Hartman * Copyright (c) 2012-2019 Greg Kroah-Hartman <gregkh@linuxfoundation.org> 75367601bSGreg Kroah-Hartman * Copyright (c) 2012-2019 Linux Foundation 85367601bSGreg Kroah-Hartman * 95367601bSGreg Kroah-Hartman * Core driver model functions and structures that should not be 105367601bSGreg Kroah-Hartman * shared outside of the drivers/base/ directory. 115367601bSGreg Kroah-Hartman * 125367601bSGreg Kroah-Hartman */ 13ba33162aSPaul Gortmaker #include <linux/notifier.h> 14a1bdc7aaSBen Dooks 15c6f7e72aSGreg Kroah-Hartman /** 166b6e39a6SKay Sievers * struct subsys_private - structure to hold the private to the driver core portions of the bus_type/class structure. 17c6f7e72aSGreg Kroah-Hartman * 186b6e39a6SKay Sievers * @subsys - the struct kset that defines this subsystem 19ca22e56dSKay Sievers * @devices_kset - the subsystem's 'devices' directory 20ca22e56dSKay Sievers * @interfaces - list of subsystem interfaces associated 21ca22e56dSKay Sievers * @mutex - protect the devices, and interfaces lists. 226b6e39a6SKay Sievers * 236b6e39a6SKay Sievers * @drivers_kset - the list of drivers associated 24c6f7e72aSGreg Kroah-Hartman * @klist_devices - the klist to iterate over the @devices_kset 25c6f7e72aSGreg Kroah-Hartman * @klist_drivers - the klist to iterate over the @drivers_kset 26c6f7e72aSGreg Kroah-Hartman * @bus_notifier - the bus notifier list for anything that cares about things 27c6f7e72aSGreg Kroah-Hartman * on this bus. 28c6f7e72aSGreg Kroah-Hartman * @bus - pointer back to the struct bus_type that this structure is associated 29c6f7e72aSGreg Kroah-Hartman * with. 30c6f7e72aSGreg Kroah-Hartman * 316b6e39a6SKay Sievers * @glue_dirs - "glue" directory to put in-between the parent device to 326b6e39a6SKay Sievers * avoid namespace conflicts 336b6e39a6SKay Sievers * @class - pointer back to the struct class that this structure is associated 346b6e39a6SKay Sievers * with. 356b6e39a6SKay Sievers * 36c6f7e72aSGreg Kroah-Hartman * This structure is the one that is the actual kobject allowing struct 376b6e39a6SKay Sievers * bus_type/class to be statically allocated safely. Nothing outside of the 386b6e39a6SKay Sievers * driver core should ever touch these fields. 39c6f7e72aSGreg Kroah-Hartman */ 406b6e39a6SKay Sievers struct subsys_private { 41c6f7e72aSGreg Kroah-Hartman struct kset subsys; 42c6f7e72aSGreg Kroah-Hartman struct kset *devices_kset; 43ca22e56dSKay Sievers struct list_head interfaces; 44ca22e56dSKay Sievers struct mutex mutex; 456b6e39a6SKay Sievers 466b6e39a6SKay Sievers struct kset *drivers_kset; 47c6f7e72aSGreg Kroah-Hartman struct klist klist_devices; 48c6f7e72aSGreg Kroah-Hartman struct klist klist_drivers; 49c6f7e72aSGreg Kroah-Hartman struct blocking_notifier_head bus_notifier; 50c6f7e72aSGreg Kroah-Hartman unsigned int drivers_autoprobe:1; 51c6f7e72aSGreg Kroah-Hartman struct bus_type *bus; 526b6e39a6SKay Sievers 536b6e39a6SKay Sievers struct kset glue_dirs; 546b6e39a6SKay Sievers struct class *class; 55c6f7e72aSGreg Kroah-Hartman }; 567bbb89b4SGreg Kroah-Hartman #define to_subsys_private(obj) container_of_const(obj, struct subsys_private, subsys.kobj) 57a1bdc7aaSBen Dooks 58e5dd1278SGreg Kroah-Hartman struct driver_private { 59e5dd1278SGreg Kroah-Hartman struct kobject kobj; 60e5dd1278SGreg Kroah-Hartman struct klist klist_devices; 61e5dd1278SGreg Kroah-Hartman struct klist_node knode_bus; 62e5dd1278SGreg Kroah-Hartman struct module_kobject *mkobj; 63e5dd1278SGreg Kroah-Hartman struct device_driver *driver; 64e5dd1278SGreg Kroah-Hartman }; 65e5dd1278SGreg Kroah-Hartman #define to_driver(obj) container_of(obj, struct driver_private, kobj) 66c6f7e72aSGreg Kroah-Hartman 67fb069a5dSGreg Kroah-Hartman /** 68fb069a5dSGreg Kroah-Hartman * struct device_private - structure to hold the private to the driver core portions of the device structure. 69fb069a5dSGreg Kroah-Hartman * 70f791b8c8SGreg Kroah-Hartman * @klist_children - klist containing all children of this device 71f791b8c8SGreg Kroah-Hartman * @knode_parent - node in sibling list 728940b4f3SGreg Kroah-Hartman * @knode_driver - node in driver list 73ae1b4171SGreg Kroah-Hartman * @knode_bus - node in bus list 74570d0200SWei Yang * @knode_class - node in class list 75ef8a3fd6SGreg Kroah-Hartman * @deferred_probe - entry in deferred_probe_list which is used to retry the 76ef8a3fd6SGreg Kroah-Hartman * binding of drivers which were unable to get all the resources needed by 77ef8a3fd6SGreg Kroah-Hartman * the device; typically because it depends on another driver getting 78ef8a3fd6SGreg Kroah-Hartman * probed first. 79ef0ff683SAlexander Duyck * @async_driver - pointer to device driver awaiting probe via async_probe 8082b2c3c5STomeu Vizoso * @device - pointer back to the struct device that this structure is 81fb069a5dSGreg Kroah-Hartman * associated with. 823451a495SAlexander Duyck * @dead - This device is currently either in the process of or has been 833451a495SAlexander Duyck * removed from the system. Any asynchronous events scheduled for this 843451a495SAlexander Duyck * device should exit without taking any action. 85fb069a5dSGreg Kroah-Hartman * 86fb069a5dSGreg Kroah-Hartman * Nothing outside of the driver core should ever touch these fields. 87fb069a5dSGreg Kroah-Hartman */ 88fb069a5dSGreg Kroah-Hartman struct device_private { 89f791b8c8SGreg Kroah-Hartman struct klist klist_children; 90f791b8c8SGreg Kroah-Hartman struct klist_node knode_parent; 918940b4f3SGreg Kroah-Hartman struct klist_node knode_driver; 92ae1b4171SGreg Kroah-Hartman struct klist_node knode_bus; 93570d0200SWei Yang struct klist_node knode_class; 94ef8a3fd6SGreg Kroah-Hartman struct list_head deferred_probe; 95ef0ff683SAlexander Duyck struct device_driver *async_driver; 96d090b70eSAndrzej Hajda char *deferred_probe_reason; 97fb069a5dSGreg Kroah-Hartman struct device *device; 983451a495SAlexander Duyck u8 dead:1; 99fb069a5dSGreg Kroah-Hartman }; 100f791b8c8SGreg Kroah-Hartman #define to_device_private_parent(obj) \ 101f791b8c8SGreg Kroah-Hartman container_of(obj, struct device_private, knode_parent) 1028940b4f3SGreg Kroah-Hartman #define to_device_private_driver(obj) \ 1038940b4f3SGreg Kroah-Hartman container_of(obj, struct device_private, knode_driver) 104ae1b4171SGreg Kroah-Hartman #define to_device_private_bus(obj) \ 105ae1b4171SGreg Kroah-Hartman container_of(obj, struct device_private, knode_bus) 106570d0200SWei Yang #define to_device_private_class(obj) \ 107570d0200SWei Yang container_of(obj, struct device_private, knode_class) 108fb069a5dSGreg Kroah-Hartman 109c6f7e72aSGreg Kroah-Hartman /* initialisation functions */ 110a1bdc7aaSBen Dooks extern int devices_init(void); 111a1bdc7aaSBen Dooks extern int buses_init(void); 112a1bdc7aaSBen Dooks extern int classes_init(void); 113a1bdc7aaSBen Dooks extern int firmware_init(void); 1144039483fSMichael Holzheu #ifdef CONFIG_SYS_HYPERVISOR 1154039483fSMichael Holzheu extern int hypervisor_init(void); 1164039483fSMichael Holzheu #else 1174039483fSMichael Holzheu static inline int hypervisor_init(void) { return 0; } 1184039483fSMichael Holzheu #endif 119a1bdc7aaSBen Dooks extern int platform_bus_init(void); 120024f7846SBen Hutchings extern void cpu_dev_init(void); 121caa73ea1SRafael J. Wysocki extern void container_dev_init(void); 122471b12c4SDave Jiang #ifdef CONFIG_AUXILIARY_BUS 123471b12c4SDave Jiang extern void auxiliary_bus_init(void); 124471b12c4SDave Jiang #else 125471b12c4SDave Jiang static inline void auxiliary_bus_init(void) { } 126471b12c4SDave Jiang #endif 127a1bdc7aaSBen Dooks 128d73ce004STejun Heo struct kobject *virtual_device_parent(struct device *dev); 129d73ce004STejun Heo 1301da177e4SLinus Torvalds extern int bus_add_device(struct device *dev); 1312023c610SAlan Stern extern void bus_probe_device(struct device *dev); 1321da177e4SLinus Torvalds extern void bus_remove_device(struct device *dev); 133ed9f9181SGreg Kroah-Hartman void bus_notify(struct device *dev, enum bus_notifier_event value); 1341da177e4SLinus Torvalds 1354a3ad20cSGreg Kroah-Hartman extern int bus_add_driver(struct device_driver *drv); 1364a3ad20cSGreg Kroah-Hartman extern void bus_remove_driver(struct device_driver *drv); 1379ed98953SRafael J. Wysocki extern void device_release_driver_internal(struct device *dev, 1389ed98953SRafael J. Wysocki struct device_driver *drv, 1399ed98953SRafael J. Wysocki struct device *parent); 1401da177e4SLinus Torvalds 14107e4a3e2Smochel@digitalimplant.org extern void driver_detach(struct device_driver *drv); 142d1c3414cSGrant Likely extern void driver_deferred_probe_del(struct device *dev); 143d090b70eSAndrzej Hajda extern void device_set_deferred_probe_reason(const struct device *dev, 144d090b70eSAndrzej Hajda struct va_format *vaf); 14549b420a1SMing Lei static inline int driver_match_device(struct device_driver *drv, 14649b420a1SMing Lei struct device *dev) 14749b420a1SMing Lei { 1485247aecfSMing Lei return drv->bus->match ? drv->bus->match(dev, drv) : 1; 14949b420a1SMing Lei } 15007e4a3e2Smochel@digitalimplant.org 151ed0617b5SGreg Kroah-Hartman extern int driver_add_groups(struct device_driver *drv, 152ed0617b5SGreg Kroah-Hartman const struct attribute_group **groups); 153ed0617b5SGreg Kroah-Hartman extern void driver_remove_groups(struct device_driver *drv, 154ed0617b5SGreg Kroah-Hartman const struct attribute_group **groups); 155ed88747cSAlexander Duyck void device_driver_detach(struct device *dev); 156ed0617b5SGreg Kroah-Hartman 1572a013455SAdrian Bunk extern int devres_release_all(struct device *dev); 158013c074fSStrashko, Grygorii extern void device_block_probing(void); 159013c074fSStrashko, Grygorii extern void device_unblock_probing(void); 1602b28a1a8SSaravana Kannan extern void deferred_probe_extend_timeout(void); 1612f8c3ae8SSaravana Kannan extern void driver_deferred_probe_trigger(void); 162*42bb5be8SGreg Kroah-Hartman const char *device_get_devnode(const struct device *dev, umode_t *mode, 163*42bb5be8SGreg Kroah-Hartman kuid_t *uid, kgid_t *gid, const char **tmp); 164823bccfcSGreg Kroah-Hartman 165ca22e56dSKay Sievers /* /sys/devices directory */ 166881c6cfdSGreg Kroah-Hartman extern struct kset *devices_kset; 16752cdbdd4SGrygorii Strashko extern void devices_kset_move_last(struct device *dev); 168c63469a3SGreg Kroah-Hartman 16992b42141SRandy Dunlap #if defined(CONFIG_MODULES) && defined(CONFIG_SYSFS) 170c63469a3SGreg Kroah-Hartman extern void module_add_driver(struct module *mod, struct device_driver *drv); 171c63469a3SGreg Kroah-Hartman extern void module_remove_driver(struct device_driver *drv); 172c63469a3SGreg Kroah-Hartman #else 173c63469a3SGreg Kroah-Hartman static inline void module_add_driver(struct module *mod, 174c63469a3SGreg Kroah-Hartman struct device_driver *drv) { } 175c63469a3SGreg Kroah-Hartman static inline void module_remove_driver(struct device_driver *drv) { } 176c63469a3SGreg Kroah-Hartman #endif 1772b2af54aSKay Sievers 1782b2af54aSKay Sievers #ifdef CONFIG_DEVTMPFS 1792b2af54aSKay Sievers extern int devtmpfs_init(void); 1802b2af54aSKay Sievers #else 1812b2af54aSKay Sievers static inline int devtmpfs_init(void) { return 0; } 1822b2af54aSKay Sievers #endif 1839ed98953SRafael J. Wysocki 1849ed98953SRafael J. Wysocki /* Device links support */ 1859ed98953SRafael J. Wysocki extern int device_links_read_lock(void); 1869ed98953SRafael J. Wysocki extern void device_links_read_unlock(int idx); 187c2fa1e1bSJoel Fernandes (Google) extern int device_links_read_lock_held(void); 1889ed98953SRafael J. Wysocki extern int device_links_check_suppliers(struct device *dev); 189b6f617dfSSaravana Kannan extern void device_links_force_bind(struct device *dev); 1909ed98953SRafael J. Wysocki extern void device_links_driver_bound(struct device *dev); 1919ed98953SRafael J. Wysocki extern void device_links_driver_cleanup(struct device *dev); 1929ed98953SRafael J. Wysocki extern void device_links_no_driver(struct device *dev); 1939ed98953SRafael J. Wysocki extern bool device_links_busy(struct device *dev); 1949ed98953SRafael J. Wysocki extern void device_links_unbind_consumers(struct device *dev); 195d46f3e3eSSaravana Kannan extern void fw_devlink_drivers_done(void); 196494fd7b7SFeng Kan 197494fd7b7SFeng Kan /* device pm support */ 198494fd7b7SFeng Kan void device_pm_move_to_tail(struct device *dev); 199cf901a1cSGreg Kroah-Hartman 200cf901a1cSGreg Kroah-Hartman #ifdef CONFIG_DEVTMPFS 201cf901a1cSGreg Kroah-Hartman int devtmpfs_create_node(struct device *dev); 202cf901a1cSGreg Kroah-Hartman int devtmpfs_delete_node(struct device *dev); 203cf901a1cSGreg Kroah-Hartman #else 204cf901a1cSGreg Kroah-Hartman static inline int devtmpfs_create_node(struct device *dev) { return 0; } 205cf901a1cSGreg Kroah-Hartman static inline int devtmpfs_delete_node(struct device *dev) { return 0; } 206cf901a1cSGreg Kroah-Hartman #endif 207384f5a85SRafael J. Wysocki 208384f5a85SRafael J. Wysocki void software_node_notify(struct device *dev); 209384f5a85SRafael J. Wysocki void software_node_notify_remove(struct device *dev); 210