Index: head/sys/conf/files =================================================================== --- head/sys/conf/files +++ head/sys/conf/files @@ -1190,8 +1190,6 @@ dev/bhnd/bhnd.c optional bhnd dev/bhnd/bhnd_erom.c optional bhnd dev/bhnd/bhnd_erom_if.m optional bhnd -dev/bhnd/bhnd_nexus.c optional bhnd siba_nexus | \ - bhnd bcma_nexus dev/bhnd/bhnd_subr.c optional bhnd dev/bhnd/bhnd_bus_if.m optional bhnd dev/bhnd/bhndb/bhnd_bhndb.c optional bhndb bhnd @@ -1206,7 +1204,6 @@ dev/bhnd/bcma/bcma.c optional bcma bhnd dev/bhnd/bcma/bcma_bhndb.c optional bcma bhnd bhndb dev/bhnd/bcma/bcma_erom.c optional bcma bhnd -dev/bhnd/bcma/bcma_nexus.c optional bcma_nexus bcma bhnd dev/bhnd/bcma/bcma_subr.c optional bcma bhnd dev/bhnd/cores/chipc/bhnd_chipc_if.m optional bhnd dev/bhnd/cores/chipc/bhnd_sprom_chipc.c optional bhnd @@ -1252,7 +1249,6 @@ dev/bhnd/siba/siba.c optional siba bhnd dev/bhnd/siba/siba_bhndb.c optional siba bhnd bhndb dev/bhnd/siba/siba_erom.c optional siba bhnd -dev/bhnd/siba/siba_nexus.c optional siba_nexus siba bhnd dev/bhnd/siba/siba_subr.c optional siba bhnd # dev/bktr/bktr_audio.c optional bktr pci Index: head/sys/dev/bhnd/bcma/bcma_nexus.c =================================================================== --- head/sys/dev/bhnd/bcma/bcma_nexus.c +++ head/sys/dev/bhnd/bcma/bcma_nexus.c @@ -1,132 +0,0 @@ -/*- - * Copyright (c) 2016 Michael Zhilin - * Copyright (c) 2015-2016 Landon Fuller - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer, - * without modification. - * 2. Redistributions in binary form must reproduce at minimum a disclaimer - * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any - * redistribution must be conditioned upon including a substantially - * similar Disclaimer requirement for further binary redistribution. - * - * NO WARRANTY - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, - * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER - * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGES. - * - * $FreeBSD$ - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include - -#include "bcmavar.h" -#include "bcma_eromreg.h" - -/* - * Supports bcma(4) attachment to a nexus bus. - */ - -static int bcma_nexus_attach(device_t); -static int bcma_nexus_probe(device_t); - -struct bcma_nexus_softc { - struct bcma_softc parent_sc; - struct bhnd_chipid bcma_cid; -}; - -static int -bcma_nexus_probe(device_t dev) -{ - struct bcma_nexus_softc *sc; - int error; - - sc = device_get_softc(dev); - - /* Read the ChipCommon info using the hints the kernel - * was compiled with. */ - if ((error = bhnd_nexus_read_chipid(dev, &sc->bcma_cid))) - return (error); - - if (sc->bcma_cid.chip_type != BHND_CHIPTYPE_BCMA) - return (ENXIO); - - if ((error = bcma_probe(dev)) > 0) { - device_printf(dev, "error %d in probe\n", error); - return (error); - } - - /* Set device description */ - bhnd_set_default_bus_desc(dev, &sc->bcma_cid); - - return (0); -} - -static int -bcma_nexus_attach(device_t dev) -{ - int error; - - /* Perform initial attach and enumerate our children. */ - if ((error = bcma_attach(dev))) - goto failed; - - /* Delegate remainder to standard bhnd method implementation */ - if ((error = bhnd_generic_attach(dev))) - goto failed; - - return (0); - -failed: - device_delete_children(dev); - return (error); -} - -static const struct bhnd_chipid * -bcma_nexus_get_chipid(device_t dev, device_t child) { - struct bcma_nexus_softc *sc = device_get_softc(dev); - return (&sc->bcma_cid); -} - -static device_method_t bcma_nexus_methods[] = { - /* Device interface */ - DEVMETHOD(device_probe, bcma_nexus_probe), - DEVMETHOD(device_attach, bcma_nexus_attach), - - /* bhnd interface */ - DEVMETHOD(bhnd_bus_get_chipid, bcma_nexus_get_chipid), - - DEVMETHOD_END -}; - -DEFINE_CLASS_2(bhnd, bcma_nexus_driver, bcma_nexus_methods, - sizeof(struct bcma_nexus_softc), bhnd_nexus_driver, bcma_driver); - -EARLY_DRIVER_MODULE(bcma_nexus, nexus, bcma_nexus_driver, bhnd_devclass, 0, 0, - BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE); Index: head/sys/dev/bhnd/bhnd_nexus.c =================================================================== --- head/sys/dev/bhnd/bhnd_nexus.c +++ head/sys/dev/bhnd/bhnd_nexus.c @@ -1,145 +0,0 @@ -/*- - * Copyright (c) 2015-2016 Landon Fuller - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer, - * without modification. - * 2. Redistributions in binary form must reproduce at minimum a disclaimer - * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any - * redistribution must be conditioned upon including a substantially - * similar Disclaimer requirement for further binary redistribution. - * - * NO WARRANTY - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, - * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER - * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGES. - * - * $FreeBSD$ - */ - -#include -__FBSDID("$FreeBSD$"); - - -/* - * bhnd(4) driver mix-in providing shared common methods for - * bhnd bus devices attached via a root nexus. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -#include "bhnd_nexusvar.h" - -static const struct resource_spec bhnd_nexus_res_spec[] = { - { SYS_RES_MEMORY, 0, RF_ACTIVE }, /* chipc registers */ - { -1, 0, 0 } -}; - -/** - * Map ChipCommon's register block and read the chip identifier data. - * - * @param dev A bhnd_nexus device. - * @param chipid On success, will be populated with the chip identifier. - * @retval 0 success - * @retval non-zero An error occurred reading the chip identifier.. - */ -int -bhnd_nexus_read_chipid(device_t dev, struct bhnd_chipid *chipid) -{ - struct resource_spec rspec[nitems(bhnd_nexus_res_spec)]; - int error; - - memcpy(rspec, bhnd_nexus_res_spec, sizeof(rspec)); - error = bhnd_read_chipid(dev, rspec, 0, chipid); - if (error) - device_printf(dev, "error %d reading chip ID\n", error); - - return (error); -} - -static bool -bhnd_nexus_is_hw_disabled(device_t dev, device_t child) -{ - return (false); -} - -static bhnd_attach_type -bhnd_nexus_get_attach_type(device_t dev, device_t child) -{ - return (BHND_ATTACH_NATIVE); -} - -static int -bhnd_nexus_activate_resource(device_t dev, device_t child, int type, int rid, - struct bhnd_resource *r) -{ - int error; - - /* Always direct */ - if ((error = bus_activate_resource(child, type, rid, r->res))) - return (error); - - r->direct = true; - return (0); -} - -static int -bhnd_nexus_deactivate_resource(device_t dev, device_t child, - int type, int rid, struct bhnd_resource *r) -{ - int error; - - /* Always direct */ - KASSERT(r->direct, ("indirect resource delegated to bhnd_nexus\n")); - - if ((error = bus_deactivate_resource(child, type, rid, r->res))) - return (error); - - r->direct = false; - return (0); -} - -static int -bhnd_nexus_get_intr_count(device_t dev, device_t child) -{ - // TODO: arch-specific interrupt handling. - return (0); -} - -static device_method_t bhnd_nexus_methods[] = { - /* bhnd interface */ - DEVMETHOD(bhnd_bus_activate_resource, bhnd_nexus_activate_resource), - DEVMETHOD(bhnd_bus_deactivate_resource, bhnd_nexus_deactivate_resource), - DEVMETHOD(bhnd_bus_is_hw_disabled, bhnd_nexus_is_hw_disabled), - DEVMETHOD(bhnd_bus_get_attach_type, bhnd_nexus_get_attach_type), - - DEVMETHOD(bhnd_bus_get_intr_count, bhnd_nexus_get_intr_count), - - DEVMETHOD_END -}; - -DEFINE_CLASS_0(bhnd, bhnd_nexus_driver, bhnd_nexus_methods, - sizeof(struct bhnd_softc)); Index: head/sys/dev/bhnd/bhnd_nexusvar.h =================================================================== --- head/sys/dev/bhnd/bhnd_nexusvar.h +++ head/sys/dev/bhnd/bhnd_nexusvar.h @@ -1,46 +0,0 @@ -/*- - * Copyright (c) 2016 Landon Fuller - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer, - * without modification. - * 2. Redistributions in binary form must reproduce at minimum a disclaimer - * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any - * redistribution must be conditioned upon including a substantially - * similar Disclaimer requirement for further binary redistribution. - * - * NO WARRANTY - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, - * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER - * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGES. - * - * $FreeBSD$ - */ - -#ifndef _BHND_BHND_NEXUSVAR_H_ -#define _BHND_BHND_NEXUSVAR_H_ - -#include -#include -#include -#include - -#include "bhndvar.h" - -DECLARE_CLASS(bhnd_nexus_driver); - -int bhnd_nexus_read_chipid(device_t dev, struct bhnd_chipid *chipid); - -#endif /* _BHND_BHND_NEXUSVAR_H_ */ Index: head/sys/dev/bhnd/siba/siba_nexus.c =================================================================== --- head/sys/dev/bhnd/siba/siba_nexus.c +++ head/sys/dev/bhnd/siba/siba_nexus.c @@ -1,125 +0,0 @@ -/*- - * Copyright (c) 2015-2016 Landon Fuller - * Copyright (c) 2007 Bruce M. Simpson. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include - -#include "sibavar.h" - -/* - * Supports siba(4) attachment to a MIPS nexus bus. - * - * Derived from Bruce M. Simpson' original siba(4) driver. - */ - -struct siba_nexus_softc { - struct siba_softc parent_sc; - struct bhnd_chipid siba_cid; -}; - -static int -siba_nexus_probe(device_t dev) -{ - struct siba_nexus_softc *sc; - int error; - - sc = device_get_softc(dev); - - /* Read the ChipCommon info using the hints the kernel - * was compiled with. */ - if ((error = bhnd_nexus_read_chipid(dev, &sc->siba_cid))) - return (error); - - if (sc->siba_cid.chip_type != BHND_CHIPTYPE_SIBA) - return (ENXIO); - - if ((error = siba_probe(dev)) > 0) { - device_printf(dev, "error %d in probe\n", error); - return (error); - } - - /* Set device description */ - bhnd_set_default_bus_desc(dev, &sc->siba_cid); - - return (0); -} - -static int -siba_nexus_attach(device_t dev) -{ - int error; - - /* Perform initial attach and enumerate our children. */ - if ((error = siba_attach(dev))) - goto failed; - - /* Delegate remainder to standard bhnd method implementation */ - if ((error = bhnd_generic_attach(dev))) - goto failed; - - return (0); - -failed: - device_delete_children(dev); - return (error); -} - -static const struct bhnd_chipid * -siba_nexus_get_chipid(device_t dev, device_t child) { - struct siba_nexus_softc *sc = device_get_softc(dev); - return (&sc->siba_cid); -} - -static device_method_t siba_nexus_methods[] = { - /* Device interface */ - DEVMETHOD(device_probe, siba_nexus_probe), - DEVMETHOD(device_attach, siba_nexus_attach), - - /* bhnd interface */ - DEVMETHOD(bhnd_bus_get_chipid, siba_nexus_get_chipid), - - DEVMETHOD_END -}; - -DEFINE_CLASS_2(bhnd, siba_nexus_driver, siba_nexus_methods, - sizeof(struct siba_nexus_softc), bhnd_nexus_driver, siba_driver); - -EARLY_DRIVER_MODULE(siba_nexus, nexus, siba_nexus_driver, bhnd_devclass, 0, 0, - BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE); Index: head/sys/mips/broadcom/bcma_nexus.c =================================================================== --- head/sys/mips/broadcom/bcma_nexus.c +++ head/sys/mips/broadcom/bcma_nexus.c @@ -0,0 +1,114 @@ +/*- + * Copyright (c) 2016 Michael Zhilin + * Copyright (c) 2015-2016 Landon Fuller + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any + * redistribution must be conditioned upon including a substantially + * similar Disclaimer requirement for further binary redistribution. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGES. + * + * $FreeBSD$ + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include + +#include "bcm_machdep.h" + +#include "bhnd_nexusvar.h" + +/* + * Supports bcma(4) attachment to a MIPS nexus bus. + */ + +static int bcma_nexus_attach(device_t); +static int bcma_nexus_probe(device_t); + +static int +bcma_nexus_probe(device_t dev) +{ + int error; + + switch (bcm_get_platform()->cid.chip_type) { + case BHND_CHIPTYPE_BCMA: + case BHND_CHIPTYPE_BCMA_ALT: + case BHND_CHIPTYPE_UBUS: + break; + default: + return (ENXIO); + } + + if ((error = bcma_probe(dev)) > 0) + return (error); + + /* Set device description */ + bhnd_set_default_bus_desc(dev, &bcm_get_platform()->cid); + + return (BUS_PROBE_SPECIFIC); +} + +static int +bcma_nexus_attach(device_t dev) +{ + int error; + + /* Perform initial attach and enumerate our children. */ + if ((error = bcma_attach(dev))) + goto failed; + + /* Delegate remainder to standard bhnd method implementation */ + if ((error = bhnd_generic_attach(dev))) + goto failed; + + return (0); + +failed: + device_delete_children(dev); + return (error); +} + +static device_method_t bcma_nexus_methods[] = { + DEVMETHOD(device_probe, bcma_nexus_probe), + DEVMETHOD(device_attach, bcma_nexus_attach), + + DEVMETHOD_END +}; + +DEFINE_CLASS_2(bhnd, bcma_nexus_driver, bcma_nexus_methods, + sizeof(struct bcma_softc), bhnd_nexus_driver, bcma_driver); + +EARLY_DRIVER_MODULE(bcma_nexus, nexus, bcma_nexus_driver, bhnd_devclass, 0, 0, + BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE); Index: head/sys/mips/broadcom/bhnd_nexus.c =================================================================== --- head/sys/mips/broadcom/bhnd_nexus.c +++ head/sys/mips/broadcom/bhnd_nexus.c @@ -0,0 +1,175 @@ +/*- + * Copyright (c) 2015-2016 Landon Fuller + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any + * redistribution must be conditioned upon including a substantially + * similar Disclaimer requirement for further binary redistribution. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGES. + * + * $FreeBSD$ + */ + +#include +__FBSDID("$FreeBSD$"); + +/* + * bhnd(4) driver mix-in providing shared common methods for + * bhnd bus devices attached via a MIPS root nexus. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include "bcm_machdep.h" + +#include "bhnd_nexusvar.h" + +/** + * Default bhnd_nexus implementation of BHND_BUS_ACTIVATE_RESOURCE(). + */ +static int +bhnd_nexus_activate_resource(device_t dev, device_t child, int type, int rid, + struct bhnd_resource *r) +{ + int error; + + /* Always direct */ + if ((error = bus_activate_resource(child, type, rid, r->res))) + return (error); + + r->direct = true; + return (0); +} + +/** + * Default bhnd_nexus implementation of BHND_BUS_DEACTIVATE_RESOURCE(). + */ +static int +bhnd_nexus_deactivate_resource(device_t dev, device_t child, + int type, int rid, struct bhnd_resource *r) +{ + int error; + + /* Always direct */ + KASSERT(r->direct, ("indirect resource delegated to bhnd_nexus\n")); + + if ((error = bus_deactivate_resource(child, type, rid, r->res))) + return (error); + + r->direct = false; + return (0); +} + +/** + * Default bhnd_nexus implementation of BHND_BUS_IS_HW_DISABLED(). + */ +static bool +bhnd_nexus_is_hw_disabled(device_t dev, device_t child) +{ + struct bcm_platform *bp; + struct bhnd_chipid *cid; + + bp = bcm_get_platform(); + cid = &bp->cid; + + /* The BCM4706 low-cost package leaves secondary GMAC cores + * floating */ + if (cid->chip_id == BHND_CHIPID_BCM4706 && + cid->chip_pkg == BHND_PKGID_BCM4706L && + bhnd_get_device(child) == BHND_COREID_4706_GMAC && + bhnd_get_core_unit(child) != 0) + { + return (true); + } + + return (false); +} + +/** + * Default bhnd_nexus implementation of BHND_BUS_AGET_ATTACH_TYPE(). + */ +static bhnd_attach_type +bhnd_nexus_get_attach_type(device_t dev, device_t child) +{ + return (BHND_ATTACH_NATIVE); +} + +/** + * Default bhnd_nexus implementation of BHND_BUS_GET_CHIPID(). + */ +static const struct bhnd_chipid * +bhnd_nexus_get_chipid(device_t dev, device_t child) +{ + return (&bcm_get_platform()->cid); +} + +/** + * Default bhnd_nexus implementation of BHND_BUS_GET_INTR_COUNT(). + */ +static int +bhnd_nexus_get_intr_count(device_t dev, device_t child) +{ + // TODO: arch-specific interrupt handling. + return (0); +} + +/** + * Default bhnd_nexus implementation of BHND_BUS_ASSIGN_INTR(). + */ +static int +bhnd_nexus_assign_intr(device_t dev, device_t child, int rid) +{ + uint32_t ivec; + int error; + + if ((error = bhnd_get_core_ivec(child, rid, &ivec))) + return (error); + + return (bus_set_resource(child, SYS_RES_IRQ, rid, ivec, 1)); +} + +static device_method_t bhnd_nexus_methods[] = { + /* bhnd interface */ + DEVMETHOD(bhnd_bus_activate_resource, bhnd_nexus_activate_resource), + DEVMETHOD(bhnd_bus_deactivate_resource, bhnd_nexus_deactivate_resource), + DEVMETHOD(bhnd_bus_is_hw_disabled, bhnd_nexus_is_hw_disabled), + DEVMETHOD(bhnd_bus_get_attach_type, bhnd_nexus_get_attach_type), + DEVMETHOD(bhnd_bus_get_chipid, bhnd_nexus_get_chipid), + DEVMETHOD(bhnd_bus_get_intr_count, bhnd_nexus_get_intr_count), + DEVMETHOD(bhnd_bus_assign_intr, bhnd_nexus_assign_intr), + + DEVMETHOD_END +}; + +DEFINE_CLASS_0(bhnd, bhnd_nexus_driver, bhnd_nexus_methods, + sizeof(struct bhnd_softc)); Index: head/sys/mips/broadcom/bhnd_nexusvar.h =================================================================== --- head/sys/mips/broadcom/bhnd_nexusvar.h +++ head/sys/mips/broadcom/bhnd_nexusvar.h @@ -0,0 +1,40 @@ +/*- + * Copyright (c) 2016 Landon Fuller + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any + * redistribution must be conditioned upon including a substantially + * similar Disclaimer requirement for further binary redistribution. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGES. + * + * $FreeBSD$ + */ + +#ifndef _MIPS_BROADCOM_BHND_NEXUSVAR_H_ +#define _MIPS_BROADCOM_BHND_NEXUSVAR_H_ + +#include +#include + +DECLARE_CLASS(bhnd_nexus_driver); + +#endif /* _MIPS_BROADCOM_BHND_NEXUSVAR_H_ */ Index: head/sys/mips/broadcom/files.broadcom =================================================================== --- head/sys/mips/broadcom/files.broadcom +++ head/sys/mips/broadcom/files.broadcom @@ -10,6 +10,12 @@ mips/broadcom/bcm_nvram_cfe.c optional bhnd siba_nexus cfe | \ bhnd bcma_nexus cfe mips/broadcom/bcm_pmu.c standard + +mips/broadcom/bhnd_nexus.c optional bhnd siba_nexus | \ + bhnd bcma_nexus +mips/broadcom/bcma_nexus.c optional bcma_nexus bcma bhnd +mips/broadcom/siba_nexus.c optional siba_nexus siba bhnd + mips/mips/tick.c standard mips/broadcom/uart_cpu_chipc.c optional uart Index: head/sys/mips/broadcom/siba_nexus.c =================================================================== --- head/sys/mips/broadcom/siba_nexus.c +++ head/sys/mips/broadcom/siba_nexus.c @@ -0,0 +1,103 @@ +/*- + * Copyright (c) 2015-2016 Landon Fuller + * Copyright (c) 2007 Bruce M. Simpson. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include + +#include "bcm_machdep.h" + +#include "bhnd_nexusvar.h" + +/* + * Supports siba(4) attachment to a MIPS nexus bus. + * + * Derived from Bruce M. Simpson' original siba(4) driver. + */ + +static int +siba_nexus_probe(device_t dev) +{ + int error; + + if (bcm_get_platform()->cid.chip_type != BHND_CHIPTYPE_SIBA) + return (ENXIO); + + if ((error = siba_probe(dev)) > 0) + return (error); + + /* Set device description */ + bhnd_set_default_bus_desc(dev, &bcm_get_platform()->cid); + + return (BUS_PROBE_SPECIFIC); +} + +static int +siba_nexus_attach(device_t dev) +{ + int error; + + /* Perform initial attach and enumerate our children. */ + if ((error = siba_attach(dev))) + goto failed; + + /* Delegate remainder to standard bhnd method implementation */ + if ((error = bhnd_generic_attach(dev))) + goto failed; + + return (0); + +failed: + device_delete_children(dev); + return (error); +} + +static device_method_t siba_nexus_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, siba_nexus_probe), + DEVMETHOD(device_attach, siba_nexus_attach), + + DEVMETHOD_END +}; + +DEFINE_CLASS_2(bhnd, siba_nexus_driver, siba_nexus_methods, + sizeof(struct siba_softc), bhnd_nexus_driver, siba_driver); + +EARLY_DRIVER_MODULE(siba_nexus, nexus, siba_nexus_driver, bhnd_devclass, 0, 0, + BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);