/*-1* Copyright (c) 2015 Landon Fuller <[email protected]>2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer,9* without modification.10* 2. Redistributions in binary form must reproduce at minimum a disclaimer11* similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any12* redistribution must be conditioned upon including a substantially13* similar Disclaimer requirement for further binary redistribution.14*15* NO WARRANTY16* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS17* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT18* LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY19* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL20* THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,21* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF22* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS23* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER24* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)25* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF26* THE POSSIBILITY OF SUCH DAMAGES.27*28*/2930#ifndef _BHND_BHNDB_H_31#define _BHND_BHNDB_H_3233#include <sys/param.h>34#include <sys/bus.h>3536#include <machine/bus.h>37#include <sys/rman.h>38#include <machine/resource.h>3940#include <dev/bhnd/bhnd.h>4142#include "bhndb_bus_if.h"4344DECLARE_CLASS(bhnd_bhndb_driver);4546int bhndb_attach_bridge(device_t parent, device_t *bhndb, int unit);4748/**49* bhndb register window types.50*/51typedef enum {52BHNDB_REGWIN_T_CORE, /**< Fixed mapping of a core port region. */53BHNDB_REGWIN_T_SPROM, /**< Fixed mapping of device SPROM */54BHNDB_REGWIN_T_DYN, /**< A dynamically configurable window */55BHNDB_REGWIN_T_INVALID /**< Invalid type */56} bhndb_regwin_type_t;5758/**59* Evaluates to true if @p _rt defines a static mapping.60*61* @param _rt A bhndb_regwin_type_t value.62*/63#define BHNDB_REGWIN_T_IS_STATIC(_rt) \64((_rt) == BHNDB_REGWIN_T_CORE || \65(_rt) == BHNDB_REGWIN_T_SPROM)6667/**68* bhndb register window definition.69*/70struct bhndb_regwin {71bhndb_regwin_type_t win_type; /**< window type */72bus_size_t win_offset; /**< offset of the window within the resource */73bus_size_t win_size; /**< size of the window */7475/** Resource identification */76struct {77int type; /**< resource type */78int rid; /**< resource id */79} res;8081union {82/** Core-specific register window (BHNDB_REGWIN_T_CORE). */83struct {84bhnd_devclass_t class; /**< mapped core's class */85u_int unit; /**< mapped core's unit */86bhnd_port_type port_type; /**< mapped port type */87u_int port; /**< mapped port number */88u_int region; /**< mapped region number */89bhnd_size_t offset; /**< mapped offset within the region */90} core;9192/** SPROM register window (BHNDB_REGWIN_T_SPROM). */93struct {} sprom;9495/** Dynamic register window (BHNDB_REGWIN_T_DYN). */96struct {97bus_size_t cfg_offset; /**< window address config offset. */98} dyn;99} d;100};101#define BHNDB_REGWIN_TABLE_END { BHNDB_REGWIN_T_INVALID, 0, 0, { 0, 0 } }102103/**104* Bridge hardware configuration.105*106* Provides the bridge's DMA address translation descriptions, register/address107* mappings, and the resources via which those mappings may be accessed.108*/109struct bhndb_hwcfg {110const struct resource_spec *resource_specs; /**< resources required by our register windows */111const struct bhndb_regwin *register_windows; /**< register window table */112const struct bhnd_dma_translation *dma_translations; /**< DMA address translation table, or NULL if DMA is not supported */113};114115/**116* Hardware specification entry.117*118* Defines a set of match criteria that may be used to determine the119* register map and resource configuration for a bhndb bridge device.120*/121struct bhndb_hw {122const char *name; /**< configuration name */123const struct bhnd_core_match *hw_reqs; /**< match requirements */124u_int num_hw_reqs; /**< number of match requirements */125const struct bhndb_hwcfg *cfg; /**< associated hardware configuration */126};127128/**129* bhndb resource allocation priorities.130*/131typedef enum {132/** No direct resources should ever be allocated for this device. */133BHNDB_PRIORITY_NONE = 0,134135/** Allocate a direct resource if available after serving all other136* higher-priority requests. */137BHNDB_PRIORITY_LOW = 1,138139/** Direct resource allocation is preferred, but not necessary140* for reasonable runtime performance. */141BHNDB_PRIORITY_DEFAULT = 2,142143/** Indirect resource allocation would incur high runtime overhead. */144BHNDB_PRIORITY_HIGH = 3145} bhndb_priority_t;146147/**148* bhndb resource allocation flags.149*/150enum bhndb_alloc_flags {151/**152* If resource overcommit prevents fulfilling a request for this153* resource, an in-use resource should be borrowed to fulfill the154* request.155*156* The only known use case is to support accessing the ChipCommon core157* during Wi-Fi driver operation on early PCI Wi-Fi devices158* (PCI_V0, SSB) that do not provide a dedicated ChipCommon register159* window mapping; on such devices, device and firmware semantics160* guarantee the safety of -- after disabling interrupts -- borrowing161* the single dynamic register window that's been assigned to the D11162* core to perform the few ChipCommon operations required by the driver.163*/164BHNDB_ALLOC_FULFILL_ON_OVERCOMMIT = (1<<0),165};166167/**168* Port resource priority descriptor.169*/170struct bhndb_port_priority {171bhnd_port_type type; /**< port type. */172u_int port; /**< port */173u_int region; /**< region */174bhndb_priority_t priority; /**< port priority */175uint32_t alloc_flags; /**< port allocation flags (@see bhndb_alloc_flags) */176};177178/**179* Core resource priority descriptor.180*/181struct bhndb_hw_priority {182struct bhnd_core_match match; /**< core match descriptor */183bhndb_priority_t priority; /**< core-level priority */184const struct bhndb_port_priority *ports; /**< port priorities */185u_int num_ports; /**< number of port priority records. */186};187#define BHNDB_HW_PRIORITY_TABLE_END { {}, BHNDB_PRIORITY_NONE, NULL, 0 }188189#endif /* _BHND_BHNDB_H_ */190191192