---
name: "bhnd_alloc_resource"
section: "9"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/BHND_MATCH_BOARD_TYPE"
---

# bhnd\_alloc\_resource(9)

BHND driver programming interface

Part of [BHND\_MATCH\_BOARD\_TYPE(9)](/BHND_MATCH_BOARD_TYPE/9.md).

## NAME

**bhnd** – BHND driver programming interface

## SYNOPSIS

**#include \<dev/bhnd/bhnd.h\>**

### Bus Resource Functions

*int*\

**bhnd\_activate\_resource**(*device\_t dev*, *int type*, *int rid*, *struct bhnd\_resource \*r*);

*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*);

*struct bhnd\_resource \**\

**bhnd\_alloc\_resource\_any**(*device\_t dev*, *int type*, *int \*rid*, *u\_int flags*);

*int*\

**bhnd\_alloc\_resources**(*device\_t dev*, *struct resource\_spec \*rs*, *struct bhnd\_resource \*\*res*);

*int*\

**bhnd\_deactivate\_resource**(*device\_t dev*, *int type*, *int rid*, *struct bhnd\_resource \*r*);

*int*\

**bhnd\_release\_resource**(*device\_t dev*, *int type*, *int rid*, *struct bhnd\_resource \*r*);

*void*\

**bhnd\_release\_resources**(*device\_t dev*, *const struct resource\_spec \*rs*, *struct bhnd\_resource \*\*res*);

### Bus Space Functions

*void*\

**bhnd\_bus\_barrier**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *bus\_size\_t length*, *int flags*);

*uint8\_t*\

**bhnd\_bus\_read\_1**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*);

*uint16\_t*\

**bhnd\_bus\_read\_2**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*);

*uint32\_t*\

**bhnd\_bus\_read\_4**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*);

*void*\

**bhnd\_bus\_read\_multi\_1**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint8\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_read\_multi\_2**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint16\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_read\_multi\_4**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint32\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_read\_multi\_stream\_1**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint8\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_read\_multi\_stream\_2**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint16\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_read\_multi\_stream\_4**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint32\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_read\_region\_1**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint8\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_read\_region\_2**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint16\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_read\_region\_4**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint32\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_read\_region\_stream\_1**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint8\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_read\_region\_stream\_2**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint16\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_read\_region\_stream\_4**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint32\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_read\_stream\_1**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*);

*void*\

**bhnd\_bus\_read\_stream\_2**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*);

*uint32\_t*\

**bhnd\_bus\_read\_stream\_4**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*);

*void*\

**bhnd\_bus\_set\_multi\_1**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint8\_t value*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_set\_multi\_2**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint16\_t value*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_set\_multi\_4**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint32\_t value*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_set\_region\_1**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint8\_t value*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_set\_region\_2**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint16\_t value*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_set\_region\_4**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint32\_t value*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_write\_1**(*struct bhnd\_resource \*r*, *uint8\_t value*);

*void*\

**bhnd\_bus\_write\_2**(*struct bhnd\_resource \*r*, *uint16\_t value*);

*void*\

**bhnd\_bus\_write\_4**(*struct bhnd\_resource \*r*, *uint32\_t value*);

*void*\

**bhnd\_bus\_write\_multi\_1**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint8\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_write\_multi\_2**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint16\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_write\_multi\_4**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint32\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_write\_multi\_stream\_1**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint8\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_write\_multi\_stream\_2**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint16\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_write\_multi\_stream\_4**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint32\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_write\_region\_1**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint8\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_write\_region\_2**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint16\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_write\_region\_4**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint32\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_write\_region\_stream\_1**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint8\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_write\_region\_stream\_2**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint16\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_write\_region\_stream\_4**(*struct bhnd\_resource \*r*, *bus\_size\_t offset*, *uint32\_t \*datap*, *bus\_size\_t count*);

*void*\

**bhnd\_bus\_write\_stream\_1**(*struct bhnd\_resource \*r*, *uint8\_t value*);

*void*\

**bhnd\_bus\_write\_stream\_2**(*struct bhnd\_resource \*r*, *uint16\_t value*);

*void*\

**bhnd\_bus\_write\_stream\_4**(*struct bhnd\_resource \*r*, *uint32\_t value*);

### Device Configuration Functions

*int*\

**bhnd\_read\_ioctl**(*device\_t dev*, *uint16\_t \*ioctl*);

*int*\

**bhnd\_write\_ioctl**(*device\_t dev*, *uint16\_t value*, *uint16\_t mask*);

*int*\

**bhnd\_read\_iost**(*device\_t dev*, *uint16\_t \*iost*);

*uint32\_t*\

**bhnd\_read\_config**(*device\_t dev*, *bus\_size\_t offset*, *void \*value*, *u\_int width*);

*int*\

**bhnd\_write\_config**(*device\_t dev*, *bus\_size\_t offset*, *const void \*value*, *u\_int width*);

*int*\

**bhnd\_reset\_hw**(*device\_t dev*, *uint16\_t ioctl*, *uint16\_t reset\_ioctl*);

*int*\

**bhnd\_suspend\_hw**(*device\_t dev*, *uint16\_t ioctl*);

*bool*\

**bhnd\_is\_hw\_suspended**(*device\_t dev*);

### Device Information Functions

*bhnd\_attach\_type*\

**bhnd\_get\_attach\_type**(*device\_t dev*);

*const struct bhnd\_chipid \**\

**bhnd\_get\_chipid**(*device\_t dev*);

*bhnd\_devclass\_t*\

**bhnd\_get\_class**(*device\_t dev*);

*u\_int*\

**bhnd\_get\_core\_index**(*device\_t dev*);

*struct bhnd\_core\_info*\

**bhnd\_get\_core\_info**(*device\_t dev*);

*int*\

**bhnd\_get\_core\_unit**(*device\_t dev*);

*uint16\_t*\

**bhnd\_get\_device**(*device\_t dev*);

*const* *char* *\**\

**bhnd\_get\_device\_name**(*device\_t dev*);

*uint8\_t*\

**bhnd\_get\_hwrev**(*device\_t dev*);

*uint16\_t*\

**bhnd\_get\_vendor**(*device\_t dev*);

*const* *char* *\**\

**bhnd\_get\_vendor\_name**(*device\_t dev*);

*int*\

**bhnd\_read\_board\_info**(*device\_t dev*, *struct bhnd\_board\_info \*info*);

### Device Matching Functions

*bool*\

**bhnd\_board\_matches**(*const struct bhnd\_board\_info \*board*, *const struct bhnd\_board\_match \*desc*);

*device\_t*\

**bhnd\_bus\_match\_child**(*device\_t bus*, *const struct bhnd\_core\_match \*desc*);

*bool*\

**bhnd\_chip\_matches**(*const struct bhnd\_chipid \*chip*, *const struct bhnd\_chip\_match \*desc*);

*struct bhnd\_core\_match*\

**bhnd\_core\_get\_match\_desc**(*const struct bhnd\_core\_info \*core*);

*bool*\

**bhnd\_core\_matches**(*const struct bhnd\_core\_info \*core*, *const struct bhnd\_core\_match \*desc*);

*bool*\

**bhnd\_cores\_equal**(*const struct bhnd\_core\_info \*lhs*, *const struct bhnd\_core\_info \*rhs*);

*bool*\

**bhnd\_hwrev\_matches**(*uint16\_t hwrev*, *const struct bhnd\_hwrev\_match \*desc*);

*const struct bhnd\_core\_info \**\

**bhnd\_match\_core**(*const struct bhnd\_core\_info \*cores*, *u\_int num\_cores*, *const struct bhnd\_core\_match \*desc*);

### Device Table Functions

*const struct bhnd\_device \**\

**bhnd\_device\_lookup**(*device\_t dev*, *const struct bhnd\_device \*table*, *size\_t entry\_size*);

*bool*\

**bhnd\_device\_matches**(*device\_t dev*, *const struct bhnd\_device\_match \*desc*);

*uint32\_t*\

**bhnd\_device\_quirks**(*device\_t dev*, *const struct bhnd\_device \*table*, *size\_t entry\_size*);

**BHND\_BOARD\_QUIRK**(*board*, *flags*);

**BHND\_CHIP\_QUIRK**(*chip*, *hwrev*, *flags*);

**BHND\_CORE\_QUIRK**(*hwrev*, *flags*);

**BHND\_DEVICE**(*vendor*, *device*, *desc*, *quirks*, *...*);

**BHND\_DEVICE\_IS\_END**(*struct bhnd\_device \*d*);

**BHND\_DEVICE\_QUIRK\_IS\_END**(*struct bhnd\_device\_quirk \*q*);

**BHND\_PKG\_QUIRK**(*chip*, *pkg*, *flags*);

```
struct bhnd_device_quirk {
	struct bhnd_device_match	desc;
	uint32_t			quirks;
};
```

```
struct bhnd_device {
    const struct bhnd_device_match	 core;
    const char				*desc;
    const struct bhnd_device_quirk	*quirks_table;
    uint32_t				 device_flags;
};
```

```
enum {
	BHND_DF_ANY	= 0,
	BHND_DF_HOSTB	= (1 << 0),
	BHND_DF_SOC	= (1 << 1),
	BHND_DF_ADAPTER	= (1 << 2)
};
```

```
#define BHND_DEVICE_END { { BHND_MATCH_ANY }, NULL, NULL, 0 }
```

```
#define BHND_DEVICE_QUIRK_END { { BHND_MATCH_ANY }, 0 }
```

### DMA Address Translation Functions

*int*\

**bhnd\_get\_dma\_translation**(*device\_t dev*, *u\_int width*, *uint32\_t flags*, *bus\_dma\_tag\_t \*dmat*, *struct bhnd\_dma\_translation \*translation*);

```
struct bhnd_dma_translation {
	bhnd_addr_t	base_addr;
	bhnd_addr_t	addr_mask;
	bhnd_addr_t	addrext_mask;
	uint32_t	flags;
};
```

```
typedef enum {
	BHND_DMA_ADDR_30BIT	= 30,
	BHND_DMA_ADDR_32BIT	= 32,
	BHND_DMA_ADDR_64BIT	= 64
} bhnd_dma_addrwidth;
```

```
enum bhnd_dma_translation_flags {
	BHND_DMA_TRANSLATION_PHYSMAP		= (1<<0),
	BHND_DMA_TRANSLATION_BYTESWAPPED	= (1<<1)
};
```

### Interrupt Functions

*u\_int*\

**bhnd\_get\_intr\_count**(*device\_t dev*);

*int*\

**bhnd\_get\_intr\_ivec**(*device\_t dev*, *u\_int intr*, *u\_int \*ivec*);

*int*\

**bhnd\_map\_intr**(*device\_t dev*, *u\_int intr*, *rman\_res\_t \*irq*);

*void*\

**bhnd\_unmap\_intr**(*device\_t dev*, *rman\_res\_t irq*);

### NVRAM Functions

*int*\

**bhnd\_nvram\_getvar**(*device\_t dev*, *const char \*name*, *void \*buf*, *size\_t \*len*, *bhnd\_nvram\_type type*);

*int*\

**bhnd\_nvram\_getvar\_array**(*device\_t dev*, *const char \*name*, *void \*buf*, *size\_t size*, *bhnd\_nvram\_type type*);

*int*\

**bhnd\_nvram\_getvar\_int**(*device\_t dev*, *const char \*name*, *void \*value*, *int width*);

*int*\

**bhnd\_nvram\_getvar\_int8**(*device\_t dev*, *const char \*name*, *int8\_t \*value*);

*int*\

**bhnd\_nvram\_getvar\_int16**(*device\_t dev*, *const char \*name*, *int16\_t \*value*);

*int*\

**bhnd\_nvram\_getvar\_int32**(*device\_t dev*, *const char \*name*, *int32\_t \*value*);

*int*\

**bhnd\_nvram\_getvar\_uint**(*device\_t dev*, *const char \*name*, *void \*value*, *int width*);

*int*\

**bhnd\_nvram\_getvar\_uint8**(*device\_t dev*, *const char \*name*, *uint8\_t \*value*);

*int*\

**bhnd\_nvram\_getvar\_uint16**(*device\_t dev*, *const char \*name*, *uint16\_t \*value*);

*int*\

**bhnd\_nvram\_getvar\_uint32**(*device\_t dev*, *const char \*name*, *uint32\_t \*value*);

*int*\

**bhnd\_nvram\_getvar\_str**(*device\_t dev*, *const char \*name*, *char \*buf*, *size\_t len*, *size\_t \*rlen*);

*const char \**\

**bhnd\_nvram\_string\_array\_next**(*const char \*inp*, *size\_t ilen*, *const char \*prev*, *size\_t \*olen*);

```
typedef enum {
	BHND_NVRAM_TYPE_UINT8		= 0,
	BHND_NVRAM_TYPE_UINT16		= 1,
	BHND_NVRAM_TYPE_UINT32		= 2,
	BHND_NVRAM_TYPE_UINT64		= 3,
	BHND_NVRAM_TYPE_INT8		= 4,
	BHND_NVRAM_TYPE_INT16		= 5,
	BHND_NVRAM_TYPE_INT32		= 6,
	BHND_NVRAM_TYPE_INT64		= 7,
	BHND_NVRAM_TYPE_CHAR		= 8,
	BHND_NVRAM_TYPE_STRING		= 9,
	BHND_NVRAM_TYPE_BOOL		= 10,
	BHND_NVRAM_TYPE_NULL		= 11,
	BHND_NVRAM_TYPE_DATA		= 12
	BHND_NVRAM_TYPE_UINT8_ARRAY	= 16,
	BHND_NVRAM_TYPE_UINT16_ARRAY	= 17,
	BHND_NVRAM_TYPE_UINT32_ARRAY	= 18,
	BHND_NVRAM_TYPE_UINT64_ARRAY	= 19,
	BHND_NVRAM_TYPE_INT8_ARRAY	= 20,
	BHND_NVRAM_TYPE_INT16_ARRAY	= 21,
	BHND_NVRAM_TYPE_INT32_ARRAY	= 22,
	BHND_NVRAM_TYPE_INT64_ARRAY	= 23,
	BHND_NVRAM_TYPE_CHAR_ARRAY	= 24,
	BHND_NVRAM_TYPE_STRING_ARRAY	= 25,
	BHND_NVRAM_TYPE_BOOL_ARRAY	= 26
} bhnd_nvram_type;
```

### Port/Region Functions

*int*\

**bhnd\_decode\_port\_rid**(*device\_t dev*, *int type*, *int rid*, *bhnd\_port\_type \*port\_type*, *u\_int \*port*, *u\_int \*region*);

*u\_int*\

**bhnd\_get\_port\_count**(*device\_t dev*, *bhnd\_port\_type type*);

*int*\

**bhnd\_get\_port\_rid**(*device\_t dev*, *bhnd\_port\_type type*, *u\_int port*, *u\_int region*);

*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*);

*u\_int*\

**bhnd\_get\_region\_count**(*device\_t dev*, *bhnd\_port\_type type*, *u\_int port*);

*bool*\

**bhnd\_is\_region\_valid**(*device\_t dev*, *bhnd\_port\_type type*, *u\_int port*, *u\_int region*);

```
typedef enum {
	BHND_PORT_DEVICE	= 0,
	BHND_PORT_BRIDGE	= 1,
	BHND_PORT_AGENT		= 2
} bhnd_port_type;
```

### Power Management Functions

*int*\

**bhnd\_alloc\_pmu**(*device\_t dev*);

*int*\

**bhnd\_release\_pmu**(*device\_t dev*);

*int*\

**bhnd\_enable\_clocks**(*device\_t dev*, *uint32\_t clocks*);

*int*\

**bhnd\_request\_clock**(*device\_t dev*, *bhnd\_clock clock*);

*int*\

**bhnd\_get\_clock\_freq**(*device\_t dev*, *bhnd\_clock clock*, *u\_int \*freq*);

*int*\

**bhnd\_get\_clock\_latency**(*device\_t dev*, *bhnd\_clock clock*, *u\_int \*latency*);

*int*\

**bhnd\_request\_ext\_rsrc**(*device\_t dev*, *u\_int rsrc*);

*int*\

**bhnd\_release\_ext\_rsrc**(*device\_t dev*, *u\_int rsrc*);

```
typedef enum {
	BHND_CLOCK_DYN	= (1 << 0),
	BHND_CLOCK_ILP	= (1 << 1),
	BHND_CLOCK_ALP	= (1 << 2),
	BHND_CLOCK_HT	= (1 << 3)
} bhnd_clock;
```

### Service Provider Functions

*int*\

**bhnd\_register\_provider**(*device\_t dev*, *bhnd\_service\_t service*);

*int*\

**bhnd\_deregister\_provider**(*device\_t dev*, *bhnd\_service\_t service*);

*device\_t*\

**bhnd\_retain\_provider**(*device\_t dev*, *bhnd\_service\_t service*);

*void*\

**bhnd\_release\_provider**(*device\_t dev*, *device\_t provider*, *bhnd\_service\_t service*);

```
typedef enum {
	BHND_SERVICE_CHIPC,
	BHND_SERVICE_PWRCTL,
	BHND_SERVICE_PMU,
	BHND_SERVICE_NVRAM,
	BHND_SERVICE_GPIO,
	BHND_SERVICE_ANY	= 1000
} bhnd_service_t;
```

### Utility Functions

*bhnd\_erom\_class\_t \**\

**bhnd\_driver\_get\_erom\_class**(*driver\_t \*driver*);

*bhnd\_devclass\_t*\

**bhnd\_find\_core\_class**(*uint16\_t vendor*, *uint16\_t device*);

*const char \**\

**bhnd\_find\_core\_name**(*uint16\_t vendor*, *uint16\_t device*);

*bhnd\_devclass\_t*\

**bhnd\_core\_class**(*const struct bhnd\_core\_info \*ci*);

*const char \**\

**bhnd\_core\_name**(*const struct bhnd\_core\_info \*ci*);

*int*\

**bhnd\_format\_chip\_id**(*char \*buffer*, *size\_t size*, *uint16\_t chip\_id*);

*void*\

**bhnd\_set\_custom\_core\_desc**(*device\_t dev*, *const char \*dev\_name*);

*void*\

**bhnd\_set\_default\_core\_desc**(*device\_t dev*);

*const char \**\

**bhnd\_vendor\_name**(*uint16\_t vendor*);

```
#define	BHND_CHIPID_MAX_NAMELEN	32
```

## DESCRIPTION

**bhnd** provides a unified bus and driver programming interface for the on-chip interconnects and IP cores found in Broadcom Home Networking Division (BHND) devices.

The BHND device family consists of MIPS/ARM SoCs (System On a Chip) and host-connected chipsets based on a common library of Broadcom IP cores, connected via one of two on-chip backplane (hardware bus) architectures.

Hardware designed prior to 2009 used Broadcom's “SSB” backplane architecture, based on Sonics Silicon's interconnect IP. Each core on the Sonics backplane vends a 4 KiB register block, containing both device-specific CSRs, and SSB-specific per-core device management (enable/reset/etc) registers.

Subsequent hardware is based on Broadcom's “BCMA” backplane, based on ARM's AMBA IP. The IP cores used in earlier SSB-based devices were adapted for compatibility with the new backplane, with additional “wrapper” cores providing per-core device management functions in place of the SSB per-core management registers.

When BHND hardware is used as a host-connected peripheral (e.g., in a PCI Wi-Fi card), the on-chip peripheral controller core is configured to operate as an endpoint device, bridging access to the SoC hardware:

- Host access to SoC address space is provided via a set of register windows (e.g., a set of configurable windows into SoC address space mapped via PCI BARs)

- DMA is supported by the bridge core's sparse mapping of host address space into the backplane address space. These address regions may be used as a target for the on-chip DMA engine.

- Any backplane interrupt vectors routed to the bridge core may be mapped by the bridge to host interrupts (e.g., PCI INTx/MSI/MSI-X).

The **bhnd** driver programming interface — and [bhndb(4)](/bhndb/4.md) host bridge drivers — support the implementation of common drivers for Broadcom IP cores, whether attached via a BHND host bridge, or via the native SoC backplane.

### Bus Resource Functions

The bhnd\_resource functions are wrappers for the standard *struct resource* bus APIs, providing support for *SYS\_RES\_MEMORY* resources that, on [bhndb(4)](/bhndb/4.md) bridged chipsets, may require on-demand remapping of address windows prior to accessing bus memory.

These functions are primarily used in the implementation of BHND platform device drivers that, on host-connected peripherals, must share a small set of register windows during initial setup and teardown.

BHND peripherals are designed to not require register window remapping during normal operation, and most drivers may safely use the standard *struct* *resource* APIs directly.

The **bhnd\_activate\_resource**() function activates a previously allocated resource.

The arguments are as follows:

- *dev*

  The device holding ownership of the allocated resource.

- *type*

  The type of the resource.

- *rid*

  The bus-specific handle that identifies the resource being activated.

- *r*

  A pointer to the resource returned by **bhnd\_alloc\_resource**().

The **bhnd\_alloc\_resource**() function allocates a resource from a device's parent [bhnd(4)](/bhnd/4.md) bus.

The arguments are as follows:

- *dev*

  The device requesting resource ownership.

- *type*

  The type of resource to allocate. This may be any type supported by the standard [bus\_alloc\_resource(9)](/bus_alloc_resource/9.md) function.

- *rid*

  The bus-specific handle identifying the resource being allocated.

- *start*

  The start address of the resource.

- *end*

  The end address of the resource.

- *count*

  The size of the resource.

- *flags*

  The flags for the resource to be allocated. These may be any values supported by the standard [bus\_alloc\_resource(9)](/bus_alloc_resource/9.md) function.

To request that the bus supply the resource's default *start*, *end*, and *count* values, pass *start* and *end* values of 0ul and ~0ul respectively, and a *count* of 1.

The **bhnd\_alloc\_resource\_any**() function is a convenience wrapper for **bhnd\_alloc\_resource**(), using the resource's default *start*, *end*, and *count* values.

The arguments are as follows:

- *dev*

  The device requesting resource ownership.

- *type*

  The type of resource to allocate. This may be any type supported by the standard [bus\_alloc\_resource(9)](/bus_alloc_resource/9.md) function.

- *rid*

  The bus-specific handle identifying the resource being allocated.

- *flags*

  The flags for the resource to be allocated. These may be any values supported by the standard [bus\_alloc\_resource(9)](/bus_alloc_resource/9.md) function.

The **bhnd\_alloc\_resources**() function allocates resources defined in resource specification from a device's parent [bhnd(4)](/bhnd/4.md) bus.

The arguments are as follows:

- *dev*

  The device requesting ownership of the resources.

- *rs*

  A standard bus resource specification. If all requested resources, are successfully allocated, this will be updated with the allocated resource identifiers.

- *res*

  If all requested resources are successfully allocated, this will be populated with the allocated *struct bhnd\_resource* instances.

The **bhnd\_deactivate\_resource**() function deactivates a resource previously activated by. **bhnd\_activate\_resource**(). The arguments are as follows:

- *dev*

  The device holding ownership of the activated resource.

- *type*

  The type of the resource.

- *rid*

  The bus-specific handle identifying the resource.

- *r*

  A pointer to the resource returned by bhnd\_alloc\_resource.

The **bhnd\_release\_resource**() function frees a resource previously returned by **bhnd\_alloc\_resource**(). The arguments are as follows:

- *dev*

  The device holding ownership of the resource.

- *type*

  The type of the resource.

- *rid*

  The bus-specific handle identifying the resource.

- *r*

  A pointer to the resource returned by bhnd\_alloc\_resource.

The **bhnd\_release\_resources**() function frees resources previously returned by **bhnd\_alloc\_resources**(). The arguments are as follows:

- *dev*

  The device that owns the resources.

- *rs*

  A standard bus resource specification previously initialized by **bhnd\_alloc\_resources**().

- *res*

  The resources to be released.

The *bhnd\_resource* structure contains the following fields:

- *res*

  A pointer to the bus *struct* *resource*.

- *direct*

  If true, the resource requires bus window remapping before it is MMIO accessible.

### Bus Space Functions

The bhnd\_bus\_space functions wrap their equivalent [bus\_space(9)](/bus_space/9.md) counterparts, and provide support for accessing bus memory via *struct bhnd\_resource*.

- **bhnd\_bus\_barrier**()

  - **bhnd\_bus\_\[read\|write\]\_\[1\|2\|4\]**()

  - **bhnd\_bus\_\[read\_multi\|write\_multi\]\_\[1\|2\|4\]**()

  - **bhnd\_bus\_\[read\_multi\_stream\|write\_multi\_stream\]\_\[1\|2\|4\]**()

  - **bhnd\_bus\_\[read\_region\|write\_region\]\_\[1\|2\|4\]**()

  - **bhnd\_bus\_\[read\_region\_stream\|write\_region\_stream\]\_\[1\|2\|4\]**()

  - **bhnd\_bus\_\[read\_stream\|write\_stream\]\_\[1\|2\|4\]**()

  - **bhnd\_bus\_\[set\_multi\|set\_stream\]\_\[1\|2\|4\]**()

  Drivers that do not rely on *struct bhnd\_resource* should use the standard *struct* *resource* and [bus\_space(9)](/bus_space/9.md) APIs directly.

### Device Configuration Functions

The **bhnd\_read\_ioctl**() function is used to read the I/O control register value of device *dev*, returning the current value in *ioctl*.

The **bhnd\_write\_ioctl**() function is used to modify the I/O control register of *dev*. The new value of the register is computed by updating any bits set in *mask* to *value*. The following I/O control flags are supported:

- BHND\_IOCTL\_BIST

  Initiate a built-in self-test (BIST). Must be cleared after BIST results are read via the IOST (I/O Status) register.

- BHND\_IOCTL\_PME

  Enable posting of power management events by the core.

- BHND\_IOCTL\_CLK\_FORCE

  Force disable of clock gating, resulting in all clocks being distributed within the core. Should be set when asserting/deasserting reset to ensure the reset signal fully propagates to the entire core.

- BHND\_IOCTL\_CLK\_EN

  If cleared, the core clock will be disabled. Should be set during normal operation, and cleared when the core is held in reset.

- BHND\_IOCTL\_CFLAGS

  The mask of IOCTL bits reserved for additional core-specific I/O control flags.

The **bhnd\_read\_iost**() function is used to read the I/O status register of device *dev*, returning the current value in *iost*. The following I/O status flags are supported:

- BHND\_IOST\_BIST\_DONE

  Set upon BIST completion. Will be cleared when the BHND\_IOCTL\_BIST flag of the I/O control register is cleared using **bhnd\_write\_ioctl**().

- BHND\_IOST\_BIST\_FAIL

  Set upon detection of a BIST error; the value is unspecified if BIST has not completed and BHND\_IOST\_BIST\_DONE is not also set.

- BHND\_IOST\_CLK

  Set if the core has required that clocked be ungated, or cleared otherwise. The value is undefined if a core does not support clock gating.

- BHND\_IOST\_DMA64

  Set if this core supports 64-bit DMA.

- BHND\_IOST\_CFLAGS

  The mask of IOST bits reserved for additional core-specific I/O status flags.

The **bhnd\_read\_config**() function is used to read a data item of *width* bytes at *offset* from the backplane-specific agent/config space of the device *dev*.

The **bhnd\_write\_config**() function is used to write a data item of *width* bytes with *value* at *offset* from the backplane-specific agent/config space of the device *dev*. The requested *width* must be one of 1, 2, or 4 bytes.

The agent/config space accessible via **bhnd\_read\_config**() and **bhnd\_write\_config**() is backplane-specific, and these functions should only be used for functionality that is not available via another **bhnd** function.

The **bhnd\_suspend\_hw**() function transitions the device *dev* to a low power “RESET” state, writing *ioctl* to the I/O control flags of *dev*. The hardware may be brought out of this state using **bhnd\_reset\_hw**().

The **bhnd\_reset\_hw**() function first transitions the device *dev* to a low power RESET state, writing *ioctl\_reset* to the I/O control flags of *dev*, and then brings the device out of RESET, writing *ioctl* to the device's I/O control flags.

The **bhnd\_is\_hw\_suspended**() function returns true if the device *dev* is currently held in a RESET state, or is otherwise not clocked. Otherwise, it returns false.

Any outstanding per-device PMU requests made using **bhnd\_enable\_clocks**(), **bhnd\_request\_clock**(), or **bhnd\_request\_ext\_rsrc**() will be released automatically upon placing a device into a RESET state.

### Device Information Functions

The **bhnd\_get\_attach\_type**() function returns the attachment type of the parent [bhnd(4)](/bhnd/4.md) bus of device *dev*.

The following attachment types are supported:

- BHND\_ATTACH\_ADAPTER

  The bus is resident on a bridged adapter, such as a PCI Wi-Fi device.

- BHND\_ATTACH\_NATIVE

  The bus is resident on the native host, such as the primary or secondary bus of an embedded SoC.

The **bhnd\_get\_chipid**() function returns chip information from the parent [bhnd(4)](/bhnd/4.md) bus of device *dev*. The returned *bhnd\_chipid* struct contains the following fields:

- *chip\_id*

  The chip identifier.

- *chip\_rev*

  The chip's hardware revision.

- *chip\_pkg*

  The chip's semiconductor package identifier.

  Several different physical semiconductor package variants may exist for a given chip, each of which may require driver workarounds for hardware errata, unpopulated components, etc.

- *chip\_type*

  The interconnect architecture used by this chip.

- *chip\_caps*

  The **bhnd** capability flags supported by this chip.

- *enum\_addr*

  The backplane enumeration address. On SSB devices, this will be the base address of the first SSB core. On BCMA devices, this will be the address of the enumeration ROM (EROM) core.

- *ncores*

  The number of cores on the chip backplane, or 0 if unknown.

The following constants are defined for known *chip\_type* values:

- BHND\_CHIPTYPE\_SIBA

  SSB interconnect.

- BHND\_CHIPTYPE\_BCMA

  BCMA interconnect.

- BHND\_CHIPTYPE\_BCMA\_ALT

  BCMA-compatible variant found in Broadcom Northstar ARM SoCs.

- BHND\_CHIPTYPE\_UBUS

  UBUS interconnect. This BCMA-derived interconnect is found in Broadcom BCM33xx DOCSIS SoCs, and BCM63xx xDSL SoCs. UBUS is not currently supported by [bhnd(4)](/bhnd/4.md).

The following *chip\_caps* flags are supported:

- BHND\_CAP\_BP64

  The backplane supports 64-bit addressing.

- BHND\_CAP\_PMU

  PMU is present.

Additional symbolic constants for known *chip\_id*, *chip\_pkg*, and *chip\_type* values are defined in ⟨dev/bhnd/bhnd\_ids.h⟩.

The **bhnd\_get\_class**() function returns the BHND class of device *dev*, if the device's *vendor* and *device* identifiers are recognized. Otherwise, returns BHND\_DEVCLASS\_OTHER.

One of the following device classes will be returned:

- BHND\_DEVCLASS\_CC

  ChipCommon I/O Controller

- BHND\_DEVCLASS\_CC\_B

  ChipCommon Auxiliary Controller

- BHND\_DEVCLASS\_PMU

  PMU Controller

- BHND\_DEVCLASS\_PCI

  PCI Host/Device Bridge

- BHND\_DEVCLASS\_PCIE

  PCIe Host/Device Bridge

- BHND\_DEVCLASS\_PCCARD

  PCMCIA Host/Device Bridge

- BHND\_DEVCLASS\_RAM

  Internal RAM/SRAM

- BHND\_DEVCLASS\_MEMC

  Memory Controller

- BHND\_DEVCLASS\_ENET

  IEEE 802.3 MAC/PHY

- BHND\_DEVCLASS\_ENET\_MAC

  IEEE 802.3 MAC

- BHND\_DEVCLASS\_ENET\_PHY

  IEEE 802.3 PHY

- BHND\_DEVCLASS\_WLAN

  IEEE 802.11 MAC/PHY/Radio

- BHND\_DEVCLASS\_WLAN\_MAC

  IEEE 802.11 MAC

- BHND\_DEVCLASS\_WLAN\_PHY

  IEEE 802.11 PHY

- BHND\_DEVCLASS\_CPU

  CPU Core

- BHND\_DEVCLASS\_SOC\_ROUTER

  Interconnect Router

- BHND\_DEVCLASS\_SOC\_BRIDGE

  Interconnect Host Bridge

- BHND\_DEVCLASS\_EROM

  Device Enumeration ROM

- BHND\_DEVCLASS\_NVRAM

  NVRAM/Flash Controller

- BHND\_DEVCLASS\_SOFTMODEM

  Analog/PSTN SoftModem Codec

- BHND\_DEVCLASS\_USB\_HOST

  USB Host Controller

- BHND\_DEVCLASS\_USB\_DEV

  USB Device Controller

- BHND\_DEVCLASS\_USB\_DUAL

  USB Host/Device Controller

- BHND\_DEVCLASS\_OTHER

  Other / Unknown

- BHND\_DEVCLASS\_INVALID

  Invalid Class

The **bhnd\_get\_core\_info**() function returns the core information for device *dev*. The returned *bhnd\_core\_info* structure contains the following fields:

- *vendor*

  Vendor identifier (JEP-106, ARM 4-bit continuation encoded)

- *device*

  Device identifier

- *hwrev*

  Hardware revision

- *core\_idx*

  Core index

- *unit*

  Core unit

Symbolic constants for common vendor and device identifiers are defined in ⟨dev/bhnd/bhnd\_ids.h⟩. Common vendor identifiers include:

- BHND\_MFGID\_ARM

  ARM

- BHND\_MFGID\_BCM

  Broadcom

- BHND\_MFGID\_MIPS

  MIPS

The **bhnd\_get\_core\_index**(), **bhnd\_get\_core\_unit**(), **bhnd\_get\_device**(), **bhnd\_get\_hwrev**(), and **bhnd\_get\_vendor**() functions are convenience wrappers for **bhnd\_get\_core\_info**(), returning, respect the *core\_idx*, *core\_unit*, *device*, *hwrev*, or *vendor* field from the *bhnd\_core\_info* structure.

The **bhnd\_get\_device\_name**() function returns a human readable name for device *dev*.

The **bhnd\_get\_vendor\_name**() function returns a human readable name for the vendor of device *dev*.

The **bhnd\_read\_board\_info**() function attempts to read the board information for device *dev*. The board information will be returned in the location pointed to by *info* on success.

The *bhnd\_board\_info* structure contains the following fields:

- *board\_vendor*

  Vendor ID of the board manufacturer (PCI-SIG assigned).

- *board\_type*

  Board ID.

- *board\_devid*

  Device ID.

- *board\_rev*

  Board revision.

- *board\_srom\_rev*

  Board SROM format revision.

- *board\_flags*

  Board flags (1)

- *board\_flags2*

  Board flags (2)

- *board\_flags3*

  Board flags (3)

The *board\_devid* field is the Broadcom PCI device ID that most closely matches the capabilities of the BHND device (if any).

On PCI devices, the *board\_vendor*, *board\_type*, and *board\_devid* fields default to the PCI Subsystem Vendor ID, PCI Subsystem ID, and PCI device ID, unless overridden in device NVRAM.

On other devices, including SoCs, the *board\_vendor*, *board\_type*, and *board\_devid* fields will be populated from device NVRAM.

Symbolic constants for common board flags are defined in ⟨dev/bhnd/bhnd\_ids.h⟩.

### Device Matching Functions

The bhnd device matching functions are used to match against core, chip, and board-level device attributes. Match requirements are specified using the *struct bhnd\_board\_match*, *struct bhnd\_chip\_match*, *struct bhnd\_core\_match*, *struct bhnd\_device\_match*, and *struct bhnd\_hwrev\_match* match descriptor structures.

The **bhnd\_board\_matches**() function returns true if *board* matches the board match descriptor *desc*. Otherwise, it returns false.

The **bhnd\_chip\_matches**() function returns true if *chip* matches the chip match descriptor *desc*. Otherwise, it returns false.

The **bhnd\_core\_matches**() function returns true if *core* matches the core match descriptor *desc*. Otherwise, it returns false.

The **bhnd\_device\_matches**() function returns true if the device *dev* matches the device match descriptor *desc*. Otherwise, it returns false.

The **bhnd\_hwrev\_matches**() function returns true if *hwrev* matches the hwrev match descriptor *desc*. Otherwise, it returns false.

The **bhnd\_bus\_match\_child**() function returns the first child device of *bus* that matches the device match descriptor *desc*. If no matching child is found, NULL is returned.

The **bhnd\_core\_get\_match\_desc**() function returns an equality match descriptor for the core info in *core*. The returned descriptor will match only on core attributes identical to those defined by *core*.

The **bhnd\_cores\_equal**() function is a convenience wrapper for **bhnd\_core\_matches**() and **bhnd\_core\_get\_match\_desc**(). This function returns true if the *bhnd\_core\_info* structures *lhs* and *rhs* are equal. Otherwise, it returns false.

The **bhnd\_match\_core**() function returns a pointer to the first entry in the array *cores* of length *num\_cores* that matches *desc*. If no matching core is found, NULL is returned.

A *bhnd\_board\_match* match descriptor may be initialized using one or more of the following macros:

- **BHND\_MATCH\_BOARD\_VENDOR**(*vendor*)

  Match on boards with a vendor equal to *vendor*.

- **BHND\_MATCH\_BOARD\_TYPE**(*type*)

  Match on boards with a type equal to BHND\_BOARD\_ ## *type*

- **BHND\_MATCH\_SROMREV**(*sromrev*)

  Match on boards with a sromrev that matches BHND\_HWREV\_ ## *sromrev*.

- **BHND\_MATCH\_BOARD\_REV**(*hwrev*)

  Match on boards with hardware revisions that match BHND\_ ## *hwrev*.

- **BHND\_MATCH\_BOARD**(*vendor*, *type*)

  A convenience wrapper for **BHND\_MATCH\_BOARD\_VENDOR**() and **BHND\_MATCH\_BOARD\_TYPE**().

For example:

```
struct bhnd_board_match board_desc = {
	BHND_MATCH_BOARD_VENDOR(BHND_MFGID_BROADCOM),
	BHND_MATCH_BOARD_TYPE(BCM94360X52C),
	BHND_MATCH_BOARD_REV(HWREV_ANY),
	BHND_MATCH_SROMREV(RANGE(0, 10))
};
```

A *bhnd\_chip\_match* match descriptor may be initialized using one or more of the following macros:

- **BHND\_MATCH\_CHIP\_ID**(*id*)

  Match on chips with an ID equal to BHND\_CHIPID\_ ## *id*

- **BHND\_MATCH\_CHIP\_REV**(*hwrev*)

  Match on chips with hardware revisions that match BHND\_ ## *hwrev*.

- **BHND\_MATCH\_CHIP\_PKG**(*pkg*)

  Match on chips with a package ID equal to BHND\_PKGID\_ ## *pkg*

- **BHND\_MATCH\_CHIP\_TYPE**(*type*)

  Match on chips with a chip type equal to BHND\_CHIPTYPE\_ ## *type*

- **BHND\_MATCH\_CHIP\_IP**(*id*, *pkg*)

  A convenience wrapper for **BHND\_MATCH\_CHIP\_ID**() and **BHND\_MATCH\_CHIP\_PKG**().

- **BHND\_MATCH\_CHIP\_IPR**(*id*, *pkg*, *hwrev*)

  A convenience wrapper for **BHND\_MATCH\_CHIP\_ID**(), **BHND\_MATCH\_CHIP\_PKG**(), and **BHND\_MATCH\_CHIP\_REV**().

- **BHND\_MATCH\_CHIP\_IR**(*id*, *hwrev*)

  A convenience wrapper for **BHND\_MATCH\_CHIP\_ID**() and **BHND\_MATCH\_CHIP\_REV**().

For example:

```
struct bhnd_chip_match chip_desc = {
	BHND_MATCH_CHIP_IP(BCM4329, BCM4329_289PIN),
	BHND_MATCH_CHIP_TYPE(SIBA)
};
```

A *bhnd\_core\_match* match descriptor may be initialized using one or more of the following macros:

- **BHND\_MATCH\_CORE\_VENDOR**(*vendor*)

  Match on cores with a vendor ID equal to *vendor*

- **BHND\_MATCH\_CORE\_ID**(*id*)

  Match on cores with a device ID equal to *id*

- **BHND\_MATCH\_CORE\_REV**(*hwrev*)

  Match on cores with hardware revisions that match BHND\_ ## *hwrev*.

- **BHND\_MATCH\_CORE\_CLASS**(*class*)

  Match on cores with a core device class equal to *class*

- **BHND\_MATCH\_CORE\_IDX**(*idx*)

  Match on cores with a core index equal to *idx*

- **BHND\_MATCH\_CORE\_UNIT**(*unit*)

  Match on cores with a core unit equal to *unit*

- **BHND\_MATCH\_CORE**(*vendor*, *id*)

  A convenience wrapper for **BHND\_MATCH\_CORE\_VENDOR**() and **BHND\_MATCH\_CORE\_ID**().

For example:

```
struct bhnd_core_match core_desc = {
	BHND_MATCH_CORE(BHND_MFGID_BROADCOM, BHND_COREID_CC),
	BHND_MATCH_CORE_REV(HWREV_RANGE(0, 10))
};
```

The *bhnd\_device\_match* match descriptor supports matching on all board, chip, and core attributes, and may be initialized using any of the *bhnd\_board\_match*, *bhnd\_chip\_match*, or *bhnd\_core\_match* macros.

For example:

```
struct bhnd_device_match device_desc = {
	BHND_MATCH_CHIP_IP(BCM4329, BCM4329_289PIN),
	BHND_MATCH_BOARD_VENDOR(BHND_MFGID_BROADCOM),
	BHND_MATCH_BOARD_TYPE(BCM94329AGB),
	BHND_MATCH_CORE(BHND_MFGID_BROADCOM, BHND_COREID_CC),
};
```

A *bhnd\_hwrev\_match* match descriptor may be initialized using one of the following macros:

- BHND\_HWREV\_ANY

  Matches any hardware revision.

- **BHND\_HWREV\_EQ**(*hwrev*)

  Matches any hardware revision equal to *hwrev*

- **BHND\_HWREV\_GTE**(*hwrev*)

  Matches any hardware revision greater than or equal to *hwrev*

- **BHND\_HWREV\_LTE**(*hwrev*)

  Matches any hardware revision less than or equal to *hwrev*

- **BHND\_HWREV\_RANGE**(*start*, *end*)

  Matches any hardware revision within an inclusive range. If BHND\_HWREV\_INVALID is specified as the *end* value, will match on any revision equal to or greater than *start*

### Device Table Functions

The bhnd device table functions are used to query device and quirk tables.

The **bhnd\_device\_lookup**() function returns a pointer to the first entry in device table *table* that matches the device *dev*. The table entry size is specified by *entry\_size*.

The **bhnd\_device\_quirks**() function scan the device table *table* for all quirk entries that match the device *dev*, returning the bitwise OR of all matching quirk flags. The table entry size is specified by *entry\_size*.

The *bhnd\_device* structure contains the following fields:

- *core*

  A *bhnd\_device\_match* descriptor.

- *desc*

  A verbose device description suitable for use with [device\_set\_desc(9)](/device_set_desc/9.md), or NULL.

- *quirks\_table*

  The quirks table for this device, or NULL.

- *device\_flags*

  The device flags required when matching this entry.

The following device flags are supported:

- BHND\_DF\_ANY

  Match on any device.

- BHND\_DF\_HOSTB

  Match only if the device is the [bhndb(4)](/bhndb/4.md) host bridge. Implies BHND\_DF\_ADAPTER.

- BHND\_DF\_SOC

  Match only if the device is attached to a native SoC backplane.

- BHND\_DF\_ADAPTER

  Match only if the device is attached to a [bhndb(4)](/bhndb/4.md) bridged backplane.

A *bhnd\_device* table entry may be initialized using one of the following macros:

- **BHND\_DEVICE**(*vendor*, *device*, *desc*, *quirks*, *flags*)

  Match on devices with a vendor ID equal to BHND\_MFGID\_ ## *vendor* and a core device ID equal to BHND\_COREID\_ ## *device*.

  The device's verbose description is specified by the *desc* argument, a pointer to the device-specific quirks table is specified by the *quirks* argument, and any required device flags may be provided in *flags*. The optional *flags* argument defaults to BHND\_DF\_ANY if omitted.

- BHND\_DEVICE\_END

  Terminate the *bhnd\_device* table.

For example:

```
struct bhnd_device bhnd_usb11_devices[] = {
	BHND_DEVICE(BCM, USB, "Broadcom USB1.1 Controller",
	    bhnd_usb11_quirks),
	BHND_DEVICE_END
};
```

The *bhnd\_device\_quirk* structure contains the following fields:

- *desc*

  A *bhnd\_device\_match* descriptor.

- *quirks*

  Applicable quirk flags.

A bhnd\_device\_quirk table entry may be initialized using one of the following convenience macros:

- **BHND\_BOARD\_QUIRK**(*board*, *flags*)

  Set quirk flags *flags* on devices with a board type equal to BHND\_BOARD\_ ## *board*.

- **BHND\_CHIP\_QUIRK**(*chip*, *hwrev*, *flags*)

  Set quirk flags *flags* on devices with a chip ID equal to BHND\_CHIPID\_BCM ## *chip* and chip hardware revision that matches BHND\_ ## *hwrev*.

- **BHND\_PKG\_QUIRK**(*chip*, *pkg*, *flags"*)

  Set quirk flags *flags* on devices with a chip ID equal to BHND\_CHIPID\_BCM ## *chip* and chip package equal to BHND\_ ## chip ## *pkg*.

- **BHND\_CORE\_QUIRK**(*hwrev*, *flags"*)

  Set quirk flags *flags* on devices with a core hardware revision that matches BHND\_ ## *hwrev*.

For example:

```
struct bhnd_device_quirk bhnd_usb11_quirks[] = {
	BHND_DEVICE(BCM, USB, "Broadcom USB1.1 Controller",
	    bhnd_usb11_quirks),
	BHND_DEVICE_END
};
```

### DMA Address Translation Functions

The **bhnd\_get\_dma\_translation**() function is used to request a DMA address translation descriptor suitable for use with a maximum DMA address width of *width*, with support for the requested translation *flags*.

If a suitable DMA address translation descriptor is found, it will be stored in *translation*, and a bus DMA tag specifying the DMA translation's address restrictions will be stored in *dmat*. The *translation* and *dmat* arguments may be NULL if the translation descriptor or DMA tag are not desired.

The following DMA translation flags are supported:

- BHND\_DMA\_TRANSLATION\_PHYSMAP

  The translation remaps the device's physical address space.

  This is used in conjunction with BHND\_DMA\_TRANSLATION\_BYTESWAPPED to define a DMA translation that provides byteswapped access to physical memory on big-endian MIPS SoCs.

- BHND\_DMA\_TRANSLATION\_BYTESWAPPED

  The translation provides a byte-swapped mapping; write requests will be byte-swapped before being written to memory, and read requests will be byte-swapped before being returned.

  This is primarily used to perform efficient byte swapping of DMA data on embedded MIPS SoCs executing in big-endian mode.

The following symbolic constants are defined for common DMA address widths:

- BHND\_DMA\_ADDR\_30BIT

  30-bit DMA

- BHND\_DMA\_ADDR\_32BIT

  32-bit DMA

- BHND\_DMA\_ADDR\_64BIT

  64-bit DMA

The *bhnd\_dma\_translation* structure contains the following fields:

- *base\_addr*

  Host-to-device physical address translation. This may be added to a host physical address to produce a device DMA address.

- *addr\_mask*

  Device-addressable address mask. This defines the device DMA address range, and excludes any bits reserved for mapping the address within the translation window at *base\_addr*.

- *addrext\_mask*

  Device-addressable extended address mask. If a the per-core BHND DMA engine supports the 'addrext' control field, it can be used to provide address bits excluded by *addr\_mask*.

  Support for DMA extended address changes — including coordination with the core providing device-to-host DMA address translation — is handled transparently by the DMA engine.

  For example, on PCI Wi-Fi devices, the Wi-Fi core's DMA engine will (in effect) update the PCI host bridge core's DMA sbtopcitranslation base address to map the target address prior to performing a DMA transaction.

- *flags*

  Translation flags.

### Interrupt Functions

The **bhnd\_get\_intr\_count**() function is used to determine the number of backplane interrupt lines assigned to the device *dev*. Interrupt line identifiers are allocated in monotonically increasing order, starting with 0.

The **bhnd\_get\_intr\_ivec**() function is used to determine the backplane interrupt vector assigned to interrupt line *intr* on the device *dev*, writing the result to *ivec*. Interrupt vector assignments are backplane-specific: On BCMA devices, this function returns the OOB bus line assigned to the interrupt. On SIBA devices, it returns the target OCP slave flag number assigned to the interrupt.

The **bhnd\_map\_intr**() function is used to map interrupt line *intr* assigned to device *dev* to an IRQ number, writing the result to *irq*. Until unmapped, this IRQ may be used when allocating a resource of type SYS\_RES\_IRQ.

Ownership of the interrupt mapping is assumed by the caller, and must be explicitly released using *bhnd\_unmap\_intr*.

The **bhnd\_unmap\_intr**() function is used to unmap bus IRQ *irq* previously mapped using **bhnd\_map\_intr**() by the device *dev*.

### NVRAM Functions

The **bhnd\_nvram\_getvar**() function is used to read the value of NVRAM variable *name* from the NVRAM provider(s) registered with the parent [bhnd(4)](/bhnd/4.md) bus of device *dev*, coerced to the desired data representation *type*, written to the buffer specified by *buf*.

Before the call, the maximum capacity of *buf* is specified by *len*. After a successful call — or if ENOMEM is returned — the size of the available data will be written to *len*. The size of the desired data representation can be determined by calling **bhnd\_nvram\_getvar**() with a NULL argument for *buf*.

The following NVRAM data types are supported:

- BHND\_NVRAM\_TYPE\_UINT8

  unsigned 8-bit integer

- BHND\_NVRAM\_TYPE\_UINT16

  unsigned 16-bit integer

- BHND\_NVRAM\_TYPE\_UINT32

  unsigned 32-bit integer

- BHND\_NVRAM\_TYPE\_UINT64

  signed 64-bit integer

- BHND\_NVRAM\_TYPE\_INT8

  signed 8-bit integer

- BHND\_NVRAM\_TYPE\_INT16

  signed 16-bit integer

- BHND\_NVRAM\_TYPE\_INT32

  signed 32-bit integer

- BHND\_NVRAM\_TYPE\_INT64

  signed 64-bit integer

- BHND\_NVRAM\_TYPE\_CHAR

  UTF-8 character

- BHND\_NVRAM\_TYPE\_STRING

  UTF-8 NUL-terminated string

- BHND\_NVRAM\_TYPE\_BOOL

  uint8 boolean value

- BHND\_NVRAM\_TYPE\_NULL

  NULL (empty) value

- BHND\_NVRAM\_TYPE\_DATA

  opaque octet string

- BHND\_NVRAM\_TYPE\_UINT8\_ARRAY

  array of uint8 integers

- BHND\_NVRAM\_TYPE\_UINT16\_ARRAY

  array of uint16 integers

- BHND\_NVRAM\_TYPE\_UINT32\_ARRAY

  array of uint32 integers

- BHND\_NVRAM\_TYPE\_UINT64\_ARRAY

  array of uint64 integers

- BHND\_NVRAM\_TYPE\_INT8\_ARRAY

  array of int8 integers

- BHND\_NVRAM\_TYPE\_INT16\_ARRAY

  array of int16 integers

- BHND\_NVRAM\_TYPE\_INT32\_ARRAY

  array of int32 integers

- BHND\_NVRAM\_TYPE\_INT64\_ARRAY

  array of int64 integers

- BHND\_NVRAM\_TYPE\_CHAR\_ARRAY

  array of UTF-8 characters

- BHND\_NVRAM\_TYPE\_STRING\_ARRAY

  array of UTF-8 NUL-terminated strings

- BHND\_NVRAM\_TYPE\_BOOL\_ARRAY

  array of uint8 boolean values

The **bhnd\_nvram\_getvar\_array**(), **bhnd\_nvram\_getvar\_int**(), **bhnd\_nvram\_getvar\_int8**(), **bhnd\_nvram\_getvar\_int16**(), **bhnd\_nvram\_getvar\_int32**(), **bhnd\_nvram\_getvar\_uint**(), **bhnd\_nvram\_getvar\_uint8**(), **bhnd\_nvram\_getvar\_uint16**(), **bhnd\_nvram\_getvar\_uint32**(), and **bhnd\_nvram\_getvar\_str**() functions are convenience wrappers for **bhnd\_nvram\_getvar**().

The **bhnd\_nvram\_getvar\_array**() function returns either a value of exactly *size* in *buf*, or returns an error code of ENXIO if the data representation is not exactly *size* in length.

The **bhnd\_nvram\_getvar\_int**() and **bhnd\_nvram\_getvar\_uint**() functions return the value of NVRAM variable *name*, coerced to a signed or unsigned integer type of *width* (1, 2, or 4 bytes).

The **bhnd\_nvram\_getvar\_int8**(), **bhnd\_nvram\_getvar\_int16**(), **bhnd\_nvram\_getvar\_int32**(), **bhnd\_nvram\_getvar\_uint**(), **bhnd\_nvram\_getvar\_uint8**(), **bhnd\_nvram\_getvar\_uint16**(), and **bhnd\_nvram\_getvar\_uint32**() functions return the value of NVRAM variable *name*, coerced to a signed or unsigned 8, 16, or 32-bit integer type.

The **bhnd\_nvram\_getvar\_str**() functions return the value of NVRAM variable *name*, coerced to a NUL-terminated string.

The **bhnd\_nvram\_string\_array\_next**() function iterates over all strings in the *inp* BHND\_NVRAM\_TYPE\_STRING\_ARRAY value. The size of *inp*, including any terminating NUL character(s), is specified using the *ilen* argument. The *prev* argument should be either a string pointer previously returned by **bhnd\_nvram\_string\_array\_next**(), or NULL to begin iteration. If *prev*, *is*, *not* NULL, the *olen* argument must be a pointer to the length previously returned by **bhnd\_nvram\_string\_array\_next**(). On success, the next string element's length will be written to this pointer.

### Port/Region Functions

Per-device interconnect memory mappings are identified by a combination of *port* *type*, *port* *number*, and *region* *number*. Port and memory region identifiers are allocated in monotonically increasing order for each *port* *type*, starting with 0.

The following port types are supported:

- BHND\_PORT\_DEVICE

  Device memory. The device's control/status registers are always mapped by the first device port and region, and will be assigned a SYS\_RES\_MEMORY resource ID of 0.

- BHND\_PORT\_BRIDGE

  Bridge memory.

- BHND\_PORT\_AGENT

  Interconnect agent/wrapper.

The **bhnd\_decode\_port\_rid**() function is used to decode the resource ID *rid* assigned to device *dev*, of resource type *type*, writing the port type to *port\_type*, port number to *port*, and region number to *region*.

The **bhnd\_get\_port\_count**() function returns the number of ports of type *type* assigned to device *dev*.

The **bhnd\_get\_port\_rid**() function returns the resource ID for the SYS\_RES\_MEMORY resource mapping the *port* of *type* and *region* on device *dev*, or -1 if the port or region are invalid, or do not have an assigned resource ID.

The **bhnd\_get\_region\_addr**() function is used to determine the base address and size of the memory *region* on *port* of *type* assigned to *dev*. The region's base device address will be written to *region\_addr*, and the region size to *region\_size*.

The **bhnd\_get\_region\_count**() function returns the number of memory regions mapped to *port* of *type* on device *dev*.

The **bhnd\_is\_region\_valid**() function returns true if *region* is a valid region mapped by *port* of *type* on device *dev*.

### Power Management Functions

Drivers must ask the parent [bhnd(4)](/bhnd/4.md) bus to allocate device PMU state using **bhnd\_alloc\_pmu**() before calling any another bhnd PMU functions.

The **bhnd\_alloc\_pmu**() function is used to allocate per-device PMU state and enable PMU request handling for device *dev*. The memory region containing the device's PMU register block must be allocated using [bus\_alloc\_resource(9)](/bus_alloc_resource/9.md) or **bhnd\_alloc\_resource**() before calling **bhnd\_alloc\_pmu**(), and must not be released until after calling **bhnd\_release\_pmu**().

On all supported BHND hardware, the PMU register block is mapped by the device's control/status registers in the first device port and region.

The **bhnd\_release\_pmu**() function releases the per-device PMU state previously allocated for device *dev* using **bhnd\_alloc\_pmu**(). Any outstanding clock and external resource requests will be discarded upon release of the device PMU state.

The **bhnd\_enable\_clocks**() function is used to request that *clocks* be powered up and routed to the backplane on behalf of device *dev*. This will power any clock sources required (e.g., XTAL, PLL, etc) and wait until the requested clocks are stable. If the request succeeds, any previous clock requests issued by *dev* will be discarded.

The following clocks are supported, and may be combined using bitwise OR to request multiple clocks:

- BHND\_CLOCK\_DYN

  Dynamically select an appropriate clock source based on all outstanding clock requests by any device attached to the parent [bhnd(4)](/bhnd/4.md) bus.

- BHND\_CLOCK\_ILP

  Idle Low-Power (ILP) Clock. May be used if no register access is required, or long request latency is acceptable.

- BHND\_CLOCK\_ALP

  Active Low-Power (ALP) Clock. Supports low-latency register access and low-rate DMA.

- BHND\_CLOCK\_HT

  High Throughput (HT) Clock. Supports high bus throughput and lowest-latency register access.

The **bhnd\_request\_clock**() function is used to request that *clock* (or faster) be powered up and routed to device *dev*.

The **bhnd\_get\_clock\_freq**() function is used to request the current clock frequency of *clock*, writing the frequency in Hz to *freq*.

The **bhnd\_get\_clock\_latency**() function is used to determine the transition latency required for *clock*, writing the latency in microseconds to *latency*. The BHND\_CLOCK\_HT latency value is suitable for use as the D11 Wi-Fi core *fastpwrup\_dly* value.

The **bhnd\_request\_ext\_rsrc**() function is used to request that the external PMU-managed resource assigned to device *dev*, identified by device-specific identifier *rsrc*, be powered up.

The **bhnd\_release\_ext\_rsrc**() function releases any outstanding requests by device *dev* for the PMU-managed resource identified by device-specific identifier *rsrc*. If an external resource is shared by multiple devices, it will not be powered down until all device requests are released.

### Service Provider Functions

The **bhnd\_register\_provider**() function is used to register device *dev* as a provider for platform *service* with the parent [bhnd(4)](/bhnd/4.md) bus.

The following service types are supported:

- BHND\_SERVICE\_CHIPC

  ChipCommon service. The providing device must implement the bhnd\_chipc interface.

- BHND\_SERVICE\_PWRCTL

  Legacy PWRCTL service. The providing device must implement the bhnd\_pwrctl interface.

- BHND\_SERVICE\_PMU

  PMU service. The providing device must implement the bhnd\_pmu interface.

- BHND\_SERVICE\_NVRAM

  NVRAM service. The providing device must implement the bhnd\_nvram interface.

- BHND\_SERVICE\_GPIO

  GPIO service. The providing device must implement the standard [gpio(4)](/gpio/4.md) interface.

- BHND\_SERVICE\_ANY

  Matches on any service type. May be used with **bhnd\_deregister\_provider**() to remove all service provider registrations for a device.

The **bhnd\_deregister\_provider**() function attempts to remove provider registration for the device *dev* and *service*. If a *service* argument of BHND\_SERVICE\_ANY is specified, this function will attempt to remove *all* *service* *provider* *registrations* *for* *dev*.

The **bhnd\_retain\_provider**() function retains and returns a reference to the provider registered for *service* with the parent [bhnd(4)](/bhnd/4.md) bus of device *dev*, if available. On success, the caller is responsible for releasing this provider reference using **bhnd\_release\_provider**(). The service provider is guaranteed to remain available until the provider reference is released.

The **bhnd\_release\_provider**() function releases a reference to a *provider* for *service*, previously retained by device *dev* using **bhnd\_retain\_provider**().

### Utility Functions

The **bhnd\_driver\_get\_erom\_class**() function returns the [bhnd\_erom(9)](/bhnd_erom/9.md) class for the device enumeration table format used by [bhnd(4)](/bhnd/4.md) bus driver instance *driver*. If the driver does not support [bhnd\_erom(9)](/bhnd_erom/9.md) device enumeration, NULL is returned.

The **bhnd\_find\_core\_class**() function looks up the BHND class, if known, for the BHND vendor ID *vendor* and device ID *device*.

The **bhnd\_find\_core\_name**() function is used to fetch the human-readable name, if known, for the BHND core with a vendor ID of *vendor* and device ID of *device*.

The **bhnd\_core\_class**() and **bhnd\_core\_name**() functions are convenience wrappers for **bhnd\_find\_core\_class**() and **bhnd\_find\_core\_name**(), that use the *vendor* and *device* fields of the core info structure *ci*.

The **bhnd\_format\_chip\_id**() function writes a NUL-terminated human-readable representation of the BHND *chip\_id* value to the specified *buffer* with a capacity of *size*. No more than *size-1* characters will be written, with the *size'th* character set to '\\0'. A buffer size of BHND\_CHIPID\_MAX\_NAMELEN is sufficient for any string representation produced using **bhnd\_format\_chip\_id**().

The **bhnd\_set\_custom\_core\_desc**() function uses the [bhnd(4)](/bhnd/4.md) device identification of *dev*, overriding the core name with the specified *dev\_name*, to populate the device's verbose description using [device\_set\_desc(9)](/device_set_desc/9.md).

The **bhnd\_set\_default\_core\_desc**() function uses the [bhnd(4)](/bhnd/4.md) device identification of *dev* to populate the device's verbose description using [device\_set\_desc(9)](/device_set_desc/9.md).

The **bhnd\_vendor\_name**() function returns the human-readable name for the JEP-106, ARM 4-bit continuation encoded manufacturer ID *vendor*, if known.

## RETURN VALUES

### Bus Resource Functions

The **bhnd\_activate\_resource**(), **bhnd\_alloc\_resources**(), **bhnd\_deactivate\_resource**(), and **bhnd\_release\_resource**() functions return 0 on success, otherwise an appropriate error code is returned.

The **bhnd\_alloc\_resource**() and **bhnd\_alloc\_resource\_any**() functions return a pointer to *struct resource* on success, a null pointer otherwise.

### Device Configuration Functions

The **bhnd\_read\_config**() and **bhnd\_write\_config**() functions return 0 on success, or one of the following values on error:

- \[EINVAL\]

  The device is not a direct child of the [bhnd(4)](/bhnd/4.md) bus

- \[EINVAL\]

  The requested width is not one of 1, 2, or 4 bytes.

- \[ENODEV\]

  Accessing agent/config space for the device is unsupported.

- \[EFAULT\]

  The requested offset or width exceeds the bounds of the mapped agent/config space.

The **bhnd\_read\_ioctl**(), **bhnd\_write\_ioctl**(), **bhnd\_read\_iost**(), **bhnd\_reset\_hw**(), and **bhnd\_suspend\_hw**() functions return 0 on success, otherwise an appropriate error code is returned.

### Device Information Functions

The **bhnd\_read\_board\_info**() function returns 0 on success, otherwise an appropriate error code is returned.

### DMA Address Translation Functions

The **bhnd\_get\_dma\_translation**() function returns 0 on success, or one of the following values on error:

- \[ENODEV\]

  DMA is not supported.

- \[ENOENT\]

  No DMA translation matching the requested address width and translation flags is available.

If fetching the requested DMA address translation otherwise fails, an appropriate error code will be returned.

### Interrupt Functions

The **bhnd\_get\_intr\_ivec**() function returns 0 on success, or ENXIO if the requested interrupt line exceeds the number of interrupt lines assigned to the device.

The **bhnd\_map\_intr**() function returns 0 on success, otherwise an appropriate error code is returned.

### NVRAM Functions

The **bhnd\_nvram\_getvar**(), **bhnd\_nvram\_getvar\_array**(), **bhnd\_nvram\_getvar\_int**(), **bhnd\_nvram\_getvar\_int8**(), **bhnd\_nvram\_getvar\_int16**(), **bhnd\_nvram\_getvar\_int32**(), **bhnd\_nvram\_getvar\_uint**(), **bhnd\_nvram\_getvar\_uint8**(), **bhnd\_nvram\_getvar\_uint16**(), and **bhnd\_nvram\_getvar\_uint32**() functions return 0 on success, or one of the following values on error:

- \[ENODEV\]

  If an NVRAM provider has not been registered with the bus.

- \[ENOENT\]

  The requested variable was not found.

- \[ENOMEM\]

  If the buffer of size is too small to hold the requested value.

- \[EOPNOTSUPP\]

  If the value's native type is incompatible with and cannot be coerced to the requested type.

- \[ERANGE\]

  If value coercion would overflow (or underflow) the requested type

If reading the variable otherwise fails, an appropriate error code will be returned.

### Port/Region Functions

The **bhnd\_decode\_port\_rid**() function returns 0 on success, or an appropriate error code if no matching port/region is found.

The **bhnd\_get\_port\_rid**() function returns the resource ID for the requested port and region, or -1 if the port or region are invalid, or do not have an assigned resource ID.

The **bhnd\_get\_region\_addr**() function returns 0 on success, or an appropriate error code if no matching port/region is found.

### PMU Functions

The **bhnd\_alloc\_pmu**() function returns 0 on success, otherwise an appropriate error code is returned.

The **bhnd\_release\_pmu**() function returns 0 on success, otherwise an appropriate error code is returned, and the core state will be left unmodified.

The **bhnd\_enable\_clocks**() and **bhnd\_request\_clock**() functions return 0 on success, or one of the following values on error:

- \[ENODEV\]

  An unsupported clock was requested.

- \[ENXIO\]

  No PMU or PWRCTL provider has been registered with the bus.

The **bhnd\_get\_clock\_freq**() function returns 0 on success, or ENODEV if the frequency for the specified clock is not available.

The **bhnd\_get\_clock\_latency**() function returns 0 on success, or ENODEV if the transition latency for the specified clock is not available.

The **bhnd\_request\_ext\_rsrc**() and **bhnd\_release\_ext\_rsrc**() functions return 0 on success, otherwise an appropriate error code is returned.

### Service Provider Functions

The **bhnd\_register\_provider**() function returns 0 on success, EEXIST if an entry for service already exists, or an appropriate error code if service registration otherwise fails.

The **bhnd\_deregister\_provider**() function returns 0 on success, or EBUSY if active references to the service provider exist.

The **bhnd\_retain\_provider**() function returns a pointer to *device\_t* on success, a null pointer if the requested provider is not registered.

### Utility Functions

The **bhnd\_format\_chip\_id**() function returns the total number of bytes written on success, or a negative integer on failure.

## SEE ALSO

[bhnd(4)](/bhnd/4.md), [bhnd\_erom(9)](/bhnd_erom/9.md)

## AUTHORS

The **bhnd** driver programming interface and this manual page were written by Landon Fuller ⟨*landonf@FreeBSD.org*⟩.
