1 /*- 2 * Copyright (c) 2015-2016 Landon Fuller <landon@landonf.org> 3 * Copyright (c) 2017 The FreeBSD Foundation 4 * All rights reserved. 5 * 6 * Portions of this software were developed by Landon Fuller 7 * under sponsorship from the FreeBSD Foundation. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer, 14 * without modification. 15 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 16 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 17 * redistribution must be conditioned upon including a substantially 18 * similar Disclaimer requirement for further binary redistribution. 19 * 20 * NO WARRANTY 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 24 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 25 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 26 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 29 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 * THE POSSIBILITY OF SUCH DAMAGES. 32 * 33 * $FreeBSD$ 34 */ 35 36 #ifndef _BHND_BHNDBVAR_H_ 37 #define _BHND_BHNDBVAR_H_ 38 39 #include <sys/param.h> 40 #include <sys/bus.h> 41 #include <sys/kernel.h> 42 #include <sys/lock.h> 43 #include <sys/malloc.h> 44 #include <sys/mutex.h> 45 #include <sys/rman.h> 46 47 #include <dev/bhnd/bhndvar.h> 48 #include "bhndb.h" 49 50 #include "bhndb_if.h" 51 52 /* 53 * Definitions shared by bhndb(4) driver implementations. 54 */ 55 56 DECLARE_CLASS(bhndb_driver); 57 58 struct bhndb_resources; 59 struct bhndb_host_resources; 60 61 int bhndb_attach(device_t dev, 62 struct bhnd_chipid *cid, 63 struct bhnd_core_info *cores, u_int ncores, 64 struct bhnd_core_info *bridge_core, 65 bhnd_erom_class_t *erom_class); 66 67 int bhndb_generic_probe(device_t dev); 68 int bhndb_generic_detach(device_t dev); 69 int bhndb_generic_suspend(device_t dev); 70 int bhndb_generic_resume(device_t dev); 71 int bhndb_generic_init_full_config(device_t dev, 72 device_t child, 73 const struct bhndb_hw_priority *hw_prio_table); 74 75 int bhnd_generic_br_suspend_child(device_t dev, 76 device_t child); 77 int bhnd_generic_br_resume_child(device_t dev, 78 device_t child); 79 80 int bhndb_find_hostb_core( 81 struct bhnd_core_info *cores, u_int ncores, 82 bhnd_devclass_t bridge_devclass, 83 struct bhnd_core_info *core); 84 85 int bhndb_alloc_host_resources(device_t dev, 86 const struct bhndb_hwcfg *hwcfg, 87 struct bhndb_host_resources **resources); 88 void bhndb_release_host_resources( 89 struct bhndb_host_resources *resources); 90 struct resource *bhndb_host_resource_for_range( 91 struct bhndb_host_resources *resources, 92 int type, rman_res_t start, 93 rman_res_t count); 94 struct resource *bhndb_host_resource_for_regwin( 95 struct bhndb_host_resources *resources, 96 const struct bhndb_regwin *win); 97 98 size_t bhndb_regwin_count( 99 const struct bhndb_regwin *table, 100 bhndb_regwin_type_t type); 101 102 const struct bhndb_regwin *bhndb_regwin_find_type( 103 const struct bhndb_regwin *table, 104 bhndb_regwin_type_t type, 105 bus_size_t min_size); 106 107 const struct bhndb_regwin *bhndb_regwin_find_core( 108 const struct bhndb_regwin *table, 109 bhnd_devclass_t class, int unit, 110 bhnd_port_type port_type, u_int port, 111 u_int region); 112 113 const struct bhndb_regwin *bhndb_regwin_find_best( 114 const struct bhndb_regwin *table, 115 bhnd_devclass_t class, int unit, 116 bhnd_port_type port_type, u_int port, 117 u_int region, bus_size_t min_size); 118 119 bool bhndb_regwin_match_core( 120 const struct bhndb_regwin *regw, 121 struct bhnd_core_info *core); 122 123 /** 124 * bhndb child address space. Children either operate in the bridged 125 * SoC address space, or within the address space mapped to the host 126 * device (e.g. the PCI BAR(s)). 127 */ 128 typedef enum { 129 BHNDB_ADDRSPACE_BRIDGED, /**< bridged (SoC) address space */ 130 BHNDB_ADDRSPACE_NATIVE /**< host address space */ 131 } bhndb_addrspace; 132 133 /** bhndb child instance state */ 134 struct bhndb_devinfo { 135 bhndb_addrspace addrspace; /**< child address space. */ 136 struct resource_list resources; /**< child resources. */ 137 }; 138 139 /** 140 * Host resources allocated for a bridge hardware configuration. 141 */ 142 struct bhndb_host_resources { 143 device_t owner; /**< device owning the allocated resources */ 144 const struct bhndb_hwcfg *cfg; /**< bridge hardware configuration */ 145 struct resource_spec *resource_specs; /**< resource specification table */ 146 struct resource **resources; /**< allocated resource table */ 147 }; 148 149 /** 150 * bhndb driver instance state. Must be first member of all subclass 151 * softc structures. 152 */ 153 struct bhndb_softc { 154 device_t dev; /**< bridge device */ 155 struct bhnd_chipid chipid; /**< chip identification */ 156 struct bhnd_core_info bridge_core; /**< bridge core info */ 157 158 device_t parent_dev; /**< parent device */ 159 device_t bus_dev; /**< child bhnd(4) bus */ 160 161 struct bhnd_service_registry services; /**< local service registry */ 162 163 struct mtx sc_mtx; /**< resource lock. */ 164 struct bhndb_resources *bus_res; /**< bus resource state */ 165 }; 166 167 #endif /* _BHND_BHNDBVAR_H_ */ 168