rman.h revision 67261
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 * 2950477Speter * $FreeBSD: head/sys/sys/rman.h 67261 2000-10-17 22:08:03Z imp $ 3040711Swollman */ 3140711Swollman 3240711Swollman#ifndef _SYS_RMAN_H_ 3340711Swollman#define _SYS_RMAN_H_ 1 3440711Swollman 3555205Speter#ifndef _KERNEL 3640711Swollman#include <sys/queue.h> 3755205Speter#endif 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 */ 4560938SjakeCIRCLEQ_HEAD(resource_head, resource); 4640711Swollmanstruct resource { 4760938Sjake CIRCLEQ_ENTRY(resource) r_link; 4860938Sjake LIST_ENTRY(resource) r_sharelink; 4960938Sjake 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 6767261Simp#define RF_ALIGNMENT_SHIFT 10 /* alignment size bit starts bit 10 */ 6867261Simp#define RF_ALIGNMENT_MASK (0x003F << RF_ALIGNMENT_SHIFT) 6967261Simp /* resource address alignemnt size bit mask */ 7067261Simp#define RF_ALIGNMENT_LOG2(x) ((x) << RF_ALIGNMENT_SHIFT) 7167261Simp#define RF_ALIGNMENT(x) (((x) & RF_ALIGNMENT_MASK) >> RF_ALIGNMENT_SHIFT) 7267261Simp 7340711Swollmanenum rman_type { RMAN_UNINIT = 0, RMAN_GAUGE, RMAN_ARRAY }; 7440711Swollman 7540711Swollmanstruct rman { 7640711Swollman struct resource_head rm_list; 7740711Swollman struct simplelock *rm_slock; /* mutex used to protect rm_list */ 7860938Sjake TAILQ_ENTRY(rman) rm_link; /* link in list of all rmans */ 7940711Swollman u_long rm_start; /* index of globally first entry */ 8040711Swollman u_long rm_end; /* index of globally last entry */ 8140711Swollman enum rman_type rm_type; /* what type of resource this is */ 8240711Swollman const char *rm_descr; /* text descripion of this resource */ 8340711Swollman}; 8460938SjakeTAILQ_HEAD(rman_head, rman); 8540711Swollman 8655205Speter#ifdef _KERNEL 8740711Swollman 8840711Swollmanint rman_activate_resource(struct resource *r); 8940711Swollmanint rman_await_resource(struct resource *r, int pri, int timo); 9040711Swollmanint rman_deactivate_resource(struct resource *r); 9140711Swollmanint rman_fini(struct rman *rm); 9240711Swollmanint rman_init(struct rman *rm); 9340711Swollmanint rman_manage_region(struct rman *rm, u_long start, u_long end); 9440711Swollmanint rman_release_resource(struct resource *r); 9540711Swollmanstruct resource *rman_reserve_resource(struct rman *rm, u_long start, 9640711Swollman u_long end, u_long count, 9740711Swollman u_int flags, struct device *dev); 9867261Simpuint32_t rman_make_alignment_flags(uint32_t size); 9940711Swollman 10045720Speter#define rman_get_start(r) ((r)->r_start) 10145720Speter#define rman_get_end(r) ((r)->r_end) 10245720Speter#define rman_get_flags(r) ((r)->r_flags) 10340711Swollman#define rman_set_virtual(r,v) ((r)->r_virtual = (v)) 10440711Swollman#define rman_get_virtual(r) ((r)->r_virtual) 10545720Speter#define rman_set_bustag(r,t) ((r)->r_bustag = (t)) 10645720Speter#define rman_get_bustag(r) ((r)->r_bustag) 10745720Speter#define rman_set_bushandle(r,h) ((r)->r_bushandle = (h)) 10845720Speter#define rman_get_bushandle(r) ((r)->r_bushandle) 10940711Swollman 11040711Swollmanextern struct rman_head rman_head; 11155205Speter#endif /* _KERNEL */ 11240711Swollman 11340711Swollman#endif /* !_SYS_RMAN_H_ */ 114