devinfo.h revision 103662
1/*-
2 * Copyright (c) 2000 Michael Smith
3 * Copyright (c) 2000 BSDi
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 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 *	$FreeBSD: head/lib/libdevinfo/devinfo.h 103662 2002-09-20 02:16:33Z imp $
28 */
29
30#include <sys/cdefs.h>
31#include <sys/_types.h>
32
33typedef __uintptr_t	devinfo_handle_t;
34#define DEVINFO_ROOT_DEVICE	((devinfo_handle_t)0)
35
36/*
37 * State of the device.
38 */
39/* XXX not sure if I want a copy here, or expose sys/bus.h */
40typedef enum devinfo_state {
41	DIS_NOTPRESENT,			/* not probed or probe failed */
42	DIS_ALIVE,			/* probe succeeded */
43	DIS_ATTACHED,			/* attach method called */
44	DIS_BUSY			/* device is open */
45} devinfo_state_t;
46
47struct devinfo_dev {
48	devinfo_handle_t	dd_handle;	/* device handle */
49	devinfo_handle_t	dd_parent;	/* parent handle */
50
51	char			*dd_name;	/* name of device */
52	char			*dd_desc;	/* device description */
53	char			*dd_drivername;	/* name of attached driver*/
54	char			*dd_pnpinfo;	/* pnp info from parent bus */
55	char			*dd_location;	/* Where bus thinks dev at */
56	uint32_t		dd_devflags;	/* API flags */
57	uint16_t		dd_flags;	/* internal dev flags */
58	devinfo_state_t		dd_state;	/* attacement state of dev */
59};
60
61struct devinfo_rman {
62	devinfo_handle_t	dm_handle;	/* resource manager handle */
63
64	unsigned long		dm_start;	/* resource start */
65	unsigned long		dm_size;	/* resource size */
66
67	char			*dm_desc;	/* resource description */
68};
69
70struct devinfo_res {
71	devinfo_handle_t	dr_handle;	/* resource handle */
72	devinfo_handle_t	dr_rman;	/* resource manager handle */
73	devinfo_handle_t	dr_device;	/* owning device */
74
75	unsigned long		dr_start;	/* region start */
76	unsigned long		dr_size;	/* region size */
77	/* XXX add flags */
78};
79
80/*
81 * Acquire a coherent copy of the kernel's device and resource tables.
82 * This must return success (zero) before any other interfaces will
83 * function.  Sets errno on failure.
84 */
85extern int	devinfo_init(void);
86
87/*
88 * Release the storage associated with the internal copy of the device
89 * and resource tables. devinfo_init must be called before any attempt
90 * is made to use any other interfaces.
91 */
92extern void	devinfo_free(void);
93
94/*
95 * Find a device/resource/resource manager by its handle.
96 */
97extern struct devinfo_dev
98	*devinfo_handle_to_device(devinfo_handle_t handle);
99extern struct devinfo_res
100	*devinfo_handle_to_resource(devinfo_handle_t handle);
101extern struct devinfo_rman
102	*devinfo_handle_to_rman(devinfo_handle_t handle);
103
104/*
105 * Iterate over the children of a device, calling (fn) on each.  If
106 * (fn) returns nonzero, abort the scan and return.
107 */
108extern int
109	devinfo_foreach_device_child(struct devinfo_dev *parent,
110	    int (* fn)(struct devinfo_dev *child, void *arg),
111	    void *arg);
112
113/*
114 * Iterate over all the resources owned by a device, calling (fn) on each.
115 * If (fn) returns nonzero, abort the scan and return.
116 */
117extern int
118	devinfo_foreach_device_resource(struct devinfo_dev *dev,
119	    int (* fn)(struct devinfo_dev *dev,
120	    struct devinfo_res *res, void *arg),
121	    void *arg);
122
123/*
124 * Iterate over all the resources owned by a resource manager, calling (fn)
125 * on each.  If (fn) returns nonzero, abort the scan and return.
126 */
127extern int
128	devinfo_foreach_rman_resource(struct devinfo_rman *rman,
129	    int (* fn)(struct devinfo_res *res, void *arg),
130	    void *arg);
131
132/*
133 * Iterate over all the resource managers, calling (fn) on each.  If (fn)
134 * returns nonzero, abort the scan and return.
135 */
136extern int
137	devinfo_foreach_rman(int (* fn)(struct devinfo_rman *rman, void *arg),
138	    void *arg);
139