/testbed/sys/device.h

http://rtems-atapi.googlecode.com/ · C Header · 527 lines · 313 code · 70 blank · 144 comment · 1 complexity · cd9b1caa2537dac32e6e658f1fcd2d4c MD5 · raw file

  1. /* $NetBSD: device.h,v 1.112.6.1 2009/03/15 19:43:48 snj Exp $ */
  2. /*
  3. * Copyright (c) 1996, 2000 Christopher G. Demetriou
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. All advertising materials mentioning features or use of this software
  15. * must display the following acknowledgement:
  16. * This product includes software developed for the
  17. * NetBSD Project. See http://www.NetBSD.org/ for
  18. * information about NetBSD.
  19. * 4. The name of the author may not be used to endorse or promote products
  20. * derived from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  23. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  24. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  25. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  27. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  31. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. * --(license Id: LICENSE.proto,v 1.1 2000/06/13 21:40:26 cgd Exp )--
  34. */
  35. /*
  36. * Copyright (c) 1992, 1993
  37. * The Regents of the University of California. All rights reserved.
  38. *
  39. * This software was developed by the Computer Systems Engineering group
  40. * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
  41. * contributed to Berkeley.
  42. *
  43. * All advertising materials mentioning features or use of this software
  44. * must display the following acknowledgement:
  45. * This product includes software developed by the University of
  46. * California, Lawrence Berkeley Laboratories.
  47. *
  48. * Redistribution and use in source and binary forms, with or without
  49. * modification, are permitted provided that the following conditions
  50. * are met:
  51. * 1. Redistributions of source code must retain the above copyright
  52. * notice, this list of conditions and the following disclaimer.
  53. * 2. Redistributions in binary form must reproduce the above copyright
  54. * notice, this list of conditions and the following disclaimer in the
  55. * documentation and/or other materials provided with the distribution.
  56. * 3. Neither the name of the University nor the names of its contributors
  57. * may be used to endorse or promote products derived from this software
  58. * without specific prior written permission.
  59. *
  60. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  61. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  62. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  63. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  64. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  65. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  66. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  67. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  68. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  69. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  70. * SUCH DAMAGE.
  71. *
  72. * @(#)device.h 8.2 (Berkeley) 2/17/94
  73. */
  74. #ifndef _SYS_DEVICE_H_
  75. #define _SYS_DEVICE_H_
  76. //#include <sys/evcnt.h>
  77. #include <rtems/bsd/sys/queue.h>
  78. //typedef struct device *device_t;
  79. #ifdef _KERNEL
  80. #include "pmf.h"
  81. #endif
  82. //#include <prop/proplib.h>
  83. /*
  84. * Minimal device structures.
  85. * Note that all ``system'' device types are listed here.
  86. */
  87. typedef enum devclass {
  88. DV_DULL, /* generic, no special info */
  89. DV_CPU, /* CPU (carries resource utilization) */
  90. DV_DISK, /* disk drive (label, etc) */
  91. DV_IFNET, /* network interface */
  92. DV_TAPE, /* tape device */
  93. DV_TTY, /* serial line interface (?) */
  94. DV_AUDIODEV, /* audio device */
  95. DV_DISPLAYDEV, /* display device */
  96. DV_BUS /* bus device */
  97. } devclass_t;
  98. /*
  99. * Actions for ca_activate.
  100. */
  101. typedef enum devact {
  102. DVACT_ACTIVATE, /* activate the device */
  103. DVACT_DEACTIVATE /* deactivate the device */
  104. } devact_t;
  105. typedef enum {
  106. DVA_SYSTEM,
  107. DVA_HARDWARE
  108. } devactive_t;
  109. typedef struct cfdata *cfdata_t;
  110. typedef struct cfdriver *cfdriver_t;
  111. typedef struct cfattach *cfattach_t;
  112. struct device {
  113. devclass_t dv_class; /* this device's classification */
  114. TAILQ_ENTRY(device) dv_list; /* entry on list of all devices */
  115. cfdata_t dv_cfdata; /* config data that found us
  116. (NULL if pseudo-device) */
  117. cfdriver_t dv_cfdriver; /* our cfdriver */
  118. cfattach_t dv_cfattach; /* our cfattach */
  119. int dv_unit; /* device unit number */
  120. char dv_xname[16]; /* external name (name + unit) */
  121. device_t dv_parent; /* pointer to parent device
  122. (NULL if pseudo- or root node) */
  123. int dv_depth; /* number of parents until root */
  124. int dv_flags; /* misc. flags; see below */
  125. void *dv_private; /* this device's private storage */
  126. int *dv_locators; /* our actual locators (optional) */
  127. //prop_dictionary_t dv_properties;/* properties dictionary */
  128. size_t dv_activity_count;
  129. void (**dv_activity_handlers)(device_t, devactive_t);
  130. bool (*dv_driver_suspend)(device_t PMF_FN_PROTO);
  131. bool (*dv_driver_resume)(device_t PMF_FN_PROTO);
  132. bool (*dv_driver_shutdown)(device_t, int);
  133. bool (*dv_driver_child_register)(device_t);
  134. void *dv_bus_private;
  135. bool (*dv_bus_suspend)(device_t PMF_FN_PROTO);
  136. bool (*dv_bus_resume)(device_t PMF_FN_PROTO);
  137. bool (*dv_bus_shutdown)(device_t, int);
  138. void (*dv_bus_deregister)(device_t);
  139. void *dv_class_private;
  140. bool (*dv_class_suspend)(device_t PMF_FN_PROTO);
  141. bool (*dv_class_resume)(device_t PMF_FN_PROTO);
  142. void (*dv_class_deregister)(device_t);
  143. void *dv_pmf_private;
  144. };
  145. /* dv_flags */
  146. #define DVF_ACTIVE 0x0001 /* device is activated */
  147. #define DVF_PRIV_ALLOC 0x0002 /* device private storage != device */
  148. #define DVF_POWER_HANDLERS 0x0004 /* device has suspend/resume support */
  149. #define DVF_CLASS_SUSPENDED 0x0008 /* device class suspend was called */
  150. #define DVF_DRIVER_SUSPENDED 0x0010 /* device driver suspend was called */
  151. #define DVF_BUS_SUSPENDED 0x0020 /* device bus suspend was called */
  152. #define DVF_SELF_SUSPENDED 0x0040 /* device suspended itself */
  153. TAILQ_HEAD(devicelist, device);
  154. enum deviter_flags {
  155. DEVITER_F_RW = 0x1
  156. , DEVITER_F_SHUTDOWN = 0x2
  157. , DEVITER_F_LEAVES_FIRST = 0x4
  158. , DEVITER_F_ROOT_FIRST = 0x8
  159. };
  160. typedef enum deviter_flags deviter_flags_t;
  161. struct deviter {
  162. device_t di_prev;
  163. deviter_flags_t di_flags;
  164. int di_curdepth;
  165. int di_maxdepth;
  166. };
  167. typedef struct deviter deviter_t;
  168. /*
  169. * Description of a locator, as part of interface attribute definitions.
  170. */
  171. struct cflocdesc {
  172. const char *cld_name;
  173. const char *cld_defaultstr; /* NULL if no default */
  174. int cld_default;
  175. };
  176. /*
  177. * Description of an interface attribute, provided by potential
  178. * parent device drivers, referred to by child device configuration data.
  179. */
  180. struct cfiattrdata {
  181. const char *ci_name;
  182. int ci_loclen;
  183. const struct cflocdesc ci_locdesc[
  184. #if defined(__GNUC__) && __GNUC__ <= 2
  185. 0
  186. #endif
  187. ];
  188. };
  189. /*
  190. * Description of a configuration parent. Each device attachment attaches
  191. * to an "interface attribute", which is given in this structure. The parent
  192. * *must* carry this attribute. Optionally, an individual device instance
  193. * may also specify a specific parent device instance.
  194. */
  195. struct cfparent {
  196. const char *cfp_iattr; /* interface attribute */
  197. const char *cfp_parent; /* optional specific parent */
  198. int cfp_unit; /* optional specific unit
  199. (-1 to wildcard) */
  200. };
  201. /*
  202. * Configuration data (i.e., data placed in ioconf.c).
  203. */
  204. struct cfdata {
  205. const char *cf_name; /* driver name */
  206. const char *cf_atname; /* attachment name */
  207. short cf_unit; /* unit number */
  208. short cf_fstate; /* finding state (below) */
  209. int *cf_loc; /* locators (machine dependent) */
  210. int cf_flags; /* flags from config */
  211. const struct cfparent *cf_pspec;/* parent specification */
  212. };
  213. #define FSTATE_NOTFOUND 0 /* has not been found */
  214. #define FSTATE_FOUND 1 /* has been found */
  215. #define FSTATE_STAR 2 /* duplicable */
  216. #define FSTATE_DSTAR 3 /* has not been found, and disabled */
  217. #define FSTATE_DNOTFOUND 4 /* duplicate, and disabled */
  218. /*
  219. * Multiple configuration data tables may be maintained. This structure
  220. * provides the linkage.
  221. */
  222. struct cftable {
  223. cfdata_t ct_cfdata; /* pointer to cfdata table */
  224. TAILQ_ENTRY(cftable) ct_list; /* list linkage */
  225. };
  226. TAILQ_HEAD(cftablelist, cftable);
  227. typedef int (*cfsubmatch_t)(device_t, cfdata_t, const int *, void *);
  228. /*
  229. * `configuration' attachment and driver (what the machine-independent
  230. * autoconf uses). As devices are found, they are applied against all
  231. * the potential matches. The one with the best match is taken, and a
  232. * device structure (plus any other data desired) is allocated. Pointers
  233. * to these are placed into an array of pointers. The array itself must
  234. * be dynamic since devices can be found long after the machine is up
  235. * and running.
  236. *
  237. * Devices can have multiple configuration attachments if they attach
  238. * to different attributes (busses, or whatever), to allow specification
  239. * of multiple match and attach functions. There is only one configuration
  240. * driver per driver, so that things like unit numbers and the device
  241. * structure array will be shared.
  242. */
  243. struct cfattach {
  244. const char *ca_name; /* name of attachment */
  245. LIST_ENTRY(cfattach) ca_list; /* link on cfdriver's list */
  246. size_t ca_devsize; /* size of dev data (for malloc) */
  247. int ca_flags; /* flags for driver allocation etc */
  248. int (*ca_match)(device_t, cfdata_t, void *);
  249. void (*ca_attach)(device_t, device_t, void *);
  250. int (*ca_detach)(device_t, int);
  251. int (*ca_activate)(device_t, devact_t);
  252. /* technically, the next 2 belong into "struct cfdriver" */
  253. int (*ca_rescan)(device_t, const char *,
  254. const int *); /* scan for new children */
  255. void (*ca_childdetached)(device_t, device_t);
  256. };
  257. LIST_HEAD(cfattachlist, cfattach);
  258. #define CFATTACH_DECL2(name, ddsize, matfn, attfn, detfn, actfn, \
  259. rescanfn, chdetfn) \
  260. struct cfattach __CONCAT(name,_ca) = { \
  261. .ca_name = ___STRING(name), \
  262. .ca_devsize = ddsize, \
  263. .ca_match = matfn, \
  264. .ca_attach = attfn, \
  265. .ca_detach = detfn, \
  266. .ca_activate = actfn, \
  267. .ca_rescan = rescanfn, \
  268. .ca_childdetached = chdetfn, \
  269. }
  270. #define CFATTACH_DECL(name, ddsize, matfn, attfn, detfn, actfn) \
  271. CFATTACH_DECL2(name, ddsize, matfn, attfn, detfn, actfn, NULL, NULL)
  272. #define CFATTACH_DECL2_NEW(name, ddsize, matfn, attfn, detfn, actfn, \
  273. rescanfn, chdetfn) \
  274. struct cfattach __CONCAT(name,_ca) = { \
  275. .ca_name = ___STRING(name), \
  276. .ca_devsize = ddsize, \
  277. .ca_flags = DVF_PRIV_ALLOC, \
  278. .ca_match = matfn, \
  279. .ca_attach = attfn, \
  280. .ca_detach = detfn, \
  281. .ca_activate = actfn, \
  282. .ca_rescan = rescanfn, \
  283. .ca_childdetached = chdetfn, \
  284. }
  285. #define CFATTACH_DECL_NEW(name, ddsize, matfn, attfn, detfn, actfn) \
  286. CFATTACH_DECL2_NEW(name, ddsize, matfn, attfn, detfn, actfn, NULL, NULL)
  287. /* Flags given to config_detach(), and the ca_detach function. */
  288. #define DETACH_FORCE 0x01 /* force detachment; hardware gone */
  289. #define DETACH_QUIET 0x02 /* don't print a notice */
  290. struct cfdriver {
  291. LIST_ENTRY(cfdriver) cd_list; /* link on allcfdrivers */
  292. struct cfattachlist cd_attach; /* list of all attachments */
  293. device_t *cd_devs; /* devices found */
  294. const char *cd_name; /* device name */
  295. enum devclass cd_class; /* device classification */
  296. int cd_ndevs; /* size of cd_devs array */
  297. const struct cfiattrdata * const *cd_attrs; /* attributes provided */
  298. };
  299. LIST_HEAD(cfdriverlist, cfdriver);
  300. #define CFDRIVER_DECL(name, class, attrs) \
  301. struct cfdriver __CONCAT(name,_cd) = { \
  302. .cd_name = ___STRING(name), \
  303. .cd_class = class, \
  304. .cd_attrs = attrs, \
  305. }
  306. /*
  307. * The cfattachinit is a data structure used to associate a list of
  308. * cfattach's with cfdrivers as found in the static kernel configuration.
  309. */
  310. struct cfattachinit {
  311. const char *cfai_name; /* driver name */
  312. struct cfattach * const *cfai_list;/* list of attachments */
  313. };
  314. /*
  315. * the same, but with a non-constant list so it can be modified
  316. * for LKM bookkeeping
  317. */
  318. struct cfattachlkminit {
  319. const char *cfai_name; /* driver name */
  320. struct cfattach **cfai_list; /* list of attachments */
  321. };
  322. /*
  323. * Configuration printing functions, and their return codes. The second
  324. * argument is NULL if the device was configured; otherwise it is the name
  325. * of the parent device. The return value is ignored if the device was
  326. * configured, so most functions can return UNCONF unconditionally.
  327. */
  328. typedef int (*cfprint_t)(void *, const char *); /* XXX const char * */
  329. #define QUIET 0 /* print nothing */
  330. #define UNCONF 1 /* print " not configured\n" */
  331. #define UNSUPP 2 /* print " not supported\n" */
  332. /*
  333. * Pseudo-device attach information (function + number of pseudo-devs).
  334. */
  335. struct pdevinit {
  336. void (*pdev_attach)(int);
  337. int pdev_count;
  338. };
  339. /* This allows us to wildcard a device unit. */
  340. #define DVUNIT_ANY -1
  341. #ifdef _KERNEL
  342. extern struct cfdriverlist allcfdrivers;/* list of all cfdrivers */
  343. extern struct devicelist alldevs; /* list of all devices */
  344. extern struct cftablelist allcftables; /* list of all cfdata tables */
  345. extern device_t booted_device; /* the device we booted from */
  346. extern device_t booted_wedge; /* the wedge on that device */
  347. extern int booted_partition; /* or the partition on that device */
  348. struct vnode *opendisk(struct device *);
  349. int config_handle_wedges(struct device *, int);
  350. void config_init(void);
  351. void drvctl_init(void);
  352. void configure(void);
  353. void configure2(void);
  354. int config_cfdriver_attach(struct cfdriver *);
  355. int config_cfdriver_detach(struct cfdriver *);
  356. int config_cfattach_attach(const char *, struct cfattach *);
  357. int config_cfattach_detach(const char *, struct cfattach *);
  358. int config_cfdata_attach(cfdata_t, int);
  359. int config_cfdata_detach(cfdata_t);
  360. struct cfdriver *config_cfdriver_lookup(const char *);
  361. struct cfattach *config_cfattach_lookup(const char *, const char *);
  362. const struct cfiattrdata *cfiattr_lookup(const char *, const struct cfdriver *);
  363. int config_stdsubmatch(device_t, cfdata_t, const int *, void *);
  364. cfdata_t config_search_loc(cfsubmatch_t, device_t,
  365. const char *, const int *, void *);
  366. cfdata_t config_search_ia(cfsubmatch_t, device_t,
  367. const char *, void *);
  368. cfdata_t config_rootsearch(cfsubmatch_t, const char *, void *);
  369. device_t config_found_sm_loc(device_t, const char *, const int *,
  370. void *, cfprint_t, cfsubmatch_t);
  371. device_t config_found_ia(device_t, const char *, void *, cfprint_t);
  372. device_t config_found(device_t, void *, cfprint_t);
  373. device_t config_rootfound(const char *, void *);
  374. device_t config_attach_loc(device_t, cfdata_t, const int *, void *, cfprint_t);
  375. device_t config_attach(device_t, cfdata_t, void *, cfprint_t);
  376. int config_match(device_t, cfdata_t, void *);
  377. device_t config_attach_pseudo(cfdata_t);
  378. int config_detach(device_t, int);
  379. int config_detach_children(device_t, int flags);
  380. int config_activate(device_t);
  381. int config_deactivate(device_t);
  382. void config_defer(device_t, void (*)(device_t));
  383. void config_deferred(device_t);
  384. void config_interrupts(device_t, void (*)(device_t));
  385. void config_pending_incr(void);
  386. void config_pending_decr(void);
  387. int config_finalize_register(device_t, int (*)(device_t));
  388. void config_finalize(void);
  389. device_t device_lookup(cfdriver_t, int);
  390. void *device_lookup_private(cfdriver_t, int);
  391. #ifdef __HAVE_DEVICE_REGISTER
  392. void device_register(device_t, void *);
  393. #endif
  394. devclass_t device_class(device_t);
  395. cfdata_t device_cfdata(device_t);
  396. cfdriver_t device_cfdriver(device_t);
  397. cfattach_t device_cfattach(device_t);
  398. int device_unit(device_t);
  399. const char *device_xname(device_t);
  400. device_t device_parent(device_t);
  401. bool device_is_active(device_t);
  402. bool device_is_enabled(device_t);
  403. bool device_has_power(device_t);
  404. int device_locator(device_t, u_int);
  405. void *device_private(device_t);
  406. //prop_dictionary_t device_properties(device_t);
  407. device_t deviter_first(deviter_t *, deviter_flags_t);
  408. void deviter_init(deviter_t *, deviter_flags_t);
  409. device_t deviter_next(deviter_t *);
  410. void deviter_release(deviter_t *);
  411. bool device_active(device_t, devactive_t);
  412. bool device_active_register(device_t,
  413. void (*)(device_t, devactive_t));
  414. void device_active_deregister(device_t,
  415. void (*)(device_t, devactive_t));
  416. bool device_is_a(device_t, const char *);
  417. device_t device_find_by_xname(const char *);
  418. device_t device_find_by_driver_unit(const char *, int);
  419. bool device_pmf_is_registered(device_t);
  420. bool device_pmf_driver_suspend(device_t PMF_FN_PROTO);
  421. bool device_pmf_driver_resume(device_t PMF_FN_PROTO);
  422. bool device_pmf_driver_shutdown(device_t, int);
  423. bool device_pmf_driver_register(device_t,
  424. bool (*)(device_t PMF_FN_PROTO),
  425. bool (*)(device_t PMF_FN_PROTO),
  426. bool (*)(device_t, int));
  427. void device_pmf_driver_deregister(device_t);
  428. bool device_pmf_driver_child_register(device_t);
  429. void device_pmf_driver_set_child_register(device_t,
  430. bool (*)(device_t));
  431. void *device_pmf_bus_private(device_t);
  432. bool device_pmf_bus_suspend(device_t PMF_FN_PROTO);
  433. bool device_pmf_bus_resume(device_t PMF_FN_PROTO);
  434. bool device_pmf_bus_shutdown(device_t, int);
  435. void *device_pmf_private(device_t);
  436. void device_pmf_unlock(device_t PMF_FN_PROTO);
  437. bool device_pmf_lock(device_t PMF_FN_PROTO);
  438. bool device_is_self_suspended(device_t);
  439. void device_pmf_self_suspend(device_t PMF_FN_PROTO);
  440. void device_pmf_self_resume(device_t PMF_FN_PROTO);
  441. bool device_pmf_self_wait(device_t PMF_FN_PROTO);
  442. void device_pmf_bus_register(device_t, void *,
  443. bool (*)(device_t PMF_FN_PROTO),
  444. bool (*)(device_t PMF_FN_PROTO),
  445. bool (*)(device_t, int),
  446. void (*)(device_t));
  447. void device_pmf_bus_deregister(device_t);
  448. void *device_pmf_class_private(device_t);
  449. bool device_pmf_class_suspend(device_t PMF_FN_PROTO);
  450. bool device_pmf_class_resume(device_t PMF_FN_PROTO);
  451. void device_pmf_class_register(device_t, void *,
  452. bool (*)(device_t PMF_FN_PROTO),
  453. bool (*)(device_t PMF_FN_PROTO),
  454. void (*)(device_t));
  455. void device_pmf_class_deregister(device_t);
  456. #endif /* _KERNEL */
  457. #endif /* !_SYS_DEVICE_H_ */