device.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  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/module.h>
  22. #include <linux/pm.h>
  23. #include <asm/atomic.h>
  24. #include <asm/device.h>
  25. struct device;
  26. struct device_private;
  27. struct device_driver;
  28. struct driver_private;
  29. struct class;
  30. struct class_private;
  31. struct bus_type;
  32. struct bus_type_private;
  33. struct device_node;
  34. struct bus_attribute {
  35. struct attribute attr;
  36. ssize_t (*show)(struct bus_type *bus, char *buf);
  37. ssize_t (*store)(struct bus_type *bus, const char *buf, size_t count);
  38. };
  39. #define BUS_ATTR(_name, _mode, _show, _store) \
  40. struct bus_attribute bus_attr_##_name = __ATTR(_name, _mode, _show, _store)
  41. extern int __must_check bus_create_file(struct bus_type *,
  42. struct bus_attribute *);
  43. extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
  44. struct bus_type {
  45. const char *name;
  46. struct bus_attribute *bus_attrs;
  47. struct device_attribute *dev_attrs;
  48. struct driver_attribute *drv_attrs;
  49. int (*match)(struct device *dev, struct device_driver *drv);
  50. int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
  51. int (*probe)(struct device *dev);
  52. int (*remove)(struct device *dev);
  53. void (*shutdown)(struct device *dev);
  54. int (*suspend)(struct device *dev, pm_message_t state);
  55. int (*resume)(struct device *dev);
  56. const struct dev_pm_ops *pm;
  57. struct bus_type_private *p;
  58. };
  59. extern int __must_check bus_register(struct bus_type *bus);
  60. extern void bus_unregister(struct bus_type *bus);
  61. extern int __must_check bus_rescan_devices(struct bus_type *bus);
  62. /* iterator helpers for buses */
  63. int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
  64. int (*fn)(struct device *dev, void *data));
  65. struct device *bus_find_device(struct bus_type *bus, struct device *start,
  66. void *data,
  67. int (*match)(struct device *dev, void *data));
  68. struct device *bus_find_device_by_name(struct bus_type *bus,
  69. struct device *start,
  70. const char *name);
  71. int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
  72. void *data, int (*fn)(struct device_driver *, void *));
  73. void bus_sort_breadthfirst(struct bus_type *bus,
  74. int (*compare)(const struct device *a,
  75. const struct device *b));
  76. /*
  77. * Bus notifiers: Get notified of addition/removal of devices
  78. * and binding/unbinding of drivers to devices.
  79. * In the long run, it should be a replacement for the platform
  80. * notify hooks.
  81. */
  82. struct notifier_block;
  83. extern int bus_register_notifier(struct bus_type *bus,
  84. struct notifier_block *nb);
  85. extern int bus_unregister_notifier(struct bus_type *bus,
  86. struct notifier_block *nb);
  87. /* All 4 notifers below get called with the target struct device *
  88. * as an argument. Note that those functions are likely to be called
  89. * with the device lock held in the core, so be careful.
  90. */
  91. #define BUS_NOTIFY_ADD_DEVICE 0x00000001 /* device added */
  92. #define BUS_NOTIFY_DEL_DEVICE 0x00000002 /* device removed */
  93. #define BUS_NOTIFY_BIND_DRIVER 0x00000003 /* driver about to be
  94. bound */
  95. #define BUS_NOTIFY_BOUND_DRIVER 0x00000004 /* driver bound to device */
  96. #define BUS_NOTIFY_UNBIND_DRIVER 0x00000005 /* driver about to be
  97. unbound */
  98. #define BUS_NOTIFY_UNBOUND_DRIVER 0x00000006 /* driver is unbound
  99. from the device */
  100. extern struct kset *bus_get_kset(struct bus_type *bus);
  101. extern struct klist *bus_get_device_klist(struct bus_type *bus);
  102. struct device_driver {
  103. const char *name;
  104. struct bus_type *bus;
  105. struct module *owner;
  106. const char *mod_name; /* used for built-in modules */
  107. bool suppress_bind_attrs; /* disables bind/unbind via sysfs */
  108. #if defined(CONFIG_OF)
  109. const struct of_device_id *of_match_table;
  110. #endif
  111. int (*probe) (struct device *dev);
  112. int (*remove) (struct device *dev);
  113. void (*shutdown) (struct device *dev);
  114. int (*suspend) (struct device *dev, pm_message_t state);
  115. int (*resume) (struct device *dev);
  116. const struct attribute_group **groups;
  117. const struct dev_pm_ops *pm;
  118. struct driver_private *p;
  119. };
  120. extern int __must_check driver_register(struct device_driver *drv);
  121. extern void driver_unregister(struct device_driver *drv);
  122. extern struct device_driver *get_driver(struct device_driver *drv);
  123. extern void put_driver(struct device_driver *drv);
  124. extern struct device_driver *driver_find(const char *name,
  125. struct bus_type *bus);
  126. extern int driver_probe_done(void);
  127. extern void wait_for_device_probe(void);
  128. /* sysfs interface for exporting driver attributes */
  129. struct driver_attribute {
  130. struct attribute attr;
  131. ssize_t (*show)(struct device_driver *driver, char *buf);
  132. ssize_t (*store)(struct device_driver *driver, const char *buf,
  133. size_t count);
  134. };
  135. #define DRIVER_ATTR(_name, _mode, _show, _store) \
  136. struct driver_attribute driver_attr_##_name = \
  137. __ATTR(_name, _mode, _show, _store)
  138. extern int __must_check driver_create_file(struct device_driver *driver,
  139. const struct driver_attribute *attr);
  140. extern void driver_remove_file(struct device_driver *driver,
  141. const struct driver_attribute *attr);
  142. extern int __must_check driver_add_kobj(struct device_driver *drv,
  143. struct kobject *kobj,
  144. const char *fmt, ...);
  145. extern int __must_check driver_for_each_device(struct device_driver *drv,
  146. struct device *start,
  147. void *data,
  148. int (*fn)(struct device *dev,
  149. void *));
  150. struct device *driver_find_device(struct device_driver *drv,
  151. struct device *start, void *data,
  152. int (*match)(struct device *dev, void *data));
  153. /*
  154. * device classes
  155. */
  156. struct class {
  157. const char *name;
  158. struct module *owner;
  159. struct class_attribute *class_attrs;
  160. struct device_attribute *dev_attrs;
  161. struct kobject *dev_kobj;
  162. int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);
  163. char *(*devnode)(struct device *dev, mode_t *mode);
  164. void (*class_release)(struct class *class);
  165. void (*dev_release)(struct device *dev);
  166. int (*suspend)(struct device *dev, pm_message_t state);
  167. int (*resume)(struct device *dev);
  168. const struct kobj_ns_type_operations *ns_type;
  169. const void *(*namespace)(struct device *dev);
  170. const struct dev_pm_ops *pm;
  171. struct class_private *p;
  172. };
  173. struct class_dev_iter {
  174. struct klist_iter ki;
  175. const struct device_type *type;
  176. };
  177. extern struct kobject *sysfs_dev_block_kobj;
  178. extern struct kobject *sysfs_dev_char_kobj;
  179. extern int __must_check __class_register(struct class *class,
  180. struct lock_class_key *key);
  181. extern void class_unregister(struct class *class);
  182. /* This is a #define to keep the compiler from merging different
  183. * instances of the __key variable */
  184. #define class_register(class) \
  185. ({ \
  186. static struct lock_class_key __key; \
  187. __class_register(class, &__key); \
  188. })
  189. struct class_compat;
  190. struct class_compat *class_compat_register(const char *name);
  191. void class_compat_unregister(struct class_compat *cls);
  192. int class_compat_create_link(struct class_compat *cls, struct device *dev,
  193. struct device *device_link);
  194. void class_compat_remove_link(struct class_compat *cls, struct device *dev,
  195. struct device *device_link);
  196. extern void class_dev_iter_init(struct class_dev_iter *iter,
  197. struct class *class,
  198. struct device *start,
  199. const struct device_type *type);
  200. extern struct device *class_dev_iter_next(struct class_dev_iter *iter);
  201. extern void class_dev_iter_exit(struct class_dev_iter *iter);
  202. extern int class_for_each_device(struct class *class, struct device *start,
  203. void *data,
  204. int (*fn)(struct device *dev, void *data));
  205. extern struct device *class_find_device(struct class *class,
  206. struct device *start, void *data,
  207. int (*match)(struct device *, void *));
  208. struct class_attribute {
  209. struct attribute attr;
  210. ssize_t (*show)(struct class *class, struct class_attribute *attr,
  211. char *buf);
  212. ssize_t (*store)(struct class *class, struct class_attribute *attr,
  213. const char *buf, size_t count);
  214. };
  215. #define CLASS_ATTR(_name, _mode, _show, _store) \
  216. struct class_attribute class_attr_##_name = __ATTR(_name, _mode, _show, _store)
  217. extern int __must_check class_create_file(struct class *class,
  218. const struct class_attribute *attr);
  219. extern void class_remove_file(struct class *class,
  220. const struct class_attribute *attr);
  221. /* Simple class attribute that is just a static string */
  222. struct class_attribute_string {
  223. struct class_attribute attr;
  224. char *str;
  225. };
  226. /* Currently read-only only */
  227. #define _CLASS_ATTR_STRING(_name, _mode, _str) \
  228. { __ATTR(_name, _mode, show_class_attr_string, NULL), _str }
  229. #define CLASS_ATTR_STRING(_name, _mode, _str) \
  230. struct class_attribute_string class_attr_##_name = \
  231. _CLASS_ATTR_STRING(_name, _mode, _str)
  232. extern ssize_t show_class_attr_string(struct class *class, struct class_attribute *attr,
  233. char *buf);
  234. struct class_interface {
  235. struct list_head node;
  236. struct class *class;
  237. int (*add_dev) (struct device *, struct class_interface *);
  238. void (*remove_dev) (struct device *, struct class_interface *);
  239. };
  240. extern int __must_check class_interface_register(struct class_interface *);
  241. extern void class_interface_unregister(struct class_interface *);
  242. extern struct class * __must_check __class_create(struct module *owner,
  243. const char *name,
  244. struct lock_class_key *key);
  245. extern void class_destroy(struct class *cls);
  246. /* This is a #define to keep the compiler from merging different
  247. * instances of the __key variable */
  248. #define class_create(owner, name) \
  249. ({ \
  250. static struct lock_class_key __key; \
  251. __class_create(owner, name, &__key); \
  252. })
  253. /*
  254. * The type of device, "struct device" is embedded in. A class
  255. * or bus can contain devices of different types
  256. * like "partitions" and "disks", "mouse" and "event".
  257. * This identifies the device type and carries type-specific
  258. * information, equivalent to the kobj_type of a kobject.
  259. * If "name" is specified, the uevent will contain it in
  260. * the DEVTYPE variable.
  261. */
  262. struct device_type {
  263. const char *name;
  264. const struct attribute_group **groups;
  265. int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
  266. char *(*devnode)(struct device *dev, mode_t *mode);
  267. void (*release)(struct device *dev);
  268. const struct dev_pm_ops *pm;
  269. };
  270. /* interface for exporting device attributes */
  271. struct device_attribute {
  272. struct attribute attr;
  273. ssize_t (*show)(struct device *dev, struct device_attribute *attr,
  274. char *buf);
  275. ssize_t (*store)(struct device *dev, struct device_attribute *attr,
  276. const char *buf, size_t count);
  277. };
  278. #define DEVICE_ATTR(_name, _mode, _show, _store) \
  279. struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
  280. extern int __must_check device_create_file(struct device *device,
  281. const struct device_attribute *entry);
  282. extern void device_remove_file(struct device *dev,
  283. const struct device_attribute *attr);
  284. extern int __must_check device_create_bin_file(struct device *dev,
  285. const struct bin_attribute *attr);
  286. extern void device_remove_bin_file(struct device *dev,
  287. const struct bin_attribute *attr);
  288. extern int device_schedule_callback_owner(struct device *dev,
  289. void (*func)(struct device *dev), struct module *owner);
  290. /* This is a macro to avoid include problems with THIS_MODULE */
  291. #define device_schedule_callback(dev, func) \
  292. device_schedule_callback_owner(dev, func, THIS_MODULE)
  293. /* device resource management */
  294. typedef void (*dr_release_t)(struct device *dev, void *res);
  295. typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data);
  296. #ifdef CONFIG_DEBUG_DEVRES
  297. extern void *__devres_alloc(dr_release_t release, size_t size, gfp_t gfp,
  298. const char *name);
  299. #define devres_alloc(release, size, gfp) \
  300. __devres_alloc(release, size, gfp, #release)
  301. #else
  302. extern void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp);
  303. #endif
  304. extern void devres_free(void *res);
  305. extern void devres_add(struct device *dev, void *res);
  306. extern void *devres_find(struct device *dev, dr_release_t release,
  307. dr_match_t match, void *match_data);
  308. extern void *devres_get(struct device *dev, void *new_res,
  309. dr_match_t match, void *match_data);
  310. extern void *devres_remove(struct device *dev, dr_release_t release,
  311. dr_match_t match, void *match_data);
  312. extern int devres_destroy(struct device *dev, dr_release_t release,
  313. dr_match_t match, void *match_data);
  314. /* devres group */
  315. extern void * __must_check devres_open_group(struct device *dev, void *id,
  316. gfp_t gfp);
  317. extern void devres_close_group(struct device *dev, void *id);
  318. extern void devres_remove_group(struct device *dev, void *id);
  319. extern int devres_release_group(struct device *dev, void *id);
  320. /* managed kzalloc/kfree for device drivers, no kmalloc, always use kzalloc */
  321. extern void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp);
  322. extern void devm_kfree(struct device *dev, void *p);
  323. struct device_dma_parameters {
  324. /*
  325. * a low level driver may set these to teach IOMMU code about
  326. * sg limitations.
  327. */
  328. unsigned int max_segment_size;
  329. unsigned long segment_boundary_mask;
  330. };
  331. struct device {
  332. struct device *parent;
  333. struct device_private *p;
  334. struct kobject kobj;
  335. const char *init_name; /* initial name of the device */
  336. struct device_type *type;
  337. struct mutex mutex; /* mutex to synchronize calls to
  338. * its driver.
  339. */
  340. struct bus_type *bus; /* type of bus device is on */
  341. struct device_driver *driver; /* which driver has allocated this
  342. device */
  343. void *platform_data; /* Platform specific data, device
  344. core doesn't touch it */
  345. struct dev_pm_info power;
  346. #ifdef CONFIG_NUMA
  347. int numa_node; /* NUMA node this device is close to */
  348. #endif
  349. u64 *dma_mask; /* dma mask (if dma'able device) */
  350. u64 coherent_dma_mask;/* Like dma_mask, but for
  351. alloc_coherent mappings as
  352. not all hardware supports
  353. 64 bit addresses for consistent
  354. allocations such descriptors. */
  355. struct device_dma_parameters *dma_parms;
  356. struct list_head dma_pools; /* dma pools (if dma'ble) */
  357. struct dma_coherent_mem *dma_mem; /* internal for coherent mem
  358. override */
  359. /* arch specific additions */
  360. struct dev_archdata archdata;
  361. #ifdef CONFIG_OF
  362. struct device_node *of_node;
  363. #endif
  364. dev_t devt; /* dev_t, creates the sysfs "dev" */
  365. spinlock_t devres_lock;
  366. struct list_head devres_head;
  367. struct klist_node knode_class;
  368. struct class *class;
  369. const struct attribute_group **groups; /* optional groups */
  370. void (*release)(struct device *dev);
  371. };
  372. /* Get the wakeup routines, which depend on struct device */
  373. #include <linux/pm_wakeup.h>
  374. static inline const char *dev_name(const struct device *dev)
  375. {
  376. /* Use the init name until the kobject becomes available */
  377. if (dev->init_name)
  378. return dev->init_name;
  379. return kobject_name(&dev->kobj);
  380. }
  381. extern int dev_set_name(struct device *dev, const char *name, ...)
  382. __attribute__((format(printf, 2, 3)));
  383. #ifdef CONFIG_NUMA
  384. static inline int dev_to_node(struct device *dev)
  385. {
  386. return dev->numa_node;
  387. }
  388. static inline void set_dev_node(struct device *dev, int node)
  389. {
  390. dev->numa_node = node;
  391. }
  392. #else
  393. static inline int dev_to_node(struct device *dev)
  394. {
  395. return -1;
  396. }
  397. static inline void set_dev_node(struct device *dev, int node)
  398. {
  399. }
  400. #endif
  401. static inline unsigned int dev_get_uevent_suppress(const struct device *dev)
  402. {
  403. return dev->kobj.uevent_suppress;
  404. }
  405. static inline void dev_set_uevent_suppress(struct device *dev, int val)
  406. {
  407. dev->kobj.uevent_suppress = val;
  408. }
  409. static inline int device_is_registered(struct device *dev)
  410. {
  411. return dev->kobj.state_in_sysfs;
  412. }
  413. static inline void device_enable_async_suspend(struct device *dev)
  414. {
  415. if (!dev->power.in_suspend)
  416. dev->power.async_suspend = true;
  417. }
  418. static inline void device_disable_async_suspend(struct device *dev)
  419. {
  420. if (!dev->power.in_suspend)
  421. dev->power.async_suspend = false;
  422. }
  423. static inline bool device_async_suspend_enabled(struct device *dev)
  424. {
  425. return !!dev->power.async_suspend;
  426. }
  427. static inline void device_lock(struct device *dev)
  428. {
  429. mutex_lock(&dev->mutex);
  430. }
  431. static inline int device_trylock(struct device *dev)
  432. {
  433. return mutex_trylock(&dev->mutex);
  434. }
  435. static inline void device_unlock(struct device *dev)
  436. {
  437. mutex_unlock(&dev->mutex);
  438. }
  439. void driver_init(void);
  440. /*
  441. * High level routines for use by the bus drivers
  442. */
  443. extern int __must_check device_register(struct device *dev);
  444. extern void device_unregister(struct device *dev);
  445. extern void device_initialize(struct device *dev);
  446. extern int __must_check device_add(struct device *dev);
  447. extern void device_del(struct device *dev);
  448. extern int device_for_each_child(struct device *dev, void *data,
  449. int (*fn)(struct device *dev, void *data));
  450. extern struct device *device_find_child(struct device *dev, void *data,
  451. int (*match)(struct device *dev, void *data));
  452. extern int device_rename(struct device *dev, const char *new_name);
  453. extern int device_move(struct device *dev, struct device *new_parent,
  454. enum dpm_order dpm_order);
  455. extern const char *device_get_devnode(struct device *dev,
  456. mode_t *mode, const char **tmp);
  457. extern void *dev_get_drvdata(const struct device *dev);
  458. extern void dev_set_drvdata(struct device *dev, void *data);
  459. /*
  460. * Root device objects for grouping under /sys/devices
  461. */
  462. extern struct device *__root_device_register(const char *name,
  463. struct module *owner);
  464. static inline struct device *root_device_register(const char *name)
  465. {
  466. return __root_device_register(name, THIS_MODULE);
  467. }
  468. extern void root_device_unregister(struct device *root);
  469. static inline void *dev_get_platdata(const struct device *dev)
  470. {
  471. return dev->platform_data;
  472. }
  473. /*
  474. * Manual binding of a device to driver. See drivers/base/bus.c
  475. * for information on use.
  476. */
  477. extern int __must_check device_bind_driver(struct device *dev);
  478. extern void device_release_driver(struct device *dev);
  479. extern int __must_check device_attach(struct device *dev);
  480. extern int __must_check driver_attach(struct device_driver *drv);
  481. extern int __must_check device_reprobe(struct device *dev);
  482. /*
  483. * Easy functions for dynamically creating devices on the fly
  484. */
  485. extern struct device *device_create_vargs(struct class *cls,
  486. struct device *parent,
  487. dev_t devt,
  488. void *drvdata,
  489. const char *fmt,
  490. va_list vargs);
  491. extern struct device *device_create(struct class *cls, struct device *parent,
  492. dev_t devt, void *drvdata,
  493. const char *fmt, ...)
  494. __attribute__((format(printf, 5, 6)));
  495. extern void device_destroy(struct class *cls, dev_t devt);
  496. /*
  497. * Platform "fixup" functions - allow the platform to have their say
  498. * about devices and actions that the general device layer doesn't
  499. * know about.
  500. */
  501. /* Notify platform of device discovery */
  502. extern int (*platform_notify)(struct device *dev);
  503. extern int (*platform_notify_remove)(struct device *dev);
  504. /**
  505. * get_device - atomically increment the reference count for the device.
  506. *
  507. */
  508. extern struct device *get_device(struct device *dev);
  509. extern void put_device(struct device *dev);
  510. extern void wait_for_device_probe(void);
  511. #ifdef CONFIG_DEVTMPFS
  512. extern int devtmpfs_create_node(struct device *dev);
  513. extern int devtmpfs_delete_node(struct device *dev);
  514. extern int devtmpfs_mount(const char *mntdir);
  515. #else
  516. static inline int devtmpfs_create_node(struct device *dev) { return 0; }
  517. static inline int devtmpfs_delete_node(struct device *dev) { return 0; }
  518. static inline int devtmpfs_mount(const char *mountpoint) { return 0; }
  519. #endif
  520. /* drivers/base/power/shutdown.c */
  521. extern void device_shutdown(void);
  522. /* drivers/base/sys.c */
  523. extern void sysdev_shutdown(void);
  524. /* debugging and troubleshooting/diagnostic helpers. */
  525. extern const char *dev_driver_string(const struct device *dev);
  526. #ifdef CONFIG_PRINTK
  527. extern int dev_printk(const char *level, const struct device *dev,
  528. const char *fmt, ...)
  529. __attribute__ ((format (printf, 3, 4)));
  530. extern int dev_emerg(const struct device *dev, const char *fmt, ...)
  531. __attribute__ ((format (printf, 2, 3)));
  532. extern int dev_alert(const struct device *dev, const char *fmt, ...)
  533. __attribute__ ((format (printf, 2, 3)));
  534. extern int dev_crit(const struct device *dev, const char *fmt, ...)
  535. __attribute__ ((format (printf, 2, 3)));
  536. extern int dev_err(const struct device *dev, const char *fmt, ...)
  537. __attribute__ ((format (printf, 2, 3)));
  538. extern int dev_warn(const struct device *dev, const char *fmt, ...)
  539. __attribute__ ((format (printf, 2, 3)));
  540. extern int dev_notice(const struct device *dev, const char *fmt, ...)
  541. __attribute__ ((format (printf, 2, 3)));
  542. extern int _dev_info(const struct device *dev, const char *fmt, ...)
  543. __attribute__ ((format (printf, 2, 3)));
  544. #else
  545. static inline int dev_printk(const char *level, const struct device *dev,
  546. const char *fmt, ...)
  547. __attribute__ ((format (printf, 3, 4)));
  548. static inline int dev_printk(const char *level, const struct device *dev,
  549. const char *fmt, ...)
  550. { return 0; }
  551. static inline int dev_emerg(const struct device *dev, const char *fmt, ...)
  552. __attribute__ ((format (printf, 2, 3)));
  553. static inline int dev_emerg(const struct device *dev, const char *fmt, ...)
  554. { return 0; }
  555. static inline int dev_crit(const struct device *dev, const char *fmt, ...)
  556. __attribute__ ((format (printf, 2, 3)));
  557. static inline int dev_crit(const struct device *dev, const char *fmt, ...)
  558. { return 0; }
  559. static inline int dev_alert(const struct device *dev, const char *fmt, ...)
  560. __attribute__ ((format (printf, 2, 3)));
  561. static inline int dev_alert(const struct device *dev, const char *fmt, ...)
  562. { return 0; }
  563. static inline int dev_err(const struct device *dev, const char *fmt, ...)
  564. __attribute__ ((format (printf, 2, 3)));
  565. static inline int dev_err(const struct device *dev, const char *fmt, ...)
  566. { return 0; }
  567. static inline int dev_warn(const struct device *dev, const char *fmt, ...)
  568. __attribute__ ((format (printf, 2, 3)));
  569. static inline int dev_warn(const struct device *dev, const char *fmt, ...)
  570. { return 0; }
  571. static inline int dev_notice(const struct device *dev, const char *fmt, ...)
  572. __attribute__ ((format (printf, 2, 3)));
  573. static inline int dev_notice(const struct device *dev, const char *fmt, ...)
  574. { return 0; }
  575. static inline int _dev_info(const struct device *dev, const char *fmt, ...)
  576. __attribute__ ((format (printf, 2, 3)));
  577. static inline int _dev_info(const struct device *dev, const char *fmt, ...)
  578. { return 0; }
  579. #endif
  580. /*
  581. * Stupid hackaround for existing uses of non-printk uses dev_info
  582. *
  583. * Note that the definition of dev_info below is actually _dev_info
  584. * and a macro is used to avoid redefining dev_info
  585. */
  586. #define dev_info(dev, fmt, arg...) _dev_info(dev, fmt, ##arg)
  587. #if defined(DEBUG)
  588. #define dev_dbg(dev, format, arg...) \
  589. dev_printk(KERN_DEBUG, dev, format, ##arg)
  590. #elif defined(CONFIG_DYNAMIC_DEBUG)
  591. #define dev_dbg(dev, format, ...) \
  592. do { \
  593. dynamic_dev_dbg(dev, format, ##__VA_ARGS__); \
  594. } while (0)
  595. #else
  596. #define dev_dbg(dev, format, arg...) \
  597. ({ \
  598. if (0) \
  599. dev_printk(KERN_DEBUG, dev, format, ##arg); \
  600. 0; \
  601. })
  602. #endif
  603. #ifdef VERBOSE_DEBUG
  604. #define dev_vdbg dev_dbg
  605. #else
  606. #define dev_vdbg(dev, format, arg...) \
  607. ({ \
  608. if (0) \
  609. dev_printk(KERN_DEBUG, dev, format, ##arg); \
  610. 0; \
  611. })
  612. #endif
  613. /*
  614. * dev_WARN() acts like dev_printk(), but with the key difference
  615. * of using a WARN/WARN_ON to get the message out, including the
  616. * file/line information and a backtrace.
  617. */
  618. #define dev_WARN(dev, format, arg...) \
  619. WARN(1, "Device: %s\n" format, dev_driver_string(dev), ## arg);
  620. /* Create alias, so I can be autoloaded. */
  621. #define MODULE_ALIAS_CHARDEV(major,minor) \
  622. MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor))
  623. #define MODULE_ALIAS_CHARDEV_MAJOR(major) \
  624. MODULE_ALIAS("char-major-" __stringify(major) "-*")
  625. #ifdef CONFIG_SYSFS_DEPRECATED
  626. extern long sysfs_deprecated;
  627. #else
  628. #define sysfs_deprecated 0
  629. #endif
  630. #endif /* _DEVICE_H_ */