2 # Copyright (c) 1998 Doug Rabson
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
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.
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
34 # Default implementations of some methods.
37 static struct resource *
38 null_alloc_resource(device_t dev, device_t child,
39 int type, int *rid, u_long start, u_long end,
40 u_long count, u_int flags)
47 # This is called from system code which prints out a description of a
48 # device. It should describe the attachment that the child has with
49 # the parent. For instance the TurboLaser bus prints which node the
50 # device is attached to. See bus_generic_print_child.9 for more
52 # This method returns the number of characters output.
54 METHOD int print_child {
57 } DEFAULT bus_generic_print_child;
60 # Called for each child device that
61 # did not succeed in probing for a
64 METHOD void probe_nomatch {
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.)
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.
81 # Read an instance variable. Return 0 on success.
83 METHOD int read_ivar {
91 # Write an instance variable. Return 0 on success.
93 METHOD int write_ivar {
101 # Called after the child's DEVICE_DETACH method to allow the parent
102 # to reclaim any resources allocated on behalf of the child.
104 METHOD void child_detached {
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.
114 METHOD void driver_added {
117 } DEFAULT bus_generic_driver_added;
120 # For busses which use 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.
125 METHOD device_t add_child {
133 # Allocate a system resource attached to `dev' on behalf of `child'.
134 # The types are defined in <machine/resource.h>; the meaning of the
135 # resource-ID field varies from bus to bus (but *rid == 0 is always
136 # valid if the resource type is). start and end reflect the allowable
137 # range, and should be passed as `0UL' and `~0UL', respectively, if
138 # the client has no range restriction. count is the number of consecutive
139 # indices in the resource required. flags is a set of sharing flags
140 # as defined in <sys/rman.h>.
142 # Returns a resource or a null pointer on failure. The caller is
143 # responsible for calling rman_activate_resource() when it actually
146 METHOD struct resource * alloc_resource {
155 } DEFAULT null_alloc_resource;
157 METHOD int activate_resource {
165 METHOD int deactivate_resource {
174 # Free a resource allocated by the preceding method. The `rid' value
175 # must be the same as the one returned by BUS_ALLOC_RESOURCE (which
176 # is not necessarily the same as the one the client passed).
178 METHOD int release_resource {
183 struct resource *_res;
186 METHOD int setup_intr {
189 struct resource *_irq;
191 driver_intr_t *_intr;
196 METHOD int teardown_intr {
199 struct resource *_irq;
204 # Set the range used for a particular resource. Return EINVAL if
205 # the type or rid are out of range.
207 METHOD int set_resource {
217 # Get the range for a resource. Return ENOENT if the type or rid are
218 # out of range or have not been set.
220 METHOD int get_resource {
232 METHOD void delete_resource {
240 # Return a struct resource_list.
242 METHOD struct resource_list * get_resource_list {
245 } DEFAULT bus_generic_get_resource_list;
248 # Is the hardware described by _child still attached to the system?
250 # This method should return 0 if the device is not present. It should
251 # return -1 if it is present. Any errors in determining should be
252 # returned as a normal errno value. Client drivers are to assume that
253 # the device is present, even if there is an error determining if it is
254 # there. Busses are to try to avoid returning errors, but newcard will return
255 # an error if the device fails to implement this method.
257 METHOD int child_present {
260 } DEFAULT bus_generic_child_present;
263 # Returns the pnp info for this device. Return it as a string. If the
264 # string is insufficient for the storage, then return EOVERFLOW.
266 METHOD int child_pnpinfo_str {
274 # Returns the location for this device. Return it as a string. If the
275 # string is insufficient for the storage, then return EOVERFLOW.
277 METHOD int child_location_str {
285 # Allow (bus) drivers to specify the trigger mode and polarity of the
286 # specified interrupt.
288 METHOD int config_intr {
291 enum intr_trigger _trig;
292 enum intr_polarity _pol;
293 } DEFAULT bus_generic_config_intr;