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 */ 344ad7e9b0SAdrian Chadd 354ad7e9b0SAdrian Chadd #ifndef _BHND_BHNDBVAR_H_ 364ad7e9b0SAdrian Chadd #define _BHND_BHNDBVAR_H_ 374ad7e9b0SAdrian Chadd 384ad7e9b0SAdrian Chadd #include <sys/param.h> 394ad7e9b0SAdrian Chadd #include <sys/bus.h> 404ad7e9b0SAdrian Chadd #include <sys/kernel.h> 414ad7e9b0SAdrian Chadd #include <sys/lock.h> 424ad7e9b0SAdrian Chadd #include <sys/malloc.h> 434ad7e9b0SAdrian Chadd #include <sys/mutex.h> 444ad7e9b0SAdrian Chadd #include <sys/rman.h> 454ad7e9b0SAdrian Chadd 464ad7e9b0SAdrian Chadd #include <dev/bhnd/bhndvar.h> 474ad7e9b0SAdrian Chadd #include "bhndb.h" 484ad7e9b0SAdrian Chadd 494ad7e9b0SAdrian Chadd #include "bhndb_if.h" 504ad7e9b0SAdrian Chadd 514ad7e9b0SAdrian Chadd /* 524ad7e9b0SAdrian Chadd * Definitions shared by bhndb(4) driver implementations. 534ad7e9b0SAdrian Chadd */ 544ad7e9b0SAdrian Chadd 554ad7e9b0SAdrian Chadd DECLARE_CLASS(bhndb_driver); 564ad7e9b0SAdrian Chadd 57caeff9a3SLandon J. Fuller /* forward declarations */ 58caeff9a3SLandon J. Fuller struct bhndb_intr_isrc; 594ad7e9b0SAdrian Chadd struct bhndb_resources; 6089294a78SLandon J. Fuller struct bhndb_host_resources; 614ad7e9b0SAdrian Chadd 6289294a78SLandon J. Fuller int bhndb_attach(device_t dev, 6389294a78SLandon J. Fuller struct bhnd_chipid *cid, 6489294a78SLandon J. Fuller struct bhnd_core_info *cores, u_int ncores, 6589294a78SLandon J. Fuller struct bhnd_core_info *bridge_core, 6689294a78SLandon J. Fuller bhnd_erom_class_t *erom_class); 674ad7e9b0SAdrian Chadd 684ad7e9b0SAdrian Chadd int bhndb_generic_probe(device_t dev); 694ad7e9b0SAdrian Chadd int bhndb_generic_detach(device_t dev); 704ad7e9b0SAdrian Chadd int bhndb_generic_suspend(device_t dev); 714ad7e9b0SAdrian Chadd int bhndb_generic_resume(device_t dev); 7289294a78SLandon J. Fuller int bhndb_generic_init_full_config(device_t dev, 7389294a78SLandon J. Fuller device_t child, 744ad7e9b0SAdrian Chadd const struct bhndb_hw_priority *hw_prio_table); 754ad7e9b0SAdrian Chadd 7689294a78SLandon J. Fuller int bhnd_generic_br_suspend_child(device_t dev, 7789294a78SLandon J. Fuller device_t child); 7889294a78SLandon J. Fuller int bhnd_generic_br_resume_child(device_t dev, 7989294a78SLandon J. Fuller device_t child); 8089294a78SLandon J. Fuller 8189294a78SLandon J. Fuller int bhndb_find_hostb_core( 8289294a78SLandon J. Fuller struct bhnd_core_info *cores, u_int ncores, 8389294a78SLandon J. Fuller bhnd_devclass_t bridge_devclass, 8489294a78SLandon J. Fuller struct bhnd_core_info *core); 8589294a78SLandon J. Fuller 86caeff9a3SLandon J. Fuller struct bhndb_intr_isrc *bhndb_alloc_intr_isrc(device_t owner, int rid, 87caeff9a3SLandon J. Fuller rman_res_t start, rman_res_t end, 88caeff9a3SLandon J. Fuller rman_res_t count, u_int flags); 89caeff9a3SLandon J. Fuller void bhndb_free_intr_isrc( 90caeff9a3SLandon J. Fuller struct bhndb_intr_isrc *isrc); 91caeff9a3SLandon J. Fuller 929ed45324SLandon J. Fuller int bhndb_alloc_host_resources( 939ed45324SLandon J. Fuller struct bhndb_host_resources **resources, 949ed45324SLandon J. Fuller device_t dev, device_t parent_dev, 959ed45324SLandon J. Fuller const struct bhndb_hwcfg *hwcfg); 969ed45324SLandon J. Fuller 9789294a78SLandon J. Fuller void bhndb_release_host_resources( 9889294a78SLandon J. Fuller struct bhndb_host_resources *resources); 9989294a78SLandon J. Fuller struct resource *bhndb_host_resource_for_range( 10089294a78SLandon J. Fuller struct bhndb_host_resources *resources, 10189294a78SLandon J. Fuller int type, rman_res_t start, 10289294a78SLandon J. Fuller rman_res_t count); 10389294a78SLandon J. Fuller struct resource *bhndb_host_resource_for_regwin( 10489294a78SLandon J. Fuller struct bhndb_host_resources *resources, 10589294a78SLandon J. Fuller const struct bhndb_regwin *win); 10689294a78SLandon J. Fuller 10789294a78SLandon J. Fuller size_t bhndb_regwin_count( 10889294a78SLandon J. Fuller const struct bhndb_regwin *table, 10989294a78SLandon J. Fuller bhndb_regwin_type_t type); 11089294a78SLandon J. Fuller 11189294a78SLandon J. Fuller const struct bhndb_regwin *bhndb_regwin_find_type( 11289294a78SLandon J. Fuller const struct bhndb_regwin *table, 11389294a78SLandon J. Fuller bhndb_regwin_type_t type, 11489294a78SLandon J. Fuller bus_size_t min_size); 11589294a78SLandon J. Fuller 11689294a78SLandon J. Fuller const struct bhndb_regwin *bhndb_regwin_find_core( 11789294a78SLandon J. Fuller const struct bhndb_regwin *table, 11889294a78SLandon J. Fuller bhnd_devclass_t class, int unit, 11989294a78SLandon J. Fuller bhnd_port_type port_type, u_int port, 120*eaa5fb4bSLandon J. Fuller u_int region, bus_size_t offset, 121*eaa5fb4bSLandon J. Fuller bus_size_t min_size); 12289294a78SLandon J. Fuller 12389294a78SLandon J. Fuller const struct bhndb_regwin *bhndb_regwin_find_best( 12489294a78SLandon J. Fuller const struct bhndb_regwin *table, 12589294a78SLandon J. Fuller bhnd_devclass_t class, int unit, 12689294a78SLandon J. Fuller bhnd_port_type port_type, u_int port, 127*eaa5fb4bSLandon J. Fuller u_int region, bus_size_t offset, 128*eaa5fb4bSLandon J. Fuller bus_size_t min_size); 12989294a78SLandon J. Fuller 13089294a78SLandon J. Fuller bool bhndb_regwin_match_core( 13189294a78SLandon J. Fuller const struct bhndb_regwin *regw, 13289294a78SLandon J. Fuller struct bhnd_core_info *core); 1334ad7e9b0SAdrian Chadd 134e9378f45SAdrian Chadd /** 135e9378f45SAdrian Chadd * bhndb child address space. Children either operate in the bridged 136e9378f45SAdrian Chadd * SoC address space, or within the address space mapped to the host 137e9378f45SAdrian Chadd * device (e.g. the PCI BAR(s)). 138e9378f45SAdrian Chadd */ 139e9378f45SAdrian Chadd typedef enum { 140e9378f45SAdrian Chadd BHNDB_ADDRSPACE_BRIDGED, /**< bridged (SoC) address space */ 141e9378f45SAdrian Chadd BHNDB_ADDRSPACE_NATIVE /**< host address space */ 142e9378f45SAdrian Chadd } bhndb_addrspace; 143e9378f45SAdrian Chadd 1444ad7e9b0SAdrian Chadd /** bhndb child instance state */ 1454ad7e9b0SAdrian Chadd struct bhndb_devinfo { 146e9378f45SAdrian Chadd bhndb_addrspace addrspace; /**< child address space. */ 1474ad7e9b0SAdrian Chadd struct resource_list resources; /**< child resources. */ 1484ad7e9b0SAdrian Chadd }; 1494ad7e9b0SAdrian Chadd 1504ad7e9b0SAdrian Chadd /** 151caeff9a3SLandon J. Fuller * Host interrupt source to which bridged interrupts may be routed. 152caeff9a3SLandon J. Fuller */ 153caeff9a3SLandon J. Fuller struct bhndb_intr_isrc { 154caeff9a3SLandon J. Fuller device_t is_owner; /**< host device (e.g. the pci device). */ 155caeff9a3SLandon J. Fuller struct resource *is_res; /**< irq resource */ 156caeff9a3SLandon J. Fuller int is_rid; /**< irq resource ID */ 157caeff9a3SLandon J. Fuller }; 158caeff9a3SLandon J. Fuller 159caeff9a3SLandon J. Fuller /** 16089294a78SLandon J. Fuller * Host resources allocated for a bridge hardware configuration. 16189294a78SLandon J. Fuller */ 16289294a78SLandon J. Fuller struct bhndb_host_resources { 16389294a78SLandon J. Fuller device_t owner; /**< device owning the allocated resources */ 16489294a78SLandon J. Fuller const struct bhndb_hwcfg *cfg; /**< bridge hardware configuration */ 16589294a78SLandon J. Fuller struct resource_spec *resource_specs; /**< resource specification table */ 16689294a78SLandon J. Fuller struct resource **resources; /**< allocated resource table */ 1679ed45324SLandon J. Fuller bus_dma_tag_t *dma_tags; /**< DMA tags for all hwcfg DMA translations, or NULL 1689ed45324SLandon J. Fuller if DMA is not supported */ 1699ed45324SLandon J. Fuller size_t num_dma_tags; /**< DMA tag count */ 17089294a78SLandon J. Fuller }; 17189294a78SLandon J. Fuller 17289294a78SLandon J. Fuller /** 1734ad7e9b0SAdrian Chadd * bhndb driver instance state. Must be first member of all subclass 1744ad7e9b0SAdrian Chadd * softc structures. 1754ad7e9b0SAdrian Chadd */ 1764ad7e9b0SAdrian Chadd struct bhndb_softc { 1774ad7e9b0SAdrian Chadd device_t dev; /**< bridge device */ 1784ad7e9b0SAdrian Chadd struct bhnd_chipid chipid; /**< chip identification */ 17989294a78SLandon J. Fuller struct bhnd_core_info bridge_core; /**< bridge core info */ 1804ad7e9b0SAdrian Chadd 1814ad7e9b0SAdrian Chadd device_t parent_dev; /**< parent device */ 1824ad7e9b0SAdrian Chadd device_t bus_dev; /**< child bhnd(4) bus */ 1834ad7e9b0SAdrian Chadd 1848e35bf83SLandon J. Fuller struct bhnd_service_registry services; /**< local service registry */ 1858e35bf83SLandon J. Fuller 1864ad7e9b0SAdrian Chadd struct mtx sc_mtx; /**< resource lock. */ 1874ad7e9b0SAdrian Chadd struct bhndb_resources *bus_res; /**< bus resource state */ 188caeff9a3SLandon J. Fuller STAILQ_HEAD(,bhndb_intr_handler) bus_intrs; /**< attached child interrupt handlers */ 1894ad7e9b0SAdrian Chadd }; 1904ad7e9b0SAdrian Chadd 1914ad7e9b0SAdrian Chadd #endif /* _BHND_BHNDBVAR_H_ */ 192