2 .\" Copyright (c) 2003 Bruce M Simpson <bms@spc.org>
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .Nm rman_activate_resource ,
34 .Nm rman_await_resource ,
35 .Nm rman_deactivate_resource ,
38 .Nm rman_manage_region ,
39 .Nm rman_release_resource ,
40 .Nm rman_reserve_resource ,
41 .Nm rman_reserve_resource_bound ,
42 .Nm rman_make_alignment_flags ,
48 .Nm rman_set_virtual ,
49 .Nm rman_get_virtual ,
52 .Nm rman_set_bushandle ,
53 .Nm rman_get_bushandle ,
56 .Nd resource management functions
60 .Fn rman_activate_resource "struct resource *r"
62 .Fn rman_await_resource "struct resource *r" "int pri2" "int timo"
64 .Fn rman_deactivate_resource "struct resource *r"
66 .Fn rman_fini "struct rman *rm"
68 .Fn rman_init "struct rman *rm"
70 .Fn rman_manage_region "struct rman *rm" "u_long start" "u_long end"
72 .Fn rman_release_resource "struct resource *r"
73 .Ft "struct resource *"
74 .Fo rman_reserve_resource
75 .Fa "struct rman *rm" "u_long start" "u_long end" "u_long count"
76 .Fa "u_int flags" "struct device *dev"
78 .Ft "struct resource *"
79 .Fo rman_reserve_resource_bound
80 .Fa "struct rman *rm" "u_long start" "u_long end" "u_long count"
81 .Fa "u_long bound" "u_int flags" "struct device *dev"
84 .Fn rman_make_alignment_flags "uint32_t size"
86 .Fn rman_get_start "struct resource *r"
88 .Fn rman_get_end "struct resource *r"
90 .Fn rman_get_device "struct resource *r"
92 .Fn rman_get_size "struct resource *r"
94 .Fn rman_get_flags "struct resource *r"
96 .Fn rman_set_virtual "struct resource *r" "void *v"
98 .Fn rman_get_virtual "struct resource *r"
100 .Fn rman_set_bustag "struct resource *r" "bus_space_tag_t t"
102 .Fn rman_get_bustag "struct resource *r"
104 .Fn rman_set_bushandle "struct resource *r" "bus_space_handle_t h"
105 .Ft bus_space_handle_t
106 .Fn rman_get_bushandle "struct resource *r"
108 .Fn rman_set_rid "struct resource *r" "int rid"
110 .Fn rman_get_rid "struct resource *r"
114 set of functions provides a flexible resource management abstraction.
115 It is used extensively by the bus management code.
116 It implements the abstractions of region and resource.
117 A region descriptor is used to manage a region; this could be memory or
118 some other form of bus space.
120 Each region has a set of bounds.
121 Within these bounds, allocated segments may reside.
122 Each segment, termed a resource, has several properties which are
123 represented by a 16-bit flag register, as follows.
125 #define RF_ALLOCATED 0x0001 /* resource has been reserved */
126 #define RF_ACTIVE 0x0002 /* resource allocation has been activated */
127 #define RF_SHAREABLE 0x0004 /* resource permits contemporaneous sharing */
128 #define RF_TIMESHARE 0x0008 /* resource permits time-division sharing */
129 #define RF_WANTED 0x0010 /* somebody is waiting for this resource */
130 #define RF_FIRSTSHARE 0x0020 /* first in sharing list */
131 #define RF_PREFETCHABLE 0x0040 /* resource is prefetchable */
134 The remainder of the flag bits are used to represent the desired alignment
135 of the resource within the region.
139 function initializes the region descriptor, pointed to by the
141 argument, for use with the resource management functions.
142 It also initializes any mutexes associated with the structure.
146 function frees any structures associated with the structure
150 If any of the resources within the managed region have the
152 flag set, it will return
154 otherwise, any mutexes associated with the structure will be released
155 and destroyed, and the function will return 0.
158 .Fn rman_manage_region
159 function establishes the concept of a region which is under
164 argument points to the region descriptor.
169 arguments specify the bounds of the region.
172 This interface is not robust against programming errors which
173 add multiple copies of the same region.
176 .Fn rman_reserve_resource_bound
177 function is where the bulk of the
180 It attempts to reserve a contiguous range in the specified region
182 for the use of the device
184 The caller can specify the
188 of an acceptable range, as well as
189 alignment, and the code will attempt to find a free segment which fits.
192 argument is the lowest acceptable starting value of the resource.
195 argument is the highest acceptable ending value of the resource.
197 .Fa start No + Fa count No \- 1
200 for any allocation to happen.
201 The default behavior is to allocate an exclusive segment, unless the
205 flags are set, in which case a shared
206 segment will be allocated.
207 If this shared segment already exists, the caller has its device
208 added to the list of consumers.
211 .Fn rman_reserve_resource
212 function is used to reserve resources within a previously established region.
213 It is a simplified interface to
214 .Fn rman_reserve_resource_bound
215 which passes 0 for the
220 .Fn rman_make_alignment_flags
221 function returns the flag mask corresponding to the desired alignment
223 This should be used when calling
224 .Fn rman_reserve_resource_bound .
227 .Fn rman_release_resource
228 function releases the reserved resource
230 It may attempt to merge adjacent free resources.
233 .Fn rman_activate_resource
234 function marks a resource as active, by setting the
237 If this is a time shared resource, and the caller has not yet acquired
238 the resource, the function returns
242 .Fn rman_deactivate_resource
243 function marks a resource
245 as inactive, by clearing the
248 If other consumers are waiting for this range, it will wakeup their threads.
251 .Fn rman_await_resource
252 function performs an asynchronous wait for a resource
254 to become inactive, that is, for the
257 It is used to enable cooperative sharing of a resource
258 which can only be safely used by one thread at a time.
264 .Fn rman_await_resource
273 functions return the bounds, size and flags of the previously reserved
279 function associates a
286 function is used to retrieve this tag once set.
289 .Fn rman_set_bushandle
290 function associates a
291 .Vt bus_space_handle_t
296 .Fn rman_get_bushandle
297 function is used to retrieve this handle once set.
301 function is used to associate a kernel virtual address with a resource
305 function can be used to retrieve the KVA once set.
309 function associates a resource identifier with a resource
313 function retrieves this RID.
317 function returns a pointer to the device which reserved the resource
320 .Xr bus_activate_resource 9 ,
321 .Xr bus_alloc_resource 9 ,
322 .Xr bus_release_resource 9 ,
323 .Xr bus_set_resource 9 ,
326 This manual page was written by
327 .An Bruce M Simpson Aq bms@spc.org .