xref: /freebsd/sys/dev/bhnd/bhnd.h (revision 2ff63af9b88c7413b7d71715b5532625752a248e)
14ad7e9b0SAdrian Chadd /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
36e778a7eSPedro F. Giffuni  *
48e35bf83SLandon J. Fuller  * Copyright (c) 2015-2016 Landon Fuller <landon@landonf.org>
58e35bf83SLandon J. Fuller  * Copyright (c) 2017 The FreeBSD Foundation
64ad7e9b0SAdrian Chadd  * All rights reserved.
74ad7e9b0SAdrian Chadd  *
88e35bf83SLandon J. Fuller  * Portions of this software were developed by Landon Fuller
98e35bf83SLandon J. Fuller  * under sponsorship from the FreeBSD Foundation.
108e35bf83SLandon J. Fuller  *
114ad7e9b0SAdrian Chadd  * Redistribution and use in source and binary forms, with or without
124ad7e9b0SAdrian Chadd  * modification, are permitted provided that the following conditions
134ad7e9b0SAdrian Chadd  * are met:
144ad7e9b0SAdrian Chadd  * 1. Redistributions of source code must retain the above copyright
154ad7e9b0SAdrian Chadd  *    notice, this list of conditions and the following disclaimer,
164ad7e9b0SAdrian Chadd  *    without modification.
174ad7e9b0SAdrian Chadd  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
184ad7e9b0SAdrian Chadd  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
194ad7e9b0SAdrian Chadd  *    redistribution must be conditioned upon including a substantially
204ad7e9b0SAdrian Chadd  *    similar Disclaimer requirement for further binary redistribution.
214ad7e9b0SAdrian Chadd  *
224ad7e9b0SAdrian Chadd  * NO WARRANTY
234ad7e9b0SAdrian Chadd  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
244ad7e9b0SAdrian Chadd  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
254ad7e9b0SAdrian Chadd  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
264ad7e9b0SAdrian Chadd  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
274ad7e9b0SAdrian Chadd  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
284ad7e9b0SAdrian Chadd  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
294ad7e9b0SAdrian Chadd  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
304ad7e9b0SAdrian Chadd  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
314ad7e9b0SAdrian Chadd  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
324ad7e9b0SAdrian Chadd  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
334ad7e9b0SAdrian Chadd  * THE POSSIBILITY OF SUCH DAMAGES.
344ad7e9b0SAdrian Chadd  *
354ad7e9b0SAdrian Chadd  */
364ad7e9b0SAdrian Chadd 
374ad7e9b0SAdrian Chadd #ifndef _BHND_BHND_H_
384ad7e9b0SAdrian Chadd #define _BHND_BHND_H_
394ad7e9b0SAdrian Chadd 
408e35bf83SLandon J. Fuller #include <sys/param.h>
414ad7e9b0SAdrian Chadd #include <sys/bus.h>
428e35bf83SLandon J. Fuller #include <sys/lock.h>
438e35bf83SLandon J. Fuller #include <sys/mutex.h>
444ad7e9b0SAdrian Chadd 
454ad7e9b0SAdrian Chadd #include <machine/bus.h>
464ad7e9b0SAdrian Chadd 
474ad7e9b0SAdrian Chadd #include "bhnd_ids.h"
484ad7e9b0SAdrian Chadd #include "bhnd_types.h"
49111d7cb2SLandon J. Fuller #include "bhnd_erom_types.h"
50fb403678SAdrian Chadd #include "bhnd_debug.h"
514ad7e9b0SAdrian Chadd #include "bhnd_bus_if.h"
525ad9ac03SAdrian Chadd #include "bhnd_match.h"
534ad7e9b0SAdrian Chadd 
54fdedcd9fSLandon J. Fuller #include "nvram/bhnd_nvram.h"
55fdedcd9fSLandon J. Fuller 
569bb95906SLandon J. Fuller #define	BHND_CHIPID_MAX_NAMELEN	32	/**< maximum buffer required for a
579bb95906SLandon J. Fuller 					     bhnd_format_chip_id() */
589bb95906SLandon J. Fuller 
594ad7e9b0SAdrian Chadd /**
604ad7e9b0SAdrian Chadd  * bhnd child instance variables
614ad7e9b0SAdrian Chadd  */
624ad7e9b0SAdrian Chadd enum bhnd_device_vars {
634ad7e9b0SAdrian Chadd 	BHND_IVAR_VENDOR,	/**< Designer's JEP-106 manufacturer ID. */
644ad7e9b0SAdrian Chadd 	BHND_IVAR_DEVICE,	/**< Part number */
654ad7e9b0SAdrian Chadd 	BHND_IVAR_HWREV,	/**< Core revision */
664ad7e9b0SAdrian Chadd 	BHND_IVAR_DEVICE_CLASS,	/**< Core class (@sa bhnd_devclass_t) */
674ad7e9b0SAdrian Chadd 	BHND_IVAR_VENDOR_NAME,	/**< Core vendor name */
684ad7e9b0SAdrian Chadd 	BHND_IVAR_DEVICE_NAME,	/**< Core name */
694ad7e9b0SAdrian Chadd 	BHND_IVAR_CORE_INDEX,	/**< Bus-assigned core number */
704ad7e9b0SAdrian Chadd 	BHND_IVAR_CORE_UNIT,	/**< Bus-assigned core unit number,
714ad7e9b0SAdrian Chadd 				     assigned sequentially (starting at 0) for
724ad7e9b0SAdrian Chadd 				     each vendor/device pair. */
738a03f98aSLandon J. Fuller 	BHND_IVAR_PMU_INFO,	/**< Internal bus-managed PMU state */
744ad7e9b0SAdrian Chadd };
754ad7e9b0SAdrian Chadd 
764ad7e9b0SAdrian Chadd /**
774ad7e9b0SAdrian Chadd  * bhnd device probe priority bands.
784ad7e9b0SAdrian Chadd  */
794ad7e9b0SAdrian Chadd enum {
804ad7e9b0SAdrian Chadd 	BHND_PROBE_ROOT         = 0,    /**< Nexus or host bridge */
81db4fcadfSConrad Meyer 	BHND_PROBE_BUS		= 1000,	/**< Buses and bridges */
824ad7e9b0SAdrian Chadd 	BHND_PROBE_CPU		= 2000,	/**< CPU devices */
834ad7e9b0SAdrian Chadd 	BHND_PROBE_INTERRUPT	= 3000,	/**< Interrupt controllers. */
844ad7e9b0SAdrian Chadd 	BHND_PROBE_TIMER	= 4000,	/**< Timers and clocks. */
854ad7e9b0SAdrian Chadd 	BHND_PROBE_RESOURCE	= 5000,	/**< Resource discovery (including NVRAM/SPROM) */
864ad7e9b0SAdrian Chadd 	BHND_PROBE_DEFAULT	= 6000,	/**< Default device priority */
874ad7e9b0SAdrian Chadd };
884ad7e9b0SAdrian Chadd 
894ad7e9b0SAdrian Chadd /**
904ad7e9b0SAdrian Chadd  * Constants defining fine grained ordering within a BHND_PROBE_* priority band.
914ad7e9b0SAdrian Chadd  *
924ad7e9b0SAdrian Chadd  * Example:
934ad7e9b0SAdrian Chadd  * @code
944ad7e9b0SAdrian Chadd  * BHND_PROBE_BUS + BHND_PROBE_ORDER_FIRST
954ad7e9b0SAdrian Chadd  * @endcode
964ad7e9b0SAdrian Chadd  */
974ad7e9b0SAdrian Chadd enum {
984ad7e9b0SAdrian Chadd 	BHND_PROBE_ORDER_FIRST		= 0,
994ad7e9b0SAdrian Chadd 	BHND_PROBE_ORDER_EARLY		= 25,
1004ad7e9b0SAdrian Chadd 	BHND_PROBE_ORDER_MIDDLE		= 50,
1014ad7e9b0SAdrian Chadd 	BHND_PROBE_ORDER_LATE		= 75,
1024ad7e9b0SAdrian Chadd 	BHND_PROBE_ORDER_LAST		= 100
1034ad7e9b0SAdrian Chadd 
1044ad7e9b0SAdrian Chadd };
1054ad7e9b0SAdrian Chadd 
1068a03f98aSLandon J. Fuller /**
1078a03f98aSLandon J. Fuller  * Per-core IOCTL flags common to all bhnd(4) cores.
1088a03f98aSLandon J. Fuller  */
1098a03f98aSLandon J. Fuller enum {
1108a03f98aSLandon J. Fuller 	BHND_IOCTL_BIST		= 0x8000,	/**< Initiate a built-in self-test (BIST). Must be cleared
1118a03f98aSLandon J. Fuller 						     after BIST results are read via BHND_IOST_BIST_* */
1128a03f98aSLandon J. Fuller 	BHND_IOCTL_PME		= 0x4000,	/**< Enable posting of power management events by the core. */
1138a03f98aSLandon J. Fuller 	BHND_IOCTL_CFLAGS	= 0x3FFC,	/**< Reserved for core-specific ioctl flags. */
1148a03f98aSLandon J. Fuller 	BHND_IOCTL_CLK_FORCE	= 0x0002,	/**< Force disable of clock gating, resulting in all clocks
1158a03f98aSLandon J. Fuller 						     being distributed within the core. Should be set when
1168a03f98aSLandon J. Fuller 						     asserting/deasserting reset to ensure the reset signal
1178a03f98aSLandon J. Fuller 						     fully propagates to the entire core. */
1188a03f98aSLandon J. Fuller 	BHND_IOCTL_CLK_EN	= 0x0001,	/**< If cleared, the core clock will be disabled. Should be
1198a03f98aSLandon J. Fuller 						     set during normal operation, and cleared when the core is
1208a03f98aSLandon J. Fuller 						     held in reset. */
1218a03f98aSLandon J. Fuller };
1228a03f98aSLandon J. Fuller 
1238a03f98aSLandon J. Fuller /**
1248a03f98aSLandon J. Fuller  * Per-core IOST flags common to all bhnd(4) cores.
1258a03f98aSLandon J. Fuller  */
1268a03f98aSLandon J. Fuller enum {
1278a03f98aSLandon J. Fuller 	BHND_IOST_BIST_DONE	= 0x8000,	/**< Set upon BIST completion (see BHND_IOCTL_BIST), and cleared
1288a03f98aSLandon J. Fuller 						     if 0 is written to BHND_IOCTL_BIST. */
1298a03f98aSLandon J. Fuller 	BHND_IOST_BIST_FAIL	= 0x4000,	/**< Set upon detection of a BIST error; the value is unspecified
1308a03f98aSLandon J. Fuller 						     if BIST has not completed and BHND_IOST_BIST_DONE is not set. */
1318a03f98aSLandon J. Fuller 	BHND_IOST_CLK		= 0x2000,	/**< Set if the core has requested that gated clocks be enabled, or
1328a03f98aSLandon J. Fuller 						     cleared otherwise. The value is undefined if a core does not
1338a03f98aSLandon J. Fuller 						     support clock gating. */
1348a03f98aSLandon J. Fuller 	BHND_IOST_DMA64		= 0x1000,	/**< Set if this core supports 64-bit DMA */
1358a03f98aSLandon J. Fuller 	BHND_IOST_CFLAGS	= 0x0FFC,	/**< Reserved for core-specific status flags. */
1368a03f98aSLandon J. Fuller };
1378a03f98aSLandon J. Fuller 
1384ad7e9b0SAdrian Chadd /*
1394ad7e9b0SAdrian Chadd  * Simplified accessors for bhnd device ivars
1404ad7e9b0SAdrian Chadd  */
1414ad7e9b0SAdrian Chadd #define	BHND_ACCESSOR(var, ivar, type) \
1424ad7e9b0SAdrian Chadd 	__BUS_ACCESSOR(bhnd, var, BHND, ivar, type)
1434ad7e9b0SAdrian Chadd 
1444ad7e9b0SAdrian Chadd BHND_ACCESSOR(vendor,		VENDOR,		uint16_t);
1454ad7e9b0SAdrian Chadd BHND_ACCESSOR(device,		DEVICE,		uint16_t);
1464ad7e9b0SAdrian Chadd BHND_ACCESSOR(hwrev,		HWREV,		uint8_t);
1474ad7e9b0SAdrian Chadd BHND_ACCESSOR(class,		DEVICE_CLASS,	bhnd_devclass_t);
1484ad7e9b0SAdrian Chadd BHND_ACCESSOR(vendor_name,	VENDOR_NAME,	const char *);
1494ad7e9b0SAdrian Chadd BHND_ACCESSOR(device_name,	DEVICE_NAME,	const char *);
1504ad7e9b0SAdrian Chadd BHND_ACCESSOR(core_index,	CORE_INDEX,	u_int);
1514ad7e9b0SAdrian Chadd BHND_ACCESSOR(core_unit,	CORE_UNIT,	int);
1524e96bf3aSLandon J. Fuller BHND_ACCESSOR(pmu_info,		PMU_INFO,	void *);
1534ad7e9b0SAdrian Chadd 
1544ad7e9b0SAdrian Chadd #undef	BHND_ACCESSOR
1554ad7e9b0SAdrian Chadd 
1564ad7e9b0SAdrian Chadd /**
157d567592bSAdrian Chadd  * A bhnd(4) board descriptor.
158d567592bSAdrian Chadd  */
159d567592bSAdrian Chadd struct bhnd_board_info {
160566ca880SLandon J. Fuller 	uint16_t	board_vendor;	/**< Board vendor (PCI-SIG vendor ID).
161d567592bSAdrian Chadd 					  *
162566ca880SLandon J. Fuller 					  * On PCI devices, this will default to
163566ca880SLandon J. Fuller 					  * the PCI subsystem vendor ID, but may
164566ca880SLandon J. Fuller 					  * be overridden by the 'boardtype'
165566ca880SLandon J. Fuller 					  * NVRAM variable.
166566ca880SLandon J. Fuller 					  *
167566ca880SLandon J. Fuller 					  * On SoCs, this will default to
168566ca880SLandon J. Fuller 					  * PCI_VENDOR_BROADCOM, but may be
169566ca880SLandon J. Fuller 					  * overridden by the 'boardvendor'
170566ca880SLandon J. Fuller 					  * NVRAM variable.
171d567592bSAdrian Chadd 					  */
172d567592bSAdrian Chadd 	uint16_t	board_type;	/**< Board type (See BHND_BOARD_*)
173d567592bSAdrian Chadd 					  *
174566ca880SLandon J. Fuller 					  *  This value is usually a
175566ca880SLandon J. Fuller 					  *  Broadcom-assigned reference board
176566ca880SLandon J. Fuller 					  *  identifier (see BHND_BOARD_*), but
177566ca880SLandon J. Fuller 					  *  may be set to an arbitrary value
178566ca880SLandon J. Fuller 					  *  assigned by the board vendor.
179566ca880SLandon J. Fuller 					  *
180566ca880SLandon J. Fuller 					  *  On PCI devices, this will default
181566ca880SLandon J. Fuller 					  *  to the PCI subsystem ID, but may be
182566ca880SLandon J. Fuller 					  *  overridden by the 'boardtype'
183566ca880SLandon J. Fuller 					  *  NVRAM variable.
184566ca880SLandon J. Fuller 					  *
185566ca880SLandon J. Fuller 					  *  On SoCs, this will always be
186566ca880SLandon J. Fuller 					  *  populated with the value of the
187566ca880SLandon J. Fuller 					  * 'boardtype' NVRAM variable.
188566ca880SLandon J. Fuller 					  */
189566ca880SLandon J. Fuller 	uint16_t	board_devid;	/**< Board device ID.
190566ca880SLandon J. Fuller 					  *
191566ca880SLandon J. Fuller 					  *  On PCI devices, this will default
192566ca880SLandon J. Fuller 					  *  to the PCI device ID, but may
193566ca880SLandon J. Fuller 					  *  be overridden by the 'devid'
194566ca880SLandon J. Fuller 					  *  NVRAM variable.
195d567592bSAdrian Chadd 					  */
196d567592bSAdrian Chadd 	uint16_t	board_rev;	/**< Board revision. */
197d567592bSAdrian Chadd 	uint8_t		board_srom_rev;	/**< Board SROM format revision */
198d567592bSAdrian Chadd 
199d567592bSAdrian Chadd 	uint32_t	board_flags;	/**< Board flags (see BHND_BFL_*) */
200d567592bSAdrian Chadd 	uint32_t	board_flags2;	/**< Board flags 2 (see BHND_BFL2_*) */
201d567592bSAdrian Chadd 	uint32_t	board_flags3;	/**< Board flags 3 (see BHND_BFL3_*) */
202d567592bSAdrian Chadd };
203d567592bSAdrian Chadd 
204d567592bSAdrian Chadd /**
2054ad7e9b0SAdrian Chadd  * Chip Identification
2064ad7e9b0SAdrian Chadd  *
2074ad7e9b0SAdrian Chadd  * This is read from the ChipCommon ID register; on earlier bhnd(4) devices
2084ad7e9b0SAdrian Chadd  * where ChipCommon is unavailable, known values must be supplied.
2094ad7e9b0SAdrian Chadd  */
2104ad7e9b0SAdrian Chadd struct bhnd_chipid {
2114ad7e9b0SAdrian Chadd 	uint16_t	chip_id;	/**< chip id (BHND_CHIPID_*) */
2124ad7e9b0SAdrian Chadd 	uint8_t		chip_rev;	/**< chip revision */
2134ad7e9b0SAdrian Chadd 	uint8_t		chip_pkg;	/**< chip package (BHND_PKGID_*) */
2144ad7e9b0SAdrian Chadd 	uint8_t		chip_type;	/**< chip type (BHND_CHIPTYPE_*) */
215f3524ec8SLandon J. Fuller 	uint32_t	chip_caps;	/**< chip capabilities (BHND_CAP_*) */
2164ad7e9b0SAdrian Chadd 
2174ad7e9b0SAdrian Chadd 	bhnd_addr_t	enum_addr;	/**< chip_type-specific enumeration
2184ad7e9b0SAdrian Chadd 					  *  address; either the siba(4) base
2194ad7e9b0SAdrian Chadd 					  *  core register block, or the bcma(4)
2204ad7e9b0SAdrian Chadd 					  *  EROM core address. */
2214ad7e9b0SAdrian Chadd 
2224ad7e9b0SAdrian Chadd 	uint8_t		ncores;		/**< number of cores, if known. 0 if
2234ad7e9b0SAdrian Chadd 					  *  not available. */
2244ad7e9b0SAdrian Chadd };
2254ad7e9b0SAdrian Chadd 
2264ad7e9b0SAdrian Chadd /**
227f3524ec8SLandon J. Fuller  * Chip capabilities
228f3524ec8SLandon J. Fuller  */
229f3524ec8SLandon J. Fuller enum bhnd_cap {
230f3524ec8SLandon J. Fuller 	BHND_CAP_BP64	= (1<<0),	/**< Backplane supports 64-bit
231f3524ec8SLandon J. Fuller 					  *  addressing */
232f3524ec8SLandon J. Fuller 	BHND_CAP_PMU	= (1<<1),	/**< PMU is present */
233f3524ec8SLandon J. Fuller };
234f3524ec8SLandon J. Fuller 
235f3524ec8SLandon J. Fuller /**
2364ad7e9b0SAdrian Chadd  * A bhnd(4) core descriptor.
2374ad7e9b0SAdrian Chadd  */
2384ad7e9b0SAdrian Chadd struct bhnd_core_info {
239d567592bSAdrian Chadd 	uint16_t	vendor;		/**< JEP-106 vendor (BHND_MFGID_*) */
2404ad7e9b0SAdrian Chadd 	uint16_t	device;		/**< device */
2414ad7e9b0SAdrian Chadd 	uint16_t	hwrev;		/**< hardware revision */
2424ad7e9b0SAdrian Chadd 	u_int		core_idx;	/**< bus-assigned core index */
2434ad7e9b0SAdrian Chadd 	int		unit;		/**< bus-assigned core unit */
2444ad7e9b0SAdrian Chadd };
2454ad7e9b0SAdrian Chadd 
2464ad7e9b0SAdrian Chadd /**
2479ed45324SLandon J. Fuller  * bhnd(4) DMA address widths.
2489ed45324SLandon J. Fuller  */
2499ed45324SLandon J. Fuller typedef enum {
2509ed45324SLandon J. Fuller 	BHND_DMA_ADDR_30BIT	= 30,	/**< 30-bit DMA */
2519ed45324SLandon J. Fuller 	BHND_DMA_ADDR_32BIT	= 32,	/**< 32-bit DMA */
2529ed45324SLandon J. Fuller 	BHND_DMA_ADDR_64BIT	= 64,	/**< 64-bit DMA */
2539ed45324SLandon J. Fuller } bhnd_dma_addrwidth;
2549ed45324SLandon J. Fuller 
2559ed45324SLandon J. Fuller /**
2569ed45324SLandon J. Fuller  * Convert an address width (in bits) to its corresponding mask.
2579ed45324SLandon J. Fuller  */
2589ed45324SLandon J. Fuller #define	BHND_DMA_ADDR_BITMASK(_width)	\
2599ed45324SLandon J. Fuller 	((_width >= 64) ? ~0ULL :	\
2609ed45324SLandon J. Fuller 	 (_width == 0) ? 0x0 :		\
2619ed45324SLandon J. Fuller 	 ((1ULL << (_width)) - 1))	\
2629ed45324SLandon J. Fuller 
2639ed45324SLandon J. Fuller /**
2649ed45324SLandon J. Fuller  * bhnd(4) DMA address translation descriptor.
2659ed45324SLandon J. Fuller  */
2669ed45324SLandon J. Fuller struct bhnd_dma_translation {
2679ed45324SLandon J. Fuller 	/**
2689ed45324SLandon J. Fuller 	 * Host-to-device physical address translation.
2699ed45324SLandon J. Fuller 	 *
2709ed45324SLandon J. Fuller 	 * This may be added to the host physical address to produce a device
2719ed45324SLandon J. Fuller 	 * DMA address.
2729ed45324SLandon J. Fuller 	 */
2739ed45324SLandon J. Fuller 	bhnd_addr_t	base_addr;
2749ed45324SLandon J. Fuller 
2759ed45324SLandon J. Fuller 	/**
2769ed45324SLandon J. Fuller 	 * Device-addressable address mask.
2779ed45324SLandon J. Fuller 	 *
2789ed45324SLandon J. Fuller 	 * This defines the device's DMA address range, excluding any bits
2799ed45324SLandon J. Fuller 	 * reserved for mapping the address to the base_addr.
2809ed45324SLandon J. Fuller 	 */
2819ed45324SLandon J. Fuller 	bhnd_addr_t	addr_mask;
2829ed45324SLandon J. Fuller 
2839ed45324SLandon J. Fuller 	/**
2849ed45324SLandon J. Fuller 	 * Device-addressable extended address mask.
2859ed45324SLandon J. Fuller 	 *
2869ed45324SLandon J. Fuller 	 * If a per-core bhnd(4) DMA engine supports the 'addrext' control
2879ed45324SLandon J. Fuller 	 * field, it can be used to provide address bits excluded by addr_mask.
2889ed45324SLandon J. Fuller 	 *
2899ed45324SLandon J. Fuller 	 * Support for DMA extended address changes – including coordination
2909ed45324SLandon J. Fuller 	 * with the core providing DMA translation – is handled transparently by
2919ed45324SLandon J. Fuller 	 * the DMA engine. For example, on PCI(e) Wi-Fi chipsets, the Wi-Fi
2929ed45324SLandon J. Fuller 	 * core DMA engine will (in effect) update the PCI core's DMA
2939ed45324SLandon J. Fuller 	 * sbtopcitranslation base address to map the full address prior to
2949ed45324SLandon J. Fuller 	 * performing a DMA transaction.
2959ed45324SLandon J. Fuller 	 */
2969ed45324SLandon J. Fuller 	bhnd_addr_t	addrext_mask;
2979ed45324SLandon J. Fuller 
2989ed45324SLandon J. Fuller 	/**
29905ed3f90SLandon J. Fuller 	 * Translation flags (see bhnd_dma_translation_flags).
3009ed45324SLandon J. Fuller 	 */
3019ed45324SLandon J. Fuller 	uint32_t	flags;
3029ed45324SLandon J. Fuller };
3039ed45324SLandon J. Fuller #define	BHND_DMA_TRANSLATION_TABLE_END	{ 0, 0, 0, 0 }
3049ed45324SLandon J. Fuller 
3059ed45324SLandon J. Fuller #define	BHND_DMA_IS_TRANSLATION_TABLE_END(_dt)			\
3069ed45324SLandon J. Fuller 	((_dt)->base_addr == 0 && (_dt)->addr_mask == 0 &&	\
3079ed45324SLandon J. Fuller 	 (_dt)->addrext_mask == 0 && (_dt)->flags == 0)
3089ed45324SLandon J. Fuller 
3099ed45324SLandon J. Fuller /**
3109ed45324SLandon J. Fuller  * bhnd(4) DMA address translation flags.
3119ed45324SLandon J. Fuller  */
3129ed45324SLandon J. Fuller enum bhnd_dma_translation_flags {
3139ed45324SLandon J. Fuller 	/**
3149ed45324SLandon J. Fuller 	 * The translation remaps the device's physical address space.
3159ed45324SLandon J. Fuller 	 *
3169ed45324SLandon J. Fuller 	 * This is used in conjunction with BHND_DMA_TRANSLATION_BYTESWAPPED to
3179ed45324SLandon J. Fuller 	 * define a DMA translation that provides byteswapped access to
3189ed45324SLandon J. Fuller 	 * physical memory on big-endian MIPS SoCs.
3199ed45324SLandon J. Fuller 	 */
3209ed45324SLandon J. Fuller 	BHND_DMA_TRANSLATION_PHYSMAP		= (1<<0),
3219ed45324SLandon J. Fuller 
3229ed45324SLandon J. Fuller 	/**
3239ed45324SLandon J. Fuller 	 * Provides a byte-swapped mapping; write requests will be byte-swapped
3249ed45324SLandon J. Fuller 	 * before being written to memory, and read requests will be
3259ed45324SLandon J. Fuller 	 * byte-swapped before being returned.
3269ed45324SLandon J. Fuller 	 *
3279ed45324SLandon J. Fuller 	 * This is primarily used to perform efficient byte swapping of DMA
3289ed45324SLandon J. Fuller 	 * data on embedded MIPS SoCs executing in big-endian mode.
3299ed45324SLandon J. Fuller 	 */
3309ed45324SLandon J. Fuller 	BHND_DMA_TRANSLATION_BYTESWAPPED	= (1<<1),
3319ed45324SLandon J. Fuller };
3329ed45324SLandon J. Fuller 
3339ed45324SLandon J. Fuller /**
334d567592bSAdrian Chadd * A bhnd(4) bus resource.
335d567592bSAdrian Chadd *
336d567592bSAdrian Chadd * This provides an abstract interface to per-core resources that may require
337d567592bSAdrian Chadd * bus-level remapping of address windows prior to access.
338d567592bSAdrian Chadd */
339d567592bSAdrian Chadd struct bhnd_resource {
340d567592bSAdrian Chadd 	struct resource	*res;		/**< the system resource. */
341d567592bSAdrian Chadd 	bool		 direct;	/**< false if the resource requires
342d567592bSAdrian Chadd 					 *   bus window remapping before it
343d567592bSAdrian Chadd 					 *   is MMIO accessible. */
344d567592bSAdrian Chadd };
345d567592bSAdrian Chadd 
346111d7cb2SLandon J. Fuller /** Wrap the active resource @p _r in a bhnd_resource structure */
347111d7cb2SLandon J. Fuller #define	BHND_DIRECT_RESOURCE(_r)	((struct bhnd_resource) {	\
348111d7cb2SLandon J. Fuller 	.res = (_r),							\
349111d7cb2SLandon J. Fuller 	.direct = true,							\
350111d7cb2SLandon J. Fuller })
351111d7cb2SLandon J. Fuller 
352d567592bSAdrian Chadd /**
35336e4410aSAdrian Chadd  * Device quirk table descriptor.
3544ad7e9b0SAdrian Chadd  */
3554ad7e9b0SAdrian Chadd struct bhnd_device_quirk {
3565ad9ac03SAdrian Chadd 	struct bhnd_device_match desc;		/**< device match descriptor */
35736e4410aSAdrian Chadd 	uint32_t		 quirks;	/**< quirk flags */
35836e4410aSAdrian Chadd };
3595ad9ac03SAdrian Chadd 
3605ad9ac03SAdrian Chadd #define	BHND_CORE_QUIRK(_rev, _flags)		\
3615ad9ac03SAdrian Chadd 	{{ BHND_MATCH_CORE_REV(_rev) }, (_flags) }
3625ad9ac03SAdrian Chadd 
3635ad9ac03SAdrian Chadd #define	BHND_CHIP_QUIRK(_chip, _rev, _flags)	\
364caeff9a3SLandon J. Fuller 	{{ BHND_MATCH_CHIP_IR(BCM ## _chip, _rev) }, (_flags) }
3655ad9ac03SAdrian Chadd 
3665ad9ac03SAdrian Chadd #define	BHND_PKG_QUIRK(_chip, _pkg, _flags)	\
367caeff9a3SLandon J. Fuller 	{{ BHND_MATCH_CHIP_IP(BCM ## _chip, BCM ## _chip ## _pkg) }, (_flags) }
3685ad9ac03SAdrian Chadd 
3695ad9ac03SAdrian Chadd #define	BHND_BOARD_QUIRK(_board, _flags)	\
3705ad9ac03SAdrian Chadd 	{{ BHND_MATCH_BOARD_TYPE(_board) },	\
3715ad9ac03SAdrian Chadd 	    (_flags) }
3725ad9ac03SAdrian Chadd #define	BHND_DEVICE_QUIRK_END		{ { BHND_MATCH_ANY }, 0 }
37336e4410aSAdrian Chadd #define	BHND_DEVICE_QUIRK_IS_END(_q)	\
3745ad9ac03SAdrian Chadd 	(((_q)->desc.m.match_flags == 0) && (_q)->quirks == 0)
37536e4410aSAdrian Chadd 
37636e4410aSAdrian Chadd enum {
37736e4410aSAdrian Chadd 	BHND_DF_ANY	= 0,
3785ad9ac03SAdrian Chadd 	BHND_DF_HOSTB	= (1<<0),	/**< core is serving as the bus' host
3795ad9ac03SAdrian Chadd 					  *  bridge. implies BHND_DF_ADAPTER */
3805ad9ac03SAdrian Chadd 	BHND_DF_SOC	= (1<<1),	/**< core is attached to a native
3815ad9ac03SAdrian Chadd 					     bus (BHND_ATTACH_NATIVE) */
3825ad9ac03SAdrian Chadd 	BHND_DF_ADAPTER	= (1<<2),	/**< core is attached to a bridged
3835ad9ac03SAdrian Chadd 					  *  adapter (BHND_ATTACH_ADAPTER) */
3844ad7e9b0SAdrian Chadd };
3854ad7e9b0SAdrian Chadd 
38636e4410aSAdrian Chadd /** Device probe table descriptor */
38736e4410aSAdrian Chadd struct bhnd_device {
3885ad9ac03SAdrian Chadd 	const struct bhnd_device_match	 core;		/**< core match descriptor */
38936e4410aSAdrian Chadd 	const char			*desc;		/**< device description, or NULL. */
39036e4410aSAdrian Chadd 	const struct bhnd_device_quirk	*quirks_table;	/**< quirks table for this device, or NULL */
39136e4410aSAdrian Chadd 	uint32_t			 device_flags;	/**< required BHND_DF_* flags */
39236e4410aSAdrian Chadd };
3934ad7e9b0SAdrian Chadd 
3945ad9ac03SAdrian Chadd #define	_BHND_DEVICE(_vendor, _device, _desc, _quirks,		\
395d567592bSAdrian Chadd      _flags, ...)						\
3965ad9ac03SAdrian Chadd 	{ { BHND_MATCH_CORE(BHND_MFGID_ ## _vendor,		\
3975ad9ac03SAdrian Chadd 	    BHND_COREID_ ## _device) }, _desc, _quirks,		\
3985ad9ac03SAdrian Chadd 	    _flags }
3994ad7e9b0SAdrian Chadd 
400b0b9c854SLandon J. Fuller #define	BHND_DEVICE(_vendor, _device, _desc, _quirks, ...)	\
401b0b9c854SLandon J. Fuller 	_BHND_DEVICE(_vendor, _device, _desc, _quirks,		\
402d567592bSAdrian Chadd 	    ## __VA_ARGS__, 0)
4035ad9ac03SAdrian Chadd #define	BHND_DEVICE_END		{ { BHND_MATCH_ANY }, NULL, NULL, 0 }
4045ad9ac03SAdrian Chadd #define	BHND_DEVICE_IS_END(_d)	\
4055ad9ac03SAdrian Chadd 	(BHND_MATCH_IS_ANY(&(_d)->core) && (_d)->desc == NULL)
4064ad7e9b0SAdrian Chadd 
4078e35bf83SLandon J. Fuller /**
4088e35bf83SLandon J. Fuller  * bhnd device sort order.
4098e35bf83SLandon J. Fuller  */
4108e35bf83SLandon J. Fuller typedef enum {
4118e35bf83SLandon J. Fuller 	BHND_DEVICE_ORDER_ATTACH,	/**< sort by bhnd(4) device attach order;
4128e35bf83SLandon J. Fuller 					     child devices should be probed/attached
4138e35bf83SLandon J. Fuller 					     in this order */
4148e35bf83SLandon J. Fuller 	BHND_DEVICE_ORDER_DETACH,	/**< sort by bhnd(4) device detach order;
4158e35bf83SLandon J. Fuller 					     child devices should be detached, suspended,
4168e35bf83SLandon J. Fuller 					     and shutdown in this order */
4178e35bf83SLandon J. Fuller } bhnd_device_order;
4188e35bf83SLandon J. Fuller 
4198e35bf83SLandon J. Fuller /**
4208e35bf83SLandon J. Fuller  * A registry of bhnd service providers.
4218e35bf83SLandon J. Fuller  */
4228e35bf83SLandon J. Fuller struct bhnd_service_registry {
4238e35bf83SLandon J. Fuller 	STAILQ_HEAD(,bhnd_service_entry)	entries;	/**< registered services */
4248e35bf83SLandon J. Fuller 	struct mtx				lock;		/**< state lock */
4258e35bf83SLandon J. Fuller };
4268e35bf83SLandon J. Fuller 
4278e35bf83SLandon J. Fuller /**
4288e35bf83SLandon J. Fuller  * bhnd service provider flags.
4298e35bf83SLandon J. Fuller  */
4308e35bf83SLandon J. Fuller enum {
4318e35bf83SLandon J. Fuller 	BHND_SPF_INHERITED	= (1<<0),	/**< service provider reference was inherited from
4328e35bf83SLandon J. Fuller 						     a parent bus, and should be deregistered when the
4338e35bf83SLandon J. Fuller 						     last active reference is released */
4348e35bf83SLandon J. Fuller };
4358e35bf83SLandon J. Fuller 
4364ad7e9b0SAdrian Chadd const char			*bhnd_vendor_name(uint16_t vendor);
4374ad7e9b0SAdrian Chadd const char			*bhnd_port_type_name(bhnd_port_type port_type);
438fdedcd9fSLandon J. Fuller const char			*bhnd_nvram_src_name(bhnd_nvram_src nvram_src);
4394ad7e9b0SAdrian Chadd 
4404ad7e9b0SAdrian Chadd const char 			*bhnd_find_core_name(uint16_t vendor,
4414ad7e9b0SAdrian Chadd 				     uint16_t device);
4424ad7e9b0SAdrian Chadd bhnd_devclass_t			 bhnd_find_core_class(uint16_t vendor,
4434ad7e9b0SAdrian Chadd 				     uint16_t device);
4444ad7e9b0SAdrian Chadd 
4454ad7e9b0SAdrian Chadd const char			*bhnd_core_name(const struct bhnd_core_info *ci);
4464ad7e9b0SAdrian Chadd bhnd_devclass_t			 bhnd_core_class(const struct bhnd_core_info *ci);
4474ad7e9b0SAdrian Chadd 
4489bb95906SLandon J. Fuller int				 bhnd_format_chip_id(char *buffer, size_t size,
4499bb95906SLandon J. Fuller 				     uint16_t chip_id);
4504ad7e9b0SAdrian Chadd 
4518e35bf83SLandon J. Fuller device_t			 bhnd_bus_match_child(device_t bus,
4524ad7e9b0SAdrian Chadd 				     const struct bhnd_core_match *desc);
4534ad7e9b0SAdrian Chadd 
4548e35bf83SLandon J. Fuller device_t			 bhnd_bus_find_child(device_t bus,
4554ad7e9b0SAdrian Chadd 				     bhnd_devclass_t class, int unit);
4564ad7e9b0SAdrian Chadd 
4578e35bf83SLandon J. Fuller int				 bhnd_bus_get_children(device_t bus,
4588e35bf83SLandon J. Fuller 				     device_t **devlistp, int *devcountp,
4598e35bf83SLandon J. Fuller 				     bhnd_device_order order);
4608e35bf83SLandon J. Fuller 
4618e35bf83SLandon J. Fuller void				 bhnd_bus_free_children(device_t *devlist);
4628e35bf83SLandon J. Fuller 
4638e35bf83SLandon J. Fuller int				 bhnd_bus_probe_children(device_t bus);
4648e35bf83SLandon J. Fuller 
4658e35bf83SLandon J. Fuller int				 bhnd_sort_devices(device_t *devlist,
4668e35bf83SLandon J. Fuller 				     size_t devcount, bhnd_device_order order);
4678e35bf83SLandon J. Fuller 
4688ef24a0dSAdrian Chadd device_t			 bhnd_find_bridge_root(device_t dev,
4698ef24a0dSAdrian Chadd 				     devclass_t bus_class);
4708ef24a0dSAdrian Chadd 
4714ad7e9b0SAdrian Chadd const struct bhnd_core_info	*bhnd_match_core(
4724ad7e9b0SAdrian Chadd 				     const struct bhnd_core_info *cores,
4734ad7e9b0SAdrian Chadd 				     u_int num_cores,
4744ad7e9b0SAdrian Chadd 				     const struct bhnd_core_match *desc);
4754ad7e9b0SAdrian Chadd 
4764ad7e9b0SAdrian Chadd const struct bhnd_core_info	*bhnd_find_core(
4774ad7e9b0SAdrian Chadd 				     const struct bhnd_core_info *cores,
4784ad7e9b0SAdrian Chadd 				     u_int num_cores, bhnd_devclass_t class);
4794ad7e9b0SAdrian Chadd 
480111d7cb2SLandon J. Fuller struct bhnd_core_match		 bhnd_core_get_match_desc(
481111d7cb2SLandon J. Fuller 				     const struct bhnd_core_info *core);
482111d7cb2SLandon J. Fuller 
483111d7cb2SLandon J. Fuller bool				 bhnd_cores_equal(
484111d7cb2SLandon J. Fuller 				     const struct bhnd_core_info *lhs,
485111d7cb2SLandon J. Fuller 				     const struct bhnd_core_info *rhs);
486111d7cb2SLandon J. Fuller 
4874ad7e9b0SAdrian Chadd bool				 bhnd_core_matches(
4884ad7e9b0SAdrian Chadd 				     const struct bhnd_core_info *core,
4894ad7e9b0SAdrian Chadd 				     const struct bhnd_core_match *desc);
4904ad7e9b0SAdrian Chadd 
491f74f1a68SAdrian Chadd bool				 bhnd_chip_matches(
492f74f1a68SAdrian Chadd 				     const struct bhnd_chipid *chipid,
493f74f1a68SAdrian Chadd 				     const struct bhnd_chip_match *desc);
494f74f1a68SAdrian Chadd 
4955ad9ac03SAdrian Chadd bool				 bhnd_board_matches(
4965ad9ac03SAdrian Chadd 				     const struct bhnd_board_info *info,
4975ad9ac03SAdrian Chadd 				     const struct bhnd_board_match *desc);
4985ad9ac03SAdrian Chadd 
4994ad7e9b0SAdrian Chadd bool				 bhnd_hwrev_matches(uint16_t hwrev,
5004ad7e9b0SAdrian Chadd 				     const struct bhnd_hwrev_match *desc);
5014ad7e9b0SAdrian Chadd 
5024ad7e9b0SAdrian Chadd bool				 bhnd_device_matches(device_t dev,
5035ad9ac03SAdrian Chadd 				     const struct bhnd_device_match *desc);
5044ad7e9b0SAdrian Chadd 
50536e4410aSAdrian Chadd const struct bhnd_device	*bhnd_device_lookup(device_t dev,
50636e4410aSAdrian Chadd 				     const struct bhnd_device *table,
50736e4410aSAdrian Chadd 				     size_t entry_size);
50836e4410aSAdrian Chadd 
50936e4410aSAdrian Chadd uint32_t			 bhnd_device_quirks(device_t dev,
51036e4410aSAdrian Chadd 				     const struct bhnd_device *table,
51136e4410aSAdrian Chadd 				     size_t entry_size);
51236e4410aSAdrian Chadd 
5134ad7e9b0SAdrian Chadd struct bhnd_core_info		 bhnd_get_core_info(device_t dev);
5144ad7e9b0SAdrian Chadd 
5154ad7e9b0SAdrian Chadd int				 bhnd_alloc_resources(device_t dev,
5164ad7e9b0SAdrian Chadd 				     struct resource_spec *rs,
5174ad7e9b0SAdrian Chadd 				     struct bhnd_resource **res);
5184ad7e9b0SAdrian Chadd 
5194ad7e9b0SAdrian Chadd void				 bhnd_release_resources(device_t dev,
5204ad7e9b0SAdrian Chadd 				     const struct resource_spec *rs,
5214ad7e9b0SAdrian Chadd 				     struct bhnd_resource **res);
5224ad7e9b0SAdrian Chadd 
52336e4410aSAdrian Chadd void				 bhnd_set_custom_core_desc(device_t dev,
52436e4410aSAdrian Chadd 				     const char *name);
52536e4410aSAdrian Chadd void				 bhnd_set_default_core_desc(device_t dev);
526386fb140SAdrian Chadd 
5279bb95906SLandon J. Fuller void				 bhnd_set_default_bus_desc(device_t dev,
5289bb95906SLandon J. Fuller 				     const struct bhnd_chipid *chip_id);
5299bb95906SLandon J. Fuller 
5301728aef2SLandon J. Fuller int				 bhnd_nvram_getvar_str(device_t dev,
5311728aef2SLandon J. Fuller 				     const char *name, char *buf, size_t len,
5321728aef2SLandon J. Fuller 				     size_t *rlen);
5331728aef2SLandon J. Fuller 
5341728aef2SLandon J. Fuller int				 bhnd_nvram_getvar_uint(device_t dev,
5351728aef2SLandon J. Fuller 				     const char *name, void *value, int width);
5361728aef2SLandon J. Fuller int				 bhnd_nvram_getvar_uint8(device_t dev,
5371728aef2SLandon J. Fuller 				     const char *name, uint8_t *value);
5381728aef2SLandon J. Fuller int				 bhnd_nvram_getvar_uint16(device_t dev,
5391728aef2SLandon J. Fuller 				     const char *name, uint16_t *value);
5401728aef2SLandon J. Fuller int				 bhnd_nvram_getvar_uint32(device_t dev,
5411728aef2SLandon J. Fuller 				     const char *name, uint32_t *value);
5421728aef2SLandon J. Fuller 
5431728aef2SLandon J. Fuller int				 bhnd_nvram_getvar_int(device_t dev,
5441728aef2SLandon J. Fuller 				     const char *name, void *value, int width);
5451728aef2SLandon J. Fuller int				 bhnd_nvram_getvar_int8(device_t dev,
5461728aef2SLandon J. Fuller 				     const char *name, int8_t *value);
5471728aef2SLandon J. Fuller int				 bhnd_nvram_getvar_int16(device_t dev,
5481728aef2SLandon J. Fuller 				     const char *name, int16_t *value);
5491728aef2SLandon J. Fuller int				 bhnd_nvram_getvar_int32(device_t dev,
5501728aef2SLandon J. Fuller 				     const char *name, int32_t *value);
5511728aef2SLandon J. Fuller 
5521728aef2SLandon J. Fuller int				 bhnd_nvram_getvar_array(device_t dev,
5531728aef2SLandon J. Fuller 				     const char *name, void *buf, size_t count,
5541728aef2SLandon J. Fuller 				     bhnd_nvram_type type);
555386fb140SAdrian Chadd 
5568e35bf83SLandon J. Fuller int				 bhnd_service_registry_init(
5578e35bf83SLandon J. Fuller 				     struct bhnd_service_registry *bsr);
5588e35bf83SLandon J. Fuller int				 bhnd_service_registry_fini(
5598e35bf83SLandon J. Fuller 				     struct bhnd_service_registry *bsr);
5608e35bf83SLandon J. Fuller int				 bhnd_service_registry_add(
5618e35bf83SLandon J. Fuller 				     struct bhnd_service_registry *bsr,
5628e35bf83SLandon J. Fuller 				     device_t provider,
5638e35bf83SLandon J. Fuller 				     bhnd_service_t service,
5648e35bf83SLandon J. Fuller 				     uint32_t flags);
5658e35bf83SLandon J. Fuller int				 bhnd_service_registry_remove(
5668e35bf83SLandon J. Fuller 				     struct bhnd_service_registry *bsr,
5678e35bf83SLandon J. Fuller 				     device_t provider,
5688e35bf83SLandon J. Fuller 				     bhnd_service_t service);
5698e35bf83SLandon J. Fuller device_t			 bhnd_service_registry_retain(
5708e35bf83SLandon J. Fuller 				     struct bhnd_service_registry *bsr,
5718e35bf83SLandon J. Fuller 				     bhnd_service_t service);
5728e35bf83SLandon J. Fuller bool				 bhnd_service_registry_release(
5738e35bf83SLandon J. Fuller 				     struct bhnd_service_registry *bsr,
5748e35bf83SLandon J. Fuller 				     device_t provider,
5758e35bf83SLandon J. Fuller 				     bhnd_service_t service);
5768e35bf83SLandon J. Fuller 
5778e35bf83SLandon J. Fuller int				 bhnd_bus_generic_register_provider(
5788e35bf83SLandon J. Fuller 				     device_t dev, device_t child,
5798e35bf83SLandon J. Fuller 				     device_t provider, bhnd_service_t service);
5808e35bf83SLandon J. Fuller int				 bhnd_bus_generic_deregister_provider(
5818e35bf83SLandon J. Fuller 				     device_t dev, device_t child,
5828e35bf83SLandon J. Fuller 				     device_t provider, bhnd_service_t service);
5838e35bf83SLandon J. Fuller device_t			 bhnd_bus_generic_retain_provider(device_t dev,
5848e35bf83SLandon J. Fuller 				     device_t child, bhnd_service_t service);
5858e35bf83SLandon J. Fuller void				 bhnd_bus_generic_release_provider(device_t dev,
5868e35bf83SLandon J. Fuller 				     device_t child, device_t provider,
5878e35bf83SLandon J. Fuller 				     bhnd_service_t service);
5888e35bf83SLandon J. Fuller 
5898e35bf83SLandon J. Fuller int				 bhnd_bus_generic_sr_register_provider(
5908e35bf83SLandon J. Fuller 				     device_t dev, device_t child,
5918e35bf83SLandon J. Fuller 				     device_t provider, bhnd_service_t service);
5928e35bf83SLandon J. Fuller int				 bhnd_bus_generic_sr_deregister_provider(
5938e35bf83SLandon J. Fuller 				     device_t dev, device_t child,
5948e35bf83SLandon J. Fuller 				     device_t provider, bhnd_service_t service);
5958e35bf83SLandon J. Fuller device_t			 bhnd_bus_generic_sr_retain_provider(device_t dev,
5968e35bf83SLandon J. Fuller 				     device_t child, bhnd_service_t service);
5978e35bf83SLandon J. Fuller void				 bhnd_bus_generic_sr_release_provider(device_t dev,
5988e35bf83SLandon J. Fuller 				     device_t child, device_t provider,
5998e35bf83SLandon J. Fuller 				     bhnd_service_t service);
6008e35bf83SLandon J. Fuller 
601386fb140SAdrian Chadd bool				 bhnd_bus_generic_is_hw_disabled(device_t dev,
602386fb140SAdrian Chadd 				     device_t child);
603386fb140SAdrian Chadd bool				 bhnd_bus_generic_is_region_valid(device_t dev,
604386fb140SAdrian Chadd 				     device_t child, bhnd_port_type type,
605386fb140SAdrian Chadd 				     u_int port, u_int region);
606fdedcd9fSLandon J. Fuller int				 bhnd_bus_generic_get_nvram_var(device_t dev,
607386fb140SAdrian Chadd 				     device_t child, const char *name,
6081728aef2SLandon J. Fuller 				     void *buf, size_t *size,
6091728aef2SLandon J. Fuller 				     bhnd_nvram_type type);
610386fb140SAdrian Chadd const struct bhnd_chipid	*bhnd_bus_generic_get_chipid(device_t dev,
611386fb140SAdrian Chadd 				     device_t child);
6129ed45324SLandon J. Fuller int				 bhnd_bus_generic_get_dma_translation(
6139ed45324SLandon J. Fuller 				     device_t dev, device_t child, u_int width,
6149ed45324SLandon J. Fuller 				     uint32_t flags, bus_dma_tag_t *dmat,
6159ed45324SLandon J. Fuller 				     struct bhnd_dma_translation *translation);
616d567592bSAdrian Chadd int				 bhnd_bus_generic_read_board_info(device_t dev,
617d567592bSAdrian Chadd 				     device_t child,
618d567592bSAdrian Chadd 				     struct bhnd_board_info *info);
619386fb140SAdrian Chadd struct bhnd_resource		*bhnd_bus_generic_alloc_resource (device_t dev,
620386fb140SAdrian Chadd 				     device_t child, int type, int *rid,
621386fb140SAdrian Chadd 				     rman_res_t start, rman_res_t end,
622386fb140SAdrian Chadd 				     rman_res_t count, u_int flags);
623386fb140SAdrian Chadd int				 bhnd_bus_generic_release_resource (device_t dev,
624386fb140SAdrian Chadd 				     device_t child, int type, int rid,
625386fb140SAdrian Chadd 				     struct bhnd_resource *r);
626386fb140SAdrian Chadd int				 bhnd_bus_generic_activate_resource (device_t dev,
627386fb140SAdrian Chadd 				     device_t child, int type, int rid,
628386fb140SAdrian Chadd 				     struct bhnd_resource *r);
629386fb140SAdrian Chadd int				 bhnd_bus_generic_deactivate_resource (device_t dev,
630386fb140SAdrian Chadd 				     device_t child, int type, int rid,
631386fb140SAdrian Chadd 				     struct bhnd_resource *r);
632caeff9a3SLandon J. Fuller uintptr_t			 bhnd_bus_generic_get_intr_domain(device_t dev,
633caeff9a3SLandon J. Fuller 				     device_t child, bool self);
634386fb140SAdrian Chadd 
635111d7cb2SLandon J. Fuller /**
636111d7cb2SLandon J. Fuller  * Return the bhnd(4) bus driver's device enumeration parser class
637111d7cb2SLandon J. Fuller  *
638111d7cb2SLandon J. Fuller  * @param driver A bhnd bus driver instance.
639111d7cb2SLandon J. Fuller  */
640111d7cb2SLandon J. Fuller static inline bhnd_erom_class_t *
bhnd_driver_get_erom_class(driver_t * driver)641111d7cb2SLandon J. Fuller bhnd_driver_get_erom_class(driver_t *driver)
642111d7cb2SLandon J. Fuller {
643111d7cb2SLandon J. Fuller 	return (BHND_BUS_GET_EROM_CLASS(driver));
644111d7cb2SLandon J. Fuller }
645386fb140SAdrian Chadd 
6464ad7e9b0SAdrian Chadd /**
647d9352570SAdrian Chadd  * Return the active host bridge core for the bhnd bus, if any, or NULL if
648d9352570SAdrian Chadd  * not found.
6494ad7e9b0SAdrian Chadd  *
650d9352570SAdrian Chadd  * @param dev A bhnd bus device.
6514ad7e9b0SAdrian Chadd  */
652d9352570SAdrian Chadd static inline device_t
bhnd_bus_find_hostb_device(device_t dev)6538e35bf83SLandon J. Fuller bhnd_bus_find_hostb_device(device_t dev) {
654d9352570SAdrian Chadd 	return (BHND_BUS_FIND_HOSTB_DEVICE(dev));
6554ad7e9b0SAdrian Chadd }
6564ad7e9b0SAdrian Chadd 
6574ad7e9b0SAdrian Chadd /**
6588e35bf83SLandon J. Fuller  * Register a provider for a given @p service.
6598e35bf83SLandon J. Fuller  *
6608e35bf83SLandon J. Fuller  * @param dev		The device to register as a service provider
6618e35bf83SLandon J. Fuller  *			with its parent bus.
6628e35bf83SLandon J. Fuller  * @param service	The service for which @p dev will be registered.
6638e35bf83SLandon J. Fuller  *
6648e35bf83SLandon J. Fuller  * @retval 0		success
6658e35bf83SLandon J. Fuller  * @retval EEXIST	if an entry for @p service already exists.
6668e35bf83SLandon J. Fuller  * @retval non-zero	if registering @p dev otherwise fails, a regular
6678e35bf83SLandon J. Fuller  *			unix error code will be returned.
6688e35bf83SLandon J. Fuller  */
6698e35bf83SLandon J. Fuller static inline int
bhnd_register_provider(device_t dev,bhnd_service_t service)6708e35bf83SLandon J. Fuller bhnd_register_provider(device_t dev, bhnd_service_t service)
6718e35bf83SLandon J. Fuller {
6728e35bf83SLandon J. Fuller 	return (BHND_BUS_REGISTER_PROVIDER(device_get_parent(dev), dev, dev,
6738e35bf83SLandon J. Fuller 	    service));
6748e35bf83SLandon J. Fuller }
6758e35bf83SLandon J. Fuller 
6768e35bf83SLandon J. Fuller  /**
6778e35bf83SLandon J. Fuller  * Attempt to remove a service provider registration for @p dev.
6788e35bf83SLandon J. Fuller  *
6798e35bf83SLandon J. Fuller  * @param dev		The device to be deregistered as a service provider.
6808e35bf83SLandon J. Fuller  * @param service	The service for which @p dev will be deregistered, or
6818e35bf83SLandon J. Fuller  *			BHND_SERVICE_INVALID to remove all service registrations
6828e35bf83SLandon J. Fuller  *			for @p dev.
6838e35bf83SLandon J. Fuller  *
6848e35bf83SLandon J. Fuller  * @retval 0		success
6858e35bf83SLandon J. Fuller  * @retval EBUSY	if active references to @p dev exist; @see
6868e35bf83SLandon J. Fuller  *			bhnd_retain_provider() and bhnd_release_provider().
6878e35bf83SLandon J. Fuller  */
6888e35bf83SLandon J. Fuller static inline int
bhnd_deregister_provider(device_t dev,bhnd_service_t service)6898e35bf83SLandon J. Fuller bhnd_deregister_provider(device_t dev, bhnd_service_t service)
6908e35bf83SLandon J. Fuller {
6918e35bf83SLandon J. Fuller 	return (BHND_BUS_DEREGISTER_PROVIDER(device_get_parent(dev), dev, dev,
6928e35bf83SLandon J. Fuller 	    service));
6938e35bf83SLandon J. Fuller }
6948e35bf83SLandon J. Fuller 
6958e35bf83SLandon J. Fuller /**
6968e35bf83SLandon J. Fuller  * Retain and return a reference to the registered @p service provider, if any.
6978e35bf83SLandon J. Fuller  *
6988e35bf83SLandon J. Fuller  * @param dev		The requesting device.
6998e35bf83SLandon J. Fuller  * @param service	The service for which a provider should be returned.
7008e35bf83SLandon J. Fuller  *
7018e35bf83SLandon J. Fuller  * On success, the caller assumes ownership the returned provider, and
7028e35bf83SLandon J. Fuller  * is responsible for releasing this reference via
7038e35bf83SLandon J. Fuller  * BHND_BUS_RELEASE_PROVIDER().
7048e35bf83SLandon J. Fuller  *
7058e35bf83SLandon J. Fuller  * @retval device_t	success
7068e35bf83SLandon J. Fuller  * @retval NULL		if no provider is registered for @p service.
7078e35bf83SLandon J. Fuller  */
7088e35bf83SLandon J. Fuller static inline device_t
bhnd_retain_provider(device_t dev,bhnd_service_t service)7098e35bf83SLandon J. Fuller bhnd_retain_provider(device_t dev, bhnd_service_t service)
7108e35bf83SLandon J. Fuller {
7118e35bf83SLandon J. Fuller 	return (BHND_BUS_RETAIN_PROVIDER(device_get_parent(dev), dev,
7128e35bf83SLandon J. Fuller 	    service));
7138e35bf83SLandon J. Fuller }
7148e35bf83SLandon J. Fuller 
7158e35bf83SLandon J. Fuller /**
7168e35bf83SLandon J. Fuller  * Release a reference to a provider device previously returned by
7178e35bf83SLandon J. Fuller  * bhnd_retain_provider().
7188e35bf83SLandon J. Fuller  *
7198e35bf83SLandon J. Fuller  * @param dev The requesting device.
7208e35bf83SLandon J. Fuller  * @param provider The provider to be released.
7218e35bf83SLandon J. Fuller  * @param service The service for which @p provider was previously retained.
7228e35bf83SLandon J. Fuller  */
7238e35bf83SLandon J. Fuller static inline void
bhnd_release_provider(device_t dev,device_t provider,bhnd_service_t service)7248e35bf83SLandon J. Fuller bhnd_release_provider(device_t dev, device_t provider,
7258e35bf83SLandon J. Fuller     bhnd_service_t service)
7268e35bf83SLandon J. Fuller {
7278e35bf83SLandon J. Fuller 	return (BHND_BUS_RELEASE_PROVIDER(device_get_parent(dev), dev,
7288e35bf83SLandon J. Fuller 	    provider, service));
7298e35bf83SLandon J. Fuller }
7308e35bf83SLandon J. Fuller 
7318e35bf83SLandon J. Fuller /**
7324ad7e9b0SAdrian Chadd  * Return true if the hardware components required by @p dev are known to be
7334ad7e9b0SAdrian Chadd  * unpopulated or otherwise unusable.
7344ad7e9b0SAdrian Chadd  *
7354ad7e9b0SAdrian Chadd  * In some cases, enumerated devices may have pins that are left floating, or
7364ad7e9b0SAdrian Chadd  * the hardware may otherwise be non-functional; this method allows a parent
7374ad7e9b0SAdrian Chadd  * device to explicitly specify if a successfully enumerated @p dev should
7384ad7e9b0SAdrian Chadd  * be disabled.
7394ad7e9b0SAdrian Chadd  *
7404ad7e9b0SAdrian Chadd  * @param dev A bhnd bus child device.
7414ad7e9b0SAdrian Chadd  */
7424ad7e9b0SAdrian Chadd static inline bool
bhnd_is_hw_disabled(device_t dev)7434ad7e9b0SAdrian Chadd bhnd_is_hw_disabled(device_t dev) {
7444ad7e9b0SAdrian Chadd 	return (BHND_BUS_IS_HW_DISABLED(device_get_parent(dev), dev));
7454ad7e9b0SAdrian Chadd }
7464ad7e9b0SAdrian Chadd 
7474ad7e9b0SAdrian Chadd /**
748f74f1a68SAdrian Chadd  * Return the BHND chip identification info for the bhnd bus.
749f74f1a68SAdrian Chadd  *
750f74f1a68SAdrian Chadd  * @param dev A bhnd bus child device.
751f74f1a68SAdrian Chadd  */
752f74f1a68SAdrian Chadd static inline const struct bhnd_chipid *
bhnd_get_chipid(device_t dev)753f74f1a68SAdrian Chadd bhnd_get_chipid(device_t dev) {
754f74f1a68SAdrian Chadd 	return (BHND_BUS_GET_CHIPID(device_get_parent(dev), dev));
755f74f1a68SAdrian Chadd };
756f74f1a68SAdrian Chadd 
7578a03f98aSLandon J. Fuller /**
7588a03f98aSLandon J. Fuller  * Read the current value of a bhnd(4) device's per-core I/O control register.
7598a03f98aSLandon J. Fuller  *
7608a03f98aSLandon J. Fuller  * @param dev The bhnd bus child device to be queried.
7618a03f98aSLandon J. Fuller  * @param[out] ioctl On success, the I/O control register value.
7628a03f98aSLandon J. Fuller  *
7638a03f98aSLandon J. Fuller  * @retval 0 success
7648a03f98aSLandon J. Fuller  * @retval EINVAL If @p child is not a direct child of @p dev.
7658a03f98aSLandon J. Fuller  * @retval ENODEV If agent/config space for @p child is unavailable.
7668a03f98aSLandon J. Fuller  * @retval non-zero If reading the IOCTL register otherwise fails, a regular
7678a03f98aSLandon J. Fuller  * unix error code will be returned.
7688a03f98aSLandon J. Fuller  */
7698a03f98aSLandon J. Fuller static inline int
bhnd_read_ioctl(device_t dev,uint16_t * ioctl)7708a03f98aSLandon J. Fuller bhnd_read_ioctl(device_t dev, uint16_t *ioctl)
7718a03f98aSLandon J. Fuller {
7728a03f98aSLandon J. Fuller 	return (BHND_BUS_READ_IOCTL(device_get_parent(dev), dev, ioctl));
7738a03f98aSLandon J. Fuller }
7748a03f98aSLandon J. Fuller 
7758a03f98aSLandon J. Fuller /**
7768a03f98aSLandon J. Fuller  * Write @p value and @p mask to a bhnd(4) device's per-core I/O control
7778a03f98aSLandon J. Fuller  * register.
7788a03f98aSLandon J. Fuller  *
7798a03f98aSLandon J. Fuller  * @param dev The bhnd bus child device for which the IOCTL register will be
7808a03f98aSLandon J. Fuller  * written.
7818a03f98aSLandon J. Fuller  * @param value The value to be written (see BHND_IOCTL_*).
7828a03f98aSLandon J. Fuller  * @param mask Only the bits defined by @p mask will be updated from @p value.
7838a03f98aSLandon J. Fuller  *
7848a03f98aSLandon J. Fuller  * @retval 0 success
7858a03f98aSLandon J. Fuller  * @retval EINVAL If @p child is not a direct child of @p dev.
7868a03f98aSLandon J. Fuller  * @retval ENODEV If agent/config space for @p child is unavailable.
7878a03f98aSLandon J. Fuller  * @retval non-zero If writing the IOCTL register otherwise fails, a regular
7888a03f98aSLandon J. Fuller  * unix error code will be returned.
7898a03f98aSLandon J. Fuller  */
7908a03f98aSLandon J. Fuller static inline int
bhnd_write_ioctl(device_t dev,uint16_t value,uint16_t mask)7918a03f98aSLandon J. Fuller bhnd_write_ioctl(device_t dev, uint16_t value, uint16_t mask)
7928a03f98aSLandon J. Fuller {
7938a03f98aSLandon J. Fuller 	return (BHND_BUS_WRITE_IOCTL(device_get_parent(dev), dev, value, mask));
7948a03f98aSLandon J. Fuller }
7958a03f98aSLandon J. Fuller 
7968a03f98aSLandon J. Fuller /**
7978a03f98aSLandon J. Fuller  * Read the current value of a bhnd(4) device's per-core I/O status register.
7988a03f98aSLandon J. Fuller  *
7998a03f98aSLandon J. Fuller  * @param dev The bhnd bus child device to be queried.
8008a03f98aSLandon J. Fuller  * @param[out] iost On success, the I/O status register value.
8018a03f98aSLandon J. Fuller  *
8028a03f98aSLandon J. Fuller  * @retval 0 success
8038a03f98aSLandon J. Fuller  * @retval EINVAL If @p child is not a direct child of @p dev.
8048a03f98aSLandon J. Fuller  * @retval ENODEV If agent/config space for @p child is unavailable.
8058a03f98aSLandon J. Fuller  * @retval non-zero If reading the IOST register otherwise fails, a regular
8068a03f98aSLandon J. Fuller  * unix error code will be returned.
8078a03f98aSLandon J. Fuller  */
8088a03f98aSLandon J. Fuller static inline int
bhnd_read_iost(device_t dev,uint16_t * iost)8098a03f98aSLandon J. Fuller bhnd_read_iost(device_t dev, uint16_t *iost)
8108a03f98aSLandon J. Fuller {
8118a03f98aSLandon J. Fuller 	return (BHND_BUS_READ_IOST(device_get_parent(dev), dev, iost));
8128a03f98aSLandon J. Fuller }
8138a03f98aSLandon J. Fuller 
8148a03f98aSLandon J. Fuller /**
8158a03f98aSLandon J. Fuller  * Return true if the given bhnd device's hardware is currently held
8168a03f98aSLandon J. Fuller  * in a RESET state or otherwise not clocked (BHND_IOCTL_CLK_EN).
8178a03f98aSLandon J. Fuller  *
8188a03f98aSLandon J. Fuller  * @param dev The device to query.
8198a03f98aSLandon J. Fuller  *
8208a03f98aSLandon J. Fuller  * @retval true If @p dev is held in RESET or not clocked (BHND_IOCTL_CLK_EN),
82188cdf609SGordon Bergling  * or an error occurred determining @p dev's hardware state.
8228a03f98aSLandon J. Fuller  * @retval false If @p dev is clocked and is not held in RESET.
8238a03f98aSLandon J. Fuller  */
8248a03f98aSLandon J. Fuller static inline bool
bhnd_is_hw_suspended(device_t dev)8258a03f98aSLandon J. Fuller bhnd_is_hw_suspended(device_t dev)
8268a03f98aSLandon J. Fuller {
8278a03f98aSLandon J. Fuller 	return (BHND_BUS_IS_HW_SUSPENDED(device_get_parent(dev), dev));
8288a03f98aSLandon J. Fuller }
8298a03f98aSLandon J. Fuller 
8308a03f98aSLandon J. Fuller /**
831ac59515bSLandon J. Fuller  * Place the bhnd(4) device's hardware into a low-power RESET state with
832ac59515bSLandon J. Fuller  * the @p reset_ioctl I/O control flags set, and then bring the hardware out of
833ac59515bSLandon J. Fuller  * RESET with the @p ioctl I/O control flags set.
8348a03f98aSLandon J. Fuller  *
835ac59515bSLandon J. Fuller  * Any clock or resource PMU requests previously made by @p child will be
8368a03f98aSLandon J. Fuller  * invalidated.
8378a03f98aSLandon J. Fuller  *
8388a03f98aSLandon J. Fuller  * @param dev The device to be reset.
839ac59515bSLandon J. Fuller  * @param ioctl Device-specific I/O control flags to be set when bringing
840ac59515bSLandon J. Fuller  * the core out of its RESET state (see BHND_IOCTL_*).
841ac59515bSLandon J. Fuller  * @param reset_ioctl Device-specific I/O control flags to be set when placing
842ac59515bSLandon J. Fuller  * the core into its RESET state.
8438a03f98aSLandon J. Fuller  *
8448a03f98aSLandon J. Fuller  * @retval 0 success
8458a03f98aSLandon J. Fuller  * @retval non-zero error
8468a03f98aSLandon J. Fuller  */
8478a03f98aSLandon J. Fuller static inline int
bhnd_reset_hw(device_t dev,uint16_t ioctl,uint16_t reset_ioctl)848ac59515bSLandon J. Fuller bhnd_reset_hw(device_t dev, uint16_t ioctl, uint16_t reset_ioctl)
8498a03f98aSLandon J. Fuller {
850ac59515bSLandon J. Fuller 	return (BHND_BUS_RESET_HW(device_get_parent(dev), dev, ioctl,
851ac59515bSLandon J. Fuller 	    reset_ioctl));
8528a03f98aSLandon J. Fuller }
8538a03f98aSLandon J. Fuller 
8548a03f98aSLandon J. Fuller /**
8558a03f98aSLandon J. Fuller  * Suspend @p child's hardware in a low-power reset state.
8568a03f98aSLandon J. Fuller  *
8578a03f98aSLandon J. Fuller  * Any clock or resource PMU requests previously made by @p dev will be
8588a03f98aSLandon J. Fuller  * invalidated.
8598a03f98aSLandon J. Fuller  *
8608a03f98aSLandon J. Fuller  * The hardware may be brought out of reset via bhnd_reset_hw().
8618a03f98aSLandon J. Fuller  *
8628a03f98aSLandon J. Fuller  * @param dev The device to be suspended.
8638a03f98aSLandon J. Fuller  *
8648a03f98aSLandon J. Fuller  * @retval 0 success
8658a03f98aSLandon J. Fuller  * @retval non-zero error
8668a03f98aSLandon J. Fuller  */
8678a03f98aSLandon J. Fuller static inline int
bhnd_suspend_hw(device_t dev,uint16_t ioctl)868ac59515bSLandon J. Fuller bhnd_suspend_hw(device_t dev, uint16_t ioctl)
8698a03f98aSLandon J. Fuller {
870ac59515bSLandon J. Fuller 	return (BHND_BUS_SUSPEND_HW(device_get_parent(dev), dev, ioctl));
8718a03f98aSLandon J. Fuller }
8728a03f98aSLandon J. Fuller 
873e83ce340SAdrian Chadd /**
8749d292ea1SAdrian Chadd  * Return the BHND attachment type of the parent bhnd bus.
8759d292ea1SAdrian Chadd  *
8769d292ea1SAdrian Chadd  * @param dev A bhnd bus child device.
8779d292ea1SAdrian Chadd  *
8789d292ea1SAdrian Chadd  * @retval BHND_ATTACH_ADAPTER if the bus is resident on a bridged adapter,
8799d292ea1SAdrian Chadd  * such as a WiFi chipset.
8809d292ea1SAdrian Chadd  * @retval BHND_ATTACH_NATIVE if the bus provides hardware services (clock,
8819d292ea1SAdrian Chadd  * CPU, etc) to a directly attached native host.
8829d292ea1SAdrian Chadd  */
8839d292ea1SAdrian Chadd static inline bhnd_attach_type
bhnd_get_attach_type(device_t dev)8849d292ea1SAdrian Chadd bhnd_get_attach_type (device_t dev) {
8859d292ea1SAdrian Chadd 	return (BHND_BUS_GET_ATTACH_TYPE(device_get_parent(dev), dev));
8869d292ea1SAdrian Chadd }
8879d292ea1SAdrian Chadd 
8889d292ea1SAdrian Chadd /**
8899ed45324SLandon J. Fuller  * Find the best available DMA address translation capable of mapping a
8909ed45324SLandon J. Fuller  * physical host address to a BHND DMA device address of @p width with
8919ed45324SLandon J. Fuller  * @p flags.
8929ed45324SLandon J. Fuller  *
8939ed45324SLandon J. Fuller  * @param dev A bhnd bus child device.
8949ed45324SLandon J. Fuller  * @param width The address width within which the translation window must
8959ed45324SLandon J. Fuller  * reside (see BHND_DMA_ADDR_*).
8969ed45324SLandon J. Fuller  * @param flags Required translation flags (see BHND_DMA_TRANSLATION_*).
8979ed45324SLandon J. Fuller  * @param[out] dmat On success, will be populated with a DMA tag specifying the
8989ed45324SLandon J. Fuller  * @p translation DMA address restrictions. This argment may be NULL if the DMA
8999ed45324SLandon J. Fuller  * tag is not desired.
9009ed45324SLandon J. Fuller  * the set of valid host DMA addresses reachable via @p translation.
9019ed45324SLandon J. Fuller  * @param[out] translation On success, will be populated with a DMA address
9029ed45324SLandon J. Fuller  * translation descriptor for @p child. This argment may be NULL if the
9039ed45324SLandon J. Fuller  * descriptor is not desired.
9049ed45324SLandon J. Fuller  *
9059ed45324SLandon J. Fuller  * @retval 0 success
9069ed45324SLandon J. Fuller  * @retval ENODEV If DMA is not supported.
9079ed45324SLandon J. Fuller  * @retval ENOENT If no DMA translation matching @p width and @p flags is
9089ed45324SLandon J. Fuller  * available.
9099ed45324SLandon J. Fuller  * @retval non-zero If determining the DMA address translation for @p child
9109ed45324SLandon J. Fuller  * otherwise fails, a regular unix error code will be returned.
9119ed45324SLandon J. Fuller  */
9129ed45324SLandon J. Fuller static inline int
bhnd_get_dma_translation(device_t dev,u_int width,uint32_t flags,bus_dma_tag_t * dmat,struct bhnd_dma_translation * translation)9139ed45324SLandon J. Fuller bhnd_get_dma_translation(device_t dev, u_int width, uint32_t flags,
9149ed45324SLandon J. Fuller     bus_dma_tag_t *dmat, struct bhnd_dma_translation *translation)
9159ed45324SLandon J. Fuller {
9169ed45324SLandon J. Fuller 	return (BHND_BUS_GET_DMA_TRANSLATION(device_get_parent(dev), dev, width,
9179ed45324SLandon J. Fuller 	    flags, dmat, translation));
9189ed45324SLandon J. Fuller }
9199ed45324SLandon J. Fuller 
9209ed45324SLandon J. Fuller /**
921d567592bSAdrian Chadd  * Attempt to read the BHND board identification from the bhnd bus.
922d567592bSAdrian Chadd  *
923d567592bSAdrian Chadd  * This relies on NVRAM access, and will fail if a valid NVRAM device cannot
924d567592bSAdrian Chadd  * be found, or is not yet attached.
925d567592bSAdrian Chadd  *
92605ed3f90SLandon J. Fuller  * @param dev The bhnd device requesting board info.
927d567592bSAdrian Chadd  * @param[out] info On success, will be populated with the bhnd(4) device's
928d567592bSAdrian Chadd  * board information.
929d567592bSAdrian Chadd  *
930d567592bSAdrian Chadd  * @retval 0 success
931d567592bSAdrian Chadd  * @retval ENODEV	No valid NVRAM source could be found.
932d567592bSAdrian Chadd  * @retval non-zero	If reading @p name otherwise fails, a regular unix
933d567592bSAdrian Chadd  *			error code will be returned.
934d567592bSAdrian Chadd  */
935d567592bSAdrian Chadd static inline int
bhnd_read_board_info(device_t dev,struct bhnd_board_info * info)936d567592bSAdrian Chadd bhnd_read_board_info(device_t dev, struct bhnd_board_info *info)
937d567592bSAdrian Chadd {
938d567592bSAdrian Chadd 	return (BHND_BUS_READ_BOARD_INFO(device_get_parent(dev), dev, info));
939d567592bSAdrian Chadd }
940d567592bSAdrian Chadd 
941d567592bSAdrian Chadd /**
942caeff9a3SLandon J. Fuller  * Return the number of interrupt lines assigned to @p dev.
943824b48efSLandon J. Fuller  *
944824b48efSLandon J. Fuller  * @param dev A bhnd bus child device.
945824b48efSLandon J. Fuller  */
946caeff9a3SLandon J. Fuller static inline u_int
bhnd_get_intr_count(device_t dev)947824b48efSLandon J. Fuller bhnd_get_intr_count(device_t dev)
948824b48efSLandon J. Fuller {
949824b48efSLandon J. Fuller 	return (BHND_BUS_GET_INTR_COUNT(device_get_parent(dev), dev));
950824b48efSLandon J. Fuller }
951824b48efSLandon J. Fuller 
952824b48efSLandon J. Fuller /**
953caeff9a3SLandon J. Fuller  * Get the backplane interrupt vector of the @p intr line attached to @p dev.
954824b48efSLandon J. Fuller  *
955824b48efSLandon J. Fuller  * @param dev A bhnd bus child device.
956caeff9a3SLandon J. Fuller  * @param intr The index of the interrupt line being queried.
957caeff9a3SLandon J. Fuller  * @param[out] ivec On success, the assigned hardware interrupt vector will be
958824b48efSLandon J. Fuller  * written to this pointer.
959824b48efSLandon J. Fuller  *
960824b48efSLandon J. Fuller  * On bcma(4) devices, this returns the OOB bus line assigned to the
961824b48efSLandon J. Fuller  * interrupt.
962824b48efSLandon J. Fuller  *
963824b48efSLandon J. Fuller  * On siba(4) devices, this returns the target OCP slave flag number assigned
964824b48efSLandon J. Fuller  * to the interrupt.
965824b48efSLandon J. Fuller  *
966824b48efSLandon J. Fuller  * @retval 0		success
967caeff9a3SLandon J. Fuller  * @retval ENXIO	If @p intr exceeds the number of interrupt lines
968caeff9a3SLandon J. Fuller  *			assigned to @p child.
969824b48efSLandon J. Fuller  */
970824b48efSLandon J. Fuller static inline int
bhnd_get_intr_ivec(device_t dev,u_int intr,u_int * ivec)971caeff9a3SLandon J. Fuller bhnd_get_intr_ivec(device_t dev, u_int intr, u_int *ivec)
972824b48efSLandon J. Fuller {
973caeff9a3SLandon J. Fuller 	return (BHND_BUS_GET_INTR_IVEC(device_get_parent(dev), dev, intr,
974824b48efSLandon J. Fuller 	    ivec));
975824b48efSLandon J. Fuller }
976824b48efSLandon J. Fuller 
977824b48efSLandon J. Fuller /**
978caeff9a3SLandon J. Fuller  * Map the given @p intr to an IRQ number; until unmapped, this IRQ may be used
979caeff9a3SLandon J. Fuller  * to allocate a resource of type SYS_RES_IRQ.
980caeff9a3SLandon J. Fuller  *
981caeff9a3SLandon J. Fuller  * On success, the caller assumes ownership of the interrupt mapping, and
982caeff9a3SLandon J. Fuller  * is responsible for releasing the mapping via bhnd_unmap_intr().
983caeff9a3SLandon J. Fuller  *
984caeff9a3SLandon J. Fuller  * @param dev The requesting device.
985caeff9a3SLandon J. Fuller  * @param intr The interrupt being mapped.
986caeff9a3SLandon J. Fuller  * @param[out] irq On success, the bus interrupt value mapped for @p intr.
987caeff9a3SLandon J. Fuller  *
988caeff9a3SLandon J. Fuller  * @retval 0		If an interrupt was assigned.
989caeff9a3SLandon J. Fuller  * @retval non-zero	If mapping an interrupt otherwise fails, a regular
990caeff9a3SLandon J. Fuller  *			unix error code will be returned.
991caeff9a3SLandon J. Fuller  */
992caeff9a3SLandon J. Fuller static inline int
bhnd_map_intr(device_t dev,u_int intr,rman_res_t * irq)993caeff9a3SLandon J. Fuller bhnd_map_intr(device_t dev, u_int intr, rman_res_t *irq)
994caeff9a3SLandon J. Fuller {
995caeff9a3SLandon J. Fuller 	return (BHND_BUS_MAP_INTR(device_get_parent(dev), dev, intr, irq));
996caeff9a3SLandon J. Fuller }
997caeff9a3SLandon J. Fuller 
998caeff9a3SLandon J. Fuller /**
999caeff9a3SLandon J. Fuller  * Unmap an bus interrupt previously mapped via bhnd_map_intr().
1000caeff9a3SLandon J. Fuller  *
1001caeff9a3SLandon J. Fuller  * @param dev The requesting device.
100205ed3f90SLandon J. Fuller  * @param irq The interrupt value being unmapped.
1003caeff9a3SLandon J. Fuller  */
1004caeff9a3SLandon J. Fuller static inline void
bhnd_unmap_intr(device_t dev,rman_res_t irq)1005caeff9a3SLandon J. Fuller bhnd_unmap_intr(device_t dev, rman_res_t irq)
1006caeff9a3SLandon J. Fuller {
1007caeff9a3SLandon J. Fuller 	return (BHND_BUS_UNMAP_INTR(device_get_parent(dev), dev, irq));
1008caeff9a3SLandon J. Fuller }
1009caeff9a3SLandon J. Fuller 
1010caeff9a3SLandon J. Fuller /**
1011f90f4b65SLandon J. Fuller  * Allocate and enable per-core PMU request handling for @p child.
1012f90f4b65SLandon J. Fuller  *
1013f90f4b65SLandon J. Fuller  * The region containing the core's PMU register block (if any) must be
1014f90f4b65SLandon J. Fuller  * allocated via bus_alloc_resource(9) (or bhnd_alloc_resource) before
1015f90f4b65SLandon J. Fuller  * calling bhnd_alloc_pmu(), and must not be released until after
1016f90f4b65SLandon J. Fuller  * calling bhnd_release_pmu().
1017f90f4b65SLandon J. Fuller  *
10184e96bf3aSLandon J. Fuller  * @param dev The requesting bhnd device.
1019f90f4b65SLandon J. Fuller  *
1020f90f4b65SLandon J. Fuller  * @retval 0           success
1021f90f4b65SLandon J. Fuller  * @retval non-zero    If allocating PMU request state otherwise fails, a
1022f90f4b65SLandon J. Fuller  *                     regular unix error code will be returned.
1023f90f4b65SLandon J. Fuller  */
1024f90f4b65SLandon J. Fuller static inline int
bhnd_alloc_pmu(device_t dev)1025f90f4b65SLandon J. Fuller bhnd_alloc_pmu(device_t dev)
1026f90f4b65SLandon J. Fuller {
1027f90f4b65SLandon J. Fuller 	return (BHND_BUS_ALLOC_PMU(device_get_parent(dev), dev));
1028f90f4b65SLandon J. Fuller }
1029f90f4b65SLandon J. Fuller 
1030f90f4b65SLandon J. Fuller /**
1031f90f4b65SLandon J. Fuller  * Release any per-core PMU resources allocated for @p child. Any outstanding
1032f90f4b65SLandon J. Fuller  * PMU requests are are discarded.
1033f90f4b65SLandon J. Fuller  *
10344e96bf3aSLandon J. Fuller  * @param dev The requesting bhnd device.
1035f90f4b65SLandon J. Fuller  *
1036f90f4b65SLandon J. Fuller  * @retval 0           success
1037f90f4b65SLandon J. Fuller  * @retval non-zero    If releasing PMU request state otherwise fails, a
1038f90f4b65SLandon J. Fuller  *                     regular unix error code will be returned, and
1039f90f4b65SLandon J. Fuller  *                     the core state will be left unmodified.
1040f90f4b65SLandon J. Fuller  */
1041f90f4b65SLandon J. Fuller static inline int
bhnd_release_pmu(device_t dev)1042f90f4b65SLandon J. Fuller bhnd_release_pmu(device_t dev)
1043f90f4b65SLandon J. Fuller {
1044f90f4b65SLandon J. Fuller 	return (BHND_BUS_RELEASE_PMU(device_get_parent(dev), dev));
1045f90f4b65SLandon J. Fuller }
1046f90f4b65SLandon J. Fuller 
1047f90f4b65SLandon J. Fuller /**
10484e96bf3aSLandon J. Fuller  * Return the transition latency required for @p clock in microseconds, if
10494e96bf3aSLandon J. Fuller  * known.
10504e96bf3aSLandon J. Fuller  *
10514e96bf3aSLandon J. Fuller  * The BHND_CLOCK_HT latency value is suitable for use as the D11 core's
10524e96bf3aSLandon J. Fuller  * 'fastpwrup_dly' value.
10534e96bf3aSLandon J. Fuller  *
10544e96bf3aSLandon J. Fuller  * @note A driver must ask the bhnd bus to allocate PMU request state
10554e96bf3aSLandon J. Fuller  * via BHND_BUS_ALLOC_PMU() before querying PMU clocks.
10564e96bf3aSLandon J. Fuller  *
10574e96bf3aSLandon J. Fuller  * @param dev The requesting bhnd device.
10584e96bf3aSLandon J. Fuller  * @param clock	The clock to be queried for transition latency.
10594e96bf3aSLandon J. Fuller  * @param[out] latency On success, the transition latency of @p clock in
10604e96bf3aSLandon J. Fuller  * microseconds.
10614e96bf3aSLandon J. Fuller  *
10624e96bf3aSLandon J. Fuller  * @retval 0		success
10634e96bf3aSLandon J. Fuller  * @retval ENODEV	If the transition latency for @p clock is not available.
10644e96bf3aSLandon J. Fuller  */
10654e96bf3aSLandon J. Fuller static inline int
bhnd_get_clock_latency(device_t dev,bhnd_clock clock,u_int * latency)10664e96bf3aSLandon J. Fuller bhnd_get_clock_latency(device_t dev, bhnd_clock clock, u_int *latency)
10674e96bf3aSLandon J. Fuller {
10684e96bf3aSLandon J. Fuller 	return (BHND_BUS_GET_CLOCK_LATENCY(device_get_parent(dev), dev, clock,
10694e96bf3aSLandon J. Fuller 	    latency));
10704e96bf3aSLandon J. Fuller }
10714e96bf3aSLandon J. Fuller 
10724e96bf3aSLandon J. Fuller /**
10734e96bf3aSLandon J. Fuller  * Return the frequency for @p clock in Hz, if known.
10744e96bf3aSLandon J. Fuller  *
10754e96bf3aSLandon J. Fuller  * @param dev The requesting bhnd device.
10764e96bf3aSLandon J. Fuller  * @param clock The clock to be queried.
10774e96bf3aSLandon J. Fuller  * @param[out] freq On success, the frequency of @p clock in Hz.
10784e96bf3aSLandon J. Fuller  *
10794e96bf3aSLandon J. Fuller  * @note A driver must ask the bhnd bus to allocate PMU request state
10804e96bf3aSLandon J. Fuller  * via BHND_BUS_ALLOC_PMU() before querying PMU clocks.
10814e96bf3aSLandon J. Fuller  *
10824e96bf3aSLandon J. Fuller  * @retval 0		success
10834e96bf3aSLandon J. Fuller  * @retval ENODEV	If the frequency for @p clock is not available.
10844e96bf3aSLandon J. Fuller  */
10854e96bf3aSLandon J. Fuller static inline int
bhnd_get_clock_freq(device_t dev,bhnd_clock clock,u_int * freq)10864e96bf3aSLandon J. Fuller bhnd_get_clock_freq(device_t dev, bhnd_clock clock, u_int *freq)
10874e96bf3aSLandon J. Fuller {
10884e96bf3aSLandon J. Fuller 	return (BHND_BUS_GET_CLOCK_FREQ(device_get_parent(dev), dev, clock,
10894e96bf3aSLandon J. Fuller 	    freq));
10904e96bf3aSLandon J. Fuller }
10914e96bf3aSLandon J. Fuller 
10924e96bf3aSLandon J. Fuller /**
1093f90f4b65SLandon J. Fuller  * Request that @p clock (or faster) be routed to @p dev.
1094f90f4b65SLandon J. Fuller  *
10958a03f98aSLandon J. Fuller  * @note A driver must ask the bhnd bus to allocate clock request state
1096f90f4b65SLandon J. Fuller  * via bhnd_alloc_pmu() before it can request clock resources.
1097f90f4b65SLandon J. Fuller  *
10988a03f98aSLandon J. Fuller  * @note Any outstanding PMU clock requests will be discarded upon calling
10998a03f98aSLandon J. Fuller  * BHND_BUS_RESET_HW() or BHND_BUS_SUSPEND_HW().
1100f90f4b65SLandon J. Fuller  *
1101f90f4b65SLandon J. Fuller  * @param dev The bhnd(4) device to which @p clock should be routed.
1102f90f4b65SLandon J. Fuller  * @param clock The requested clock source.
1103f90f4b65SLandon J. Fuller  *
1104f90f4b65SLandon J. Fuller  * @retval 0 success
1105f90f4b65SLandon J. Fuller  * @retval ENODEV If an unsupported clock was requested.
11068a03f98aSLandon J. Fuller  * @retval ENXIO If the PMU has not been initialized or is otherwise unvailable,
1107f90f4b65SLandon J. Fuller  */
1108f90f4b65SLandon J. Fuller static inline int
bhnd_request_clock(device_t dev,bhnd_clock clock)1109f90f4b65SLandon J. Fuller bhnd_request_clock(device_t dev, bhnd_clock clock)
1110f90f4b65SLandon J. Fuller {
1111f90f4b65SLandon J. Fuller 	return (BHND_BUS_REQUEST_CLOCK(device_get_parent(dev), dev, clock));
1112f90f4b65SLandon J. Fuller }
1113f90f4b65SLandon J. Fuller 
1114f90f4b65SLandon J. Fuller /**
1115f90f4b65SLandon J. Fuller  * Request that @p clocks be powered on behalf of @p dev.
1116f90f4b65SLandon J. Fuller  *
1117f90f4b65SLandon J. Fuller  * This will power any clock sources (e.g. XTAL, PLL, etc) required for
1118f90f4b65SLandon J. Fuller  * @p clocks and wait until they are ready, discarding any previous
1119f90f4b65SLandon J. Fuller  * requests by @p dev.
1120f90f4b65SLandon J. Fuller  *
11218a03f98aSLandon J. Fuller  * @note A driver must ask the bhnd bus to allocate clock request state
1122f90f4b65SLandon J. Fuller  * via bhnd_alloc_pmu() before it can request clock resources.
1123f90f4b65SLandon J. Fuller  *
11248a03f98aSLandon J. Fuller  * @note Any outstanding PMU clock requests will be discarded upon calling
11258a03f98aSLandon J. Fuller  * BHND_BUS_RESET_HW() or BHND_BUS_SUSPEND_HW().
11268a03f98aSLandon J. Fuller  *
1127f90f4b65SLandon J. Fuller  * @param dev The requesting bhnd(4) device.
1128f90f4b65SLandon J. Fuller  * @param clocks The clock(s) to be enabled.
1129f90f4b65SLandon J. Fuller  *
1130f90f4b65SLandon J. Fuller  * @retval 0 success
1131f90f4b65SLandon J. Fuller  * @retval ENODEV If an unsupported clock was requested.
1132f90f4b65SLandon J. Fuller  * @retval ENXIO If the PMU has not been initialized or is otherwise unvailable.
1133f90f4b65SLandon J. Fuller  */
1134f90f4b65SLandon J. Fuller static inline int
bhnd_enable_clocks(device_t dev,uint32_t clocks)1135f90f4b65SLandon J. Fuller bhnd_enable_clocks(device_t dev, uint32_t clocks)
1136f90f4b65SLandon J. Fuller {
1137f90f4b65SLandon J. Fuller 	return (BHND_BUS_ENABLE_CLOCKS(device_get_parent(dev), dev, clocks));
1138f90f4b65SLandon J. Fuller }
1139f90f4b65SLandon J. Fuller 
1140f90f4b65SLandon J. Fuller /**
1141f90f4b65SLandon J. Fuller  * Power up an external PMU-managed resource assigned to @p dev.
1142f90f4b65SLandon J. Fuller  *
11438a03f98aSLandon J. Fuller  * @note A driver must ask the bhnd bus to allocate PMU request state
1144f90f4b65SLandon J. Fuller  * via bhnd_alloc_pmu() before it can request PMU resources.
1145f90f4b65SLandon J. Fuller  *
11468a03f98aSLandon J. Fuller  * @note Any outstanding PMU resource requests will be released upon calling
11478a03f98aSLandon J. Fuller  * bhnd_reset_hw() or bhnd_suspend_hw().
11488a03f98aSLandon J. Fuller  *
1149f90f4b65SLandon J. Fuller  * @param dev The requesting bhnd(4) device.
1150f90f4b65SLandon J. Fuller  * @param rsrc The core-specific external resource identifier.
1151f90f4b65SLandon J. Fuller  *
1152f90f4b65SLandon J. Fuller  * @retval 0 success
1153f90f4b65SLandon J. Fuller  * @retval ENODEV If the PMU does not support @p rsrc.
1154f90f4b65SLandon J. Fuller  * @retval ENXIO If the PMU has not been initialized or is otherwise unvailable.
1155f90f4b65SLandon J. Fuller  */
1156f90f4b65SLandon J. Fuller static inline int
bhnd_request_ext_rsrc(device_t dev,u_int rsrc)1157f90f4b65SLandon J. Fuller bhnd_request_ext_rsrc(device_t dev, u_int rsrc)
1158f90f4b65SLandon J. Fuller {
1159f90f4b65SLandon J. Fuller 	return (BHND_BUS_REQUEST_EXT_RSRC(device_get_parent(dev), dev, rsrc));
1160f90f4b65SLandon J. Fuller }
1161f90f4b65SLandon J. Fuller 
1162f90f4b65SLandon J. Fuller /**
1163f90f4b65SLandon J. Fuller  * Power down an external PMU-managed resource assigned to @p dev.
1164f90f4b65SLandon J. Fuller  *
1165f90f4b65SLandon J. Fuller  * A driver must ask the bhnd bus to allocate PMU request state
1166f90f4b65SLandon J. Fuller  * via bhnd_alloc_pmu() before it can request PMU resources.
1167f90f4b65SLandon J. Fuller  *
1168f90f4b65SLandon J. Fuller  * @param dev The requesting bhnd(4) device.
1169f90f4b65SLandon J. Fuller  * @param rsrc The core-specific external resource identifier.
1170f90f4b65SLandon J. Fuller  *
1171f90f4b65SLandon J. Fuller  * @retval 0 success
1172f90f4b65SLandon J. Fuller  * @retval ENODEV If the PMU does not support @p rsrc.
1173f90f4b65SLandon J. Fuller  * @retval ENXIO If the PMU has not been initialized or is otherwise unvailable.
1174f90f4b65SLandon J. Fuller  */
1175f90f4b65SLandon J. Fuller static inline int
bhnd_release_ext_rsrc(device_t dev,u_int rsrc)1176f90f4b65SLandon J. Fuller bhnd_release_ext_rsrc(device_t dev, u_int rsrc)
1177f90f4b65SLandon J. Fuller {
1178f90f4b65SLandon J. Fuller 	return (BHND_BUS_RELEASE_EXT_RSRC(device_get_parent(dev), dev, rsrc));
1179f90f4b65SLandon J. Fuller }
1180f90f4b65SLandon J. Fuller 
1181f90f4b65SLandon J. Fuller /**
1182f90f4b65SLandon J. Fuller  * Read @p width bytes at @p offset from the bus-specific agent/config
1183f90f4b65SLandon J. Fuller  * space of @p dev.
1184f90f4b65SLandon J. Fuller  *
1185f90f4b65SLandon J. Fuller  * @param dev The bhnd device for which @p offset should be read.
1186f90f4b65SLandon J. Fuller  * @param offset The offset to be read.
11878a03f98aSLandon J. Fuller  * @param[out] value On success, the will be set to the @p width value read
11888a03f98aSLandon J. Fuller  * at @p offset.
1189f90f4b65SLandon J. Fuller  * @param width The size of the access. Must be 1, 2 or 4 bytes.
1190f90f4b65SLandon J. Fuller  *
1191f90f4b65SLandon J. Fuller  * The exact behavior of this method is bus-specific. In the case of
1192f90f4b65SLandon J. Fuller  * bcma(4), this method provides access to the first agent port of @p child.
1193f90f4b65SLandon J. Fuller  *
1194f90f4b65SLandon J. Fuller  * @note Device drivers should only use this API for functionality
1195f90f4b65SLandon J. Fuller  * that is not available via another bhnd(4) function.
11968a03f98aSLandon J. Fuller  *
11978a03f98aSLandon J. Fuller  * @retval 0 success
11988a03f98aSLandon J. Fuller  * @retval EINVAL If @p child is not a direct child of @p dev.
11998a03f98aSLandon J. Fuller  * @retval EINVAL If @p width is not one of 1, 2, or 4 bytes.
12008a03f98aSLandon J. Fuller  * @retval ENODEV If accessing agent/config space for @p child is unsupported.
12018a03f98aSLandon J. Fuller  * @retval EFAULT If reading @p width at @p offset exceeds the bounds of
12028a03f98aSLandon J. Fuller  * the mapped agent/config space  for @p child.
1203f90f4b65SLandon J. Fuller  */
1204f90f4b65SLandon J. Fuller static inline uint32_t
bhnd_read_config(device_t dev,bus_size_t offset,void * value,u_int width)12058a03f98aSLandon J. Fuller bhnd_read_config(device_t dev, bus_size_t offset, void *value, u_int width)
1206f90f4b65SLandon J. Fuller {
1207f90f4b65SLandon J. Fuller 	return (BHND_BUS_READ_CONFIG(device_get_parent(dev), dev, offset,
12088a03f98aSLandon J. Fuller 	    value, width));
1209f90f4b65SLandon J. Fuller }
1210f90f4b65SLandon J. Fuller 
1211f90f4b65SLandon J. Fuller /**
12128a03f98aSLandon J. Fuller  * Write @p width bytes at @p offset to the bus-specific agent/config
1213f90f4b65SLandon J. Fuller  * space of @p dev.
1214f90f4b65SLandon J. Fuller  *
1215f90f4b65SLandon J. Fuller  * @param dev The bhnd device for which @p offset should be read.
1216f90f4b65SLandon J. Fuller  * @param offset The offset to be written.
12178a03f98aSLandon J. Fuller  * @param value A pointer to the value to be written.
12188a03f98aSLandon J. Fuller  * @param width The size of @p value. Must be 1, 2 or 4 bytes.
1219f90f4b65SLandon J. Fuller  *
1220f90f4b65SLandon J. Fuller  * The exact behavior of this method is bus-specific. In the case of
1221f90f4b65SLandon J. Fuller  * bcma(4), this method provides access to the first agent port of @p child.
1222f90f4b65SLandon J. Fuller  *
1223f90f4b65SLandon J. Fuller  * @note Device drivers should only use this API for functionality
1224f90f4b65SLandon J. Fuller  * that is not available via another bhnd(4) function.
12258a03f98aSLandon J. Fuller  *
12268a03f98aSLandon J. Fuller  * @retval 0 success
12278a03f98aSLandon J. Fuller  * @retval EINVAL If @p child is not a direct child of @p dev.
12288a03f98aSLandon J. Fuller  * @retval EINVAL If @p width is not one of 1, 2, or 4 bytes.
12298a03f98aSLandon J. Fuller  * @retval ENODEV If accessing agent/config space for @p child is unsupported.
12308a03f98aSLandon J. Fuller  * @retval EFAULT If reading @p width at @p offset exceeds the bounds of
12318a03f98aSLandon J. Fuller  * the mapped agent/config space  for @p child.
1232f90f4b65SLandon J. Fuller  */
12338a03f98aSLandon J. Fuller static inline int
bhnd_write_config(device_t dev,bus_size_t offset,const void * value,u_int width)12348a03f98aSLandon J. Fuller bhnd_write_config(device_t dev, bus_size_t offset, const void *value,
12358a03f98aSLandon J. Fuller     u_int width)
1236f90f4b65SLandon J. Fuller {
12378a03f98aSLandon J. Fuller 	return (BHND_BUS_WRITE_CONFIG(device_get_parent(dev), dev, offset,
12388a03f98aSLandon J. Fuller 	    value, width));
1239f90f4b65SLandon J. Fuller }
1240f90f4b65SLandon J. Fuller 
1241f90f4b65SLandon J. Fuller /**
12421728aef2SLandon J. Fuller  * Read an NVRAM variable, coerced to the requested @p type.
1243e83ce340SAdrian Chadd  *
1244e83ce340SAdrian Chadd  * @param 		dev	A bhnd bus child device.
1245e83ce340SAdrian Chadd  * @param		name	The NVRAM variable name.
12461728aef2SLandon J. Fuller  * @param[out]		buf	A buffer large enough to hold @p len bytes. On
12471728aef2SLandon J. Fuller  *				success, the requested value will be written to
12481728aef2SLandon J. Fuller  *				this buffer. This argment may be NULL if
12491728aef2SLandon J. Fuller  *				the value is not desired.
12501728aef2SLandon J. Fuller  * @param[in,out]	len	The maximum capacity of @p buf. On success,
12511728aef2SLandon J. Fuller  *				will be set to the actual size of the requested
12521728aef2SLandon J. Fuller  *				value.
12531728aef2SLandon J. Fuller  * @param		type	The desired data representation to be written
12541728aef2SLandon J. Fuller  *				to @p buf.
1255e83ce340SAdrian Chadd  *
1256e83ce340SAdrian Chadd  * @retval 0		success
1257e83ce340SAdrian Chadd  * @retval ENOENT	The requested variable was not found.
1258d567592bSAdrian Chadd  * @retval ENODEV	No valid NVRAM source could be found.
12591728aef2SLandon J. Fuller  * @retval ENOMEM	If a buffer of @p size is too small to hold the
12601728aef2SLandon J. Fuller  *			requested value.
12611728aef2SLandon J. Fuller  * @retval EOPNOTSUPP	If the value cannot be coerced to @p type.
12621728aef2SLandon J. Fuller  * @retval ERANGE	If value coercion would overflow @p type.
1263e83ce340SAdrian Chadd  * @retval non-zero	If reading @p name otherwise fails, a regular unix
1264e83ce340SAdrian Chadd  *			error code will be returned.
1265e83ce340SAdrian Chadd  */
1266e83ce340SAdrian Chadd static inline int
bhnd_nvram_getvar(device_t dev,const char * name,void * buf,size_t * len,bhnd_nvram_type type)12671728aef2SLandon J. Fuller bhnd_nvram_getvar(device_t dev, const char *name, void *buf, size_t *len,
12681728aef2SLandon J. Fuller      bhnd_nvram_type type)
1269e83ce340SAdrian Chadd {
1270e83ce340SAdrian Chadd 	return (BHND_BUS_GET_NVRAM_VAR(device_get_parent(dev), dev, name, buf,
12711728aef2SLandon J. Fuller 	    len, type));
1272e83ce340SAdrian Chadd }
1273f74f1a68SAdrian Chadd 
1274f74f1a68SAdrian Chadd /**
12754ad7e9b0SAdrian Chadd  * Allocate a resource from a device's parent bhnd(4) bus.
12764ad7e9b0SAdrian Chadd  *
12774ad7e9b0SAdrian Chadd  * @param dev The device requesting resource ownership.
12784ad7e9b0SAdrian Chadd  * @param type The type of resource to allocate. This may be any type supported
12794ad7e9b0SAdrian Chadd  * by the standard bus APIs.
12804ad7e9b0SAdrian Chadd  * @param rid The bus-specific handle identifying the resource being allocated.
12814ad7e9b0SAdrian Chadd  * @param start The start address of the resource.
12824ad7e9b0SAdrian Chadd  * @param end The end address of the resource.
12834ad7e9b0SAdrian Chadd  * @param count The size of the resource.
12844ad7e9b0SAdrian Chadd  * @param flags The flags for the resource to be allocated. These may be any
12854ad7e9b0SAdrian Chadd  * values supported by the standard bus APIs.
12864ad7e9b0SAdrian Chadd  *
12874ad7e9b0SAdrian Chadd  * To request the resource's default addresses, pass @p start and
1288534ccd7bSJustin Hibbits  * @p end values of @c 0 and @c ~0, respectively, and
12894ad7e9b0SAdrian Chadd  * a @p count of @c 1.
12904ad7e9b0SAdrian Chadd  *
12914ad7e9b0SAdrian Chadd  * @retval NULL The resource could not be allocated.
12924ad7e9b0SAdrian Chadd  * @retval resource The allocated resource.
12934ad7e9b0SAdrian Chadd  */
12944ad7e9b0SAdrian Chadd static inline struct bhnd_resource *
bhnd_alloc_resource(device_t dev,int type,int * rid,rman_res_t start,rman_res_t end,rman_res_t count,u_int flags)12954ad7e9b0SAdrian Chadd bhnd_alloc_resource(device_t dev, int type, int *rid, rman_res_t start,
12964ad7e9b0SAdrian Chadd     rman_res_t end, rman_res_t count, u_int flags)
12974ad7e9b0SAdrian Chadd {
12984ad7e9b0SAdrian Chadd 	return BHND_BUS_ALLOC_RESOURCE(device_get_parent(dev), dev, type, rid,
12994ad7e9b0SAdrian Chadd 	    start, end, count, flags);
13004ad7e9b0SAdrian Chadd }
13014ad7e9b0SAdrian Chadd 
13024ad7e9b0SAdrian Chadd /**
13034ad7e9b0SAdrian Chadd  * Allocate a resource from a device's parent bhnd(4) bus, using the
13044ad7e9b0SAdrian Chadd  * resource's default start, end, and count values.
13054ad7e9b0SAdrian Chadd  *
13064ad7e9b0SAdrian Chadd  * @param dev The device requesting resource ownership.
13074ad7e9b0SAdrian Chadd  * @param type The type of resource to allocate. This may be any type supported
13084ad7e9b0SAdrian Chadd  * by the standard bus APIs.
13094ad7e9b0SAdrian Chadd  * @param rid The bus-specific handle identifying the resource being allocated.
13104ad7e9b0SAdrian Chadd  * @param flags The flags for the resource to be allocated. These may be any
13114ad7e9b0SAdrian Chadd  * values supported by the standard bus APIs.
13124ad7e9b0SAdrian Chadd  *
13134ad7e9b0SAdrian Chadd  * @retval NULL The resource could not be allocated.
13144ad7e9b0SAdrian Chadd  * @retval resource The allocated resource.
13154ad7e9b0SAdrian Chadd  */
13164ad7e9b0SAdrian Chadd static inline struct bhnd_resource *
bhnd_alloc_resource_any(device_t dev,int type,int * rid,u_int flags)13174ad7e9b0SAdrian Chadd bhnd_alloc_resource_any(device_t dev, int type, int *rid, u_int flags)
13184ad7e9b0SAdrian Chadd {
1319534ccd7bSJustin Hibbits 	return bhnd_alloc_resource(dev, type, rid, 0, ~0, 1, flags);
13204ad7e9b0SAdrian Chadd }
13214ad7e9b0SAdrian Chadd 
13224ad7e9b0SAdrian Chadd /**
13234ad7e9b0SAdrian Chadd  * Activate a previously allocated bhnd resource.
13244ad7e9b0SAdrian Chadd  *
13254ad7e9b0SAdrian Chadd  * @param dev The device holding ownership of the allocated resource.
13264ad7e9b0SAdrian Chadd  * @param type The type of the resource.
13274ad7e9b0SAdrian Chadd  * @param rid The bus-specific handle identifying the resource.
13284ad7e9b0SAdrian Chadd  * @param r A pointer to the resource returned by bhnd_alloc_resource or
13294ad7e9b0SAdrian Chadd  * BHND_BUS_ALLOC_RESOURCE.
13304ad7e9b0SAdrian Chadd  *
13314ad7e9b0SAdrian Chadd  * @retval 0 success
1332453130d9SPedro F. Giffuni  * @retval non-zero an error occurred while activating the resource.
13334ad7e9b0SAdrian Chadd  */
13344ad7e9b0SAdrian Chadd static inline int
bhnd_activate_resource(device_t dev,int type,int rid,struct bhnd_resource * r)13354ad7e9b0SAdrian Chadd bhnd_activate_resource(device_t dev, int type, int rid,
13364ad7e9b0SAdrian Chadd    struct bhnd_resource *r)
13374ad7e9b0SAdrian Chadd {
13384ad7e9b0SAdrian Chadd 	return BHND_BUS_ACTIVATE_RESOURCE(device_get_parent(dev), dev, type,
13394ad7e9b0SAdrian Chadd 	    rid, r);
13404ad7e9b0SAdrian Chadd }
13414ad7e9b0SAdrian Chadd 
13424ad7e9b0SAdrian Chadd /**
13434ad7e9b0SAdrian Chadd  * Deactivate a previously activated bhnd resource.
13444ad7e9b0SAdrian Chadd  *
13454ad7e9b0SAdrian Chadd  * @param dev The device holding ownership of the activated resource.
13464ad7e9b0SAdrian Chadd  * @param type The type of the resource.
13474ad7e9b0SAdrian Chadd  * @param rid The bus-specific handle identifying the resource.
13484ad7e9b0SAdrian Chadd  * @param r A pointer to the resource returned by bhnd_alloc_resource or
13494ad7e9b0SAdrian Chadd  * BHND_BUS_ALLOC_RESOURCE.
13504ad7e9b0SAdrian Chadd  *
13514ad7e9b0SAdrian Chadd  * @retval 0 success
1352453130d9SPedro F. Giffuni  * @retval non-zero an error occurred while activating the resource.
13534ad7e9b0SAdrian Chadd  */
13544ad7e9b0SAdrian Chadd static inline int
bhnd_deactivate_resource(device_t dev,int type,int rid,struct bhnd_resource * r)13554ad7e9b0SAdrian Chadd bhnd_deactivate_resource(device_t dev, int type, int rid,
13564ad7e9b0SAdrian Chadd    struct bhnd_resource *r)
13574ad7e9b0SAdrian Chadd {
13584ad7e9b0SAdrian Chadd 	return BHND_BUS_DEACTIVATE_RESOURCE(device_get_parent(dev), dev, type,
13594ad7e9b0SAdrian Chadd 	    rid, r);
13604ad7e9b0SAdrian Chadd }
13614ad7e9b0SAdrian Chadd 
13624ad7e9b0SAdrian Chadd /**
13634ad7e9b0SAdrian Chadd  * Free a resource allocated by bhnd_alloc_resource().
13644ad7e9b0SAdrian Chadd  *
13654ad7e9b0SAdrian Chadd  * @param dev The device holding ownership of the resource.
13664ad7e9b0SAdrian Chadd  * @param type The type of the resource.
13674ad7e9b0SAdrian Chadd  * @param rid The bus-specific handle identifying the resource.
13684ad7e9b0SAdrian Chadd  * @param r A pointer to the resource returned by bhnd_alloc_resource or
13694ad7e9b0SAdrian Chadd  * BHND_ALLOC_RESOURCE.
13704ad7e9b0SAdrian Chadd  *
13714ad7e9b0SAdrian Chadd  * @retval 0 success
1372453130d9SPedro F. Giffuni  * @retval non-zero an error occurred while activating the resource.
13734ad7e9b0SAdrian Chadd  */
13744ad7e9b0SAdrian Chadd static inline int
bhnd_release_resource(device_t dev,int type,int rid,struct bhnd_resource * r)13754ad7e9b0SAdrian Chadd bhnd_release_resource(device_t dev, int type, int rid,
13764ad7e9b0SAdrian Chadd    struct bhnd_resource *r)
13774ad7e9b0SAdrian Chadd {
13784ad7e9b0SAdrian Chadd 	return BHND_BUS_RELEASE_RESOURCE(device_get_parent(dev), dev, type,
13794ad7e9b0SAdrian Chadd 	    rid, r);
13804ad7e9b0SAdrian Chadd }
13814ad7e9b0SAdrian Chadd 
13824ad7e9b0SAdrian Chadd /**
13834ad7e9b0SAdrian Chadd  * Return true if @p region_num is a valid region on @p port_num of
13844ad7e9b0SAdrian Chadd  * @p type attached to @p dev.
13854ad7e9b0SAdrian Chadd  *
13864ad7e9b0SAdrian Chadd  * @param dev A bhnd bus child device.
13874ad7e9b0SAdrian Chadd  * @param type The port type being queried.
138805ed3f90SLandon J. Fuller  * @param port The port number being queried.
138905ed3f90SLandon J. Fuller  * @param region The region number being queried.
13904ad7e9b0SAdrian Chadd  */
13914ad7e9b0SAdrian Chadd static inline bool
bhnd_is_region_valid(device_t dev,bhnd_port_type type,u_int port,u_int region)139205ed3f90SLandon J. Fuller bhnd_is_region_valid(device_t dev, bhnd_port_type type, u_int port,
139305ed3f90SLandon J. Fuller     u_int region)
13944ad7e9b0SAdrian Chadd {
13954ad7e9b0SAdrian Chadd 	return (BHND_BUS_IS_REGION_VALID(device_get_parent(dev), dev, type,
139605ed3f90SLandon J. Fuller 	    port, region));
13974ad7e9b0SAdrian Chadd }
13984ad7e9b0SAdrian Chadd 
13994ad7e9b0SAdrian Chadd /**
14004ad7e9b0SAdrian Chadd  * Return the number of ports of type @p type attached to @p def.
14014ad7e9b0SAdrian Chadd  *
14024ad7e9b0SAdrian Chadd  * @param dev A bhnd bus child device.
14034ad7e9b0SAdrian Chadd  * @param type The port type being queried.
14044ad7e9b0SAdrian Chadd  */
14054ad7e9b0SAdrian Chadd static inline u_int
bhnd_get_port_count(device_t dev,bhnd_port_type type)14064ad7e9b0SAdrian Chadd bhnd_get_port_count(device_t dev, bhnd_port_type type) {
14074ad7e9b0SAdrian Chadd 	return (BHND_BUS_GET_PORT_COUNT(device_get_parent(dev), dev, type));
14084ad7e9b0SAdrian Chadd }
14094ad7e9b0SAdrian Chadd 
14104ad7e9b0SAdrian Chadd /**
14114ad7e9b0SAdrian Chadd  * Return the number of memory regions mapped to @p child @p port of
14124ad7e9b0SAdrian Chadd  * type @p type.
14134ad7e9b0SAdrian Chadd  *
14144ad7e9b0SAdrian Chadd  * @param dev A bhnd bus child device.
14154ad7e9b0SAdrian Chadd  * @param port The port number being queried.
14164ad7e9b0SAdrian Chadd  * @param type The port type being queried.
14174ad7e9b0SAdrian Chadd  */
14184ad7e9b0SAdrian Chadd static inline u_int
bhnd_get_region_count(device_t dev,bhnd_port_type type,u_int port)14194ad7e9b0SAdrian Chadd bhnd_get_region_count(device_t dev, bhnd_port_type type, u_int port) {
14204ad7e9b0SAdrian Chadd 	return (BHND_BUS_GET_REGION_COUNT(device_get_parent(dev), dev, type,
14214ad7e9b0SAdrian Chadd 	    port));
14224ad7e9b0SAdrian Chadd }
14234ad7e9b0SAdrian Chadd 
14244ad7e9b0SAdrian Chadd /**
14254ad7e9b0SAdrian Chadd  * Return the resource-ID for a memory region on the given device port.
14264ad7e9b0SAdrian Chadd  *
14274ad7e9b0SAdrian Chadd  * @param dev A bhnd bus child device.
14284ad7e9b0SAdrian Chadd  * @param type The port type.
14294ad7e9b0SAdrian Chadd  * @param port The port identifier.
14304ad7e9b0SAdrian Chadd  * @param region The identifier of the memory region on @p port.
14314ad7e9b0SAdrian Chadd  *
14324ad7e9b0SAdrian Chadd  * @retval int The RID for the given @p port and @p region on @p device.
14334ad7e9b0SAdrian Chadd  * @retval -1 No such port/region found.
14344ad7e9b0SAdrian Chadd  */
14354ad7e9b0SAdrian Chadd static inline int
bhnd_get_port_rid(device_t dev,bhnd_port_type type,u_int port,u_int region)14364ad7e9b0SAdrian Chadd bhnd_get_port_rid(device_t dev, bhnd_port_type type, u_int port, u_int region)
14374ad7e9b0SAdrian Chadd {
14384ad7e9b0SAdrian Chadd 	return BHND_BUS_GET_PORT_RID(device_get_parent(dev), dev, type, port,
14394ad7e9b0SAdrian Chadd 	    region);
14404ad7e9b0SAdrian Chadd }
14414ad7e9b0SAdrian Chadd 
14424ad7e9b0SAdrian Chadd /**
14434ad7e9b0SAdrian Chadd  * Decode a port / region pair on @p dev defined by @p rid.
14444ad7e9b0SAdrian Chadd  *
14454ad7e9b0SAdrian Chadd  * @param dev A bhnd bus child device.
14464ad7e9b0SAdrian Chadd  * @param type The resource type.
14474ad7e9b0SAdrian Chadd  * @param rid The resource identifier.
14484ad7e9b0SAdrian Chadd  * @param[out] port_type The decoded port type.
14494ad7e9b0SAdrian Chadd  * @param[out] port The decoded port identifier.
14504ad7e9b0SAdrian Chadd  * @param[out] region The decoded region identifier.
14514ad7e9b0SAdrian Chadd  *
14524ad7e9b0SAdrian Chadd  * @retval 0 success
14534ad7e9b0SAdrian Chadd  * @retval non-zero No matching port/region found.
14544ad7e9b0SAdrian Chadd  */
14554ad7e9b0SAdrian Chadd static inline int
bhnd_decode_port_rid(device_t dev,int type,int rid,bhnd_port_type * port_type,u_int * port,u_int * region)14564ad7e9b0SAdrian Chadd bhnd_decode_port_rid(device_t dev, int type, int rid, bhnd_port_type *port_type,
14574ad7e9b0SAdrian Chadd     u_int *port, u_int *region)
14584ad7e9b0SAdrian Chadd {
14594ad7e9b0SAdrian Chadd 	return BHND_BUS_DECODE_PORT_RID(device_get_parent(dev), dev, type, rid,
14604ad7e9b0SAdrian Chadd 	    port_type, port, region);
14614ad7e9b0SAdrian Chadd }
14624ad7e9b0SAdrian Chadd 
14634ad7e9b0SAdrian Chadd /**
14644ad7e9b0SAdrian Chadd  * Get the address and size of @p region on @p port.
14654ad7e9b0SAdrian Chadd  *
14664ad7e9b0SAdrian Chadd  * @param dev A bhnd bus child device.
14674ad7e9b0SAdrian Chadd  * @param port_type The port type.
14684ad7e9b0SAdrian Chadd  * @param port The port identifier.
14694ad7e9b0SAdrian Chadd  * @param region The identifier of the memory region on @p port.
14704ad7e9b0SAdrian Chadd  * @param[out] region_addr The region's base address.
14714ad7e9b0SAdrian Chadd  * @param[out] region_size The region's size.
14724ad7e9b0SAdrian Chadd  *
14734ad7e9b0SAdrian Chadd  * @retval 0 success
14744ad7e9b0SAdrian Chadd  * @retval non-zero No matching port/region found.
14754ad7e9b0SAdrian Chadd  */
14764ad7e9b0SAdrian Chadd static inline int
bhnd_get_region_addr(device_t dev,bhnd_port_type port_type,u_int port,u_int region,bhnd_addr_t * region_addr,bhnd_size_t * region_size)14774ad7e9b0SAdrian Chadd bhnd_get_region_addr(device_t dev, bhnd_port_type port_type, u_int port,
14784ad7e9b0SAdrian Chadd     u_int region, bhnd_addr_t *region_addr, bhnd_size_t *region_size)
14794ad7e9b0SAdrian Chadd {
14804ad7e9b0SAdrian Chadd 	return BHND_BUS_GET_REGION_ADDR(device_get_parent(dev), dev, port_type,
14814ad7e9b0SAdrian Chadd 	    port, region, region_addr, region_size);
14824ad7e9b0SAdrian Chadd }
14834ad7e9b0SAdrian Chadd 
14844ad7e9b0SAdrian Chadd /*
14854ad7e9b0SAdrian Chadd  * bhnd bus-level equivalents of the bus_(read|write|set|barrier|...)
14864ad7e9b0SAdrian Chadd  * macros (compatible with bhnd_resource).
14874ad7e9b0SAdrian Chadd  *
14884ad7e9b0SAdrian Chadd  * Generated with bhnd/tools/bus_macro.sh
14894ad7e9b0SAdrian Chadd  */
14904ad7e9b0SAdrian Chadd #define bhnd_bus_barrier(r, o, l, f) \
14917f1c814bSLandon J. Fuller     (((r)->direct) ? \
14924ad7e9b0SAdrian Chadd 	bus_barrier((r)->res, (o), (l), (f)) : \
1493a73ac06dSAdrian Chadd 	BHND_BUS_BARRIER( \
1494a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
14957f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (l), (f)))
14964ad7e9b0SAdrian Chadd #define bhnd_bus_read_1(r, o) \
14977f1c814bSLandon J. Fuller     (((r)->direct) ? \
14984ad7e9b0SAdrian Chadd 	bus_read_1((r)->res, (o)) : \
1499a73ac06dSAdrian Chadd 	BHND_BUS_READ_1( \
1500a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
15017f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o)))
1502a73ac06dSAdrian Chadd #define bhnd_bus_read_multi_1(r, o, d, c) \
15037f1c814bSLandon J. Fuller     (((r)->direct) ? \
1504a73ac06dSAdrian Chadd 	bus_read_multi_1((r)->res, (o), (d), (c)) : \
1505a73ac06dSAdrian Chadd 	BHND_BUS_READ_MULTI_1( \
1506a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
15077f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
15080e141e3cSAdrian Chadd #define bhnd_bus_read_region_1(r, o, d, c) \
15097f1c814bSLandon J. Fuller     (((r)->direct) ? \
15100e141e3cSAdrian Chadd 	bus_read_region_1((r)->res, (o), (d), (c)) : \
15110e141e3cSAdrian Chadd 	BHND_BUS_READ_REGION_1( \
15120e141e3cSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
15137f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
15144ad7e9b0SAdrian Chadd #define bhnd_bus_write_1(r, o, v) \
15157f1c814bSLandon J. Fuller     (((r)->direct) ? \
15164ad7e9b0SAdrian Chadd 	bus_write_1((r)->res, (o), (v)) : \
1517a73ac06dSAdrian Chadd 	BHND_BUS_WRITE_1( \
1518a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
15197f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (v)))
1520a73ac06dSAdrian Chadd #define bhnd_bus_write_multi_1(r, o, d, c) \
15217f1c814bSLandon J. Fuller     (((r)->direct) ? \
1522a73ac06dSAdrian Chadd 	bus_write_multi_1((r)->res, (o), (d), (c)) : \
1523a73ac06dSAdrian Chadd 	BHND_BUS_WRITE_MULTI_1( \
1524a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
15257f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
15260e141e3cSAdrian Chadd #define bhnd_bus_write_region_1(r, o, d, c) \
15277f1c814bSLandon J. Fuller     (((r)->direct) ? \
15280e141e3cSAdrian Chadd 	bus_write_region_1((r)->res, (o), (d), (c)) : \
15290e141e3cSAdrian Chadd 	BHND_BUS_WRITE_REGION_1( \
15300e141e3cSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
15317f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
1532a73ac06dSAdrian Chadd #define bhnd_bus_read_stream_1(r, o) \
15337f1c814bSLandon J. Fuller     (((r)->direct) ? \
1534a73ac06dSAdrian Chadd 	bus_read_stream_1((r)->res, (o)) : \
1535a73ac06dSAdrian Chadd 	BHND_BUS_READ_STREAM_1( \
1536a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
15377f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o)))
1538a73ac06dSAdrian Chadd #define bhnd_bus_read_multi_stream_1(r, o, d, c) \
15397f1c814bSLandon J. Fuller     (((r)->direct) ? \
1540a73ac06dSAdrian Chadd 	bus_read_multi_stream_1((r)->res, (o), (d), (c)) : \
1541a73ac06dSAdrian Chadd 	BHND_BUS_READ_MULTI_STREAM_1( \
1542a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
15437f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
15440e141e3cSAdrian Chadd #define bhnd_bus_read_region_stream_1(r, o, d, c) \
15457f1c814bSLandon J. Fuller     (((r)->direct) ? \
15460e141e3cSAdrian Chadd 	bus_read_region_stream_1((r)->res, (o), (d), (c)) : \
15470e141e3cSAdrian Chadd 	BHND_BUS_READ_REGION_STREAM_1( \
15480e141e3cSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
15497f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
1550a73ac06dSAdrian Chadd #define bhnd_bus_write_stream_1(r, o, v) \
15517f1c814bSLandon J. Fuller     (((r)->direct) ? \
1552a73ac06dSAdrian Chadd 	bus_write_stream_1((r)->res, (o), (v)) : \
1553a73ac06dSAdrian Chadd 	BHND_BUS_WRITE_STREAM_1( \
1554a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
15557f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (v)))
1556a73ac06dSAdrian Chadd #define bhnd_bus_write_multi_stream_1(r, o, d, c) \
15577f1c814bSLandon J. Fuller     (((r)->direct) ? \
1558a73ac06dSAdrian Chadd 	bus_write_multi_stream_1((r)->res, (o), (d), (c)) : \
1559a73ac06dSAdrian Chadd 	BHND_BUS_WRITE_MULTI_STREAM_1( \
1560a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
15617f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
15620e141e3cSAdrian Chadd #define bhnd_bus_write_region_stream_1(r, o, d, c) \
15637f1c814bSLandon J. Fuller     (((r)->direct) ? \
15640e141e3cSAdrian Chadd 	bus_write_region_stream_1((r)->res, (o), (d), (c)) : \
15650e141e3cSAdrian Chadd 	BHND_BUS_WRITE_REGION_STREAM_1( \
15660e141e3cSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
15677f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
15680e141e3cSAdrian Chadd #define bhnd_bus_set_multi_1(r, o, v, c) \
15697f1c814bSLandon J. Fuller     (((r)->direct) ? \
15700e141e3cSAdrian Chadd 	bus_set_multi_1((r)->res, (o), (v), (c)) : \
15710e141e3cSAdrian Chadd 	BHND_BUS_SET_MULTI_1( \
15720e141e3cSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
15737f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (v), (c)))
15740e141e3cSAdrian Chadd #define bhnd_bus_set_region_1(r, o, v, c) \
15757f1c814bSLandon J. Fuller     (((r)->direct) ? \
15760e141e3cSAdrian Chadd 	bus_set_region_1((r)->res, (o), (v), (c)) : \
15770e141e3cSAdrian Chadd 	BHND_BUS_SET_REGION_1( \
15780e141e3cSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
15797f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (v), (c)))
15804ad7e9b0SAdrian Chadd #define bhnd_bus_read_2(r, o) \
15817f1c814bSLandon J. Fuller     (((r)->direct) ? \
15824ad7e9b0SAdrian Chadd 	bus_read_2((r)->res, (o)) : \
1583a73ac06dSAdrian Chadd 	BHND_BUS_READ_2( \
1584a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
15857f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o)))
1586a73ac06dSAdrian Chadd #define bhnd_bus_read_multi_2(r, o, d, c) \
15877f1c814bSLandon J. Fuller     (((r)->direct) ? \
1588a73ac06dSAdrian Chadd 	bus_read_multi_2((r)->res, (o), (d), (c)) : \
1589a73ac06dSAdrian Chadd 	BHND_BUS_READ_MULTI_2( \
1590a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
15917f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
15920e141e3cSAdrian Chadd #define bhnd_bus_read_region_2(r, o, d, c) \
15937f1c814bSLandon J. Fuller     (((r)->direct) ? \
15940e141e3cSAdrian Chadd 	bus_read_region_2((r)->res, (o), (d), (c)) : \
15950e141e3cSAdrian Chadd 	BHND_BUS_READ_REGION_2( \
15960e141e3cSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
15977f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
15984ad7e9b0SAdrian Chadd #define bhnd_bus_write_2(r, o, v) \
15997f1c814bSLandon J. Fuller     (((r)->direct) ? \
16004ad7e9b0SAdrian Chadd 	bus_write_2((r)->res, (o), (v)) : \
1601a73ac06dSAdrian Chadd 	BHND_BUS_WRITE_2( \
1602a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
16037f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (v)))
1604a73ac06dSAdrian Chadd #define bhnd_bus_write_multi_2(r, o, d, c) \
16057f1c814bSLandon J. Fuller     (((r)->direct) ? \
1606a73ac06dSAdrian Chadd 	bus_write_multi_2((r)->res, (o), (d), (c)) : \
1607a73ac06dSAdrian Chadd 	BHND_BUS_WRITE_MULTI_2( \
1608a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
16097f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
16100e141e3cSAdrian Chadd #define bhnd_bus_write_region_2(r, o, d, c) \
16117f1c814bSLandon J. Fuller     (((r)->direct) ? \
16120e141e3cSAdrian Chadd 	bus_write_region_2((r)->res, (o), (d), (c)) : \
16130e141e3cSAdrian Chadd 	BHND_BUS_WRITE_REGION_2( \
16140e141e3cSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
16157f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
1616a73ac06dSAdrian Chadd #define bhnd_bus_read_stream_2(r, o) \
16177f1c814bSLandon J. Fuller     (((r)->direct) ? \
1618a73ac06dSAdrian Chadd 	bus_read_stream_2((r)->res, (o)) : \
1619a73ac06dSAdrian Chadd 	BHND_BUS_READ_STREAM_2( \
1620a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
16217f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o)))
1622a73ac06dSAdrian Chadd #define bhnd_bus_read_multi_stream_2(r, o, d, c) \
16237f1c814bSLandon J. Fuller     (((r)->direct) ? \
1624a73ac06dSAdrian Chadd 	bus_read_multi_stream_2((r)->res, (o), (d), (c)) : \
1625a73ac06dSAdrian Chadd 	BHND_BUS_READ_MULTI_STREAM_2( \
1626a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
16277f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
16280e141e3cSAdrian Chadd #define bhnd_bus_read_region_stream_2(r, o, d, c) \
16297f1c814bSLandon J. Fuller     (((r)->direct) ? \
16300e141e3cSAdrian Chadd 	bus_read_region_stream_2((r)->res, (o), (d), (c)) : \
16310e141e3cSAdrian Chadd 	BHND_BUS_READ_REGION_STREAM_2( \
16320e141e3cSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
16337f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
1634a73ac06dSAdrian Chadd #define bhnd_bus_write_stream_2(r, o, v) \
16357f1c814bSLandon J. Fuller     (((r)->direct) ? \
1636a73ac06dSAdrian Chadd 	bus_write_stream_2((r)->res, (o), (v)) : \
1637a73ac06dSAdrian Chadd 	BHND_BUS_WRITE_STREAM_2( \
1638a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
16397f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (v)))
1640a73ac06dSAdrian Chadd #define bhnd_bus_write_multi_stream_2(r, o, d, c) \
16417f1c814bSLandon J. Fuller     (((r)->direct) ? \
1642a73ac06dSAdrian Chadd 	bus_write_multi_stream_2((r)->res, (o), (d), (c)) : \
1643a73ac06dSAdrian Chadd 	BHND_BUS_WRITE_MULTI_STREAM_2( \
1644a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
16457f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
16460e141e3cSAdrian Chadd #define bhnd_bus_write_region_stream_2(r, o, d, c) \
16477f1c814bSLandon J. Fuller     (((r)->direct) ? \
16480e141e3cSAdrian Chadd 	bus_write_region_stream_2((r)->res, (o), (d), (c)) : \
16490e141e3cSAdrian Chadd 	BHND_BUS_WRITE_REGION_STREAM_2( \
16500e141e3cSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
16517f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
16520e141e3cSAdrian Chadd #define bhnd_bus_set_multi_2(r, o, v, c) \
16537f1c814bSLandon J. Fuller     (((r)->direct) ? \
16540e141e3cSAdrian Chadd 	bus_set_multi_2((r)->res, (o), (v), (c)) : \
16550e141e3cSAdrian Chadd 	BHND_BUS_SET_MULTI_2( \
16560e141e3cSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
16577f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (v), (c)))
16580e141e3cSAdrian Chadd #define bhnd_bus_set_region_2(r, o, v, c) \
16597f1c814bSLandon J. Fuller     (((r)->direct) ? \
16600e141e3cSAdrian Chadd 	bus_set_region_2((r)->res, (o), (v), (c)) : \
16610e141e3cSAdrian Chadd 	BHND_BUS_SET_REGION_2( \
16620e141e3cSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
16637f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (v), (c)))
16644ad7e9b0SAdrian Chadd #define bhnd_bus_read_4(r, o) \
16657f1c814bSLandon J. Fuller     (((r)->direct) ? \
16664ad7e9b0SAdrian Chadd 	bus_read_4((r)->res, (o)) : \
1667a73ac06dSAdrian Chadd 	BHND_BUS_READ_4( \
1668a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
16697f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o)))
1670a73ac06dSAdrian Chadd #define bhnd_bus_read_multi_4(r, o, d, c) \
16717f1c814bSLandon J. Fuller     (((r)->direct) ? \
1672a73ac06dSAdrian Chadd 	bus_read_multi_4((r)->res, (o), (d), (c)) : \
1673a73ac06dSAdrian Chadd 	BHND_BUS_READ_MULTI_4( \
1674a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
16757f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
16760e141e3cSAdrian Chadd #define bhnd_bus_read_region_4(r, o, d, c) \
16777f1c814bSLandon J. Fuller     (((r)->direct) ? \
16780e141e3cSAdrian Chadd 	bus_read_region_4((r)->res, (o), (d), (c)) : \
16790e141e3cSAdrian Chadd 	BHND_BUS_READ_REGION_4( \
16800e141e3cSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
16817f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
16824ad7e9b0SAdrian Chadd #define bhnd_bus_write_4(r, o, v) \
16837f1c814bSLandon J. Fuller     (((r)->direct) ? \
16844ad7e9b0SAdrian Chadd 	bus_write_4((r)->res, (o), (v)) : \
1685a73ac06dSAdrian Chadd 	BHND_BUS_WRITE_4( \
1686a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
16877f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (v)))
1688a73ac06dSAdrian Chadd #define bhnd_bus_write_multi_4(r, o, d, c) \
16897f1c814bSLandon J. Fuller     (((r)->direct) ? \
1690a73ac06dSAdrian Chadd 	bus_write_multi_4((r)->res, (o), (d), (c)) : \
1691a73ac06dSAdrian Chadd 	BHND_BUS_WRITE_MULTI_4( \
1692a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
16937f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
16940e141e3cSAdrian Chadd #define bhnd_bus_write_region_4(r, o, d, c) \
16957f1c814bSLandon J. Fuller     (((r)->direct) ? \
16960e141e3cSAdrian Chadd 	bus_write_region_4((r)->res, (o), (d), (c)) : \
16970e141e3cSAdrian Chadd 	BHND_BUS_WRITE_REGION_4( \
16980e141e3cSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
16997f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
1700a73ac06dSAdrian Chadd #define bhnd_bus_read_stream_4(r, o) \
17017f1c814bSLandon J. Fuller     (((r)->direct) ? \
1702a73ac06dSAdrian Chadd 	bus_read_stream_4((r)->res, (o)) : \
1703a73ac06dSAdrian Chadd 	BHND_BUS_READ_STREAM_4( \
1704a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
17057f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o)))
1706a73ac06dSAdrian Chadd #define bhnd_bus_read_multi_stream_4(r, o, d, c) \
17077f1c814bSLandon J. Fuller     (((r)->direct) ? \
1708a73ac06dSAdrian Chadd 	bus_read_multi_stream_4((r)->res, (o), (d), (c)) : \
1709a73ac06dSAdrian Chadd 	BHND_BUS_READ_MULTI_STREAM_4( \
1710a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
17117f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
17120e141e3cSAdrian Chadd #define bhnd_bus_read_region_stream_4(r, o, d, c) \
17137f1c814bSLandon J. Fuller     (((r)->direct) ? \
17140e141e3cSAdrian Chadd 	bus_read_region_stream_4((r)->res, (o), (d), (c)) : \
17150e141e3cSAdrian Chadd 	BHND_BUS_READ_REGION_STREAM_4( \
17160e141e3cSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
17177f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
1718a73ac06dSAdrian Chadd #define bhnd_bus_write_stream_4(r, o, v) \
17197f1c814bSLandon J. Fuller     (((r)->direct) ? \
1720a73ac06dSAdrian Chadd 	bus_write_stream_4((r)->res, (o), (v)) : \
1721a73ac06dSAdrian Chadd 	BHND_BUS_WRITE_STREAM_4( \
1722a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
17237f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (v)))
1724a73ac06dSAdrian Chadd #define bhnd_bus_write_multi_stream_4(r, o, d, c) \
17257f1c814bSLandon J. Fuller     (((r)->direct) ? \
1726a73ac06dSAdrian Chadd 	bus_write_multi_stream_4((r)->res, (o), (d), (c)) : \
1727a73ac06dSAdrian Chadd 	BHND_BUS_WRITE_MULTI_STREAM_4( \
1728a73ac06dSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
17297f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
17300e141e3cSAdrian Chadd #define bhnd_bus_write_region_stream_4(r, o, d, c) \
17317f1c814bSLandon J. Fuller     (((r)->direct) ? \
17320e141e3cSAdrian Chadd 	bus_write_region_stream_4((r)->res, (o), (d), (c)) : \
17330e141e3cSAdrian Chadd 	BHND_BUS_WRITE_REGION_STREAM_4( \
17340e141e3cSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
17357f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (d), (c)))
17360e141e3cSAdrian Chadd #define bhnd_bus_set_multi_4(r, o, v, c) \
17377f1c814bSLandon J. Fuller     (((r)->direct) ? \
17380e141e3cSAdrian Chadd 	bus_set_multi_4((r)->res, (o), (v), (c)) : \
17390e141e3cSAdrian Chadd 	BHND_BUS_SET_MULTI_4( \
17400e141e3cSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
17417f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (v), (c)))
17420e141e3cSAdrian Chadd #define bhnd_bus_set_region_4(r, o, v, c) \
17437f1c814bSLandon J. Fuller     (((r)->direct) ? \
17440e141e3cSAdrian Chadd 	bus_set_region_4((r)->res, (o), (v), (c)) : \
17450e141e3cSAdrian Chadd 	BHND_BUS_SET_REGION_4( \
17460e141e3cSAdrian Chadd 	    device_get_parent(rman_get_device((r)->res)),	\
17477f1c814bSLandon J. Fuller 	    rman_get_device((r)->res), (r), (o), (v), (c)))
17484ad7e9b0SAdrian Chadd 
17494ad7e9b0SAdrian Chadd #endif /* _BHND_BHND_H_ */
1750