xref: /freebsd/sys/dev/bhnd/bhnd.c (revision 3fc36ee018bb836bd1796067cf4ef8683f166ebc)
1 /*-
2  * Copyright (c) 2015-2016 Landon Fuller <landonf@FreeBSD.org>
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  *    without modification.
11  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13  *    redistribution must be conditioned upon including a substantially
14  *    similar Disclaimer requirement for further binary redistribution.
15  *
16  * NO WARRANTY
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27  * THE POSSIBILITY OF SUCH DAMAGES.
28  */
29 
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
32 
33 /*
34  * Broadcom Home Networking Division (HND) Bus Driver.
35  *
36  * The Broadcom HND family of devices consists of both SoCs and host-connected
37  * networking chipsets containing a common family of Broadcom IP cores,
38  * including an integrated MIPS and/or ARM cores.
39  *
40  * HND devices expose a nearly identical interface whether accessible over a
41  * native SoC interconnect, or when connected via a host interface such as
42  * PCIe. As a result, the majority of hardware support code should be re-usable
43  * across host drivers for HND networking chipsets, as well as FreeBSD support
44  * for Broadcom MIPS/ARM HND SoCs.
45  *
46  * Earlier HND models used the siba(4) on-chip interconnect, while later models
47  * use bcma(4); the programming model is almost entirely independent
48  * of the actual underlying interconect.
49  */
50 
51 #include <sys/param.h>
52 #include <sys/kernel.h>
53 #include <sys/bus.h>
54 #include <sys/module.h>
55 #include <sys/systm.h>
56 
57 #include <machine/bus.h>
58 #include <sys/rman.h>
59 #include <machine/resource.h>
60 
61 #include <dev/bhnd/cores/chipc/chipcvar.h>
62 
63 #include <dev/bhnd/cores/pmu/bhnd_pmu.h>
64 #include <dev/bhnd/cores/pmu/bhnd_pmureg.h>
65 
66 #include "bhnd_chipc_if.h"
67 #include "bhnd_nvram_if.h"
68 
69 #include "bhnd.h"
70 #include "bhndvar.h"
71 
72 MALLOC_DEFINE(M_BHND, "bhnd", "bhnd bus data structures");
73 
74 /* Bus pass at which all bus-required children must be available, and
75  * attachment may be finalized. */
76 #define	BHND_FINISH_ATTACH_PASS	BUS_PASS_DEFAULT
77 
78 /**
79  * bhnd_generic_probe_nomatch() reporting configuration.
80  */
81 static const struct bhnd_nomatch {
82 	uint16_t	vendor;		/**< core designer */
83 	uint16_t	device;		/**< core id */
84 	bool		if_verbose;	/**< print when bootverbose is set. */
85 } bhnd_nomatch_table[] = {
86 	{ BHND_MFGID_ARM,	BHND_COREID_OOB_ROUTER,		true	},
87 	{ BHND_MFGID_ARM,	BHND_COREID_EROM,		true	},
88 	{ BHND_MFGID_ARM,	BHND_COREID_PL301,		true	},
89 	{ BHND_MFGID_ARM,	BHND_COREID_APB_BRIDGE,		true	},
90 	{ BHND_MFGID_ARM,	BHND_COREID_AXI_UNMAPPED,	false	},
91 
92 	{ BHND_MFGID_INVALID,	BHND_COREID_INVALID,		false	}
93 };
94 
95 
96 static int			 bhnd_delete_children(struct bhnd_softc *sc);
97 
98 static int			 bhnd_finish_attach(struct bhnd_softc *sc);
99 
100 static device_t			 bhnd_find_chipc(struct bhnd_softc *sc);
101 static struct chipc_caps	*bhnd_find_chipc_caps(struct bhnd_softc *sc);
102 static device_t			 bhnd_find_platform_dev(struct bhnd_softc *sc,
103 				     const char *classname);
104 static device_t			 bhnd_find_pmu(struct bhnd_softc *sc);
105 static device_t			 bhnd_find_nvram(struct bhnd_softc *sc);
106 
107 static int			 compare_ascending_probe_order(const void *lhs,
108 				     const void *rhs);
109 static int			 compare_descending_probe_order(const void *lhs,
110 				     const void *rhs);
111 
112 /**
113  * Default bhnd(4) bus driver implementation of DEVICE_ATTACH().
114  *
115  * This implementation calls device_probe_and_attach() for each of the device's
116  * children, in bhnd probe order.
117  */
118 int
119 bhnd_generic_attach(device_t dev)
120 {
121 	struct bhnd_softc	*sc;
122 	device_t		*devs;
123 	int			 ndevs;
124 	int			 error;
125 
126 	if (device_is_attached(dev))
127 		return (EBUSY);
128 
129 	sc = device_get_softc(dev);
130 	sc->dev = dev;
131 
132 	if ((error = device_get_children(dev, &devs, &ndevs)))
133 		return (error);
134 
135 	/* Probe and attach all children */
136 	qsort(devs, ndevs, sizeof(*devs), compare_ascending_probe_order);
137 	for (int i = 0; i < ndevs; i++) {
138 		device_t child = devs[i];
139 		device_probe_and_attach(child);
140 	}
141 
142 	/* Try to finalize attachment */
143 	if (bus_current_pass >= BHND_FINISH_ATTACH_PASS) {
144 		if ((error = bhnd_finish_attach(sc)))
145 			goto cleanup;
146 	}
147 
148 cleanup:
149 	free(devs, M_TEMP);
150 
151 	if (error)
152 		bhnd_delete_children(sc);
153 
154 	return (error);
155 }
156 
157 /**
158  * Detach and delete all children, in reverse of their attach order.
159  */
160 static int
161 bhnd_delete_children(struct bhnd_softc *sc)
162 {
163 	device_t		*devs;
164 	int			 ndevs;
165 	int			 error;
166 
167 	if ((error = device_get_children(sc->dev, &devs, &ndevs)))
168 		return (error);
169 
170 	/* Detach in the reverse of attach order */
171 	qsort(devs, ndevs, sizeof(*devs), compare_descending_probe_order);
172 	for (int i = 0; i < ndevs; i++) {
173 		device_t child = devs[i];
174 
175 		/* Terminate on first error */
176 		if ((error = device_delete_child(sc->dev, child)))
177 			goto cleanup;
178 	}
179 
180 cleanup:
181 	free(devs, M_TEMP);
182 	return (error);
183 }
184 
185 /**
186  * Default bhnd(4) bus driver implementation of DEVICE_DETACH().
187  *
188  * This implementation calls device_detach() for each of the device's
189  * children, in reverse bhnd probe order, terminating if any call to
190  * device_detach() fails.
191  */
192 int
193 bhnd_generic_detach(device_t dev)
194 {
195 	struct bhnd_softc	*sc;
196 
197 	if (!device_is_attached(dev))
198 		return (EBUSY);
199 
200 	sc = device_get_softc(dev);
201 	return (bhnd_delete_children(sc));
202 }
203 
204 /**
205  * Default bhnd(4) bus driver implementation of DEVICE_SHUTDOWN().
206  *
207  * This implementation calls device_shutdown() for each of the device's
208  * children, in reverse bhnd probe order, terminating if any call to
209  * device_shutdown() fails.
210  */
211 int
212 bhnd_generic_shutdown(device_t dev)
213 {
214 	device_t	*devs;
215 	int		 ndevs;
216 	int		 error;
217 
218 	if (!device_is_attached(dev))
219 		return (EBUSY);
220 
221 	if ((error = device_get_children(dev, &devs, &ndevs)))
222 		return (error);
223 
224 	/* Shutdown in the reverse of attach order */
225 	qsort(devs, ndevs, sizeof(*devs), compare_descending_probe_order);
226 	for (int i = 0; i < ndevs; i++) {
227 		device_t child = devs[i];
228 
229 		/* Terminate on first error */
230 		if ((error = device_shutdown(child)))
231 			goto cleanup;
232 	}
233 
234 cleanup:
235 	free(devs, M_TEMP);
236 	return (error);
237 }
238 
239 /**
240  * Default bhnd(4) bus driver implementation of DEVICE_RESUME().
241  *
242  * This implementation calls BUS_RESUME_CHILD() for each of the device's
243  * children in bhnd probe order, terminating if any call to BUS_RESUME_CHILD()
244  * fails.
245  */
246 int
247 bhnd_generic_resume(device_t dev)
248 {
249 	device_t	*devs;
250 	int		 ndevs;
251 	int		 error;
252 
253 	if (!device_is_attached(dev))
254 		return (EBUSY);
255 
256 	if ((error = device_get_children(dev, &devs, &ndevs)))
257 		return (error);
258 
259 	qsort(devs, ndevs, sizeof(*devs), compare_ascending_probe_order);
260 	for (int i = 0; i < ndevs; i++) {
261 		device_t child = devs[i];
262 
263 		/* Terminate on first error */
264 		if ((error = BUS_RESUME_CHILD(device_get_parent(child), child)))
265 			goto cleanup;
266 	}
267 
268 cleanup:
269 	free(devs, M_TEMP);
270 	return (error);
271 }
272 
273 /**
274  * Default bhnd(4) bus driver implementation of DEVICE_SUSPEND().
275  *
276  * This implementation calls BUS_SUSPEND_CHILD() for each of the device's
277  * children in reverse bhnd probe order. If any call to BUS_SUSPEND_CHILD()
278  * fails, the suspend operation is terminated and any devices that were
279  * suspended are resumed immediately by calling their BUS_RESUME_CHILD()
280  * methods.
281  */
282 int
283 bhnd_generic_suspend(device_t dev)
284 {
285 	device_t	*devs;
286 	int		 ndevs;
287 	int		 error;
288 
289 	if (!device_is_attached(dev))
290 		return (EBUSY);
291 
292 	if ((error = device_get_children(dev, &devs, &ndevs)))
293 		return (error);
294 
295 	/* Suspend in the reverse of attach order */
296 	qsort(devs, ndevs, sizeof(*devs), compare_descending_probe_order);
297 	for (int i = 0; i < ndevs; i++) {
298 		device_t child = devs[i];
299 		error = BUS_SUSPEND_CHILD(device_get_parent(child), child);
300 
301 		/* On error, resume suspended devices and then terminate */
302 		if (error) {
303 			for (int j = 0; j < i; j++) {
304 				BUS_RESUME_CHILD(device_get_parent(devs[j]),
305 				    devs[j]);
306 			}
307 
308 			goto cleanup;
309 		}
310 	}
311 
312 cleanup:
313 	free(devs, M_TEMP);
314 	return (error);
315 }
316 
317 static void
318 bhnd_new_pass(device_t dev)
319 {
320 	struct bhnd_softc	*sc;
321 	int			 error;
322 
323 	sc = device_get_softc(dev);
324 
325 	/* Attach any permissible children */
326 	bus_generic_new_pass(dev);
327 
328 	/* Finalize attachment */
329 	if (!sc->attach_done && bus_current_pass >= BHND_FINISH_ATTACH_PASS) {
330 		if ((error = bhnd_finish_attach(sc))) {
331 			panic("bhnd_finish_attach() failed: %d", error);
332 		}
333 	}
334 }
335 
336 /*
337  * Finish any pending bus attachment operations.
338  *
339  * When attached as a SoC bus (as opposed to a bridged WiFi device), our
340  * platform devices may not be attached until later bus passes, necessitating
341  * delayed initialization on our part.
342  */
343 static int
344 bhnd_finish_attach(struct bhnd_softc *sc)
345 {
346 	struct chipc_caps	*ccaps;
347 
348 	GIANT_REQUIRED;	/* for newbus */
349 
350 	KASSERT(bus_current_pass >= BHND_FINISH_ATTACH_PASS,
351 	    ("bhnd_finish_attach() called in pass %d", bus_current_pass));
352 
353 	KASSERT(!sc->attach_done, ("duplicate call to bhnd_finish_attach()"));
354 
355 	/* Locate chipc device */
356 	if ((sc->chipc_dev = bhnd_find_chipc(sc)) == NULL) {
357 		device_printf(sc->dev, "error: ChipCommon device not found\n");
358 		return (ENXIO);
359 	}
360 
361 	ccaps = BHND_CHIPC_GET_CAPS(sc->chipc_dev);
362 
363 	/* Look for NVRAM device */
364 	if (ccaps->nvram_src != BHND_NVRAM_SRC_UNKNOWN) {
365 		if ((sc->nvram_dev = bhnd_find_nvram(sc)) == NULL) {
366 			device_printf(sc->dev,
367 			    "warning: NVRAM %s device not found\n",
368 			    bhnd_nvram_src_name(ccaps->nvram_src));
369 		}
370 	}
371 
372 	/* Look for a PMU  */
373 	if (ccaps->pmu || ccaps->pwr_ctrl) {
374 		if ((sc->pmu_dev = bhnd_find_pmu(sc)) == NULL) {
375 			device_printf(sc->dev,
376 			    "attach failed: supported PMU not found\n");
377 			return (ENXIO);
378 		}
379 	}
380 
381 	/* Mark attach as completed */
382 	sc->attach_done = true;
383 
384 	return (0);
385 }
386 
387 /* Locate the ChipCommon core. */
388 static device_t
389 bhnd_find_chipc(struct bhnd_softc *sc)
390 {
391 	device_t chipc;
392 
393         /* Make sure we're holding Giant for newbus */
394 	GIANT_REQUIRED;
395 
396 	/* chipc_dev is initialized during attachment */
397 	if (sc->attach_done) {
398 		if ((chipc = sc->chipc_dev) == NULL)
399 			return (NULL);
400 
401 		goto found;
402 	}
403 
404 	/* Locate chipc core with a core unit of 0 */
405 	chipc = bhnd_find_child(sc->dev, BHND_DEVCLASS_CC, 0);
406 	if (chipc == NULL)
407 		return (NULL);
408 
409 found:
410 	if (device_get_state(chipc) < DS_ATTACHING) {
411 		device_printf(sc->dev, "chipc found, but did not attach\n");
412 		return (NULL);
413 	}
414 
415 	return (chipc);
416 }
417 
418 /* Locate the ChipCommon core and return the device capabilities  */
419 static struct chipc_caps *
420 bhnd_find_chipc_caps(struct bhnd_softc *sc)
421 {
422 	device_t chipc;
423 
424 	if ((chipc = bhnd_find_chipc(sc)) == NULL) {
425 		device_printf(sc->dev,
426 		    "chipc unavailable; cannot fetch capabilities\n");
427 		return (NULL);
428 	}
429 
430 	return (BHND_CHIPC_GET_CAPS(chipc));
431 }
432 
433 /**
434  * Find an attached platform device on @p dev, searching first for cores
435  * matching @p classname, and if not found, searching the children of the first
436  * bhnd_chipc device on the bus.
437  *
438  * @param sc Driver state.
439  * @param chipc Attached ChipCommon device.
440  * @param classname Device class to search for.
441  *
442  * @retval device_t A matching device.
443  * @retval NULL If no matching device is found.
444  */
445 static device_t
446 bhnd_find_platform_dev(struct bhnd_softc *sc, const char *classname)
447 {
448 	device_t chipc, child;
449 
450         /* Make sure we're holding Giant for newbus */
451 	GIANT_REQUIRED;
452 
453 	/* Look for a directly-attached child */
454 	child = device_find_child(sc->dev, classname, -1);
455 	if (child != NULL)
456 		goto found;
457 
458 	/* Look for the first matching ChipCommon child */
459 	if ((chipc = bhnd_find_chipc(sc)) == NULL) {
460 		device_printf(sc->dev,
461 		    "chipc unavailable; cannot locate %s\n", classname);
462 		return (NULL);
463 	}
464 
465 	child = device_find_child(chipc, classname, -1);
466 	if (child != NULL)
467 		goto found;
468 
469 	/* Look for a parent-attached device (e.g. nexus0 -> bhnd_nvram) */
470 	child = device_find_child(device_get_parent(sc->dev), classname, -1);
471 	if (child == NULL)
472 		return (NULL);
473 
474 found:
475 	if (device_get_state(child) < DS_ATTACHING)
476 		return (NULL);
477 
478 	return (child);
479 }
480 
481 /* Locate the PMU device, if any */
482 static device_t
483 bhnd_find_pmu(struct bhnd_softc *sc)
484 {
485         /* Make sure we're holding Giant for newbus */
486 	GIANT_REQUIRED;
487 
488 	/* pmu_dev is initialized during attachment */
489 	if (sc->attach_done) {
490 		if (sc->pmu_dev == NULL)
491 			return (NULL);
492 
493 		if (device_get_state(sc->pmu_dev) < DS_ATTACHING)
494 			return (NULL);
495 
496 		return (sc->pmu_dev);
497 	}
498 
499 
500 	return (bhnd_find_platform_dev(sc, "bhnd_pmu"));
501 }
502 
503 /* Locate the NVRAM device, if any */
504 static device_t
505 bhnd_find_nvram(struct bhnd_softc *sc)
506 {
507 	struct chipc_caps *ccaps;
508 
509         /* Make sure we're holding Giant for newbus */
510 	GIANT_REQUIRED;
511 
512 
513 	/* nvram_dev is initialized during attachment */
514 	if (sc->attach_done) {
515 		if (sc->nvram_dev == NULL)
516 			return (NULL);
517 
518 		if (device_get_state(sc->nvram_dev) < DS_ATTACHING)
519 			return (NULL);
520 
521 		return (sc->nvram_dev);
522 	}
523 
524 	if ((ccaps = bhnd_find_chipc_caps(sc)) == NULL)
525 		return (NULL);
526 
527 	if (ccaps->nvram_src == BHND_NVRAM_SRC_UNKNOWN)
528 		return (NULL);
529 
530 	return (bhnd_find_platform_dev(sc, "bhnd_nvram"));
531 }
532 
533 /*
534  * Ascending comparison of bhnd device's probe order.
535  */
536 static int
537 compare_ascending_probe_order(const void *lhs, const void *rhs)
538 {
539 	device_t	ldev, rdev;
540 	int		lorder, rorder;
541 
542 	ldev = (*(const device_t *) lhs);
543 	rdev = (*(const device_t *) rhs);
544 
545 	lorder = BHND_BUS_GET_PROBE_ORDER(device_get_parent(ldev), ldev);
546 	rorder = BHND_BUS_GET_PROBE_ORDER(device_get_parent(rdev), rdev);
547 
548 	if (lorder < rorder) {
549 		return (-1);
550 	} else if (lorder > rorder) {
551 		return (1);
552 	} else {
553 		return (0);
554 	}
555 }
556 
557 /*
558  * Descending comparison of bhnd device's probe order.
559  */
560 static int
561 compare_descending_probe_order(const void *lhs, const void *rhs)
562 {
563 	return (compare_ascending_probe_order(rhs, lhs));
564 }
565 
566 /**
567  * Default bhnd(4) bus driver implementation of BHND_BUS_GET_PROBE_ORDER().
568  *
569  * This implementation determines probe ordering based on the device's class
570  * and other properties, including whether the device is serving as a host
571  * bridge.
572  */
573 int
574 bhnd_generic_get_probe_order(device_t dev, device_t child)
575 {
576 	switch (bhnd_get_class(child)) {
577 	case BHND_DEVCLASS_CC:
578 		/* Must be early enough to provide NVRAM access to the
579 		 * host bridge */
580 		return (BHND_PROBE_ROOT + BHND_PROBE_ORDER_FIRST);
581 
582 	case BHND_DEVCLASS_CC_B:
583 		/* fall through */
584 	case BHND_DEVCLASS_PMU:
585 		return (BHND_PROBE_BUS + BHND_PROBE_ORDER_EARLY);
586 
587 	case BHND_DEVCLASS_SOC_ROUTER:
588 		return (BHND_PROBE_BUS + BHND_PROBE_ORDER_LATE);
589 
590 	case BHND_DEVCLASS_SOC_BRIDGE:
591 		return (BHND_PROBE_BUS + BHND_PROBE_ORDER_LAST);
592 
593 	case BHND_DEVCLASS_CPU:
594 		return (BHND_PROBE_CPU + BHND_PROBE_ORDER_FIRST);
595 
596 	case BHND_DEVCLASS_RAM:
597 		/* fall through */
598 	case BHND_DEVCLASS_MEMC:
599 		return (BHND_PROBE_CPU + BHND_PROBE_ORDER_EARLY);
600 
601 	case BHND_DEVCLASS_NVRAM:
602 		return (BHND_PROBE_RESOURCE + BHND_PROBE_ORDER_EARLY);
603 
604 	case BHND_DEVCLASS_PCI:
605 	case BHND_DEVCLASS_PCIE:
606 	case BHND_DEVCLASS_PCCARD:
607 	case BHND_DEVCLASS_ENET:
608 	case BHND_DEVCLASS_ENET_MAC:
609 	case BHND_DEVCLASS_ENET_PHY:
610 	case BHND_DEVCLASS_WLAN:
611 	case BHND_DEVCLASS_WLAN_MAC:
612 	case BHND_DEVCLASS_WLAN_PHY:
613 	case BHND_DEVCLASS_EROM:
614 	case BHND_DEVCLASS_OTHER:
615 	case BHND_DEVCLASS_INVALID:
616 		if (bhnd_find_hostb_device(dev) == child)
617 			return (BHND_PROBE_ROOT + BHND_PROBE_ORDER_EARLY);
618 
619 		return (BHND_PROBE_DEFAULT);
620 	default:
621 		return (BHND_PROBE_DEFAULT);
622 	}
623 }
624 
625 /**
626  * Default bhnd(4) bus driver implementation of BHND_BUS_ALLOC_PMU().
627  */
628 int
629 bhnd_generic_alloc_pmu(device_t dev, device_t child)
630 {
631 	struct bhnd_softc		*sc;
632 	struct bhnd_resource		*br;
633 	struct chipc_caps		*ccaps;
634 	struct bhnd_devinfo		*dinfo;
635 	struct bhnd_core_pmu_info	*pm;
636 	struct resource_list		*rl;
637 	struct resource_list_entry	*rle;
638 	device_t			 pmu_dev;
639 	bhnd_addr_t			 r_addr;
640 	bhnd_size_t			 r_size;
641 	bus_size_t			 pmu_regs;
642 	int				 error;
643 
644 	GIANT_REQUIRED;	/* for newbus */
645 
646 	sc = device_get_softc(dev);
647 	dinfo = device_get_ivars(child);
648 	pmu_regs = BHND_CLK_CTL_ST;
649 
650 	if ((ccaps = bhnd_find_chipc_caps(sc)) == NULL) {
651 		device_printf(sc->dev, "alloc_pmu failed: chipc "
652 		    "capabilities unavailable\n");
653 		return (ENXIO);
654 	}
655 
656 	if ((pmu_dev = bhnd_find_pmu(sc)) == NULL) {
657 		device_printf(sc->dev,
658 		    "pmu unavailable; cannot allocate request state\n");
659 		return (ENXIO);
660 	}
661 
662 	/* already allocated? */
663 	if (dinfo->pmu_info != NULL) {
664 		panic("duplicate PMU allocation for %s",
665 		    device_get_nameunit(child));
666 	}
667 
668 	/* Determine address+size of the core's PMU register block */
669 	error = bhnd_get_region_addr(child, BHND_PORT_DEVICE, 0, 0, &r_addr,
670 	    &r_size);
671 	if (error) {
672 		device_printf(sc->dev, "error fetching register block info for "
673 		    "%s: %d\n", device_get_nameunit(child), error);
674 		return (error);
675 	}
676 
677 	if (r_size < (pmu_regs + sizeof(uint32_t))) {
678 		device_printf(sc->dev, "pmu offset %#jx would overrun %s "
679 		    "register block\n", (uintmax_t)pmu_regs,
680 		    device_get_nameunit(child));
681 		return (ENODEV);
682 	}
683 
684 	/* Locate actual resource containing the core's register block */
685 	if ((rl = BUS_GET_RESOURCE_LIST(dev, child)) == NULL) {
686 		device_printf(dev, "NULL resource list returned for %s\n",
687 		    device_get_nameunit(child));
688 		return (ENXIO);
689 	}
690 
691 	if ((rle = resource_list_find(rl, SYS_RES_MEMORY, 0)) == NULL) {
692 		device_printf(dev, "cannot locate core register resource "
693 		    "for %s\n", device_get_nameunit(child));
694 		return (ENXIO);
695 	}
696 
697 	if (rle->res == NULL) {
698 		device_printf(dev, "core register resource unallocated for "
699 		    "%s\n", device_get_nameunit(child));
700 		return (ENXIO);
701 	}
702 
703 	if (r_addr+pmu_regs < rman_get_start(rle->res) ||
704 	    r_addr+pmu_regs >= rman_get_end(rle->res))
705 	{
706 		device_printf(dev, "core register resource does not map PMU "
707 		    "registers at %#jx\n for %s\n", r_addr+pmu_regs,
708 		    device_get_nameunit(child));
709 		return (ENXIO);
710 	}
711 
712 	/* Adjust PMU register offset relative to the actual start address
713 	 * of the core's register block allocation.
714 	 *
715 	 * XXX: The saved offset will be invalid if bus_adjust_resource is
716 	 * used to modify the resource's start address.
717 	 */
718 	if (rman_get_start(rle->res) > r_addr)
719 		pmu_regs -= rman_get_start(rle->res) - r_addr;
720 	else
721 		pmu_regs -= r_addr - rman_get_start(rle->res);
722 
723 	/* Allocate and initialize PMU info */
724 	br = malloc(sizeof(struct bhnd_resource), M_BHND, M_NOWAIT);
725 	if (br == NULL)
726 		return (ENOMEM);
727 
728 	br->res = rle->res;
729 	br->direct = ((rman_get_flags(rle->res) & RF_ACTIVE) != 0);
730 
731 	pm = malloc(sizeof(*dinfo->pmu_info), M_BHND, M_NOWAIT);
732 	if (pm == NULL) {
733 		free(br, M_BHND);
734 		return (ENOMEM);
735 	}
736 	pm->pm_dev = child;
737 	pm->pm_pmu = pmu_dev;
738 	pm->pm_res = br;
739 	pm->pm_regs = pmu_regs;
740 
741 	dinfo->pmu_info = pm;
742 	return (0);
743 }
744 
745 /**
746  * Default bhnd(4) bus driver implementation of BHND_BUS_RELEASE_PMU().
747  */
748 int
749 bhnd_generic_release_pmu(device_t dev, device_t child)
750 {
751 	struct bhnd_softc		*sc;
752 	struct bhnd_devinfo		*dinfo;
753 	device_t			 pmu;
754 	int				 error;
755 
756 	GIANT_REQUIRED;	/* for newbus */
757 
758 	sc = device_get_softc(dev);
759 	dinfo = device_get_ivars(child);
760 
761 	if ((pmu = bhnd_find_pmu(sc)) == NULL) {
762 		device_printf(sc->dev,
763 		    "pmu unavailable; cannot release request state\n");
764 		return (ENXIO);
765 	}
766 
767 	/* dispatch release request */
768 	if (dinfo->pmu_info == NULL)
769 		panic("pmu over-release for %s", device_get_nameunit(child));
770 
771 	if ((error = BHND_PMU_CORE_RELEASE(pmu, dinfo->pmu_info)))
772 		return (error);
773 
774 	/* free PMU info */
775 	free(dinfo->pmu_info->pm_res, M_BHND);
776 	free(dinfo->pmu_info, M_BHND);
777 	dinfo->pmu_info = NULL;
778 
779 	return (0);
780 }
781 
782 /**
783  * Default bhnd(4) bus driver implementation of BHND_BUS_REQUEST_CLOCK().
784  */
785 int
786 bhnd_generic_request_clock(device_t dev, device_t child, bhnd_clock clock)
787 {
788 	struct bhnd_softc		*sc;
789 	struct bhnd_devinfo		*dinfo;
790 	struct bhnd_core_pmu_info	*pm;
791 
792 	sc = device_get_softc(dev);
793 	dinfo = device_get_ivars(child);
794 
795 	if ((pm = dinfo->pmu_info) == NULL)
796 		panic("no active PMU request state");
797 
798 	/* dispatch request to PMU */
799 	return (BHND_PMU_CORE_REQ_CLOCK(pm->pm_pmu, pm, clock));
800 }
801 
802 /**
803  * Default bhnd(4) bus driver implementation of BHND_BUS_ENABLE_CLOCKS().
804  */
805 int
806 bhnd_generic_enable_clocks(device_t dev, device_t child, uint32_t clocks)
807 {
808 	struct bhnd_softc		*sc;
809 	struct bhnd_devinfo		*dinfo;
810 	struct bhnd_core_pmu_info	*pm;
811 
812 	sc = device_get_softc(dev);
813 	dinfo = device_get_ivars(child);
814 
815 	if ((pm = dinfo->pmu_info) == NULL)
816 		panic("no active PMU request state");
817 
818 	/* dispatch request to PMU */
819 	return (BHND_PMU_CORE_EN_CLOCKS(pm->pm_pmu, pm, clocks));
820 }
821 
822 /**
823  * Default bhnd(4) bus driver implementation of BHND_BUS_REQUEST_EXT_RSRC().
824  */
825 int
826 bhnd_generic_request_ext_rsrc(device_t dev, device_t child, u_int rsrc)
827 {
828 	struct bhnd_softc		*sc;
829 	struct bhnd_devinfo		*dinfo;
830 	struct bhnd_core_pmu_info	*pm;
831 
832 	sc = device_get_softc(dev);
833 	dinfo = device_get_ivars(child);
834 
835 	if ((pm = dinfo->pmu_info) == NULL)
836 		panic("no active PMU request state");
837 
838 	/* dispatch request to PMU */
839 	return (BHND_PMU_CORE_REQ_EXT_RSRC(pm->pm_pmu, pm, rsrc));
840 }
841 
842 /**
843  * Default bhnd(4) bus driver implementation of BHND_BUS_RELEASE_EXT_RSRC().
844  */
845 int
846 bhnd_generic_release_ext_rsrc(device_t dev, device_t child, u_int rsrc)
847 {
848 	struct bhnd_softc		*sc;
849 	struct bhnd_devinfo		*dinfo;
850 	struct bhnd_core_pmu_info	*pm;
851 
852 	sc = device_get_softc(dev);
853 	dinfo = device_get_ivars(child);
854 
855 	if ((pm = dinfo->pmu_info) == NULL)
856 		panic("no active PMU request state");
857 
858 	/* dispatch request to PMU */
859 	return (BHND_PMU_CORE_RELEASE_EXT_RSRC(pm->pm_pmu, pm, rsrc));
860 }
861 
862 
863 /**
864  * Default bhnd(4) bus driver implementation of BHND_BUS_IS_REGION_VALID().
865  *
866  * This implementation assumes that port and region numbers are 0-indexed and
867  * are allocated non-sparsely, using BHND_BUS_GET_PORT_COUNT() and
868  * BHND_BUS_GET_REGION_COUNT() to determine if @p port and @p region fall
869  * within the defined range.
870  */
871 static bool
872 bhnd_generic_is_region_valid(device_t dev, device_t child,
873     bhnd_port_type type, u_int port, u_int region)
874 {
875 	if (port >= bhnd_get_port_count(child, type))
876 		return (false);
877 
878 	if (region >= bhnd_get_region_count(child, type, port))
879 		return (false);
880 
881 	return (true);
882 }
883 
884 /**
885  * Default bhnd(4) bus driver implementation of BHND_BUS_GET_NVRAM_VAR().
886  *
887  * This implementation searches @p dev for a usable NVRAM child device.
888  *
889  * If no usable child device is found on @p dev, the request is delegated to
890  * the BHND_BUS_GET_NVRAM_VAR() method on the parent of @p dev.
891  */
892 int
893 bhnd_generic_get_nvram_var(device_t dev, device_t child, const char *name,
894     void *buf, size_t *size, bhnd_nvram_type type)
895 {
896 	struct bhnd_softc	*sc;
897 	device_t		 nvram, parent;
898 
899 	sc = device_get_softc(dev);
900 
901 	/* If a NVRAM device is available, consult it first */
902 	if ((nvram = bhnd_find_nvram(sc)) != NULL)
903 		return BHND_NVRAM_GETVAR(nvram, name, buf, size, type);
904 
905 	/* Otherwise, try to delegate to parent */
906 	if ((parent = device_get_parent(dev)) == NULL)
907 		return (ENODEV);
908 
909 	return (BHND_BUS_GET_NVRAM_VAR(device_get_parent(dev), child,
910 	    name, buf, size, type));
911 }
912 
913 /**
914  * Default bhnd(4) bus driver implementation of BUS_PRINT_CHILD().
915  *
916  * This implementation requests the device's struct resource_list via
917  * BUS_GET_RESOURCE_LIST.
918  */
919 int
920 bhnd_generic_print_child(device_t dev, device_t child)
921 {
922 	struct resource_list	*rl;
923 	int			retval = 0;
924 
925 	retval += bus_print_child_header(dev, child);
926 
927 	rl = BUS_GET_RESOURCE_LIST(dev, child);
928 
929 
930 	if (rl != NULL) {
931 		retval += resource_list_print_type(rl, "mem", SYS_RES_MEMORY,
932 		    "%#jx");
933 
934 		retval += resource_list_print_type(rl, "irq", SYS_RES_IRQ,
935 		    "%#jd");
936 	}
937 
938 	retval += printf(" at core %u", bhnd_get_core_index(child));
939 
940 	retval += bus_print_child_domain(dev, child);
941 	retval += bus_print_child_footer(dev, child);
942 
943 	return (retval);
944 }
945 
946 /**
947  * Default bhnd(4) bus driver implementation of BUS_PROBE_NOMATCH().
948  *
949  * This implementation requests the device's struct resource_list via
950  * BUS_GET_RESOURCE_LIST.
951  */
952 void
953 bhnd_generic_probe_nomatch(device_t dev, device_t child)
954 {
955 	struct resource_list		*rl;
956 	const struct bhnd_nomatch	*nm;
957 	bool				 report;
958 
959 	/* Fetch reporting configuration for this device */
960 	report = true;
961 	for (nm = bhnd_nomatch_table; nm->device != BHND_COREID_INVALID; nm++) {
962 		if (nm->vendor != bhnd_get_vendor(child))
963 			continue;
964 
965 		if (nm->device != bhnd_get_device(child))
966 			continue;
967 
968 		report = false;
969 		if (bootverbose && nm->if_verbose)
970 			report = true;
971 		break;
972 	}
973 
974 	if (!report)
975 		return;
976 
977 	/* Print the non-matched device info */
978 	device_printf(dev, "<%s %s>", bhnd_get_vendor_name(child),
979 		bhnd_get_device_name(child));
980 
981 	rl = BUS_GET_RESOURCE_LIST(dev, child);
982 	if (rl != NULL) {
983 		resource_list_print_type(rl, "mem", SYS_RES_MEMORY, "%#jx");
984 		resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%#jd");
985 	}
986 
987 	printf(" at core %u (no driver attached)\n",
988 	    bhnd_get_core_index(child));
989 }
990 
991 /**
992  * Default implementation of BUS_CHILD_PNPINFO_STR().
993  */
994 static int
995 bhnd_child_pnpinfo_str(device_t dev, device_t child, char *buf,
996     size_t buflen)
997 {
998 	if (device_get_parent(child) != dev) {
999 		return (BUS_CHILD_PNPINFO_STR(device_get_parent(dev), child,
1000 		    buf, buflen));
1001 	}
1002 
1003 	snprintf(buf, buflen, "vendor=0x%hx device=0x%hx rev=0x%hhx",
1004 	    bhnd_get_vendor(child), bhnd_get_device(child),
1005 	    bhnd_get_hwrev(child));
1006 
1007 	return (0);
1008 }
1009 
1010 /**
1011  * Default implementation of BUS_CHILD_LOCATION_STR().
1012  */
1013 static int
1014 bhnd_child_location_str(device_t dev, device_t child, char *buf,
1015     size_t buflen)
1016 {
1017 	bhnd_addr_t	addr;
1018 	bhnd_size_t	size;
1019 
1020 	if (device_get_parent(child) != dev) {
1021 		return (BUS_CHILD_LOCATION_STR(device_get_parent(dev), child,
1022 		    buf, buflen));
1023 	}
1024 
1025 
1026 	if (bhnd_get_region_addr(child, BHND_PORT_DEVICE, 0, 0, &addr, &size)) {
1027 		/* No device default port/region */
1028 		if (buflen > 0)
1029 			*buf = '\0';
1030 		return (0);
1031 	}
1032 
1033 	snprintf(buf, buflen, "port0.0=0x%llx", (unsigned long long) addr);
1034 	return (0);
1035 }
1036 
1037 /**
1038  * Default bhnd(4) bus driver implementation of BUS_ADD_CHILD().
1039  *
1040  * This implementation manages internal bhnd(4) state, and must be called
1041  * by subclassing drivers.
1042  */
1043 device_t
1044 bhnd_generic_add_child(device_t dev, u_int order, const char *name, int unit)
1045 {
1046 	struct bhnd_devinfo	*dinfo;
1047 	device_t		 child;
1048 
1049 	child = device_add_child_ordered(dev, order, name, unit);
1050 	if (child == NULL)
1051 		return (NULL);
1052 
1053 	if ((dinfo = BHND_BUS_ALLOC_DEVINFO(dev)) == NULL) {
1054 		device_delete_child(dev, child);
1055 		return (NULL);
1056 	}
1057 
1058 	device_set_ivars(child, dinfo);
1059 
1060 	return (child);
1061 }
1062 
1063 /**
1064  * Default bhnd(4) bus driver implementation of BHND_BUS_CHILD_ADDED().
1065  *
1066  * This implementation manages internal bhnd(4) state, and must be called
1067  * by subclassing drivers.
1068  */
1069 void
1070 bhnd_generic_child_added(device_t dev, device_t child)
1071 {
1072 }
1073 
1074 /**
1075  * Default bhnd(4) bus driver implementation of BUS_CHILD_DELETED().
1076  *
1077  * This implementation manages internal bhnd(4) state, and must be called
1078  * by subclassing drivers.
1079  */
1080 void
1081 bhnd_generic_child_deleted(device_t dev, device_t child)
1082 {
1083 	struct bhnd_softc	*sc;
1084 	struct bhnd_devinfo	*dinfo;
1085 
1086 	sc = device_get_softc(dev);
1087 
1088 	/* Free device info */
1089 	if ((dinfo = device_get_ivars(child)) != NULL) {
1090 		if (dinfo->pmu_info != NULL) {
1091 			/* Releasing PMU requests automatically would be nice,
1092 			 * but we can't reference per-core PMU register
1093 			 * resource after driver detach */
1094 			panic("%s leaked device pmu state\n",
1095 			    device_get_nameunit(child));
1096 		}
1097 
1098 		BHND_BUS_FREE_DEVINFO(dev, dinfo);
1099 	}
1100 
1101 	/* Clean up platform device references */
1102 	if (sc->chipc_dev == child) {
1103 		sc->chipc_dev = NULL;
1104 	} else if (sc->nvram_dev == child) {
1105 		sc->nvram_dev = NULL;
1106 	} else if (sc->pmu_dev == child) {
1107 		sc->pmu_dev = NULL;
1108 	}
1109 }
1110 
1111 /**
1112  * Helper function for implementing BUS_SUSPEND_CHILD().
1113  *
1114  * TODO: Power management
1115  *
1116  * If @p child is not a direct child of @p dev, suspension is delegated to
1117  * the @p dev parent.
1118  */
1119 int
1120 bhnd_generic_suspend_child(device_t dev, device_t child)
1121 {
1122 	if (device_get_parent(child) != dev)
1123 		BUS_SUSPEND_CHILD(device_get_parent(dev), child);
1124 
1125 	return bus_generic_suspend_child(dev, child);
1126 }
1127 
1128 /**
1129  * Helper function for implementing BUS_RESUME_CHILD().
1130  *
1131  * TODO: Power management
1132  *
1133  * If @p child is not a direct child of @p dev, suspension is delegated to
1134  * the @p dev parent.
1135  */
1136 int
1137 bhnd_generic_resume_child(device_t dev, device_t child)
1138 {
1139 	if (device_get_parent(child) != dev)
1140 		BUS_RESUME_CHILD(device_get_parent(dev), child);
1141 
1142 	return bus_generic_resume_child(dev, child);
1143 }
1144 
1145 /*
1146  * Delegate all indirect I/O to the parent device. When inherited by
1147  * non-bridged bus implementations, resources will never be marked as
1148  * indirect, and these methods will never be called.
1149  */
1150 #define	BHND_IO_READ(_type, _name, _method)				\
1151 static _type								\
1152 bhnd_read_ ## _name (device_t dev, device_t child,			\
1153     struct bhnd_resource *r, bus_size_t offset)				\
1154 {									\
1155 	return (BHND_BUS_READ_ ## _method(				\
1156 		    device_get_parent(dev), child, r, offset));		\
1157 }
1158 
1159 #define	BHND_IO_WRITE(_type, _name, _method)				\
1160 static void								\
1161 bhnd_write_ ## _name (device_t dev, device_t child,			\
1162     struct bhnd_resource *r, bus_size_t offset, _type value)		\
1163 {									\
1164 	return (BHND_BUS_WRITE_ ## _method(				\
1165 		    device_get_parent(dev), child, r, offset,		\
1166 		    value));	\
1167 }
1168 
1169 #define	BHND_IO_MISC(_type, _op, _method)				\
1170 static void								\
1171 bhnd_ ## _op (device_t dev, device_t child,				\
1172     struct bhnd_resource *r, bus_size_t offset, _type datap,		\
1173     bus_size_t count)							\
1174 {									\
1175 	BHND_BUS_ ## _method(device_get_parent(dev), child, r,		\
1176 	    offset, datap, count);					\
1177 }
1178 
1179 #define	BHND_IO_METHODS(_type, _size)					\
1180 	BHND_IO_READ(_type, _size, _size)				\
1181 	BHND_IO_WRITE(_type, _size, _size)				\
1182 									\
1183 	BHND_IO_READ(_type, stream_ ## _size, STREAM_ ## _size)		\
1184 	BHND_IO_WRITE(_type, stream_ ## _size, STREAM_ ## _size)	\
1185 									\
1186 	BHND_IO_MISC(_type*, read_multi_ ## _size,			\
1187 	    READ_MULTI_ ## _size)					\
1188 	BHND_IO_MISC(_type*, write_multi_ ## _size,			\
1189 	    WRITE_MULTI_ ## _size)					\
1190 									\
1191 	BHND_IO_MISC(_type*, read_multi_stream_ ## _size,		\
1192 	   READ_MULTI_STREAM_ ## _size)					\
1193 	BHND_IO_MISC(_type*, write_multi_stream_ ## _size,		\
1194 	   WRITE_MULTI_STREAM_ ## _size)				\
1195 									\
1196 	BHND_IO_MISC(_type, set_multi_ ## _size, SET_MULTI_ ## _size)	\
1197 	BHND_IO_MISC(_type, set_region_ ## _size, SET_REGION_ ## _size)	\
1198 									\
1199 	BHND_IO_MISC(_type*, read_region_ ## _size,			\
1200 	    READ_REGION_ ## _size)					\
1201 	BHND_IO_MISC(_type*, write_region_ ## _size,			\
1202 	    WRITE_REGION_ ## _size)					\
1203 									\
1204 	BHND_IO_MISC(_type*, read_region_stream_ ## _size,		\
1205 	    READ_REGION_STREAM_ ## _size)				\
1206 	BHND_IO_MISC(_type*, write_region_stream_ ## _size,		\
1207 	    WRITE_REGION_STREAM_ ## _size)				\
1208 
1209 BHND_IO_METHODS(uint8_t, 1);
1210 BHND_IO_METHODS(uint16_t, 2);
1211 BHND_IO_METHODS(uint32_t, 4);
1212 
1213 static void
1214 bhnd_barrier(device_t dev, device_t child, struct bhnd_resource *r,
1215     bus_size_t offset, bus_size_t length, int flags)
1216 {
1217 	BHND_BUS_BARRIER(device_get_parent(dev), child, r, offset, length,
1218 	    flags);
1219 }
1220 
1221 static device_method_t bhnd_methods[] = {
1222 	/* Device interface */ \
1223 	DEVMETHOD(device_attach,		bhnd_generic_attach),
1224 	DEVMETHOD(device_detach,		bhnd_generic_detach),
1225 	DEVMETHOD(device_shutdown,		bhnd_generic_shutdown),
1226 	DEVMETHOD(device_suspend,		bhnd_generic_suspend),
1227 	DEVMETHOD(device_resume,		bhnd_generic_resume),
1228 
1229 	/* Bus interface */
1230 	DEVMETHOD(bus_new_pass,			bhnd_new_pass),
1231 	DEVMETHOD(bus_add_child,		bhnd_generic_add_child),
1232 	DEVMETHOD(bus_child_deleted,		bhnd_generic_child_deleted),
1233 	DEVMETHOD(bus_probe_nomatch,		bhnd_generic_probe_nomatch),
1234 	DEVMETHOD(bus_print_child,		bhnd_generic_print_child),
1235 	DEVMETHOD(bus_child_pnpinfo_str,	bhnd_child_pnpinfo_str),
1236 	DEVMETHOD(bus_child_location_str,	bhnd_child_location_str),
1237 
1238 	DEVMETHOD(bus_suspend_child,		bhnd_generic_suspend_child),
1239 	DEVMETHOD(bus_resume_child,		bhnd_generic_resume_child),
1240 
1241 	DEVMETHOD(bus_set_resource,		bus_generic_rl_set_resource),
1242 	DEVMETHOD(bus_get_resource,		bus_generic_rl_get_resource),
1243 	DEVMETHOD(bus_delete_resource,		bus_generic_rl_delete_resource),
1244 	DEVMETHOD(bus_alloc_resource,		bus_generic_rl_alloc_resource),
1245 	DEVMETHOD(bus_adjust_resource,		bus_generic_adjust_resource),
1246 	DEVMETHOD(bus_release_resource,		bus_generic_rl_release_resource),
1247 	DEVMETHOD(bus_activate_resource,	bus_generic_activate_resource),
1248 	DEVMETHOD(bus_deactivate_resource,	bus_generic_deactivate_resource),
1249 
1250 	DEVMETHOD(bus_setup_intr,		bus_generic_setup_intr),
1251 	DEVMETHOD(bus_teardown_intr,		bus_generic_teardown_intr),
1252 	DEVMETHOD(bus_config_intr,		bus_generic_config_intr),
1253 	DEVMETHOD(bus_bind_intr,		bus_generic_bind_intr),
1254 	DEVMETHOD(bus_describe_intr,		bus_generic_describe_intr),
1255 
1256 	DEVMETHOD(bus_get_dma_tag,		bus_generic_get_dma_tag),
1257 
1258 	/* BHND interface */
1259 	DEVMETHOD(bhnd_bus_get_chipid,		bhnd_bus_generic_get_chipid),
1260 	DEVMETHOD(bhnd_bus_is_hw_disabled,	bhnd_bus_generic_is_hw_disabled),
1261 	DEVMETHOD(bhnd_bus_read_board_info,	bhnd_bus_generic_read_board_info),
1262 
1263 	DEVMETHOD(bhnd_bus_get_probe_order,	bhnd_generic_get_probe_order),
1264 
1265 	DEVMETHOD(bhnd_bus_alloc_pmu,		bhnd_generic_alloc_pmu),
1266 	DEVMETHOD(bhnd_bus_release_pmu,		bhnd_generic_release_pmu),
1267 	DEVMETHOD(bhnd_bus_request_clock,	bhnd_generic_request_clock),
1268 	DEVMETHOD(bhnd_bus_enable_clocks,	bhnd_generic_enable_clocks),
1269 	DEVMETHOD(bhnd_bus_request_ext_rsrc,	bhnd_generic_request_ext_rsrc),
1270 	DEVMETHOD(bhnd_bus_release_ext_rsrc,	bhnd_generic_release_ext_rsrc),
1271 
1272 	DEVMETHOD(bhnd_bus_child_added,		bhnd_generic_child_added),
1273 	DEVMETHOD(bhnd_bus_is_region_valid,	bhnd_generic_is_region_valid),
1274 	DEVMETHOD(bhnd_bus_get_nvram_var,	bhnd_generic_get_nvram_var),
1275 
1276 	/* BHND interface (bus I/O) */
1277 	DEVMETHOD(bhnd_bus_read_1,		bhnd_read_1),
1278 	DEVMETHOD(bhnd_bus_read_2,		bhnd_read_2),
1279 	DEVMETHOD(bhnd_bus_read_4,		bhnd_read_4),
1280 	DEVMETHOD(bhnd_bus_write_1,		bhnd_write_1),
1281 	DEVMETHOD(bhnd_bus_write_2,		bhnd_write_2),
1282 	DEVMETHOD(bhnd_bus_write_4,		bhnd_write_4),
1283 
1284 	DEVMETHOD(bhnd_bus_read_stream_1,	bhnd_read_stream_1),
1285 	DEVMETHOD(bhnd_bus_read_stream_2,	bhnd_read_stream_2),
1286 	DEVMETHOD(bhnd_bus_read_stream_4,	bhnd_read_stream_4),
1287 	DEVMETHOD(bhnd_bus_write_stream_1,	bhnd_write_stream_1),
1288 	DEVMETHOD(bhnd_bus_write_stream_2,	bhnd_write_stream_2),
1289 	DEVMETHOD(bhnd_bus_write_stream_4,	bhnd_write_stream_4),
1290 
1291 	DEVMETHOD(bhnd_bus_read_multi_1,	bhnd_read_multi_1),
1292 	DEVMETHOD(bhnd_bus_read_multi_2,	bhnd_read_multi_2),
1293 	DEVMETHOD(bhnd_bus_read_multi_4,	bhnd_read_multi_4),
1294 	DEVMETHOD(bhnd_bus_write_multi_1,	bhnd_write_multi_1),
1295 	DEVMETHOD(bhnd_bus_write_multi_2,	bhnd_write_multi_2),
1296 	DEVMETHOD(bhnd_bus_write_multi_4,	bhnd_write_multi_4),
1297 
1298 	DEVMETHOD(bhnd_bus_read_multi_stream_1,	bhnd_read_multi_stream_1),
1299 	DEVMETHOD(bhnd_bus_read_multi_stream_2,	bhnd_read_multi_stream_2),
1300 	DEVMETHOD(bhnd_bus_read_multi_stream_4,	bhnd_read_multi_stream_4),
1301 	DEVMETHOD(bhnd_bus_write_multi_stream_1,bhnd_write_multi_stream_1),
1302 	DEVMETHOD(bhnd_bus_write_multi_stream_2,bhnd_write_multi_stream_2),
1303 	DEVMETHOD(bhnd_bus_write_multi_stream_4,bhnd_write_multi_stream_4),
1304 
1305 	DEVMETHOD(bhnd_bus_set_multi_1,		bhnd_set_multi_1),
1306 	DEVMETHOD(bhnd_bus_set_multi_2,		bhnd_set_multi_2),
1307 	DEVMETHOD(bhnd_bus_set_multi_4,		bhnd_set_multi_4),
1308 
1309 	DEVMETHOD(bhnd_bus_set_region_1,	bhnd_set_region_1),
1310 	DEVMETHOD(bhnd_bus_set_region_2,	bhnd_set_region_2),
1311 	DEVMETHOD(bhnd_bus_set_region_4,	bhnd_set_region_4),
1312 
1313 	DEVMETHOD(bhnd_bus_read_region_1,	bhnd_read_region_1),
1314 	DEVMETHOD(bhnd_bus_read_region_2,	bhnd_read_region_2),
1315 	DEVMETHOD(bhnd_bus_read_region_4,	bhnd_read_region_4),
1316 	DEVMETHOD(bhnd_bus_write_region_1,	bhnd_write_region_1),
1317 	DEVMETHOD(bhnd_bus_write_region_2,	bhnd_write_region_2),
1318 	DEVMETHOD(bhnd_bus_write_region_4,	bhnd_write_region_4),
1319 
1320 	DEVMETHOD(bhnd_bus_read_region_stream_1,bhnd_read_region_stream_1),
1321 	DEVMETHOD(bhnd_bus_read_region_stream_2,bhnd_read_region_stream_2),
1322 	DEVMETHOD(bhnd_bus_read_region_stream_4,bhnd_read_region_stream_4),
1323 	DEVMETHOD(bhnd_bus_write_region_stream_1, bhnd_write_region_stream_1),
1324 	DEVMETHOD(bhnd_bus_write_region_stream_2, bhnd_write_region_stream_2),
1325 	DEVMETHOD(bhnd_bus_write_region_stream_4, bhnd_write_region_stream_4),
1326 
1327 	DEVMETHOD(bhnd_bus_barrier,			bhnd_barrier),
1328 
1329 	DEVMETHOD_END
1330 };
1331 
1332 devclass_t bhnd_devclass;	/**< bhnd bus. */
1333 devclass_t bhnd_hostb_devclass;	/**< bhnd bus host bridge. */
1334 devclass_t bhnd_nvram_devclass;	/**< bhnd NVRAM device */
1335 
1336 DEFINE_CLASS_0(bhnd, bhnd_driver, bhnd_methods, sizeof(struct bhnd_softc));
1337 MODULE_VERSION(bhnd, 1);
1338