devinfo.h revision 285830
1207753Smm/*- 2207753Smm * Copyright (c) 2000 Michael Smith 3207753Smm * Copyright (c) 2000 BSDi 4207753Smm * All rights reserved. 5207753Smm * 6207753Smm * Redistribution and use in source and binary forms, with or without 7207753Smm * modification, are permitted provided that the following conditions 8207753Smm * are met: 9207753Smm * 1. Redistributions of source code must retain the above copyright 10207753Smm * notice, this list of conditions and the following disclaimer. 11207753Smm * 2. Redistributions in binary form must reproduce the above copyright 12207753Smm * notice, this list of conditions and the following disclaimer in the 13207753Smm * documentation and/or other materials provided with the distribution. 14207753Smm * 15207753Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16207753Smm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17207753Smm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18207753Smm * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19207753Smm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20207753Smm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21207753Smm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22207753Smm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23207753Smm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24207753Smm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25207753Smm * SUCH DAMAGE. 26207753Smm * 27207753Smm * $FreeBSD: releng/10.2/lib/libdevinfo/devinfo.h 218505 2011-02-10 04:53:09Z imp $ 28207753Smm */ 29207753Smm 30207753Smm#ifndef _DEVINFO_H_INCLUDED 31207753Smm#define _DEVINFO_H_INCLUDED 32207753Smm 33207753Smm#include <sys/cdefs.h> 34207753Smm#include <sys/types.h> 35207753Smm#include <sys/bus.h> 36207753Smm 37207753Smmtypedef __uintptr_t devinfo_handle_t; 38207753Smm#define DEVINFO_ROOT_DEVICE ((devinfo_handle_t)0) 39207753Smm 40207753Smmtypedef enum device_state devinfo_state_t; 41207753Smm 42207753Smmstruct devinfo_dev { 43207753Smm devinfo_handle_t dd_handle; /* device handle */ 44207753Smm devinfo_handle_t dd_parent; /* parent handle */ 45207753Smm 46207753Smm char *dd_name; /* name of device */ 47207753Smm char *dd_desc; /* device description */ 48207753Smm char *dd_drivername; /* name of attached driver*/ 49207753Smm char *dd_pnpinfo; /* pnp info from parent bus */ 50207753Smm char *dd_location; /* Where bus thinks dev at */ 51207753Smm uint32_t dd_devflags; /* API flags */ 52207753Smm uint16_t dd_flags; /* internal dev flags */ 53207753Smm devinfo_state_t dd_state; /* attacement state of dev */ 54207753Smm}; 55207753Smm 56207753Smmstruct devinfo_rman { 57207753Smm devinfo_handle_t dm_handle; /* resource manager handle */ 58207753Smm 59207753Smm unsigned long dm_start; /* resource start */ 60207753Smm unsigned long dm_size; /* resource size */ 61207753Smm 62207753Smm char *dm_desc; /* resource description */ 63207753Smm}; 64207753Smm 65207753Smmstruct devinfo_res { 66207753Smm devinfo_handle_t dr_handle; /* resource handle */ 67207753Smm devinfo_handle_t dr_rman; /* resource manager handle */ 68207753Smm devinfo_handle_t dr_device; /* owning device */ 69207753Smm 70207753Smm unsigned long dr_start; /* region start */ 71207753Smm unsigned long dr_size; /* region size */ 72207753Smm /* XXX add flags */ 73207753Smm}; 74207753Smm 75207753Smm__BEGIN_DECLS 76207753Smm 77207753Smm/* 78207753Smm * Acquire a coherent copy of the kernel's device and resource tables. 79207753Smm * This must return success (zero) before any other interfaces will 80207753Smm * function. Sets errno on failure. 81207753Smm */ 82207753Smmextern int devinfo_init(void); 83207753Smm 84207753Smm/* 85207753Smm * Release the storage associated with the internal copy of the device 86207753Smm * and resource tables. devinfo_init must be called before any attempt 87207753Smm * is made to use any other interfaces. 88207753Smm */ 89207753Smmextern void devinfo_free(void); 90207753Smm 91207753Smm/* 92207753Smm * Find a device/resource/resource manager by its handle. 93207753Smm */ 94207753Smmextern struct devinfo_dev 95207753Smm *devinfo_handle_to_device(devinfo_handle_t handle); 96207753Smmextern struct devinfo_res 97207753Smm *devinfo_handle_to_resource(devinfo_handle_t handle); 98207753Smmextern struct devinfo_rman 99207753Smm *devinfo_handle_to_rman(devinfo_handle_t handle); 100207753Smm 101207753Smm/* 102207753Smm * Iterate over the children of a device, calling (fn) on each. If 103207753Smm * (fn) returns nonzero, abort the scan and return. 104207753Smm */ 105207753Smmextern int 106207753Smm devinfo_foreach_device_child(struct devinfo_dev *parent, 107207753Smm int (* fn)(struct devinfo_dev *child, void *arg), 108207753Smm void *arg); 109207753Smm 110207753Smm/* 111207753Smm * Iterate over all the resources owned by a device, calling (fn) on each. 112207753Smm * If (fn) returns nonzero, abort the scan and return. 113207753Smm */ 114207753Smmextern int 115207753Smm devinfo_foreach_device_resource(struct devinfo_dev *dev, 116207753Smm int (* fn)(struct devinfo_dev *dev, 117207753Smm struct devinfo_res *res, void *arg), 118207753Smm void *arg); 119207753Smm 120207753Smm/* 121207753Smm * Iterate over all the resources owned by a resource manager, calling (fn) 122207753Smm * on each. If (fn) returns nonzero, abort the scan and return. 123207753Smm */ 124207753Smmextern int 125207753Smm devinfo_foreach_rman_resource(struct devinfo_rman *rman, 126207753Smm int (* fn)(struct devinfo_res *res, void *arg), 127207753Smm void *arg); 128207753Smm 129207753Smm/* 130207753Smm * Iterate over all the resource managers, calling (fn) on each. If (fn) 131207753Smm * returns nonzero, abort the scan and return. 132207753Smm */ 133207753Smmextern int 134207753Smm devinfo_foreach_rman(int (* fn)(struct devinfo_rman *rman, void *arg), 135207753Smm void *arg); 136207753Smm 137207753Smm__END_DECLS 138207753Smm 139207753Smm#endif /* ! _DEVINFO_H_INCLUDED */ 140207753Smm