1/*- 2 * Copyright (c) 2016 Michael Zhilin <mizhka@gmail.com> |
3 * Copyright (c) 2015-2016 Landon Fuller <landon@freebsd.org> |
4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer, 11 * without modification. --- 9 unchanged lines hidden (view full) --- 21 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 23 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 26 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 * THE POSSIBILITY OF SUCH DAMAGES. |
29 * 30 * $FreeBSD: head/sys/dev/bhnd/bcma/bcma_nexus.c 301410 2016-06-04 19:53:47Z landonf $ |
31 */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/sys/dev/bhnd/bcma/bcma_nexus.c 301410 2016-06-04 19:53:47Z landonf $"); |
35 36#include <sys/param.h> 37#include <sys/kernel.h> 38#include <sys/bus.h> 39#include <sys/module.h> |
40 41#include <machine/bus.h> |
42#include <sys/rman.h> |
43#include <machine/resource.h> 44 |
45#include <dev/bhnd/bhnd_ids.h> 46#include <dev/bhnd/bhnd_nexusvar.h> 47#include <dev/bhnd/cores/chipc/chipcreg.h> |
48 |
49#include "bcmavar.h" 50#include "bcma_eromreg.h" 51 |
52/* 53 * Supports bcma(4) attachment to a nexus bus. 54 */ |
55 |
56static int bcma_nexus_attach(device_t); 57static int bcma_nexus_probe(device_t); 58 59struct bcma_nexus_softc { 60 struct bcma_softc parent_sc; 61 struct bhnd_chipid bcma_cid; 62}; 63 |
64static int 65bcma_nexus_probe(device_t dev) 66{ |
67 struct bcma_nexus_softc *sc; 68 int error; |
69 |
70 sc = device_get_softc(dev); 71 72 /* Read the ChipCommon info using the hints the kernel 73 * was compiled with. */ 74 if ((error = bhnd_nexus_read_chipid(dev, &sc->bcma_cid))) 75 return (error); 76 77 if (sc->bcma_cid.chip_type != BHND_CHIPTYPE_BCMA) |
78 return (ENXIO); 79 |
80 if ((error = bcma_probe(dev)) > 0) { 81 device_printf(dev, "error %d in probe\n", error); 82 return (error); 83 } 84 85 return (0); |
86} 87 88static int 89bcma_nexus_attach(device_t dev) 90{ |
91 struct bcma_nexus_softc *sc; 92 struct resource *erom_res; 93 int error; 94 int rid; |
95 |
96 sc = device_get_softc(dev); |
97 |
98 /* Map the EROM resource and enumerate the bus. */ 99 rid = 0; 100 erom_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 101 sc->bcma_cid.enum_addr, 102 sc->bcma_cid.enum_addr + BCMA_EROM_TABLE_SIZE, 103 BCMA_EROM_TABLE_SIZE, RF_ACTIVE); 104 if (erom_res == NULL) { 105 device_printf(dev, "failed to allocate EROM resource\n"); 106 return (ENXIO); 107 } |
108 |
109 error = bcma_add_children(dev, erom_res, BCMA_EROM_TABLE_START); 110 bus_release_resource(dev, SYS_RES_MEMORY, rid, erom_res); |
111 |
112 if (error) 113 return (error); |
114 |
115 return (bcma_attach(dev)); |
116} 117 |
118static const struct bhnd_chipid * 119bcma_nexus_get_chipid(device_t dev, device_t child) { 120 struct bcma_nexus_softc *sc = device_get_softc(dev); 121 return (&sc->bcma_cid); 122} 123 |
124static device_method_t bcma_nexus_methods[] = { 125 /* Device interface */ 126 DEVMETHOD(device_probe, bcma_nexus_probe), 127 DEVMETHOD(device_attach, bcma_nexus_attach), |
128 129 /* bhnd interface */ 130 DEVMETHOD(bhnd_bus_get_chipid, bcma_nexus_get_chipid), 131 |
132 DEVMETHOD_END 133}; 134 |
135DEFINE_CLASS_2(bhnd, bcma_nexus_driver, bcma_nexus_methods, 136 sizeof(struct bcma_nexus_softc), bhnd_nexus_driver, bcma_driver); |
137 |
138DRIVER_MODULE(bcma_nexus, nexus, bcma_nexus_driver, bhnd_devclass, 0, 0); |