---
name: "bus_activate_resource"
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/bus_activate_resource"
---

# bus\_activate\_resource(9)

activate or deactivate a resource

## NAME

**bus\_activate\_resource**, **bus\_deactivate\_resource** – activate or deactivate a resource

## SYNOPSIS

**#include \<sys/param.h\>**

**#include \<sys/bus.h\>**

**#include \<machine/bus.h\>**

**#include \<sys/rman.h\>**

**#include \<machine/resource.h\>**

*int*\

**bus\_activate\_resource**(*device\_t dev*, *struct resource \*r*);

*int*\

**bus\_deactivate\_resource**(*device\_t dev*, *struct resource \*r*);

## DESCRIPTION

These functions activate or deactivate a previously allocated resource. In general, resources must be activated before they can be accessed by the driver. Bus drivers may perform additional actions to ensure that the resource is ready to be accessed. For example, the PCI bus driver enables memory decoding in a PCI device's command register when activating a memory resource.

The arguments are as follows:

- *dev*

  The device that requests ownership of the resource. Before allocation, the resource is owned by the parent bus.

- *r*

  A pointer to the *struct resource* returned by [bus\_alloc\_resource(9)](/bus_alloc_resource/9.md).

### Resource Mapping

Resources which can be mapped for CPU access by a [bus\_space(9)](/bus_space/9.md) tag and handle will create a mapping of the entire resource when activated. The tag and handle for this mapping are stored in *r* and can be retrieved via [rman\_get\_bustag(9)](/rman_get_bustag/9.md) and [rman\_get\_bushandle(9)](/rman_get_bushandle/9.md). These can be used with the [bus\_space(9)](/bus_space/9.md) API to access device registers or memory described by *r*. If the mapping is associated with a virtual address, the virtual address can be retrieved via [rman\_get\_virtual(9)](/rman_get_virtual/9.md).

This implicit mapping can be disabled by passing the RF\_UNMAPPED flag to [bus\_alloc\_resource(9)](/bus_alloc_resource/9.md). A driver may use this if it wishes to allocate its own mappings of a resource using [bus\_map\_resource(9)](/bus_map_resource/9.md).

A wrapper API for [bus\_space(9)](/bus_space/9.md) is also provided that accepts the associated resource as the first argument in place of the [bus\_space(9)](/bus_space/9.md) tag and handle. The functions in this wrapper API are named similarly to the [bus\_space(9)](/bus_space/9.md) API except that “\_space” is removed from their name. For example, **bus\_read\_4**() can be used in place of **bus\_space\_read\_4**(). The wrapper API is preferred in new drivers.

These two statements both read a 32-bit register at the start of a resource:

```
	bus_space_read_4(rman_get_bustag(res), rman_get_bushandle(res), 0);
	bus_read_4(res, 0);
```

## RETURN VALUES

Zero is returned on success, otherwise an error is returned.

## SEE ALSO

[bus\_alloc\_resource(9)](/bus_alloc_resource/9.md), [bus\_map\_resource(9)](/bus_map_resource/9.md), [bus\_space(9)](/bus_space/9.md), [device(9)](/device/9.md), [driver(9)](/driver/9.md)

## AUTHORS

This manual page was written by Warner Losh ⟨*imp@FreeBSD.org*⟩.
