device.h 42 KB

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