device.h 21 KB

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