rman.h revision 40711
1/*
2 * Copyright 1998 Massachusetts Institute of Technology
3 *
4 * Permission to use, copy, modify, and distribute this software and
5 * its documentation for any purpose and without fee is hereby
6 * granted, provided that both the above copyright notice and this
7 * permission notice appear in all copies, that both the above
8 * copyright notice and this permission notice appear in all
9 * supporting documentation, and that the name of M.I.T. not be used
10 * in advertising or publicity pertaining to distribution of the
11 * software without specific, written prior permission.  M.I.T. makes
12 * no representations about the suitability of this software for any
13 * purpose.  It is provided "as is" without express or implied
14 * warranty.
15 *
16 * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
17 * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
20 * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 *	$Id$
30 */
31
32#ifndef _SYS_RMAN_H_
33#define	_SYS_RMAN_H_	1
34
35#ifndef	KERNEL
36#include <sys/queue.h>
37#endif /* !KERNEL */
38
39/*
40 * We use a linked list rather than a bitmap because we need to be able to
41 * represent potentially huge objects (like all of a processor's physical
42 * address space).  That is also why the indices are defined to have type
43 * `unsigned long' -- that being the largest integral type in Standard C.
44 */
45CIRCLEQ_HEAD(resource_head, resource);
46struct	resource {
47	CIRCLEQ_ENTRY(resource)	r_link;
48	LIST_ENTRY(resource)	r_sharelink;
49	LIST_HEAD(, resource) 	*r_sharehead;
50	u_long	r_start;	/* index of the first entry in this resource */
51	u_long	r_end;		/* index of the last entry (inclusive) */
52	u_int	r_flags;
53	void	*r_virtual;	/* virtual address of this resource */
54	struct	device *r_dev;	/* device which has allocated this resource */
55	struct	rman *r_rm;	/* resource manager from whence this came */
56};
57
58#define	RF_ALLOCATED	0x0001	/* resource has been reserved */
59#define	RF_ACTIVE	0x0002	/* resource allocation has been activated */
60#define	RF_SHAREABLE	0x0004	/* resource permits contemporaneous sharing */
61#define	RF_TIMESHARE	0x0008	/* resource permits time-division sharing */
62#define	RF_WANTED	0x0010	/* somebody is waiting for this resource */
63#define	RF_FIRSTSHARE	0x0020	/* first in sharing list */
64
65enum	rman_type { RMAN_UNINIT = 0, RMAN_GAUGE, RMAN_ARRAY };
66
67struct	rman {
68	struct	resource_head 	rm_list;
69	struct	simplelock *rm_slock; /* mutex used to protect rm_list */
70	TAILQ_ENTRY(rman)	rm_link; /* link in list of all rmans */
71	u_long	rm_start;	/* index of globally first entry */
72	u_long	rm_end;		/* index of globally last entry */
73	enum	rman_type rm_type; /* what type of resource this is */
74	const	char *rm_descr;	/* text descripion of this resource */
75};
76TAILQ_HEAD(rman_head, rman);
77
78#ifdef KERNEL
79
80int	rman_activate_resource(struct resource *r);
81int	rman_await_resource(struct resource *r, int pri, int timo);
82int	rman_deactivate_resource(struct resource *r);
83int	rman_fini(struct rman *rm);
84int	rman_init(struct rman *rm);
85int	rman_manage_region(struct rman *rm, u_long start, u_long end);
86int	rman_release_resource(struct resource *r);
87struct	resource *rman_reserve_resource(struct rman *rm, u_long start,
88					u_long end, u_long count,
89					u_int flags, struct device *dev);
90
91#define	rman_set_virtual(r,v)	((r)->r_virtual = (v))
92#define	rman_get_virtual(r)	((r)->r_virtual)
93
94extern	struct rman_head rman_head;
95#endif /* KERNEL */
96
97#endif /* !_SYS_RMAN_H_ */
98