device.h 41 KB

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