1251843Sbapt/*- 2220749Snwhitehorn * Copyright (c) 2000 Michael Smith 3217309Snwhitehorn * Copyright (c) 2000 BSDi 4217309Snwhitehorn * All rights reserved. 5217309Snwhitehorn * 6217309Snwhitehorn * Redistribution and use in source and binary forms, with or without 7217309Snwhitehorn * modification, are permitted provided that the following conditions 8217309Snwhitehorn * are met: 9217309Snwhitehorn * 1. Redistributions of source code must retain the above copyright 10217309Snwhitehorn * notice, this list of conditions and the following disclaimer. 11217309Snwhitehorn * 2. Redistributions in binary form must reproduce the above copyright 12217309Snwhitehorn * notice, this list of conditions and the following disclaimer in the 13217309Snwhitehorn * documentation and/or other materials provided with the distribution. 14217309Snwhitehorn * 15217309Snwhitehorn * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16217309Snwhitehorn * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17217309Snwhitehorn * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18217309Snwhitehorn * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19217309Snwhitehorn * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20217309Snwhitehorn * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21217309Snwhitehorn * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22217309Snwhitehorn * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23217309Snwhitehorn * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24217309Snwhitehorn * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25217309Snwhitehorn * SUCH DAMAGE. 26217309Snwhitehorn * 27217309Snwhitehorn * $FreeBSD$ 28217309Snwhitehorn */ 29217309Snwhitehorn 30217309Snwhitehorn#ifndef _DEVINFO_H_INCLUDED 31217309Snwhitehorn#define _DEVINFO_H_INCLUDED 32217309Snwhitehorn 33217309Snwhitehorn#include <sys/cdefs.h> 34217309Snwhitehorn#include <sys/types.h> 35217309Snwhitehorn#include <sys/bus.h> 36217309Snwhitehorn 37217309Snwhitehorntypedef __uintptr_t devinfo_handle_t; 38217309Snwhitehorn#define DEVINFO_ROOT_DEVICE ((devinfo_handle_t)0) 39217309Snwhitehorn 40217309Snwhitehorntypedef enum device_state devinfo_state_t; 41217309Snwhitehorn 42217309Snwhitehornstruct devinfo_dev { 43217309Snwhitehorn devinfo_handle_t dd_handle; /* device handle */ 44217309Snwhitehorn devinfo_handle_t dd_parent; /* parent handle */ 45217309Snwhitehorn 46217309Snwhitehorn char *dd_name; /* name of device */ 47217309Snwhitehorn char *dd_desc; /* device description */ 48217309Snwhitehorn char *dd_drivername; /* name of attached driver*/ 49251843Sbapt char *dd_pnpinfo; /* pnp info from parent bus */ 50217309Snwhitehorn char *dd_location; /* Where bus thinks dev at */ 51217309Snwhitehorn uint32_t dd_devflags; /* API flags */ 52251843Sbapt uint16_t dd_flags; /* internal dev flags */ 53217309Snwhitehorn devinfo_state_t dd_state; /* attacement state of dev */ 54217309Snwhitehorn}; 55217309Snwhitehorn 56217309Snwhitehornstruct devinfo_rman { 57217309Snwhitehorn devinfo_handle_t dm_handle; /* resource manager handle */ 58217309Snwhitehorn 59217309Snwhitehorn unsigned long dm_start; /* resource start */ 60217309Snwhitehorn unsigned long dm_size; /* resource size */ 61217309Snwhitehorn 62217309Snwhitehorn char *dm_desc; /* resource description */ 63217309Snwhitehorn}; 64251843Sbapt 65217309Snwhitehornstruct devinfo_res { 66217309Snwhitehorn devinfo_handle_t dr_handle; /* resource handle */ 67251843Sbapt devinfo_handle_t dr_rman; /* resource manager handle */ 68217309Snwhitehorn devinfo_handle_t dr_device; /* owning device */ 69217309Snwhitehorn 70251843Sbapt unsigned long dr_start; /* region start */ 71217309Snwhitehorn unsigned long dr_size; /* region size */ 72217309Snwhitehorn /* XXX add flags */ 73251843Sbapt}; 74217309Snwhitehorn 75217309Snwhitehorn__BEGIN_DECLS 76251843Sbapt 77217309Snwhitehorn/* 78217309Snwhitehorn * Acquire a coherent copy of the kernel's device and resource tables. 79251843Sbapt * This must return success (zero) before any other interfaces will 80217309Snwhitehorn * function. Sets errno on failure. 81217309Snwhitehorn */ 82251843Sbaptextern int devinfo_init(void); 83217309Snwhitehorn 84217309Snwhitehorn/* 85251843Sbapt * Release the storage associated with the internal copy of the device 86217309Snwhitehorn * and resource tables. devinfo_init must be called before any attempt 87217309Snwhitehorn * is made to use any other interfaces. 88251843Sbapt */ 89217309Snwhitehornextern void devinfo_free(void); 90217309Snwhitehorn 91251843Sbapt/* 92217309Snwhitehorn * Find a device/resource/resource manager by its handle. 93217309Snwhitehorn */ 94251843Sbaptextern struct devinfo_dev 95217309Snwhitehorn *devinfo_handle_to_device(devinfo_handle_t handle); 96217309Snwhitehornextern struct devinfo_res 97251843Sbapt *devinfo_handle_to_resource(devinfo_handle_t handle); 98217309Snwhitehornextern struct devinfo_rman 99217309Snwhitehorn *devinfo_handle_to_rman(devinfo_handle_t handle); 100251843Sbapt 101217309Snwhitehorn/* 102217309Snwhitehorn * Iterate over the children of a device, calling (fn) on each. If 103251843Sbapt * (fn) returns nonzero, abort the scan and return. 104217309Snwhitehorn */ 105217309Snwhitehornextern int 106251843Sbapt devinfo_foreach_device_child(struct devinfo_dev *parent, 107217309Snwhitehorn int (* fn)(struct devinfo_dev *child, void *arg), 108217309Snwhitehorn void *arg); 109251843Sbapt 110217309Snwhitehorn/* 111217309Snwhitehorn * Iterate over all the resources owned by a device, calling (fn) on each. 112251843Sbapt * If (fn) returns nonzero, abort the scan and return. 113217309Snwhitehorn */ 114217309Snwhitehornextern int 115251843Sbapt devinfo_foreach_device_resource(struct devinfo_dev *dev, 116217309Snwhitehorn int (* fn)(struct devinfo_dev *dev, 117217309Snwhitehorn struct devinfo_res *res, void *arg), 118217309Snwhitehorn void *arg); 119217309Snwhitehorn 120217309Snwhitehorn/* 121251843Sbapt * Iterate over all the resources owned by a resource manager, calling (fn) 122217309Snwhitehorn * on each. If (fn) returns nonzero, abort the scan and return. 123217309Snwhitehorn */ 124251843Sbaptextern int 125220749Snwhitehorn devinfo_foreach_rman_resource(struct devinfo_rman *rman, 126220749Snwhitehorn int (* fn)(struct devinfo_res *res, void *arg), 127220749Snwhitehorn void *arg); 128220749Snwhitehorn 129220749Snwhitehorn/* 130220749Snwhitehorn * Iterate over all the resource managers, calling (fn) on each. If (fn) 131251843Sbapt * returns nonzero, abort the scan and return. 132251843Sbapt */ 133251843Sbaptextern int 134251843Sbapt devinfo_foreach_rman(int (* fn)(struct devinfo_rman *rman, void *arg), 135251843Sbapt void *arg); 136251843Sbapt 137251843Sbapt__END_DECLS 138251843Sbapt 139251843Sbapt#endif /* ! _DEVINFO_H_INCLUDED */ 140251843Sbapt