/*-1* Copyright (c) 2015-2016 Landon Fuller <[email protected]>2* Copyright (c) 2017 The FreeBSD Foundation3* All rights reserved.4*5* Portions of this software were developed by Landon Fuller6* under sponsorship from the FreeBSD Foundation.7*8* Redistribution and use in source and binary forms, with or without9* modification, are permitted provided that the following conditions10* are met:11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer,13* without modification.14* 2. Redistributions in binary form must reproduce at minimum a disclaimer15* similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any16* redistribution must be conditioned upon including a substantially17* similar Disclaimer requirement for further binary redistribution.18*19* NO WARRANTY20* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS21* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT22* LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY23* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL24* THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,25* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF26* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS27* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER28* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)29* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF30* THE POSSIBILITY OF SUCH DAMAGES.31*32*/3334#ifndef _BHND_BHNDB_PCIVAR_H_35#define _BHND_BHNDB_PCIVAR_H_3637#include "bhndbvar.h"3839/*40* bhndb(4) PCI driver subclass.41*/4243DECLARE_CLASS(bhndb_pci_driver);4445struct bhndb_pci_softc;4647/*48* An interconnect-specific function implementing BHNDB_SET_WINDOW_ADDR49*/50typedef int (*bhndb_pci_set_regwin_t)(device_t dev, device_t pci_dev,51const struct bhndb_regwin *rw, bhnd_addr_t addr);5253/**54* PCI/PCIe bridge-level device quirks55*/56enum {57/** No quirks */58BHNDB_PCI_QUIRK_NONE = 0,5960/**61* The core requires fixup of the BAR0 SROM shadow to point at the62* current PCI core.63*/64BHNDB_PCI_QUIRK_SRSH_WAR = (1<<0),6566/**67* The PCI (rev <= 5) core does not provide interrupt status/mask68* registers; these siba-only devices require routing backplane69* interrupt flags via the SIBA_CFG0_INTVEC register.70*/71BHNDB_PCI_QUIRK_SIBA_INTVEC = (1<<1),72};7374/** bhndb_pci quirk table entry */75struct bhndb_pci_quirk {76struct bhnd_chip_match chip_desc; /**< chip match descriptor */77struct bhnd_core_match core_desc; /**< core match descriptor */78uint32_t quirks; /**< quirk flags */79};8081#define BHNDB_PCI_QUIRK(_rev, _flags) { \82{ BHND_MATCH_ANY }, \83{ BHND_MATCH_CORE_REV(_rev) }, \84_flags, \85}8687#define BHNDB_PCI_QUIRK_END \88{ { BHND_MATCH_ANY }, { BHND_MATCH_ANY }, 0 }8990#define BHNDB_PCI_IS_QUIRK_END(_q) \91(BHND_MATCH_IS_ANY(&(_q)->core_desc) && \92BHND_MATCH_IS_ANY(&(_q)->chip_desc) && \93(_q)->quirks == 0)9495/** bhndb_pci core table entry */96struct bhndb_pci_core {97struct bhnd_core_match match; /**< core match descriptor */98struct bhndb_pci_quirk *quirks; /**< quirk table */99};100101#define BHNDB_PCI_CORE(_device, _quirks) { \102{ BHND_MATCH_CORE(BHND_MFGID_BCM, BHND_COREID_ ## _device) }, \103_quirks \104}105#define BHNDB_PCI_CORE_END { { BHND_MATCH_ANY }, NULL }106#define BHNDB_PCI_IS_CORE_END(_c) BHND_MATCH_IS_ANY(&(_c)->match)107108struct bhndb_pci_softc {109struct bhndb_softc bhndb; /**< parent softc */110device_t dev; /**< bridge device */111device_t parent; /**< parent PCI device */112bhnd_devclass_t pci_devclass; /**< PCI core's devclass */113uint32_t pci_quirks; /**< PCI bridge-level quirks */114int msi_count; /**< MSI count, or 0 */115struct bhndb_intr_isrc *isrc; /**< host interrupt source */116117struct mtx mtx;118bhndb_pci_set_regwin_t set_regwin; /**< regwin handler */119};120121#define BHNDB_PCI_LOCK_INIT(sc) \122mtx_init(&(sc)->mtx, device_get_nameunit((sc)->dev), \123"bhndb_pc state", MTX_DEF)124#define BHNDB_PCI_LOCK(sc) mtx_lock(&(sc)->mtx)125#define BHNDB_PCI_UNLOCK(sc) mtx_unlock(&(sc)->mtx)126#define BHNDB_PCI_LOCK_ASSERT(sc, what) mtx_assert(&(sc)->mtx, what)127#define BHNDB_PCI_LOCK_DESTROY(sc) mtx_destroy(&(sc)->mtx)128129#endif /* _BHND_BHNDB_PCIVAR_H_ */130131132