/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2000 Michael Smith4* Copyright (c) 2000 BSDi5* All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10* 1. Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND17* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE20* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26* SUCH DAMAGE.27*/2829#ifndef _DEVINFO_H_INCLUDED30#define _DEVINFO_H_INCLUDED3132#include <sys/types.h>33#include <sys/bus.h>3435typedef __uintptr_t devinfo_handle_t;36#define DEVINFO_ROOT_DEVICE ((devinfo_handle_t)-1)3738typedef enum device_state devinfo_state_t;3940struct devinfo_dev {41devinfo_handle_t dd_handle; /* device handle */42devinfo_handle_t dd_parent; /* parent handle */4344char *dd_name; /* name of device */45char *dd_desc; /* device description */46char *dd_drivername; /* name of attached driver*/47char *dd_pnpinfo; /* pnp info from parent bus */48char *dd_location; /* Where bus thinks dev at */49uint32_t dd_devflags; /* API flags */50uint16_t dd_flags; /* internal dev flags */51devinfo_state_t dd_state; /* attachment state of dev */52};5354struct devinfo_rman {55devinfo_handle_t dm_handle; /* resource manager handle */5657rman_res_t dm_start; /* resource start */58rman_res_t dm_size; /* resource size */5960char *dm_desc; /* resource description */61};6263struct devinfo_res {64devinfo_handle_t dr_handle; /* resource handle */65devinfo_handle_t dr_rman; /* resource manager handle */66devinfo_handle_t dr_device; /* owning device */6768rman_res_t dr_start; /* region start */69rman_res_t dr_size; /* region size */70/* XXX add flags */71};7273__BEGIN_DECLS7475/*76* Acquire a coherent copy of the kernel's device and resource tables.77* This must return success (zero) before any other interfaces will78* function. Sets errno on failure.79*/80extern int devinfo_init(void);8182/*83* Release the storage associated with the internal copy of the device84* and resource tables. devinfo_init must be called before any attempt85* is made to use any other interfaces.86*/87extern void devinfo_free(void);8889/*90* Find a device/resource/resource manager by its handle.91*/92extern struct devinfo_dev93*devinfo_handle_to_device(devinfo_handle_t handle);94extern struct devinfo_res95*devinfo_handle_to_resource(devinfo_handle_t handle);96extern struct devinfo_rman97*devinfo_handle_to_rman(devinfo_handle_t handle);9899/*100* Iterate over the children of a device, calling (fn) on each. If101* (fn) returns nonzero, abort the scan and return.102*/103extern int104devinfo_foreach_device_child(struct devinfo_dev *parent,105int (* fn)(struct devinfo_dev *child, void *arg),106void *arg);107108/*109* Iterate over all the resources owned by a device, calling (fn) on each.110* If (fn) returns nonzero, abort the scan and return.111*/112extern int113devinfo_foreach_device_resource(struct devinfo_dev *dev,114int (* fn)(struct devinfo_dev *dev,115struct devinfo_res *res, void *arg),116void *arg);117118/*119* Iterate over all the resources owned by a resource manager, calling (fn)120* on each. If (fn) returns nonzero, abort the scan and return.121*/122extern int123devinfo_foreach_rman_resource(struct devinfo_rman *rman,124int (* fn)(struct devinfo_res *res, void *arg),125void *arg);126127/*128* Iterate over all the resource managers, calling (fn) on each. If (fn)129* returns nonzero, abort the scan and return.130*/131extern int132devinfo_foreach_rman(int (* fn)(struct devinfo_rman *rman, void *arg),133void *arg);134135__END_DECLS136137#endif /* ! _DEVINFO_H_INCLUDED */138139140