device.h 24 KB

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