rman.h revision 68522
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 68522 2000-11-09 10:21:23Z msmith $ 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 3968522Smsmith#define RF_ALLOCATED 0x0001 /* resource has been reserved */ 4068522Smsmith#define RF_ACTIVE 0x0002 /* resource allocation has been activated */ 4168522Smsmith#define RF_SHAREABLE 0x0004 /* resource permits contemporaneous sharing */ 4268522Smsmith#define RF_TIMESHARE 0x0008 /* resource permits time-division sharing */ 4368522Smsmith#define RF_WANTED 0x0010 /* somebody is waiting for this resource */ 4468522Smsmith#define RF_FIRSTSHARE 0x0020 /* first in sharing list */ 4568522Smsmith 4668522Smsmith#define RF_ALIGNMENT_SHIFT 10 /* alignment size bit starts bit 10 */ 4768522Smsmith#define RF_ALIGNMENT_MASK (0x003F << RF_ALIGNMENT_SHIFT) 4868522Smsmith /* resource address alignemnt size bit mask */ 4968522Smsmith#define RF_ALIGNMENT_LOG2(x) ((x) << RF_ALIGNMENT_SHIFT) 5068522Smsmith#define RF_ALIGNMENT(x) (((x) & RF_ALIGNMENT_MASK) >> RF_ALIGNMENT_SHIFT) 5168522Smsmith 5268522Smsmithenum rman_type { RMAN_UNINIT = 0, RMAN_GAUGE, RMAN_ARRAY }; 5368522Smsmith 5440711Swollman/* 5568522Smsmith * String length exported to userspace for resource names, etc. 5668522Smsmith */ 5768522Smsmith#define RM_TEXTLEN 32 5868522Smsmith 5968522Smsmith/* 6068522Smsmith * Userspace-exported structures. 6168522Smsmith */ 6268522Smsmithstruct u_resource { 6368522Smsmith uintptr_t r_handle; /* resource uniquifier */ 6468522Smsmith uintptr_t r_parent; /* parent rman */ 6568522Smsmith uintptr_t r_device; /* device owning this resource */ 6668522Smsmith char r_devname[RM_TEXTLEN]; /* device name XXX obsolete */ 6768522Smsmith 6868522Smsmith u_long r_start; /* offset in resource space */ 6968522Smsmith u_long r_size; /* size in resource space */ 7068522Smsmith u_int r_flags; /* RF_* flags */ 7168522Smsmith}; 7268522Smsmith 7368522Smsmithstruct u_rman { 7468522Smsmith uintptr_t rm_handle; /* rman uniquifier */ 7568522Smsmith char rm_descr[RM_TEXTLEN]; /* rman description */ 7668522Smsmith 7768522Smsmith u_long rm_start; /* base of managed region */ 7868522Smsmith u_long rm_size; /* size of managed region */ 7968522Smsmith enum rman_type rm_type; /* region type */ 8068522Smsmith}; 8168522Smsmith 8268522Smsmith#ifdef _KERNEL 8368522Smsmith/* 8440711Swollman * We use a linked list rather than a bitmap because we need to be able to 8540711Swollman * represent potentially huge objects (like all of a processor's physical 8640711Swollman * address space). That is also why the indices are defined to have type 8740711Swollman * `unsigned long' -- that being the largest integral type in Standard C. 8840711Swollman */ 8960938SjakeCIRCLEQ_HEAD(resource_head, resource); 9040711Swollmanstruct resource { 9160938Sjake CIRCLEQ_ENTRY(resource) r_link; 9260938Sjake LIST_ENTRY(resource) r_sharelink; 9360938Sjake LIST_HEAD(, resource) *r_sharehead; 9440711Swollman u_long r_start; /* index of the first entry in this resource */ 9540711Swollman u_long r_end; /* index of the last entry (inclusive) */ 9640711Swollman u_int r_flags; 9740711Swollman void *r_virtual; /* virtual address of this resource */ 9845720Speter bus_space_tag_t r_bustag; /* bus_space tag */ 9945720Speter bus_space_handle_t r_bushandle; /* bus_space handle */ 10040711Swollman struct device *r_dev; /* device which has allocated this resource */ 10140711Swollman struct rman *r_rm; /* resource manager from whence this came */ 10240711Swollman}; 10340711Swollman 10440711Swollmanstruct rman { 10540711Swollman struct resource_head rm_list; 10640711Swollman struct simplelock *rm_slock; /* mutex used to protect rm_list */ 10760938Sjake TAILQ_ENTRY(rman) rm_link; /* link in list of all rmans */ 10840711Swollman u_long rm_start; /* index of globally first entry */ 10940711Swollman u_long rm_end; /* index of globally last entry */ 11040711Swollman enum rman_type rm_type; /* what type of resource this is */ 11140711Swollman const char *rm_descr; /* text descripion of this resource */ 11240711Swollman}; 11360938SjakeTAILQ_HEAD(rman_head, rman); 11440711Swollman 11540711Swollmanint rman_activate_resource(struct resource *r); 11640711Swollmanint rman_await_resource(struct resource *r, int pri, int timo); 11740711Swollmanint rman_deactivate_resource(struct resource *r); 11840711Swollmanint rman_fini(struct rman *rm); 11940711Swollmanint rman_init(struct rman *rm); 12040711Swollmanint rman_manage_region(struct rman *rm, u_long start, u_long end); 12140711Swollmanint rman_release_resource(struct resource *r); 12240711Swollmanstruct resource *rman_reserve_resource(struct rman *rm, u_long start, 12340711Swollman u_long end, u_long count, 12440711Swollman u_int flags, struct device *dev); 12567261Simpuint32_t rman_make_alignment_flags(uint32_t size); 12640711Swollman 12745720Speter#define rman_get_start(r) ((r)->r_start) 12845720Speter#define rman_get_end(r) ((r)->r_end) 12967267Smdodd#define rman_get_size(r) (((r)->r_end - (r)->r_start) + 1) 13045720Speter#define rman_get_flags(r) ((r)->r_flags) 13140711Swollman#define rman_set_virtual(r,v) ((r)->r_virtual = (v)) 13240711Swollman#define rman_get_virtual(r) ((r)->r_virtual) 13345720Speter#define rman_set_bustag(r,t) ((r)->r_bustag = (t)) 13445720Speter#define rman_get_bustag(r) ((r)->r_bustag) 13545720Speter#define rman_set_bushandle(r,h) ((r)->r_bushandle = (h)) 13645720Speter#define rman_get_bushandle(r) ((r)->r_bushandle) 13740711Swollman 13840711Swollmanextern struct rman_head rman_head; 13955205Speter#endif /* _KERNEL */ 14040711Swollman 14140711Swollman#endif /* !_SYS_RMAN_H_ */ 142