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 May 20, 2016
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" "int type" "int rid" "struct resource *r"
41.Fc
42.Ft int
43.Fo bus_deactivate_resource
44.Fa "device_t dev" "int type" "int rid" "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 type
62The type of resource you want to allocate.
63It is one of:
64.Pp
65.Bl -tag -width ".Dv SYS_RES_MEMORY" -compact
66.It Dv PCI_RES_BUS
67for PCI bus numbers
68.It Dv SYS_RES_IRQ
69for IRQs
70.It Dv SYS_RES_DRQ
71for ISA DMA lines
72.It Dv SYS_RES_IOPORT
73for I/O ports
74.It Dv SYS_RES_MEMORY
75for I/O memory
76.El
77.It Fa rid
78A pointer to a bus specific handle that identifies the resource being allocated.
79.It Fa r
80A pointer to the
81.Vt "struct resource"
82returned by
83.Xr bus_alloc_resource 9 .
84.El
85.Ss Resource Mapping
86Resources which can be mapped for CPU access by a
87.Xr bus_space 9
88tag and handle will create a mapping of the entire resource when activated.
89The tag and handle for this mapping are stored in
90.Fa r
91and can be retrieved via
92.Xr rman_get_bustag 9
93and
94.Xr rman_get_bushandle 9 .
95These can be used with the
96.Xr bus_space 9
97API to access device registers or memory described by
98.Fa r .
99If the mapping is associated with a virtual address,
100the virtual address can be retrieved via
101.Xr rman_get_virtual 9 .
102.Pp
103This implicit mapping can be disabled by passing the
104.Dv RF_UNMAPPED
105flag to
106.Xr bus_alloc_resource 9 .
107A driver may use this if it wishes to allocate its own mappings of a resource
108using
109.Xr bus_map_resource 9 .
110.Pp
111A wrapper API for
112.Xr bus_space 9
113is also provided that accepts the associated resource as the first argument
114in place of the
115.Xr bus_space 9
116tag and handle.
117The functions in this wrapper API are named similarly to the
118.Xr bus_space 9
119API except that
120.Dq _space
121is removed from their name.
122For example,
123.Fn bus_read_4
124can be used in place of
125.Fn bus_space_read_4 .
126The wrapper API is preferred in new drivers.
127.Pp
128These two statements both read a 32-bit register at the start of a
129resource:
130.Bd -literal
131	bus_space_read_4(rman_get_bustag(res), rman_get_bushandle(res), 0);
132	bus_read_4(res, 0);
133.Ed
134.Sh RETURN VALUES
135Zero is returned on success, otherwise an error is returned.
136.Sh SEE ALSO
137.Xr bus_alloc_resource 9 ,
138.Xr bus_map_resource 9 ,
139.Xr bus_space 9 ,
140.Xr device 9 ,
141.Xr driver 9
142.Sh AUTHORS
143This manual page was written by
144.An Warner Losh Aq Mt imp@FreeBSD.org .
145