]>
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> |
3c2670e6 | 28 | #include <linux/uidgid.h> |
c6dbaef2 | 29 | #include <asm/device.h> |
1da177e4 | 30 | |
1da177e4 | 31 | struct device; |
fb069a5d | 32 | struct device_private; |
1da177e4 | 33 | struct device_driver; |
e5dd1278 | 34 | struct driver_private; |
de477254 | 35 | struct module; |
1da177e4 | 36 | struct class; |
6b6e39a6 | 37 | struct subsys_private; |
b8c5cec2 | 38 | struct bus_type; |
d706c1b0 | 39 | struct device_node; |
ff21776d | 40 | struct iommu_ops; |
74416e1e | 41 | struct iommu_group; |
b8c5cec2 KS |
42 | |
43 | struct bus_attribute { | |
44 | struct attribute attr; | |
d462943a GKH |
45 | ssize_t (*show)(struct bus_type *bus, char *buf); |
46 | ssize_t (*store)(struct bus_type *bus, const char *buf, size_t count); | |
b8c5cec2 KS |
47 | }; |
48 | ||
d462943a | 49 | #define BUS_ATTR(_name, _mode, _show, _store) \ |
ced321bf GKH |
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) | |
b8c5cec2 KS |
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 *); | |
1da177e4 | 59 | |
880ffb5c WG |
60 | /** |
61 | * struct bus_type - The bus type of the device | |
62 | * | |
63 | * @name: The name of the bus. | |
ca22e56d KS |
64 | * @dev_name: Used for subsystems to enumerate devices like ("foo%u", dev->id). |
65 | * @dev_root: Default device to use as the parent. | |
880ffb5c WG |
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. | |
fa6fdb33 | 69 | * @dev_groups: Default attributes of the devices on the bus. |
ed0617b5 | 70 | * @drv_groups: Default attributes of the device drivers on the bus. |
880ffb5c WG |
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. | |
4f3549d7 RW |
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 | * | |
880ffb5c WG |
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. | |
7b08fae8 | 88 | * @iommu_ops: IOMMU specific operations for this bus, used to attach IOMMU |
ff21776d JR |
89 | * driver implementations to a bus and allow the driver to do |
90 | * bus-specific setup | |
880ffb5c WG |
91 | * @p: The private data of the driver core, only the driver core can |
92 | * touch this. | |
bfd63cd2 | 93 | * @lock_key: Lock class key for use by the lock validator |
880ffb5c WG |
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 | */ | |
1da177e4 | 104 | struct bus_type { |
d462943a | 105 | const char *name; |
ca22e56d KS |
106 | const char *dev_name; |
107 | struct device *dev_root; | |
d462943a | 108 | struct bus_attribute *bus_attrs; |
fa6fdb33 | 109 | struct device_attribute *dev_attrs; /* use dev_groups instead */ |
ed0617b5 | 110 | struct driver_attribute *drv_attrs; /* use drv_groups instead */ |
fa6fdb33 | 111 | const struct attribute_group **dev_groups; |
ed0617b5 | 112 | const struct attribute_group **drv_groups; |
d462943a GKH |
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 | ||
4f3549d7 RW |
120 | int (*online)(struct device *dev); |
121 | int (*offline)(struct device *dev); | |
122 | ||
d462943a | 123 | int (*suspend)(struct device *dev, pm_message_t state); |
d462943a | 124 | int (*resume)(struct device *dev); |
b8c5cec2 | 125 | |
8150f32b | 126 | const struct dev_pm_ops *pm; |
1eede070 | 127 | |
ff21776d JR |
128 | struct iommu_ops *iommu_ops; |
129 | ||
6b6e39a6 | 130 | struct subsys_private *p; |
be871b7e | 131 | struct lock_class_key lock_key; |
1da177e4 LT |
132 | }; |
133 | ||
be871b7e MH |
134 | extern int __must_check bus_register(struct bus_type *bus); |
135 | ||
d462943a | 136 | extern void bus_unregister(struct bus_type *bus); |
1da177e4 | 137 | |
d462943a | 138 | extern int __must_check bus_rescan_devices(struct bus_type *bus); |
1da177e4 | 139 | |
1da177e4 | 140 | /* iterator helpers for buses */ |
ca22e56d KS |
141 | struct subsys_dev_iter { |
142 | struct klist_iter ki; | |
143 | const struct device_type *type; | |
144 | }; | |
7cd9c9bb | 145 | void subsys_dev_iter_init(struct subsys_dev_iter *iter, |
ca22e56d KS |
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); | |
1da177e4 | 151 | |
d462943a GKH |
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)); | |
1f9ffc04 GKH |
157 | struct device *bus_find_device_by_name(struct bus_type *bus, |
158 | struct device *start, | |
159 | const char *name); | |
ca22e56d KS |
160 | struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id, |
161 | struct device *hint); | |
cc7447a5 JD |
162 | int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, |
163 | void *data, int (*fn)(struct device_driver *, void *)); | |
99178b03 GKH |
164 | void bus_sort_breadthfirst(struct bus_type *bus, |
165 | int (*compare)(const struct device *a, | |
166 | const struct device *b)); | |
116af378 BH |
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 | |
8e9394ce | 182 | * with the device lock held in the core, so be careful. |
116af378 BH |
183 | */ |
184 | #define BUS_NOTIFY_ADD_DEVICE 0x00000001 /* device added */ | |
185 | #define BUS_NOTIFY_DEL_DEVICE 0x00000002 /* device removed */ | |
45daef0f MD |
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 | |
116af378 | 190 | unbound */ |
45daef0f | 191 | #define BUS_NOTIFY_UNBOUND_DRIVER 0x00000006 /* driver is unbound |
309b7d60 | 192 | from the device */ |
116af378 | 193 | |
0fed80f7 | 194 | extern struct kset *bus_get_kset(struct bus_type *bus); |
b249072e | 195 | extern struct klist *bus_get_device_klist(struct bus_type *bus); |
0fed80f7 | 196 | |
880ffb5c WG |
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. | |
06f64c8f | 205 | * @acpi_match_table: The ACPI match table. |
880ffb5c WG |
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 | */ | |
1da177e4 | 229 | struct device_driver { |
e5dd1278 GKH |
230 | const char *name; |
231 | struct bus_type *bus; | |
1da177e4 | 232 | |
e5dd1278 | 233 | struct module *owner; |
1a6f2a75 DT |
234 | const char *mod_name; /* used for built-in modules */ |
235 | ||
236 | bool suppress_bind_attrs; /* disables bind/unbind via sysfs */ | |
1da177e4 | 237 | |
597b9d1e | 238 | const struct of_device_id *of_match_table; |
06f64c8f | 239 | const struct acpi_device_id *acpi_match_table; |
597b9d1e | 240 | |
d462943a GKH |
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); | |
a4dbd674 | 246 | const struct attribute_group **groups; |
e5dd1278 | 247 | |
8150f32b | 248 | const struct dev_pm_ops *pm; |
1eede070 | 249 | |
e5dd1278 | 250 | struct driver_private *p; |
1da177e4 LT |
251 | }; |
252 | ||
253 | ||
d462943a GKH |
254 | extern int __must_check driver_register(struct device_driver *drv); |
255 | extern void driver_unregister(struct device_driver *drv); | |
1da177e4 | 256 | |
d462943a GKH |
257 | extern struct device_driver *driver_find(const char *name, |
258 | struct bus_type *bus); | |
d779249e | 259 | extern int driver_probe_done(void); |
b23530eb | 260 | extern void wait_for_device_probe(void); |
216773a7 | 261 | |
1da177e4 | 262 | |
405ae7d3 | 263 | /* sysfs interface for exporting driver attributes */ |
1da177e4 LT |
264 | |
265 | struct driver_attribute { | |
d462943a GKH |
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); | |
1da177e4 LT |
270 | }; |
271 | ||
ced321bf GKH |
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) | |
1da177e4 | 278 | |
d462943a | 279 | extern int __must_check driver_create_file(struct device_driver *driver, |
099c2f21 | 280 | const struct driver_attribute *attr); |
d462943a | 281 | extern void driver_remove_file(struct device_driver *driver, |
099c2f21 | 282 | const struct driver_attribute *attr); |
1da177e4 | 283 | |
d462943a GKH |
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)); | |
fae3cd00 | 292 | |
ca22e56d KS |
293 | /** |
294 | * struct subsys_interface - interfaces to device functions | |
2eda013f RD |
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 | |
ca22e56d KS |
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); | |
d73ce004 TH |
319 | int subsys_virtual_register(struct bus_type *subsys, |
320 | const struct attribute_group **groups); | |
ca22e56d | 321 | |
880ffb5c WG |
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. | |
d05a6f96 | 327 | * @dev_groups: Default attributes of the devices that belong to the class. |
880ffb5c WG |
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. | |
1da177e4 LT |
351 | */ |
352 | struct class { | |
d462943a GKH |
353 | const char *name; |
354 | struct module *owner; | |
1da177e4 | 355 | |
d462943a | 356 | struct class_attribute *class_attrs; |
d05a6f96 GKH |
357 | struct device_attribute *dev_attrs; /* use dev_groups instead */ |
358 | const struct attribute_group **dev_groups; | |
c97415a7 | 359 | struct bin_attribute *dev_bin_attrs; |
e105b8bf | 360 | struct kobject *dev_kobj; |
1da177e4 | 361 | |
d462943a | 362 | int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env); |
2c9ede55 | 363 | char *(*devnode)(struct device *dev, umode_t *mode); |
1da177e4 | 364 | |
d462943a GKH |
365 | void (*class_release)(struct class *class); |
366 | void (*dev_release)(struct device *dev); | |
7c8265f5 | 367 | |
d462943a GKH |
368 | int (*suspend)(struct device *dev, pm_message_t state); |
369 | int (*resume)(struct device *dev); | |
1eede070 | 370 | |
bc451f20 EB |
371 | const struct kobj_ns_type_operations *ns_type; |
372 | const void *(*namespace)(struct device *dev); | |
373 | ||
8150f32b DT |
374 | const struct dev_pm_ops *pm; |
375 | ||
6b6e39a6 | 376 | struct subsys_private *p; |
1da177e4 LT |
377 | }; |
378 | ||
5a3ceb86 TH |
379 | struct class_dev_iter { |
380 | struct klist_iter ki; | |
381 | const struct device_type *type; | |
382 | }; | |
383 | ||
e105b8bf DW |
384 | extern struct kobject *sysfs_dev_block_kobj; |
385 | extern struct kobject *sysfs_dev_char_kobj; | |
d2a3b914 MW |
386 | extern int __must_check __class_register(struct class *class, |
387 | struct lock_class_key *key); | |
d462943a | 388 | extern void class_unregister(struct class *class); |
d2a3b914 MW |
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 | ||
46227094 JD |
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 | ||
7cd9c9bb GKH |
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); | |
5a3ceb86 TH |
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 | ||
93562b53 GKH |
413 | extern int class_for_each_device(struct class *class, struct device *start, |
414 | void *data, | |
fd04897b | 415 | int (*fn)(struct device *dev, void *data)); |
695794ae | 416 | extern struct device *class_find_device(struct class *class, |
9f3b795a MM |
417 | struct device *start, const void *data, |
418 | int (*match)(struct device *, const void *)); | |
1da177e4 LT |
419 | |
420 | struct class_attribute { | |
d462943a | 421 | struct attribute attr; |
28812fe1 AK |
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); | |
672d82c1 EB |
426 | const void *(*namespace)(struct class *class, |
427 | const struct class_attribute *attr); | |
1da177e4 LT |
428 | }; |
429 | ||
ced321bf GKH |
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) | |
1da177e4 | 436 | |
d462943a GKH |
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); | |
1da177e4 | 441 | |
869dfc87 | 442 | /* Simple class attribute that is just a static string */ |
869dfc87 AK |
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 | ||
1da177e4 LT |
458 | struct class_interface { |
459 | struct list_head node; | |
460 | struct class *class; | |
461 | ||
c47ed219 GKH |
462 | int (*add_dev) (struct device *, struct class_interface *); |
463 | void (*remove_dev) (struct device *, struct class_interface *); | |
1da177e4 LT |
464 | }; |
465 | ||
4a7fb636 | 466 | extern int __must_check class_interface_register(struct class_interface *); |
1da177e4 LT |
467 | extern void class_interface_unregister(struct class_interface *); |
468 | ||
d2a3b914 MW |
469 | extern struct class * __must_check __class_create(struct module *owner, |
470 | const char *name, | |
471 | struct lock_class_key *key); | |
e9ba6365 | 472 | extern void class_destroy(struct class *cls); |
e9ba6365 | 473 | |
d2a3b914 MW |
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 | ||
414264f9 KS |
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 | */ | |
f9f852df | 491 | struct device_type { |
414264f9 | 492 | const char *name; |
a4dbd674 | 493 | const struct attribute_group **groups; |
7eff2e7a | 494 | int (*uevent)(struct device *dev, struct kobj_uevent_env *env); |
3c2670e6 | 495 | char *(*devnode)(struct device *dev, umode_t *mode, |
4e4098a3 | 496 | kuid_t *uid, kgid_t *gid); |
f9f852df | 497 | void (*release)(struct device *dev); |
1eede070 | 498 | |
8150f32b | 499 | const struct dev_pm_ops *pm; |
f9f852df KS |
500 | }; |
501 | ||
a7fd6706 KS |
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 | ||
ca22e56d KS |
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); | |
91872392 BP |
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); | |
a7fd6706 | 528 | |
d462943a | 529 | #define DEVICE_ATTR(_name, _mode, _show, _store) \ |
ca22e56d | 530 | struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store) |
ced321bf GKH |
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) | |
ca22e56d KS |
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 = \ | |
94758185 | 540 | { __ATTR(_name, _mode, device_show_int, device_store_int), &(_var) } |
91872392 BP |
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) } | |
356c05d5 AS |
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) | |
a7fd6706 | 547 | |
b9d4e714 GKH |
548 | extern int device_create_file(struct device *device, |
549 | const struct device_attribute *entry); | |
d462943a | 550 | extern void device_remove_file(struct device *dev, |
26579ab7 | 551 | const struct device_attribute *attr); |
2589f188 | 552 | extern int __must_check device_create_bin_file(struct device *dev, |
66ecb92b | 553 | const struct bin_attribute *attr); |
2589f188 | 554 | extern void device_remove_bin_file(struct device *dev, |
66ecb92b | 555 | const struct bin_attribute *attr); |
523ded71 | 556 | extern int device_schedule_callback_owner(struct device *dev, |
d462943a | 557 | void (*func)(struct device *dev), struct module *owner); |
523ded71 AS |
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) | |
9ac7849e TH |
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 | |
d462943a | 568 | extern void *__devres_alloc(dr_release_t release, size_t size, gfp_t gfp, |
9ac7849e TH |
569 | const char *name); |
570 | #define devres_alloc(release, size, gfp) \ | |
571 | __devres_alloc(release, size, gfp, #release) | |
572 | #else | |
d462943a | 573 | extern void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp); |
9ac7849e | 574 | #endif |
bddb1b90 ML |
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); | |
9ac7849e TH |
579 | extern void devres_free(void *res); |
580 | extern void devres_add(struct device *dev, void *res); | |
d462943a | 581 | extern void *devres_find(struct device *dev, dr_release_t release, |
9ac7849e | 582 | dr_match_t match, void *match_data); |
d462943a GKH |
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); | |
9ac7849e TH |
587 | extern int devres_destroy(struct device *dev, dr_release_t release, |
588 | dr_match_t match, void *match_data); | |
d926d0e4 MB |
589 | extern int devres_release(struct device *dev, dr_release_t release, |
590 | dr_match_t match, void *match_data); | |
9ac7849e TH |
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 | ||
75096579 | 603 | void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res); |
72f8c0bf WS |
604 | void __iomem *devm_request_and_ioremap(struct device *dev, |
605 | struct resource *res); | |
606 | ||
d6b0c580 DT |
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 | ||
6b7b6510 FT |
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 | ||
95f8a082 RW |
620 | struct acpi_dev_node { |
621 | #ifdef CONFIG_ACPI | |
622 | void *handle; | |
623 | #endif | |
624 | }; | |
625 | ||
880ffb5c WG |
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. | |
564b905a | 652 | * @pm_domain: Provide callbacks that are executed during system suspend, |
880ffb5c WG |
653 | * hibernation, system resume and during runtime PM transitions |
654 | * along with subsystem-level and driver-level callbacks. | |
ab78029e LW |
655 | * @pins: For device pin management. |
656 | * See Documentation/pinctrl.txt for details. | |
880ffb5c WG |
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. | |
bfd63cd2 | 666 | * @cma_area: Contiguous memory area for dma allocations |
880ffb5c WG |
667 | * @archdata: For arch-specific additions. |
668 | * @of_node: Associated device tree node. | |
95f8a082 | 669 | * @acpi_node: Associated ACPI device node. |
880ffb5c | 670 | * @devt: For creating the sysfs "dev". |
2eda013f | 671 | * @id: device instance |
880ffb5c WG |
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). | |
bfd63cd2 | 680 | * @iommu_group: IOMMU group the device belongs to. |
880ffb5c | 681 | * |
4f3549d7 RW |
682 | * @offline_disabled: If set, the device is permanently online. |
683 | * @offline: Set after successful invocation of bus type's .offline(). | |
880ffb5c WG |
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 | */ | |
1da177e4 | 693 | struct device { |
49a4ec18 | 694 | struct device *parent; |
1da177e4 | 695 | |
fb069a5d GKH |
696 | struct device_private *p; |
697 | ||
1da177e4 | 698 | struct kobject kobj; |
c906a48a | 699 | const char *init_name; /* initial name of the device */ |
aed65af1 | 700 | const struct device_type *type; |
1da177e4 | 701 | |
3142788b | 702 | struct mutex mutex; /* mutex to synchronize calls to |
af70316a PM |
703 | * its driver. |
704 | */ | |
705 | ||
d462943a | 706 | struct bus_type *bus; /* type of bus device is on */ |
1da177e4 LT |
707 | struct device_driver *driver; /* which driver has allocated this |
708 | device */ | |
e67c8562 GKH |
709 | void *platform_data; /* Platform specific data, device |
710 | core doesn't touch it */ | |
1da177e4 | 711 | struct dev_pm_info power; |
564b905a | 712 | struct dev_pm_domain *pm_domain; |
1da177e4 | 713 | |
ab78029e LW |
714 | #ifdef CONFIG_PINCTRL |
715 | struct dev_pin_info *pins; | |
716 | #endif | |
717 | ||
87348136 CH |
718 | #ifdef CONFIG_NUMA |
719 | int numa_node; /* NUMA node this device is close to */ | |
720 | #endif | |
1da177e4 LT |
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 | ||
6b7b6510 FT |
728 | struct device_dma_parameters *dma_parms; |
729 | ||
1da177e4 LT |
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 */ | |
c64be2bb MS |
734 | #ifdef CONFIG_CMA |
735 | struct cma *cma_area; /* contiguous memory area for dma | |
736 | allocations */ | |
737 | #endif | |
c6dbaef2 BH |
738 | /* arch specific additions */ |
739 | struct dev_archdata archdata; | |
c9e358df GL |
740 | |
741 | struct device_node *of_node; /* associated device tree node */ | |
95f8a082 | 742 | struct acpi_dev_node acpi_node; /* associated ACPI device node */ |
1da177e4 | 743 | |
929d2fa5 | 744 | dev_t devt; /* dev_t, creates the sysfs "dev" */ |
ca22e56d | 745 | u32 id; /* device instance */ |
929d2fa5 | 746 | |
9ac7849e TH |
747 | spinlock_t devres_lock; |
748 | struct list_head devres_head; | |
749 | ||
5a3ceb86 | 750 | struct klist_node knode_class; |
b7a3e813 | 751 | struct class *class; |
a4dbd674 | 752 | const struct attribute_group **groups; /* optional groups */ |
23681e47 | 753 | |
d462943a | 754 | void (*release)(struct device *dev); |
74416e1e | 755 | struct iommu_group *iommu_group; |
4f3549d7 RW |
756 | |
757 | bool offline_disabled:1; | |
758 | bool offline:1; | |
1da177e4 LT |
759 | }; |
760 | ||
a4232963 LPC |
761 | static inline struct device *kobj_to_dev(struct kobject *kobj) |
762 | { | |
763 | return container_of(kobj, struct device, kobj); | |
764 | } | |
765 | ||
95f8a082 RW |
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 | ||
9a3df1f7 AS |
774 | /* Get the wakeup routines, which depend on struct device */ |
775 | #include <linux/pm_wakeup.h> | |
776 | ||
bf9ca69f | 777 | static inline const char *dev_name(const struct device *dev) |
06916639 | 778 | { |
a636ee7f PM |
779 | /* Use the init name until the kobject becomes available */ |
780 | if (dev->init_name) | |
781 | return dev->init_name; | |
782 | ||
1fa5ae85 | 783 | return kobject_name(&dev->kobj); |
06916639 KS |
784 | } |
785 | ||
b9075fa9 JP |
786 | extern __printf(2, 3) |
787 | int dev_set_name(struct device *dev, const char *name, ...); | |
413c239f | 788 | |
87348136 CH |
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 | ||
5c095a0e RW |
808 | static inline struct pm_subsys_data *dev_to_psd(struct device *dev) |
809 | { | |
810 | return dev ? dev->power.subsys_data : NULL; | |
811 | } | |
812 | ||
f67f129e ML |
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 | ||
d305ef5d DR |
823 | static inline int device_is_registered(struct device *dev) |
824 | { | |
3f62e570 | 825 | return dev->kobj.state_in_sysfs; |
d305ef5d DR |
826 | } |
827 | ||
5af84b82 RW |
828 | static inline void device_enable_async_suspend(struct device *dev) |
829 | { | |
f76b168b | 830 | if (!dev->power.is_prepared) |
5af84b82 RW |
831 | dev->power.async_suspend = true; |
832 | } | |
833 | ||
5a2eb858 RW |
834 | static inline void device_disable_async_suspend(struct device *dev) |
835 | { | |
f76b168b | 836 | if (!dev->power.is_prepared) |
5a2eb858 RW |
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 | ||
8b258cc8 RW |
845 | static inline void pm_suspend_ignore_children(struct device *dev, bool enable) |
846 | { | |
847 | dev->power.ignore_children = enable; | |
848 | } | |
849 | ||
feb70af0 RW |
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 | ||
8e9394ce GKH |
857 | static inline void device_lock(struct device *dev) |
858 | { | |
3142788b | 859 | mutex_lock(&dev->mutex); |
8e9394ce GKH |
860 | } |
861 | ||
862 | static inline int device_trylock(struct device *dev) | |
863 | { | |
3142788b | 864 | return mutex_trylock(&dev->mutex); |
8e9394ce GKH |
865 | } |
866 | ||
867 | static inline void device_unlock(struct device *dev) | |
868 | { | |
3142788b | 869 | mutex_unlock(&dev->mutex); |
8e9394ce GKH |
870 | } |
871 | ||
1f21782e AB |
872 | void driver_init(void); |
873 | ||
1da177e4 LT |
874 | /* |
875 | * High level routines for use by the bus drivers | |
876 | */ | |
d462943a GKH |
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)); | |
6937e8f8 | 886 | extern int device_rename(struct device *dev, const char *new_name); |
ffa6a705 CH |
887 | extern int device_move(struct device *dev, struct device *new_parent, |
888 | enum dpm_order dpm_order); | |
e454cea2 | 889 | extern const char *device_get_devnode(struct device *dev, |
4e4098a3 | 890 | umode_t *mode, kuid_t *uid, kgid_t *gid, |
3c2670e6 | 891 | const char **tmp); |
b4028437 | 892 | extern void *dev_get_drvdata(const struct device *dev); |
c8705082 | 893 | extern int dev_set_drvdata(struct device *dev, void *data); |
1da177e4 | 894 | |
4f3549d7 RW |
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); | |
0aa0dc41 MM |
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); | |
eb5589a8 PG |
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 | ||
0aa0dc41 MM |
917 | extern void root_device_unregister(struct device *root); |
918 | ||
a5b8b1ad MB |
919 | static inline void *dev_get_platdata(const struct device *dev) |
920 | { | |
921 | return dev->platform_data; | |
922 | } | |
923 | ||
1da177e4 LT |
924 | /* |
925 | * Manual binding of a device to driver. See drivers/base/bus.c | |
926 | * for information on use. | |
927 | */ | |
f86db396 | 928 | extern int __must_check device_bind_driver(struct device *dev); |
d462943a GKH |
929 | extern void device_release_driver(struct device *dev); |
930 | extern int __must_check device_attach(struct device *dev); | |
f86db396 AM |
931 | extern int __must_check driver_attach(struct device_driver *drv); |
932 | extern int __must_check device_reprobe(struct device *dev); | |
1da177e4 | 933 | |
23681e47 GKH |
934 | /* |
935 | * Easy functions for dynamically creating devices on the fly | |
936 | */ | |
8882b394 GKH |
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); | |
b9075fa9 JP |
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, ...); | |
39ef3112 GR |
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, ...); | |
23681e47 | 952 | extern void device_destroy(struct class *cls, dev_t devt); |
1da177e4 | 953 | |
1da177e4 LT |
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 */ | |
d462943a | 960 | extern int (*platform_notify)(struct device *dev); |
1da177e4 | 961 | |
d462943a | 962 | extern int (*platform_notify_remove)(struct device *dev); |
1da177e4 LT |
963 | |
964 | ||
880ffb5c | 965 | /* |
1da177e4 LT |
966 | * get_device - atomically increment the reference count for the device. |
967 | * | |
968 | */ | |
d462943a GKH |
969 | extern struct device *get_device(struct device *dev); |
970 | extern void put_device(struct device *dev); | |
1da177e4 | 971 | |
2b2af54a KS |
972 | #ifdef CONFIG_DEVTMPFS |
973 | extern int devtmpfs_create_node(struct device *dev); | |
974 | extern int devtmpfs_delete_node(struct device *dev); | |
073120cc | 975 | extern int devtmpfs_mount(const char *mntdir); |
2b2af54a KS |
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 | ||
116f232b | 982 | /* drivers/base/power/shutdown.c */ |
1da177e4 LT |
983 | extern void device_shutdown(void); |
984 | ||
1da177e4 | 985 | /* debugging and troubleshooting/diagnostic helpers. */ |
bf9ca69f | 986 | extern const char *dev_driver_string(const struct device *dev); |
99bcf217 JP |
987 | |
988 | ||
989 | #ifdef CONFIG_PRINTK | |
990 | ||
0a18b050 JP |
991 | extern __printf(3, 0) |
992 | int dev_vprintk_emit(int level, const struct device *dev, | |
993 | const char *fmt, va_list args); | |
05e4e5b8 JP |
994 | extern __printf(3, 4) |
995 | int dev_printk_emit(int level, const struct device *dev, const char *fmt, ...); | |
798efc60 | 996 | |
b9075fa9 JP |
997 | extern __printf(3, 4) |
998 | int dev_printk(const char *level, const struct device *dev, | |
798efc60 | 999 | const char *fmt, ...); |
b9075fa9 JP |
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, ...); | |
99bcf217 JP |
1014 | |
1015 | #else | |
1016 | ||
0a18b050 JP |
1017 | static inline __printf(3, 0) |
1018 | int dev_vprintk_emit(int level, const struct device *dev, | |
1019 | const char *fmt, va_list args) | |
05e4e5b8 JP |
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 | ||
cbc46635 JP |
1025 | static inline int __dev_printk(const char *level, const struct device *dev, |
1026 | struct va_format *vaf) | |
b9075fa9 JP |
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; } | |
99bcf217 JP |
1054 | |
1055 | #endif | |
1056 | ||
6f586e66 HD |
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 | ||
6ca04593 HD |
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__) | |
6f586e66 | 1106 | #if defined(CONFIG_DYNAMIC_DEBUG) || defined(DEBUG) |
6ca04593 | 1107 | #define dev_dbg_ratelimited(dev, fmt, ...) \ |
6f586e66 HD |
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__); \ | |
99bcf217 | 1117 | } while (0) |
1da177e4 | 1118 | #else |
6f586e66 HD |
1119 | #define dev_dbg_ratelimited(dev, fmt, ...) \ |
1120 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) | |
1da177e4 LT |
1121 | #endif |
1122 | ||
aebdc3b4 DB |
1123 | #ifdef VERBOSE_DEBUG |
1124 | #define dev_vdbg dev_dbg | |
1125 | #else | |
99bcf217 JP |
1126 | #define dev_vdbg(dev, format, arg...) \ |
1127 | ({ \ | |
1128 | if (0) \ | |
1129 | dev_printk(KERN_DEBUG, dev, format, ##arg); \ | |
1130 | 0; \ | |
1131 | }) | |
aebdc3b4 DB |
1132 | #endif |
1133 | ||
e6139662 | 1134 | /* |
bcdd323b | 1135 | * dev_WARN*() acts like dev_printk(), but with the key difference |
e6139662 AV |
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 | ||
bcdd323b FB |
1142 | #define dev_WARN_ONCE(dev, condition, format, arg...) \ |
1143 | WARN_ONCE(condition, "Device %s\n" format, \ | |
1144 | dev_driver_string(dev), ## arg) | |
1145 | ||
1da177e4 LT |
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) "-*") | |
e52eec13 AK |
1151 | |
1152 | #ifdef CONFIG_SYSFS_DEPRECATED | |
1153 | extern long sysfs_deprecated; | |
1154 | #else | |
1155 | #define sysfs_deprecated 0 | |
1156 | #endif | |
1157 | ||
907d0ed1 LPC |
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 | * | |
2eda013f RD |
1164 | * @__driver: driver name |
1165 | * @__register: register function for this driver type | |
1166 | * @__unregister: unregister function for this driver type | |
cd494618 | 1167 | * @...: Additional arguments to be passed to __register and __unregister. |
2eda013f | 1168 | * |
907d0ed1 LPC |
1169 | * Use this macro to construct bus specific macros for registering |
1170 | * drivers, and do not use it on its own. | |
1171 | */ | |
cd494618 | 1172 | #define module_driver(__driver, __register, __unregister, ...) \ |
907d0ed1 LPC |
1173 | static int __init __driver##_init(void) \ |
1174 | { \ | |
cd494618 | 1175 | return __register(&(__driver) , ##__VA_ARGS__); \ |
907d0ed1 LPC |
1176 | } \ |
1177 | module_init(__driver##_init); \ | |
1178 | static void __exit __driver##_exit(void) \ | |
1179 | { \ | |
cd494618 | 1180 | __unregister(&(__driver) , ##__VA_ARGS__); \ |
907d0ed1 LPC |
1181 | } \ |
1182 | module_exit(__driver##_exit); | |
1183 | ||
1da177e4 | 1184 | #endif /* _DEVICE_H_ */ |