1#- 2# Copyright (c) 2015 Landon Fuller <landon@landonf.org> 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions 7# are met: 8# 1. Redistributions of source code must retain the above copyright 9# notice, this list of conditions and the following disclaimer. 10# 2. Redistributions in binary form must reproduce the above copyright 11# notice, this list of conditions and the following disclaimer in the 12# documentation and/or other materials provided with the distribution. 13# 14# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17# IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 18# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 23# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24# 25# $FreeBSD$ 26 27#include <sys/param.h> 28#include <sys/bus.h> 29 30#include <machine/bus.h> 31#include <sys/rman.h> 32#include <machine/resource.h> 33 34#include <dev/bhnd/bhnd.h> 35 36# 37# bhndb bridge device interface. 38# 39 40INTERFACE bhndb; 41 42HEADER { 43 struct bhndb_regwin; 44 struct bhndb_hw; 45 struct bhndb_hw_priority; 46} 47 48CODE { 49 #include <sys/systm.h> 50 #include <dev/bhnd/bhndb/bhndbvar.h> 51 52 static const struct bhnd_chipid * 53 bhndb_null_get_chipid(device_t dev, device_t child) 54 { 55 panic("bhndb_get_chipid unimplemented"); 56 } 57 58 static int 59 bhndb_null_init_full_config(device_t dev, device_t child, 60 const struct bhndb_hw_priority *priority_table) 61 { 62 panic("bhndb_init_full_config unimplemented"); 63 } 64 65 static void 66 bhndb_null_suspend_resource(device_t dev, device_t child, int type, 67 struct resource *r) 68 { 69 panic("bhndb_suspend_resource unimplemented"); 70 } 71 72 static int 73 bhndb_null_resume_resource(device_t dev, device_t child, int type, 74 struct resource *r) 75 { 76 panic("bhndb_resume_resource unimplemented"); 77 } 78 79 static int 80 bhndb_null_set_window_addr(device_t dev, 81 const struct bhndb_regwin *rw, bhnd_addr_t addr) 82 { 83 panic("bhndb_set_window_addr unimplemented"); 84 } 85} 86 87/** 88 * Return the chip identification information for @p child. 89 * 90 * @param dev The parent device of @p child. 91 * @param child The bhndb-attached device. 92 */ 93METHOD const struct bhnd_chipid * get_chipid { 94 device_t dev; 95 device_t child; 96} DEFAULT bhndb_null_get_chipid; 97 98/** 99 * Perform final bridge hardware configuration after @p child has fully 100 * enumerated its children. 101 * 102 * This must be called by any bhndb-attached bus device; this allows the 103 * bridge to perform final configuration based on the hardware information 104 * enumerated by the child bus. 105 * 106 * When calling this method: 107 * - Any bus resources previously allocated by @p child must be deallocated. 108 * - The @p child bus must have performed initial enumeration -- but not 109 * probe or attachment -- of its children. 110 * 111 * @param dev The bridge device. 112 * @param child The bhnd bus device attached to @p dev. 113 * @param hw_priority The hardware priority table to be used when determining 114 * the bridge resource allocation strategy. 115 */ 116METHOD int init_full_config { 117 device_t dev; 118 device_t child; 119 const struct bhndb_hw_priority *priority_table; 120} DEFAULT bhndb_null_init_full_config; 121 122/** 123 * Mark a resource as 'suspended', gauranteeing to the bridge that no 124 * further use of the resource will be made until BHNDB_RESUME_RESOURCE() 125 * is called. 126 * 127 * Bridge resources consumed by the reference may be released; these will 128 * be reacquired if BHNDB_RESUME_RESOURCE() completes successfully. 129 * 130 * Requests to suspend a suspended resource will be ignored. 131 * 132 * @param dev The bridge device. 133 * @param child The child device requesting resource suspension. This does 134 * not need to be the owner of @p r. 135 * @param type The resource type. 136 * @param r The resource to be suspended. 137 */ 138METHOD void suspend_resource { 139 device_t dev; 140 device_t child; 141 int type; 142 struct resource *r; 143} DEFAULT bhndb_null_suspend_resource; 144 145/** 146 * Attempt to re-enable a resource previously suspended by 147 * BHNDB_SUSPEND_RESOURCE(). 148 * 149 * Bridge resources required by the reference may not be available, in which 150 * case an error will be returned and the resource mapped by @p r must not be 151 * used in any capacity. 152 * 153 * Requests to resume a non-suspended resource will be ignored. 154 * 155 * @param dev The bridge device. 156 * @param child The child device requesting resource suspension. This does 157 * not need to be the owner of @p r. 158 * @param type The resource type. 159 * @param r The resource to be suspended. 160 */ 161METHOD int resume_resource { 162 device_t dev; 163 device_t child; 164 int type; 165 struct resource *r; 166} DEFAULT bhndb_null_resume_resource; 167 168/** 169 * Set a given register window's base address. 170 * 171 * @param dev The bridge device. 172 * @param win The register window. 173 * @param addr The address to be configured for @p win. 174 * 175 * @retval 0 success 176 * @retval ENODEV The provided @p win is not memory-mapped on the bus or does 177 * not support setting a base address. 178 * @retval non-zero failure 179 */ 180METHOD int set_window_addr { 181 device_t dev; 182 const struct bhndb_regwin *win; 183 bhnd_addr_t addr; 184} DEFAULT bhndb_null_set_window_addr; 185