Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright (c) 2001-2003 Patrick Mochel <mochel@osdl.org>
0004  * Copyright (c) 2004-2009 Greg Kroah-Hartman <gregkh@suse.de>
0005  * Copyright (c) 2008-2012 Novell Inc.
0006  * Copyright (c) 2012-2019 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
0007  * Copyright (c) 2012-2019 Linux Foundation
0008  *
0009  * Core driver model functions and structures that should not be
0010  * shared outside of the drivers/base/ directory.
0011  *
0012  */
0013 #include <linux/notifier.h>
0014 
0015 /**
0016  * struct subsys_private - structure to hold the private to the driver core portions of the bus_type/class structure.
0017  *
0018  * @subsys - the struct kset that defines this subsystem
0019  * @devices_kset - the subsystem's 'devices' directory
0020  * @interfaces - list of subsystem interfaces associated
0021  * @mutex - protect the devices, and interfaces lists.
0022  *
0023  * @drivers_kset - the list of drivers associated
0024  * @klist_devices - the klist to iterate over the @devices_kset
0025  * @klist_drivers - the klist to iterate over the @drivers_kset
0026  * @bus_notifier - the bus notifier list for anything that cares about things
0027  *                 on this bus.
0028  * @bus - pointer back to the struct bus_type that this structure is associated
0029  *        with.
0030  *
0031  * @glue_dirs - "glue" directory to put in-between the parent device to
0032  *              avoid namespace conflicts
0033  * @class - pointer back to the struct class that this structure is associated
0034  *          with.
0035  *
0036  * This structure is the one that is the actual kobject allowing struct
0037  * bus_type/class to be statically allocated safely.  Nothing outside of the
0038  * driver core should ever touch these fields.
0039  */
0040 struct subsys_private {
0041     struct kset subsys;
0042     struct kset *devices_kset;
0043     struct list_head interfaces;
0044     struct mutex mutex;
0045 
0046     struct kset *drivers_kset;
0047     struct klist klist_devices;
0048     struct klist klist_drivers;
0049     struct blocking_notifier_head bus_notifier;
0050     unsigned int drivers_autoprobe:1;
0051     struct bus_type *bus;
0052 
0053     struct kset glue_dirs;
0054     struct class *class;
0055 };
0056 #define to_subsys_private(obj) container_of(obj, struct subsys_private, subsys.kobj)
0057 
0058 struct driver_private {
0059     struct kobject kobj;
0060     struct klist klist_devices;
0061     struct klist_node knode_bus;
0062     struct module_kobject *mkobj;
0063     struct device_driver *driver;
0064 };
0065 #define to_driver(obj) container_of(obj, struct driver_private, kobj)
0066 
0067 /**
0068  * struct device_private - structure to hold the private to the driver core portions of the device structure.
0069  *
0070  * @klist_children - klist containing all children of this device
0071  * @knode_parent - node in sibling list
0072  * @knode_driver - node in driver list
0073  * @knode_bus - node in bus list
0074  * @knode_class - node in class list
0075  * @deferred_probe - entry in deferred_probe_list which is used to retry the
0076  *  binding of drivers which were unable to get all the resources needed by
0077  *  the device; typically because it depends on another driver getting
0078  *  probed first.
0079  * @async_driver - pointer to device driver awaiting probe via async_probe
0080  * @device - pointer back to the struct device that this structure is
0081  * associated with.
0082  * @dead - This device is currently either in the process of or has been
0083  *  removed from the system. Any asynchronous events scheduled for this
0084  *  device should exit without taking any action.
0085  *
0086  * Nothing outside of the driver core should ever touch these fields.
0087  */
0088 struct device_private {
0089     struct klist klist_children;
0090     struct klist_node knode_parent;
0091     struct klist_node knode_driver;
0092     struct klist_node knode_bus;
0093     struct klist_node knode_class;
0094     struct list_head deferred_probe;
0095     struct device_driver *async_driver;
0096     char *deferred_probe_reason;
0097     struct device *device;
0098     u8 dead:1;
0099 };
0100 #define to_device_private_parent(obj)   \
0101     container_of(obj, struct device_private, knode_parent)
0102 #define to_device_private_driver(obj)   \
0103     container_of(obj, struct device_private, knode_driver)
0104 #define to_device_private_bus(obj)  \
0105     container_of(obj, struct device_private, knode_bus)
0106 #define to_device_private_class(obj)    \
0107     container_of(obj, struct device_private, knode_class)
0108 
0109 /* initialisation functions */
0110 extern int devices_init(void);
0111 extern int buses_init(void);
0112 extern int classes_init(void);
0113 extern int firmware_init(void);
0114 #ifdef CONFIG_SYS_HYPERVISOR
0115 extern int hypervisor_init(void);
0116 #else
0117 static inline int hypervisor_init(void) { return 0; }
0118 #endif
0119 extern int platform_bus_init(void);
0120 extern void cpu_dev_init(void);
0121 extern void container_dev_init(void);
0122 #ifdef CONFIG_AUXILIARY_BUS
0123 extern void auxiliary_bus_init(void);
0124 #else
0125 static inline void auxiliary_bus_init(void) { }
0126 #endif
0127 
0128 struct kobject *virtual_device_parent(struct device *dev);
0129 
0130 extern int bus_add_device(struct device *dev);
0131 extern void bus_probe_device(struct device *dev);
0132 extern void bus_remove_device(struct device *dev);
0133 
0134 extern int bus_add_driver(struct device_driver *drv);
0135 extern void bus_remove_driver(struct device_driver *drv);
0136 extern void device_release_driver_internal(struct device *dev,
0137                        struct device_driver *drv,
0138                        struct device *parent);
0139 
0140 extern void driver_detach(struct device_driver *drv);
0141 extern void driver_deferred_probe_del(struct device *dev);
0142 extern void device_set_deferred_probe_reason(const struct device *dev,
0143                          struct va_format *vaf);
0144 static inline int driver_match_device(struct device_driver *drv,
0145                       struct device *dev)
0146 {
0147     return drv->bus->match ? drv->bus->match(dev, drv) : 1;
0148 }
0149 extern bool driver_allows_async_probing(struct device_driver *drv);
0150 
0151 extern int driver_add_groups(struct device_driver *drv,
0152                  const struct attribute_group **groups);
0153 extern void driver_remove_groups(struct device_driver *drv,
0154                  const struct attribute_group **groups);
0155 void device_driver_detach(struct device *dev);
0156 
0157 extern char *make_class_name(const char *name, struct kobject *kobj);
0158 
0159 extern int devres_release_all(struct device *dev);
0160 extern void device_block_probing(void);
0161 extern void device_unblock_probing(void);
0162 extern void deferred_probe_extend_timeout(void);
0163 extern void driver_deferred_probe_trigger(void);
0164 
0165 /* /sys/devices directory */
0166 extern struct kset *devices_kset;
0167 extern void devices_kset_move_last(struct device *dev);
0168 
0169 #if defined(CONFIG_MODULES) && defined(CONFIG_SYSFS)
0170 extern void module_add_driver(struct module *mod, struct device_driver *drv);
0171 extern void module_remove_driver(struct device_driver *drv);
0172 #else
0173 static inline void module_add_driver(struct module *mod,
0174                      struct device_driver *drv) { }
0175 static inline void module_remove_driver(struct device_driver *drv) { }
0176 #endif
0177 
0178 #ifdef CONFIG_DEVTMPFS
0179 extern int devtmpfs_init(void);
0180 #else
0181 static inline int devtmpfs_init(void) { return 0; }
0182 #endif
0183 
0184 /* Device links support */
0185 extern int device_links_read_lock(void);
0186 extern void device_links_read_unlock(int idx);
0187 extern int device_links_read_lock_held(void);
0188 extern int device_links_check_suppliers(struct device *dev);
0189 extern void device_links_force_bind(struct device *dev);
0190 extern void device_links_driver_bound(struct device *dev);
0191 extern void device_links_driver_cleanup(struct device *dev);
0192 extern void device_links_no_driver(struct device *dev);
0193 extern bool device_links_busy(struct device *dev);
0194 extern void device_links_unbind_consumers(struct device *dev);
0195 extern void fw_devlink_drivers_done(void);
0196 
0197 /* device pm support */
0198 void device_pm_move_to_tail(struct device *dev);
0199 
0200 #ifdef CONFIG_DEVTMPFS
0201 int devtmpfs_create_node(struct device *dev);
0202 int devtmpfs_delete_node(struct device *dev);
0203 #else
0204 static inline int devtmpfs_create_node(struct device *dev) { return 0; }
0205 static inline int devtmpfs_delete_node(struct device *dev) { return 0; }
0206 #endif
0207 
0208 void software_node_notify(struct device *dev);
0209 void software_node_notify_remove(struct device *dev);