]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man9/bus_alloc_resource.9
accept_filter(9): Fix a mandoc related error
[FreeBSD/FreeBSD.git] / share / man / man9 / bus_alloc_resource.9
1 .\" -*- nroff -*-
2 .\"
3 .\" Copyright (c) 2000 Alexander Langer
4 .\"
5 .\" All rights reserved.
6 .\"
7 .\" This program is free software.
8 .\"
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
11 .\" are met:
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\"    notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\"    notice, this list of conditions and the following disclaimer in the
16 .\"    documentation and/or other materials provided with the distribution.
17 .\"
18 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
19 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 .\"
29 .\" $FreeBSD$
30 .\"
31 .Dd May 20, 2016
32 .Dt BUS_ALLOC_RESOURCE 9
33 .Os
34 .Sh NAME
35 .Nm bus_alloc_resource ,
36 .Nm bus_alloc_resource_any ,
37 .Nm bus_alloc_resource_anywhere
38 .Nd allocate resources from a parent bus
39 .Sh SYNOPSIS
40 .In sys/param.h
41 .In sys/bus.h
42 .Pp
43 .In machine/bus.h
44 .In sys/rman.h
45 .In machine/resource.h
46 .Ft struct resource *
47 .Fo bus_alloc_resource
48 .Fa "device_t dev" "int type" "int *rid" "rman_res_t start" "rman_res_t end"
49 .Fa "rman_res_t count" "u_int flags"
50 .Fc
51 .Ft struct resource *
52 .Fn bus_alloc_resource_any "device_t dev" "int type" "int *rid" "u_int flags"
53 .Ft struct resource *
54 .Fo bus_alloc_resource_anywhere
55 .Fa "device_t dev" "int type" "int *rid" "rman_res_t count" "u_int flags"
56 .Fc
57 .Sh DESCRIPTION
58 This is an easy interface to the resource-management functions.
59 It hides the indirection through the parent's method table.
60 This function generally should be called in attach, but (except in some
61 rare cases) never earlier.
62 .Pp
63 The
64 .Fn bus_alloc_resource_any
65 and
66 .Fn bus_alloc_resource_anywhere
67 functions are convenience wrappers for
68 .Fn bus_alloc_resource .
69 .Fn bus_alloc_resource_any
70 sets
71 .Fa start ,
72 .Fa end ,
73 and
74 .Fa count
75 to the default resource (see description of
76 .Fa start
77 below).
78 .Fn bus_alloc_resource_anywhere
79 sets
80 .Fa start
81 and
82 .Fa end
83 to the default resource and uses the provided
84 .Fa count
85 argument.
86 .Pp
87 The arguments are as follows:
88 .Bl -item
89 .It
90 .Fa dev
91 is the device that requests ownership of the resource.
92 Before allocation, the resource is owned by the parent bus.
93 .It
94 .Fa type
95 is the type of resource you want to allocate.
96 It is one of:
97 .Bl -tag -width SYS_RES_MEMORY
98 .It Dv PCI_RES_BUS
99 for PCI bus numbers
100 .It Dv SYS_RES_IRQ
101 for IRQs
102 .It Dv SYS_RES_DRQ
103 for ISA DMA lines
104 .It Dv SYS_RES_IOPORT
105 for I/O ports
106 .It Dv SYS_RES_MEMORY
107 for I/O memory
108 .El
109 .It
110 .Fa rid
111 points to a bus specific handle that identifies the resource being allocated.
112 For ISA this is an index into an array of resources that have been setup
113 for this device by either the PnP mechanism, or via the hints mechanism.
114 For PCCARD, this is an index into the array of resources described by the PC Card's
115 CIS entry.
116 For PCI, the offset into PCI config space which has the BAR to use to access
117 the resource.
118 The bus methods are free to change the RIDs that they are given as a parameter.
119 You must not depend on the value you gave it earlier.
120 .It
121 .Fa start
122 and
123 .Fa end
124 are the start/end addresses of the resource.
125 If you specify values of 0ul for
126 .Fa start
127 and ~0ul for
128 .Fa end
129 and 1 for
130 .Fa count ,
131 the default values for the bus are calculated.
132 .It
133 .Fa count
134 is the size of the resource.
135 For example, the size of an I/O port is usually 1 byte (but some devices
136 override this).
137 If you specified the default values for
138 .Fa start
139 and
140 .Fa end ,
141 then the default value of the bus is used if
142 .Fa count
143 is smaller than the default value and
144 .Fa count
145 is used, if it is bigger than the default value.
146 .It
147 .Fa flags
148 sets the flags for the resource.
149 You can set one or more of these flags:
150 .Bl -tag -width RF_SHAREABLE
151 .It Dv RF_ALLOCATED
152 resource has been reserved.
153 The resource still needs to be activated with
154 .Xr bus_activate_resource 9 .
155 .It Dv RF_ACTIVE
156 activate resource atomically.
157 .It Dv RF_PREFETCHABLE
158 resource is prefetchable.
159 .It Dv RF_SHAREABLE
160 resource permits contemporaneous sharing.
161 It should always be set unless you know that the resource cannot be shared.
162 It is the bus driver's task to filter out the flag if the bus does not
163 support sharing.
164 For example,
165 .Xr pccard 4
166 cannot share IRQs while
167 .Xr cardbus 4
168 can.
169 .It Dv RF_UNMAPPED
170 do not establish implicit mapping when activated via
171 .Xr bus_activate_resource 9 .
172 .El
173 .El
174 .Sh RETURN VALUES
175 A pointer to
176 .Va struct resource
177 is returned on success, a null pointer otherwise.
178 .Sh EXAMPLES
179 This is some example code that allocates a 32 byte I/O port range and an IRQ.
180 The values of
181 .Va portid
182 and
183 .Va irqid
184 should be saved in the softc of the device after these calls.
185 .Bd -literal
186         struct resource *portres, *irqres;
187         int portid, irqid;
188
189         portid = 0;
190         irqid = 0;
191         portres = bus_alloc_resource(dev, SYS_RES_IOPORT, &portid,
192                         0ul, ~0ul, 32, RF_ACTIVE);
193         irqres = bus_alloc_resource_any(dev, SYS_RES_IRQ, &irqid,
194                         RF_ACTIVE | RF_SHAREABLE);
195 .Ed
196 .Sh SEE ALSO
197 .Xr bus_activate_resource 9 ,
198 .Xr bus_adjust_resource 9 ,
199 .Xr bus_map_resource 9 ,
200 .Xr bus_release_resource 9 ,
201 .Xr device 9 ,
202 .Xr driver 9
203 .Sh AUTHORS
204 .An -nosplit
205 This manual page was written by
206 .An Alexander Langer Aq Mt alex@big.endian.de
207 with parts by
208 .An Warner Losh Aq Mt imp@FreeBSD.org .