devinfo.h revision 75726
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 75726 2001-04-20 05:53:30Z msmith $
2875726Smsmith */
2975726Smsmith
3075726Smsmithtypedef uintptr_t	devinfo_handle_t;
3175726Smsmith#define DEVINFO_ROOT_DEVICE	(devinfo_handle_t)0
3275726Smsmith
3375726Smsmithstruct devinfo_dev {
3475726Smsmith	devinfo_handle_t	dd_handle;	/* device handle */
3575726Smsmith	devinfo_handle_t	dd_parent;	/* parent handle */
3675726Smsmith
3775726Smsmith	char			*dd_name;	/* name of device */
3875726Smsmith	char			*dd_desc;	/* device description */
3975726Smsmith	char			*dd_drivername;	/* name of attached driver*/
4075726Smsmith};
4175726Smsmith
4275726Smsmithstruct devinfo_rman {
4375726Smsmith	devinfo_handle_t	dm_handle;	/* resource manager handle */
4475726Smsmith
4575726Smsmith	u_long			dm_start;	/* resource start */
4675726Smsmith	u_long			dm_size;	/* resource size */
4775726Smsmith
4875726Smsmith	char			*dm_desc;	/* resource description */
4975726Smsmith};
5075726Smsmith
5175726Smsmithstruct devinfo_res {
5275726Smsmith	devinfo_handle_t	dr_handle;	/* resource handle */
5375726Smsmith	devinfo_handle_t	dr_rman;	/* resource manager handle */
5475726Smsmith	devinfo_handle_t	dr_device;	/* owning device */
5575726Smsmith
5675726Smsmith	u_long			dr_start;	/* region start */
5775726Smsmith	u_long			dr_size;	/* region size */
5875726Smsmith	/* XXX add flags */
5975726Smsmith};
6075726Smsmith
6175726Smsmith/*
6275726Smsmith * Acquire a coherent copy of the kernel's device and resource tables.
6375726Smsmith * This must return success (zero) before any other interfaces will
6475726Smsmith * function.  Sets errno on failure.
6575726Smsmith */
6675726Smsmithextern int	devinfo_init(void);
6775726Smsmith
6875726Smsmith/*
6975726Smsmith * Release the storage associated with the internal copy of the device
7075726Smsmith * and resource tables. devinfo_init must be called before any attempt
7175726Smsmith * is made to use any other interfaces.
7275726Smsmith */
7375726Smsmithextern void	devinfo_free(void);
7475726Smsmith
7575726Smsmith/*
7675726Smsmith * Find a device/resource/resource manager by its handle.
7775726Smsmith */
7875726Smsmithextern struct devinfo_dev
7975726Smsmith	*devinfo_handle_to_device(devinfo_handle_t handle);
8075726Smsmithextern struct devinfo_res
8175726Smsmith	*devinfo_handle_to_resource(devinfo_handle_t handle);
8275726Smsmithextern struct devinfo_rman
8375726Smsmith	*devinfo_handle_to_rman(devinfo_handle_t handle);
8475726Smsmith
8575726Smsmith/*
8675726Smsmith * Iterate over the children of a device, calling (fn) on each.  If
8775726Smsmith * (fn) returns nonzero, abort the scan and return.
8875726Smsmith */
8975726Smsmithextern int
9075726Smsmith	devinfo_foreach_device_child(struct devinfo_dev *parent,
9175726Smsmith	    int (* fn)(struct devinfo_dev *child, void *arg),
9275726Smsmith	    void *arg);
9375726Smsmith
9475726Smsmith/*
9575726Smsmith * Iterate over all the resources owned by a device, calling (fn) on each.
9675726Smsmith * If (fn) returns nonzero, abort the scan and return.
9775726Smsmith */
9875726Smsmithextern int
9975726Smsmith	devinfo_foreach_device_resource(struct devinfo_dev *dev,
10075726Smsmith	    int (* fn)(struct devinfo_dev *dev,
10175726Smsmith	    struct devinfo_res *res, void *arg),
10275726Smsmith	    void *arg);
10375726Smsmith
10475726Smsmith/*
10575726Smsmith * Iterate over all the resources owned by a resource manager, calling (fn)
10675726Smsmith * on each.  If (fn) returns nonzero, abort the scan and return.
10775726Smsmith */
10875726Smsmithextern int
10975726Smsmith	devinfo_foreach_rman_resource(struct devinfo_rman *rman,
11075726Smsmith	    int (* fn)(struct devinfo_res *res, void *arg),
11175726Smsmith	    void *arg);
11275726Smsmith
11375726Smsmith/*
11475726Smsmith * Iterate over all the resource managers, calling (fn) on each.  If (fn)
11575726Smsmith * returns nonzero, abort the scan and return.
11675726Smsmith */
11775726Smsmithextern int
11875726Smsmith	devinfo_foreach_rman(int (* fn)(struct devinfo_rman *rman, void *arg),
11975726Smsmith	    void *arg);
120