kernel: Rename the struct behind device_t to bsd_device
[dragonfly.git] / sys / sys / bus_private.h
blobc93879d7b1aa1c6f1d6daa8ffd632d855d1d9b07
1 /*-
2 * Copyright (c) 1997, 1998 Doug Rabson
3 * All rights reserved.
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.
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.
26 * $FreeBSD: src/sys/sys/bus_private.h,v 1.11.2.2 2000/08/03 00:25:22 peter Exp $
27 * $DragonFly: src/sys/sys/bus_private.h,v 1.10 2008/09/30 12:20:29 hasso Exp $
30 #ifndef _SYS_BUS_PRIVATE_H_
31 #define _SYS_BUS_PRIVATE_H_
33 #include <sys/sysctl.h>
35 #if !defined(_KERNEL) && !defined(_KERNEL_STRUCTURES)
37 #error "This file should not be included by userland programs."
39 #else
41 #ifndef _SYS_BUS_H_
42 #include <sys/bus.h>
43 #endif
46 * Used to attach drivers to devclasses.
48 typedef struct driverlink *driverlink_t;
49 struct driverlink {
50 kobj_class_t driver;
51 TAILQ_ENTRY(driverlink) link; /* list of drivers in devclass */
55 * Forward declarations
57 typedef TAILQ_HEAD(devclass_list, devclass) devclass_list_t;
58 typedef TAILQ_HEAD(driver_list, driverlink) driver_list_t;
59 typedef TAILQ_HEAD(device_list, bsd_device) device_list_t;
61 struct devclass {
62 TAILQ_ENTRY(devclass) link;
63 devclass_t parent; /* parent in devclass hierarchy */
64 driver_list_t drivers; /* bus devclasses store drivers for bus */
65 char *name;
66 device_t *devices; /* array of devices indexed by unit */
67 int maxunit; /* size of devices array */
69 struct sysctl_ctx_list sysctl_ctx;
70 struct sysctl_oid *sysctl_tree;
74 * Resources from config(8).
76 typedef enum {
77 RES_INT, RES_STRING, RES_LONG
78 } resource_type;
80 struct config_resource {
81 char *name;
82 resource_type type;
83 union {
84 long longval;
85 int intval;
86 char* stringval;
87 } u;
90 struct config_device {
91 char *name; /* e.g. "lpt", "wdc" etc */
92 int unit;
93 int resource_count;
94 struct config_resource *resources;
98 * Implementation of device.
100 struct bsd_device {
102 * A device is a kernel object. The first field must be the
103 * current ops table for the object.
105 KOBJ_FIELDS;
108 * Device hierarchy.
110 TAILQ_ENTRY(bsd_device) link; /* list of devices in parent */
111 TAILQ_ENTRY(bsd_device) devlink; /* global device list membership */
112 device_t parent;
113 device_list_t children; /* list of subordinate devices */
116 * Details of this device.
118 driver_t *driver;
119 devclass_t devclass; /* device class which we are in */
120 int unit;
121 char* nameunit; /* name+unit e.g. foodev0 */
122 char* desc; /* driver specific description */
123 int busy; /* count of calls to device_busy() */
124 device_state_t state;
125 uint32_t devflags; /* api level flags for device_get_flags() */
126 u_short flags;
127 #define DF_ENABLED 0x0001 /* device should be probed/attached */
128 #define DF_FIXEDCLASS 0x0002 /* devclass specified at create time */
129 #define DF_WILDCARD 0x0004 /* unit was originally wildcard */
130 #define DF_DESCMALLOCED 0x0008 /* description was malloced */
131 #define DF_QUIET 0x0010 /* don't print verbose attach message */
132 #define DF_DONENOMATCH 0x0020 /* don't execute DEVICE_NOMATCH again */
133 #define DF_EXTERNALSOFTC 0x0040 /* softc not allocated by us */
134 #define DF_ASYNCPROBE 0x0080 /* can be probed with its own thread */
135 u_char order; /* order from device_add_child_ordered() */
136 u_char pad;
137 void *ivars;
138 void *softc;
140 struct sysctl_ctx_list sysctl_ctx; /**< state for sysctl variables */
141 struct sysctl_oid *sysctl_tree; /**< state for sysctl variables */
144 struct device_op_desc {
145 unsigned int offset; /* offset in driver ops */
146 struct method* method; /* internal method implementation */
147 devop_t deflt; /* default implementation */
148 const char* name; /* unique name (for registration) */
151 #endif /* _KERNEL || _KERNEL_STRUCTURES */
152 #endif /* !_SYS_BUS_PRIVATE_H_ */