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$ 28 */ 29 30 #include <sys/cdefs.h> 31 #include <machine/ansi.h> 32 33 typedef __uintptr_t devinfo_handle_t; 34 #define DEVINFO_ROOT_DEVICE ((devinfo_handle_t)0) 35 36 struct devinfo_dev { 37 devinfo_handle_t dd_handle; /* device handle */ 38 devinfo_handle_t dd_parent; /* parent handle */ 39 40 char *dd_name; /* name of device */ 41 char *dd_desc; /* device description */ 42 char *dd_drivername; /* name of attached driver*/ 43 }; 44 45 struct devinfo_rman { 46 devinfo_handle_t dm_handle; /* resource manager handle */ 47 48 unsigned long dm_start; /* resource start */ 49 unsigned long dm_size; /* resource size */ 50 51 char *dm_desc; /* resource description */ 52 }; 53 54 struct devinfo_res { 55 devinfo_handle_t dr_handle; /* resource handle */ 56 devinfo_handle_t dr_rman; /* resource manager handle */ 57 devinfo_handle_t dr_device; /* owning device */ 58 59 unsigned long dr_start; /* region start */ 60 unsigned long dr_size; /* region size */ 61 /* XXX add flags */ 62 }; 63 64 /* 65 * Acquire a coherent copy of the kernel's device and resource tables. 66 * This must return success (zero) before any other interfaces will 67 * function. Sets errno on failure. 68 */ 69 extern int devinfo_init(void); 70 71 /* 72 * Release the storage associated with the internal copy of the device 73 * and resource tables. devinfo_init must be called before any attempt 74 * is made to use any other interfaces. 75 */ 76 extern void devinfo_free(void); 77 78 /* 79 * Find a device/resource/resource manager by its handle. 80 */ 81 extern struct devinfo_dev 82 *devinfo_handle_to_device(devinfo_handle_t handle); 83 extern struct devinfo_res 84 *devinfo_handle_to_resource(devinfo_handle_t handle); 85 extern struct devinfo_rman 86 *devinfo_handle_to_rman(devinfo_handle_t handle); 87 88 /* 89 * Iterate over the children of a device, calling (fn) on each. If 90 * (fn) returns nonzero, abort the scan and return. 91 */ 92 extern int 93 devinfo_foreach_device_child(struct devinfo_dev *parent, 94 int (* fn)(struct devinfo_dev *child, void *arg), 95 void *arg); 96 97 /* 98 * Iterate over all the resources owned by a device, calling (fn) on each. 99 * If (fn) returns nonzero, abort the scan and return. 100 */ 101 extern int 102 devinfo_foreach_device_resource(struct devinfo_dev *dev, 103 int (* fn)(struct devinfo_dev *dev, 104 struct devinfo_res *res, void *arg), 105 void *arg); 106 107 /* 108 * Iterate over all the resources owned by a resource manager, calling (fn) 109 * on each. If (fn) returns nonzero, abort the scan and return. 110 */ 111 extern int 112 devinfo_foreach_rman_resource(struct devinfo_rman *rman, 113 int (* fn)(struct devinfo_res *res, void *arg), 114 void *arg); 115 116 /* 117 * Iterate over all the resource managers, calling (fn) on each. If (fn) 118 * returns nonzero, abort the scan and return. 119 */ 120 extern int 121 devinfo_foreach_rman(int (* fn)(struct devinfo_rman *rman, void *arg), 122 void *arg); 123