RMAN(9)
rman, rman_activate_resource, rman_adjust_resource, rman_deactivate_resource, rman_fini, rman_init, rman_init_from_resource, rman_is_region_manager, rman_manage_region, rman_first_free_region, rman_last_free_region, rman_release_resource, rman_reserve_resource, rman_reserve_resource_bound, rman_make_alignment_flags, rman_get_start, rman_get_end, rman_get_device, rman_get_size, rman_get_flags, rman_set_mapping, rman_get_mapping, rman_set_virtual, rman_get_virtual, rman_set_bustag, rman_get_bustag, rman_set_bushandle, rman_get_bushandle, rman_set_rid, rman_get_rid β resource management functions π
okay bestie, gather round, this is the rman page from the Kernel Developer's Manual β section 9, kernel-land, no userland vibes here β¨
πΈ NAME πΈ
rman, rman_activate_resource, rman_adjust_resource, rman_deactivate_resource, rman_fini, rman_init, rman_init_from_resource, rman_is_region_manager, rman_manage_region, rman_first_free_region, rman_last_free_region, rman_release_resource, rman_reserve_resource, rman_reserve_resource_bound, rman_make_alignment_flags, rman_get_start, rman_get_end, rman_get_device, rman_get_size, rman_get_flags, rman_set_mapping, rman_get_mapping, rman_set_virtual, rman_get_virtual, rman_set_bustag, rman_get_bustag, rman_set_bushandle, rman_get_bushandle, rman_set_rid, rman_get_rid β resource management functions π
β¨ SYNOPSIS β¨
like, this is the whole squad, here's how you call them π«Ά
#include <sys/types.h>
#include <sys/rman.h>
int
rman_activate_resource(struct resource *r);
int
rman_adjust_resource(struct resource *r, rman_res_t start,
rman_res_t end);
int
rman_deactivate_resource(struct resource *r);
int
rman_fini(struct rman *rm);
int
rman_init(struct rman *rm);
int
rman_init_from_resource(struct rman *rm, struct resource *r);
int
rman_is_region_manager(struct resource *r, struct rman *rm);
int
rman_manage_region(struct rman *rm, rman_res_t start, rman_res_t end);
int
rman_first_free_region(struct rman *rm, rman_res_t *start,
rman_res_t *end);
int
rman_last_free_region(struct rman *rm, rman_res_t *start,
rman_res_t *end);
int
rman_release_resource(struct resource *r);
struct resource *
rman_reserve_resource(struct rman *rm, rman_res_t start, rman_res_t end,
rman_res_t count, u_int flags, struct device *dev);
struct resource *
rman_reserve_resource_bound(struct rman *rm, rman_res_t start,
rman_res_t end, rman_res_t count, rman_res_t bound, u_int flags,
struct device *dev);
uint32_t
rman_make_alignment_flags(uint32_t size);
rman_res_t
rman_get_start(struct resource *r);
rman_res_t
rman_get_end(struct resource *r);
struct device *
rman_get_device(struct resource *r);
rman_res_t
rman_get_size(struct resource *r);
u_int
rman_get_flags(struct resource *r);
void
rman_set_mapping(struct resource *r, struct resource_map *map);
void
rman_get_mapping(struct resource *r, struct resource_map *map);
void
rman_set_virtual(struct resource *r, void *v);
void *
rman_get_virtual(struct resource *r);
void
rman_set_bustag(struct resource *r, bus_space_tag_t t);
bus_space_tag_t
rman_get_bustag(struct resource *r);
void
rman_set_bushandle(struct resource *r, bus_space_handle_t h);
bus_space_handle_t
rman_get_bushandle(struct resource *r);
void
rman_set_rid(struct resource *r, int rid);
int
rman_get_rid(struct resource *r);
π DESCRIPTION π
so the rman fam of functions is literally a whole flexible resource management abstraction. the bus management code uses it constantly, it's giving main character energy in there. it implements two big concepts: region and resource. a region descriptor is what you use to manage a region β and a region could be memory, or some other form of bus space, whatever, it's flexible like that π
every region has a set of bounds. and within those bounds, allocated segments can live. each segment, which we call a resource, has a bunch of properties, and those properties are stored in a 16-bit flag register, like so:
#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 */
#define RF_UNMAPPED 0x0100 /* don't map resource when activating */
and bits 15:10 of that flag register? those are used to represent the desired alignment of the resource within the region. no cap π
π¦ the init and fini girlies π¦
the rman_init() function initializes the region descriptor that rm points to, so it's ready to hang out with the resource management functions. important: you must set the fields rm_type and rm_descr of struct rman before you call rman_init(). like, required required.
- the field
rm_typeshall be set toRMAN_ARRAY - the field
rm_descrshall be set to a string that describes the resource to be managed - the
rm_startandrm_endfields may be set to limit the range of acceptable resource addresses. if you don't set them,rman_init()will initialize them to allow the entire range of resource addresses π
it also initializes any mutexes associated with the structure. if rman_init() fails to initialize the mutex, it returns ENOMEM; otherwise it returns 0 and rm is initialized. slay.
the rman_fini() function frees any structures associated with the structure that rm points to. if any of the resources within the managed region have the RF_ALLOCATED flag set, it returns EBUSY π€ β otherwise, any mutexes associated with the structure get released and destroyed, and the function returns 0.
πΈ managing regions πΈ
the rman_manage_region() function establishes the whole concept of a region that's under rman control. the rman argument points to the region descriptor, and the start and end arguments specify the bounds of the region.
- if it's successful,
rman_manage_region()returns0 - if the region overlaps with an existing region, it returns
EBUSY - if any part of the region falls outside the valid address range for
rm, it returnsEINVAL ENOMEMgets returned whenrman_manage_region()fails to allocate memory for the region
the rman_init_from_resource() function is a lil wrapper routine that creates a resource manager backed by an existing resource. it initializes rm using rman_init() and then adds a region to rm corresponding to the address range allocated to r via rman_manage_region(). cute, efficient, obsessed π
the rman_first_free_region() and rman_last_free_region() functions let you query a resource manager for its first (or last) unallocated region. if rm contains no free region, these functions return ENOENT. otherwise, *start and *end get set to the bounds of the free region, and zero is returned β¨
π₯ reserving resources π₯
the rman_reserve_resource_bound() function is where the bulk of the rman logic lives. like, this is the whole personality right here. it attempts to reserve a contiguous range in the specified region rm for the use of the device dev.
the caller can specify the start and end of an acceptable range, plus a boundary restriction and the required alignment, and the code will try to find a free segment that fits.
- the
startargument is the lowest acceptable starting value of the resource - the
endargument is the highest acceptable ending value of the resource
sostart + count - 1must be β€endfor any allocation to happen. math said so, periodt π
- the alignment requirement (if there is one) is specified in
flags - the
boundargument may be set to specify a boundary restriction such that an allocated region may cross an address that is a multiple of the boundary. theboundargument must be a power of two. it may be set to0to specify no boundary restriction - a shared segment will be allocated if the
RF_SHAREABLEflag is set, otherwise an exclusive segment gets allocated. if this shared segment already exists, the caller has its device added to the list of consumers π
the rman_reserve_resource() function is used to reserve resources within a previously established region. it's just a simplified interface to rman_reserve_resource_bound() that passes 0 for the bound argument. easy π
the rman_make_alignment_flags() function returns the flag mask corresponding to the desired alignment size. use this when you're calling rman_reserve_resource_bound(), bestie.
the rman_is_region_manager() function returns true if the allocated resource r was allocated from rm. otherwise it returns false. simple as π¦
π adjusting, releasing, activating π
the rman_adjust_resource() function adjusts the reserved address range of an allocated resource to reserve start through end. it can be used to grow or shrink one or both ends of the resource range.
ngl there are some real limits here. the current implementation does not support entirely relocating the resource, and it will fail withEINVALif 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 fails withEBUSY. andrman_adjust_resource()does not support adjusting the resource range for shared resources β those attempts fail withEINVAL.
upon success, the resource r will have a start address of start and an end address of end, and the function returns zero.
β οΈ also important: none of the constraints of the original allocation request β like alignment or boundary restrictions β are checked by rman_adjust_resource(). it is the caller's responsibility to enforce any such requirements. you're the main character here, act like it π
the rman_release_resource() function releases the reserved resource r. it may attempt to merge adjacent free resources. tidy π§
the rman_activate_resource() function marks a resource as active by setting the RF_ACTIVE flag. if this is a time shared resource, and the caller has not yet acquired the resource, the function returns EBUSY.
the rman_deactivate_resource() function marks a resource r as inactive by clearing the RF_ACTIVE flag. if other consumers are waiting for this range, it will wakeup their threads. so polite πΈ
π getters and setters π
the rman_get_start(), rman_get_end(), rman_get_size(), and rman_get_flags() functions return the bounds, size and flags of the previously reserved resource r.
the rman_set_bustag() function associates a bus_space_tag_t t with the resource r. the rman_get_bustag() function is used to retrieve this tag once it's set.
the rman_set_bushandle() function associates a bus_space_handle_t h with the resource r. the rman_get_bushandle() function is used to retrieve this handle once it's set.
the rman_set_virtual() function is used to associate a kernel virtual address with a resource r. the rman_get_virtual() function can be used to retrieve the KVA once it's set.
the rman_set_mapping() function is used to associate a resource mapping with a resource r.
the mapping must cover the entire resource, no partial vibes allowed π
setting a mapping sets the associated bus_space(9) handle and tag for r as well as the kernel virtual address if the mapping contains one. these individual values can be retrieved via rman_get_bushandle(), rman_get_bustag(), and rman_get_virtual().
the rman_get_mapping() function can be used to retrieve the associated resource mapping once it's set.
the rman_set_rid() function associates a resource identifier with a resource r. the rman_get_rid() function retrieves this RID.
the rman_get_device() function returns a pointer to the device which reserved the resource r. iconic β
π SEE ALSO π
bus_activate_resource(9)bus_adjust_resource(9)bus_alloc_resource(9)bus_map_resource(9)bus_release_resource(9)bus_set_resource(9)bus_space(9)mutex(9)
β¨ AUTHORS β¨
This manual page was written by Bruce M Simpson <bms@spc.org> π
bestie wrote the whole thing fr fr, give them their flowers πΈ
okay that's literally the whole page π this lil beauty comes to you from the Debian crew, dated May 20, 2016 β so if you're reading this, go forth and slay your kernel modules, mwah π«Άβ¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2003 Bruce M Simpson <bms@spc.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms