/*-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_BHNDBVAR_H_35#define _BHND_BHNDBVAR_H_3637#include <sys/param.h>38#include <sys/bus.h>39#include <sys/kernel.h>40#include <sys/lock.h>41#include <sys/malloc.h>42#include <sys/mutex.h>43#include <sys/rman.h>4445#include <dev/bhnd/bhndvar.h>46#include "bhndb.h"4748#include "bhndb_if.h"4950/*51* Definitions shared by bhndb(4) driver implementations.52*/5354DECLARE_CLASS(bhndb_driver);5556/* forward declarations */57struct bhndb_intr_isrc;58struct bhndb_resources;59struct bhndb_host_resources;6061int bhndb_attach(device_t dev,62struct bhnd_chipid *cid,63struct bhnd_core_info *cores, u_int ncores,64struct bhnd_core_info *bridge_core,65bhnd_erom_class_t *erom_class);6667int bhndb_generic_probe(device_t dev);68int bhndb_generic_detach(device_t dev);69int bhndb_generic_suspend(device_t dev);70int bhndb_generic_resume(device_t dev);71int bhndb_generic_init_full_config(device_t dev,72device_t child,73const struct bhndb_hw_priority *hw_prio_table);7475int bhnd_generic_br_suspend_child(device_t dev,76device_t child);77int bhnd_generic_br_resume_child(device_t dev,78device_t child);7980int bhndb_find_hostb_core(81struct bhnd_core_info *cores, u_int ncores,82bhnd_devclass_t bridge_devclass,83struct bhnd_core_info *core);8485struct bhndb_intr_isrc *bhndb_alloc_intr_isrc(device_t owner, int rid,86rman_res_t start, rman_res_t end,87rman_res_t count, u_int flags);88void bhndb_free_intr_isrc(89struct bhndb_intr_isrc *isrc);9091int bhndb_alloc_host_resources(92struct bhndb_host_resources **resources,93device_t dev, device_t parent_dev,94const struct bhndb_hwcfg *hwcfg);9596void bhndb_release_host_resources(97struct bhndb_host_resources *resources);98struct resource *bhndb_host_resource_for_range(99struct bhndb_host_resources *resources,100int type, rman_res_t start,101rman_res_t count);102struct resource *bhndb_host_resource_for_regwin(103struct bhndb_host_resources *resources,104const struct bhndb_regwin *win);105106size_t bhndb_regwin_count(107const struct bhndb_regwin *table,108bhndb_regwin_type_t type);109110const struct bhndb_regwin *bhndb_regwin_find_type(111const struct bhndb_regwin *table,112bhndb_regwin_type_t type,113bus_size_t min_size);114115const struct bhndb_regwin *bhndb_regwin_find_core(116const struct bhndb_regwin *table,117bhnd_devclass_t class, int unit,118bhnd_port_type port_type, u_int port,119u_int region, bus_size_t offset,120bus_size_t min_size);121122const struct bhndb_regwin *bhndb_regwin_find_best(123const struct bhndb_regwin *table,124bhnd_devclass_t class, int unit,125bhnd_port_type port_type, u_int port,126u_int region, bus_size_t offset,127bus_size_t min_size);128129bool bhndb_regwin_match_core(130const struct bhndb_regwin *regw,131struct bhnd_core_info *core);132133/**134* bhndb child address space. Children either operate in the bridged135* SoC address space, or within the address space mapped to the host136* device (e.g. the PCI BAR(s)).137*/138typedef enum {139BHNDB_ADDRSPACE_BRIDGED, /**< bridged (SoC) address space */140BHNDB_ADDRSPACE_NATIVE /**< host address space */141} bhndb_addrspace;142143/** bhndb child instance state */144struct bhndb_devinfo {145bhndb_addrspace addrspace; /**< child address space. */146struct resource_list resources; /**< child resources. */147};148149/**150* Host interrupt source to which bridged interrupts may be routed.151*/152struct bhndb_intr_isrc {153device_t is_owner; /**< host device (e.g. the pci device). */154struct resource *is_res; /**< irq resource */155int is_rid; /**< irq resource ID */156};157158/**159* Host resources allocated for a bridge hardware configuration.160*/161struct bhndb_host_resources {162device_t owner; /**< device owning the allocated resources */163const struct bhndb_hwcfg *cfg; /**< bridge hardware configuration */164struct resource_spec *resource_specs; /**< resource specification table */165struct resource **resources; /**< allocated resource table */166bus_dma_tag_t *dma_tags; /**< DMA tags for all hwcfg DMA translations, or NULL167if DMA is not supported */168size_t num_dma_tags; /**< DMA tag count */169};170171/**172* bhndb driver instance state. Must be first member of all subclass173* softc structures.174*/175struct bhndb_softc {176device_t dev; /**< bridge device */177struct bhnd_chipid chipid; /**< chip identification */178struct bhnd_core_info bridge_core; /**< bridge core info */179180device_t parent_dev; /**< parent device */181device_t bus_dev; /**< child bhnd(4) bus */182183struct bhnd_service_registry services; /**< local service registry */184185struct mtx sc_mtx; /**< resource lock. */186struct bhndb_resources *bus_res; /**< bus resource state */187STAILQ_HEAD(,bhndb_intr_handler) bus_intrs; /**< attached child interrupt handlers */188};189190#endif /* _BHND_BHNDBVAR_H_ */191192193