---
name: "rman"
section: "9"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/rman/9"
---

# rman(9)

resource management functions

## 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\_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**, **rman\_set\_type**, **rman\_get\_type** – resource management functions

## SYNOPSIS

**#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*, *device\_t 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*);

*device\_t*\

**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*);

*void*\

**rman\_set\_type**(*struct resource \*r*, *int type*);

*int*\

**rman\_get\_type**(*struct resource \*r*);

## DESCRIPTION

The **rman** 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 */
#define RF_UNMAPPED     0x0100 /* don't map resource when activating */
```

Bits 15:10  of the flag register are used to represent the desired alignment of the resource within the region.

The **rman\_init**() function initializes the region descriptor, pointed to by the *rm* argument, for use with the resource management functions. It is required that the fields *rm\_type* and *rm\_descr* of *struct rman* be set before calling **rman\_init**(). The field *rm\_type* shall be set to RMAN\_ARRAY. The field *rm\_descr* shall be set to a string that describes the resource to be managed. The *rm\_start* and *rm\_end* fields may be set to limit the range of acceptable resource addresses. If these fields are not set, **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 will return ENOMEM; otherwise it will return 0 and *rm* will be initialized.

The **rman\_fini**() function frees any structures associated with the structure pointed to by the *rm* argument. If any of the resources within the managed region have the RF\_ALLOCATED flag set, it will return EBUSY; otherwise, any mutexes associated with the structure will be released and destroyed, and the function will return 0.

The **rman\_manage\_region**() function establishes the concept of a region which is under **rman** control. The *rman* argument points to the region descriptor. The *start* and *end* arguments specify the bounds of the region. If successful, **rman\_manage\_region**() will return 0. If the region overlaps with an existing region, it will return EBUSY. If any part of the region falls outside of the valid address range for *rm*, it will return EINVAL. ENOMEM will be returned when **rman\_manage\_region**() failed to allocate memory for the region.

The **rman\_init\_from\_resource**() function is a wrapper routine to create 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**().

The **rman\_first\_free\_region**() and **rman\_last\_free\_region**() functions can be used to query a resource manager for its first (or last) unallocated region. If *rm* contains no free region, these functions will return ENOENT. Otherwise, *\*start* and *\*end* are set to the bounds of the free region and zero is returned.

The **rman\_reserve\_resource**() function is where the bulk of the **rman** logic is located. 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, required alignment, and the code will attempt to find a free segment which fits. The *start* argument is the lowest acceptable starting value of the resource. The *end* argument is the highest acceptable ending value of the resource. Therefore, *start* + *count* - 1 must be ≤ *end* for any allocation to happen. The alignment requirement (if any) is specified in *flags*. Often the RF\_ALIGNMENT\_LOG2 macro is used to specify alignment to a power-of-2 size, or **rman\_make\_alignment\_flags**() can be used to compute the *flags* value at runtime. A shared segment will be allocated if the RF\_SHAREABLE 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.

The **rman\_make\_alignment\_flags**() function returns the flag mask corresponding to the desired alignment *size*. This should be used when calling **rman\_reserve\_resource\_bound**().

The **rman\_is\_region\_manager**() function returns true if the allocated resource *r* was allocated from *rm*. Otherwise, it returns false.

The **rman\_adjust\_resource**() function is used to adjust 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. The current implementation does not support entirely relocating the resource and will fail with EINVAL 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 EBUSY. The **rman\_adjust\_resource**() function does not support adjusting the resource range for shared resources and will fail such attempts with EINVAL. Upon success, the resource *r* will have a start address of *start* and an end address of *end* 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 **rman\_adjust\_resource**(). It is the caller's responsibility to enforce any such requirements.

The **rman\_release\_resource**() function releases the reserved resource *r*. It may attempt to merge adjacent free resources.

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.

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 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 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 set.

The **rman\_set\_mapping**() function is used to associate a resource mapping with a resource *r*. The mapping must cover the entire resource. Setting a mapping sets the associated [bus\_space(9)](/bus_space/9.md) 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 set.

The **rman\_set\_rid**() function associates a resource identifier with a resource *r*. The **rman\_get\_rid**() function retrieves this RID.

The **rman\_set\_type**() function associates a resource type with a resource *r*. The **rman\_get\_type**() function retrieves this type.

The **rman\_get\_device**() function returns a pointer to the device which reserved the resource *r*.

## SEE ALSO

[bus\_activate\_resource(9)](/bus_activate_resource/9.md), [bus\_adjust\_resource(9)](/bus_adjust_resource/9.md), [bus\_alloc\_resource(9)](/bus_alloc_resource/9.md), [bus\_map\_resource(9)](/bus_map_resource/9.md), [bus\_release\_resource(9)](/bus_release_resource/9.md), [bus\_set\_resource(9)](/bus_set_resource/9.md), [bus\_space(9)](/bus_space/9.md), [mutex(9)](/mutex/9.md)

## AUTHORS

This manual page was written by Bruce M Simpson ⟨*bms@spc.org*⟩.
