devinfo.h revision 103662
175726Smsmith/*- 275726Smsmith * Copyright (c) 2000 Michael Smith 375726Smsmith * Copyright (c) 2000 BSDi 475726Smsmith * All rights reserved. 575726Smsmith * 675726Smsmith * Redistribution and use in source and binary forms, with or without 775726Smsmith * modification, are permitted provided that the following conditions 875726Smsmith * are met: 975726Smsmith * 1. Redistributions of source code must retain the above copyright 1075726Smsmith * notice, this list of conditions and the following disclaimer. 1175726Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1275726Smsmith * notice, this list of conditions and the following disclaimer in the 1375726Smsmith * documentation and/or other materials provided with the distribution. 1475726Smsmith * 1575726Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1675726Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1775726Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1875726Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1975726Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2075726Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2175726Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2275726Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2375726Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2475726Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2575726Smsmith * SUCH DAMAGE. 2675726Smsmith * 2775726Smsmith * $FreeBSD: head/lib/libdevinfo/devinfo.h 103662 2002-09-20 02:16:33Z imp $ 2875726Smsmith */ 2975726Smsmith 3084399Sbde#include <sys/cdefs.h> 31102227Smike#include <sys/_types.h> 3275726Smsmith 3384399Sbdetypedef __uintptr_t devinfo_handle_t; 3484399Sbde#define DEVINFO_ROOT_DEVICE ((devinfo_handle_t)0) 3584399Sbde 36103662Simp/* 37103662Simp * State of the device. 38103662Simp */ 39103662Simp/* XXX not sure if I want a copy here, or expose sys/bus.h */ 40103662Simptypedef enum devinfo_state { 41103662Simp DIS_NOTPRESENT, /* not probed or probe failed */ 42103662Simp DIS_ALIVE, /* probe succeeded */ 43103662Simp DIS_ATTACHED, /* attach method called */ 44103662Simp DIS_BUSY /* device is open */ 45103662Simp} devinfo_state_t; 46103662Simp 4775726Smsmithstruct devinfo_dev { 4875726Smsmith devinfo_handle_t dd_handle; /* device handle */ 4975726Smsmith devinfo_handle_t dd_parent; /* parent handle */ 5075726Smsmith 5175726Smsmith char *dd_name; /* name of device */ 5275726Smsmith char *dd_desc; /* device description */ 5375726Smsmith char *dd_drivername; /* name of attached driver*/ 54103662Simp char *dd_pnpinfo; /* pnp info from parent bus */ 55103662Simp char *dd_location; /* Where bus thinks dev at */ 56103662Simp uint32_t dd_devflags; /* API flags */ 57103662Simp uint16_t dd_flags; /* internal dev flags */ 58103662Simp devinfo_state_t dd_state; /* attacement state of dev */ 5975726Smsmith}; 6075726Smsmith 6175726Smsmithstruct devinfo_rman { 6275726Smsmith devinfo_handle_t dm_handle; /* resource manager handle */ 6375726Smsmith 6484399Sbde unsigned long dm_start; /* resource start */ 6584399Sbde unsigned long dm_size; /* resource size */ 6675726Smsmith 6775726Smsmith char *dm_desc; /* resource description */ 6875726Smsmith}; 6975726Smsmith 7075726Smsmithstruct devinfo_res { 7175726Smsmith devinfo_handle_t dr_handle; /* resource handle */ 7275726Smsmith devinfo_handle_t dr_rman; /* resource manager handle */ 7375726Smsmith devinfo_handle_t dr_device; /* owning device */ 7475726Smsmith 7584399Sbde unsigned long dr_start; /* region start */ 7684399Sbde unsigned long dr_size; /* region size */ 7775726Smsmith /* XXX add flags */ 7875726Smsmith}; 7975726Smsmith 8075726Smsmith/* 8175726Smsmith * Acquire a coherent copy of the kernel's device and resource tables. 8275726Smsmith * This must return success (zero) before any other interfaces will 8375726Smsmith * function. Sets errno on failure. 8475726Smsmith */ 8575726Smsmithextern int devinfo_init(void); 8675726Smsmith 8775726Smsmith/* 8875726Smsmith * Release the storage associated with the internal copy of the device 8975726Smsmith * and resource tables. devinfo_init must be called before any attempt 9075726Smsmith * is made to use any other interfaces. 9175726Smsmith */ 9275726Smsmithextern void devinfo_free(void); 9375726Smsmith 9475726Smsmith/* 9575726Smsmith * Find a device/resource/resource manager by its handle. 9675726Smsmith */ 9775726Smsmithextern struct devinfo_dev 9875726Smsmith *devinfo_handle_to_device(devinfo_handle_t handle); 9975726Smsmithextern struct devinfo_res 10075726Smsmith *devinfo_handle_to_resource(devinfo_handle_t handle); 10175726Smsmithextern struct devinfo_rman 10275726Smsmith *devinfo_handle_to_rman(devinfo_handle_t handle); 10375726Smsmith 10475726Smsmith/* 10575726Smsmith * Iterate over the children of a device, calling (fn) on each. If 10675726Smsmith * (fn) returns nonzero, abort the scan and return. 10775726Smsmith */ 10875726Smsmithextern int 10975726Smsmith devinfo_foreach_device_child(struct devinfo_dev *parent, 11075726Smsmith int (* fn)(struct devinfo_dev *child, void *arg), 11175726Smsmith void *arg); 11275726Smsmith 11375726Smsmith/* 11475726Smsmith * Iterate over all the resources owned by a device, calling (fn) on each. 11575726Smsmith * If (fn) returns nonzero, abort the scan and return. 11675726Smsmith */ 11775726Smsmithextern int 11875726Smsmith devinfo_foreach_device_resource(struct devinfo_dev *dev, 11975726Smsmith int (* fn)(struct devinfo_dev *dev, 12075726Smsmith struct devinfo_res *res, void *arg), 12175726Smsmith void *arg); 12275726Smsmith 12375726Smsmith/* 12475726Smsmith * Iterate over all the resources owned by a resource manager, calling (fn) 12575726Smsmith * on each. If (fn) returns nonzero, abort the scan and return. 12675726Smsmith */ 12775726Smsmithextern int 12875726Smsmith devinfo_foreach_rman_resource(struct devinfo_rman *rman, 12975726Smsmith int (* fn)(struct devinfo_res *res, void *arg), 13075726Smsmith void *arg); 13175726Smsmith 13275726Smsmith/* 13375726Smsmith * Iterate over all the resource managers, calling (fn) on each. If (fn) 13475726Smsmith * returns nonzero, abort the scan and return. 13575726Smsmith */ 13675726Smsmithextern int 13775726Smsmith devinfo_foreach_rman(int (* fn)(struct devinfo_rman *rman, void *arg), 13875726Smsmith void *arg); 139