Remove macro definitions for BPF_MTAP
[dragonfly.git] / sys / sys / rman.h
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  * $FreeBSD: src/sys/sys/rman.h,v 1.5.2.1 2001/06/05 08:06:07 imp Exp $
30  * $DragonFly: src/sys/sys/rman.h,v 1.7 2004/03/01 06:33:19 dillon Exp $
31  */
32
33 #ifndef _SYS_RMAN_H_
34 #define _SYS_RMAN_H_    1
35
36 #ifndef _KERNEL
37 #include <sys/queue.h>
38 #endif
39 #ifndef _MACHINE_BUS_H_
40 #include <machine/bus.h>        /* bus_space_tag_t */
41 #endif
42
43 /*
44  * We use a linked list rather than a bitmap because we need to be able to
45  * represent potentially huge objects (like all of a processor's physical
46  * address space).  That is also why the indices are defined to have type
47  * `unsigned long' -- that being the largest integral type in Standard C.
48  */
49 CIRCLEQ_HEAD(resource_head, resource);
50 struct  resource {
51         CIRCLEQ_ENTRY(resource) r_link;
52         LIST_ENTRY(resource)    r_sharelink;
53         LIST_HEAD(, resource)   *r_sharehead;
54         u_long  r_start;        /* index of the first entry in this resource */
55         u_long  r_end;          /* index of the last entry (inclusive) */
56         u_int   r_flags;
57         void    *r_virtual;     /* virtual address of this resource */
58         bus_space_tag_t r_bustag; /* bus_space tag */
59         bus_space_handle_t r_bushandle; /* bus_space handle */
60         struct  device *r_dev;  /* device which has allocated this resource */
61         struct  rman *r_rm;     /* resource manager from whence this came */
62 };
63
64 #define RF_ALLOCATED    0x0001  /* resource has been reserved */
65 #define RF_ACTIVE       0x0002  /* resource allocation has been activated */
66 #define RF_SHAREABLE    0x0004  /* resource permits contemporaneous sharing */
67 #define RF_TIMESHARE    0x0008  /* resource permits time-division sharing */
68 #define RF_WANTED       0x0010  /* somebody is waiting for this resource */
69 #define RF_FIRSTSHARE   0x0020  /* first in sharing list */
70 #define RF_PREFETCHABLE 0x0040  /* resource is prefetchable */
71
72 #define RF_ALIGNMENT_SHIFT      10 /* alignment size bit starts bit 10 */
73 #define RF_ALIGNMENT_MASK       (0x003F << RF_ALIGNMENT_SHIFT)
74                                 /* resource address alignemnt size bit mask */
75 #define RF_ALIGNMENT_LOG2(x)    ((x) << RF_ALIGNMENT_SHIFT)
76 #define RF_ALIGNMENT(x)         (((x) & RF_ALIGNMENT_MASK) >> RF_ALIGNMENT_SHIFT)
77
78 enum    rman_type { RMAN_UNINIT = 0, RMAN_GAUGE, RMAN_ARRAY };
79
80 struct lwkt_token;
81 struct lwkt_tokref;
82
83 struct  rman {
84         struct  resource_head   rm_list;
85         struct  lwkt_token      *rm_slock; /* mutex used to protect rm_list */
86         TAILQ_ENTRY(rman)       rm_link; /* link in list of all rmans */
87         u_long  rm_start;       /* index of globally first entry */
88         u_long  rm_end;         /* index of globally last entry */
89         enum    rman_type rm_type; /* what type of resource this is */
90         const   char *rm_descr; /* text descripion of this resource */
91 };
92 TAILQ_HEAD(rman_head, rman);
93
94 #ifdef _KERNEL
95
96 int     rman_activate_resource(struct resource *r);
97 int     rman_await_resource(struct resource *r, struct lwkt_tokref *ilock, int slpflags, int timo);
98 int     rman_deactivate_resource(struct resource *r);
99 int     rman_fini(struct rman *rm);
100 int     rman_init(struct rman *rm);
101 int     rman_manage_region(struct rman *rm, u_long start, u_long end);
102 int     rman_release_resource(struct resource *r);
103 struct  resource *rman_reserve_resource(struct rman *rm, u_long start,
104                                         u_long end, u_long count,
105                                         u_int flags, struct device *dev);
106 uint32_t rman_make_alignment_flags(uint32_t size);
107
108 #define rman_get_start(r)       ((r)->r_start)
109 #define rman_get_end(r)         ((r)->r_end)
110 #define rman_get_device(r)      ((r)->r_dev)
111 #define rman_get_size(r)        ((r)->r_end - (r)->r_start + 1)
112 #define rman_get_flags(r)       ((r)->r_flags)
113 #define rman_set_virtual(r,v)   ((r)->r_virtual = (v))
114 #define rman_get_virtual(r)     ((r)->r_virtual)
115 #define rman_set_bustag(r,t)    ((r)->r_bustag = (t))
116 #define rman_get_bustag(r)      ((r)->r_bustag)
117 #define rman_set_bushandle(r,h) ((r)->r_bushandle = (h))
118 #define rman_get_bushandle(r)   ((r)->r_bushandle)
119
120 extern  struct rman_head rman_head;
121 #endif /* _KERNEL */
122
123 #endif /* !_SYS_RMAN_H_ */