Blame view

drivers/base/base.h 7.23 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  /* SPDX-License-Identifier: GPL-2.0 */
5367601b5   Greg Kroah-Hartman   drivers/base: bas...
2
3
4
5
6
7
8
9
10
11
12
  /*
   * Copyright (c) 2001-2003 Patrick Mochel <mochel@osdl.org>
   * Copyright (c) 2004-2009 Greg Kroah-Hartman <gregkh@suse.de>
   * Copyright (c) 2008-2012 Novell Inc.
   * Copyright (c) 2012-2019 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
   * Copyright (c) 2012-2019 Linux Foundation
   *
   * Core driver model functions and structures that should not be
   * shared outside of the drivers/base/ directory.
   *
   */
ba33162a2   Paul Gortmaker   drivers/base: bas...
13
  #include <linux/notifier.h>
a1bdc7aad   Ben Dooks   [PATCH] drivers/b...
14

c6f7e72a3   Greg Kroah-Hartman   driver core: remo...
15
  /**
6b6e39a6a   Kay Sievers   driver-core: merg...
16
   * struct subsys_private - structure to hold the private to the driver core portions of the bus_type/class structure.
c6f7e72a3   Greg Kroah-Hartman   driver core: remo...
17
   *
6b6e39a6a   Kay Sievers   driver-core: merg...
18
   * @subsys - the struct kset that defines this subsystem
ca22e56de   Kay Sievers   driver-core: impl...
19
20
21
   * @devices_kset - the subsystem's 'devices' directory
   * @interfaces - list of subsystem interfaces associated
   * @mutex - protect the devices, and interfaces lists.
6b6e39a6a   Kay Sievers   driver-core: merg...
22
23
   *
   * @drivers_kset - the list of drivers associated
c6f7e72a3   Greg Kroah-Hartman   driver core: remo...
24
25
26
   * @klist_devices - the klist to iterate over the @devices_kset
   * @klist_drivers - the klist to iterate over the @drivers_kset
   * @bus_notifier - the bus notifier list for anything that cares about things
6b6e39a6a   Kay Sievers   driver-core: merg...
27
   *                 on this bus.
c6f7e72a3   Greg Kroah-Hartman   driver core: remo...
28
   * @bus - pointer back to the struct bus_type that this structure is associated
6b6e39a6a   Kay Sievers   driver-core: merg...
29
30
   *        with.
   *
6b6e39a6a   Kay Sievers   driver-core: merg...
31
32
   * @glue_dirs - "glue" directory to put in-between the parent device to
   *              avoid namespace conflicts
6b6e39a6a   Kay Sievers   driver-core: merg...
33
34
   * @class - pointer back to the struct class that this structure is associated
   *          with.
c6f7e72a3   Greg Kroah-Hartman   driver core: remo...
35
36
   *
   * This structure is the one that is the actual kobject allowing struct
6b6e39a6a   Kay Sievers   driver-core: merg...
37
38
   * bus_type/class to be statically allocated safely.  Nothing outside of the
   * driver core should ever touch these fields.
c6f7e72a3   Greg Kroah-Hartman   driver core: remo...
39
   */
6b6e39a6a   Kay Sievers   driver-core: merg...
40
  struct subsys_private {
c6f7e72a3   Greg Kroah-Hartman   driver core: remo...
41
  	struct kset subsys;
c6f7e72a3   Greg Kroah-Hartman   driver core: remo...
42
  	struct kset *devices_kset;
ca22e56de   Kay Sievers   driver-core: impl...
43
44
  	struct list_head interfaces;
  	struct mutex mutex;
6b6e39a6a   Kay Sievers   driver-core: merg...
45
46
  
  	struct kset *drivers_kset;
c6f7e72a3   Greg Kroah-Hartman   driver core: remo...
47
48
49
50
51
  	struct klist klist_devices;
  	struct klist klist_drivers;
  	struct blocking_notifier_head bus_notifier;
  	unsigned int drivers_autoprobe:1;
  	struct bus_type *bus;
6b6e39a6a   Kay Sievers   driver-core: merg...
52

6b6e39a6a   Kay Sievers   driver-core: merg...
53
  	struct kset glue_dirs;
6b6e39a6a   Kay Sievers   driver-core: merg...
54
  	struct class *class;
c6f7e72a3   Greg Kroah-Hartman   driver core: remo...
55
  };
6b6e39a6a   Kay Sievers   driver-core: merg...
56
  #define to_subsys_private(obj) container_of(obj, struct subsys_private, subsys.kobj)
c6f7e72a3   Greg Kroah-Hartman   driver core: remo...
57

e5dd12784   Greg Kroah-Hartman   Driver core: move...
58
59
60
61
62
63
64
65
  struct driver_private {
  	struct kobject kobj;
  	struct klist klist_devices;
  	struct klist_node knode_bus;
  	struct module_kobject *mkobj;
  	struct device_driver *driver;
  };
  #define to_driver(obj) container_of(obj, struct driver_private, kobj)
a1bdc7aad   Ben Dooks   [PATCH] drivers/b...
66

fb069a5d1   Greg Kroah-Hartman   driver core: crea...
67
68
69
  /**
   * struct device_private - structure to hold the private to the driver core portions of the device structure.
   *
f791b8c83   Greg Kroah-Hartman   driver core: move...
70
71
   * @klist_children - klist containing all children of this device
   * @knode_parent - node in sibling list
8940b4f31   Greg Kroah-Hartman   driver core: move...
72
   * @knode_driver - node in driver list
ae1b41715   Greg Kroah-Hartman   driver core: move...
73
   * @knode_bus - node in bus list
570d02001   Wei Yang   driver core: move...
74
   * @knode_class - node in class list
ef8a3fd6e   Greg Kroah-Hartman   driver core: move...
75
76
77
78
   * @deferred_probe - entry in deferred_probe_list which is used to retry the
   *	binding of drivers which were unable to get all the resources needed by
   *	the device; typically because it depends on another driver getting
   *	probed first.
ef0ff6835   Alexander Duyck   driver core: Prob...
79
   * @async_driver - pointer to device driver awaiting probe via async_probe
82b2c3c5b   Tomeu Vizoso   driver core: fix ...
80
   * @device - pointer back to the struct device that this structure is
fb069a5d1   Greg Kroah-Hartman   driver core: crea...
81
   * associated with.
3451a495e   Alexander Duyck   driver core: Esta...
82
83
84
   * @dead - This device is currently either in the process of or has been
   *	removed from the system. Any asynchronous events scheduled for this
   *	device should exit without taking any action.
fb069a5d1   Greg Kroah-Hartman   driver core: crea...
85
86
87
88
   *
   * Nothing outside of the driver core should ever touch these fields.
   */
  struct device_private {
f791b8c83   Greg Kroah-Hartman   driver core: move...
89
90
  	struct klist klist_children;
  	struct klist_node knode_parent;
8940b4f31   Greg Kroah-Hartman   driver core: move...
91
  	struct klist_node knode_driver;
ae1b41715   Greg Kroah-Hartman   driver core: move...
92
  	struct klist_node knode_bus;
570d02001   Wei Yang   driver core: move...
93
  	struct klist_node knode_class;
ef8a3fd6e   Greg Kroah-Hartman   driver core: move...
94
  	struct list_head deferred_probe;
ef0ff6835   Alexander Duyck   driver core: Prob...
95
  	struct device_driver *async_driver;
d090b70ed   Andrzej Hajda   driver core: add ...
96
  	char *deferred_probe_reason;
fb069a5d1   Greg Kroah-Hartman   driver core: crea...
97
  	struct device *device;
3451a495e   Alexander Duyck   driver core: Esta...
98
  	u8 dead:1;
fb069a5d1   Greg Kroah-Hartman   driver core: crea...
99
  };
f791b8c83   Greg Kroah-Hartman   driver core: move...
100
101
  #define to_device_private_parent(obj)	\
  	container_of(obj, struct device_private, knode_parent)
8940b4f31   Greg Kroah-Hartman   driver core: move...
102
103
  #define to_device_private_driver(obj)	\
  	container_of(obj, struct device_private, knode_driver)
ae1b41715   Greg Kroah-Hartman   driver core: move...
104
105
  #define to_device_private_bus(obj)	\
  	container_of(obj, struct device_private, knode_bus)
570d02001   Wei Yang   driver core: move...
106
107
  #define to_device_private_class(obj)	\
  	container_of(obj, struct device_private, knode_class)
fb069a5d1   Greg Kroah-Hartman   driver core: crea...
108

c6f7e72a3   Greg Kroah-Hartman   driver core: remo...
109
  /* initialisation functions */
a1bdc7aad   Ben Dooks   [PATCH] drivers/b...
110
111
112
113
  extern int devices_init(void);
  extern int buses_init(void);
  extern int classes_init(void);
  extern int firmware_init(void);
4039483fd   Michael Holzheu   [PATCH] Driver Co...
114
115
116
117
118
  #ifdef CONFIG_SYS_HYPERVISOR
  extern int hypervisor_init(void);
  #else
  static inline int hypervisor_init(void) { return 0; }
  #endif
a1bdc7aad   Ben Dooks   [PATCH] drivers/b...
119
  extern int platform_bus_init(void);
024f78462   Ben Hutchings   cpu: Do not retur...
120
  extern void cpu_dev_init(void);
caa73ea15   Rafael J. Wysocki   ACPI / hotplug / ...
121
  extern void container_dev_init(void);
a1bdc7aad   Ben Dooks   [PATCH] drivers/b...
122

d73ce0042   Tejun Heo   driver/base: impl...
123
  struct kobject *virtual_device_parent(struct device *dev);
4a3ad20cc   Greg Kroah-Hartman   Driver core: codi...
124
  extern int bus_add_device(struct device *dev);
2023c610d   Alan Stern   Driver core: add ...
125
  extern void bus_probe_device(struct device *dev);
4a3ad20cc   Greg Kroah-Hartman   Driver core: codi...
126
  extern void bus_remove_device(struct device *dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
127

4a3ad20cc   Greg Kroah-Hartman   Driver core: codi...
128
129
  extern int bus_add_driver(struct device_driver *drv);
  extern void bus_remove_driver(struct device_driver *drv);
9ed989537   Rafael J. Wysocki   driver core: Func...
130
131
132
  extern void device_release_driver_internal(struct device *dev,
  					   struct device_driver *drv,
  					   struct device *parent);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
133

4a3ad20cc   Greg Kroah-Hartman   Driver core: codi...
134
135
  extern void driver_detach(struct device_driver *drv);
  extern int driver_probe_device(struct device_driver *drv, struct device *dev);
d1c3414c2   Grant Likely   drivercore: Add d...
136
  extern void driver_deferred_probe_del(struct device *dev);
d090b70ed   Andrzej Hajda   driver core: add ...
137
138
  extern void device_set_deferred_probe_reason(const struct device *dev,
  					     struct va_format *vaf);
49b420a13   Ming Lei   driver core: chec...
139
140
141
  static inline int driver_match_device(struct device_driver *drv,
  				      struct device *dev)
  {
5247aecfe   Ming Lei   driver core: fix ...
142
  	return drv->bus->match ? drv->bus->match(dev, drv) : 1;
49b420a13   Ming Lei   driver core: chec...
143
  }
765230b5f   Dmitry Torokhov   driver-core: add ...
144
  extern bool driver_allows_async_probing(struct device_driver *drv);
07e4a3e27   Patrick Mochel   [PATCH] Move devi...
145

ed0617b5c   Greg Kroah-Hartman   driver core: bus_...
146
147
148
149
  extern int driver_add_groups(struct device_driver *drv,
  			     const struct attribute_group **groups);
  extern void driver_remove_groups(struct device_driver *drv,
  				 const struct attribute_group **groups);
ed88747c6   Alexander Duyck   device core: Cons...
150
151
  int device_driver_attach(struct device_driver *drv, struct device *dev);
  void device_driver_detach(struct device *dev);
ed0617b5c   Greg Kroah-Hartman   driver core: bus_...
152

aa49b9136   Greg Kroah-Hartman   [PATCH] Driver co...
153
  extern char *make_class_name(const char *name, struct kobject *kobj);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
154

2a0134554   Adrian Bunk   Driver core: fix ...
155
  extern int devres_release_all(struct device *dev);
013c074f8   Strashko, Grygorii   PM / sleep: prohi...
156
157
  extern void device_block_probing(void);
  extern void device_unblock_probing(void);
823bccfc4   Greg Kroah-Hartman   remove "struct su...
158

ca22e56de   Kay Sievers   driver-core: impl...
159
  /* /sys/devices directory */
881c6cfd7   Greg Kroah-Hartman   kset: convert /sy...
160
  extern struct kset *devices_kset;
52cdbdd49   Grygorii Strashko   driver core: corr...
161
  extern void devices_kset_move_last(struct device *dev);
c63469a39   Greg Kroah-Hartman   Driver core: move...
162

92b421416   Randy Dunlap   driver core: fix ...
163
  #if defined(CONFIG_MODULES) && defined(CONFIG_SYSFS)
c63469a39   Greg Kroah-Hartman   Driver core: move...
164
165
166
167
168
169
170
  extern void module_add_driver(struct module *mod, struct device_driver *drv);
  extern void module_remove_driver(struct device_driver *drv);
  #else
  static inline void module_add_driver(struct module *mod,
  				     struct device_driver *drv) { }
  static inline void module_remove_driver(struct device_driver *drv) { }
  #endif
2b2af54a5   Kay Sievers   Driver Core: devt...
171
172
173
174
175
176
  
  #ifdef CONFIG_DEVTMPFS
  extern int devtmpfs_init(void);
  #else
  static inline int devtmpfs_init(void) { return 0; }
  #endif
9ed989537   Rafael J. Wysocki   driver core: Func...
177
178
179
180
  
  /* Device links support */
  extern int device_links_read_lock(void);
  extern void device_links_read_unlock(int idx);
c2fa1e1bf   Joel Fernandes (Google)   driver/core: Conv...
181
  extern int device_links_read_lock_held(void);
9ed989537   Rafael J. Wysocki   driver core: Func...
182
183
184
185
186
187
  extern int device_links_check_suppliers(struct device *dev);
  extern void device_links_driver_bound(struct device *dev);
  extern void device_links_driver_cleanup(struct device *dev);
  extern void device_links_no_driver(struct device *dev);
  extern bool device_links_busy(struct device *dev);
  extern void device_links_unbind_consumers(struct device *dev);
494fd7b7a   Feng Kan   PM / core: fix de...
188
189
190
  
  /* device pm support */
  void device_pm_move_to_tail(struct device *dev);
cf901a1c5   Greg Kroah-Hartman   device.h: move de...
191
192
193
194
195
196
197
198
  
  #ifdef CONFIG_DEVTMPFS
  int devtmpfs_create_node(struct device *dev);
  int devtmpfs_delete_node(struct device *dev);
  #else
  static inline int devtmpfs_create_node(struct device *dev) { return 0; }
  static inline int devtmpfs_delete_node(struct device *dev) { return 0; }
  #endif