siba_bhndb.c revision 298479
1132718Skan/*- 2169689Skan * Copyright (c) 2015 Landon Fuller <landon@landonf.org> 3169689Skan * All rights reserved. 4132718Skan * 5132718Skan * Redistribution and use in source and binary forms, with or without 6132718Skan * modification, are permitted provided that the following conditions 7132718Skan * are met: 8132718Skan * 1. Redistributions of source code must retain the above copyright 9132718Skan * notice, this list of conditions and the following disclaimer, 10132718Skan * without modification. 11132718Skan * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12132718Skan * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 13132718Skan * redistribution must be conditioned upon including a substantially 14132718Skan * similar Disclaimer requirement for further binary redistribution. 15132718Skan * 16132718Skan * NO WARRANTY 17132718Skan * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18132718Skan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19132718Skan * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 20132718Skan * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21169689Skan * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 22169689Skan * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23132718Skan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24132718Skan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25132718Skan * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26132718Skan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27132718Skan * THE POSSIBILITY OF SUCH DAMAGES. 28132718Skan */ 29132718Skan 30132718Skan#include <sys/cdefs.h> 31132718Skan__FBSDID("$FreeBSD: head/sys/dev/bhnd/siba/siba_bhndb.c 298479 2016-04-22 16:26:53Z adrian $"); 32132718Skan 33132718Skan#include <sys/param.h> 34132718Skan#include <sys/kernel.h> 35132718Skan#include <sys/bus.h> 36132718Skan#include <sys/module.h> 37132718Skan 38132718Skan#include <dev/bhnd/bhnd_ids.h> 39132718Skan#include <dev/bhnd/bhndb/bhndbvar.h> 40132718Skan#include <dev/bhnd/bhndb/bhndb_hwdata.h> 41132718Skan 42132718Skan#include "sibavar.h" 43132718Skan 44132718Skan/* 45132718Skan * Supports attachment of siba(4) bus devices via a bhndb bridge. 46132718Skan */ 47132718Skan 48132718Skan// 49132718Skan// TODO: PCI rev < 6 interrupt handling 50132718Skan// 51132718Skan// On early PCI cores (rev < 6) interrupt masking is handled via interconnect 52132718Skan// configuration registers (SBINTVEC), rather than the PCI_INT_MASK 53132718Skan// config register. 54132718Skan// 55132718Skan// On those devices, we should handle interrupts locally using SBINTVEC, rather 56132718Skan// than delegating to our parent bhndb device. 57132718Skan// 58132718Skan 59132718Skanstatic int 60132718Skansiba_bhndb_probe(device_t dev) 61132718Skan{ 62132718Skan const struct bhnd_chipid *cid; 63132718Skan 64132718Skan /* Check bus type */ 65132718Skan cid = BHNDB_GET_CHIPID(device_get_parent(dev), dev); 66132718Skan if (cid->chip_type != BHND_CHIPTYPE_SIBA) 67132718Skan return (ENXIO); 68132718Skan 69132718Skan /* Delegate to default probe implementation */ 70132718Skan return (siba_probe(dev)); 71132718Skan} 72132718Skan 73132718Skanstatic int 74132718Skansiba_bhndb_attach(device_t dev) 75132718Skan{ 76132718Skan const struct bhnd_chipid *chipid; 77169689Skan int error; 78132718Skan 79132718Skan /* Enumerate our children. */ 80132718Skan chipid = BHNDB_GET_CHIPID(device_get_parent(dev), dev); 81132718Skan if ((error = siba_add_children(dev, chipid))) 82132718Skan return (error); 83132718Skan 84132718Skan /* Initialize full bridge configuration */ 85132718Skan error = BHNDB_INIT_FULL_CONFIG(device_get_parent(dev), dev, 86132718Skan bhndb_siba_priority_table); 87132718Skan if (error) 88132718Skan return (error); 89132718Skan 90132718Skan /* Call our superclass' implementation */ 91132718Skan return (siba_attach(dev)); 92132718Skan} 93132718Skan 94132718Skan/* Suspend all references to the device's cfg register blocks */ 95132718Skanstatic void 96132718Skansiba_bhndb_suspend_cfgblocks(device_t dev, struct siba_devinfo *dinfo) { 97132718Skan for (u_int i = 0; i < dinfo->core_id.num_cfg_blocks; i++) { 98132718Skan if (dinfo->cfg[i] == NULL) 99132718Skan continue; 100132718Skan 101132718Skan BHNDB_SUSPEND_RESOURCE(device_get_parent(dev), dev, 102132718Skan SYS_RES_MEMORY, dinfo->cfg[i]->res); 103132718Skan } 104132718Skan} 105132718Skan 106132718Skanstatic int 107132718Skansiba_bhndb_suspend_child(device_t dev, device_t child) 108132718Skan{ 109132718Skan struct siba_devinfo *dinfo; 110132718Skan int error; 111132718Skan 112132718Skan if (device_get_parent(child) != dev) 113132718Skan BUS_SUSPEND_CHILD(device_get_parent(dev), child); 114132718Skan 115132718Skan dinfo = device_get_ivars(child); 116132718Skan 117132718Skan /* Suspend the child */ 118132718Skan if ((error = bhnd_generic_br_suspend_child(dev, child))) 119132718Skan return (error); 120132718Skan 121132718Skan /* Suspend resource references to the child's config registers */ 122132718Skan siba_bhndb_suspend_cfgblocks(dev, dinfo); 123132718Skan 124132718Skan return (0); 125132718Skan} 126132718Skan 127132718Skanstatic int 128132718Skansiba_bhndb_resume_child(device_t dev, device_t child) 129132718Skan{ 130132718Skan struct siba_devinfo *dinfo; 131132718Skan int error; 132132718Skan 133132718Skan if (device_get_parent(child) != dev) 134132718Skan BUS_SUSPEND_CHILD(device_get_parent(dev), child); 135132718Skan 136132718Skan if (!device_is_suspended(child)) 137132718Skan return (EBUSY); 138132718Skan 139132718Skan dinfo = device_get_ivars(child); 140132718Skan 141132718Skan /* Resume all resource references to the child's config registers */ 142132718Skan for (u_int i = 0; i < dinfo->core_id.num_cfg_blocks; i++) { 143132718Skan if (dinfo->cfg[i] == NULL) 144132718Skan continue; 145132718Skan 146132718Skan error = BHNDB_RESUME_RESOURCE(device_get_parent(dev), dev, 147132718Skan SYS_RES_MEMORY, dinfo->cfg[i]->res); 148132718Skan if (error) { 149132718Skan siba_bhndb_suspend_cfgblocks(dev, dinfo); 150132718Skan return (error); 151132718Skan } 152132718Skan } 153132718Skan 154132718Skan /* Resume the child */ 155132718Skan if ((error = bhnd_generic_br_resume_child(dev, child))) { 156132718Skan siba_bhndb_suspend_cfgblocks(dev, dinfo); 157132718Skan return (error); 158132718Skan } 159132718Skan 160132718Skan return (0); 161132718Skan} 162132718Skan 163132718Skanstatic device_method_t siba_bhndb_methods[] = { 164132718Skan /* Device interface */ 165132718Skan DEVMETHOD(device_probe, siba_bhndb_probe), 166132718Skan DEVMETHOD(device_attach, siba_bhndb_attach), 167132718Skan 168132718Skan /* Bus interface */ 169132718Skan DEVMETHOD(bus_suspend_child, siba_bhndb_suspend_child), 170132718Skan DEVMETHOD(bus_resume_child, siba_bhndb_resume_child), 171132718Skan 172132718Skan DEVMETHOD_END 173132718Skan}; 174132718Skan 175132718SkanDEFINE_CLASS_1(bhnd, siba_bhndb_driver, siba_bhndb_methods, 176132718Skan sizeof(struct siba_softc), siba_driver); 177132718Skan 178132718SkanDRIVER_MODULE(siba_bhndb, bhndb, siba_bhndb_driver, bhnd_devclass, NULL, NULL); 179132718Skan 180132718SkanMODULE_VERSION(siba_bhndb, 1); 181132718SkanMODULE_DEPEND(siba_bhndb, siba, 1, 1, 1); 182132718SkanMODULE_DEPEND(siba_bhndb, bhndb, 1, 1, 1);