device.h 42 KB

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