2 # Copyright (c) 2015 Landon Fuller <landon@landonf.org>
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 ``AS IS'' AND ANY EXPRESS OR
15 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 # IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18 # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
23 # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/types.h>
31 #include <dev/bhnd/bhnd_types.h>
36 # bhnd(4) bus interface
40 /* forward declarations */
41 struct bhnd_core_info;
48 #include <sys/systm.h>
50 #include <dev/bhnd/bhndvar.h>
52 static struct bhnd_chipid *
53 bhnd_bus_null_get_chipid(device_t dev, device_t child)
55 panic("bhnd_bus_get_chipid unimplemented");
59 bhnd_bus_null_find_hostb_device(device_t dev)
61 panic("bhnd_bus_find_hostb_device unimplemented");
65 bhnd_bus_null_is_hw_disabled(device_t dev, device_t child)
67 panic("bhnd_bus_is_hw_disabled unimplemented");
71 bhnd_bus_null_get_probe_order(device_t dev, device_t child)
73 panic("bhnd_bus_get_probe_order unimplemented");
77 bhnd_bus_null_get_port_rid(device_t dev, device_t child,
78 bhnd_port_type port_type, u_int port, u_int region)
84 bhnd_bus_null_decode_port_rid(device_t dev, device_t child, int type,
85 int rid, bhnd_port_type *port_type, u_int *port, u_int *region)
91 bhnd_bus_null_get_region_addr(device_t dev, device_t child,
92 bhnd_port_type type, u_int port, u_int region, bhnd_addr_t *addr,
99 bhnd_bus_null_get_nvram_var(device_t dev, device_t child,
100 const char *name, void *buf, size_t *size)
108 * Return the active host bridge core for the bhnd bus, if any.
110 * @param dev The bhnd bus device.
112 * @retval device_t if a hostb device exists
113 * @retval NULL if no hostb device is found.
115 METHOD device_t find_hostb_device {
117 } DEFAULT bhnd_bus_null_find_hostb_device;
120 * Return true if the hardware components required by @p child are unpopulated
121 * or otherwise unusable.
123 * In some cases, enumerated devices may have pins that are left floating, or
124 * the hardware may otherwise be non-functional; this method allows a parent
125 * device to explicitly specify if a successfully enumerated @p child should
128 * @param dev The device whose child is being examined.
129 * @param child The child device.
131 METHOD bool is_hw_disabled {
134 } DEFAULT bhnd_bus_null_is_hw_disabled;
137 * Return the probe (and attach) order for @p child.
139 * All devices on the bhnd(4) bus will be probed, attached, or resumed in
140 * ascending order; they will be suspended, shutdown, and detached in
143 * The following device methods will be dispatched in ascending probe order
150 * The following device methods will be dispatched in descending probe order
153 * - DEVICE_SHUTDOWN()
157 * @param dev The device whose child is being examined.
158 * @param child The child device.
160 * Refer to BHND_PROBE_* and BHND_PROBE_ORDER_* for the standard set of
163 METHOD int get_probe_order {
166 } DEFAULT bhnd_bus_null_get_probe_order;
169 * Return the BHND chip identification for the parent bus.
171 * @param dev The device whose child is being examined.
172 * @param child The child device.
174 METHOD const struct bhnd_chipid * get_chipid {
177 } DEFAULT bhnd_bus_null_get_chipid;
180 * Reset the device's hardware core.
182 * @param dev The parent of @p child.
183 * @param child The device to be reset.
184 * @param flags Device-specific core flags to be supplied on reset.
187 * @retval non-zero error
189 METHOD int reset_core {
196 * Suspend a device hardware core.
198 * @param dev The parent of @p child.
199 * @param child The device to be reset.
202 * @retval non-zero error
204 METHOD int suspend_core {
210 * Allocate a bhnd resource.
212 * This method's semantics are functionally identical to the bus API of the same
213 * name; refer to BUS_ALLOC_RESOURCE for complete documentation.
215 METHOD struct bhnd_resource * alloc_resource {
224 } DEFAULT bhnd_bus_generic_alloc_resource;
227 * Release a bhnd resource.
229 * This method's semantics are functionally identical to the bus API of the same
230 * name; refer to BUS_RELEASE_RESOURCE for complete documentation.
232 METHOD int release_resource {
237 struct bhnd_resource *res;
238 } DEFAULT bhnd_bus_generic_release_resource;
241 * Activate a bhnd resource.
243 * This method's semantics are functionally identical to the bus API of the same
244 * name; refer to BUS_ACTIVATE_RESOURCE for complete documentation.
246 METHOD int activate_resource {
251 struct bhnd_resource *r;
252 } DEFAULT bhnd_bus_generic_activate_resource;
255 * Deactivate a bhnd resource.
257 * This method's semantics are functionally identical to the bus API of the same
258 * name; refer to BUS_DEACTIVATE_RESOURCE for complete documentation.
260 METHOD int deactivate_resource {
265 struct bhnd_resource *r;
266 } DEFAULT bhnd_bus_generic_deactivate_resource;
269 * Return true if @p region_num is a valid region on @p port_num of
270 * @p type attached to @p child.
272 * @param dev The device whose child is being examined.
273 * @param child The child device.
274 * @param type The port type being queried.
275 * @param port_num The port number being queried.
276 * @param region_num The region number being queried.
278 METHOD bool is_region_valid {
287 * Return the number of ports of type @p type attached to @p child.
289 * @param dev The device whose child is being examined.
290 * @param child The child device.
291 * @param type The port type being queried.
293 METHOD u_int get_port_count {
300 * Return the number of memory regions mapped to @p child @p port of
303 * @param dev The device whose child is being examined.
304 * @param child The child device.
305 * @param port The port number being queried.
306 * @param type The port type being queried.
308 METHOD u_int get_region_count {
316 * Return the SYS_RES_MEMORY resource-ID for a port/region pair attached to
319 * @param dev The bus device.
320 * @param child The bhnd child.
321 * @param port_type The port type.
322 * @param port_num The index of the child interconnect port.
323 * @param region_num The index of the port-mapped address region.
325 * @retval -1 No such port/region found.
327 METHOD int get_port_rid {
330 bhnd_port_type port_type;
333 } DEFAULT bhnd_bus_null_get_port_rid;
337 * Decode a port / region pair on @p child defined by @p type and @p rid.
339 * @param dev The bus device.
340 * @param child The bhnd child.
341 * @param type The resource type.
342 * @param rid The resource ID.
343 * @param[out] port_type The port's type.
344 * @param[out] port The port identifier.
345 * @param[out] region The identifier of the memory region on @p port.
348 * @retval non-zero No matching type/rid found.
350 METHOD int decode_port_rid {
355 bhnd_port_type *port_type;
358 } DEFAULT bhnd_bus_null_decode_port_rid;
361 * Get the address and size of @p region on @p port.
363 * @param dev The bus device.
364 * @param child The bhnd child.
365 * @param port_type The port type.
366 * @param port The port identifier.
367 * @param region The identifier of the memory region on @p port.
368 * @param[out] region_addr The region's base address.
369 * @param[out] region_size The region's size.
372 * @retval non-zero No matching port/region found.
374 METHOD int get_region_addr {
377 bhnd_port_type port_type;
380 bhnd_addr_t *region_addr;
381 bhnd_size_t *region_size;
382 } DEFAULT bhnd_bus_null_get_region_addr;
385 * Read an NVRAM variable.
387 * It is the responsibility of the bus to delegate this request to
388 * the appropriate NVRAM child device, or to a parent bus implementation.
390 * @param dev The bus device.
391 * @param child The requesting device.
392 * @param name The NVRAM variable name.
393 * @param[out] buf On success, the requested value will be written
394 * to this buffer. This argment may be NULL if
395 * the value is not desired.
396 * @param[in,out] size The capacity of @p buf. On success, will be set
397 * to the actual size of the requested value.
400 * @retval ENOENT The requested variable was not found.
401 * @retval ENOMEM If @p buf is non-NULL and a buffer of @p size is too
402 * small to hold the requested value.
403 * @retval non-zero If reading @p name otherwise fails, a regular unix
404 * error code will be returned.
406 METHOD int get_nvram_var {
412 } DEFAULT bhnd_bus_null_get_nvram_var;
415 /** An implementation of bus_read_1() compatible with bhnd_resource */
416 METHOD uint8_t read_1 {
419 struct bhnd_resource *r;
423 /** An implementation of bus_read_2() compatible with bhnd_resource */
424 METHOD uint16_t read_2 {
427 struct bhnd_resource *r;
431 /** An implementation of bus_read_4() compatible with bhnd_resource */
432 METHOD uint32_t read_4 {
435 struct bhnd_resource *r;
439 /** An implementation of bus_write_1() compatible with bhnd_resource */
440 METHOD void write_1 {
443 struct bhnd_resource *r;
448 /** An implementation of bus_write_2() compatible with bhnd_resource */
449 METHOD void write_2 {
452 struct bhnd_resource *r;
457 /** An implementation of bus_write_4() compatible with bhnd_resource */
458 METHOD void write_4 {
461 struct bhnd_resource *r;
466 /** An implementation of bus_read_stream_1() compatible with bhnd_resource */
467 METHOD uint8_t read_stream_1 {
470 struct bhnd_resource *r;
474 /** An implementation of bus_read_stream_2() compatible with bhnd_resource */
475 METHOD uint16_t read_stream_2 {
478 struct bhnd_resource *r;
482 /** An implementation of bus_read_stream_4() compatible with bhnd_resource */
483 METHOD uint32_t read_stream_4 {
486 struct bhnd_resource *r;
490 /** An implementation of bus_write_stream_1() compatible with bhnd_resource */
491 METHOD void write_stream_1 {
494 struct bhnd_resource *r;
499 /** An implementation of bus_write_stream_2() compatible with bhnd_resource */
500 METHOD void write_stream_2 {
503 struct bhnd_resource *r;
508 /** An implementation of bus_write_stream_4() compatible with bhnd_resource */
509 METHOD void write_stream_4 {
512 struct bhnd_resource *r;
517 /** An implementation of bus_read_multi_1() compatible with bhnd_resource */
518 METHOD void read_multi_1 {
521 struct bhnd_resource *r;
527 /** An implementation of bus_read_multi_2() compatible with bhnd_resource */
528 METHOD void read_multi_2 {
531 struct bhnd_resource *r;
537 /** An implementation of bus_read_multi_4() compatible with bhnd_resource */
538 METHOD void read_multi_4 {
541 struct bhnd_resource *r;
547 /** An implementation of bus_write_multi_1() compatible with bhnd_resource */
548 METHOD void write_multi_1 {
551 struct bhnd_resource *r;
557 /** An implementation of bus_write_multi_2() compatible with bhnd_resource */
558 METHOD void write_multi_2 {
561 struct bhnd_resource *r;
567 /** An implementation of bus_write_multi_4() compatible with bhnd_resource */
568 METHOD void write_multi_4 {
571 struct bhnd_resource *r;
577 /** An implementation of bus_read_multi_stream_1() compatible
579 METHOD void read_multi_stream_1 {
582 struct bhnd_resource *r;
588 /** An implementation of bus_read_multi_stream_2() compatible
590 METHOD void read_multi_stream_2 {
593 struct bhnd_resource *r;
599 /** An implementation of bus_read_multi_stream_4() compatible
601 METHOD void read_multi_stream_4 {
604 struct bhnd_resource *r;
610 /** An implementation of bus_write_multi_stream_1() compatible
612 METHOD void write_multi_stream_1 {
615 struct bhnd_resource *r;
621 /** An implementation of bus_write_multi_stream_2() compatible with
623 METHOD void write_multi_stream_2 {
626 struct bhnd_resource *r;
632 /** An implementation of bus_write_multi_stream_4() compatible with
634 METHOD void write_multi_stream_4 {
637 struct bhnd_resource *r;
643 /** An implementation of bus_barrier() compatible with bhnd_resource */
644 METHOD void barrier {
647 struct bhnd_resource *r;