device.h 24 KB

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