Merge branch 'vendor/DIFFUTILS'
[dragonfly.git] / sys / kern / bus_if.m
1 #
2 # Copyright (c) 1998 Doug Rabson
3 # All rights reserved.
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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 # SUCH DAMAGE.
25 #
26 # $FreeBSD: src/sys/kern/bus_if.m,v 1.16 1999/10/12 21:35:50 dfr Exp $
27 # $DragonFly: src/sys/kern/bus_if.m,v 1.11 2006/10/25 20:56:02 dillon Exp $
28 #
29
30 #include <sys/bus.h>
31
32 INTERFACE bus;
33
34 #
35 # Default implementations of some methods.
36 #
37 CODE {
38         static struct resource *
39         null_alloc_resource(device_t dev, device_t child,
40                             int type, int *rid,
41                             u_long start, u_long end,
42                             u_long count, u_int flags, int cpuid)
43         {
44             return 0;
45         }
46 };
47
48 #
49 # This is called from system code which prints out a description of a
50 # device.  It should describe the attachment that the child has with
51 # the parent.  See bus_generic_print_child.9 for more information.
52 # This method returns the number of characters output.
53 #
54 METHOD int print_child {
55         device_t dev;
56         device_t child;
57 } DEFAULT bus_generic_print_child;
58
59
60 # Called for each child device that 
61 # did not succeed in probing for a
62 # driver.
63 #    
64 METHOD void probe_nomatch {
65         device_t dev;
66         device_t child;
67 };
68
69 #
70 # These two methods manage a bus specific set of instance variables of
71 # a child device.  The intention is that each different type of bus
72 # defines a set of appropriate instance variables (such as ports and
73 # irqs for ISA bus etc.)
74 #
75 # This information could be given to the child device as a struct but
76 # that makes it hard for a bus to add or remove variables without
77 # forcing an edit and recompile for all drivers which may not be
78 # possible for vendor supplied binary drivers.
79
80 #
81 # Read an instance variable.  Return 0 on success.
82 #
83 METHOD int read_ivar {
84         device_t dev;
85         device_t child;
86         int index;
87         uintptr_t *result;
88 };
89
90 #
91 # Write an instance variable.  Return 0 on success.
92 #
93 METHOD int write_ivar {
94         device_t dev;
95         device_t child;
96         int index;
97         uintptr_t value;
98 };
99
100 #
101 # Called after the child's DEVICE_DETACH method to allow the parent
102 # to reclaim any resources allocated on behalf of the child.
103 #
104 METHOD void child_detached {
105         device_t dev;
106         device_t child;
107 };
108
109 #
110 # Called when a new driver is added to the devclass which owns this
111 # bus. The generic implementation of this method attempts to probe and
112 # attach any un-matched children of the bus.
113 #
114 METHOD void driver_added {
115         device_t dev;
116         driver_t *driver;
117 } DEFAULT bus_generic_driver_added;
118
119 #
120 # For busses which use drivers supporting DEVICE_IDENTIFY to
121 # enumerate their devices, these methods are used to create new
122 # device instances. If place is non-NULL, the new device will be
123 # added after the last existing child with the same order.
124 #
125 # bus is an entity which may iterate up through the bus heirarchy
126 # while parent is the parent device under which the child should be
127 # added.
128 #
129 METHOD device_t add_child {
130         device_t bus;
131         device_t parent;
132         int order;
133         const char *name;
134         int unit;
135 };
136
137 #
138 # Allocate a system resource attached to `dev' on behalf of `child'.
139 # The types are defined in <sys/bus_resource.h>; the meaning of the
140 # resource-ID field varies from bus to bus (but *rid == 0 is always
141 # valid if the resource type is).  start and end reflect the allowable
142 # range, and should be passed as `0UL' and `~0UL', respectively, if
143 # the client has no range restriction.  count is the number of consecutive
144 # indices in the resource required.  flags is a set of sharing flags
145 # as defined in <sys/rman.h>.
146 #
147 # Returns a resource or a null pointer on failure.  The caller is
148 # responsible for calling rman_activate_resource() when it actually
149 # uses the resource.
150 #
151 METHOD struct resource * alloc_resource {
152         device_t        dev;
153         device_t        child;
154         int             type;
155         int            *rid;
156         u_long          start;
157         u_long          end;
158         u_long          count;
159         u_int           flags;
160         int             cpuid;
161 } DEFAULT null_alloc_resource;
162
163 METHOD int activate_resource {
164         device_t        dev;
165         device_t        child;
166         int             type;
167         int             rid;
168         struct resource *r;
169 };
170
171 METHOD int deactivate_resource {
172         device_t        dev;
173         device_t        child;
174         int             type;
175         int             rid;
176         struct resource *r;
177 };
178
179 #
180 # Free a resource allocated by the preceding method.  The `rid' value
181 # must be the same as the one returned by BUS_ALLOC_RESOURCE (which
182 # is not necessarily the same as the one the client passed).
183 #
184 METHOD int release_resource {
185         device_t        dev;
186         device_t        child;
187         int             type;
188         int             rid;
189         struct resource *res;
190 };
191
192 METHOD int setup_intr {
193         device_t        dev;
194         device_t        child;
195         struct resource *irq;
196         int             flags;
197         driver_intr_t   *intr;
198         void            *arg;
199         void            **cookiep;
200         lwkt_serialize_t serializer;
201         const char      *desc;
202 };
203
204 METHOD int teardown_intr {
205         device_t        dev;
206         device_t        child;
207         struct resource *irq;
208         void            *cookie;
209 };
210
211 # Enable or disable an interrupt.  The device is generally expected to do
212 # the physical enablement and disablement.  The bus code must flag the
213 # condition so it does not call the handler from a scheduled interrupt thread,
214 # since the hard interrupt might be disabled after the interrupt thread
215 # has been scheduled but before it runs.
216 #
217 # The disable function returns an indication as to whether the handler
218 # is currently running (i.e. the disablement is racing the execution of
219 # the interrupt handler).  0 is returned if it isn't, non-zero if it is.
220 #
221 # The disablement function does NOT interlock against a running handler, it
222 # simply prevents future handler calls from being made.
223 #
224 METHOD void enable_intr {
225         device_t        dev;
226         device_t        child;
227         void            *cookie;
228 } DEFAULT bus_generic_enable_intr;
229
230 METHOD int disable_intr {
231         device_t        dev;
232         device_t        child;
233         void            *cookie;
234 } DEFAULT bus_generic_disable_intr;
235
236 #
237 # Set the range used for a particular resource. Return EINVAL if
238 # the type or rid are out of range.
239 #
240 METHOD int set_resource {
241         device_t        dev;
242         device_t        child;
243         int             type;
244         int             rid;
245         u_long          start;
246         u_long          count;
247         int             cpuid;
248 };
249
250 #
251 # Get the range for a resource. Return ENOENT if the type or rid are
252 # out of range or have not been set.
253 #
254 METHOD int get_resource {
255         device_t        dev;
256         device_t        child;
257         int             type;
258         int             rid;
259         u_long          *startp;
260         u_long          *countp;
261 };
262
263 #
264 # Delete a resource.
265 #
266 METHOD void delete_resource {
267         device_t        dev;
268         device_t        child;
269         int             type;
270         int             rid;
271 };
272
273 #
274 # Return a struct resource_list.
275 #
276 METHOD struct resource_list * get_resource_list {
277         device_t        _dev;
278         device_t        _child;
279 } DEFAULT bus_generic_get_resource_list;
280
281 #
282 # Is the hardware described by _child still attached to the system?
283 #
284 # This method should return 0 if the device is not present.  It should
285 # return -1 if it is present.  Any errors in determining should be
286 # returned as a normal errno value.  Client drivers are to assume that
287 # the device is present, even if there is an error determining if it is
288 # there.  Busses are to try to avoid returning errors, but newcard will return
289 # an error if the device fails to implement this method.
290 #
291 METHOD int child_present {
292         device_t        _dev;
293         device_t        _child;
294 } DEFAULT bus_generic_child_present;
295
296 #
297 # Returns the pnp info for this device.  Return it as a string.  If the
298 # string is insufficient for the storage, then return EOVERFLOW.
299 #
300 METHOD int child_pnpinfo_str {
301         device_t        _dev;
302         device_t        _child;
303         char            *_buf;
304         size_t          _buflen;
305 };
306
307 #
308 # Returns the location for this device.  Return it as a string.  If the
309 # string is insufficient for the storage, then return EOVERFLOW.
310 #
311 METHOD int child_location_str {
312         device_t        _dev;
313         device_t        _child;
314         char            *_buf;
315         size_t          _buflen;
316 };
317
318 #
319 # Allow (bus) drivers to specify the trigger mode and polarity of the
320 # specified interrupt.
321 #
322 METHOD int config_intr {
323         device_t        _dev;
324         device_t        _child;
325         int             _irq;
326         enum intr_trigger _trig;
327         enum intr_polarity _pol;
328 } DEFAULT bus_generic_config_intr;
329