xref: /freebsd/share/man/man9/bus_activate_resource.9 (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
1.\" -*- nroff -*-
2.\"
3.\" Copyright (c) 2003 M. Warner Losh <imp@FreeBSD.org>
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
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.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
15.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
18.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24.\"
25.Dd March 13, 2024
26.Dt BUS_ACTIVATE_RESOURCE 9
27.Os
28.Sh NAME
29.Nm bus_activate_resource , bus_deactivate_resource
30.Nd activate or deactivate a resource
31.Sh SYNOPSIS
32.In sys/param.h
33.In sys/bus.h
34.Pp
35.In machine/bus.h
36.In sys/rman.h
37.In machine/resource.h
38.Ft int
39.Fo bus_activate_resource
40.Fa "device_t dev" "struct resource *r"
41.Fc
42.Ft int
43.Fo bus_deactivate_resource
44.Fa "device_t dev" "struct resource *r"
45.Fc
46.Sh DESCRIPTION
47These functions activate or deactivate a previously allocated resource.
48In general, resources must be activated before they can be accessed by
49the driver.
50Bus drivers may perform additional actions to ensure that the resource is
51ready to be accessed.
52For example,
53the PCI bus driver enables memory decoding in a PCI device's command register
54when activating a memory resource.
55.Pp
56The arguments are as follows:
57.Bl -tag -width indent
58.It Fa dev
59The device that requests ownership of the resource.
60Before allocation, the resource is owned by the parent bus.
61.It Fa r
62A pointer to the
63.Vt "struct resource"
64returned by
65.Xr bus_alloc_resource 9 .
66.El
67.Ss Resource Mapping
68Resources which can be mapped for CPU access by a
69.Xr bus_space 9
70tag and handle will create a mapping of the entire resource when activated.
71The tag and handle for this mapping are stored in
72.Fa r
73and can be retrieved via
74.Xr rman_get_bustag 9
75and
76.Xr rman_get_bushandle 9 .
77These can be used with the
78.Xr bus_space 9
79API to access device registers or memory described by
80.Fa r .
81If the mapping is associated with a virtual address,
82the virtual address can be retrieved via
83.Xr rman_get_virtual 9 .
84.Pp
85This implicit mapping can be disabled by passing the
86.Dv RF_UNMAPPED
87flag to
88.Xr bus_alloc_resource 9 .
89A driver may use this if it wishes to allocate its own mappings of a resource
90using
91.Xr bus_map_resource 9 .
92.Pp
93A wrapper API for
94.Xr bus_space 9
95is also provided that accepts the associated resource as the first argument
96in place of the
97.Xr bus_space 9
98tag and handle.
99The functions in this wrapper API are named similarly to the
100.Xr bus_space 9
101API except that
102.Dq _space
103is removed from their name.
104For example,
105.Fn bus_read_4
106can be used in place of
107.Fn bus_space_read_4 .
108The wrapper API is preferred in new drivers.
109.Pp
110These two statements both read a 32-bit register at the start of a
111resource:
112.Bd -literal
113	bus_space_read_4(rman_get_bustag(res), rman_get_bushandle(res), 0);
114	bus_read_4(res, 0);
115.Ed
116.Sh RETURN VALUES
117Zero is returned on success, otherwise an error is returned.
118.Sh SEE ALSO
119.Xr bus_alloc_resource 9 ,
120.Xr bus_map_resource 9 ,
121.Xr bus_space 9 ,
122.Xr device 9 ,
123.Xr driver 9
124.Sh AUTHORS
125This manual page was written by
126.An Warner Losh Aq Mt imp@FreeBSD.org .
127