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