1a2e6df29SMike Smith /*- 24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 35e53a4f9SPedro F. Giffuni * 4a2e6df29SMike Smith * Copyright (c) 2000 Michael Smith 5a2e6df29SMike Smith * Copyright (c) 2000 BSDi 6a2e6df29SMike Smith * All rights reserved. 7a2e6df29SMike Smith * 8a2e6df29SMike Smith * Redistribution and use in source and binary forms, with or without 9a2e6df29SMike Smith * modification, are permitted provided that the following conditions 10a2e6df29SMike Smith * are met: 11a2e6df29SMike Smith * 1. Redistributions of source code must retain the above copyright 12a2e6df29SMike Smith * notice, this list of conditions and the following disclaimer. 13a2e6df29SMike Smith * 2. Redistributions in binary form must reproduce the above copyright 14a2e6df29SMike Smith * notice, this list of conditions and the following disclaimer in the 15a2e6df29SMike Smith * documentation and/or other materials provided with the distribution. 16a2e6df29SMike Smith * 17a2e6df29SMike Smith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18a2e6df29SMike Smith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19a2e6df29SMike Smith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20a2e6df29SMike Smith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21a2e6df29SMike Smith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22a2e6df29SMike Smith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23a2e6df29SMike Smith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24a2e6df29SMike Smith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25a2e6df29SMike Smith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26a2e6df29SMike Smith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27a2e6df29SMike Smith * SUCH DAMAGE. 28a2e6df29SMike Smith */ 29a2e6df29SMike Smith 301760096dSCraig Rodrigues #ifndef _DEVINFO_H_INCLUDED 311760096dSCraig Rodrigues #define _DEVINFO_H_INCLUDED 321760096dSCraig Rodrigues 3382394a8dSWarner Losh #include <sys/types.h> 3412628101SAttilio Rao #include <sys/bus.h> 35e3be9e10SBruce Evans 36e3be9e10SBruce Evans typedef __uintptr_t devinfo_handle_t; 37*7554746cSJohn Baldwin #define DEVINFO_ROOT_DEVICE ((devinfo_handle_t)-1) 38a2e6df29SMike Smith 3912628101SAttilio Rao typedef enum device_state devinfo_state_t; 4043832002SWarner Losh 41a2e6df29SMike Smith struct devinfo_dev { 42a2e6df29SMike Smith devinfo_handle_t dd_handle; /* device handle */ 43a2e6df29SMike Smith devinfo_handle_t dd_parent; /* parent handle */ 44a2e6df29SMike Smith 45a2e6df29SMike Smith char *dd_name; /* name of device */ 46a2e6df29SMike Smith char *dd_desc; /* device description */ 47a2e6df29SMike Smith char *dd_drivername; /* name of attached driver*/ 4843832002SWarner Losh char *dd_pnpinfo; /* pnp info from parent bus */ 4943832002SWarner Losh char *dd_location; /* Where bus thinks dev at */ 5043832002SWarner Losh uint32_t dd_devflags; /* API flags */ 5143832002SWarner Losh uint16_t dd_flags; /* internal dev flags */ 5294f0eafcSJohn Baldwin devinfo_state_t dd_state; /* attachment state of dev */ 53a2e6df29SMike Smith }; 54a2e6df29SMike Smith 55a2e6df29SMike Smith struct devinfo_rman { 56a2e6df29SMike Smith devinfo_handle_t dm_handle; /* resource manager handle */ 57a2e6df29SMike Smith 582dd1bdf1SJustin Hibbits rman_res_t dm_start; /* resource start */ 592dd1bdf1SJustin Hibbits rman_res_t dm_size; /* resource size */ 60a2e6df29SMike Smith 61a2e6df29SMike Smith char *dm_desc; /* resource description */ 62a2e6df29SMike Smith }; 63a2e6df29SMike Smith 64a2e6df29SMike Smith struct devinfo_res { 65a2e6df29SMike Smith devinfo_handle_t dr_handle; /* resource handle */ 66a2e6df29SMike Smith devinfo_handle_t dr_rman; /* resource manager handle */ 67a2e6df29SMike Smith devinfo_handle_t dr_device; /* owning device */ 68a2e6df29SMike Smith 692dd1bdf1SJustin Hibbits rman_res_t dr_start; /* region start */ 702dd1bdf1SJustin Hibbits rman_res_t dr_size; /* region size */ 71a2e6df29SMike Smith /* XXX add flags */ 72a2e6df29SMike Smith }; 73a2e6df29SMike Smith 741760096dSCraig Rodrigues __BEGIN_DECLS 751760096dSCraig Rodrigues 76a2e6df29SMike Smith /* 77a2e6df29SMike Smith * Acquire a coherent copy of the kernel's device and resource tables. 78a2e6df29SMike Smith * This must return success (zero) before any other interfaces will 79a2e6df29SMike Smith * function. Sets errno on failure. 80a2e6df29SMike Smith */ 81a2e6df29SMike Smith extern int devinfo_init(void); 82a2e6df29SMike Smith 83a2e6df29SMike Smith /* 84a2e6df29SMike Smith * Release the storage associated with the internal copy of the device 85a2e6df29SMike Smith * and resource tables. devinfo_init must be called before any attempt 86a2e6df29SMike Smith * is made to use any other interfaces. 87a2e6df29SMike Smith */ 88a2e6df29SMike Smith extern void devinfo_free(void); 89a2e6df29SMike Smith 90a2e6df29SMike Smith /* 91a2e6df29SMike Smith * Find a device/resource/resource manager by its handle. 92a2e6df29SMike Smith */ 93a2e6df29SMike Smith extern struct devinfo_dev 94a2e6df29SMike Smith *devinfo_handle_to_device(devinfo_handle_t handle); 95a2e6df29SMike Smith extern struct devinfo_res 96a2e6df29SMike Smith *devinfo_handle_to_resource(devinfo_handle_t handle); 97a2e6df29SMike Smith extern struct devinfo_rman 98a2e6df29SMike Smith *devinfo_handle_to_rman(devinfo_handle_t handle); 99a2e6df29SMike Smith 100a2e6df29SMike Smith /* 101a2e6df29SMike Smith * Iterate over the children of a device, calling (fn) on each. If 102a2e6df29SMike Smith * (fn) returns nonzero, abort the scan and return. 103a2e6df29SMike Smith */ 104a2e6df29SMike Smith extern int 105a2e6df29SMike Smith devinfo_foreach_device_child(struct devinfo_dev *parent, 106a2e6df29SMike Smith int (* fn)(struct devinfo_dev *child, void *arg), 107a2e6df29SMike Smith void *arg); 108a2e6df29SMike Smith 109a2e6df29SMike Smith /* 110a2e6df29SMike Smith * Iterate over all the resources owned by a device, calling (fn) on each. 111a2e6df29SMike Smith * If (fn) returns nonzero, abort the scan and return. 112a2e6df29SMike Smith */ 113a2e6df29SMike Smith extern int 114a2e6df29SMike Smith devinfo_foreach_device_resource(struct devinfo_dev *dev, 115a2e6df29SMike Smith int (* fn)(struct devinfo_dev *dev, 116a2e6df29SMike Smith struct devinfo_res *res, void *arg), 117a2e6df29SMike Smith void *arg); 118a2e6df29SMike Smith 119a2e6df29SMike Smith /* 120a2e6df29SMike Smith * Iterate over all the resources owned by a resource manager, calling (fn) 121a2e6df29SMike Smith * on each. If (fn) returns nonzero, abort the scan and return. 122a2e6df29SMike Smith */ 123a2e6df29SMike Smith extern int 124a2e6df29SMike Smith devinfo_foreach_rman_resource(struct devinfo_rman *rman, 125a2e6df29SMike Smith int (* fn)(struct devinfo_res *res, void *arg), 126a2e6df29SMike Smith void *arg); 127a2e6df29SMike Smith 128a2e6df29SMike Smith /* 129a2e6df29SMike Smith * Iterate over all the resource managers, calling (fn) on each. If (fn) 130a2e6df29SMike Smith * returns nonzero, abort the scan and return. 131a2e6df29SMike Smith */ 132a2e6df29SMike Smith extern int 133a2e6df29SMike Smith devinfo_foreach_rman(int (* fn)(struct devinfo_rman *rman, void *arg), 134a2e6df29SMike Smith void *arg); 1351760096dSCraig Rodrigues 1361760096dSCraig Rodrigues __END_DECLS 1371760096dSCraig Rodrigues 1381760096dSCraig Rodrigues #endif /* ! _DEVINFO_H_INCLUDED */ 139