14ad7e9b0SAdrian Chadd /*- 28e35bf83SLandon J. Fuller * Copyright (c) 2015-2016 Landon Fuller <landon@landonf.org> 38e35bf83SLandon J. Fuller * Copyright (c) 2017 The FreeBSD Foundation 44ad7e9b0SAdrian Chadd * All rights reserved. 54ad7e9b0SAdrian Chadd * 68e35bf83SLandon J. Fuller * Portions of this software were developed by Landon Fuller 78e35bf83SLandon J. Fuller * under sponsorship from the FreeBSD Foundation. 88e35bf83SLandon J. Fuller * 94ad7e9b0SAdrian Chadd * Redistribution and use in source and binary forms, with or without 104ad7e9b0SAdrian Chadd * modification, are permitted provided that the following conditions 114ad7e9b0SAdrian Chadd * are met: 124ad7e9b0SAdrian Chadd * 1. Redistributions of source code must retain the above copyright 134ad7e9b0SAdrian Chadd * notice, this list of conditions and the following disclaimer, 144ad7e9b0SAdrian Chadd * without modification. 154ad7e9b0SAdrian Chadd * 2. Redistributions in binary form must reproduce at minimum a disclaimer 164ad7e9b0SAdrian Chadd * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 174ad7e9b0SAdrian Chadd * redistribution must be conditioned upon including a substantially 184ad7e9b0SAdrian Chadd * similar Disclaimer requirement for further binary redistribution. 194ad7e9b0SAdrian Chadd * 204ad7e9b0SAdrian Chadd * NO WARRANTY 214ad7e9b0SAdrian Chadd * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 224ad7e9b0SAdrian Chadd * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 234ad7e9b0SAdrian Chadd * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 244ad7e9b0SAdrian Chadd * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 254ad7e9b0SAdrian Chadd * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 264ad7e9b0SAdrian Chadd * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 274ad7e9b0SAdrian Chadd * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 284ad7e9b0SAdrian Chadd * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 294ad7e9b0SAdrian Chadd * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 304ad7e9b0SAdrian Chadd * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 314ad7e9b0SAdrian Chadd * THE POSSIBILITY OF SUCH DAMAGES. 324ad7e9b0SAdrian Chadd * 334ad7e9b0SAdrian Chadd * $FreeBSD$ 344ad7e9b0SAdrian Chadd */ 354ad7e9b0SAdrian Chadd 364ad7e9b0SAdrian Chadd #ifndef _BHND_BHNDBVAR_H_ 374ad7e9b0SAdrian Chadd #define _BHND_BHNDBVAR_H_ 384ad7e9b0SAdrian Chadd 394ad7e9b0SAdrian Chadd #include <sys/param.h> 404ad7e9b0SAdrian Chadd #include <sys/bus.h> 414ad7e9b0SAdrian Chadd #include <sys/kernel.h> 424ad7e9b0SAdrian Chadd #include <sys/lock.h> 434ad7e9b0SAdrian Chadd #include <sys/malloc.h> 444ad7e9b0SAdrian Chadd #include <sys/mutex.h> 454ad7e9b0SAdrian Chadd #include <sys/rman.h> 464ad7e9b0SAdrian Chadd 474ad7e9b0SAdrian Chadd #include <dev/bhnd/bhndvar.h> 484ad7e9b0SAdrian Chadd #include "bhndb.h" 494ad7e9b0SAdrian Chadd 504ad7e9b0SAdrian Chadd #include "bhndb_if.h" 514ad7e9b0SAdrian Chadd 524ad7e9b0SAdrian Chadd /* 534ad7e9b0SAdrian Chadd * Definitions shared by bhndb(4) driver implementations. 544ad7e9b0SAdrian Chadd */ 554ad7e9b0SAdrian Chadd 564ad7e9b0SAdrian Chadd DECLARE_CLASS(bhndb_driver); 574ad7e9b0SAdrian Chadd 58caeff9a3SLandon J. Fuller /* forward declarations */ 59caeff9a3SLandon J. Fuller struct bhndb_intr_isrc; 604ad7e9b0SAdrian Chadd struct bhndb_resources; 6189294a78SLandon J. Fuller struct bhndb_host_resources; 624ad7e9b0SAdrian Chadd 6389294a78SLandon J. Fuller int bhndb_attach(device_t dev, 6489294a78SLandon J. Fuller struct bhnd_chipid *cid, 6589294a78SLandon J. Fuller struct bhnd_core_info *cores, u_int ncores, 6689294a78SLandon J. Fuller struct bhnd_core_info *bridge_core, 6789294a78SLandon J. Fuller bhnd_erom_class_t *erom_class); 684ad7e9b0SAdrian Chadd 694ad7e9b0SAdrian Chadd int bhndb_generic_probe(device_t dev); 704ad7e9b0SAdrian Chadd int bhndb_generic_detach(device_t dev); 714ad7e9b0SAdrian Chadd int bhndb_generic_suspend(device_t dev); 724ad7e9b0SAdrian Chadd int bhndb_generic_resume(device_t dev); 7389294a78SLandon J. Fuller int bhndb_generic_init_full_config(device_t dev, 7489294a78SLandon J. Fuller device_t child, 754ad7e9b0SAdrian Chadd const struct bhndb_hw_priority *hw_prio_table); 764ad7e9b0SAdrian Chadd 7789294a78SLandon J. Fuller int bhnd_generic_br_suspend_child(device_t dev, 7889294a78SLandon J. Fuller device_t child); 7989294a78SLandon J. Fuller int bhnd_generic_br_resume_child(device_t dev, 8089294a78SLandon J. Fuller device_t child); 8189294a78SLandon J. Fuller 8289294a78SLandon J. Fuller int bhndb_find_hostb_core( 8389294a78SLandon J. Fuller struct bhnd_core_info *cores, u_int ncores, 8489294a78SLandon J. Fuller bhnd_devclass_t bridge_devclass, 8589294a78SLandon J. Fuller struct bhnd_core_info *core); 8689294a78SLandon J. Fuller 87caeff9a3SLandon J. Fuller struct bhndb_intr_isrc *bhndb_alloc_intr_isrc(device_t owner, int rid, 88caeff9a3SLandon J. Fuller rman_res_t start, rman_res_t end, 89caeff9a3SLandon J. Fuller rman_res_t count, u_int flags); 90caeff9a3SLandon J. Fuller void bhndb_free_intr_isrc( 91caeff9a3SLandon J. Fuller struct bhndb_intr_isrc *isrc); 92caeff9a3SLandon J. Fuller 939ed45324SLandon J. Fuller int bhndb_alloc_host_resources( 949ed45324SLandon J. Fuller struct bhndb_host_resources **resources, 959ed45324SLandon J. Fuller device_t dev, device_t parent_dev, 969ed45324SLandon J. Fuller const struct bhndb_hwcfg *hwcfg); 979ed45324SLandon J. Fuller 9889294a78SLandon J. Fuller void bhndb_release_host_resources( 9989294a78SLandon J. Fuller struct bhndb_host_resources *resources); 10089294a78SLandon J. Fuller struct resource *bhndb_host_resource_for_range( 10189294a78SLandon J. Fuller struct bhndb_host_resources *resources, 10289294a78SLandon J. Fuller int type, rman_res_t start, 10389294a78SLandon J. Fuller rman_res_t count); 10489294a78SLandon J. Fuller struct resource *bhndb_host_resource_for_regwin( 10589294a78SLandon J. Fuller struct bhndb_host_resources *resources, 10689294a78SLandon J. Fuller const struct bhndb_regwin *win); 10789294a78SLandon J. Fuller 10889294a78SLandon J. Fuller size_t bhndb_regwin_count( 10989294a78SLandon J. Fuller const struct bhndb_regwin *table, 11089294a78SLandon J. Fuller bhndb_regwin_type_t type); 11189294a78SLandon J. Fuller 11289294a78SLandon J. Fuller const struct bhndb_regwin *bhndb_regwin_find_type( 11389294a78SLandon J. Fuller const struct bhndb_regwin *table, 11489294a78SLandon J. Fuller bhndb_regwin_type_t type, 11589294a78SLandon J. Fuller bus_size_t min_size); 11689294a78SLandon J. Fuller 11789294a78SLandon J. Fuller const struct bhndb_regwin *bhndb_regwin_find_core( 11889294a78SLandon J. Fuller const struct bhndb_regwin *table, 11989294a78SLandon J. Fuller bhnd_devclass_t class, int unit, 12089294a78SLandon J. Fuller bhnd_port_type port_type, u_int port, 121*eaa5fb4bSLandon J. Fuller u_int region, bus_size_t offset, 122*eaa5fb4bSLandon J. Fuller bus_size_t min_size); 12389294a78SLandon J. Fuller 12489294a78SLandon J. Fuller const struct bhndb_regwin *bhndb_regwin_find_best( 12589294a78SLandon J. Fuller const struct bhndb_regwin *table, 12689294a78SLandon J. Fuller bhnd_devclass_t class, int unit, 12789294a78SLandon J. Fuller bhnd_port_type port_type, u_int port, 128*eaa5fb4bSLandon J. Fuller u_int region, bus_size_t offset, 129*eaa5fb4bSLandon J. Fuller bus_size_t min_size); 13089294a78SLandon J. Fuller 13189294a78SLandon J. Fuller bool bhndb_regwin_match_core( 13289294a78SLandon J. Fuller const struct bhndb_regwin *regw, 13389294a78SLandon J. Fuller struct bhnd_core_info *core); 1344ad7e9b0SAdrian Chadd 135e9378f45SAdrian Chadd /** 136e9378f45SAdrian Chadd * bhndb child address space. Children either operate in the bridged 137e9378f45SAdrian Chadd * SoC address space, or within the address space mapped to the host 138e9378f45SAdrian Chadd * device (e.g. the PCI BAR(s)). 139e9378f45SAdrian Chadd */ 140e9378f45SAdrian Chadd typedef enum { 141e9378f45SAdrian Chadd BHNDB_ADDRSPACE_BRIDGED, /**< bridged (SoC) address space */ 142e9378f45SAdrian Chadd BHNDB_ADDRSPACE_NATIVE /**< host address space */ 143e9378f45SAdrian Chadd } bhndb_addrspace; 144e9378f45SAdrian Chadd 1454ad7e9b0SAdrian Chadd /** bhndb child instance state */ 1464ad7e9b0SAdrian Chadd struct bhndb_devinfo { 147e9378f45SAdrian Chadd bhndb_addrspace addrspace; /**< child address space. */ 1484ad7e9b0SAdrian Chadd struct resource_list resources; /**< child resources. */ 1494ad7e9b0SAdrian Chadd }; 1504ad7e9b0SAdrian Chadd 1514ad7e9b0SAdrian Chadd /** 152caeff9a3SLandon J. Fuller * Host interrupt source to which bridged interrupts may be routed. 153caeff9a3SLandon J. Fuller */ 154caeff9a3SLandon J. Fuller struct bhndb_intr_isrc { 155caeff9a3SLandon J. Fuller device_t is_owner; /**< host device (e.g. the pci device). */ 156caeff9a3SLandon J. Fuller struct resource *is_res; /**< irq resource */ 157caeff9a3SLandon J. Fuller int is_rid; /**< irq resource ID */ 158caeff9a3SLandon J. Fuller }; 159caeff9a3SLandon J. Fuller 160caeff9a3SLandon J. Fuller /** 16189294a78SLandon J. Fuller * Host resources allocated for a bridge hardware configuration. 16289294a78SLandon J. Fuller */ 16389294a78SLandon J. Fuller struct bhndb_host_resources { 16489294a78SLandon J. Fuller device_t owner; /**< device owning the allocated resources */ 16589294a78SLandon J. Fuller const struct bhndb_hwcfg *cfg; /**< bridge hardware configuration */ 16689294a78SLandon J. Fuller struct resource_spec *resource_specs; /**< resource specification table */ 16789294a78SLandon J. Fuller struct resource **resources; /**< allocated resource table */ 1689ed45324SLandon J. Fuller bus_dma_tag_t *dma_tags; /**< DMA tags for all hwcfg DMA translations, or NULL 1699ed45324SLandon J. Fuller if DMA is not supported */ 1709ed45324SLandon J. Fuller size_t num_dma_tags; /**< DMA tag count */ 17189294a78SLandon J. Fuller }; 17289294a78SLandon J. Fuller 17389294a78SLandon J. Fuller /** 1744ad7e9b0SAdrian Chadd * bhndb driver instance state. Must be first member of all subclass 1754ad7e9b0SAdrian Chadd * softc structures. 1764ad7e9b0SAdrian Chadd */ 1774ad7e9b0SAdrian Chadd struct bhndb_softc { 1784ad7e9b0SAdrian Chadd device_t dev; /**< bridge device */ 1794ad7e9b0SAdrian Chadd struct bhnd_chipid chipid; /**< chip identification */ 18089294a78SLandon J. Fuller struct bhnd_core_info bridge_core; /**< bridge core info */ 1814ad7e9b0SAdrian Chadd 1824ad7e9b0SAdrian Chadd device_t parent_dev; /**< parent device */ 1834ad7e9b0SAdrian Chadd device_t bus_dev; /**< child bhnd(4) bus */ 1844ad7e9b0SAdrian Chadd 1858e35bf83SLandon J. Fuller struct bhnd_service_registry services; /**< local service registry */ 1868e35bf83SLandon J. Fuller 1874ad7e9b0SAdrian Chadd struct mtx sc_mtx; /**< resource lock. */ 1884ad7e9b0SAdrian Chadd struct bhndb_resources *bus_res; /**< bus resource state */ 189caeff9a3SLandon J. Fuller STAILQ_HEAD(,bhndb_intr_handler) bus_intrs; /**< attached child interrupt handlers */ 1904ad7e9b0SAdrian Chadd }; 1914ad7e9b0SAdrian Chadd 1924ad7e9b0SAdrian Chadd #endif /* _BHND_BHNDBVAR_H_ */ 193