Deleted Added
full compact
fdt_ic_if.m (119967) fdt_ic_if.m (132354)
1
1#
2#
2# Copyright (c) 1998 Doug Rabson
3# Copyright (c) 1998,2004 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

--- 7 unchanged lines hidden (view full) ---

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#
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright

--- 7 unchanged lines hidden (view full) ---

19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26#
26# $FreeBSD: head/sys/kern/bus_if.m 119967 2003-09-10 21:37:10Z marcel $
27# $FreeBSD: head/sys/kern/bus_if.m 132354 2004-07-18 16:30:31Z dfr $
27#
28
29#include <sys/bus.h>
30
28#
29
30#include <sys/bus.h>
31
32/**
33 * @defgroup BUS bus - KObj methods for drivers of devices with children
34 * @brief A set of methods required device drivers that support
35 * child devices.
36 * @{
37 */
31INTERFACE bus;
32
33#
34# Default implementations of some methods.
35#
36CODE {
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)
41 {
42 return (0);
43 }
44};
45
38INTERFACE bus;
39
40#
41# Default implementations of some methods.
42#
43CODE {
44 static struct resource *
45 null_alloc_resource(device_t dev, device_t child,
46 int type, int *rid, u_long start, u_long end,
47 u_long count, u_int flags)
48 {
49 return (0);
50 }
51};
52
46#
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
51# information.
52# This method returns the number of characters output.
53#
53/**
54 * @brief Print a description of a child device
55 *
56 * This is called from system code which prints out a description of a
57 * device. It should describe the attachment that the child has with
58 * the parent. For instance the TurboLaser bus prints which node the
59 * device is attached to. See bus_generic_print_child() for more
60 * information.
61 *
62 * @param _dev the device whose child is being printed
63 * @param _child the child device to describe
64 *
65 * @returns the number of characters output.
66 */
54METHOD int print_child {
67METHOD int print_child {
55 device_t dev;
56 device_t child;
68 device_t _dev;
69 device_t _child;
57} DEFAULT bus_generic_print_child;
58
70} DEFAULT bus_generic_print_child;
71
59#
60# Called for each child device that
61# did not succeed in probing for a
62# driver.
63#
72/**
73 * @brief Print a notification about an unprobed child device.
74 *
75 * Called for each child device that did not succeed in probing for a
76 * driver.
77 *
78 * @param _dev the device whose child was being probed
79 * @param _child the child device which failed to probe
80 */
64METHOD void probe_nomatch {
81METHOD void probe_nomatch {
65 device_t dev;
66 device_t child;
82 device_t _dev;
83 device_t _child;
67};
68
84};
85
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#
86/**
87 * @brief Read the value of a bus-specific attribute of a device
88 *
89 * This method, along with BUS_WRITE_IVAR() manages a bus-specific set
90 * of instance variables of a child device. The intention is that
91 * each different type of bus defines a set of appropriate instance
92 * variables (such as ports and irqs for ISA bus etc.)
93 *
94 * This information could be given to the child device as a struct but
95 * that makes it hard for a bus to add or remove variables without
96 * forcing an edit and recompile for all drivers which may not be
97 * possible for vendor supplied binary drivers.
98 *
99 * This method copies the value of an instance variable to the
100 * location specified by @p *_result.
101 *
102 * @param _dev the device whose child was being examined
103 * @param _child the child device whose instance variable is
104 * being read
105 * @param _index the instance variable to read
106 * @param _result a loction to recieve the instance variable
107 * value
108 *
109 * @retval 0 success
110 * @retval ENOENT no such instance variable is supported by @p
111 * _dev
112 */
83METHOD int read_ivar {
84 device_t _dev;
85 device_t _child;
113METHOD int read_ivar {
114 device_t _dev;
115 device_t _child;
86 int _indx;
116 int _index;
87 uintptr_t *_result;
88};
89
117 uintptr_t *_result;
118};
119
90#
91# Write an instance variable. Return 0 on success.
92#
120/**
121 * @brief Write the value of a bus-specific attribute of a device
122 *
123 * This method sets the value of an instance variable to @p _value.
124 *
125 * @param _dev the device whose child was being updated
126 * @param _child the child device whose instance variable is
127 * being written
128 * @param _index the instance variable to write
129 * @param _value the value to write to that instance variable
130 *
131 * @retval 0 success
132 * @retval ENOENT no such instance variable is supported by @p
133 * _dev
134 * @retval EINVAL the instance variable was recognised but
135 * contains a read-only value
136 */
93METHOD int write_ivar {
94 device_t _dev;
95 device_t _child;
96 int _indx;
97 uintptr_t _value;
98};
99
137METHOD int write_ivar {
138 device_t _dev;
139 device_t _child;
140 int _indx;
141 uintptr_t _value;
142};
143
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#
144/**
145 * @brief Notify a bus that a child was detached
146 *
147 * Called after the child's DEVICE_DETACH() method to allow the parent
148 * to reclaim any resources allocated on behalf of the child.
149 *
150 * @param _dev the device whose child changed state
151 * @param _child the child device which changed state
152 */
104METHOD void child_detached {
105 device_t _dev;
106 device_t _child;
107};
108
153METHOD void child_detached {
154 device_t _dev;
155 device_t _child;
156};
157
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#
158/**
159 * @brief Notify a bus that a new driver was added
160 *
161 * Called when a new driver is added to the devclass which owns this
162 * bus. The generic implementation of this method attempts to probe and
163 * attach any un-matched children of the bus.
164 *
165 * @param _dev the device whose devclass had a new driver
166 * added to it
167 * @param _driver the new driver which was added
168 */
114METHOD void driver_added {
115 device_t _dev;
116 driver_t *_driver;
117} DEFAULT bus_generic_driver_added;
118
169METHOD void driver_added {
170 device_t _dev;
171 driver_t *_driver;
172} DEFAULT bus_generic_driver_added;
173
119#
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.
124#
174/**
175 * @brief Create a new child device
176 *
177 * For busses which use use drivers supporting DEVICE_IDENTIFY() to
178 * enumerate their devices, this method is used to create new
179 * device instances. The new device will be added after the last
180 * existing child with the same order.
181 *
182 * @param _dev the bus device which will be the parent of the
183 * new child device
184 * @param _order a value which is used to partially sort the
185 * children of @p _dev - devices created using
186 * lower values of @p _order appear first in @p
187 * _dev's list of children
188 * @param _name devclass name for new device or @c NULL if not
189 * specified
190 * @param _unit unit number for new device or @c -1 if not
191 * specified
192 */
125METHOD device_t add_child {
126 device_t _dev;
127 int _order;
128 const char *_name;
129 int _unit;
130};
131
193METHOD device_t add_child {
194 device_t _dev;
195 int _order;
196 const char *_name;
197 int _unit;
198};
199
132#
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>.
141#
142# Returns a resource or a null pointer on failure. The caller is
143# responsible for calling rman_activate_resource() when it actually
144# uses the resource.
145#
200/**
201 * @brief Allocate a system resource
202 *
203 * This method is called by child devices of a bus to allocate resources.
204 * The types are defined in <machine/resource.h>; the meaning of the
205 * resource-ID field varies from bus to bus (but @p *rid == 0 is always
206 * valid if the resource type is). If a resource was allocated and the
207 * caller did not use the RF_ACTIVE to specify that it should be
208 * activated immediately, the caller is responsible for calling
209 * BUS_ACTIVATE_RESOURCE() when it actually uses the resource.
210 *
211 * @param _dev the parent device of @p _child
212 * @param _child the device which is requesting an allocation
213 * @param _type the type of resource to allocate
214 * @param _rid a pointer to the resource identifier
215 * @param _start hint at the start of the resource range - pass
216 * @c 0UL for any start address
217 * @param _end hint at the end of the resource range - pass
218 * @c ~0UL for any end address
219 * @param _count hint at the size of range required - pass @c 1
220 * for any size
221 * @param _flags any extra flags to control the resource
222 * allocation - see @c RF_XXX flags in
223 * <sys/rman.h> for details
224 *
225 * @returns the resource which was allocated or @c NULL if no
226 * resource could be allocated
227 */
146METHOD struct resource * alloc_resource {
147 device_t _dev;
148 device_t _child;
149 int _type;
150 int *_rid;
151 u_long _start;
152 u_long _end;
153 u_long _count;
154 u_int _flags;
155} DEFAULT null_alloc_resource;
156
228METHOD struct resource * alloc_resource {
229 device_t _dev;
230 device_t _child;
231 int _type;
232 int *_rid;
233 u_long _start;
234 u_long _end;
235 u_long _count;
236 u_int _flags;
237} DEFAULT null_alloc_resource;
238
239/**
240 * @brief Activate a resource
241 *
242 * Activate a resource previously allocated with
243 * BUS_ALLOC_RESOURCE(). This may for instance map a memory region
244 * into the kernel's virtual address space.
245 *
246 * @param _dev the parent device of @p _child
247 * @param _child the device which allocated the resource
248 * @param _type the type of resource
249 * @param _rid the resource identifier
250 * @param _r the resource to activate
251 */
157METHOD int activate_resource {
158 device_t _dev;
159 device_t _child;
160 int _type;
161 int _rid;
162 struct resource *_r;
163};
164
252METHOD int activate_resource {
253 device_t _dev;
254 device_t _child;
255 int _type;
256 int _rid;
257 struct resource *_r;
258};
259
260/**
261 * @brief Deactivate a resource
262 *
263 * Deactivate a resource previously allocated with
264 * BUS_ALLOC_RESOURCE(). This may for instance unmap a memory region
265 * from the kernel's virtual address space.
266 *
267 * @param _dev the parent device of @p _child
268 * @param _child the device which allocated the resource
269 * @param _type the type of resource
270 * @param _rid the resource identifier
271 * @param _r the resource to deactivate
272 */
165METHOD int deactivate_resource {
166 device_t _dev;
167 device_t _child;
168 int _type;
169 int _rid;
170 struct resource *_r;
171};
172
273METHOD int deactivate_resource {
274 device_t _dev;
275 device_t _child;
276 int _type;
277 int _rid;
278 struct resource *_r;
279};
280
173#
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).
177#
281/**
282 * @brief Release a resource
283 *
284 * Free a resource allocated by the BUS_ALLOC_RESOURCE. The @p _rid
285 * value must be the same as the one returned by BUS_ALLOC_RESOURCE()
286 * (which is not necessarily the same as the one the client passed).
287 *
288 * @param _dev the parent device of @p _child
289 * @param _child the device which allocated the resource
290 * @param _type the type of resource
291 * @param _rid the resource identifier
292 * @param _r the resource to release
293 */
178METHOD int release_resource {
179 device_t _dev;
180 device_t _child;
181 int _type;
182 int _rid;
183 struct resource *_res;
184};
185
294METHOD int release_resource {
295 device_t _dev;
296 device_t _child;
297 int _type;
298 int _rid;
299 struct resource *_res;
300};
301
302/**
303 * @brief Install an interrupt handler
304 *
305 * This method is used to associate an interrupt handler function with
306 * an irq resource. When the interrupt triggers, the function @p _intr
307 * will be called with the value of @p _arg as its single
308 * argument. The value returned in @p *_cookiep is used to cancel the
309 * interrupt handler - the caller should save this value to use in a
310 * future call to BUS_TEARDOWN_INTR().
311 *
312 * @param _dev the parent device of @p _child
313 * @param _child the device which allocated the resource
314 * @param _irq the resource representing the interrupt
315 * @param _flags a set of bits from enum intr_type specifying
316 * the class of interrupt
317 * @param _intr the function to call when the interrupt
318 * triggers
319 * @param _arg a value to use as the single argument in calls
320 * to @p _intr
321 * @param _cookiep a pointer to a location to recieve a cookie
322 * value that may be used to remove the interrupt
323 * handler
324 */
186METHOD int setup_intr {
187 device_t _dev;
188 device_t _child;
189 struct resource *_irq;
190 int _flags;
191 driver_intr_t *_intr;
192 void *_arg;
193 void **_cookiep;
194};
195
325METHOD int setup_intr {
326 device_t _dev;
327 device_t _child;
328 struct resource *_irq;
329 int _flags;
330 driver_intr_t *_intr;
331 void *_arg;
332 void **_cookiep;
333};
334
335/**
336 * @brief Uninstall an interrupt handler
337 *
338 * This method is used to disassociate an interrupt handler function
339 * with an irq resource. The value of @p _cookie must be the value
340 * returned from a previous call to BUS_SETUP_INTR().
341 *
342 * @param _dev the parent device of @p _child
343 * @param _child the device which allocated the resource
344 * @param _irq the resource representing the interrupt
345 * @param _cookie the cookie value returned when the interrupt
346 * was originally registered
347 */
196METHOD int teardown_intr {
197 device_t _dev;
198 device_t _child;
199 struct resource *_irq;
200 void *_cookie;
201};
202
348METHOD int teardown_intr {
349 device_t _dev;
350 device_t _child;
351 struct resource *_irq;
352 void *_cookie;
353};
354
203#
204# Set the range used for a particular resource. Return EINVAL if
205# the type or rid are out of range.
206#
355/**
356 * @brief Define a resource which can be allocated with
357 * BUS_ALLOC_RESOURCE().
358 *
359 * This method is used by some busses (typically ISA) to allow a
360 * driver to describe a resource range that it would like to
361 * allocate. The resource defined by @p _type and @p _rid is defined
362 * to start at @p _start and to include @p _count indices in its
363 * range.
364 *
365 * @param _dev the parent device of @p _child
366 * @param _child the device which owns the resource
367 * @param _type the type of resource
368 * @param _rid the resource identifier
369 * @param _start the start of the resource range
370 * @param _count the size of the resource range
371 */
207METHOD int set_resource {
208 device_t _dev;
209 device_t _child;
210 int _type;
211 int _rid;
212 u_long _start;
213 u_long _count;
214};
215
372METHOD int set_resource {
373 device_t _dev;
374 device_t _child;
375 int _type;
376 int _rid;
377 u_long _start;
378 u_long _count;
379};
380
216#
217# Get the range for a resource. Return ENOENT if the type or rid are
218# out of range or have not been set.
219#
381/**
382 * @brief Describe a resource
383 *
384 * This method allows a driver to examine the range used for a given
385 * resource without actually allocating it.
386 *
387 * @param _dev the parent device of @p _child
388 * @param _child the device which owns the resource
389 * @param _type the type of resource
390 * @param _rid the resource identifier
391 * @param _start the address of a location to recieve the start
392 * index of the resource range
393 * @param _count the address of a location to recieve the size
394 * of the resource range
395 */
220METHOD int get_resource {
221 device_t _dev;
222 device_t _child;
223 int _type;
224 int _rid;
225 u_long *_startp;
226 u_long *_countp;
227};
228
396METHOD int get_resource {
397 device_t _dev;
398 device_t _child;
399 int _type;
400 int _rid;
401 u_long *_startp;
402 u_long *_countp;
403};
404
229#
230# Delete a resource.
231#
405/**
406 * @brief Delete a resource.
407 *
408 * Use this to delete a resource (possibly one previously added with
409 * BUS_SET_RESOURCE()).
410 *
411 * @param _dev the parent device of @p _child
412 * @param _child the device which owns the resource
413 * @param _type the type of resource
414 * @param _rid the resource identifier
415 */
232METHOD void delete_resource {
233 device_t _dev;
234 device_t _child;
235 int _type;
236 int _rid;
237};
238
416METHOD void delete_resource {
417 device_t _dev;
418 device_t _child;
419 int _type;
420 int _rid;
421};
422
239#
240# Return a struct resource_list.
241#
423/**
424 * @brief Return a struct resource_list.
425 *
426 * Used by drivers which use bus_generic_rl_alloc_resource() etc. to
427 * implement their resource handling. It should return the resource
428 * list of the given child device.
429 *
430 * @param _dev the parent device of @p _child
431 * @param _child the device which owns the resource list
432 */
242METHOD struct resource_list * get_resource_list {
243 device_t _dev;
244 device_t _child;
245} DEFAULT bus_generic_get_resource_list;
246
433METHOD struct resource_list * get_resource_list {
434 device_t _dev;
435 device_t _child;
436} DEFAULT bus_generic_get_resource_list;
437
247#
248# Is the hardware described by _child still attached to the system?
249#
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.
256#
438/**
439 * @brief Is the hardware described by @p _child still attached to the
440 * system?
441 *
442 * This method should return 0 if the device is not present. It should
443 * return -1 if it is present. Any errors in determining should be
444 * returned as a normal errno value. Client drivers are to assume that
445 * the device is present, even if there is an error determining if it is
446 * there. Busses are to try to avoid returning errors, but newcard will return
447 * an error if the device fails to implement this method.
448 *
449 * @param _dev the parent device of @p _child
450 * @param _child the device which is being examined
451 */
257METHOD int child_present {
258 device_t _dev;
259 device_t _child;
260} DEFAULT bus_generic_child_present;
261
452METHOD int child_present {
453 device_t _dev;
454 device_t _child;
455} DEFAULT bus_generic_child_present;
456
262#
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.
265#
457/**
458 * @brief Returns the pnp info for this device.
459 *
460 * Return it as a string. If the string is insufficient for the
461 * storage, then return EOVERFLOW.
462 *
463 * @param _dev the parent device of @p _child
464 * @param _child the device which is being examined
465 * @param _buf the address of a buffer to receive the pnp
466 * string
467 * @param _buflen the size of the buffer pointed to by @p _buf
468 */
266METHOD int child_pnpinfo_str {
267 device_t _dev;
268 device_t _child;
269 char *_buf;
270 size_t _buflen;
271};
272
469METHOD int child_pnpinfo_str {
470 device_t _dev;
471 device_t _child;
472 char *_buf;
473 size_t _buflen;
474};
475
273#
274# Returns the location for this device. Return it as a string. If the
275# string is insufficient for the storage, then return EOVERFLOW.
276#
476/**
477 * @brief Returns the location for this device.
478 *
479 * Return it as a string. If the string is insufficient for the
480 * storage, then return EOVERFLOW.
481 *
482 * @param _dev the parent device of @p _child
483 * @param _child the device which is being examined
484 * @param _buf the address of a buffer to receive the location
485 * string
486 * @param _buflen the size of the buffer pointed to by @p _buf
487 */
277METHOD int child_location_str {
278 device_t _dev;
279 device_t _child;
280 char *_buf;
281 size_t _buflen;
282};
283
488METHOD int child_location_str {
489 device_t _dev;
490 device_t _child;
491 char *_buf;
492 size_t _buflen;
493};
494
284#
285# Allow (bus) drivers to specify the trigger mode and polarity of the
286# specified interrupt.
287#
495/**
496 * @brief Allow (bus) drivers to specify the trigger mode and polarity
497 * of the specified interrupt.
498 *
499 * @param _dev the bus device
500 * @param _irq the interrupt number to modify
501 * @param _trig the trigger mode required
502 * @param _pol the interrupt polarity required
503 */
288METHOD int config_intr {
289 device_t _dev;
290 int _irq;
291 enum intr_trigger _trig;
292 enum intr_polarity _pol;
293} DEFAULT bus_generic_config_intr;
504METHOD int config_intr {
505 device_t _dev;
506 int _irq;
507 enum intr_trigger _trig;
508 enum intr_polarity _pol;
509} DEFAULT bus_generic_config_intr;