1/*- 2 * Copyright (c) 2016 Michael Zhilin <mizhka@gmail.com>
| 1/*- 2 * Copyright (c) 2016 Michael Zhilin <mizhka@gmail.com>
|
| 3 * Copyright (c) 2015-2016 Landon Fuller <landon@freebsd.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 * without modification. 11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 13 * redistribution must be conditioned upon including a substantially 14 * similar Disclaimer requirement for further binary redistribution. 15 * 16 * NO WARRANTY 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 * THE POSSIBILITY OF SUCH DAMAGES.
| 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. 12 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 13 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 14 * redistribution must be conditioned upon including a substantially 15 * similar Disclaimer requirement for further binary redistribution. 16 * 17 * NO WARRANTY 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 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 $
|
28 */ 29 30#include <sys/cdefs.h>
| 31 */ 32 33#include <sys/cdefs.h>
|
31__FBSDID("$FreeBSD: head/sys/dev/bhnd/bcma/bcma_nexus.c 300252 2016-05-20 01:02:58Z adrian $");
| 34__FBSDID("$FreeBSD: head/sys/dev/bhnd/bcma/bcma_nexus.c 301410 2016-06-04 19:53:47Z landonf $");
|
32 33#include <sys/param.h> 34#include <sys/kernel.h> 35#include <sys/bus.h> 36#include <sys/module.h>
| 35 36#include <sys/param.h> 37#include <sys/kernel.h> 38#include <sys/bus.h> 39#include <sys/module.h>
|
37#include <sys/errno.h>
| |
38 39#include <machine/bus.h>
| 40 41#include <machine/bus.h>
|
| 42#include <sys/rman.h>
|
40#include <machine/resource.h> 41
| 43#include <machine/resource.h> 44
|
42#include
| 45#include <dev/bhnd/bhnd_ids.h> 46#include <dev/bhnd/bhnd_nexusvar.h> 47#include <dev/bhnd/cores/chipc/chipcreg.h>
|
43
| 48
|
44#include "bhnd_bus_if.h"
| |
45#include "bcmavar.h" 46#include "bcma_eromreg.h" 47
| 49#include "bcmavar.h" 50#include "bcma_eromreg.h" 51
|
48#define BCMA_NEXUS_EROM_RID 10
| 52/* 53 * Supports bcma(4) attachment to a nexus bus. 54 */
|
49
| 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
|
50static int 51bcma_nexus_probe(device_t dev) 52{
| 64static int 65bcma_nexus_probe(device_t dev) 66{
|
53 const struct bhnd_chipid *cid = BHND_BUS_GET_CHIPID(device_get_parent(dev), dev);
| 67 struct bcma_nexus_softc *sc; 68 int error;
|
54
| 69
|
55 /* Check bus type */ 56 if (cid->chip_type != BHND_CHIPTYPE_BCMA)
| 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)
|
57 return (ENXIO); 58
| 78 return (ENXIO); 79
|
59 /* Delegate to default probe implementation */ 60 return (bcma_probe(dev));
| 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);
|
61} 62 63static int 64bcma_nexus_attach(device_t dev) 65{
| 86} 87 88static int 89bcma_nexus_attach(device_t dev) 90{
|
66 int erom_rid; 67 int error; 68 struct resource *erom_res; 69 const struct bhnd_chipid *cid = BHND_BUS_GET_CHIPID(device_get_parent(dev), dev);
| 91 struct bcma_nexus_softc *sc; 92 struct resource *erom_res; 93 int error; 94 int rid;
|
70
| 95
|
71 erom_rid = BCMA_NEXUS_EROM_RID; 72 error = bus_set_resource(dev, SYS_RES_MEMORY, erom_rid, cid->enum_addr, BCMA_EROM_TABLE_SIZE); 73 if (error != 0) { 74 BHND_ERROR_DEV(dev, "failed to set EROM resource"); 75 return (error); 76 }
| 96 sc = device_get_softc(dev);
|
77
| 97
|
78 /* Map the EROM resource and enumerate our children. */ 79 BHND_DEBUG_DEV(dev, "erom enum address: %jx", cid->enum_addr); 80 erom_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &erom_rid, RF_ACTIVE); 81 if (erom_res == NULL) { 82 BHND_ERROR_DEV(dev, "failed to allocate EROM resource"); 83 return (ENXIO); 84 }
| 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 }
|
85
| 108
|
86 BHND_DEBUG_DEV(dev, "erom scanning start address: %p", rman_get_virtual(erom_res)); 87 error = bcma_add_children(dev, erom_res, BCMA_EROM_TABLE_START);
| 109 error = bcma_add_children(dev, erom_res, BCMA_EROM_TABLE_START); 110 bus_release_resource(dev, SYS_RES_MEMORY, rid, erom_res);
|
88
| 111
|
89 /* Clean up */ 90 bus_release_resource(dev, SYS_RES_MEMORY, erom_rid, erom_res); 91 if (error) 92 return (error);
| 112 if (error) 113 return (error);
|
93
| 114
|
94 /* Call our superclass' implementation */ 95 return (bcma_attach(dev));
| 115 return (bcma_attach(dev));
|
96} 97
| 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
|
98static device_method_t bcma_nexus_methods[] = { 99 /* Device interface */ 100 DEVMETHOD(device_probe, bcma_nexus_probe), 101 DEVMETHOD(device_attach, bcma_nexus_attach),
| 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
|
102 DEVMETHOD_END 103}; 104
| 132 DEVMETHOD_END 133}; 134
|
105DEFINE_CLASS_1(bhnd, bcma_nexus_driver, bcma_nexus_methods, sizeof(struct bcma_softc), bcma_driver); 106EARLY_DRIVER_MODULE(bcma_nexus, bhnd_soc, bcma_nexus_driver, bhnd_devclass, 107 NULL, NULL, BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);
| 135DEFINE_CLASS_2(bhnd, bcma_nexus_driver, bcma_nexus_methods, 136 sizeof(struct bcma_nexus_softc), bhnd_nexus_driver, bcma_driver);
|
108
| 137
|
109MODULE_VERSION(bcma_nexus, 1); 110MODULE_DEPEND(bcma_nexus, bcma, 1, 1, 1); 111MODULE_DEPEND(bcma_nexus, bhnd_soc, 1, 1, 1);
| 138DRIVER_MODULE(bcma_nexus, nexus, bcma_nexus_driver, bhnd_devclass, 0, 0);
|
| |