FreeBSD/Linux Kernel Cross Reference
sys/sys/bus_private.h
1 /*-
2 * Copyright (c) 1997,1998 Doug Rabson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD$
27 */
28
29 #ifndef _SYS_BUS_PRIVATE_H_
30 #define _SYS_BUS_PRIVATE_H_
31
32 #include <sys/bus.h>
33
34 /*
35 * Forward declarations
36 */
37 typedef TAILQ_HEAD(devclass_list, devclass) devclass_list_t;
38 typedef TAILQ_HEAD(driver_list, driver) driver_list_t;
39 typedef TAILQ_HEAD(device_list, device) device_list_t;
40
41 struct devclass {
42 TAILQ_ENTRY(devclass) link;
43 driver_list_t drivers; /* bus devclasses store drivers for bus */
44 char *name;
45 device_t *devices; /* array of devices indexed by unit */
46 int maxunit; /* size of devices array */
47 int nextunit; /* next unused unit number */
48 };
49
50 /*
51 * Resources from config(8).
52 */
53 typedef enum {
54 RES_INT, RES_STRING, RES_LONG
55 } resource_type;
56
57 struct config_resource {
58 char *name;
59 resource_type type;
60 union {
61 long longval;
62 int intval;
63 char* stringval;
64 } u;
65 };
66
67 struct config_device {
68 char *name; /* e.g. "lpt", "wdc" etc */
69 int unit;
70 int resource_count;
71 struct config_resource *resources;
72 };
73
74 /*
75 * Compiled device methods.
76 */
77 struct device_ops {
78 int maxoffset;
79 devop_t methods[1];
80 };
81
82 /*
83 * Helpers for device method wrappers.
84 */
85 #define DEVOPDESC(OP) (&OP##_##desc)
86
87 #define DEVOPOFF(DEV, OP) \
88 ((DEVOPDESC(OP)->offset >= DEV->ops->maxoffset \
89 || !DEV->ops->methods[DEVOPDESC(OP)->offset]) \
90 ? 0 : DEVOPDESC(OP)->offset)
91
92 #define DEVOPMETH(DEV, OP) (DEV->ops->methods[DEVOPOFF(DEV, OP)])
93
94 /*
95 * Implementation of device.
96 */
97 struct device {
98 /*
99 * Device hierarchy.
100 */
101 TAILQ_ENTRY(device) link; /* list of devices in parent */
102 device_t parent;
103 device_list_t children; /* list of subordinate devices */
104
105 /*
106 * Details of this device.
107 */
108 device_ops_t ops;
109 driver_t *driver;
110 devclass_t devclass; /* device class which we are in */
111 int unit;
112 const char* desc; /* driver specific description */
113 int busy; /* count of calls to device_busy() */
114 device_state_t state;
115 int flags;
116 #define DF_ENABLED 1 /* device should be probed/attached */
117 #define DF_FIXEDCLASS 2 /* devclass specified at create time */
118 #define DF_WILDCARD 4 /* unit was originally wildcard */
119 void *ivars;
120 void *softc;
121 };
122
123 struct device_op_desc {
124 unsigned int offset; /* offset in driver ops */
125 const char* name; /* unique name (for registration) */
126 };
127
128 #endif /* !_SYS_BUS_PRIVATE_H_ */
Cache object: f5790213e402b6425d1ff0e4e87f2c9e
|