set of functions provides a flexible resource management abstraction.
It is used extensively by the bus management code.
It implements the abstractions of region and resource.
A region descriptor is used to manage a region; this could be memory or
some other form of bus space.
Each region has a set of bounds.
Within these bounds, allocated segments may reside.
Each segment, termed a resource, has several properties which are
represented by a 16-bit flag register, as follows.
#define RF_ALLOCATED 0x0001 /* resource has been reserved */
#define RF_ACTIVE 0x0002 /* resource allocation has been activated */
#define RF_SHAREABLE 0x0004 /* resource permits contemporaneous sharing */
#define RF_FIRSTSHARE 0x0020 /* first in sharing list */
#define RF_PREFETCHABLE 0x0040 /* resource is prefetchable */
Bits 15:10 of the flag register are used to represent the desired alignment
of the resource within the region.
function initializes the region descriptor, pointed to by the
argument, for use with the resource management functions.
It is required that the fields
.Vt struct rman
be set before calling
shall be set to
shall be set to a string that describes the resource to be managed.
fields may be set to limit the range of acceptable resource addresses.
If these fields are not set,
will initialize them to allow the entire range of resource addresses.
It also initializes any mutexes associated with the structure.
fails to initialize the mutex, it will return
ENOMEM; otherwise it will return 0 and
will be initialized.
function frees any structures associated with the structure
pointed to by the
If any of the resources within the managed region have the
flag set, it will return
otherwise, any mutexes associated with the structure will be released
and destroyed, and the function will return 0.
function establishes the concept of a region which is under
argument points to the region descriptor.
arguments specify the bounds of the region.
will return 0.
If the region overlaps with an existing region, it will return
If any part of the region falls outside of the valid address range for
it will return
will be returned when
failed to allocate memory for the region.
function is a wrapper routine to create a resource manager backed by an
and then adds a region to
corresponding to the address range allocated to
functions can be used to query a resource manager for its first
contains no free region,
these functions will return
are set to the bounds of the free region and zero is returned.
function is where the bulk of the
logic is located.
It attempts to reserve a contiguous range in the specified region
for the use of the device
The caller can specify the
of an acceptable range,
as well as a boundary restriction and required aligment,
and the code will attempt to find a free segment which fits.
argument is the lowest acceptable starting value of the resource.
argument is the highest acceptable ending value of the resource.
start + count - 1
must be [<=]
for any allocation to happen.
The aligment requirement
is specified in
argument may be set to specify a boundary restriction such that an
allocated region may cross an address that is a multiple of the
argument must be a power of two.
It may be set to zero to specify no boundary restriction.
A shared segment will be allocated if the
flag is set, otherwise an exclusive segment will be allocated.
If this shared segment already exists, the caller has its device
added to the list of consumers.
function is used to reserve resources within a previously established region.
It is a simplified interface to
which passes 0 for the
function returns the flag mask corresponding to the desired alignment
This should be used when calling
function returns true if the allocated resource
was allocated from
it returns false.
function is used to adjust the reserved address range of an allocated resource
It can be used to grow or shrink one or both ends of the resource range.
The current implementation does not support entirely relocating the resource
and will fail with
if the new resource range does not overlap the old resource range.
If either end of the resource range grows and the new resource range would
conflict with another allocated resource,
the function will fail with
function does not support adjusting the resource range for shared resources
and will fail such attempts with
will have a start address of
and an end address of
and the function will return zero.
Note that none of the constraints of the original allocation request such
as alignment or boundary restrictions are checked by
It is the callers responsibility to enforce any such requirements.
function releases the reserved resource
It may attempt to merge adjacent free resources.
function marks a resource as active, by setting the
If this is a time shared resource, and the caller has not yet acquired
the resource, the function returns
function marks a resource
as inactive, by clearing the
If other consumers are waiting for this range, it will wakeup their threads.
function performs an asynchronous wait for a resource
to become inactive, that is, for the
flag to be cleared.
It is used to enable cooperative sharing of a resource
which can only be safely used by one thread at a time.
are passed to the
functions return the bounds, size and flags of the previously reserved
function associates a
with the resource
function is used to retrieve this tag once set.
function associates a
with the resource
function is used to retrieve this handle once set.
function is used to associate a kernel virtual address with a resource
function can be used to retrieve the KVA once set.
function associates a resource identifier with a resource
function retrieves this RID.
function returns a pointer to the device which reserved the resource