rman.h revision 45720
140711Swollman/*
240711Swollman * Copyright 1998 Massachusetts Institute of Technology
340711Swollman *
440711Swollman * Permission to use, copy, modify, and distribute this software and
540711Swollman * its documentation for any purpose and without fee is hereby
640711Swollman * granted, provided that both the above copyright notice and this
740711Swollman * permission notice appear in all copies, that both the above
840711Swollman * copyright notice and this permission notice appear in all
940711Swollman * supporting documentation, and that the name of M.I.T. not be used
1040711Swollman * in advertising or publicity pertaining to distribution of the
1140711Swollman * software without specific, written prior permission.  M.I.T. makes
1240711Swollman * no representations about the suitability of this software for any
1340711Swollman * purpose.  It is provided "as is" without express or implied
1440711Swollman * warranty.
1540711Swollman *
1640711Swollman * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
1740711Swollman * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
1840711Swollman * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1940711Swollman * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
2040711Swollman * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2140711Swollman * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2240711Swollman * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
2340711Swollman * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2440711Swollman * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2540711Swollman * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
2640711Swollman * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2740711Swollman * SUCH DAMAGE.
2840711Swollman *
2945720Speter *	$Id: rman.h,v 1.1 1998/10/29 01:48:30 wollman Exp $
3040711Swollman */
3140711Swollman
3240711Swollman#ifndef _SYS_RMAN_H_
3340711Swollman#define	_SYS_RMAN_H_	1
3440711Swollman
3540711Swollman#ifndef	KERNEL
3640711Swollman#include <sys/queue.h>
3740711Swollman#endif /* !KERNEL */
3840711Swollman
3940711Swollman/*
4040711Swollman * We use a linked list rather than a bitmap because we need to be able to
4140711Swollman * represent potentially huge objects (like all of a processor's physical
4240711Swollman * address space).  That is also why the indices are defined to have type
4340711Swollman * `unsigned long' -- that being the largest integral type in Standard C.
4440711Swollman */
4540711SwollmanCIRCLEQ_HEAD(resource_head, resource);
4640711Swollmanstruct	resource {
4740711Swollman	CIRCLEQ_ENTRY(resource)	r_link;
4840711Swollman	LIST_ENTRY(resource)	r_sharelink;
4940711Swollman	LIST_HEAD(, resource) 	*r_sharehead;
5040711Swollman	u_long	r_start;	/* index of the first entry in this resource */
5140711Swollman	u_long	r_end;		/* index of the last entry (inclusive) */
5240711Swollman	u_int	r_flags;
5340711Swollman	void	*r_virtual;	/* virtual address of this resource */
5445720Speter	bus_space_tag_t r_bustag; /* bus_space tag */
5545720Speter	bus_space_handle_t r_bushandle;	/* bus_space handle */
5640711Swollman	struct	device *r_dev;	/* device which has allocated this resource */
5740711Swollman	struct	rman *r_rm;	/* resource manager from whence this came */
5840711Swollman};
5940711Swollman
6040711Swollman#define	RF_ALLOCATED	0x0001	/* resource has been reserved */
6140711Swollman#define	RF_ACTIVE	0x0002	/* resource allocation has been activated */
6240711Swollman#define	RF_SHAREABLE	0x0004	/* resource permits contemporaneous sharing */
6340711Swollman#define	RF_TIMESHARE	0x0008	/* resource permits time-division sharing */
6440711Swollman#define	RF_WANTED	0x0010	/* somebody is waiting for this resource */
6540711Swollman#define	RF_FIRSTSHARE	0x0020	/* first in sharing list */
6640711Swollman
6740711Swollmanenum	rman_type { RMAN_UNINIT = 0, RMAN_GAUGE, RMAN_ARRAY };
6840711Swollman
6940711Swollmanstruct	rman {
7040711Swollman	struct	resource_head 	rm_list;
7140711Swollman	struct	simplelock *rm_slock; /* mutex used to protect rm_list */
7240711Swollman	TAILQ_ENTRY(rman)	rm_link; /* link in list of all rmans */
7340711Swollman	u_long	rm_start;	/* index of globally first entry */
7440711Swollman	u_long	rm_end;		/* index of globally last entry */
7540711Swollman	enum	rman_type rm_type; /* what type of resource this is */
7640711Swollman	const	char *rm_descr;	/* text descripion of this resource */
7740711Swollman};
7840711SwollmanTAILQ_HEAD(rman_head, rman);
7940711Swollman
8040711Swollman#ifdef KERNEL
8140711Swollman
8240711Swollmanint	rman_activate_resource(struct resource *r);
8340711Swollmanint	rman_await_resource(struct resource *r, int pri, int timo);
8440711Swollmanint	rman_deactivate_resource(struct resource *r);
8540711Swollmanint	rman_fini(struct rman *rm);
8640711Swollmanint	rman_init(struct rman *rm);
8740711Swollmanint	rman_manage_region(struct rman *rm, u_long start, u_long end);
8840711Swollmanint	rman_release_resource(struct resource *r);
8940711Swollmanstruct	resource *rman_reserve_resource(struct rman *rm, u_long start,
9040711Swollman					u_long end, u_long count,
9140711Swollman					u_int flags, struct device *dev);
9240711Swollman
9345720Speter#define rman_get_start(r)	((r)->r_start)
9445720Speter#define rman_get_end(r)		((r)->r_end)
9545720Speter#define rman_get_flags(r)	((r)->r_flags)
9640711Swollman#define	rman_set_virtual(r,v)	((r)->r_virtual = (v))
9740711Swollman#define	rman_get_virtual(r)	((r)->r_virtual)
9845720Speter#define rman_set_bustag(r,t)	((r)->r_bustag = (t))
9945720Speter#define rman_get_bustag(r)	((r)->r_bustag)
10045720Speter#define rman_set_bushandle(r,h)	((r)->r_bushandle = (h))
10145720Speter#define rman_get_bushandle(r)	((r)->r_bushandle)
10240711Swollman
10340711Swollmanextern	struct rman_head rman_head;
10440711Swollman#endif /* KERNEL */
10540711Swollman
10640711Swollman#endif /* !_SYS_RMAN_H_ */
107