.. | .. |
---|
6 | 6 | * Copyright (c) 2004-2009 Greg Kroah-Hartman <gregkh@suse.de> |
---|
7 | 7 | * Copyright (c) 2008-2009 Novell Inc. |
---|
8 | 8 | * |
---|
9 | | - * See Documentation/driver-model/ for more information. |
---|
| 9 | + * See Documentation/driver-api/driver-model/ for more information. |
---|
10 | 10 | */ |
---|
11 | 11 | |
---|
12 | 12 | #ifndef _DEVICE_H_ |
---|
13 | 13 | #define _DEVICE_H_ |
---|
14 | 14 | |
---|
| 15 | +#include <linux/dev_printk.h> |
---|
| 16 | +#include <linux/energy_model.h> |
---|
15 | 17 | #include <linux/ioport.h> |
---|
16 | 18 | #include <linux/kobject.h> |
---|
17 | 19 | #include <linux/klist.h> |
---|
.. | .. |
---|
22 | 24 | #include <linux/mutex.h> |
---|
23 | 25 | #include <linux/pm.h> |
---|
24 | 26 | #include <linux/atomic.h> |
---|
25 | | -#include <linux/ratelimit.h> |
---|
26 | 27 | #include <linux/uidgid.h> |
---|
27 | 28 | #include <linux/gfp.h> |
---|
28 | 29 | #include <linux/overflow.h> |
---|
| 30 | +#include <linux/device/bus.h> |
---|
| 31 | +#include <linux/device/class.h> |
---|
| 32 | +#include <linux/device/driver.h> |
---|
29 | 33 | #include <linux/android_kabi.h> |
---|
30 | 34 | #include <asm/device.h> |
---|
31 | 35 | |
---|
.. | .. |
---|
36 | 40 | struct module; |
---|
37 | 41 | struct class; |
---|
38 | 42 | struct subsys_private; |
---|
39 | | -struct bus_type; |
---|
40 | 43 | struct device_node; |
---|
41 | 44 | struct fwnode_handle; |
---|
42 | 45 | struct iommu_ops; |
---|
43 | 46 | struct iommu_group; |
---|
44 | | -struct iommu_fwspec; |
---|
45 | 47 | struct dev_pin_info; |
---|
46 | | - |
---|
47 | | -struct bus_attribute { |
---|
48 | | - struct attribute attr; |
---|
49 | | - ssize_t (*show)(struct bus_type *bus, char *buf); |
---|
50 | | - ssize_t (*store)(struct bus_type *bus, const char *buf, size_t count); |
---|
51 | | -}; |
---|
52 | | - |
---|
53 | | -#define BUS_ATTR(_name, _mode, _show, _store) \ |
---|
54 | | - struct bus_attribute bus_attr_##_name = __ATTR(_name, _mode, _show, _store) |
---|
55 | | -#define BUS_ATTR_RW(_name) \ |
---|
56 | | - struct bus_attribute bus_attr_##_name = __ATTR_RW(_name) |
---|
57 | | -#define BUS_ATTR_RO(_name) \ |
---|
58 | | - struct bus_attribute bus_attr_##_name = __ATTR_RO(_name) |
---|
59 | | - |
---|
60 | | -extern int __must_check bus_create_file(struct bus_type *, |
---|
61 | | - struct bus_attribute *); |
---|
62 | | -extern void bus_remove_file(struct bus_type *, struct bus_attribute *); |
---|
63 | | - |
---|
64 | | -/** |
---|
65 | | - * struct bus_type - The bus type of the device |
---|
66 | | - * |
---|
67 | | - * @name: The name of the bus. |
---|
68 | | - * @dev_name: Used for subsystems to enumerate devices like ("foo%u", dev->id). |
---|
69 | | - * @dev_root: Default device to use as the parent. |
---|
70 | | - * @bus_groups: Default attributes of the bus. |
---|
71 | | - * @dev_groups: Default attributes of the devices on the bus. |
---|
72 | | - * @drv_groups: Default attributes of the device drivers on the bus. |
---|
73 | | - * @match: Called, perhaps multiple times, whenever a new device or driver |
---|
74 | | - * is added for this bus. It should return a positive value if the |
---|
75 | | - * given device can be handled by the given driver and zero |
---|
76 | | - * otherwise. It may also return error code if determining that |
---|
77 | | - * the driver supports the device is not possible. In case of |
---|
78 | | - * -EPROBE_DEFER it will queue the device for deferred probing. |
---|
79 | | - * @uevent: Called when a device is added, removed, or a few other things |
---|
80 | | - * that generate uevents to add the environment variables. |
---|
81 | | - * @probe: Called when a new device or driver add to this bus, and callback |
---|
82 | | - * the specific driver's probe to initial the matched device. |
---|
83 | | - * @sync_state: Called to sync device state to software state after all the |
---|
84 | | - * state tracking consumers linked to this device (present at |
---|
85 | | - * the time of late_initcall) have successfully bound to a |
---|
86 | | - * driver. If the device has no consumers, this function will |
---|
87 | | - * be called at late_initcall_sync level. If the device has |
---|
88 | | - * consumers that are never bound to a driver, this function |
---|
89 | | - * will never get called until they do. |
---|
90 | | - * @remove: Called when a device removed from this bus. |
---|
91 | | - * @shutdown: Called at shut-down time to quiesce the device. |
---|
92 | | - * |
---|
93 | | - * @online: Called to put the device back online (after offlining it). |
---|
94 | | - * @offline: Called to put the device offline for hot-removal. May fail. |
---|
95 | | - * |
---|
96 | | - * @suspend: Called when a device on this bus wants to go to sleep mode. |
---|
97 | | - * @resume: Called to bring a device on this bus out of sleep mode. |
---|
98 | | - * @num_vf: Called to find out how many virtual functions a device on this |
---|
99 | | - * bus supports. |
---|
100 | | - * @dma_configure: Called to setup DMA configuration on a device on |
---|
101 | | - * this bus. |
---|
102 | | - * @pm: Power management operations of this bus, callback the specific |
---|
103 | | - * device driver's pm-ops. |
---|
104 | | - * @iommu_ops: IOMMU specific operations for this bus, used to attach IOMMU |
---|
105 | | - * driver implementations to a bus and allow the driver to do |
---|
106 | | - * bus-specific setup |
---|
107 | | - * @p: The private data of the driver core, only the driver core can |
---|
108 | | - * touch this. |
---|
109 | | - * @lock_key: Lock class key for use by the lock validator |
---|
110 | | - * @need_parent_lock: When probing or removing a device on this bus, the |
---|
111 | | - * device core should lock the device's parent. |
---|
112 | | - * |
---|
113 | | - * A bus is a channel between the processor and one or more devices. For the |
---|
114 | | - * purposes of the device model, all devices are connected via a bus, even if |
---|
115 | | - * it is an internal, virtual, "platform" bus. Buses can plug into each other. |
---|
116 | | - * A USB controller is usually a PCI device, for example. The device model |
---|
117 | | - * represents the actual connections between buses and the devices they control. |
---|
118 | | - * A bus is represented by the bus_type structure. It contains the name, the |
---|
119 | | - * default attributes, the bus' methods, PM operations, and the driver core's |
---|
120 | | - * private data. |
---|
121 | | - */ |
---|
122 | | -struct bus_type { |
---|
123 | | - const char *name; |
---|
124 | | - const char *dev_name; |
---|
125 | | - struct device *dev_root; |
---|
126 | | - const struct attribute_group **bus_groups; |
---|
127 | | - const struct attribute_group **dev_groups; |
---|
128 | | - const struct attribute_group **drv_groups; |
---|
129 | | - |
---|
130 | | - int (*match)(struct device *dev, struct device_driver *drv); |
---|
131 | | - int (*uevent)(struct device *dev, struct kobj_uevent_env *env); |
---|
132 | | - int (*probe)(struct device *dev); |
---|
133 | | - void (*sync_state)(struct device *dev); |
---|
134 | | - int (*remove)(struct device *dev); |
---|
135 | | - void (*shutdown)(struct device *dev); |
---|
136 | | - |
---|
137 | | - int (*online)(struct device *dev); |
---|
138 | | - int (*offline)(struct device *dev); |
---|
139 | | - |
---|
140 | | - int (*suspend)(struct device *dev, pm_message_t state); |
---|
141 | | - int (*resume)(struct device *dev); |
---|
142 | | - |
---|
143 | | - int (*num_vf)(struct device *dev); |
---|
144 | | - |
---|
145 | | - int (*dma_configure)(struct device *dev); |
---|
146 | | - |
---|
147 | | - const struct dev_pm_ops *pm; |
---|
148 | | - |
---|
149 | | - const struct iommu_ops *iommu_ops; |
---|
150 | | - |
---|
151 | | - struct subsys_private *p; |
---|
152 | | - struct lock_class_key lock_key; |
---|
153 | | - |
---|
154 | | - bool need_parent_lock; |
---|
155 | | - |
---|
156 | | - ANDROID_KABI_RESERVE(1); |
---|
157 | | - ANDROID_KABI_RESERVE(2); |
---|
158 | | - ANDROID_KABI_RESERVE(3); |
---|
159 | | - ANDROID_KABI_RESERVE(4); |
---|
160 | | -}; |
---|
161 | | - |
---|
162 | | -extern int __must_check bus_register(struct bus_type *bus); |
---|
163 | | - |
---|
164 | | -extern void bus_unregister(struct bus_type *bus); |
---|
165 | | - |
---|
166 | | -extern int __must_check bus_rescan_devices(struct bus_type *bus); |
---|
167 | | - |
---|
168 | | -/* iterator helpers for buses */ |
---|
169 | | -struct subsys_dev_iter { |
---|
170 | | - struct klist_iter ki; |
---|
171 | | - const struct device_type *type; |
---|
172 | | -}; |
---|
173 | | -void subsys_dev_iter_init(struct subsys_dev_iter *iter, |
---|
174 | | - struct bus_type *subsys, |
---|
175 | | - struct device *start, |
---|
176 | | - const struct device_type *type); |
---|
177 | | -struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter); |
---|
178 | | -void subsys_dev_iter_exit(struct subsys_dev_iter *iter); |
---|
179 | | - |
---|
180 | | -int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, |
---|
181 | | - int (*fn)(struct device *dev, void *data)); |
---|
182 | | -struct device *bus_find_device(struct bus_type *bus, struct device *start, |
---|
183 | | - void *data, |
---|
184 | | - int (*match)(struct device *dev, void *data)); |
---|
185 | | -struct device *bus_find_device_by_name(struct bus_type *bus, |
---|
186 | | - struct device *start, |
---|
187 | | - const char *name); |
---|
188 | | -struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id, |
---|
189 | | - struct device *hint); |
---|
190 | | -int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, |
---|
191 | | - void *data, int (*fn)(struct device_driver *, void *)); |
---|
192 | | -void bus_sort_breadthfirst(struct bus_type *bus, |
---|
193 | | - int (*compare)(const struct device *a, |
---|
194 | | - const struct device *b)); |
---|
195 | | -/* |
---|
196 | | - * Bus notifiers: Get notified of addition/removal of devices |
---|
197 | | - * and binding/unbinding of drivers to devices. |
---|
198 | | - * In the long run, it should be a replacement for the platform |
---|
199 | | - * notify hooks. |
---|
200 | | - */ |
---|
201 | | -struct notifier_block; |
---|
202 | | - |
---|
203 | | -extern int bus_register_notifier(struct bus_type *bus, |
---|
204 | | - struct notifier_block *nb); |
---|
205 | | -extern int bus_unregister_notifier(struct bus_type *bus, |
---|
206 | | - struct notifier_block *nb); |
---|
207 | | - |
---|
208 | | -/* All 4 notifers below get called with the target struct device * |
---|
209 | | - * as an argument. Note that those functions are likely to be called |
---|
210 | | - * with the device lock held in the core, so be careful. |
---|
211 | | - */ |
---|
212 | | -#define BUS_NOTIFY_ADD_DEVICE 0x00000001 /* device added */ |
---|
213 | | -#define BUS_NOTIFY_DEL_DEVICE 0x00000002 /* device to be removed */ |
---|
214 | | -#define BUS_NOTIFY_REMOVED_DEVICE 0x00000003 /* device removed */ |
---|
215 | | -#define BUS_NOTIFY_BIND_DRIVER 0x00000004 /* driver about to be |
---|
216 | | - bound */ |
---|
217 | | -#define BUS_NOTIFY_BOUND_DRIVER 0x00000005 /* driver bound to device */ |
---|
218 | | -#define BUS_NOTIFY_UNBIND_DRIVER 0x00000006 /* driver about to be |
---|
219 | | - unbound */ |
---|
220 | | -#define BUS_NOTIFY_UNBOUND_DRIVER 0x00000007 /* driver is unbound |
---|
221 | | - from the device */ |
---|
222 | | -#define BUS_NOTIFY_DRIVER_NOT_BOUND 0x00000008 /* driver fails to be bound */ |
---|
223 | | - |
---|
224 | | -extern struct kset *bus_get_kset(struct bus_type *bus); |
---|
225 | | -extern struct klist *bus_get_device_klist(struct bus_type *bus); |
---|
226 | | - |
---|
227 | | -/** |
---|
228 | | - * enum probe_type - device driver probe type to try |
---|
229 | | - * Device drivers may opt in for special handling of their |
---|
230 | | - * respective probe routines. This tells the core what to |
---|
231 | | - * expect and prefer. |
---|
232 | | - * |
---|
233 | | - * @PROBE_DEFAULT_STRATEGY: Used by drivers that work equally well |
---|
234 | | - * whether probed synchronously or asynchronously. |
---|
235 | | - * @PROBE_PREFER_ASYNCHRONOUS: Drivers for "slow" devices which |
---|
236 | | - * probing order is not essential for booting the system may |
---|
237 | | - * opt into executing their probes asynchronously. |
---|
238 | | - * @PROBE_FORCE_SYNCHRONOUS: Use this to annotate drivers that need |
---|
239 | | - * their probe routines to run synchronously with driver and |
---|
240 | | - * device registration (with the exception of -EPROBE_DEFER |
---|
241 | | - * handling - re-probing always ends up being done asynchronously). |
---|
242 | | - * |
---|
243 | | - * Note that the end goal is to switch the kernel to use asynchronous |
---|
244 | | - * probing by default, so annotating drivers with |
---|
245 | | - * %PROBE_PREFER_ASYNCHRONOUS is a temporary measure that allows us |
---|
246 | | - * to speed up boot process while we are validating the rest of the |
---|
247 | | - * drivers. |
---|
248 | | - */ |
---|
249 | | -enum probe_type { |
---|
250 | | - PROBE_DEFAULT_STRATEGY, |
---|
251 | | - PROBE_PREFER_ASYNCHRONOUS, |
---|
252 | | - PROBE_FORCE_SYNCHRONOUS, |
---|
253 | | -}; |
---|
254 | | - |
---|
255 | | -/** |
---|
256 | | - * struct device_driver - The basic device driver structure |
---|
257 | | - * @name: Name of the device driver. |
---|
258 | | - * @bus: The bus which the device of this driver belongs to. |
---|
259 | | - * @owner: The module owner. |
---|
260 | | - * @mod_name: Used for built-in modules. |
---|
261 | | - * @suppress_bind_attrs: Disables bind/unbind via sysfs. |
---|
262 | | - * @probe_type: Type of the probe (synchronous or asynchronous) to use. |
---|
263 | | - * @of_match_table: The open firmware table. |
---|
264 | | - * @acpi_match_table: The ACPI match table. |
---|
265 | | - * @probe: Called to query the existence of a specific device, |
---|
266 | | - * whether this driver can work with it, and bind the driver |
---|
267 | | - * to a specific device. |
---|
268 | | - * @sync_state: Called to sync device state to software state after all the |
---|
269 | | - * state tracking consumers linked to this device (present at |
---|
270 | | - * the time of late_initcall) have successfully bound to a |
---|
271 | | - * driver. If the device has no consumers, this function will |
---|
272 | | - * be called at late_initcall_sync level. If the device has |
---|
273 | | - * consumers that are never bound to a driver, this function |
---|
274 | | - * will never get called until they do. |
---|
275 | | - * @remove: Called when the device is removed from the system to |
---|
276 | | - * unbind a device from this driver. |
---|
277 | | - * @shutdown: Called at shut-down time to quiesce the device. |
---|
278 | | - * @suspend: Called to put the device to sleep mode. Usually to a |
---|
279 | | - * low power state. |
---|
280 | | - * @resume: Called to bring a device from sleep mode. |
---|
281 | | - * @groups: Default attributes that get created by the driver core |
---|
282 | | - * automatically. |
---|
283 | | - * @pm: Power management operations of the device which matched |
---|
284 | | - * this driver. |
---|
285 | | - * @coredump: Called when sysfs entry is written to. The device driver |
---|
286 | | - * is expected to call the dev_coredump API resulting in a |
---|
287 | | - * uevent. |
---|
288 | | - * @p: Driver core's private data, no one other than the driver |
---|
289 | | - * core can touch this. |
---|
290 | | - * |
---|
291 | | - * The device driver-model tracks all of the drivers known to the system. |
---|
292 | | - * The main reason for this tracking is to enable the driver core to match |
---|
293 | | - * up drivers with new devices. Once drivers are known objects within the |
---|
294 | | - * system, however, a number of other things become possible. Device drivers |
---|
295 | | - * can export information and configuration variables that are independent |
---|
296 | | - * of any specific device. |
---|
297 | | - */ |
---|
298 | | -struct device_driver { |
---|
299 | | - const char *name; |
---|
300 | | - struct bus_type *bus; |
---|
301 | | - |
---|
302 | | - struct module *owner; |
---|
303 | | - const char *mod_name; /* used for built-in modules */ |
---|
304 | | - |
---|
305 | | - bool suppress_bind_attrs; /* disables bind/unbind via sysfs */ |
---|
306 | | - enum probe_type probe_type; |
---|
307 | | - |
---|
308 | | - const struct of_device_id *of_match_table; |
---|
309 | | - const struct acpi_device_id *acpi_match_table; |
---|
310 | | - |
---|
311 | | - int (*probe) (struct device *dev); |
---|
312 | | - void (*sync_state)(struct device *dev); |
---|
313 | | - int (*remove) (struct device *dev); |
---|
314 | | - void (*shutdown) (struct device *dev); |
---|
315 | | - int (*suspend) (struct device *dev, pm_message_t state); |
---|
316 | | - int (*resume) (struct device *dev); |
---|
317 | | - const struct attribute_group **groups; |
---|
318 | | - |
---|
319 | | - const struct dev_pm_ops *pm; |
---|
320 | | - void (*coredump) (struct device *dev); |
---|
321 | | - |
---|
322 | | - struct driver_private *p; |
---|
323 | | - |
---|
324 | | - ANDROID_KABI_RESERVE(1); |
---|
325 | | - ANDROID_KABI_RESERVE(2); |
---|
326 | | - ANDROID_KABI_RESERVE(3); |
---|
327 | | - ANDROID_KABI_RESERVE(4); |
---|
328 | | -}; |
---|
329 | | - |
---|
330 | | - |
---|
331 | | -extern int __must_check driver_register(struct device_driver *drv); |
---|
332 | | -extern void driver_unregister(struct device_driver *drv); |
---|
333 | | - |
---|
334 | | -extern struct device_driver *driver_find(const char *name, |
---|
335 | | - struct bus_type *bus); |
---|
336 | | -extern int driver_probe_done(void); |
---|
337 | | -extern void wait_for_device_probe(void); |
---|
338 | | - |
---|
339 | | -/* sysfs interface for exporting driver attributes */ |
---|
340 | | - |
---|
341 | | -struct driver_attribute { |
---|
342 | | - struct attribute attr; |
---|
343 | | - ssize_t (*show)(struct device_driver *driver, char *buf); |
---|
344 | | - ssize_t (*store)(struct device_driver *driver, const char *buf, |
---|
345 | | - size_t count); |
---|
346 | | -}; |
---|
347 | | - |
---|
348 | | -#define DRIVER_ATTR_RW(_name) \ |
---|
349 | | - struct driver_attribute driver_attr_##_name = __ATTR_RW(_name) |
---|
350 | | -#define DRIVER_ATTR_RO(_name) \ |
---|
351 | | - struct driver_attribute driver_attr_##_name = __ATTR_RO(_name) |
---|
352 | | -#define DRIVER_ATTR_WO(_name) \ |
---|
353 | | - struct driver_attribute driver_attr_##_name = __ATTR_WO(_name) |
---|
354 | | - |
---|
355 | | -extern int __must_check driver_create_file(struct device_driver *driver, |
---|
356 | | - const struct driver_attribute *attr); |
---|
357 | | -extern void driver_remove_file(struct device_driver *driver, |
---|
358 | | - const struct driver_attribute *attr); |
---|
359 | | - |
---|
360 | | -extern int __must_check driver_for_each_device(struct device_driver *drv, |
---|
361 | | - struct device *start, |
---|
362 | | - void *data, |
---|
363 | | - int (*fn)(struct device *dev, |
---|
364 | | - void *)); |
---|
365 | | -struct device *driver_find_device(struct device_driver *drv, |
---|
366 | | - struct device *start, void *data, |
---|
367 | | - int (*match)(struct device *dev, void *data)); |
---|
368 | | - |
---|
369 | | -void driver_deferred_probe_add(struct device *dev); |
---|
370 | | -int driver_deferred_probe_check_state(struct device *dev); |
---|
| 48 | +struct dev_iommu; |
---|
371 | 49 | |
---|
372 | 50 | /** |
---|
373 | 51 | * struct subsys_interface - interfaces to device functions |
---|
.. | .. |
---|
397 | 75 | const struct attribute_group **groups); |
---|
398 | 76 | int subsys_virtual_register(struct bus_type *subsys, |
---|
399 | 77 | const struct attribute_group **groups); |
---|
400 | | - |
---|
401 | | -/** |
---|
402 | | - * struct class - device classes |
---|
403 | | - * @name: Name of the class. |
---|
404 | | - * @owner: The module owner. |
---|
405 | | - * @class_groups: Default attributes of this class. |
---|
406 | | - * @dev_groups: Default attributes of the devices that belong to the class. |
---|
407 | | - * @dev_kobj: The kobject that represents this class and links it into the hierarchy. |
---|
408 | | - * @dev_uevent: Called when a device is added, removed from this class, or a |
---|
409 | | - * few other things that generate uevents to add the environment |
---|
410 | | - * variables. |
---|
411 | | - * @devnode: Callback to provide the devtmpfs. |
---|
412 | | - * @class_release: Called to release this class. |
---|
413 | | - * @dev_release: Called to release the device. |
---|
414 | | - * @shutdown_pre: Called at shut-down time before driver shutdown. |
---|
415 | | - * @ns_type: Callbacks so sysfs can detemine namespaces. |
---|
416 | | - * @namespace: Namespace of the device belongs to this class. |
---|
417 | | - * @get_ownership: Allows class to specify uid/gid of the sysfs directories |
---|
418 | | - * for the devices belonging to the class. Usually tied to |
---|
419 | | - * device's namespace. |
---|
420 | | - * @pm: The default device power management operations of this class. |
---|
421 | | - * @p: The private data of the driver core, no one other than the |
---|
422 | | - * driver core can touch this. |
---|
423 | | - * |
---|
424 | | - * A class is a higher-level view of a device that abstracts out low-level |
---|
425 | | - * implementation details. Drivers may see a SCSI disk or an ATA disk, but, |
---|
426 | | - * at the class level, they are all simply disks. Classes allow user space |
---|
427 | | - * to work with devices based on what they do, rather than how they are |
---|
428 | | - * connected or how they work. |
---|
429 | | - */ |
---|
430 | | -struct class { |
---|
431 | | - const char *name; |
---|
432 | | - struct module *owner; |
---|
433 | | - |
---|
434 | | - const struct attribute_group **class_groups; |
---|
435 | | - const struct attribute_group **dev_groups; |
---|
436 | | - struct kobject *dev_kobj; |
---|
437 | | - |
---|
438 | | - int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env); |
---|
439 | | - char *(*devnode)(struct device *dev, umode_t *mode); |
---|
440 | | - |
---|
441 | | - void (*class_release)(struct class *class); |
---|
442 | | - void (*dev_release)(struct device *dev); |
---|
443 | | - |
---|
444 | | - int (*shutdown_pre)(struct device *dev); |
---|
445 | | - |
---|
446 | | - const struct kobj_ns_type_operations *ns_type; |
---|
447 | | - const void *(*namespace)(struct device *dev); |
---|
448 | | - |
---|
449 | | - void (*get_ownership)(struct device *dev, kuid_t *uid, kgid_t *gid); |
---|
450 | | - |
---|
451 | | - const struct dev_pm_ops *pm; |
---|
452 | | - |
---|
453 | | - struct subsys_private *p; |
---|
454 | | - |
---|
455 | | - ANDROID_KABI_RESERVE(1); |
---|
456 | | - ANDROID_KABI_RESERVE(2); |
---|
457 | | - ANDROID_KABI_RESERVE(3); |
---|
458 | | - ANDROID_KABI_RESERVE(4); |
---|
459 | | -}; |
---|
460 | | - |
---|
461 | | -struct class_dev_iter { |
---|
462 | | - struct klist_iter ki; |
---|
463 | | - const struct device_type *type; |
---|
464 | | -}; |
---|
465 | | - |
---|
466 | | -extern struct kobject *sysfs_dev_block_kobj; |
---|
467 | | -extern struct kobject *sysfs_dev_char_kobj; |
---|
468 | | -extern int __must_check __class_register(struct class *class, |
---|
469 | | - struct lock_class_key *key); |
---|
470 | | -extern void class_unregister(struct class *class); |
---|
471 | | - |
---|
472 | | -/* This is a #define to keep the compiler from merging different |
---|
473 | | - * instances of the __key variable */ |
---|
474 | | -#define class_register(class) \ |
---|
475 | | -({ \ |
---|
476 | | - static struct lock_class_key __key; \ |
---|
477 | | - __class_register(class, &__key); \ |
---|
478 | | -}) |
---|
479 | | - |
---|
480 | | -struct class_compat; |
---|
481 | | -struct class_compat *class_compat_register(const char *name); |
---|
482 | | -void class_compat_unregister(struct class_compat *cls); |
---|
483 | | -int class_compat_create_link(struct class_compat *cls, struct device *dev, |
---|
484 | | - struct device *device_link); |
---|
485 | | -void class_compat_remove_link(struct class_compat *cls, struct device *dev, |
---|
486 | | - struct device *device_link); |
---|
487 | | - |
---|
488 | | -extern void class_dev_iter_init(struct class_dev_iter *iter, |
---|
489 | | - struct class *class, |
---|
490 | | - struct device *start, |
---|
491 | | - const struct device_type *type); |
---|
492 | | -extern struct device *class_dev_iter_next(struct class_dev_iter *iter); |
---|
493 | | -extern void class_dev_iter_exit(struct class_dev_iter *iter); |
---|
494 | | - |
---|
495 | | -extern int class_for_each_device(struct class *class, struct device *start, |
---|
496 | | - void *data, |
---|
497 | | - int (*fn)(struct device *dev, void *data)); |
---|
498 | | -extern struct device *class_find_device(struct class *class, |
---|
499 | | - struct device *start, const void *data, |
---|
500 | | - int (*match)(struct device *, const void *)); |
---|
501 | | - |
---|
502 | | -struct class_attribute { |
---|
503 | | - struct attribute attr; |
---|
504 | | - ssize_t (*show)(struct class *class, struct class_attribute *attr, |
---|
505 | | - char *buf); |
---|
506 | | - ssize_t (*store)(struct class *class, struct class_attribute *attr, |
---|
507 | | - const char *buf, size_t count); |
---|
508 | | -}; |
---|
509 | | - |
---|
510 | | -#define CLASS_ATTR_RW(_name) \ |
---|
511 | | - struct class_attribute class_attr_##_name = __ATTR_RW(_name) |
---|
512 | | -#define CLASS_ATTR_RO(_name) \ |
---|
513 | | - struct class_attribute class_attr_##_name = __ATTR_RO(_name) |
---|
514 | | -#define CLASS_ATTR_WO(_name) \ |
---|
515 | | - struct class_attribute class_attr_##_name = __ATTR_WO(_name) |
---|
516 | | - |
---|
517 | | -extern int __must_check class_create_file_ns(struct class *class, |
---|
518 | | - const struct class_attribute *attr, |
---|
519 | | - const void *ns); |
---|
520 | | -extern void class_remove_file_ns(struct class *class, |
---|
521 | | - const struct class_attribute *attr, |
---|
522 | | - const void *ns); |
---|
523 | | - |
---|
524 | | -static inline int __must_check class_create_file(struct class *class, |
---|
525 | | - const struct class_attribute *attr) |
---|
526 | | -{ |
---|
527 | | - return class_create_file_ns(class, attr, NULL); |
---|
528 | | -} |
---|
529 | | - |
---|
530 | | -static inline void class_remove_file(struct class *class, |
---|
531 | | - const struct class_attribute *attr) |
---|
532 | | -{ |
---|
533 | | - return class_remove_file_ns(class, attr, NULL); |
---|
534 | | -} |
---|
535 | | - |
---|
536 | | -/* Simple class attribute that is just a static string */ |
---|
537 | | -struct class_attribute_string { |
---|
538 | | - struct class_attribute attr; |
---|
539 | | - char *str; |
---|
540 | | -}; |
---|
541 | | - |
---|
542 | | -/* Currently read-only only */ |
---|
543 | | -#define _CLASS_ATTR_STRING(_name, _mode, _str) \ |
---|
544 | | - { __ATTR(_name, _mode, show_class_attr_string, NULL), _str } |
---|
545 | | -#define CLASS_ATTR_STRING(_name, _mode, _str) \ |
---|
546 | | - struct class_attribute_string class_attr_##_name = \ |
---|
547 | | - _CLASS_ATTR_STRING(_name, _mode, _str) |
---|
548 | | - |
---|
549 | | -extern ssize_t show_class_attr_string(struct class *class, struct class_attribute *attr, |
---|
550 | | - char *buf); |
---|
551 | | - |
---|
552 | | -struct class_interface { |
---|
553 | | - struct list_head node; |
---|
554 | | - struct class *class; |
---|
555 | | - |
---|
556 | | - int (*add_dev) (struct device *, struct class_interface *); |
---|
557 | | - void (*remove_dev) (struct device *, struct class_interface *); |
---|
558 | | -}; |
---|
559 | | - |
---|
560 | | -extern int __must_check class_interface_register(struct class_interface *); |
---|
561 | | -extern void class_interface_unregister(struct class_interface *); |
---|
562 | | - |
---|
563 | | -extern struct class * __must_check __class_create(struct module *owner, |
---|
564 | | - const char *name, |
---|
565 | | - struct lock_class_key *key); |
---|
566 | | -extern void class_destroy(struct class *cls); |
---|
567 | | - |
---|
568 | | -/* This is a #define to keep the compiler from merging different |
---|
569 | | - * instances of the __key variable */ |
---|
570 | | -#define class_create(owner, name) \ |
---|
571 | | -({ \ |
---|
572 | | - static struct lock_class_key __key; \ |
---|
573 | | - __class_create(owner, name, &__key); \ |
---|
574 | | -}) |
---|
575 | 78 | |
---|
576 | 79 | /* |
---|
577 | 80 | * The type of device, "struct device" is embedded in. A class |
---|
.. | .. |
---|
627 | 130 | __ATTR_PREALLOC(_name, _mode, _show, _store) |
---|
628 | 131 | #define DEVICE_ATTR_RW(_name) \ |
---|
629 | 132 | struct device_attribute dev_attr_##_name = __ATTR_RW(_name) |
---|
| 133 | +#define DEVICE_ATTR_ADMIN_RW(_name) \ |
---|
| 134 | + struct device_attribute dev_attr_##_name = __ATTR_RW_MODE(_name, 0600) |
---|
630 | 135 | #define DEVICE_ATTR_RO(_name) \ |
---|
631 | 136 | struct device_attribute dev_attr_##_name = __ATTR_RO(_name) |
---|
| 137 | +#define DEVICE_ATTR_ADMIN_RO(_name) \ |
---|
| 138 | + struct device_attribute dev_attr_##_name = __ATTR_RO_MODE(_name, 0400) |
---|
632 | 139 | #define DEVICE_ATTR_WO(_name) \ |
---|
633 | 140 | struct device_attribute dev_attr_##_name = __ATTR_WO(_name) |
---|
634 | 141 | #define DEVICE_ULONG_ATTR(_name, _mode, _var) \ |
---|
.. | .. |
---|
644 | 151 | struct device_attribute dev_attr_##_name = \ |
---|
645 | 152 | __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) |
---|
646 | 153 | |
---|
647 | | -extern int device_create_file(struct device *device, |
---|
648 | | - const struct device_attribute *entry); |
---|
649 | | -extern void device_remove_file(struct device *dev, |
---|
650 | | - const struct device_attribute *attr); |
---|
651 | | -extern bool device_remove_file_self(struct device *dev, |
---|
652 | | - const struct device_attribute *attr); |
---|
653 | | -extern int __must_check device_create_bin_file(struct device *dev, |
---|
| 154 | +int device_create_file(struct device *device, |
---|
| 155 | + const struct device_attribute *entry); |
---|
| 156 | +void device_remove_file(struct device *dev, |
---|
| 157 | + const struct device_attribute *attr); |
---|
| 158 | +bool device_remove_file_self(struct device *dev, |
---|
| 159 | + const struct device_attribute *attr); |
---|
| 160 | +int __must_check device_create_bin_file(struct device *dev, |
---|
654 | 161 | const struct bin_attribute *attr); |
---|
655 | | -extern void device_remove_bin_file(struct device *dev, |
---|
656 | | - const struct bin_attribute *attr); |
---|
| 162 | +void device_remove_bin_file(struct device *dev, |
---|
| 163 | + const struct bin_attribute *attr); |
---|
657 | 164 | |
---|
658 | 165 | /* device resource management */ |
---|
659 | 166 | typedef void (*dr_release_t)(struct device *dev, void *res); |
---|
660 | 167 | typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data); |
---|
661 | 168 | |
---|
662 | 169 | #ifdef CONFIG_DEBUG_DEVRES |
---|
663 | | -extern void *__devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, |
---|
664 | | - int nid, const char *name) __malloc; |
---|
| 170 | +void *__devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, |
---|
| 171 | + int nid, const char *name) __malloc; |
---|
665 | 172 | #define devres_alloc(release, size, gfp) \ |
---|
666 | 173 | __devres_alloc_node(release, size, gfp, NUMA_NO_NODE, #release) |
---|
667 | 174 | #define devres_alloc_node(release, size, gfp, nid) \ |
---|
668 | 175 | __devres_alloc_node(release, size, gfp, nid, #release) |
---|
669 | 176 | #else |
---|
670 | | -extern void *devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, |
---|
671 | | - int nid) __malloc; |
---|
| 177 | +void *devres_alloc_node(dr_release_t release, size_t size, |
---|
| 178 | + gfp_t gfp, int nid) __malloc; |
---|
672 | 179 | static inline void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp) |
---|
673 | 180 | { |
---|
674 | 181 | return devres_alloc_node(release, size, gfp, NUMA_NO_NODE); |
---|
675 | 182 | } |
---|
676 | 183 | #endif |
---|
677 | 184 | |
---|
678 | | -extern void devres_for_each_res(struct device *dev, dr_release_t release, |
---|
679 | | - dr_match_t match, void *match_data, |
---|
680 | | - void (*fn)(struct device *, void *, void *), |
---|
681 | | - void *data); |
---|
682 | | -extern void devres_free(void *res); |
---|
683 | | -extern void devres_add(struct device *dev, void *res); |
---|
684 | | -extern void *devres_find(struct device *dev, dr_release_t release, |
---|
685 | | - dr_match_t match, void *match_data); |
---|
686 | | -extern void *devres_get(struct device *dev, void *new_res, |
---|
687 | | - dr_match_t match, void *match_data); |
---|
688 | | -extern void *devres_remove(struct device *dev, dr_release_t release, |
---|
689 | | - dr_match_t match, void *match_data); |
---|
690 | | -extern int devres_destroy(struct device *dev, dr_release_t release, |
---|
691 | | - dr_match_t match, void *match_data); |
---|
692 | | -extern int devres_release(struct device *dev, dr_release_t release, |
---|
693 | | - dr_match_t match, void *match_data); |
---|
| 185 | +void devres_for_each_res(struct device *dev, dr_release_t release, |
---|
| 186 | + dr_match_t match, void *match_data, |
---|
| 187 | + void (*fn)(struct device *, void *, void *), |
---|
| 188 | + void *data); |
---|
| 189 | +void devres_free(void *res); |
---|
| 190 | +void devres_add(struct device *dev, void *res); |
---|
| 191 | +void *devres_find(struct device *dev, dr_release_t release, |
---|
| 192 | + dr_match_t match, void *match_data); |
---|
| 193 | +void *devres_get(struct device *dev, void *new_res, |
---|
| 194 | + dr_match_t match, void *match_data); |
---|
| 195 | +void *devres_remove(struct device *dev, dr_release_t release, |
---|
| 196 | + dr_match_t match, void *match_data); |
---|
| 197 | +int devres_destroy(struct device *dev, dr_release_t release, |
---|
| 198 | + dr_match_t match, void *match_data); |
---|
| 199 | +int devres_release(struct device *dev, dr_release_t release, |
---|
| 200 | + dr_match_t match, void *match_data); |
---|
694 | 201 | |
---|
695 | 202 | /* devres group */ |
---|
696 | | -extern void * __must_check devres_open_group(struct device *dev, void *id, |
---|
697 | | - gfp_t gfp); |
---|
698 | | -extern void devres_close_group(struct device *dev, void *id); |
---|
699 | | -extern void devres_remove_group(struct device *dev, void *id); |
---|
700 | | -extern int devres_release_group(struct device *dev, void *id); |
---|
| 203 | +void * __must_check devres_open_group(struct device *dev, void *id, gfp_t gfp); |
---|
| 204 | +void devres_close_group(struct device *dev, void *id); |
---|
| 205 | +void devres_remove_group(struct device *dev, void *id); |
---|
| 206 | +int devres_release_group(struct device *dev, void *id); |
---|
701 | 207 | |
---|
702 | 208 | /* managed devm_k.alloc/kfree for device drivers */ |
---|
703 | | -extern void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp) __malloc; |
---|
704 | | -extern __printf(3, 0) |
---|
705 | | -char *devm_kvasprintf(struct device *dev, gfp_t gfp, const char *fmt, |
---|
706 | | - va_list ap) __malloc; |
---|
707 | | -extern __printf(3, 4) |
---|
708 | | -char *devm_kasprintf(struct device *dev, gfp_t gfp, const char *fmt, ...) __malloc; |
---|
| 209 | +void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp) __malloc; |
---|
| 210 | +void *devm_krealloc(struct device *dev, void *ptr, size_t size, |
---|
| 211 | + gfp_t gfp) __must_check; |
---|
| 212 | +__printf(3, 0) char *devm_kvasprintf(struct device *dev, gfp_t gfp, |
---|
| 213 | + const char *fmt, va_list ap) __malloc; |
---|
| 214 | +__printf(3, 4) char *devm_kasprintf(struct device *dev, gfp_t gfp, |
---|
| 215 | + const char *fmt, ...) __malloc; |
---|
709 | 216 | static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp) |
---|
710 | 217 | { |
---|
711 | 218 | return devm_kmalloc(dev, size, gfp | __GFP_ZERO); |
---|
.. | .. |
---|
725 | 232 | { |
---|
726 | 233 | return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO); |
---|
727 | 234 | } |
---|
728 | | -extern void devm_kfree(struct device *dev, void *p); |
---|
729 | | -extern char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc; |
---|
730 | | -extern void *devm_kmemdup(struct device *dev, const void *src, size_t len, |
---|
731 | | - gfp_t gfp); |
---|
| 235 | +void devm_kfree(struct device *dev, const void *p); |
---|
| 236 | +char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc; |
---|
| 237 | +const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp); |
---|
| 238 | +void *devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp); |
---|
732 | 239 | |
---|
733 | | -extern unsigned long devm_get_free_pages(struct device *dev, |
---|
734 | | - gfp_t gfp_mask, unsigned int order); |
---|
735 | | -extern void devm_free_pages(struct device *dev, unsigned long addr); |
---|
| 240 | +unsigned long devm_get_free_pages(struct device *dev, |
---|
| 241 | + gfp_t gfp_mask, unsigned int order); |
---|
| 242 | +void devm_free_pages(struct device *dev, unsigned long addr); |
---|
736 | 243 | |
---|
737 | 244 | void __iomem *devm_ioremap_resource(struct device *dev, |
---|
738 | 245 | const struct resource *res); |
---|
| 246 | +void __iomem *devm_ioremap_resource_wc(struct device *dev, |
---|
| 247 | + const struct resource *res); |
---|
739 | 248 | |
---|
740 | 249 | void __iomem *devm_of_iomap(struct device *dev, |
---|
741 | 250 | struct device_node *node, int index, |
---|
.. | .. |
---|
744 | 253 | /* allows to add/remove a custom action to devres stack */ |
---|
745 | 254 | int devm_add_action(struct device *dev, void (*action)(void *), void *data); |
---|
746 | 255 | void devm_remove_action(struct device *dev, void (*action)(void *), void *data); |
---|
| 256 | +void devm_release_action(struct device *dev, void (*action)(void *), void *data); |
---|
747 | 257 | |
---|
748 | 258 | static inline int devm_add_action_or_reset(struct device *dev, |
---|
749 | 259 | void (*action)(void *), void *data) |
---|
.. | .. |
---|
756 | 266 | |
---|
757 | 267 | return ret; |
---|
758 | 268 | } |
---|
| 269 | + |
---|
| 270 | +#define module_driver2(__driver, __register, __unregister, ...) \ |
---|
| 271 | +static int __init __driver##_init(void) \ |
---|
| 272 | +{ \ |
---|
| 273 | + return __register(&(__driver), ##__VA_ARGS__); \ |
---|
| 274 | +} \ |
---|
| 275 | +late_initcall(__driver##_init); \ |
---|
| 276 | +static void __exit __driver##_exit(void) \ |
---|
| 277 | +{ \ |
---|
| 278 | + __unregister(&(__driver), ##__VA_ARGS__); \ |
---|
| 279 | +} \ |
---|
| 280 | +module_exit(__driver##_exit); |
---|
759 | 281 | |
---|
760 | 282 | /** |
---|
761 | 283 | * devm_alloc_percpu - Resource-managed alloc_percpu |
---|
.. | .. |
---|
782 | 304 | * sg limitations. |
---|
783 | 305 | */ |
---|
784 | 306 | unsigned int max_segment_size; |
---|
| 307 | + unsigned int min_align_mask; |
---|
785 | 308 | unsigned long segment_boundary_mask; |
---|
786 | 309 | }; |
---|
787 | | - |
---|
788 | | -/** |
---|
789 | | - * struct device_connection - Device Connection Descriptor |
---|
790 | | - * @fwnode: The device node of the connected device |
---|
791 | | - * @endpoint: The names of the two devices connected together |
---|
792 | | - * @id: Unique identifier for the connection |
---|
793 | | - * @list: List head, private, for internal use only |
---|
794 | | - * |
---|
795 | | - * NOTE: @fwnode is not used together with @endpoint. @fwnode is used when |
---|
796 | | - * platform firmware defines the connection. When the connection is registered |
---|
797 | | - * with device_connection_add() @endpoint is used instead. |
---|
798 | | - */ |
---|
799 | | -struct device_connection { |
---|
800 | | - struct fwnode_handle *fwnode; |
---|
801 | | - const char *endpoint[2]; |
---|
802 | | - const char *id; |
---|
803 | | - struct list_head list; |
---|
804 | | -}; |
---|
805 | | - |
---|
806 | | -void *device_connection_find_match(struct device *dev, const char *con_id, |
---|
807 | | - void *data, |
---|
808 | | - void *(*match)(struct device_connection *con, |
---|
809 | | - int ep, void *data)); |
---|
810 | | - |
---|
811 | | -struct device *device_connection_find(struct device *dev, const char *con_id); |
---|
812 | | - |
---|
813 | | -void device_connection_add(struct device_connection *con); |
---|
814 | | -void device_connection_remove(struct device_connection *con); |
---|
815 | | - |
---|
816 | | -/** |
---|
817 | | - * device_connections_add - Add multiple device connections at once |
---|
818 | | - * @cons: Zero terminated array of device connection descriptors |
---|
819 | | - */ |
---|
820 | | -static inline void device_connections_add(struct device_connection *cons) |
---|
821 | | -{ |
---|
822 | | - struct device_connection *c; |
---|
823 | | - |
---|
824 | | - for (c = cons; c->endpoint[0]; c++) |
---|
825 | | - device_connection_add(c); |
---|
826 | | -} |
---|
827 | | - |
---|
828 | | -/** |
---|
829 | | - * device_connections_remove - Remove multiple device connections at once |
---|
830 | | - * @cons: Zero terminated array of device connection descriptors |
---|
831 | | - */ |
---|
832 | | -static inline void device_connections_remove(struct device_connection *cons) |
---|
833 | | -{ |
---|
834 | | - struct device_connection *c; |
---|
835 | | - |
---|
836 | | - for (c = cons; c->endpoint[0]; c++) |
---|
837 | | - device_connection_remove(c); |
---|
838 | | -} |
---|
839 | 310 | |
---|
840 | 311 | /** |
---|
841 | 312 | * enum device_link_state - Device link states. |
---|
.. | .. |
---|
866 | 337 | * AUTOPROBE_CONSUMER: Probe consumer driver automatically after supplier binds. |
---|
867 | 338 | * MANAGED: The core tracks presence of supplier/consumer drivers (internal). |
---|
868 | 339 | * SYNC_STATE_ONLY: Link only affects sync_state() behavior. |
---|
| 340 | + * INFERRED: Inferred from data (eg: firmware) and not from driver actions. |
---|
869 | 341 | */ |
---|
870 | 342 | #define DL_FLAG_STATELESS BIT(0) |
---|
871 | 343 | #define DL_FLAG_AUTOREMOVE_CONSUMER BIT(1) |
---|
.. | .. |
---|
875 | 347 | #define DL_FLAG_AUTOPROBE_CONSUMER BIT(5) |
---|
876 | 348 | #define DL_FLAG_MANAGED BIT(6) |
---|
877 | 349 | #define DL_FLAG_SYNC_STATE_ONLY BIT(7) |
---|
878 | | - |
---|
879 | | -/** |
---|
880 | | - * struct device_link - Device link representation. |
---|
881 | | - * @supplier: The device on the supplier end of the link. |
---|
882 | | - * @s_node: Hook to the supplier device's list of links to consumers. |
---|
883 | | - * @consumer: The device on the consumer end of the link. |
---|
884 | | - * @c_node: Hook to the consumer device's list of links to suppliers. |
---|
885 | | - * @status: The state of the link (with respect to the presence of drivers). |
---|
886 | | - * @flags: Link flags. |
---|
887 | | - * @rpm_active: Whether or not the consumer device is runtime-PM-active. |
---|
888 | | - * @kref: Count repeated addition of the same link. |
---|
889 | | - * @rcu_head: An RCU head to use for deferred execution of SRCU callbacks. |
---|
890 | | - */ |
---|
891 | | -struct device_link { |
---|
892 | | - struct device *supplier; |
---|
893 | | - struct list_head s_node; |
---|
894 | | - struct device *consumer; |
---|
895 | | - struct list_head c_node; |
---|
896 | | - enum device_link_state status; |
---|
897 | | - u32 flags; |
---|
898 | | - refcount_t rpm_active; |
---|
899 | | - struct kref kref; |
---|
900 | | -#ifdef CONFIG_SRCU |
---|
901 | | - struct rcu_head rcu_head; |
---|
902 | | -#endif |
---|
903 | | - bool supplier_preactivated; /* Owned by consumer probe. */ |
---|
904 | | - |
---|
905 | | - ANDROID_KABI_RESERVE(1); |
---|
906 | | - ANDROID_KABI_RESERVE(2); |
---|
907 | | - ANDROID_KABI_RESERVE(3); |
---|
908 | | - ANDROID_KABI_RESERVE(4); |
---|
909 | | -}; |
---|
| 350 | +#define DL_FLAG_INFERRED BIT(8) |
---|
910 | 351 | |
---|
911 | 352 | /** |
---|
912 | 353 | * enum dl_dev_state - Device driver presence tracking information. |
---|
.. | .. |
---|
926 | 367 | * struct dev_links_info - Device data related to device links. |
---|
927 | 368 | * @suppliers: List of links to supplier devices. |
---|
928 | 369 | * @consumers: List of links to consumer devices. |
---|
929 | | - * @needs_suppliers: Hook to global list of devices waiting for suppliers. |
---|
930 | | - * @defer_hook: Hook to global list of devices that have deferred sync_state or |
---|
931 | | - * deferred fw_devlink. |
---|
932 | | - * @need_for_probe: If needs_suppliers is on a list, this indicates if the |
---|
933 | | - * suppliers are needed for probe or not. |
---|
| 370 | + * @defer_sync: Hook to global list of devices that have deferred sync_state. |
---|
934 | 371 | * @status: Driver status information. |
---|
935 | 372 | */ |
---|
936 | 373 | struct dev_links_info { |
---|
937 | 374 | struct list_head suppliers; |
---|
938 | 375 | struct list_head consumers; |
---|
939 | | - struct list_head needs_suppliers; |
---|
940 | | - struct list_head defer_hook; |
---|
941 | | - bool need_for_probe; |
---|
| 376 | + struct list_head defer_sync; |
---|
942 | 377 | enum dl_dev_state status; |
---|
943 | | - |
---|
944 | | - ANDROID_KABI_RESERVE(1); |
---|
945 | | - ANDROID_KABI_RESERVE(2); |
---|
946 | | - ANDROID_KABI_RESERVE(3); |
---|
947 | | - ANDROID_KABI_RESERVE(4); |
---|
948 | 378 | }; |
---|
949 | 379 | |
---|
950 | 380 | /** |
---|
.. | .. |
---|
961 | 391 | * This identifies the device type and carries type-specific |
---|
962 | 392 | * information. |
---|
963 | 393 | * @mutex: Mutex to synchronize calls to its driver. |
---|
| 394 | + * @lockdep_mutex: An optional debug lock that a subsystem can use as a |
---|
| 395 | + * peer lock to gain localized lockdep coverage of the device_lock. |
---|
964 | 396 | * @bus: Type of bus device is on. |
---|
965 | 397 | * @driver: Which driver has allocated this |
---|
966 | 398 | * @platform_data: Platform data specific to the device. |
---|
.. | .. |
---|
978 | 410 | * @pm_domain: Provide callbacks that are executed during system suspend, |
---|
979 | 411 | * hibernation, system resume and during runtime PM transitions |
---|
980 | 412 | * along with subsystem-level and driver-level callbacks. |
---|
| 413 | + * @em_pd: device's energy model performance domain |
---|
981 | 414 | * @pins: For device pin management. |
---|
982 | 415 | * See Documentation/driver-api/pinctl.rst for details. |
---|
983 | 416 | * @msi_list: Hosts MSI descriptors |
---|
.. | .. |
---|
988 | 421 | * @coherent_dma_mask: Like dma_mask, but for alloc_coherent mapping as not all |
---|
989 | 422 | * hardware supports 64-bit addresses for consistent allocations |
---|
990 | 423 | * such descriptors. |
---|
991 | | - * @bus_dma_mask: Mask of an upstream bridge or bus which imposes a smaller DMA |
---|
992 | | - * limit than the device itself supports. |
---|
993 | | - * @dma_pfn_offset: offset of DMA memory range relatively of RAM |
---|
| 424 | + * @bus_dma_limit: Limit of an upstream bridge or bus which imposes a smaller |
---|
| 425 | + * DMA limit than the device itself supports. |
---|
| 426 | + * @dma_range_map: map for DMA memory ranges relative to that of RAM |
---|
994 | 427 | * @dma_parms: A low level driver may set these to teach IOMMU code about |
---|
995 | 428 | * segment limitations. |
---|
996 | 429 | * @dma_pools: Dma pools (if dma'ble device). |
---|
.. | .. |
---|
1010 | 443 | * gone away. This should be set by the allocator of the |
---|
1011 | 444 | * device (i.e. the bus driver that discovered the device). |
---|
1012 | 445 | * @iommu_group: IOMMU group the device belongs to. |
---|
1013 | | - * @iommu_fwspec: IOMMU-specific properties supplied by firmware. |
---|
| 446 | + * @iommu: Per device generic IOMMU runtime data |
---|
1014 | 447 | * |
---|
1015 | 448 | * @offline_disabled: If set, the device is permanently online. |
---|
1016 | 449 | * @offline: Set after successful invocation of bus type's .offline(). |
---|
.. | .. |
---|
1019 | 452 | * @state_synced: The hardware state of this device has been synced to match |
---|
1020 | 453 | * the software state of this device by calling the driver/bus |
---|
1021 | 454 | * sync_state() callback. |
---|
| 455 | + * @dma_coherent: this particular device is dma coherent, even if the |
---|
| 456 | + * architecture supports non-coherent devices. |
---|
| 457 | + * @dma_ops_bypass: If set to %true then the dma_ops are bypassed for the |
---|
| 458 | + * streaming DMA operations (->map_* / ->unmap_* / ->sync_*), |
---|
| 459 | + * and optionall (if the coherent mask is large enough) also |
---|
| 460 | + * for dma allocations. This flag is managed by the dma ops |
---|
| 461 | + * instance from ->dma_supported. |
---|
1022 | 462 | * |
---|
1023 | 463 | * At the lowest level, every device in a Linux system is represented by an |
---|
1024 | 464 | * instance of struct device. The device structure contains the information |
---|
.. | .. |
---|
1029 | 469 | * a higher-level representation of the device. |
---|
1030 | 470 | */ |
---|
1031 | 471 | struct device { |
---|
| 472 | + struct kobject kobj; |
---|
1032 | 473 | struct device *parent; |
---|
1033 | 474 | |
---|
1034 | 475 | struct device_private *p; |
---|
1035 | 476 | |
---|
1036 | | - struct kobject kobj; |
---|
1037 | 477 | const char *init_name; /* initial name of the device */ |
---|
1038 | 478 | const struct device_type *type; |
---|
1039 | | - |
---|
1040 | | - struct mutex mutex; /* mutex to synchronize calls to |
---|
1041 | | - * its driver. |
---|
1042 | | - */ |
---|
1043 | 479 | |
---|
1044 | 480 | struct bus_type *bus; /* type of bus device is on */ |
---|
1045 | 481 | struct device_driver *driver; /* which driver has allocated this |
---|
.. | .. |
---|
1047 | 483 | void *platform_data; /* Platform specific data, device |
---|
1048 | 484 | core doesn't touch it */ |
---|
1049 | 485 | void *driver_data; /* Driver data, set and get with |
---|
1050 | | - dev_set/get_drvdata */ |
---|
| 486 | + dev_set_drvdata/dev_get_drvdata */ |
---|
| 487 | +#ifdef CONFIG_PROVE_LOCKING |
---|
| 488 | + struct mutex lockdep_mutex; |
---|
| 489 | +#endif |
---|
| 490 | + struct mutex mutex; /* mutex to synchronize calls to |
---|
| 491 | + * its driver. |
---|
| 492 | + */ |
---|
| 493 | + |
---|
1051 | 494 | struct dev_links_info links; |
---|
1052 | 495 | struct dev_pm_info power; |
---|
1053 | 496 | struct dev_pm_domain *pm_domain; |
---|
| 497 | + |
---|
| 498 | +#ifdef CONFIG_ENERGY_MODEL |
---|
| 499 | + struct em_perf_domain *em_pd; |
---|
| 500 | +#endif |
---|
1054 | 501 | |
---|
1055 | 502 | #ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN |
---|
1056 | 503 | struct irq_domain *msi_domain; |
---|
.. | .. |
---|
1061 | 508 | #ifdef CONFIG_GENERIC_MSI_IRQ |
---|
1062 | 509 | struct list_head msi_list; |
---|
1063 | 510 | #endif |
---|
1064 | | - |
---|
1065 | | -#ifdef CONFIG_NUMA |
---|
1066 | | - int numa_node; /* NUMA node this device is close to */ |
---|
1067 | | -#endif |
---|
| 511 | +#ifdef CONFIG_DMA_OPS |
---|
1068 | 512 | const struct dma_map_ops *dma_ops; |
---|
| 513 | +#endif |
---|
1069 | 514 | u64 *dma_mask; /* dma mask (if dma'able device) */ |
---|
1070 | 515 | u64 coherent_dma_mask;/* Like dma_mask, but for |
---|
1071 | 516 | alloc_coherent mappings as |
---|
1072 | 517 | not all hardware supports |
---|
1073 | 518 | 64 bit addresses for consistent |
---|
1074 | 519 | allocations such descriptors. */ |
---|
1075 | | - u64 bus_dma_mask; /* upstream dma_mask constraint */ |
---|
1076 | | - unsigned long dma_pfn_offset; |
---|
| 520 | + u64 bus_dma_limit; /* upstream dma constraint */ |
---|
| 521 | + const struct bus_dma_region *dma_range_map; |
---|
1077 | 522 | |
---|
1078 | 523 | struct device_dma_parameters *dma_parms; |
---|
1079 | 524 | |
---|
1080 | 525 | struct list_head dma_pools; /* dma pools (if dma'ble) */ |
---|
1081 | 526 | |
---|
| 527 | +#ifdef CONFIG_DMA_DECLARE_COHERENT |
---|
1082 | 528 | struct dma_coherent_mem *dma_mem; /* internal for coherent mem |
---|
1083 | 529 | override */ |
---|
| 530 | +#endif |
---|
1084 | 531 | #ifdef CONFIG_DMA_CMA |
---|
1085 | 532 | struct cma *cma_area; /* contiguous memory area for dma |
---|
1086 | 533 | allocations */ |
---|
1087 | 534 | #endif |
---|
1088 | | - struct removed_region *removed_mem; |
---|
1089 | 535 | /* arch specific additions */ |
---|
1090 | 536 | struct dev_archdata archdata; |
---|
1091 | 537 | |
---|
1092 | 538 | struct device_node *of_node; /* associated device tree node */ |
---|
1093 | 539 | struct fwnode_handle *fwnode; /* firmware device node */ |
---|
1094 | 540 | |
---|
| 541 | +#ifdef CONFIG_NUMA |
---|
| 542 | + int numa_node; /* NUMA node this device is close to */ |
---|
| 543 | +#endif |
---|
1095 | 544 | dev_t devt; /* dev_t, creates the sysfs "dev" */ |
---|
1096 | 545 | u32 id; /* device instance */ |
---|
1097 | 546 | |
---|
1098 | 547 | spinlock_t devres_lock; |
---|
1099 | 548 | struct list_head devres_head; |
---|
1100 | 549 | |
---|
1101 | | - struct klist_node knode_class; |
---|
1102 | 550 | struct class *class; |
---|
1103 | 551 | const struct attribute_group **groups; /* optional groups */ |
---|
1104 | 552 | |
---|
1105 | 553 | void (*release)(struct device *dev); |
---|
1106 | 554 | struct iommu_group *iommu_group; |
---|
1107 | | - struct iommu_fwspec *iommu_fwspec; |
---|
| 555 | + struct dev_iommu *iommu; |
---|
1108 | 556 | |
---|
1109 | 557 | bool offline_disabled:1; |
---|
1110 | 558 | bool offline:1; |
---|
1111 | 559 | bool of_node_reused:1; |
---|
1112 | 560 | bool state_synced:1; |
---|
1113 | | - |
---|
| 561 | +#if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \ |
---|
| 562 | + defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \ |
---|
| 563 | + defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL) |
---|
| 564 | + bool dma_coherent:1; |
---|
| 565 | +#endif |
---|
| 566 | +#ifdef CONFIG_DMA_OPS_BYPASS |
---|
| 567 | + bool dma_ops_bypass : 1; |
---|
| 568 | +#endif |
---|
1114 | 569 | ANDROID_KABI_RESERVE(1); |
---|
1115 | 570 | ANDROID_KABI_RESERVE(2); |
---|
1116 | 571 | ANDROID_KABI_RESERVE(3); |
---|
.. | .. |
---|
1121 | 576 | ANDROID_KABI_RESERVE(8); |
---|
1122 | 577 | }; |
---|
1123 | 578 | |
---|
| 579 | +/** |
---|
| 580 | + * struct device_link - Device link representation. |
---|
| 581 | + * @supplier: The device on the supplier end of the link. |
---|
| 582 | + * @s_node: Hook to the supplier device's list of links to consumers. |
---|
| 583 | + * @consumer: The device on the consumer end of the link. |
---|
| 584 | + * @c_node: Hook to the consumer device's list of links to suppliers. |
---|
| 585 | + * @link_dev: device used to expose link details in sysfs |
---|
| 586 | + * @status: The state of the link (with respect to the presence of drivers). |
---|
| 587 | + * @flags: Link flags. |
---|
| 588 | + * @rpm_active: Whether or not the consumer device is runtime-PM-active. |
---|
| 589 | + * @kref: Count repeated addition of the same link. |
---|
| 590 | + * @rm_work: Work structure used for removing the link. |
---|
| 591 | + * @supplier_preactivated: Supplier has been made active before consumer probe. |
---|
| 592 | + */ |
---|
| 593 | +struct device_link { |
---|
| 594 | + struct device *supplier; |
---|
| 595 | + struct list_head s_node; |
---|
| 596 | + struct device *consumer; |
---|
| 597 | + struct list_head c_node; |
---|
| 598 | + struct device link_dev; |
---|
| 599 | + enum device_link_state status; |
---|
| 600 | + u32 flags; |
---|
| 601 | + refcount_t rpm_active; |
---|
| 602 | + struct kref kref; |
---|
| 603 | +#ifdef CONFIG_SRCU |
---|
| 604 | + /* Not currently used, here for potential abi issues in the future */ |
---|
| 605 | + struct rcu_head rcu_head; |
---|
| 606 | +#endif |
---|
| 607 | + struct work_struct rm_work; |
---|
| 608 | + bool supplier_preactivated; /* Owned by consumer probe. */ |
---|
| 609 | + ANDROID_KABI_RESERVE(1); |
---|
| 610 | + ANDROID_KABI_RESERVE(2); |
---|
| 611 | +}; |
---|
| 612 | + |
---|
1124 | 613 | static inline struct device *kobj_to_dev(struct kobject *kobj) |
---|
1125 | 614 | { |
---|
1126 | 615 | return container_of(kobj, struct device, kobj); |
---|
| 616 | +} |
---|
| 617 | + |
---|
| 618 | +/** |
---|
| 619 | + * device_iommu_mapped - Returns true when the device DMA is translated |
---|
| 620 | + * by an IOMMU |
---|
| 621 | + * @dev: Device to perform the check on |
---|
| 622 | + */ |
---|
| 623 | +static inline bool device_iommu_mapped(struct device *dev) |
---|
| 624 | +{ |
---|
| 625 | + return (dev->iommu_group != NULL); |
---|
1127 | 626 | } |
---|
1128 | 627 | |
---|
1129 | 628 | /* Get the wakeup routines, which depend on struct device */ |
---|
.. | .. |
---|
1138 | 637 | return kobject_name(&dev->kobj); |
---|
1139 | 638 | } |
---|
1140 | 639 | |
---|
1141 | | -extern __printf(2, 3) |
---|
1142 | | -int dev_set_name(struct device *dev, const char *name, ...); |
---|
| 640 | +/** |
---|
| 641 | + * dev_bus_name - Return a device's bus/class name, if at all possible |
---|
| 642 | + * @dev: struct device to get the bus/class name of |
---|
| 643 | + * |
---|
| 644 | + * Will return the name of the bus/class the device is attached to. If it is |
---|
| 645 | + * not attached to a bus/class, an empty string will be returned. |
---|
| 646 | + */ |
---|
| 647 | +static inline const char *dev_bus_name(const struct device *dev) |
---|
| 648 | +{ |
---|
| 649 | + return dev->bus ? dev->bus->name : (dev->class ? dev->class->name : ""); |
---|
| 650 | +} |
---|
| 651 | + |
---|
| 652 | +__printf(2, 3) int dev_set_name(struct device *dev, const char *name, ...); |
---|
1143 | 653 | |
---|
1144 | 654 | #ifdef CONFIG_NUMA |
---|
1145 | 655 | static inline int dev_to_node(struct device *dev) |
---|
.. | .. |
---|
1153 | 663 | #else |
---|
1154 | 664 | static inline int dev_to_node(struct device *dev) |
---|
1155 | 665 | { |
---|
1156 | | - return -1; |
---|
| 666 | + return NUMA_NO_NODE; |
---|
1157 | 667 | } |
---|
1158 | 668 | static inline void set_dev_node(struct device *dev, int node) |
---|
1159 | 669 | { |
---|
.. | .. |
---|
1277 | 787 | |
---|
1278 | 788 | static inline struct device_node *dev_of_node(struct device *dev) |
---|
1279 | 789 | { |
---|
1280 | | - if (!IS_ENABLED(CONFIG_OF)) |
---|
| 790 | + if (!IS_ENABLED(CONFIG_OF) || !dev) |
---|
1281 | 791 | return NULL; |
---|
1282 | 792 | return dev->of_node; |
---|
1283 | 793 | } |
---|
.. | .. |
---|
1293 | 803 | return false; |
---|
1294 | 804 | } |
---|
1295 | 805 | |
---|
1296 | | -void driver_init(void); |
---|
1297 | | - |
---|
1298 | 806 | /* |
---|
1299 | 807 | * High level routines for use by the bus drivers |
---|
1300 | 808 | */ |
---|
1301 | | -extern int __must_check device_register(struct device *dev); |
---|
1302 | | -extern void device_unregister(struct device *dev); |
---|
1303 | | -extern void device_initialize(struct device *dev); |
---|
1304 | | -extern int __must_check device_add(struct device *dev); |
---|
1305 | | -extern void device_del(struct device *dev); |
---|
1306 | | -extern int device_for_each_child(struct device *dev, void *data, |
---|
1307 | | - int (*fn)(struct device *dev, void *data)); |
---|
1308 | | -extern int device_for_each_child_reverse(struct device *dev, void *data, |
---|
1309 | | - int (*fn)(struct device *dev, void *data)); |
---|
1310 | | -extern struct device *device_find_child(struct device *dev, void *data, |
---|
1311 | | - int (*match)(struct device *dev, void *data)); |
---|
1312 | | -extern int device_rename(struct device *dev, const char *new_name); |
---|
1313 | | -extern int device_move(struct device *dev, struct device *new_parent, |
---|
1314 | | - enum dpm_order dpm_order); |
---|
1315 | | -extern const char *device_get_devnode(struct device *dev, |
---|
1316 | | - umode_t *mode, kuid_t *uid, kgid_t *gid, |
---|
1317 | | - const char **tmp); |
---|
| 809 | +int __must_check device_register(struct device *dev); |
---|
| 810 | +void device_unregister(struct device *dev); |
---|
| 811 | +void device_initialize(struct device *dev); |
---|
| 812 | +int __must_check device_add(struct device *dev); |
---|
| 813 | +void device_del(struct device *dev); |
---|
| 814 | +int device_for_each_child(struct device *dev, void *data, |
---|
| 815 | + int (*fn)(struct device *dev, void *data)); |
---|
| 816 | +int device_for_each_child_reverse(struct device *dev, void *data, |
---|
| 817 | + int (*fn)(struct device *dev, void *data)); |
---|
| 818 | +struct device *device_find_child(struct device *dev, void *data, |
---|
| 819 | + int (*match)(struct device *dev, void *data)); |
---|
| 820 | +struct device *device_find_child_by_name(struct device *parent, |
---|
| 821 | + const char *name); |
---|
| 822 | +int device_rename(struct device *dev, const char *new_name); |
---|
| 823 | +int device_move(struct device *dev, struct device *new_parent, |
---|
| 824 | + enum dpm_order dpm_order); |
---|
| 825 | +int device_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid); |
---|
| 826 | +const char *device_get_devnode(struct device *dev, umode_t *mode, kuid_t *uid, |
---|
| 827 | + kgid_t *gid, const char **tmp); |
---|
| 828 | +int device_is_dependent(struct device *dev, void *target); |
---|
1318 | 829 | |
---|
1319 | 830 | static inline bool device_supports_offline(struct device *dev) |
---|
1320 | 831 | { |
---|
1321 | 832 | return dev->bus && dev->bus->offline && dev->bus->online; |
---|
1322 | 833 | } |
---|
1323 | 834 | |
---|
1324 | | -extern void lock_device_hotplug(void); |
---|
1325 | | -extern void unlock_device_hotplug(void); |
---|
1326 | | -extern int lock_device_hotplug_sysfs(void); |
---|
1327 | | -extern int device_offline(struct device *dev); |
---|
1328 | | -extern int device_online(struct device *dev); |
---|
1329 | | -extern void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode); |
---|
1330 | | -extern void set_secondary_fwnode(struct device *dev, struct fwnode_handle *fwnode); |
---|
| 835 | +void lock_device_hotplug(void); |
---|
| 836 | +void unlock_device_hotplug(void); |
---|
| 837 | +int lock_device_hotplug_sysfs(void); |
---|
| 838 | +int device_offline(struct device *dev); |
---|
| 839 | +int device_online(struct device *dev); |
---|
| 840 | +void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode); |
---|
| 841 | +void set_secondary_fwnode(struct device *dev, struct fwnode_handle *fwnode); |
---|
1331 | 842 | void device_set_of_node_from_dev(struct device *dev, const struct device *dev2); |
---|
| 843 | +void device_set_node(struct device *dev, struct fwnode_handle *fwnode); |
---|
1332 | 844 | |
---|
1333 | 845 | static inline int dev_num_vf(struct device *dev) |
---|
1334 | 846 | { |
---|
.. | .. |
---|
1340 | 852 | /* |
---|
1341 | 853 | * Root device objects for grouping under /sys/devices |
---|
1342 | 854 | */ |
---|
1343 | | -extern struct device *__root_device_register(const char *name, |
---|
1344 | | - struct module *owner); |
---|
| 855 | +struct device *__root_device_register(const char *name, struct module *owner); |
---|
1345 | 856 | |
---|
1346 | 857 | /* This is a macro to avoid include problems with THIS_MODULE */ |
---|
1347 | 858 | #define root_device_register(name) \ |
---|
1348 | 859 | __root_device_register(name, THIS_MODULE) |
---|
1349 | 860 | |
---|
1350 | | -extern void root_device_unregister(struct device *root); |
---|
| 861 | +void root_device_unregister(struct device *root); |
---|
1351 | 862 | |
---|
1352 | 863 | static inline void *dev_get_platdata(const struct device *dev) |
---|
1353 | 864 | { |
---|
.. | .. |
---|
1358 | 869 | * Manual binding of a device to driver. See drivers/base/bus.c |
---|
1359 | 870 | * for information on use. |
---|
1360 | 871 | */ |
---|
1361 | | -extern int __must_check device_bind_driver(struct device *dev); |
---|
1362 | | -extern void device_release_driver(struct device *dev); |
---|
1363 | | -extern int __must_check device_attach(struct device *dev); |
---|
1364 | | -extern int __must_check driver_attach(struct device_driver *drv); |
---|
1365 | | -extern void device_initial_probe(struct device *dev); |
---|
1366 | | -extern int __must_check device_reprobe(struct device *dev); |
---|
| 872 | +int __must_check device_bind_driver(struct device *dev); |
---|
| 873 | +void device_release_driver(struct device *dev); |
---|
| 874 | +int __must_check device_attach(struct device *dev); |
---|
| 875 | +int __must_check driver_attach(struct device_driver *drv); |
---|
| 876 | +void device_initial_probe(struct device *dev); |
---|
| 877 | +int __must_check device_reprobe(struct device *dev); |
---|
1367 | 878 | |
---|
1368 | | -extern bool device_is_bound(struct device *dev); |
---|
| 879 | +bool device_is_bound(struct device *dev); |
---|
1369 | 880 | |
---|
1370 | 881 | /* |
---|
1371 | 882 | * Easy functions for dynamically creating devices on the fly |
---|
1372 | 883 | */ |
---|
1373 | | -extern __printf(5, 0) |
---|
1374 | | -struct device *device_create_vargs(struct class *cls, struct device *parent, |
---|
1375 | | - dev_t devt, void *drvdata, |
---|
1376 | | - const char *fmt, va_list vargs); |
---|
1377 | | -extern __printf(5, 6) |
---|
1378 | | -struct device *device_create(struct class *cls, struct device *parent, |
---|
1379 | | - dev_t devt, void *drvdata, |
---|
1380 | | - const char *fmt, ...); |
---|
1381 | | -extern __printf(6, 7) |
---|
1382 | | -struct device *device_create_with_groups(struct class *cls, |
---|
1383 | | - struct device *parent, dev_t devt, void *drvdata, |
---|
1384 | | - const struct attribute_group **groups, |
---|
1385 | | - const char *fmt, ...); |
---|
1386 | | -extern void device_destroy(struct class *cls, dev_t devt); |
---|
| 884 | +__printf(5, 6) struct device * |
---|
| 885 | +device_create(struct class *cls, struct device *parent, dev_t devt, |
---|
| 886 | + void *drvdata, const char *fmt, ...); |
---|
| 887 | +__printf(6, 7) struct device * |
---|
| 888 | +device_create_with_groups(struct class *cls, struct device *parent, dev_t devt, |
---|
| 889 | + void *drvdata, const struct attribute_group **groups, |
---|
| 890 | + const char *fmt, ...); |
---|
| 891 | +void device_destroy(struct class *cls, dev_t devt); |
---|
1387 | 892 | |
---|
1388 | | -extern int __must_check device_add_groups(struct device *dev, |
---|
1389 | | - const struct attribute_group **groups); |
---|
1390 | | -extern void device_remove_groups(struct device *dev, |
---|
1391 | | - const struct attribute_group **groups); |
---|
| 893 | +int __must_check device_add_groups(struct device *dev, |
---|
| 894 | + const struct attribute_group **groups); |
---|
| 895 | +void device_remove_groups(struct device *dev, |
---|
| 896 | + const struct attribute_group **groups); |
---|
1392 | 897 | |
---|
1393 | 898 | static inline int __must_check device_add_group(struct device *dev, |
---|
1394 | 899 | const struct attribute_group *grp) |
---|
.. | .. |
---|
1406 | 911 | return device_remove_groups(dev, groups); |
---|
1407 | 912 | } |
---|
1408 | 913 | |
---|
1409 | | -extern int __must_check devm_device_add_groups(struct device *dev, |
---|
| 914 | +int __must_check devm_device_add_groups(struct device *dev, |
---|
1410 | 915 | const struct attribute_group **groups); |
---|
1411 | | -extern void devm_device_remove_groups(struct device *dev, |
---|
1412 | | - const struct attribute_group **groups); |
---|
1413 | | -extern int __must_check devm_device_add_group(struct device *dev, |
---|
1414 | | - const struct attribute_group *grp); |
---|
1415 | | -extern void devm_device_remove_group(struct device *dev, |
---|
1416 | | - const struct attribute_group *grp); |
---|
| 916 | +void devm_device_remove_groups(struct device *dev, |
---|
| 917 | + const struct attribute_group **groups); |
---|
| 918 | +int __must_check devm_device_add_group(struct device *dev, |
---|
| 919 | + const struct attribute_group *grp); |
---|
| 920 | +void devm_device_remove_group(struct device *dev, |
---|
| 921 | + const struct attribute_group *grp); |
---|
1417 | 922 | |
---|
1418 | 923 | /* |
---|
1419 | 924 | * Platform "fixup" functions - allow the platform to have their say |
---|
.. | .. |
---|
1430 | 935 | * get_device - atomically increment the reference count for the device. |
---|
1431 | 936 | * |
---|
1432 | 937 | */ |
---|
1433 | | -extern struct device *get_device(struct device *dev); |
---|
1434 | | -extern void put_device(struct device *dev); |
---|
1435 | | -extern bool kill_device(struct device *dev); |
---|
| 938 | +struct device *get_device(struct device *dev); |
---|
| 939 | +void put_device(struct device *dev); |
---|
| 940 | +bool kill_device(struct device *dev); |
---|
1436 | 941 | |
---|
1437 | 942 | #ifdef CONFIG_DEVTMPFS |
---|
1438 | | -extern int devtmpfs_create_node(struct device *dev); |
---|
1439 | | -extern int devtmpfs_delete_node(struct device *dev); |
---|
1440 | | -extern int devtmpfs_mount(const char *mntdir); |
---|
| 943 | +int devtmpfs_mount(void); |
---|
1441 | 944 | #else |
---|
1442 | | -static inline int devtmpfs_create_node(struct device *dev) { return 0; } |
---|
1443 | | -static inline int devtmpfs_delete_node(struct device *dev) { return 0; } |
---|
1444 | | -static inline int devtmpfs_mount(const char *mountpoint) { return 0; } |
---|
| 945 | +static inline int devtmpfs_mount(void) { return 0; } |
---|
1445 | 946 | #endif |
---|
1446 | 947 | |
---|
1447 | 948 | /* drivers/base/power/shutdown.c */ |
---|
1448 | | -extern void device_shutdown(void); |
---|
| 949 | +void device_shutdown(void); |
---|
1449 | 950 | |
---|
1450 | 951 | /* debugging and troubleshooting/diagnostic helpers. */ |
---|
1451 | | -extern const char *dev_driver_string(const struct device *dev); |
---|
| 952 | +const char *dev_driver_string(const struct device *dev); |
---|
1452 | 953 | |
---|
1453 | 954 | /* Device links interface. */ |
---|
1454 | 955 | struct device_link *device_link_add(struct device *consumer, |
---|
.. | .. |
---|
1458 | 959 | void device_links_supplier_sync_state_pause(void); |
---|
1459 | 960 | void device_links_supplier_sync_state_resume(void); |
---|
1460 | 961 | |
---|
1461 | | -#ifndef dev_fmt |
---|
1462 | | -#define dev_fmt(fmt) fmt |
---|
1463 | | -#endif |
---|
1464 | | - |
---|
1465 | | -#ifdef CONFIG_PRINTK |
---|
1466 | | - |
---|
1467 | | -__printf(3, 0) |
---|
1468 | | -int dev_vprintk_emit(int level, const struct device *dev, |
---|
1469 | | - const char *fmt, va_list args); |
---|
1470 | | -__printf(3, 4) |
---|
1471 | | -int dev_printk_emit(int level, const struct device *dev, const char *fmt, ...); |
---|
1472 | | - |
---|
1473 | | -__printf(3, 4) |
---|
1474 | | -void dev_printk(const char *level, const struct device *dev, |
---|
1475 | | - const char *fmt, ...); |
---|
1476 | | -__printf(2, 3) |
---|
1477 | | -void _dev_emerg(const struct device *dev, const char *fmt, ...); |
---|
1478 | | -__printf(2, 3) |
---|
1479 | | -void _dev_alert(const struct device *dev, const char *fmt, ...); |
---|
1480 | | -__printf(2, 3) |
---|
1481 | | -void _dev_crit(const struct device *dev, const char *fmt, ...); |
---|
1482 | | -__printf(2, 3) |
---|
1483 | | -void _dev_err(const struct device *dev, const char *fmt, ...); |
---|
1484 | | -__printf(2, 3) |
---|
1485 | | -void _dev_warn(const struct device *dev, const char *fmt, ...); |
---|
1486 | | -__printf(2, 3) |
---|
1487 | | -void _dev_notice(const struct device *dev, const char *fmt, ...); |
---|
1488 | | -__printf(2, 3) |
---|
1489 | | -void _dev_info(const struct device *dev, const char *fmt, ...); |
---|
1490 | | - |
---|
1491 | | -#else |
---|
1492 | | - |
---|
1493 | | -static inline __printf(3, 0) |
---|
1494 | | -int dev_vprintk_emit(int level, const struct device *dev, |
---|
1495 | | - const char *fmt, va_list args) |
---|
1496 | | -{ return 0; } |
---|
1497 | | -static inline __printf(3, 4) |
---|
1498 | | -int dev_printk_emit(int level, const struct device *dev, const char *fmt, ...) |
---|
1499 | | -{ return 0; } |
---|
1500 | | - |
---|
1501 | | -static inline void __dev_printk(const char *level, const struct device *dev, |
---|
1502 | | - struct va_format *vaf) |
---|
1503 | | -{} |
---|
1504 | | -static inline __printf(3, 4) |
---|
1505 | | -void dev_printk(const char *level, const struct device *dev, |
---|
1506 | | - const char *fmt, ...) |
---|
1507 | | -{} |
---|
1508 | | - |
---|
1509 | | -static inline __printf(2, 3) |
---|
1510 | | -void _dev_emerg(const struct device *dev, const char *fmt, ...) |
---|
1511 | | -{} |
---|
1512 | | -static inline __printf(2, 3) |
---|
1513 | | -void _dev_crit(const struct device *dev, const char *fmt, ...) |
---|
1514 | | -{} |
---|
1515 | | -static inline __printf(2, 3) |
---|
1516 | | -void _dev_alert(const struct device *dev, const char *fmt, ...) |
---|
1517 | | -{} |
---|
1518 | | -static inline __printf(2, 3) |
---|
1519 | | -void _dev_err(const struct device *dev, const char *fmt, ...) |
---|
1520 | | -{} |
---|
1521 | | -static inline __printf(2, 3) |
---|
1522 | | -void _dev_warn(const struct device *dev, const char *fmt, ...) |
---|
1523 | | -{} |
---|
1524 | | -static inline __printf(2, 3) |
---|
1525 | | -void _dev_notice(const struct device *dev, const char *fmt, ...) |
---|
1526 | | -{} |
---|
1527 | | -static inline __printf(2, 3) |
---|
1528 | | -void _dev_info(const struct device *dev, const char *fmt, ...) |
---|
1529 | | -{} |
---|
1530 | | - |
---|
1531 | | -#endif |
---|
1532 | | - |
---|
1533 | | -/* |
---|
1534 | | - * #defines for all the dev_<level> macros to prefix with whatever |
---|
1535 | | - * possible use of #define dev_fmt(fmt) ... |
---|
1536 | | - */ |
---|
1537 | | - |
---|
1538 | | -#define dev_emerg(dev, fmt, ...) \ |
---|
1539 | | - _dev_emerg(dev, dev_fmt(fmt), ##__VA_ARGS__) |
---|
1540 | | -#define dev_crit(dev, fmt, ...) \ |
---|
1541 | | - _dev_crit(dev, dev_fmt(fmt), ##__VA_ARGS__) |
---|
1542 | | -#define dev_alert(dev, fmt, ...) \ |
---|
1543 | | - _dev_alert(dev, dev_fmt(fmt), ##__VA_ARGS__) |
---|
1544 | | -#define dev_err(dev, fmt, ...) \ |
---|
1545 | | - _dev_err(dev, dev_fmt(fmt), ##__VA_ARGS__) |
---|
1546 | | -#define dev_warn(dev, fmt, ...) \ |
---|
1547 | | - _dev_warn(dev, dev_fmt(fmt), ##__VA_ARGS__) |
---|
1548 | | -#define dev_notice(dev, fmt, ...) \ |
---|
1549 | | - _dev_notice(dev, dev_fmt(fmt), ##__VA_ARGS__) |
---|
1550 | | -#define dev_info(dev, fmt, ...) \ |
---|
1551 | | - _dev_info(dev, dev_fmt(fmt), ##__VA_ARGS__) |
---|
1552 | | - |
---|
1553 | | -#if defined(CONFIG_DYNAMIC_DEBUG) |
---|
1554 | | -#define dev_dbg(dev, fmt, ...) \ |
---|
1555 | | - dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__) |
---|
1556 | | -#elif defined(DEBUG) |
---|
1557 | | -#define dev_dbg(dev, fmt, ...) \ |
---|
1558 | | - dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__) |
---|
1559 | | -#else |
---|
1560 | | -#define dev_dbg(dev, fmt, ...) \ |
---|
1561 | | -({ \ |
---|
1562 | | - if (0) \ |
---|
1563 | | - dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \ |
---|
1564 | | -}) |
---|
1565 | | -#endif |
---|
1566 | | - |
---|
1567 | | -#ifdef CONFIG_PRINTK |
---|
1568 | | -#define dev_level_once(dev_level, dev, fmt, ...) \ |
---|
1569 | | -do { \ |
---|
1570 | | - static bool __print_once __read_mostly; \ |
---|
1571 | | - \ |
---|
1572 | | - if (!__print_once) { \ |
---|
1573 | | - __print_once = true; \ |
---|
1574 | | - dev_level(dev, fmt, ##__VA_ARGS__); \ |
---|
1575 | | - } \ |
---|
1576 | | -} while (0) |
---|
1577 | | -#else |
---|
1578 | | -#define dev_level_once(dev_level, dev, fmt, ...) \ |
---|
1579 | | -do { \ |
---|
1580 | | - if (0) \ |
---|
1581 | | - dev_level(dev, fmt, ##__VA_ARGS__); \ |
---|
1582 | | -} while (0) |
---|
1583 | | -#endif |
---|
1584 | | - |
---|
1585 | | -#define dev_emerg_once(dev, fmt, ...) \ |
---|
1586 | | - dev_level_once(dev_emerg, dev, fmt, ##__VA_ARGS__) |
---|
1587 | | -#define dev_alert_once(dev, fmt, ...) \ |
---|
1588 | | - dev_level_once(dev_alert, dev, fmt, ##__VA_ARGS__) |
---|
1589 | | -#define dev_crit_once(dev, fmt, ...) \ |
---|
1590 | | - dev_level_once(dev_crit, dev, fmt, ##__VA_ARGS__) |
---|
1591 | | -#define dev_err_once(dev, fmt, ...) \ |
---|
1592 | | - dev_level_once(dev_err, dev, fmt, ##__VA_ARGS__) |
---|
1593 | | -#define dev_warn_once(dev, fmt, ...) \ |
---|
1594 | | - dev_level_once(dev_warn, dev, fmt, ##__VA_ARGS__) |
---|
1595 | | -#define dev_notice_once(dev, fmt, ...) \ |
---|
1596 | | - dev_level_once(dev_notice, dev, fmt, ##__VA_ARGS__) |
---|
1597 | | -#define dev_info_once(dev, fmt, ...) \ |
---|
1598 | | - dev_level_once(dev_info, dev, fmt, ##__VA_ARGS__) |
---|
1599 | | -#define dev_dbg_once(dev, fmt, ...) \ |
---|
1600 | | - dev_level_once(dev_dbg, dev, fmt, ##__VA_ARGS__) |
---|
1601 | | - |
---|
1602 | | -#define dev_level_ratelimited(dev_level, dev, fmt, ...) \ |
---|
1603 | | -do { \ |
---|
1604 | | - static DEFINE_RATELIMIT_STATE(_rs, \ |
---|
1605 | | - DEFAULT_RATELIMIT_INTERVAL, \ |
---|
1606 | | - DEFAULT_RATELIMIT_BURST); \ |
---|
1607 | | - if (__ratelimit(&_rs)) \ |
---|
1608 | | - dev_level(dev, fmt, ##__VA_ARGS__); \ |
---|
1609 | | -} while (0) |
---|
1610 | | - |
---|
1611 | | -#define dev_emerg_ratelimited(dev, fmt, ...) \ |
---|
1612 | | - dev_level_ratelimited(dev_emerg, dev, fmt, ##__VA_ARGS__) |
---|
1613 | | -#define dev_alert_ratelimited(dev, fmt, ...) \ |
---|
1614 | | - dev_level_ratelimited(dev_alert, dev, fmt, ##__VA_ARGS__) |
---|
1615 | | -#define dev_crit_ratelimited(dev, fmt, ...) \ |
---|
1616 | | - dev_level_ratelimited(dev_crit, dev, fmt, ##__VA_ARGS__) |
---|
1617 | | -#define dev_err_ratelimited(dev, fmt, ...) \ |
---|
1618 | | - dev_level_ratelimited(dev_err, dev, fmt, ##__VA_ARGS__) |
---|
1619 | | -#define dev_warn_ratelimited(dev, fmt, ...) \ |
---|
1620 | | - dev_level_ratelimited(dev_warn, dev, fmt, ##__VA_ARGS__) |
---|
1621 | | -#define dev_notice_ratelimited(dev, fmt, ...) \ |
---|
1622 | | - dev_level_ratelimited(dev_notice, dev, fmt, ##__VA_ARGS__) |
---|
1623 | | -#define dev_info_ratelimited(dev, fmt, ...) \ |
---|
1624 | | - dev_level_ratelimited(dev_info, dev, fmt, ##__VA_ARGS__) |
---|
1625 | | -#if defined(CONFIG_DYNAMIC_DEBUG) |
---|
1626 | | -/* descriptor check is first to prevent flooding with "callbacks suppressed" */ |
---|
1627 | | -#define dev_dbg_ratelimited(dev, fmt, ...) \ |
---|
1628 | | -do { \ |
---|
1629 | | - static DEFINE_RATELIMIT_STATE(_rs, \ |
---|
1630 | | - DEFAULT_RATELIMIT_INTERVAL, \ |
---|
1631 | | - DEFAULT_RATELIMIT_BURST); \ |
---|
1632 | | - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ |
---|
1633 | | - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \ |
---|
1634 | | - __ratelimit(&_rs)) \ |
---|
1635 | | - __dynamic_dev_dbg(&descriptor, dev, dev_fmt(fmt), \ |
---|
1636 | | - ##__VA_ARGS__); \ |
---|
1637 | | -} while (0) |
---|
1638 | | -#elif defined(DEBUG) |
---|
1639 | | -#define dev_dbg_ratelimited(dev, fmt, ...) \ |
---|
1640 | | -do { \ |
---|
1641 | | - static DEFINE_RATELIMIT_STATE(_rs, \ |
---|
1642 | | - DEFAULT_RATELIMIT_INTERVAL, \ |
---|
1643 | | - DEFAULT_RATELIMIT_BURST); \ |
---|
1644 | | - if (__ratelimit(&_rs)) \ |
---|
1645 | | - dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \ |
---|
1646 | | -} while (0) |
---|
1647 | | -#else |
---|
1648 | | -#define dev_dbg_ratelimited(dev, fmt, ...) \ |
---|
1649 | | -do { \ |
---|
1650 | | - if (0) \ |
---|
1651 | | - dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \ |
---|
1652 | | -} while (0) |
---|
1653 | | -#endif |
---|
1654 | | - |
---|
1655 | | -#ifdef VERBOSE_DEBUG |
---|
1656 | | -#define dev_vdbg dev_dbg |
---|
1657 | | -#else |
---|
1658 | | -#define dev_vdbg(dev, fmt, ...) \ |
---|
1659 | | -({ \ |
---|
1660 | | - if (0) \ |
---|
1661 | | - dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \ |
---|
1662 | | -}) |
---|
1663 | | -#endif |
---|
1664 | | - |
---|
1665 | | -/* |
---|
1666 | | - * dev_WARN*() acts like dev_printk(), but with the key difference of |
---|
1667 | | - * using WARN/WARN_ONCE to include file/line information and a backtrace. |
---|
1668 | | - */ |
---|
1669 | | -#define dev_WARN(dev, format, arg...) \ |
---|
1670 | | - WARN(1, "%s %s: " format, dev_driver_string(dev), dev_name(dev), ## arg); |
---|
1671 | | - |
---|
1672 | | -#define dev_WARN_ONCE(dev, condition, format, arg...) \ |
---|
1673 | | - WARN_ONCE(condition, "%s %s: " format, \ |
---|
1674 | | - dev_driver_string(dev), dev_name(dev), ## arg) |
---|
| 962 | +extern __printf(3, 4) |
---|
| 963 | +int dev_err_probe(const struct device *dev, int err, const char *fmt, ...); |
---|
1675 | 964 | |
---|
1676 | 965 | /* Create alias, so I can be autoloaded. */ |
---|
1677 | 966 | #define MODULE_ALIAS_CHARDEV(major,minor) \ |
---|
.. | .. |
---|
1684 | 973 | #else |
---|
1685 | 974 | #define sysfs_deprecated 0 |
---|
1686 | 975 | #endif |
---|
1687 | | - |
---|
1688 | | -/** |
---|
1689 | | - * module_driver() - Helper macro for drivers that don't do anything |
---|
1690 | | - * special in module init/exit. This eliminates a lot of boilerplate. |
---|
1691 | | - * Each module may only use this macro once, and calling it replaces |
---|
1692 | | - * module_init() and module_exit(). |
---|
1693 | | - * |
---|
1694 | | - * @__driver: driver name |
---|
1695 | | - * @__register: register function for this driver type |
---|
1696 | | - * @__unregister: unregister function for this driver type |
---|
1697 | | - * @...: Additional arguments to be passed to __register and __unregister. |
---|
1698 | | - * |
---|
1699 | | - * Use this macro to construct bus specific macros for registering |
---|
1700 | | - * drivers, and do not use it on its own. |
---|
1701 | | - */ |
---|
1702 | | -#define module_driver(__driver, __register, __unregister, ...) \ |
---|
1703 | | -static int __init __driver##_init(void) \ |
---|
1704 | | -{ \ |
---|
1705 | | - return __register(&(__driver) , ##__VA_ARGS__); \ |
---|
1706 | | -} \ |
---|
1707 | | -module_init(__driver##_init); \ |
---|
1708 | | -static void __exit __driver##_exit(void) \ |
---|
1709 | | -{ \ |
---|
1710 | | - __unregister(&(__driver) , ##__VA_ARGS__); \ |
---|
1711 | | -} \ |
---|
1712 | | -module_exit(__driver##_exit); |
---|
1713 | | - |
---|
1714 | | -#define module_driver1(__driver, __register, __unregister, ...) \ |
---|
1715 | | -static int __init __driver##_init(void) \ |
---|
1716 | | -{ \ |
---|
1717 | | - return __register(&(__driver) , ##__VA_ARGS__); \ |
---|
1718 | | -} \ |
---|
1719 | | -arch_initcall(__driver##_init); \ |
---|
1720 | | -static void __exit __driver##_exit(void) \ |
---|
1721 | | -{ \ |
---|
1722 | | - __unregister(&(__driver) , ##__VA_ARGS__); \ |
---|
1723 | | -} \ |
---|
1724 | | -module_exit(__driver##_exit); |
---|
1725 | | -/** |
---|
1726 | | - * builtin_driver() - Helper macro for drivers that don't do anything |
---|
1727 | | - * special in init and have no exit. This eliminates some boilerplate. |
---|
1728 | | - * Each driver may only use this macro once, and calling it replaces |
---|
1729 | | - * device_initcall (or in some cases, the legacy __initcall). This is |
---|
1730 | | - * meant to be a direct parallel of module_driver() above but without |
---|
1731 | | - * the __exit stuff that is not used for builtin cases. |
---|
1732 | | - * |
---|
1733 | | - * @__driver: driver name |
---|
1734 | | - * @__register: register function for this driver type |
---|
1735 | | - * @...: Additional arguments to be passed to __register |
---|
1736 | | - * |
---|
1737 | | - * Use this macro to construct bus specific macros for registering |
---|
1738 | | - * drivers, and do not use it on its own. |
---|
1739 | | - */ |
---|
1740 | | -#define builtin_driver(__driver, __register, ...) \ |
---|
1741 | | -static int __init __driver##_init(void) \ |
---|
1742 | | -{ \ |
---|
1743 | | - return __register(&(__driver) , ##__VA_ARGS__); \ |
---|
1744 | | -} \ |
---|
1745 | | -device_initcall(__driver##_init); |
---|
1746 | 976 | |
---|
1747 | 977 | #endif /* _DEVICE_H_ */ |
---|