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_board_info;
42 struct bhnd_core_info;
49 #include <sys/systm.h>
51 #include <dev/bhnd/bhndvar.h>
53 static struct bhnd_chipid *
54 bhnd_bus_null_get_chipid(device_t dev, device_t child)
56 panic("bhnd_bus_get_chipid unimplemented");
59 static bhnd_attach_type
60 bhnd_bus_null_get_attach_type(device_t dev, device_t child)
62 panic("bhnd_bus_get_attach_type unimplemented");
66 bhnd_bus_null_read_board_info(device_t dev, device_t child,
67 struct bhnd_board_info *info)
69 panic("bhnd_bus_read_boardinfo unimplemented");
73 bhnd_bus_null_child_added(device_t dev, device_t child)
78 bhnd_bus_null_find_hostb_device(device_t dev)
80 panic("bhnd_bus_find_hostb_device unimplemented");
84 bhnd_bus_null_is_hw_disabled(device_t dev, device_t child)
86 panic("bhnd_bus_is_hw_disabled unimplemented");
90 bhnd_bus_null_get_probe_order(device_t dev, device_t child)
92 panic("bhnd_bus_get_probe_order unimplemented");
96 bhnd_bus_null_get_port_rid(device_t dev, device_t child,
97 bhnd_port_type port_type, u_int port, u_int region)
103 bhnd_bus_null_decode_port_rid(device_t dev, device_t child, int type,
104 int rid, bhnd_port_type *port_type, u_int *port, u_int *region)
110 bhnd_bus_null_get_region_addr(device_t dev, device_t child,
111 bhnd_port_type type, u_int port, u_int region, bhnd_addr_t *addr,
118 bhnd_bus_null_get_nvram_var(device_t dev, device_t child,
119 const char *name, void *buf, size_t *size)
127 * Return the active host bridge core for the bhnd bus, if any.
129 * @param dev The bhnd bus device.
131 * @retval device_t if a hostb device exists
132 * @retval NULL if no hostb device is found.
134 METHOD device_t find_hostb_device {
136 } DEFAULT bhnd_bus_null_find_hostb_device;
139 * Return true if the hardware components required by @p child are unpopulated
140 * or otherwise unusable.
142 * In some cases, enumerated devices may have pins that are left floating, or
143 * the hardware may otherwise be non-functional; this method allows a parent
144 * device to explicitly specify if a successfully enumerated @p child should
147 * @param dev The device whose child is being examined.
148 * @param child The child device.
150 METHOD bool is_hw_disabled {
153 } DEFAULT bhnd_bus_null_is_hw_disabled;
156 * Return the probe (and attach) order for @p child.
158 * All devices on the bhnd(4) bus will be probed, attached, or resumed in
159 * ascending order; they will be suspended, shutdown, and detached in
162 * The following device methods will be dispatched in ascending probe order
169 * The following device methods will be dispatched in descending probe order
172 * - DEVICE_SHUTDOWN()
176 * @param dev The device whose child is being examined.
177 * @param child The child device.
179 * Refer to BHND_PROBE_* and BHND_PROBE_ORDER_* for the standard set of
182 METHOD int get_probe_order {
185 } DEFAULT bhnd_bus_null_get_probe_order;
188 * Return the BHND chip identification for the parent bus.
190 * @param dev The device whose child is being examined.
191 * @param child The child device.
193 METHOD const struct bhnd_chipid * get_chipid {
196 } DEFAULT bhnd_bus_null_get_chipid;
199 * Return the BHND attachment type of the parent bus.
201 * @param dev The device whose child is being examined.
202 * @param child The child device.
204 * @retval BHND_ATTACH_ADAPTER if the bus is resident on a bridged adapter,
205 * such as a WiFi chipset.
206 * @retval BHND_ATTACH_NATIVE if the bus provides hardware services (clock,
207 * CPU, etc) to a directly attached native host.
209 METHOD bhnd_attach_type get_attach_type {
212 } DEFAULT bhnd_bus_null_get_attach_type;
215 * Attempt to read the BHND board identification from the parent bus.
217 * This relies on NVRAM access, and will fail if a valid NVRAM device cannot
218 * be found, or is not yet attached.
220 * @param dev The parent of @p child.
221 * @param child The bhnd device requesting board info.
222 * @param[out] info On success, will be populated with the bhnd(4) device's
226 * @retval ENODEV No valid NVRAM source could be found.
227 * @retval non-zero If reading @p name otherwise fails, a regular unix
228 * error code will be returned.
230 METHOD int read_board_info {
233 struct bhnd_board_info *info;
234 } DEFAULT bhnd_bus_null_read_board_info;
237 * Allocate and zero-initialize a buffer suitably sized and aligned for a
238 * bhnd_devinfo structure.
240 * @param dev The bhnd bus device.
242 * @retval non-NULL success
243 * @retval NULL allocation failed
245 METHOD struct bhnd_devinfo * alloc_devinfo {
250 * Release memory previously allocated for @p devinfo.
252 * @param dev The bhnd bus device.
253 * @param dinfo A devinfo buffer previously allocated via
254 * BHND_BUS_ALLOC_DEVINFO().
256 METHOD void free_devinfo {
258 struct bhnd_devinfo *dinfo;
262 * Notify a bhnd bus that a child was added.
264 * Called at the end of BUS_ADD_CHILD() to allow the concrete bhnd(4)
265 * driver instance to initialize any additional driver-specific state for the
268 * @param dev The bhnd bus whose child is being added.
269 * @param child The child added to @p dev.
271 METHOD void child_added {
274 } DEFAULT bhnd_bus_null_child_added;
277 * Reset the device's hardware core.
279 * @param dev The parent of @p child.
280 * @param child The device to be reset.
281 * @param flags Device-specific core flags to be supplied on reset.
284 * @retval non-zero error
286 METHOD int reset_core {
293 * Suspend a device hardware core.
295 * @param dev The parent of @p child.
296 * @param child The device to be reset.
299 * @retval non-zero error
301 METHOD int suspend_core {
307 * Allocate a bhnd resource.
309 * This method's semantics are functionally identical to the bus API of the same
310 * name; refer to BUS_ALLOC_RESOURCE for complete documentation.
312 METHOD struct bhnd_resource * alloc_resource {
321 } DEFAULT bhnd_bus_generic_alloc_resource;
324 * Release a bhnd resource.
326 * This method's semantics are functionally identical to the bus API of the same
327 * name; refer to BUS_RELEASE_RESOURCE for complete documentation.
329 METHOD int release_resource {
334 struct bhnd_resource *res;
335 } DEFAULT bhnd_bus_generic_release_resource;
338 * Activate a bhnd resource.
340 * This method's semantics are functionally identical to the bus API of the same
341 * name; refer to BUS_ACTIVATE_RESOURCE for complete documentation.
343 METHOD int activate_resource {
348 struct bhnd_resource *r;
349 } DEFAULT bhnd_bus_generic_activate_resource;
352 * Deactivate a bhnd resource.
354 * This method's semantics are functionally identical to the bus API of the same
355 * name; refer to BUS_DEACTIVATE_RESOURCE for complete documentation.
357 METHOD int deactivate_resource {
362 struct bhnd_resource *r;
363 } DEFAULT bhnd_bus_generic_deactivate_resource;
366 * Return true if @p region_num is a valid region on @p port_num of
367 * @p type attached to @p child.
369 * @param dev The device whose child is being examined.
370 * @param child The child device.
371 * @param type The port type being queried.
372 * @param port_num The port number being queried.
373 * @param region_num The region number being queried.
375 METHOD bool is_region_valid {
384 * Return the number of ports of type @p type attached to @p child.
386 * @param dev The device whose child is being examined.
387 * @param child The child device.
388 * @param type The port type being queried.
390 METHOD u_int get_port_count {
397 * Return the number of memory regions mapped to @p child @p port of
400 * @param dev The device whose child is being examined.
401 * @param child The child device.
402 * @param port The port number being queried.
403 * @param type The port type being queried.
405 METHOD u_int get_region_count {
413 * Return the SYS_RES_MEMORY resource-ID for a port/region pair attached to
416 * @param dev The bus device.
417 * @param child The bhnd child.
418 * @param port_type The port type.
419 * @param port_num The index of the child interconnect port.
420 * @param region_num The index of the port-mapped address region.
422 * @retval -1 No such port/region found.
424 METHOD int get_port_rid {
427 bhnd_port_type port_type;
430 } DEFAULT bhnd_bus_null_get_port_rid;
434 * Decode a port / region pair on @p child defined by @p type and @p rid.
436 * @param dev The bus device.
437 * @param child The bhnd child.
438 * @param type The resource type.
439 * @param rid The resource ID.
440 * @param[out] port_type The port's type.
441 * @param[out] port The port identifier.
442 * @param[out] region The identifier of the memory region on @p port.
445 * @retval non-zero No matching type/rid found.
447 METHOD int decode_port_rid {
452 bhnd_port_type *port_type;
455 } DEFAULT bhnd_bus_null_decode_port_rid;
458 * Get the address and size of @p region on @p port.
460 * @param dev The bus device.
461 * @param child The bhnd child.
462 * @param port_type The port type.
463 * @param port The port identifier.
464 * @param region The identifier of the memory region on @p port.
465 * @param[out] region_addr The region's base address.
466 * @param[out] region_size The region's size.
469 * @retval non-zero No matching port/region found.
471 METHOD int get_region_addr {
474 bhnd_port_type port_type;
477 bhnd_addr_t *region_addr;
478 bhnd_size_t *region_size;
479 } DEFAULT bhnd_bus_null_get_region_addr;
482 * Read an NVRAM variable.
484 * It is the responsibility of the bus to delegate this request to
485 * the appropriate NVRAM child device, or to a parent bus implementation.
487 * @param dev The bus device.
488 * @param child The requesting device.
489 * @param name The NVRAM variable name.
490 * @param[out] buf On success, the requested value will be written
491 * to this buffer. This argment may be NULL if
492 * the value is not desired.
493 * @param[in,out] size The capacity of @p buf. On success, will be set
494 * to the actual size of the requested value.
497 * @retval ENOENT The requested variable was not found.
498 * @retval ENOMEM If @p buf is non-NULL and a buffer of @p size is too
499 * small to hold the requested value.
500 * @retval ENODEV No valid NVRAM source could be found.
501 * @retval non-zero If reading @p name otherwise fails, a regular unix
502 * error code will be returned.
504 METHOD int get_nvram_var {
510 } DEFAULT bhnd_bus_null_get_nvram_var;
513 /** An implementation of bus_read_1() compatible with bhnd_resource */
514 METHOD uint8_t read_1 {
517 struct bhnd_resource *r;
521 /** An implementation of bus_read_2() compatible with bhnd_resource */
522 METHOD uint16_t read_2 {
525 struct bhnd_resource *r;
529 /** An implementation of bus_read_4() compatible with bhnd_resource */
530 METHOD uint32_t read_4 {
533 struct bhnd_resource *r;
537 /** An implementation of bus_write_1() compatible with bhnd_resource */
538 METHOD void write_1 {
541 struct bhnd_resource *r;
546 /** An implementation of bus_write_2() compatible with bhnd_resource */
547 METHOD void write_2 {
550 struct bhnd_resource *r;
555 /** An implementation of bus_write_4() compatible with bhnd_resource */
556 METHOD void write_4 {
559 struct bhnd_resource *r;
564 /** An implementation of bus_read_stream_1() compatible with bhnd_resource */
565 METHOD uint8_t read_stream_1 {
568 struct bhnd_resource *r;
572 /** An implementation of bus_read_stream_2() compatible with bhnd_resource */
573 METHOD uint16_t read_stream_2 {
576 struct bhnd_resource *r;
580 /** An implementation of bus_read_stream_4() compatible with bhnd_resource */
581 METHOD uint32_t read_stream_4 {
584 struct bhnd_resource *r;
588 /** An implementation of bus_write_stream_1() compatible with bhnd_resource */
589 METHOD void write_stream_1 {
592 struct bhnd_resource *r;
597 /** An implementation of bus_write_stream_2() compatible with bhnd_resource */
598 METHOD void write_stream_2 {
601 struct bhnd_resource *r;
606 /** An implementation of bus_write_stream_4() compatible with bhnd_resource */
607 METHOD void write_stream_4 {
610 struct bhnd_resource *r;
615 /** An implementation of bus_read_multi_1() compatible with bhnd_resource */
616 METHOD void read_multi_1 {
619 struct bhnd_resource *r;
625 /** An implementation of bus_read_multi_2() compatible with bhnd_resource */
626 METHOD void read_multi_2 {
629 struct bhnd_resource *r;
635 /** An implementation of bus_read_multi_4() compatible with bhnd_resource */
636 METHOD void read_multi_4 {
639 struct bhnd_resource *r;
645 /** An implementation of bus_write_multi_1() compatible with bhnd_resource */
646 METHOD void write_multi_1 {
649 struct bhnd_resource *r;
655 /** An implementation of bus_write_multi_2() compatible with bhnd_resource */
656 METHOD void write_multi_2 {
659 struct bhnd_resource *r;
665 /** An implementation of bus_write_multi_4() compatible with bhnd_resource */
666 METHOD void write_multi_4 {
669 struct bhnd_resource *r;
675 /** An implementation of bus_read_multi_stream_1() compatible
677 METHOD void read_multi_stream_1 {
680 struct bhnd_resource *r;
686 /** An implementation of bus_read_multi_stream_2() compatible
688 METHOD void read_multi_stream_2 {
691 struct bhnd_resource *r;
697 /** An implementation of bus_read_multi_stream_4() compatible
699 METHOD void read_multi_stream_4 {
702 struct bhnd_resource *r;
708 /** An implementation of bus_write_multi_stream_1() compatible
710 METHOD void write_multi_stream_1 {
713 struct bhnd_resource *r;
719 /** An implementation of bus_write_multi_stream_2() compatible with
721 METHOD void write_multi_stream_2 {
724 struct bhnd_resource *r;
730 /** An implementation of bus_write_multi_stream_4() compatible with
732 METHOD void write_multi_stream_4 {
735 struct bhnd_resource *r;
741 /** An implementation of bus_set_multi_1() compatible with bhnd_resource */
742 METHOD void set_multi_1 {
745 struct bhnd_resource *r;
751 /** An implementation of bus_set_multi_2() compatible with bhnd_resource */
752 METHOD void set_multi_2 {
755 struct bhnd_resource *r;
761 /** An implementation of bus_set_multi_4() compatible with bhnd_resource */
762 METHOD void set_multi_4 {
765 struct bhnd_resource *r;
771 /** An implementation of bus_set_region_1() compatible with bhnd_resource */
772 METHOD void set_region_1 {
775 struct bhnd_resource *r;
781 /** An implementation of bus_set_region_2() compatible with bhnd_resource */
782 METHOD void set_region_2 {
785 struct bhnd_resource *r;
791 /** An implementation of bus_set_region_4() compatible with bhnd_resource */
792 METHOD void set_region_4 {
795 struct bhnd_resource *r;
801 /** An implementation of bus_read_region_1() compatible with bhnd_resource */
802 METHOD void read_region_1 {
805 struct bhnd_resource *r;
811 /** An implementation of bus_read_region_2() compatible with bhnd_resource */
812 METHOD void read_region_2 {
815 struct bhnd_resource *r;
821 /** An implementation of bus_read_region_4() compatible with bhnd_resource */
822 METHOD void read_region_4 {
825 struct bhnd_resource *r;
831 /** An implementation of bus_read_region_stream_1() compatible with
833 METHOD void read_region_stream_1 {
836 struct bhnd_resource *r;
842 /** An implementation of bus_read_region_stream_2() compatible with
844 METHOD void read_region_stream_2 {
847 struct bhnd_resource *r;
853 /** An implementation of bus_read_region_stream_4() compatible with
855 METHOD void read_region_stream_4 {
858 struct bhnd_resource *r;
864 /** An implementation of bus_write_region_1() compatible with bhnd_resource */
865 METHOD void write_region_1 {
868 struct bhnd_resource *r;
874 /** An implementation of bus_write_region_2() compatible with bhnd_resource */
875 METHOD void write_region_2 {
878 struct bhnd_resource *r;
884 /** An implementation of bus_write_region_4() compatible with bhnd_resource */
885 METHOD void write_region_4 {
888 struct bhnd_resource *r;
894 /** An implementation of bus_write_region_stream_1() compatible with
896 METHOD void write_region_stream_1 {
899 struct bhnd_resource *r;
905 /** An implementation of bus_write_region_stream_2() compatible with
907 METHOD void write_region_stream_2 {
910 struct bhnd_resource *r;
916 /** An implementation of bus_write_region_stream_4() compatible with
918 METHOD void write_region_stream_4 {
921 struct bhnd_resource *r;
927 /** An implementation of bus_barrier() compatible with bhnd_resource */
928 METHOD void barrier {
931 struct bhnd_resource *r;