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 *
| 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 197224 2009-09-15 16:59:52Z attilio $
| 27 * $FreeBSD: head/lib/libdevinfo/devinfo.h 199291 2009-11-15 16:44:43Z attilio $
|
28 */ 29 30#ifndef _DEVINFO_H_INCLUDED 31#define _DEVINFO_H_INCLUDED 32 33#include <sys/cdefs.h> 34#include <sys/_types.h>
| 28 */ 29 30#ifndef _DEVINFO_H_INCLUDED 31#define _DEVINFO_H_INCLUDED 32 33#include <sys/cdefs.h> 34#include <sys/_types.h>
|
| 35#include <sys/bus.h>
|
35 36typedef __uintptr_t devinfo_handle_t; 37#define DEVINFO_ROOT_DEVICE ((devinfo_handle_t)0) 38
| 36 37typedef __uintptr_t devinfo_handle_t; 38#define DEVINFO_ROOT_DEVICE ((devinfo_handle_t)0) 39
|
39/* 40 * State of the device. 41 */ 42/* XXX not sure if I want a copy here, or expose sys/bus.h */ 43typedef enum devinfo_state { 44 DIS_NOTPRESENT = 10, /* not probed or probe failed */ 45 DIS_ALIVE = 20, /* probe succeeded */ 46 DIS_ATTACHED = 30, /* attach method called */ 47 DIS_BUSY = 40 /* device is open */ 48} devinfo_state_t;
| 40typedef enum device_state devinfo_state_t;
|
49 50struct devinfo_dev { 51 devinfo_handle_t dd_handle; /* device handle */ 52 devinfo_handle_t dd_parent; /* parent handle */ 53 54 char *dd_name; /* name of device */ 55 char *dd_desc; /* device description */ 56 char *dd_drivername; /* name of attached driver*/ 57 char *dd_pnpinfo; /* pnp info from parent bus */ 58 char *dd_location; /* Where bus thinks dev at */ 59 uint32_t dd_devflags; /* API flags */ 60 uint16_t dd_flags; /* internal dev flags */ 61 devinfo_state_t dd_state; /* attacement state of dev */ 62}; 63 64struct devinfo_rman { 65 devinfo_handle_t dm_handle; /* resource manager handle */ 66 67 unsigned long dm_start; /* resource start */ 68 unsigned long dm_size; /* resource size */ 69 70 char *dm_desc; /* resource description */ 71}; 72 73struct devinfo_res { 74 devinfo_handle_t dr_handle; /* resource handle */ 75 devinfo_handle_t dr_rman; /* resource manager handle */ 76 devinfo_handle_t dr_device; /* owning device */ 77 78 unsigned long dr_start; /* region start */ 79 unsigned long dr_size; /* region size */ 80 /* XXX add flags */ 81}; 82 83__BEGIN_DECLS 84 85/* 86 * Acquire a coherent copy of the kernel's device and resource tables. 87 * This must return success (zero) before any other interfaces will 88 * function. Sets errno on failure. 89 */ 90extern int devinfo_init(void); 91 92/* 93 * Release the storage associated with the internal copy of the device 94 * and resource tables. devinfo_init must be called before any attempt 95 * is made to use any other interfaces. 96 */ 97extern void devinfo_free(void); 98 99/* 100 * Find a device/resource/resource manager by its handle. 101 */ 102extern struct devinfo_dev 103 *devinfo_handle_to_device(devinfo_handle_t handle); 104extern struct devinfo_res 105 *devinfo_handle_to_resource(devinfo_handle_t handle); 106extern struct devinfo_rman 107 *devinfo_handle_to_rman(devinfo_handle_t handle); 108 109/* 110 * Iterate over the children of a device, calling (fn) on each. If 111 * (fn) returns nonzero, abort the scan and return. 112 */ 113extern int 114 devinfo_foreach_device_child(struct devinfo_dev *parent, 115 int (* fn)(struct devinfo_dev *child, void *arg), 116 void *arg); 117 118/* 119 * Iterate over all the resources owned by a device, calling (fn) on each. 120 * If (fn) returns nonzero, abort the scan and return. 121 */ 122extern int 123 devinfo_foreach_device_resource(struct devinfo_dev *dev, 124 int (* fn)(struct devinfo_dev *dev, 125 struct devinfo_res *res, void *arg), 126 void *arg); 127 128/* 129 * Iterate over all the resources owned by a resource manager, calling (fn) 130 * on each. If (fn) returns nonzero, abort the scan and return. 131 */ 132extern int 133 devinfo_foreach_rman_resource(struct devinfo_rman *rman, 134 int (* fn)(struct devinfo_res *res, void *arg), 135 void *arg); 136 137/* 138 * Iterate over all the resource managers, calling (fn) on each. If (fn) 139 * returns nonzero, abort the scan and return. 140 */ 141extern int 142 devinfo_foreach_rman(int (* fn)(struct devinfo_rman *rman, void *arg), 143 void *arg); 144 145__END_DECLS 146 147#endif /* ! _DEVINFO_H_INCLUDED */
| 41 42struct devinfo_dev { 43 devinfo_handle_t dd_handle; /* device handle */ 44 devinfo_handle_t dd_parent; /* parent handle */ 45 46 char *dd_name; /* name of device */ 47 char *dd_desc; /* device description */ 48 char *dd_drivername; /* name of attached driver*/ 49 char *dd_pnpinfo; /* pnp info from parent bus */ 50 char *dd_location; /* Where bus thinks dev at */ 51 uint32_t dd_devflags; /* API flags */ 52 uint16_t dd_flags; /* internal dev flags */ 53 devinfo_state_t dd_state; /* attacement state of dev */ 54}; 55 56struct devinfo_rman { 57 devinfo_handle_t dm_handle; /* resource manager handle */ 58 59 unsigned long dm_start; /* resource start */ 60 unsigned long dm_size; /* resource size */ 61 62 char *dm_desc; /* resource description */ 63}; 64 65struct devinfo_res { 66 devinfo_handle_t dr_handle; /* resource handle */ 67 devinfo_handle_t dr_rman; /* resource manager handle */ 68 devinfo_handle_t dr_device; /* owning device */ 69 70 unsigned long dr_start; /* region start */ 71 unsigned long dr_size; /* region size */ 72 /* XXX add flags */ 73}; 74 75__BEGIN_DECLS 76 77/* 78 * Acquire a coherent copy of the kernel's device and resource tables. 79 * This must return success (zero) before any other interfaces will 80 * function. Sets errno on failure. 81 */ 82extern int devinfo_init(void); 83 84/* 85 * Release the storage associated with the internal copy of the device 86 * and resource tables. devinfo_init must be called before any attempt 87 * is made to use any other interfaces. 88 */ 89extern void devinfo_free(void); 90 91/* 92 * Find a device/resource/resource manager by its handle. 93 */ 94extern struct devinfo_dev 95 *devinfo_handle_to_device(devinfo_handle_t handle); 96extern struct devinfo_res 97 *devinfo_handle_to_resource(devinfo_handle_t handle); 98extern struct devinfo_rman 99 *devinfo_handle_to_rman(devinfo_handle_t handle); 100 101/* 102 * Iterate over the children of a device, calling (fn) on each. If 103 * (fn) returns nonzero, abort the scan and return. 104 */ 105extern int 106 devinfo_foreach_device_child(struct devinfo_dev *parent, 107 int (* fn)(struct devinfo_dev *child, void *arg), 108 void *arg); 109 110/* 111 * Iterate over all the resources owned by a device, calling (fn) on each. 112 * If (fn) returns nonzero, abort the scan and return. 113 */ 114extern int 115 devinfo_foreach_device_resource(struct devinfo_dev *dev, 116 int (* fn)(struct devinfo_dev *dev, 117 struct devinfo_res *res, void *arg), 118 void *arg); 119 120/* 121 * Iterate over all the resources owned by a resource manager, calling (fn) 122 * on each. If (fn) returns nonzero, abort the scan and return. 123 */ 124extern int 125 devinfo_foreach_rman_resource(struct devinfo_rman *rman, 126 int (* fn)(struct devinfo_res *res, void *arg), 127 void *arg); 128 129/* 130 * Iterate over all the resource managers, calling (fn) on each. If (fn) 131 * returns nonzero, abort the scan and return. 132 */ 133extern int 134 devinfo_foreach_rman(int (* fn)(struct devinfo_rman *rman, void *arg), 135 void *arg); 136 137__END_DECLS 138 139#endif /* ! _DEVINFO_H_INCLUDED */
|