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$
2875726Smsmith */
2975726Smsmith
30149671Srodrigc#ifndef _DEVINFO_H_INCLUDED
31149671Srodrigc#define _DEVINFO_H_INCLUDED
32149671Srodrigc
3384399Sbde#include <sys/cdefs.h>
34218505Simp#include <sys/types.h>
35199291Sattilio#include <sys/bus.h>
3675726Smsmith
3784399Sbdetypedef __uintptr_t	devinfo_handle_t;
3884399Sbde#define DEVINFO_ROOT_DEVICE	((devinfo_handle_t)0)
3984399Sbde
40199291Sattiliotypedef enum device_state devinfo_state_t;
41103662Simp
4275726Smsmithstruct devinfo_dev {
4375726Smsmith	devinfo_handle_t	dd_handle;	/* device handle */
4475726Smsmith	devinfo_handle_t	dd_parent;	/* parent handle */
4575726Smsmith
4675726Smsmith	char			*dd_name;	/* name of device */
4775726Smsmith	char			*dd_desc;	/* device description */
4875726Smsmith	char			*dd_drivername;	/* name of attached driver*/
49103662Simp	char			*dd_pnpinfo;	/* pnp info from parent bus */
50103662Simp	char			*dd_location;	/* Where bus thinks dev at */
51103662Simp	uint32_t		dd_devflags;	/* API flags */
52103662Simp	uint16_t		dd_flags;	/* internal dev flags */
53103662Simp	devinfo_state_t		dd_state;	/* attacement state of dev */
5475726Smsmith};
5575726Smsmith
5675726Smsmithstruct devinfo_rman {
5775726Smsmith	devinfo_handle_t	dm_handle;	/* resource manager handle */
5875726Smsmith
5984399Sbde	unsigned long		dm_start;	/* resource start */
6084399Sbde	unsigned long		dm_size;	/* resource size */
6175726Smsmith
6275726Smsmith	char			*dm_desc;	/* resource description */
6375726Smsmith};
6475726Smsmith
6575726Smsmithstruct devinfo_res {
6675726Smsmith	devinfo_handle_t	dr_handle;	/* resource handle */
6775726Smsmith	devinfo_handle_t	dr_rman;	/* resource manager handle */
6875726Smsmith	devinfo_handle_t	dr_device;	/* owning device */
6975726Smsmith
7084399Sbde	unsigned long		dr_start;	/* region start */
7184399Sbde	unsigned long		dr_size;	/* region size */
7275726Smsmith	/* XXX add flags */
7375726Smsmith};
7475726Smsmith
75149671Srodrigc__BEGIN_DECLS
76149671Srodrigc
7775726Smsmith/*
7875726Smsmith * Acquire a coherent copy of the kernel's device and resource tables.
7975726Smsmith * This must return success (zero) before any other interfaces will
8075726Smsmith * function.  Sets errno on failure.
8175726Smsmith */
8275726Smsmithextern int	devinfo_init(void);
8375726Smsmith
8475726Smsmith/*
8575726Smsmith * Release the storage associated with the internal copy of the device
8675726Smsmith * and resource tables. devinfo_init must be called before any attempt
8775726Smsmith * is made to use any other interfaces.
8875726Smsmith */
8975726Smsmithextern void	devinfo_free(void);
9075726Smsmith
9175726Smsmith/*
9275726Smsmith * Find a device/resource/resource manager by its handle.
9375726Smsmith */
9475726Smsmithextern struct devinfo_dev
9575726Smsmith	*devinfo_handle_to_device(devinfo_handle_t handle);
9675726Smsmithextern struct devinfo_res
9775726Smsmith	*devinfo_handle_to_resource(devinfo_handle_t handle);
9875726Smsmithextern struct devinfo_rman
9975726Smsmith	*devinfo_handle_to_rman(devinfo_handle_t handle);
10075726Smsmith
10175726Smsmith/*
10275726Smsmith * Iterate over the children of a device, calling (fn) on each.  If
10375726Smsmith * (fn) returns nonzero, abort the scan and return.
10475726Smsmith */
10575726Smsmithextern int
10675726Smsmith	devinfo_foreach_device_child(struct devinfo_dev *parent,
10775726Smsmith	    int (* fn)(struct devinfo_dev *child, void *arg),
10875726Smsmith	    void *arg);
10975726Smsmith
11075726Smsmith/*
11175726Smsmith * Iterate over all the resources owned by a device, calling (fn) on each.
11275726Smsmith * If (fn) returns nonzero, abort the scan and return.
11375726Smsmith */
11475726Smsmithextern int
11575726Smsmith	devinfo_foreach_device_resource(struct devinfo_dev *dev,
11675726Smsmith	    int (* fn)(struct devinfo_dev *dev,
11775726Smsmith	    struct devinfo_res *res, void *arg),
11875726Smsmith	    void *arg);
11975726Smsmith
12075726Smsmith/*
12175726Smsmith * Iterate over all the resources owned by a resource manager, calling (fn)
12275726Smsmith * on each.  If (fn) returns nonzero, abort the scan and return.
12375726Smsmith */
12475726Smsmithextern int
12575726Smsmith	devinfo_foreach_rman_resource(struct devinfo_rman *rman,
12675726Smsmith	    int (* fn)(struct devinfo_res *res, void *arg),
12775726Smsmith	    void *arg);
12875726Smsmith
12975726Smsmith/*
13075726Smsmith * Iterate over all the resource managers, calling (fn) on each.  If (fn)
13175726Smsmith * returns nonzero, abort the scan and return.
13275726Smsmith */
13375726Smsmithextern int
13475726Smsmith	devinfo_foreach_rman(int (* fn)(struct devinfo_rman *rman, void *arg),
13575726Smsmith	    void *arg);
136149671Srodrigc
137149671Srodrigc__END_DECLS
138149671Srodrigc
139149671Srodrigc#endif /* ! _DEVINFO_H_INCLUDED */
140