xref: /freebsd/share/man/man9/bus_alloc_resource.9 (revision 729362425c09cf6b362366aabc6fb547eee8035a)
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 18, 2000
32.Dt BUS_ALLOC_RESOURCE 9
33.Os
34.Sh NAME
35.Nm bus_alloc_resource
36.Nd alloc resources on a bus
37.Sh SYNOPSIS
38.In sys/param.h
39.In sys/bus.h
40.Pp
41.In machine/bus.h
42.In sys/rman.h
43.In machine/resource.h
44.Ft struct resource *
45.Fn bus_alloc_resource "device_t dev" "int type" "int *rid" "u_long start" "u_long end" "u_long count" "u_int flags"
46.Sh DESCRIPTION
47This is an easy interface to the resource-management functions.
48It hides the indirection through the parent's method table.
49This function generally should be called in attach, but (except in some
50rare cases) never earlier.
51.Pp
52Its arguments are as follows:
53.Bl -item
54.It
55.Fa dev
56is the device that requests ownership of the resource.
57Before allocation, the resource is owned by the parent bus.
58.It
59.Fa type
60is the type of resource you want to allocate.
61It is one of:
62.Bl -tag -width SYS_RES_MEMORY
63.It Dv SYS_RES_IRQ
64for IRQs
65.It Dv SYS_RES_DRQ
66for ISA DMA lines
67.It Dv SYS_RES_IOPORT
68for I/O ports
69.It Dv SYS_RES_MEMORY
70for I/O memory
71.El
72.It
73.Fa rid
74points to a bus specific handle that identifies the resource being allocated.
75For ISA this is an index into an array of resources that have been setup
76for this device by either the PnP mechanism, or via the hints mechanism.
77For PCCARD, similar things are used as of writing,
78but that may change in the future with newcard.
79For PCI it just happens to be the offset into pci config space which has
80a word that describes the resource.
81The bus methods are free to change the RIDs that they are given as a parameter.
82You must not depend on the value you gave it earlier.
83.It
84.Fa start
85and
86.Fa end
87are the start/end addresses of the resource.
88If you specify values of
89.Dv 0
90for
91.Fa start
92and
93.Dv ~0
94for
95.Fa end
96and
97.Dv 1
98for
99.Fa count ,
100the default values for the bus are calculated.
101.It
102.Fa count
103is the size of the resource, e.g. the size of an I/O port (often
104.Dv 1, but some devices override this).
105If you specified the default values for
106.Fa start
107and
108.Fa end ,
109then the default value of the bus is used if
110.Fa count
111is smaller than the default value and
112.Fa count
113is used, if it is bigger as the default value.
114.It
115.Fa flags
116sets the flags for the resource.
117You can set one or more of these flags:
118.Bl -tag -width RF_SHAREABLE
119.It Dv RF_ALLOCATED
120resource has been reserved.
121The resource still needs to be activated with
122.Xr bus_activate_resource 9 .
123.It Dv RF_ACTIVE
124activate resource atomically.
125.It Dv RF_SHAREABLE
126resource permits contemporaneous sharing.
127Should always be set unless you know, that the resource cannot be shared.
128It is the bus-code's task to filter out the flag if the bus doesn't
129support sharing, which is, for example, the case for pccard/cardbus,
130which can or cannot share devices, depending on the bus.
131.It Dv RF_TIMESHARE
132resource permits time-division sharing.
133.El
134.El
135.Sh RETURN VALUES
136A pointer to
137.Va struct res
138is returned on success, a null pointer otherwise.
139.Sh EXAMPLES
140This is some example code.
141The values of
142.Va portid
143and
144.Va irqid
145should be saved in the softc of the device after these calls.
146.Bd -literal
147	struct resource *portres, irqres;
148	int portid, irqid;
149
150	portid = 0;
151	irqid = 0;
152	portres = bus_alloc_resource(dev, SYS_RES_IOPORT, &portid,
153			0ul, ~0ul, 32, RF_ACTIVE);
154	irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &irqid,
155			0ul, ~0ul, 1, RF_ACTIVE | RF_SHAREABLE);
156.Ed
157.Sh SEE ALSO
158.Xr bus_activate_resource 9 ,
159.Xr bus_release_resource 9 ,
160.Xr device 9 ,
161.Xr driver 9
162.Sh AUTHORS
163.An -nosplit
164This man page was written by
165.An Alexander Langer Aq alex@big.endian.de
166with parts by
167.An Warner Losh Aq imp@FreeBSD.org .
168