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