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