xref: /dragonfly/sys/sys/bus_private.h (revision 2cd2d2b5)
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: 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.6 2004/04/15 13:31:41 joerg Exp $
28  */
29 
30 #ifndef _SYS_BUS_PRIVATE_H_
31 #define _SYS_BUS_PRIVATE_H_
32 
33 #include <sys/bus.h>
34 
35 /*
36  * Used to attach drivers to devclasses.
37  */
38 typedef struct driverlink *driverlink_t;
39 struct driverlink {
40 	kobj_class_t		driver;
41 	TAILQ_ENTRY(driverlink) link;	/* list of drivers in devclass */
42 };
43 
44 /*
45  * Forward declarations
46  */
47 typedef TAILQ_HEAD(devclass_list, devclass) devclass_list_t;
48 typedef TAILQ_HEAD(driver_list, driverlink) driver_list_t;
49 typedef TAILQ_HEAD(device_list, device) device_list_t;
50 
51 struct devclass {
52 	TAILQ_ENTRY(devclass) link;
53 	devclass_t	parent;		/* parent in devclass hierarchy */
54 	driver_list_t	drivers;	/* bus devclasses store drivers for bus */
55 	char		*name;
56 	device_t	*devices;	/* array of devices indexed by unit */
57 	int		maxunit;	/* size of devices array */
58 };
59 
60 /*
61  * Resources from config(8).
62  */
63 typedef enum {
64 	RES_INT, RES_STRING, RES_LONG
65 } resource_type;
66 
67 struct config_resource {
68 	char		*name;
69 	resource_type	type;
70 	union {
71 		long	longval;
72 		int	intval;
73 		char*	stringval;
74 	} u;
75 };
76 
77 struct config_device {
78 	char			*name;		/* e.g. "lpt", "wdc" etc */
79 	int			unit;
80 	int			resource_count;
81 	struct config_resource	*resources;
82 };
83 
84 /*
85  * Implementation of device.
86  */
87 struct device {
88 	/*
89 	 * A device is a kernel object. The first field must be the
90 	 * current ops table for the object.
91 	 */
92 	KOBJ_FIELDS;
93 
94 	/*
95 	 * Device hierarchy.
96 	 */
97 	TAILQ_ENTRY(device)	link;		/* list of devices in parent */
98 	device_t		parent;
99 	device_list_t		children;	/* list of subordinate devices */
100 
101 	/*
102 	 * Details of this device.
103 	 */
104 	driver_t	*driver;
105 	devclass_t	devclass;	/* device class which we are in */
106 	int		unit;
107 	char*		nameunit;	/* name+unit e.g. foodev0 */
108 	char*		desc;		/* driver specific description */
109 	int		busy;		/* count of calls to device_busy() */
110 	device_state_t	state;
111 	uint32_t	devflags;	/* api level flags for device_get_flags() */
112 	u_short		flags;
113 #define DF_ENABLED	0x0001		/* device should be probed/attached */
114 #define DF_FIXEDCLASS	0x0002		/* devclass specified at create time */
115 #define DF_WILDCARD	0x0004		/* unit was originally wildcard */
116 #define DF_DESCMALLOCED	0x0008		/* description was malloced */
117 #define DF_QUIET	0x0010		/* don't print verbose attach message */
118 #define DF_DONENOMATCH	0x0020		/* don't execute DEVICE_NOMATCH again */
119 #define DF_EXTERNALSOFTC 0x0040		/* softc not allocated by us */
120 	u_char		order;		/* order from device_add_child_ordered() */
121 	u_char		pad;
122 #ifdef DEVICE_SYSCTLS
123 	struct sysctl_oid	oid[4];
124 	struct sysctl_oid_list oidlist[1];
125 #endif
126 	void		*ivars;
127 	void		*softc;
128 };
129 
130 struct device_op_desc {
131 	unsigned int	offset;		/* offset in driver ops */
132 	struct method*	method;		/* internal method implementation */
133 	devop_t		deflt;		/* default implementation */
134 	const char*	name;		/* unique name (for registration) */
135 };
136 
137 #endif /* !_SYS_BUS_PRIVATE_H_ */
138