]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * device.h - generic, centralized driver model | |
3 | * | |
4 | * Copyright (c) 2001-2003 Patrick Mochel <mochel@osdl.org> | |
b4028437 GKH |
5 | * Copyright (c) 2004-2009 Greg Kroah-Hartman <gregkh@suse.de> |
6 | * Copyright (c) 2008-2009 Novell Inc. | |
1da177e4 LT |
7 | * |
8 | * This file is released under the GPLv2 | |
9 | * | |
10 | * See Documentation/driver-model/ for more information. | |
11 | */ | |
12 | ||
13 | #ifndef _DEVICE_H_ | |
14 | #define _DEVICE_H_ | |
15 | ||
1da177e4 LT |
16 | #include <linux/ioport.h> |
17 | #include <linux/kobject.h> | |
465c7a3a | 18 | #include <linux/klist.h> |
1da177e4 | 19 | #include <linux/list.h> |
d2a3b914 | 20 | #include <linux/lockdep.h> |
4a7fb636 | 21 | #include <linux/compiler.h> |
1da177e4 | 22 | #include <linux/types.h> |
de477254 | 23 | #include <linux/mutex.h> |
ab78029e | 24 | #include <linux/pinctrl/devinfo.h> |
1da177e4 | 25 | #include <linux/pm.h> |
60063497 | 26 | #include <linux/atomic.h> |
6ca04593 | 27 | #include <linux/ratelimit.h> |
c6dbaef2 | 28 | #include <asm/device.h> |
1da177e4 | 29 | |
1da177e4 | 30 | struct device; |
fb069a5d | 31 | struct device_private; |
1da177e4 | 32 | struct device_driver; |
e5dd1278 | 33 | struct driver_private; |
de477254 | 34 | struct module; |
1da177e4 | 35 | struct class; |
6b6e39a6 | 36 | struct subsys_private; |
b8c5cec2 | 37 | struct bus_type; |
d706c1b0 | 38 | struct device_node; |
ff21776d | 39 | struct iommu_ops; |
74416e1e | 40 | struct iommu_group; |
b8c5cec2 KS |
41 | |
42 | struct bus_attribute { | |
43 | struct attribute attr; | |
d462943a GKH |
44 | ssize_t (*show)(struct bus_type *bus, char *buf); |
45 | ssize_t (*store)(struct bus_type *bus, const char *buf, size_t count); | |
b8c5cec2 KS |
46 | }; |
47 | ||
d462943a GKH |
48 | #define BUS_ATTR(_name, _mode, _show, _store) \ |
49 | struct bus_attribute bus_attr_##_name = __ATTR(_name, _mode, _show, _store) | |
b8c5cec2 KS |
50 | |
51 | extern int __must_check bus_create_file(struct bus_type *, | |
52 | struct bus_attribute *); | |
53 | extern void bus_remove_file(struct bus_type *, struct bus_attribute *); | |
1da177e4 | 54 | |
880ffb5c WG |
55 | /** |
56 | * struct bus_type - The bus type of the device | |
57 | * | |
58 | * @name: The name of the bus. | |
ca22e56d KS |
59 | * @dev_name: Used for subsystems to enumerate devices like ("foo%u", dev->id). |
60 | * @dev_root: Default device to use as the parent. | |
880ffb5c WG |
61 | * @bus_attrs: Default attributes of the bus. |
62 | * @dev_attrs: Default attributes of the devices on the bus. | |
63 | * @drv_attrs: Default attributes of the device drivers on the bus. | |
64 | * @match: Called, perhaps multiple times, whenever a new device or driver | |
65 | * is added for this bus. It should return a nonzero value if the | |
66 | * given device can be handled by the given driver. | |
67 | * @uevent: Called when a device is added, removed, or a few other things | |
68 | * that generate uevents to add the environment variables. | |
69 | * @probe: Called when a new device or driver add to this bus, and callback | |
70 | * the specific driver's probe to initial the matched device. | |
71 | * @remove: Called when a device removed from this bus. | |
72 | * @shutdown: Called at shut-down time to quiesce the device. | |
73 | * @suspend: Called when a device on this bus wants to go to sleep mode. | |
74 | * @resume: Called to bring a device on this bus out of sleep mode. | |
75 | * @pm: Power management operations of this bus, callback the specific | |
76 | * device driver's pm-ops. | |
7b08fae8 | 77 | * @iommu_ops: IOMMU specific operations for this bus, used to attach IOMMU |
ff21776d JR |
78 | * driver implementations to a bus and allow the driver to do |
79 | * bus-specific setup | |
880ffb5c WG |
80 | * @p: The private data of the driver core, only the driver core can |
81 | * touch this. | |
82 | * | |
83 | * A bus is a channel between the processor and one or more devices. For the | |
84 | * purposes of the device model, all devices are connected via a bus, even if | |
85 | * it is an internal, virtual, "platform" bus. Buses can plug into each other. | |
86 | * A USB controller is usually a PCI device, for example. The device model | |
87 | * represents the actual connections between buses and the devices they control. | |
88 | * A bus is represented by the bus_type structure. It contains the name, the | |
89 | * default attributes, the bus' methods, PM operations, and the driver core's | |
90 | * private data. | |
91 | */ | |
1da177e4 | 92 | struct bus_type { |
d462943a | 93 | const char *name; |
ca22e56d KS |
94 | const char *dev_name; |
95 | struct device *dev_root; | |
d462943a GKH |
96 | struct bus_attribute *bus_attrs; |
97 | struct device_attribute *dev_attrs; | |
98 | struct driver_attribute *drv_attrs; | |
99 | ||
100 | int (*match)(struct device *dev, struct device_driver *drv); | |
101 | int (*uevent)(struct device *dev, struct kobj_uevent_env *env); | |
102 | int (*probe)(struct device *dev); | |
103 | int (*remove)(struct device *dev); | |
104 | void (*shutdown)(struct device *dev); | |
105 | ||
106 | int (*suspend)(struct device *dev, pm_message_t state); | |
d462943a | 107 | int (*resume)(struct device *dev); |
b8c5cec2 | 108 | |
8150f32b | 109 | const struct dev_pm_ops *pm; |
1eede070 | 110 | |
ff21776d JR |
111 | struct iommu_ops *iommu_ops; |
112 | ||
6b6e39a6 | 113 | struct subsys_private *p; |
be871b7e | 114 | struct lock_class_key lock_key; |
1da177e4 LT |
115 | }; |
116 | ||
be871b7e MH |
117 | extern int __must_check bus_register(struct bus_type *bus); |
118 | ||
d462943a | 119 | extern void bus_unregister(struct bus_type *bus); |
1da177e4 | 120 | |
d462943a | 121 | extern int __must_check bus_rescan_devices(struct bus_type *bus); |
1da177e4 | 122 | |
1da177e4 | 123 | /* iterator helpers for buses */ |
ca22e56d KS |
124 | struct subsys_dev_iter { |
125 | struct klist_iter ki; | |
126 | const struct device_type *type; | |
127 | }; | |
7cd9c9bb | 128 | void subsys_dev_iter_init(struct subsys_dev_iter *iter, |
ca22e56d KS |
129 | struct bus_type *subsys, |
130 | struct device *start, | |
131 | const struct device_type *type); | |
132 | struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter); | |
133 | void subsys_dev_iter_exit(struct subsys_dev_iter *iter); | |
1da177e4 | 134 | |
d462943a GKH |
135 | int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, |
136 | int (*fn)(struct device *dev, void *data)); | |
137 | struct device *bus_find_device(struct bus_type *bus, struct device *start, | |
138 | void *data, | |
139 | int (*match)(struct device *dev, void *data)); | |
1f9ffc04 GKH |
140 | struct device *bus_find_device_by_name(struct bus_type *bus, |
141 | struct device *start, | |
142 | const char *name); | |
ca22e56d KS |
143 | struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id, |
144 | struct device *hint); | |
cc7447a5 JD |
145 | int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, |
146 | void *data, int (*fn)(struct device_driver *, void *)); | |
99178b03 GKH |
147 | void bus_sort_breadthfirst(struct bus_type *bus, |
148 | int (*compare)(const struct device *a, | |
149 | const struct device *b)); | |
116af378 BH |
150 | /* |
151 | * Bus notifiers: Get notified of addition/removal of devices | |
152 | * and binding/unbinding of drivers to devices. | |
153 | * In the long run, it should be a replacement for the platform | |
154 | * notify hooks. | |
155 | */ | |
156 | struct notifier_block; | |
157 | ||
158 | extern int bus_register_notifier(struct bus_type *bus, | |
159 | struct notifier_block *nb); | |
160 | extern int bus_unregister_notifier(struct bus_type *bus, | |
161 | struct notifier_block *nb); | |
162 | ||
163 | /* All 4 notifers below get called with the target struct device * | |
164 | * as an argument. Note that those functions are likely to be called | |
8e9394ce | 165 | * with the device lock held in the core, so be careful. |
116af378 BH |
166 | */ |
167 | #define BUS_NOTIFY_ADD_DEVICE 0x00000001 /* device added */ | |
168 | #define BUS_NOTIFY_DEL_DEVICE 0x00000002 /* device removed */ | |
45daef0f MD |
169 | #define BUS_NOTIFY_BIND_DRIVER 0x00000003 /* driver about to be |
170 | bound */ | |
171 | #define BUS_NOTIFY_BOUND_DRIVER 0x00000004 /* driver bound to device */ | |
172 | #define BUS_NOTIFY_UNBIND_DRIVER 0x00000005 /* driver about to be | |
116af378 | 173 | unbound */ |
45daef0f | 174 | #define BUS_NOTIFY_UNBOUND_DRIVER 0x00000006 /* driver is unbound |
309b7d60 | 175 | from the device */ |
116af378 | 176 | |
0fed80f7 | 177 | extern struct kset *bus_get_kset(struct bus_type *bus); |
b249072e | 178 | extern struct klist *bus_get_device_klist(struct bus_type *bus); |
0fed80f7 | 179 | |
880ffb5c WG |
180 | /** |
181 | * struct device_driver - The basic device driver structure | |
182 | * @name: Name of the device driver. | |
183 | * @bus: The bus which the device of this driver belongs to. | |
184 | * @owner: The module owner. | |
185 | * @mod_name: Used for built-in modules. | |
186 | * @suppress_bind_attrs: Disables bind/unbind via sysfs. | |
187 | * @of_match_table: The open firmware table. | |
06f64c8f | 188 | * @acpi_match_table: The ACPI match table. |
880ffb5c WG |
189 | * @probe: Called to query the existence of a specific device, |
190 | * whether this driver can work with it, and bind the driver | |
191 | * to a specific device. | |
192 | * @remove: Called when the device is removed from the system to | |
193 | * unbind a device from this driver. | |
194 | * @shutdown: Called at shut-down time to quiesce the device. | |
195 | * @suspend: Called to put the device to sleep mode. Usually to a | |
196 | * low power state. | |
197 | * @resume: Called to bring a device from sleep mode. | |
198 | * @groups: Default attributes that get created by the driver core | |
199 | * automatically. | |
200 | * @pm: Power management operations of the device which matched | |
201 | * this driver. | |
202 | * @p: Driver core's private data, no one other than the driver | |
203 | * core can touch this. | |
204 | * | |
205 | * The device driver-model tracks all of the drivers known to the system. | |
206 | * The main reason for this tracking is to enable the driver core to match | |
207 | * up drivers with new devices. Once drivers are known objects within the | |
208 | * system, however, a number of other things become possible. Device drivers | |
209 | * can export information and configuration variables that are independent | |
210 | * of any specific device. | |
211 | */ | |
1da177e4 | 212 | struct device_driver { |
e5dd1278 GKH |
213 | const char *name; |
214 | struct bus_type *bus; | |
1da177e4 | 215 | |
e5dd1278 | 216 | struct module *owner; |
1a6f2a75 DT |
217 | const char *mod_name; /* used for built-in modules */ |
218 | ||
219 | bool suppress_bind_attrs; /* disables bind/unbind via sysfs */ | |
1da177e4 | 220 | |
597b9d1e | 221 | const struct of_device_id *of_match_table; |
06f64c8f | 222 | const struct acpi_device_id *acpi_match_table; |
597b9d1e | 223 | |
d462943a GKH |
224 | int (*probe) (struct device *dev); |
225 | int (*remove) (struct device *dev); | |
226 | void (*shutdown) (struct device *dev); | |
227 | int (*suspend) (struct device *dev, pm_message_t state); | |
228 | int (*resume) (struct device *dev); | |
a4dbd674 | 229 | const struct attribute_group **groups; |
e5dd1278 | 230 | |
8150f32b | 231 | const struct dev_pm_ops *pm; |
1eede070 | 232 | |
e5dd1278 | 233 | struct driver_private *p; |
1da177e4 LT |
234 | }; |
235 | ||
236 | ||
d462943a GKH |
237 | extern int __must_check driver_register(struct device_driver *drv); |
238 | extern void driver_unregister(struct device_driver *drv); | |
1da177e4 | 239 | |
d462943a GKH |
240 | extern struct device_driver *driver_find(const char *name, |
241 | struct bus_type *bus); | |
d779249e | 242 | extern int driver_probe_done(void); |
b23530eb | 243 | extern void wait_for_device_probe(void); |
216773a7 | 244 | |
1da177e4 | 245 | |
405ae7d3 | 246 | /* sysfs interface for exporting driver attributes */ |
1da177e4 LT |
247 | |
248 | struct driver_attribute { | |
d462943a GKH |
249 | struct attribute attr; |
250 | ssize_t (*show)(struct device_driver *driver, char *buf); | |
251 | ssize_t (*store)(struct device_driver *driver, const char *buf, | |
252 | size_t count); | |
1da177e4 LT |
253 | }; |
254 | ||
d462943a GKH |
255 | #define DRIVER_ATTR(_name, _mode, _show, _store) \ |
256 | struct driver_attribute driver_attr_##_name = \ | |
257 | __ATTR(_name, _mode, _show, _store) | |
1da177e4 | 258 | |
d462943a | 259 | extern int __must_check driver_create_file(struct device_driver *driver, |
099c2f21 | 260 | const struct driver_attribute *attr); |
d462943a | 261 | extern void driver_remove_file(struct device_driver *driver, |
099c2f21 | 262 | const struct driver_attribute *attr); |
1da177e4 | 263 | |
d462943a GKH |
264 | extern int __must_check driver_for_each_device(struct device_driver *drv, |
265 | struct device *start, | |
266 | void *data, | |
267 | int (*fn)(struct device *dev, | |
268 | void *)); | |
269 | struct device *driver_find_device(struct device_driver *drv, | |
270 | struct device *start, void *data, | |
271 | int (*match)(struct device *dev, void *data)); | |
fae3cd00 | 272 | |
ca22e56d KS |
273 | /** |
274 | * struct subsys_interface - interfaces to device functions | |
2eda013f RD |
275 | * @name: name of the device function |
276 | * @subsys: subsytem of the devices to attach to | |
277 | * @node: the list of functions registered at the subsystem | |
278 | * @add_dev: device hookup to device function handler | |
279 | * @remove_dev: device hookup to device function handler | |
ca22e56d KS |
280 | * |
281 | * Simple interfaces attached to a subsystem. Multiple interfaces can | |
282 | * attach to a subsystem and its devices. Unlike drivers, they do not | |
283 | * exclusively claim or control devices. Interfaces usually represent | |
284 | * a specific functionality of a subsystem/class of devices. | |
285 | */ | |
286 | struct subsys_interface { | |
287 | const char *name; | |
288 | struct bus_type *subsys; | |
289 | struct list_head node; | |
290 | int (*add_dev)(struct device *dev, struct subsys_interface *sif); | |
291 | int (*remove_dev)(struct device *dev, struct subsys_interface *sif); | |
292 | }; | |
293 | ||
294 | int subsys_interface_register(struct subsys_interface *sif); | |
295 | void subsys_interface_unregister(struct subsys_interface *sif); | |
296 | ||
297 | int subsys_system_register(struct bus_type *subsys, | |
298 | const struct attribute_group **groups); | |
299 | ||
880ffb5c WG |
300 | /** |
301 | * struct class - device classes | |
302 | * @name: Name of the class. | |
303 | * @owner: The module owner. | |
304 | * @class_attrs: Default attributes of this class. | |
305 | * @dev_attrs: Default attributes of the devices belong to the class. | |
306 | * @dev_bin_attrs: Default binary attributes of the devices belong to the class. | |
307 | * @dev_kobj: The kobject that represents this class and links it into the hierarchy. | |
308 | * @dev_uevent: Called when a device is added, removed from this class, or a | |
309 | * few other things that generate uevents to add the environment | |
310 | * variables. | |
311 | * @devnode: Callback to provide the devtmpfs. | |
312 | * @class_release: Called to release this class. | |
313 | * @dev_release: Called to release the device. | |
314 | * @suspend: Used to put the device to sleep mode, usually to a low power | |
315 | * state. | |
316 | * @resume: Used to bring the device from the sleep mode. | |
317 | * @ns_type: Callbacks so sysfs can detemine namespaces. | |
318 | * @namespace: Namespace of the device belongs to this class. | |
319 | * @pm: The default device power management operations of this class. | |
320 | * @p: The private data of the driver core, no one other than the | |
321 | * driver core can touch this. | |
322 | * | |
323 | * A class is a higher-level view of a device that abstracts out low-level | |
324 | * implementation details. Drivers may see a SCSI disk or an ATA disk, but, | |
325 | * at the class level, they are all simply disks. Classes allow user space | |
326 | * to work with devices based on what they do, rather than how they are | |
327 | * connected or how they work. | |
1da177e4 LT |
328 | */ |
329 | struct class { | |
d462943a GKH |
330 | const char *name; |
331 | struct module *owner; | |
1da177e4 | 332 | |
d462943a | 333 | struct class_attribute *class_attrs; |
d462943a | 334 | struct device_attribute *dev_attrs; |
c97415a7 | 335 | struct bin_attribute *dev_bin_attrs; |
e105b8bf | 336 | struct kobject *dev_kobj; |
1da177e4 | 337 | |
d462943a | 338 | int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env); |
2c9ede55 | 339 | char *(*devnode)(struct device *dev, umode_t *mode); |
1da177e4 | 340 | |
d462943a GKH |
341 | void (*class_release)(struct class *class); |
342 | void (*dev_release)(struct device *dev); | |
7c8265f5 | 343 | |
d462943a GKH |
344 | int (*suspend)(struct device *dev, pm_message_t state); |
345 | int (*resume)(struct device *dev); | |
1eede070 | 346 | |
bc451f20 EB |
347 | const struct kobj_ns_type_operations *ns_type; |
348 | const void *(*namespace)(struct device *dev); | |
349 | ||
8150f32b DT |
350 | const struct dev_pm_ops *pm; |
351 | ||
6b6e39a6 | 352 | struct subsys_private *p; |
1da177e4 LT |
353 | }; |
354 | ||
5a3ceb86 TH |
355 | struct class_dev_iter { |
356 | struct klist_iter ki; | |
357 | const struct device_type *type; | |
358 | }; | |
359 | ||
e105b8bf DW |
360 | extern struct kobject *sysfs_dev_block_kobj; |
361 | extern struct kobject *sysfs_dev_char_kobj; | |
d2a3b914 MW |
362 | extern int __must_check __class_register(struct class *class, |
363 | struct lock_class_key *key); | |
d462943a | 364 | extern void class_unregister(struct class *class); |
d2a3b914 MW |
365 | |
366 | /* This is a #define to keep the compiler from merging different | |
367 | * instances of the __key variable */ | |
368 | #define class_register(class) \ | |
369 | ({ \ | |
370 | static struct lock_class_key __key; \ | |
371 | __class_register(class, &__key); \ | |
372 | }) | |
373 | ||
46227094 JD |
374 | struct class_compat; |
375 | struct class_compat *class_compat_register(const char *name); | |
376 | void class_compat_unregister(struct class_compat *cls); | |
377 | int class_compat_create_link(struct class_compat *cls, struct device *dev, | |
378 | struct device *device_link); | |
379 | void class_compat_remove_link(struct class_compat *cls, struct device *dev, | |
380 | struct device *device_link); | |
381 | ||
7cd9c9bb GKH |
382 | extern void class_dev_iter_init(struct class_dev_iter *iter, |
383 | struct class *class, | |
384 | struct device *start, | |
385 | const struct device_type *type); | |
5a3ceb86 TH |
386 | extern struct device *class_dev_iter_next(struct class_dev_iter *iter); |
387 | extern void class_dev_iter_exit(struct class_dev_iter *iter); | |
388 | ||
93562b53 GKH |
389 | extern int class_for_each_device(struct class *class, struct device *start, |
390 | void *data, | |
fd04897b | 391 | int (*fn)(struct device *dev, void *data)); |
695794ae | 392 | extern struct device *class_find_device(struct class *class, |
9f3b795a MM |
393 | struct device *start, const void *data, |
394 | int (*match)(struct device *, const void *)); | |
1da177e4 LT |
395 | |
396 | struct class_attribute { | |
d462943a | 397 | struct attribute attr; |
28812fe1 AK |
398 | ssize_t (*show)(struct class *class, struct class_attribute *attr, |
399 | char *buf); | |
400 | ssize_t (*store)(struct class *class, struct class_attribute *attr, | |
401 | const char *buf, size_t count); | |
672d82c1 EB |
402 | const void *(*namespace)(struct class *class, |
403 | const struct class_attribute *attr); | |
1da177e4 LT |
404 | }; |
405 | ||
d462943a GKH |
406 | #define CLASS_ATTR(_name, _mode, _show, _store) \ |
407 | struct class_attribute class_attr_##_name = __ATTR(_name, _mode, _show, _store) | |
1da177e4 | 408 | |
d462943a GKH |
409 | extern int __must_check class_create_file(struct class *class, |
410 | const struct class_attribute *attr); | |
411 | extern void class_remove_file(struct class *class, | |
412 | const struct class_attribute *attr); | |
1da177e4 | 413 | |
869dfc87 AK |
414 | /* Simple class attribute that is just a static string */ |
415 | ||
416 | struct class_attribute_string { | |
417 | struct class_attribute attr; | |
418 | char *str; | |
419 | }; | |
420 | ||
421 | /* Currently read-only only */ | |
422 | #define _CLASS_ATTR_STRING(_name, _mode, _str) \ | |
423 | { __ATTR(_name, _mode, show_class_attr_string, NULL), _str } | |
424 | #define CLASS_ATTR_STRING(_name, _mode, _str) \ | |
425 | struct class_attribute_string class_attr_##_name = \ | |
426 | _CLASS_ATTR_STRING(_name, _mode, _str) | |
427 | ||
428 | extern ssize_t show_class_attr_string(struct class *class, struct class_attribute *attr, | |
429 | char *buf); | |
430 | ||
1da177e4 LT |
431 | struct class_interface { |
432 | struct list_head node; | |
433 | struct class *class; | |
434 | ||
c47ed219 GKH |
435 | int (*add_dev) (struct device *, struct class_interface *); |
436 | void (*remove_dev) (struct device *, struct class_interface *); | |
1da177e4 LT |
437 | }; |
438 | ||
4a7fb636 | 439 | extern int __must_check class_interface_register(struct class_interface *); |
1da177e4 LT |
440 | extern void class_interface_unregister(struct class_interface *); |
441 | ||
d2a3b914 MW |
442 | extern struct class * __must_check __class_create(struct module *owner, |
443 | const char *name, | |
444 | struct lock_class_key *key); | |
e9ba6365 | 445 | extern void class_destroy(struct class *cls); |
e9ba6365 | 446 | |
d2a3b914 MW |
447 | /* This is a #define to keep the compiler from merging different |
448 | * instances of the __key variable */ | |
449 | #define class_create(owner, name) \ | |
450 | ({ \ | |
451 | static struct lock_class_key __key; \ | |
452 | __class_create(owner, name, &__key); \ | |
453 | }) | |
454 | ||
414264f9 KS |
455 | /* |
456 | * The type of device, "struct device" is embedded in. A class | |
457 | * or bus can contain devices of different types | |
458 | * like "partitions" and "disks", "mouse" and "event". | |
459 | * This identifies the device type and carries type-specific | |
460 | * information, equivalent to the kobj_type of a kobject. | |
461 | * If "name" is specified, the uevent will contain it in | |
462 | * the DEVTYPE variable. | |
463 | */ | |
f9f852df | 464 | struct device_type { |
414264f9 | 465 | const char *name; |
a4dbd674 | 466 | const struct attribute_group **groups; |
7eff2e7a | 467 | int (*uevent)(struct device *dev, struct kobj_uevent_env *env); |
2c9ede55 | 468 | char *(*devnode)(struct device *dev, umode_t *mode); |
f9f852df | 469 | void (*release)(struct device *dev); |
1eede070 | 470 | |
8150f32b | 471 | const struct dev_pm_ops *pm; |
f9f852df KS |
472 | }; |
473 | ||
a7fd6706 KS |
474 | /* interface for exporting device attributes */ |
475 | struct device_attribute { | |
476 | struct attribute attr; | |
477 | ssize_t (*show)(struct device *dev, struct device_attribute *attr, | |
478 | char *buf); | |
479 | ssize_t (*store)(struct device *dev, struct device_attribute *attr, | |
480 | const char *buf, size_t count); | |
481 | }; | |
482 | ||
ca22e56d KS |
483 | struct dev_ext_attribute { |
484 | struct device_attribute attr; | |
485 | void *var; | |
486 | }; | |
487 | ||
488 | ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr, | |
489 | char *buf); | |
490 | ssize_t device_store_ulong(struct device *dev, struct device_attribute *attr, | |
491 | const char *buf, size_t count); | |
492 | ssize_t device_show_int(struct device *dev, struct device_attribute *attr, | |
493 | char *buf); | |
494 | ssize_t device_store_int(struct device *dev, struct device_attribute *attr, | |
495 | const char *buf, size_t count); | |
91872392 BP |
496 | ssize_t device_show_bool(struct device *dev, struct device_attribute *attr, |
497 | char *buf); | |
498 | ssize_t device_store_bool(struct device *dev, struct device_attribute *attr, | |
499 | const char *buf, size_t count); | |
a7fd6706 | 500 | |
d462943a | 501 | #define DEVICE_ATTR(_name, _mode, _show, _store) \ |
ca22e56d KS |
502 | struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store) |
503 | #define DEVICE_ULONG_ATTR(_name, _mode, _var) \ | |
504 | struct dev_ext_attribute dev_attr_##_name = \ | |
505 | { __ATTR(_name, _mode, device_show_ulong, device_store_ulong), &(_var) } | |
506 | #define DEVICE_INT_ATTR(_name, _mode, _var) \ | |
507 | struct dev_ext_attribute dev_attr_##_name = \ | |
94758185 | 508 | { __ATTR(_name, _mode, device_show_int, device_store_int), &(_var) } |
91872392 BP |
509 | #define DEVICE_BOOL_ATTR(_name, _mode, _var) \ |
510 | struct dev_ext_attribute dev_attr_##_name = \ | |
511 | { __ATTR(_name, _mode, device_show_bool, device_store_bool), &(_var) } | |
356c05d5 AS |
512 | #define DEVICE_ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) \ |
513 | struct device_attribute dev_attr_##_name = \ | |
514 | __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) | |
a7fd6706 | 515 | |
b9d4e714 GKH |
516 | extern int device_create_file(struct device *device, |
517 | const struct device_attribute *entry); | |
d462943a | 518 | extern void device_remove_file(struct device *dev, |
26579ab7 | 519 | const struct device_attribute *attr); |
2589f188 | 520 | extern int __must_check device_create_bin_file(struct device *dev, |
66ecb92b | 521 | const struct bin_attribute *attr); |
2589f188 | 522 | extern void device_remove_bin_file(struct device *dev, |
66ecb92b | 523 | const struct bin_attribute *attr); |
523ded71 | 524 | extern int device_schedule_callback_owner(struct device *dev, |
d462943a | 525 | void (*func)(struct device *dev), struct module *owner); |
523ded71 AS |
526 | |
527 | /* This is a macro to avoid include problems with THIS_MODULE */ | |
528 | #define device_schedule_callback(dev, func) \ | |
529 | device_schedule_callback_owner(dev, func, THIS_MODULE) | |
9ac7849e TH |
530 | |
531 | /* device resource management */ | |
532 | typedef void (*dr_release_t)(struct device *dev, void *res); | |
533 | typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data); | |
534 | ||
535 | #ifdef CONFIG_DEBUG_DEVRES | |
d462943a | 536 | extern void *__devres_alloc(dr_release_t release, size_t size, gfp_t gfp, |
9ac7849e TH |
537 | const char *name); |
538 | #define devres_alloc(release, size, gfp) \ | |
539 | __devres_alloc(release, size, gfp, #release) | |
540 | #else | |
d462943a | 541 | extern void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp); |
9ac7849e | 542 | #endif |
bddb1b90 ML |
543 | extern void devres_for_each_res(struct device *dev, dr_release_t release, |
544 | dr_match_t match, void *match_data, | |
545 | void (*fn)(struct device *, void *, void *), | |
546 | void *data); | |
9ac7849e TH |
547 | extern void devres_free(void *res); |
548 | extern void devres_add(struct device *dev, void *res); | |
d462943a | 549 | extern void *devres_find(struct device *dev, dr_release_t release, |
9ac7849e | 550 | dr_match_t match, void *match_data); |
d462943a GKH |
551 | extern void *devres_get(struct device *dev, void *new_res, |
552 | dr_match_t match, void *match_data); | |
553 | extern void *devres_remove(struct device *dev, dr_release_t release, | |
554 | dr_match_t match, void *match_data); | |
9ac7849e TH |
555 | extern int devres_destroy(struct device *dev, dr_release_t release, |
556 | dr_match_t match, void *match_data); | |
d926d0e4 MB |
557 | extern int devres_release(struct device *dev, dr_release_t release, |
558 | dr_match_t match, void *match_data); | |
9ac7849e TH |
559 | |
560 | /* devres group */ | |
561 | extern void * __must_check devres_open_group(struct device *dev, void *id, | |
562 | gfp_t gfp); | |
563 | extern void devres_close_group(struct device *dev, void *id); | |
564 | extern void devres_remove_group(struct device *dev, void *id); | |
565 | extern int devres_release_group(struct device *dev, void *id); | |
566 | ||
567 | /* managed kzalloc/kfree for device drivers, no kmalloc, always use kzalloc */ | |
568 | extern void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp); | |
569 | extern void devm_kfree(struct device *dev, void *p); | |
570 | ||
75096579 | 571 | void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res); |
72f8c0bf WS |
572 | void __iomem *devm_request_and_ioremap(struct device *dev, |
573 | struct resource *res); | |
574 | ||
6b7b6510 FT |
575 | struct device_dma_parameters { |
576 | /* | |
577 | * a low level driver may set these to teach IOMMU code about | |
578 | * sg limitations. | |
579 | */ | |
580 | unsigned int max_segment_size; | |
581 | unsigned long segment_boundary_mask; | |
582 | }; | |
583 | ||
95f8a082 RW |
584 | struct acpi_dev_node { |
585 | #ifdef CONFIG_ACPI | |
586 | void *handle; | |
587 | #endif | |
588 | }; | |
589 | ||
880ffb5c WG |
590 | /** |
591 | * struct device - The basic device structure | |
592 | * @parent: The device's "parent" device, the device to which it is attached. | |
593 | * In most cases, a parent device is some sort of bus or host | |
594 | * controller. If parent is NULL, the device, is a top-level device, | |
595 | * which is not usually what you want. | |
596 | * @p: Holds the private data of the driver core portions of the device. | |
597 | * See the comment of the struct device_private for detail. | |
598 | * @kobj: A top-level, abstract class from which other classes are derived. | |
599 | * @init_name: Initial name of the device. | |
600 | * @type: The type of device. | |
601 | * This identifies the device type and carries type-specific | |
602 | * information. | |
603 | * @mutex: Mutex to synchronize calls to its driver. | |
604 | * @bus: Type of bus device is on. | |
605 | * @driver: Which driver has allocated this | |
606 | * @platform_data: Platform data specific to the device. | |
607 | * Example: For devices on custom boards, as typical of embedded | |
608 | * and SOC based hardware, Linux often uses platform_data to point | |
609 | * to board-specific structures describing devices and how they | |
610 | * are wired. That can include what ports are available, chip | |
611 | * variants, which GPIO pins act in what additional roles, and so | |
612 | * on. This shrinks the "Board Support Packages" (BSPs) and | |
613 | * minimizes board-specific #ifdefs in drivers. | |
614 | * @power: For device power management. | |
615 | * See Documentation/power/devices.txt for details. | |
564b905a | 616 | * @pm_domain: Provide callbacks that are executed during system suspend, |
880ffb5c WG |
617 | * hibernation, system resume and during runtime PM transitions |
618 | * along with subsystem-level and driver-level callbacks. | |
ab78029e LW |
619 | * @pins: For device pin management. |
620 | * See Documentation/pinctrl.txt for details. | |
880ffb5c WG |
621 | * @numa_node: NUMA node this device is close to. |
622 | * @dma_mask: Dma mask (if dma'ble device). | |
623 | * @coherent_dma_mask: Like dma_mask, but for alloc_coherent mapping as not all | |
624 | * hardware supports 64-bit addresses for consistent allocations | |
625 | * such descriptors. | |
626 | * @dma_parms: A low level driver may set these to teach IOMMU code about | |
627 | * segment limitations. | |
628 | * @dma_pools: Dma pools (if dma'ble device). | |
629 | * @dma_mem: Internal for coherent mem override. | |
630 | * @archdata: For arch-specific additions. | |
631 | * @of_node: Associated device tree node. | |
95f8a082 | 632 | * @acpi_node: Associated ACPI device node. |
880ffb5c | 633 | * @devt: For creating the sysfs "dev". |
2eda013f | 634 | * @id: device instance |
880ffb5c WG |
635 | * @devres_lock: Spinlock to protect the resource of the device. |
636 | * @devres_head: The resources list of the device. | |
637 | * @knode_class: The node used to add the device to the class list. | |
638 | * @class: The class of the device. | |
639 | * @groups: Optional attribute groups. | |
640 | * @release: Callback to free the device after all references have | |
641 | * gone away. This should be set by the allocator of the | |
642 | * device (i.e. the bus driver that discovered the device). | |
643 | * | |
644 | * At the lowest level, every device in a Linux system is represented by an | |
645 | * instance of struct device. The device structure contains the information | |
646 | * that the device model core needs to model the system. Most subsystems, | |
647 | * however, track additional information about the devices they host. As a | |
648 | * result, it is rare for devices to be represented by bare device structures; | |
649 | * instead, that structure, like kobject structures, is usually embedded within | |
650 | * a higher-level representation of the device. | |
651 | */ | |
1da177e4 | 652 | struct device { |
49a4ec18 | 653 | struct device *parent; |
1da177e4 | 654 | |
fb069a5d GKH |
655 | struct device_private *p; |
656 | ||
1da177e4 | 657 | struct kobject kobj; |
c906a48a | 658 | const char *init_name; /* initial name of the device */ |
aed65af1 | 659 | const struct device_type *type; |
1da177e4 | 660 | |
3142788b | 661 | struct mutex mutex; /* mutex to synchronize calls to |
af70316a PM |
662 | * its driver. |
663 | */ | |
664 | ||
d462943a | 665 | struct bus_type *bus; /* type of bus device is on */ |
1da177e4 LT |
666 | struct device_driver *driver; /* which driver has allocated this |
667 | device */ | |
e67c8562 GKH |
668 | void *platform_data; /* Platform specific data, device |
669 | core doesn't touch it */ | |
1da177e4 | 670 | struct dev_pm_info power; |
564b905a | 671 | struct dev_pm_domain *pm_domain; |
1da177e4 | 672 | |
ab78029e LW |
673 | #ifdef CONFIG_PINCTRL |
674 | struct dev_pin_info *pins; | |
675 | #endif | |
676 | ||
87348136 CH |
677 | #ifdef CONFIG_NUMA |
678 | int numa_node; /* NUMA node this device is close to */ | |
679 | #endif | |
1da177e4 LT |
680 | u64 *dma_mask; /* dma mask (if dma'able device) */ |
681 | u64 coherent_dma_mask;/* Like dma_mask, but for | |
682 | alloc_coherent mappings as | |
683 | not all hardware supports | |
684 | 64 bit addresses for consistent | |
685 | allocations such descriptors. */ | |
686 | ||
6b7b6510 FT |
687 | struct device_dma_parameters *dma_parms; |
688 | ||
1da177e4 LT |
689 | struct list_head dma_pools; /* dma pools (if dma'ble) */ |
690 | ||
691 | struct dma_coherent_mem *dma_mem; /* internal for coherent mem | |
692 | override */ | |
c64be2bb MS |
693 | #ifdef CONFIG_CMA |
694 | struct cma *cma_area; /* contiguous memory area for dma | |
695 | allocations */ | |
696 | #endif | |
c6dbaef2 BH |
697 | /* arch specific additions */ |
698 | struct dev_archdata archdata; | |
c9e358df GL |
699 | |
700 | struct device_node *of_node; /* associated device tree node */ | |
95f8a082 | 701 | struct acpi_dev_node acpi_node; /* associated ACPI device node */ |
1da177e4 | 702 | |
929d2fa5 | 703 | dev_t devt; /* dev_t, creates the sysfs "dev" */ |
ca22e56d | 704 | u32 id; /* device instance */ |
929d2fa5 | 705 | |
9ac7849e TH |
706 | spinlock_t devres_lock; |
707 | struct list_head devres_head; | |
708 | ||
5a3ceb86 | 709 | struct klist_node knode_class; |
b7a3e813 | 710 | struct class *class; |
a4dbd674 | 711 | const struct attribute_group **groups; /* optional groups */ |
23681e47 | 712 | |
d462943a | 713 | void (*release)(struct device *dev); |
74416e1e | 714 | struct iommu_group *iommu_group; |
1da177e4 LT |
715 | }; |
716 | ||
a4232963 LPC |
717 | static inline struct device *kobj_to_dev(struct kobject *kobj) |
718 | { | |
719 | return container_of(kobj, struct device, kobj); | |
720 | } | |
721 | ||
95f8a082 RW |
722 | #ifdef CONFIG_ACPI |
723 | #define ACPI_HANDLE(dev) ((dev)->acpi_node.handle) | |
724 | #define ACPI_HANDLE_SET(dev, _handle_) (dev)->acpi_node.handle = (_handle_) | |
725 | #else | |
726 | #define ACPI_HANDLE(dev) (NULL) | |
727 | #define ACPI_HANDLE_SET(dev, _handle_) do { } while (0) | |
728 | #endif | |
729 | ||
9a3df1f7 AS |
730 | /* Get the wakeup routines, which depend on struct device */ |
731 | #include <linux/pm_wakeup.h> | |
732 | ||
bf9ca69f | 733 | static inline const char *dev_name(const struct device *dev) |
06916639 | 734 | { |
a636ee7f PM |
735 | /* Use the init name until the kobject becomes available */ |
736 | if (dev->init_name) | |
737 | return dev->init_name; | |
738 | ||
1fa5ae85 | 739 | return kobject_name(&dev->kobj); |
06916639 KS |
740 | } |
741 | ||
b9075fa9 JP |
742 | extern __printf(2, 3) |
743 | int dev_set_name(struct device *dev, const char *name, ...); | |
413c239f | 744 | |
87348136 CH |
745 | #ifdef CONFIG_NUMA |
746 | static inline int dev_to_node(struct device *dev) | |
747 | { | |
748 | return dev->numa_node; | |
749 | } | |
750 | static inline void set_dev_node(struct device *dev, int node) | |
751 | { | |
752 | dev->numa_node = node; | |
753 | } | |
754 | #else | |
755 | static inline int dev_to_node(struct device *dev) | |
756 | { | |
757 | return -1; | |
758 | } | |
759 | static inline void set_dev_node(struct device *dev, int node) | |
760 | { | |
761 | } | |
762 | #endif | |
763 | ||
5c095a0e RW |
764 | static inline struct pm_subsys_data *dev_to_psd(struct device *dev) |
765 | { | |
766 | return dev ? dev->power.subsys_data : NULL; | |
767 | } | |
768 | ||
f67f129e ML |
769 | static inline unsigned int dev_get_uevent_suppress(const struct device *dev) |
770 | { | |
771 | return dev->kobj.uevent_suppress; | |
772 | } | |
773 | ||
774 | static inline void dev_set_uevent_suppress(struct device *dev, int val) | |
775 | { | |
776 | dev->kobj.uevent_suppress = val; | |
777 | } | |
778 | ||
d305ef5d DR |
779 | static inline int device_is_registered(struct device *dev) |
780 | { | |
3f62e570 | 781 | return dev->kobj.state_in_sysfs; |
d305ef5d DR |
782 | } |
783 | ||
5af84b82 RW |
784 | static inline void device_enable_async_suspend(struct device *dev) |
785 | { | |
f76b168b | 786 | if (!dev->power.is_prepared) |
5af84b82 RW |
787 | dev->power.async_suspend = true; |
788 | } | |
789 | ||
5a2eb858 RW |
790 | static inline void device_disable_async_suspend(struct device *dev) |
791 | { | |
f76b168b | 792 | if (!dev->power.is_prepared) |
5a2eb858 RW |
793 | dev->power.async_suspend = false; |
794 | } | |
795 | ||
796 | static inline bool device_async_suspend_enabled(struct device *dev) | |
797 | { | |
798 | return !!dev->power.async_suspend; | |
799 | } | |
800 | ||
8b258cc8 RW |
801 | static inline void pm_suspend_ignore_children(struct device *dev, bool enable) |
802 | { | |
803 | dev->power.ignore_children = enable; | |
804 | } | |
805 | ||
feb70af0 RW |
806 | static inline void dev_pm_syscore_device(struct device *dev, bool val) |
807 | { | |
808 | #ifdef CONFIG_PM_SLEEP | |
809 | dev->power.syscore = val; | |
810 | #endif | |
811 | } | |
812 | ||
8e9394ce GKH |
813 | static inline void device_lock(struct device *dev) |
814 | { | |
3142788b | 815 | mutex_lock(&dev->mutex); |
8e9394ce GKH |
816 | } |
817 | ||
818 | static inline int device_trylock(struct device *dev) | |
819 | { | |
3142788b | 820 | return mutex_trylock(&dev->mutex); |
8e9394ce GKH |
821 | } |
822 | ||
823 | static inline void device_unlock(struct device *dev) | |
824 | { | |
3142788b | 825 | mutex_unlock(&dev->mutex); |
8e9394ce GKH |
826 | } |
827 | ||
1f21782e AB |
828 | void driver_init(void); |
829 | ||
1da177e4 LT |
830 | /* |
831 | * High level routines for use by the bus drivers | |
832 | */ | |
d462943a GKH |
833 | extern int __must_check device_register(struct device *dev); |
834 | extern void device_unregister(struct device *dev); | |
835 | extern void device_initialize(struct device *dev); | |
836 | extern int __must_check device_add(struct device *dev); | |
837 | extern void device_del(struct device *dev); | |
838 | extern int device_for_each_child(struct device *dev, void *data, | |
839 | int (*fn)(struct device *dev, void *data)); | |
840 | extern struct device *device_find_child(struct device *dev, void *data, | |
841 | int (*match)(struct device *dev, void *data)); | |
6937e8f8 | 842 | extern int device_rename(struct device *dev, const char *new_name); |
ffa6a705 CH |
843 | extern int device_move(struct device *dev, struct device *new_parent, |
844 | enum dpm_order dpm_order); | |
e454cea2 | 845 | extern const char *device_get_devnode(struct device *dev, |
2c9ede55 | 846 | umode_t *mode, const char **tmp); |
b4028437 | 847 | extern void *dev_get_drvdata(const struct device *dev); |
c8705082 | 848 | extern int dev_set_drvdata(struct device *dev, void *data); |
1da177e4 | 849 | |
0aa0dc41 MM |
850 | /* |
851 | * Root device objects for grouping under /sys/devices | |
852 | */ | |
853 | extern struct device *__root_device_register(const char *name, | |
854 | struct module *owner); | |
eb5589a8 PG |
855 | |
856 | /* | |
857 | * This is a macro to avoid include problems with THIS_MODULE, | |
858 | * just as per what is done for device_schedule_callback() above. | |
859 | */ | |
860 | #define root_device_register(name) \ | |
861 | __root_device_register(name, THIS_MODULE) | |
862 | ||
0aa0dc41 MM |
863 | extern void root_device_unregister(struct device *root); |
864 | ||
a5b8b1ad MB |
865 | static inline void *dev_get_platdata(const struct device *dev) |
866 | { | |
867 | return dev->platform_data; | |
868 | } | |
869 | ||
1da177e4 LT |
870 | /* |
871 | * Manual binding of a device to driver. See drivers/base/bus.c | |
872 | * for information on use. | |
873 | */ | |
f86db396 | 874 | extern int __must_check device_bind_driver(struct device *dev); |
d462943a GKH |
875 | extern void device_release_driver(struct device *dev); |
876 | extern int __must_check device_attach(struct device *dev); | |
f86db396 AM |
877 | extern int __must_check driver_attach(struct device_driver *drv); |
878 | extern int __must_check device_reprobe(struct device *dev); | |
1da177e4 | 879 | |
23681e47 GKH |
880 | /* |
881 | * Easy functions for dynamically creating devices on the fly | |
882 | */ | |
8882b394 GKH |
883 | extern struct device *device_create_vargs(struct class *cls, |
884 | struct device *parent, | |
885 | dev_t devt, | |
886 | void *drvdata, | |
887 | const char *fmt, | |
888 | va_list vargs); | |
b9075fa9 JP |
889 | extern __printf(5, 6) |
890 | struct device *device_create(struct class *cls, struct device *parent, | |
891 | dev_t devt, void *drvdata, | |
892 | const char *fmt, ...); | |
23681e47 | 893 | extern void device_destroy(struct class *cls, dev_t devt); |
1da177e4 | 894 | |
1da177e4 LT |
895 | /* |
896 | * Platform "fixup" functions - allow the platform to have their say | |
897 | * about devices and actions that the general device layer doesn't | |
898 | * know about. | |
899 | */ | |
900 | /* Notify platform of device discovery */ | |
d462943a | 901 | extern int (*platform_notify)(struct device *dev); |
1da177e4 | 902 | |
d462943a | 903 | extern int (*platform_notify_remove)(struct device *dev); |
1da177e4 LT |
904 | |
905 | ||
880ffb5c | 906 | /* |
1da177e4 LT |
907 | * get_device - atomically increment the reference count for the device. |
908 | * | |
909 | */ | |
d462943a GKH |
910 | extern struct device *get_device(struct device *dev); |
911 | extern void put_device(struct device *dev); | |
1da177e4 | 912 | |
2b2af54a KS |
913 | #ifdef CONFIG_DEVTMPFS |
914 | extern int devtmpfs_create_node(struct device *dev); | |
915 | extern int devtmpfs_delete_node(struct device *dev); | |
073120cc | 916 | extern int devtmpfs_mount(const char *mntdir); |
2b2af54a KS |
917 | #else |
918 | static inline int devtmpfs_create_node(struct device *dev) { return 0; } | |
919 | static inline int devtmpfs_delete_node(struct device *dev) { return 0; } | |
920 | static inline int devtmpfs_mount(const char *mountpoint) { return 0; } | |
921 | #endif | |
922 | ||
116f232b | 923 | /* drivers/base/power/shutdown.c */ |
1da177e4 LT |
924 | extern void device_shutdown(void); |
925 | ||
1da177e4 | 926 | /* debugging and troubleshooting/diagnostic helpers. */ |
bf9ca69f | 927 | extern const char *dev_driver_string(const struct device *dev); |
99bcf217 JP |
928 | |
929 | ||
930 | #ifdef CONFIG_PRINTK | |
931 | ||
0a18b050 JP |
932 | extern __printf(3, 0) |
933 | int dev_vprintk_emit(int level, const struct device *dev, | |
934 | const char *fmt, va_list args); | |
05e4e5b8 JP |
935 | extern __printf(3, 4) |
936 | int dev_printk_emit(int level, const struct device *dev, const char *fmt, ...); | |
798efc60 | 937 | |
b9075fa9 JP |
938 | extern __printf(3, 4) |
939 | int dev_printk(const char *level, const struct device *dev, | |
798efc60 | 940 | const char *fmt, ...); |
b9075fa9 JP |
941 | extern __printf(2, 3) |
942 | int dev_emerg(const struct device *dev, const char *fmt, ...); | |
943 | extern __printf(2, 3) | |
944 | int dev_alert(const struct device *dev, const char *fmt, ...); | |
945 | extern __printf(2, 3) | |
946 | int dev_crit(const struct device *dev, const char *fmt, ...); | |
947 | extern __printf(2, 3) | |
948 | int dev_err(const struct device *dev, const char *fmt, ...); | |
949 | extern __printf(2, 3) | |
950 | int dev_warn(const struct device *dev, const char *fmt, ...); | |
951 | extern __printf(2, 3) | |
952 | int dev_notice(const struct device *dev, const char *fmt, ...); | |
953 | extern __printf(2, 3) | |
954 | int _dev_info(const struct device *dev, const char *fmt, ...); | |
99bcf217 JP |
955 | |
956 | #else | |
957 | ||
0a18b050 JP |
958 | static inline __printf(3, 0) |
959 | int dev_vprintk_emit(int level, const struct device *dev, | |
960 | const char *fmt, va_list args) | |
05e4e5b8 JP |
961 | { return 0; } |
962 | static inline __printf(3, 4) | |
963 | int dev_printk_emit(int level, const struct device *dev, const char *fmt, ...) | |
964 | { return 0; } | |
965 | ||
cbc46635 JP |
966 | static inline int __dev_printk(const char *level, const struct device *dev, |
967 | struct va_format *vaf) | |
b9075fa9 JP |
968 | { return 0; } |
969 | static inline __printf(3, 4) | |
970 | int dev_printk(const char *level, const struct device *dev, | |
971 | const char *fmt, ...) | |
972 | { return 0; } | |
973 | ||
974 | static inline __printf(2, 3) | |
975 | int dev_emerg(const struct device *dev, const char *fmt, ...) | |
976 | { return 0; } | |
977 | static inline __printf(2, 3) | |
978 | int dev_crit(const struct device *dev, const char *fmt, ...) | |
979 | { return 0; } | |
980 | static inline __printf(2, 3) | |
981 | int dev_alert(const struct device *dev, const char *fmt, ...) | |
982 | { return 0; } | |
983 | static inline __printf(2, 3) | |
984 | int dev_err(const struct device *dev, const char *fmt, ...) | |
985 | { return 0; } | |
986 | static inline __printf(2, 3) | |
987 | int dev_warn(const struct device *dev, const char *fmt, ...) | |
988 | { return 0; } | |
989 | static inline __printf(2, 3) | |
990 | int dev_notice(const struct device *dev, const char *fmt, ...) | |
991 | { return 0; } | |
992 | static inline __printf(2, 3) | |
993 | int _dev_info(const struct device *dev, const char *fmt, ...) | |
994 | { return 0; } | |
99bcf217 JP |
995 | |
996 | #endif | |
997 | ||
6f586e66 HD |
998 | /* |
999 | * Stupid hackaround for existing uses of non-printk uses dev_info | |
1000 | * | |
1001 | * Note that the definition of dev_info below is actually _dev_info | |
1002 | * and a macro is used to avoid redefining dev_info | |
1003 | */ | |
1004 | ||
1005 | #define dev_info(dev, fmt, arg...) _dev_info(dev, fmt, ##arg) | |
1006 | ||
1007 | #if defined(CONFIG_DYNAMIC_DEBUG) | |
1008 | #define dev_dbg(dev, format, ...) \ | |
1009 | do { \ | |
1010 | dynamic_dev_dbg(dev, format, ##__VA_ARGS__); \ | |
1011 | } while (0) | |
1012 | #elif defined(DEBUG) | |
1013 | #define dev_dbg(dev, format, arg...) \ | |
1014 | dev_printk(KERN_DEBUG, dev, format, ##arg) | |
1015 | #else | |
1016 | #define dev_dbg(dev, format, arg...) \ | |
1017 | ({ \ | |
1018 | if (0) \ | |
1019 | dev_printk(KERN_DEBUG, dev, format, ##arg); \ | |
1020 | 0; \ | |
1021 | }) | |
1022 | #endif | |
1023 | ||
6ca04593 HD |
1024 | #define dev_level_ratelimited(dev_level, dev, fmt, ...) \ |
1025 | do { \ | |
1026 | static DEFINE_RATELIMIT_STATE(_rs, \ | |
1027 | DEFAULT_RATELIMIT_INTERVAL, \ | |
1028 | DEFAULT_RATELIMIT_BURST); \ | |
1029 | if (__ratelimit(&_rs)) \ | |
1030 | dev_level(dev, fmt, ##__VA_ARGS__); \ | |
1031 | } while (0) | |
1032 | ||
1033 | #define dev_emerg_ratelimited(dev, fmt, ...) \ | |
1034 | dev_level_ratelimited(dev_emerg, dev, fmt, ##__VA_ARGS__) | |
1035 | #define dev_alert_ratelimited(dev, fmt, ...) \ | |
1036 | dev_level_ratelimited(dev_alert, dev, fmt, ##__VA_ARGS__) | |
1037 | #define dev_crit_ratelimited(dev, fmt, ...) \ | |
1038 | dev_level_ratelimited(dev_crit, dev, fmt, ##__VA_ARGS__) | |
1039 | #define dev_err_ratelimited(dev, fmt, ...) \ | |
1040 | dev_level_ratelimited(dev_err, dev, fmt, ##__VA_ARGS__) | |
1041 | #define dev_warn_ratelimited(dev, fmt, ...) \ | |
1042 | dev_level_ratelimited(dev_warn, dev, fmt, ##__VA_ARGS__) | |
1043 | #define dev_notice_ratelimited(dev, fmt, ...) \ | |
1044 | dev_level_ratelimited(dev_notice, dev, fmt, ##__VA_ARGS__) | |
1045 | #define dev_info_ratelimited(dev, fmt, ...) \ | |
1046 | dev_level_ratelimited(dev_info, dev, fmt, ##__VA_ARGS__) | |
6f586e66 | 1047 | #if defined(CONFIG_DYNAMIC_DEBUG) || defined(DEBUG) |
6ca04593 | 1048 | #define dev_dbg_ratelimited(dev, fmt, ...) \ |
6f586e66 HD |
1049 | do { \ |
1050 | static DEFINE_RATELIMIT_STATE(_rs, \ | |
1051 | DEFAULT_RATELIMIT_INTERVAL, \ | |
1052 | DEFAULT_RATELIMIT_BURST); \ | |
1053 | DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ | |
1054 | if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \ | |
1055 | __ratelimit(&_rs)) \ | |
1056 | __dynamic_pr_debug(&descriptor, pr_fmt(fmt), \ | |
1057 | ##__VA_ARGS__); \ | |
99bcf217 | 1058 | } while (0) |
1da177e4 | 1059 | #else |
6f586e66 HD |
1060 | #define dev_dbg_ratelimited(dev, fmt, ...) \ |
1061 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) | |
1da177e4 LT |
1062 | #endif |
1063 | ||
aebdc3b4 DB |
1064 | #ifdef VERBOSE_DEBUG |
1065 | #define dev_vdbg dev_dbg | |
1066 | #else | |
99bcf217 JP |
1067 | #define dev_vdbg(dev, format, arg...) \ |
1068 | ({ \ | |
1069 | if (0) \ | |
1070 | dev_printk(KERN_DEBUG, dev, format, ##arg); \ | |
1071 | 0; \ | |
1072 | }) | |
aebdc3b4 DB |
1073 | #endif |
1074 | ||
e6139662 | 1075 | /* |
bcdd323b | 1076 | * dev_WARN*() acts like dev_printk(), but with the key difference |
e6139662 AV |
1077 | * of using a WARN/WARN_ON to get the message out, including the |
1078 | * file/line information and a backtrace. | |
1079 | */ | |
1080 | #define dev_WARN(dev, format, arg...) \ | |
1081 | WARN(1, "Device: %s\n" format, dev_driver_string(dev), ## arg); | |
1082 | ||
bcdd323b FB |
1083 | #define dev_WARN_ONCE(dev, condition, format, arg...) \ |
1084 | WARN_ONCE(condition, "Device %s\n" format, \ | |
1085 | dev_driver_string(dev), ## arg) | |
1086 | ||
1da177e4 LT |
1087 | /* Create alias, so I can be autoloaded. */ |
1088 | #define MODULE_ALIAS_CHARDEV(major,minor) \ | |
1089 | MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor)) | |
1090 | #define MODULE_ALIAS_CHARDEV_MAJOR(major) \ | |
1091 | MODULE_ALIAS("char-major-" __stringify(major) "-*") | |
e52eec13 AK |
1092 | |
1093 | #ifdef CONFIG_SYSFS_DEPRECATED | |
1094 | extern long sysfs_deprecated; | |
1095 | #else | |
1096 | #define sysfs_deprecated 0 | |
1097 | #endif | |
1098 | ||
907d0ed1 LPC |
1099 | /** |
1100 | * module_driver() - Helper macro for drivers that don't do anything | |
1101 | * special in module init/exit. This eliminates a lot of boilerplate. | |
1102 | * Each module may only use this macro once, and calling it replaces | |
1103 | * module_init() and module_exit(). | |
1104 | * | |
2eda013f RD |
1105 | * @__driver: driver name |
1106 | * @__register: register function for this driver type | |
1107 | * @__unregister: unregister function for this driver type | |
cd494618 | 1108 | * @...: Additional arguments to be passed to __register and __unregister. |
2eda013f | 1109 | * |
907d0ed1 LPC |
1110 | * Use this macro to construct bus specific macros for registering |
1111 | * drivers, and do not use it on its own. | |
1112 | */ | |
cd494618 | 1113 | #define module_driver(__driver, __register, __unregister, ...) \ |
907d0ed1 LPC |
1114 | static int __init __driver##_init(void) \ |
1115 | { \ | |
cd494618 | 1116 | return __register(&(__driver) , ##__VA_ARGS__); \ |
907d0ed1 LPC |
1117 | } \ |
1118 | module_init(__driver##_init); \ | |
1119 | static void __exit __driver##_exit(void) \ | |
1120 | { \ | |
cd494618 | 1121 | __unregister(&(__driver) , ##__VA_ARGS__); \ |
907d0ed1 LPC |
1122 | } \ |
1123 | module_exit(__driver##_exit); | |
1124 | ||
1da177e4 | 1125 | #endif /* _DEVICE_H_ */ |