1120492Sfjoe/*-
2120492Sfjoe * Copyright (c) 2000 Michael Smith
3120492Sfjoe * Copyright (c) 2000 BSDi
4120492Sfjoe * All rights reserved.
5120492Sfjoe *
6120492Sfjoe * Redistribution and use in source and binary forms, with or without
7120492Sfjoe * modification, are permitted provided that the following conditions
8120492Sfjoe * are met:
9120492Sfjoe * 1. Redistributions of source code must retain the above copyright
10120492Sfjoe *    notice, this list of conditions and the following disclaimer.
11120492Sfjoe * 2. Redistributions in binary form must reproduce the above copyright
12120492Sfjoe *    notice, this list of conditions and the following disclaimer in the
13120492Sfjoe *    documentation and/or other materials provided with the distribution.
14120492Sfjoe *
15120492Sfjoe * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16120492Sfjoe * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17120492Sfjoe * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18120492Sfjoe * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19120492Sfjoe * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20120492Sfjoe * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21120492Sfjoe * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22120492Sfjoe * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23120492Sfjoe * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24120492Sfjoe * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25120492Sfjoe * SUCH DAMAGE.
26120492Sfjoe *
27120492Sfjoe *	$FreeBSD: releng/10.3/lib/libdevinfo/devinfo.h 218505 2011-02-10 04:53:09Z imp $
28120492Sfjoe */
29120492Sfjoe
30120492Sfjoe#ifndef _DEVINFO_H_INCLUDED
31120492Sfjoe#define _DEVINFO_H_INCLUDED
32120492Sfjoe
33120492Sfjoe#include <sys/cdefs.h>
34120492Sfjoe#include <sys/types.h>
35120492Sfjoe#include <sys/bus.h>
36120492Sfjoe
37120492Sfjoetypedef __uintptr_t	devinfo_handle_t;
38120492Sfjoe#define DEVINFO_ROOT_DEVICE	((devinfo_handle_t)0)
39120492Sfjoe
40120492Sfjoetypedef enum device_state devinfo_state_t;
41120492Sfjoe
42120492Sfjoestruct devinfo_dev {
43120492Sfjoe	devinfo_handle_t	dd_handle;	/* device handle */
44120492Sfjoe	devinfo_handle_t	dd_parent;	/* parent handle */
45120492Sfjoe
46120492Sfjoe	char			*dd_name;	/* name of device */
47120492Sfjoe	char			*dd_desc;	/* device description */
48120492Sfjoe	char			*dd_drivername;	/* name of attached driver*/
49120492Sfjoe	char			*dd_pnpinfo;	/* pnp info from parent bus */
50120492Sfjoe	char			*dd_location;	/* Where bus thinks dev at */
51120492Sfjoe	uint32_t		dd_devflags;	/* API flags */
52120492Sfjoe	uint16_t		dd_flags;	/* internal dev flags */
53120492Sfjoe	devinfo_state_t		dd_state;	/* attacement state of dev */
54120492Sfjoe};
55120492Sfjoe
56120492Sfjoestruct devinfo_rman {
57120492Sfjoe	devinfo_handle_t	dm_handle;	/* resource manager handle */
58120492Sfjoe
59120492Sfjoe	unsigned long		dm_start;	/* resource start */
60120492Sfjoe	unsigned long		dm_size;	/* resource size */
61120492Sfjoe
62120492Sfjoe	char			*dm_desc;	/* resource description */
63120492Sfjoe};
64120492Sfjoe
65120492Sfjoestruct devinfo_res {
66120492Sfjoe	devinfo_handle_t	dr_handle;	/* resource handle */
67120492Sfjoe	devinfo_handle_t	dr_rman;	/* resource manager handle */
68120492Sfjoe	devinfo_handle_t	dr_device;	/* owning device */
69120492Sfjoe
70120492Sfjoe	unsigned long		dr_start;	/* region start */
71120492Sfjoe	unsigned long		dr_size;	/* region size */
72120492Sfjoe	/* XXX add flags */
73120492Sfjoe};
74120492Sfjoe
75120492Sfjoe__BEGIN_DECLS
76120492Sfjoe
77120492Sfjoe/*
78120492Sfjoe * Acquire a coherent copy of the kernel's device and resource tables.
79120492Sfjoe * This must return success (zero) before any other interfaces will
80120492Sfjoe * function.  Sets errno on failure.
81120492Sfjoe */
82120492Sfjoeextern int	devinfo_init(void);
83120492Sfjoe
84120492Sfjoe/*
85120492Sfjoe * Release the storage associated with the internal copy of the device
86120492Sfjoe * and resource tables. devinfo_init must be called before any attempt
87120492Sfjoe * is made to use any other interfaces.
88120492Sfjoe */
89120492Sfjoeextern void	devinfo_free(void);
90120492Sfjoe
91120492Sfjoe/*
92120492Sfjoe * Find a device/resource/resource manager by its handle.
93120492Sfjoe */
94120492Sfjoeextern struct devinfo_dev
95120492Sfjoe	*devinfo_handle_to_device(devinfo_handle_t handle);
96120492Sfjoeextern struct devinfo_res
97120492Sfjoe	*devinfo_handle_to_resource(devinfo_handle_t handle);
98120492Sfjoeextern struct devinfo_rman
99120492Sfjoe	*devinfo_handle_to_rman(devinfo_handle_t handle);
100120492Sfjoe
101120492Sfjoe/*
102120492Sfjoe * Iterate over the children of a device, calling (fn) on each.  If
103120492Sfjoe * (fn) returns nonzero, abort the scan and return.
104120492Sfjoe */
105120492Sfjoeextern int
106120492Sfjoe	devinfo_foreach_device_child(struct devinfo_dev *parent,
107120492Sfjoe	    int (* fn)(struct devinfo_dev *child, void *arg),
108120492Sfjoe	    void *arg);
109120492Sfjoe
110120492Sfjoe/*
111120492Sfjoe * Iterate over all the resources owned by a device, calling (fn) on each.
112120492Sfjoe * If (fn) returns nonzero, abort the scan and return.
113120492Sfjoe */
114120492Sfjoeextern int
115120492Sfjoe	devinfo_foreach_device_resource(struct devinfo_dev *dev,
116120492Sfjoe	    int (* fn)(struct devinfo_dev *dev,
117120492Sfjoe	    struct devinfo_res *res, void *arg),
118120492Sfjoe	    void *arg);
119120492Sfjoe
120120492Sfjoe/*
121120492Sfjoe * Iterate over all the resources owned by a resource manager, calling (fn)
122120492Sfjoe * on each.  If (fn) returns nonzero, abort the scan and return.
123120492Sfjoe */
124120492Sfjoeextern int
125120492Sfjoe	devinfo_foreach_rman_resource(struct devinfo_rman *rman,
126120492Sfjoe	    int (* fn)(struct devinfo_res *res, void *arg),
127120492Sfjoe	    void *arg);
128120492Sfjoe
129120492Sfjoe/*
130120492Sfjoe * Iterate over all the resource managers, calling (fn) on each.  If (fn)
131120492Sfjoe * returns nonzero, abort the scan and return.
132120492Sfjoe */
133120492Sfjoeextern int
134120492Sfjoe	devinfo_foreach_rman(int (* fn)(struct devinfo_rman *rman, void *arg),
135120492Sfjoe	    void *arg);
136120492Sfjoe
137120492Sfjoe__END_DECLS
138120492Sfjoe
139120492Sfjoe#endif /* ! _DEVINFO_H_INCLUDED */
140120492Sfjoe