Date: Sat, 4 Jun 2016 19:53:48 +0000 (UTC) From: "Landon J. Fuller" <landonf@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r301410 - in head/sys: conf dev/bhnd dev/bhnd/bcma dev/bhnd/siba dev/bhnd/soc dev/siba mips/broadcom mips/conf Message-ID: <201606041953.u54JrmWA016305@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: landonf Date: Sat Jun 4 19:53:47 2016 New Revision: 301410 URL: https://svnweb.freebsd.org/changeset/base/301410 Log: Switch mips/sentry5 to bhnd(4), and unify with mips/broadcom Now that bhnd(4) provides feature parity with the previous siba/mips implementation, we can switch sentry5 over and begin lifting common support code out for use across bhnd(4) embedded targets. Changes: - Fixed enumeration of siba(4) per-core address maps, required for discovery of memory mapped chipc flash region on siba(4) devices. - Simplified bhnd kernel configuration (dropped 'bhndbus' option). - Replaced files.broadcom's direct file references with their corresponding standard kernel options. - Lifted out common bcma/siba nexus support, inheriting from the new generic bhnd_nexus driver. - Dropped now-unused sentry5 siba code. - Re-integrated BCM into the universe build now that it actually compiles. Approved by: adrian (mentor) Differential Revision: https://reviews.freebsd.org/D6712 Added: head/sys/dev/bhnd/bhnd_nexus.c (contents, props changed) head/sys/dev/bhnd/bhnd_nexusvar.h - copied, changed from r301409, head/sys/dev/bhnd/soc/bhnd_soc.h Deleted: head/sys/dev/bhnd/soc/bhnd_soc.c head/sys/dev/bhnd/soc/bhnd_soc.h head/sys/dev/siba/siba_cc.c head/sys/dev/siba/siba_mips.c head/sys/dev/siba/siba_pcib.c head/sys/dev/siba/siba_pcibvar.h Modified: head/sys/conf/files head/sys/dev/bhnd/bcma/bcma.c head/sys/dev/bhnd/bcma/bcma_nexus.c head/sys/dev/bhnd/siba/siba.c head/sys/dev/bhnd/siba/siba_nexus.c head/sys/dev/bhnd/siba/siba_subr.c head/sys/mips/broadcom/files.broadcom head/sys/mips/conf/BCM head/sys/mips/conf/BCM.hints head/sys/mips/conf/SENTRY5 head/sys/mips/conf/SENTRY5.hints Modified: head/sys/conf/files ============================================================================== --- head/sys/conf/files Sat Jun 4 19:39:05 2016 (r301409) +++ head/sys/conf/files Sat Jun 4 19:53:47 2016 (r301410) @@ -9,12 +9,12 @@ acpi_quirks.h optional acpi \ compile-with "${AWK} -f $S/tools/acpi_quirks2h.awk $S/dev/acpica/acpi_quirks" \ no-obj no-implicit-rule before-depend \ clean "acpi_quirks.h" -bhnd_nvram_map.h optional bhndbus | bhnd \ +bhnd_nvram_map.h optional bhnd \ dependency "$S/dev/bhnd/tools/nvram_map_gen.sh $S/dev/bhnd/tools/nvram_map_gen.awk $S/dev/bhnd/nvram/nvram_map" \ compile-with "sh $S/dev/bhnd/tools/nvram_map_gen.sh $S/dev/bhnd/nvram/nvram_map -h" \ no-obj no-implicit-rule before-depend \ clean "bhnd_nvram_map.h" -bhnd_nvram_map_data.h optional bhndbus | bhnd \ +bhnd_nvram_map_data.h optional bhnd \ dependency "$S/dev/bhnd/tools/nvram_map_gen.sh $S/dev/bhnd/tools/nvram_map_gen.awk $S/dev/bhnd/nvram/nvram_map" \ compile-with "sh $S/dev/bhnd/tools/nvram_map_gen.sh $S/dev/bhnd/nvram/nvram_map -d" \ no-obj no-implicit-rule before-depend \ @@ -1127,40 +1127,46 @@ dev/ath/ath_dfs/null/dfs_null.c optional dev/bce/if_bce.c optional bce dev/bfe/if_bfe.c optional bfe dev/bge/if_bge.c optional bge -dev/bhnd/bhnd.c optional bhndbus | bhnd -dev/bhnd/bhnd_subr.c optional bhndbus | bhnd -dev/bhnd/bhnd_bus_if.m optional bhndbus | bhnd -dev/bhnd/bhndb/bhnd_bhndb.c optional bhndbus | bhndb -dev/bhnd/bhndb/bhndb.c optional bhndbus | bhndb -dev/bhnd/bhndb/bhndb_bus_if.m optional bhndbus | bhndb -dev/bhnd/bhndb/bhndb_hwdata.c optional bhndbus | bhndb -dev/bhnd/bhndb/bhndb_if.m optional bhndbus | bhndb -dev/bhnd/bhndb/bhndb_pci.c optional bhndbus pci | bhndb pci -dev/bhnd/bhndb/bhndb_pci_hwdata.c optional bhndbus pci | bhndb pci -dev/bhnd/bhndb/bhndb_pci_sprom.c optional bhndbus pci | bhndb pci -dev/bhnd/bhndb/bhndb_subr.c optional bhndbus pci | bhndb -dev/bhnd/bcma/bcma.c optional bhndbus | bcma -dev/bhnd/bcma/bcma_bhndb.c optional bhndbus | bcma bhndb -dev/bhnd/bcma/bcma_erom.c optional bhndbus | bcma -dev/bhnd/bcma/bcma_subr.c optional bhndbus | bcma -dev/bhnd/cores/chipc/chipc.c optional bhndbus | bhnd -dev/bhnd/cores/chipc/chipc_subr.c optional bhndbus | bhnd -dev/bhnd/cores/chipc/bhnd_chipc_if.m optional bhndbus | bhnd -dev/bhnd/cores/chipc/bhnd_sprom_chipc.c optional bhndbus | bhnd -dev/bhnd/cores/pci/bhnd_pci.c optional bhndbus pci | bhnd pci -dev/bhnd/cores/pci/bhnd_pci_hostb.c optional bhndbus pci | bhndb pci +dev/bhnd/bhnd.c 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 +dev/bhnd/bhndb/bhndb.c optional bhndb bhnd +dev/bhnd/bhndb/bhndb_bus_if.m optional bhndb bhnd +dev/bhnd/bhndb/bhndb_hwdata.c optional bhndb bhnd +dev/bhnd/bhndb/bhndb_if.m optional bhndb bhnd +dev/bhnd/bhndb/bhndb_pci.c optional bhndb bhnd pci +dev/bhnd/bhndb/bhndb_pci_hwdata.c optional bhndb bhnd pci +dev/bhnd/bhndb/bhndb_pci_sprom.c optional bhndb bhnd pci +dev/bhnd/bhndb/bhndb_subr.c optional bhndb bhnd +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/chipc.c optional bhnd +dev/bhnd/cores/chipc/chipc_cfi.c optional bhnd cfi +dev/bhnd/cores/chipc/chipc_slicer.c optional bhnd cfi | bhnd spibus +dev/bhnd/cores/chipc/chipc_spi.c optional bhnd spibus +dev/bhnd/cores/chipc/chipc_subr.c optional bhnd +dev/bhnd/cores/chipc/bhnd_chipc_if.m optional bhnd +dev/bhnd/cores/chipc/bhnd_sprom_chipc.c optional bhnd +dev/bhnd/cores/pci/bhnd_pci.c optional bhnd pci +dev/bhnd/cores/pci/bhnd_pci_hostb.c optional bhndb bhnd pci dev/bhnd/cores/pci/bhnd_pcib.c optional bhnd_pcib bhnd pci -dev/bhnd/cores/pcie2/bhnd_pcie2.c optional bhndbus pci | bhnd pci -dev/bhnd/cores/pcie2/bhnd_pcie2_hostb.c optional bhndbus pci | bhndb pci +dev/bhnd/cores/pcie2/bhnd_pcie2.c optional bhnd pci +dev/bhnd/cores/pcie2/bhnd_pcie2_hostb.c optional bhndb bhnd pci dev/bhnd/cores/pcie2/bhnd_pcie2b.c optional bhnd_pcie2b bhnd pci -dev/bhnd/nvram/bhnd_nvram_if.m optional bhndbus | bhnd -dev/bhnd/nvram/bhnd_sprom.c optional bhndbus | bhnd -dev/bhnd/nvram/bhnd_sprom_subr.c optional bhndbus | bhnd -dev/bhnd/nvram/nvram_subr.c optional bhndbus | bhnd -dev/bhnd/siba/siba.c optional bhndbus | siba -dev/bhnd/siba/siba_bhndb.c optional bhndbus | siba bhndb -dev/bhnd/siba/siba_nexus.c optional siba_nexus siba -dev/bhnd/siba/siba_subr.c optional bhndbus | siba +dev/bhnd/nvram/bhnd_nvram_if.m optional bhnd +dev/bhnd/nvram/bhnd_sprom.c optional bhnd +dev/bhnd/nvram/bhnd_sprom_subr.c optional bhnd +dev/bhnd/nvram/nvram_subr.c optional bhnd +dev/bhnd/siba/siba.c optional siba bhnd +dev/bhnd/siba/siba_bhndb.c optional siba bhnd bhndb +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 dev/bktr/bktr_card.c optional bktr pci @@ -1182,7 +1188,7 @@ dev/bwi/if_bwi_pci.c optional bwi pci # XXX Work around clang warning, until maintainer approves fix. dev/bwn/if_bwn.c optional bwn siba_bwn \ compile-with "${NORMAL_C} ${NO_WSOMETIMES_UNINITIALIZED}" -dev/bwn/if_bwn_pci.c optional bwn pci bhnd | bwn pci bhndbus +dev/bwn/if_bwn_pci.c optional bwn pci bhnd dev/bwn/if_bwn_phy_common.c optional bwn siba_bwn dev/bwn/if_bwn_phy_g.c optional bwn siba_bwn \ compile-with "${NORMAL_C} ${NO_WSOMETIMES_UNINITIALIZED}" @@ -1190,7 +1196,7 @@ dev/bwn/if_bwn_phy_lp.c optional bwn si compile-with "${NORMAL_C} ${NO_WSOMETIMES_UNINITIALIZED}" dev/bwn/if_bwn_phy_n.c optional bwn siba_bwn dev/bwn/if_bwn_util.c optional bwn siba_bwn -dev/bwn/bwn_mac.c optional bwn bhnd | bwn bhndbus +dev/bwn/bwn_mac.c optional bwn bhnd dev/cardbus/cardbus.c optional cardbus dev/cardbus/cardbus_cis.c optional cardbus dev/cardbus/cardbus_device.c optional cardbus @@ -2490,10 +2496,7 @@ dev/si/si_eisa.c optional si eisa dev/si/si_isa.c optional si isa dev/si/si_pci.c optional si pci dev/siba/siba_bwn.c optional siba_bwn pci -dev/siba/siba_cc.c optional siba_s5 !bhnd !bhndbus -dev/siba/siba_core.c optional siba_s5 | siba_bwn pci -dev/siba/siba_mips.c optional siba_s5 !bhnd !bhndbus -dev/siba/siba_pcib.c optional siba_s5 pci !bhnd !bhndbus +dev/siba/siba_core.c optional siba_bwn pci dev/siis/siis.c optional siis pci dev/sis/if_sis.c optional sis pci dev/sk/if_sk.c optional sk pci Modified: head/sys/dev/bhnd/bcma/bcma.c ============================================================================== --- head/sys/dev/bhnd/bcma/bcma.c Sat Jun 4 19:39:05 2016 (r301409) +++ head/sys/dev/bhnd/bcma/bcma.c Sat Jun 4 19:53:47 2016 (r301410) @@ -98,8 +98,9 @@ bcma_attach(device_t dev) r_end = r_start + r_count - 1; dinfo->rid_agent = i + 1; - dinfo->res_agent = bhnd_alloc_resource(dev, SYS_RES_MEMORY, - &dinfo->rid_agent, r_start, r_end, r_count, RF_ACTIVE); + dinfo->res_agent = BHND_BUS_ALLOC_RESOURCE(dev, dev, + SYS_RES_MEMORY, &dinfo->rid_agent, r_start, r_end, r_count, + RF_ACTIVE); if (dinfo->res_agent == NULL) { device_printf(dev, "failed allocating agent register " "block for core %d\n", i); Modified: head/sys/dev/bhnd/bcma/bcma_nexus.c ============================================================================== --- head/sys/dev/bhnd/bcma/bcma_nexus.c Sat Jun 4 19:39:05 2016 (r301409) +++ head/sys/dev/bhnd/bcma/bcma_nexus.c Sat Jun 4 19:53:47 2016 (r301410) @@ -1,5 +1,6 @@ /*- * Copyright (c) 2016 Michael Zhilin <mizhka@gmail.com> + * Copyright (c) 2015-2016 Landon Fuller <landon@freebsd.org> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,6 +26,8 @@ * 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 <sys/cdefs.h> @@ -34,78 +37,102 @@ __FBSDID("$FreeBSD$"); #include <sys/kernel.h> #include <sys/bus.h> #include <sys/module.h> -#include <sys/errno.h> #include <machine/bus.h> +#include <sys/rman.h> #include <machine/resource.h> -#include <dev/bhnd/bhnd.h> +#include <dev/bhnd/bhnd_ids.h> +#include <dev/bhnd/bhnd_nexusvar.h> +#include <dev/bhnd/cores/chipc/chipcreg.h> -#include "bhnd_bus_if.h" #include "bcmavar.h" #include "bcma_eromreg.h" -#define BCMA_NEXUS_EROM_RID 10 +/* + * 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) { - const struct bhnd_chipid *cid = BHND_BUS_GET_CHIPID(device_get_parent(dev), dev); + struct bcma_nexus_softc *sc; + int error; - /* Check bus type */ - if (cid->chip_type != BHND_CHIPTYPE_BCMA) + 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); - /* Delegate to default probe implementation */ - return (bcma_probe(dev)); + if ((error = bcma_probe(dev)) > 0) { + device_printf(dev, "error %d in probe\n", error); + return (error); + } + + return (0); } static int bcma_nexus_attach(device_t dev) { - int erom_rid; - int error; - struct resource *erom_res; - const struct bhnd_chipid *cid = BHND_BUS_GET_CHIPID(device_get_parent(dev), dev); - - erom_rid = BCMA_NEXUS_EROM_RID; - error = bus_set_resource(dev, SYS_RES_MEMORY, erom_rid, cid->enum_addr, BCMA_EROM_TABLE_SIZE); - if (error != 0) { - BHND_ERROR_DEV(dev, "failed to set EROM resource"); - return (error); - } - - /* Map the EROM resource and enumerate our children. */ - BHND_DEBUG_DEV(dev, "erom enum address: %jx", cid->enum_addr); - erom_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &erom_rid, RF_ACTIVE); - if (erom_res == NULL) { - BHND_ERROR_DEV(dev, "failed to allocate EROM resource"); - return (ENXIO); - } - - BHND_DEBUG_DEV(dev, "erom scanning start address: %p", rman_get_virtual(erom_res)); - error = bcma_add_children(dev, erom_res, BCMA_EROM_TABLE_START); - - /* Clean up */ - bus_release_resource(dev, SYS_RES_MEMORY, erom_rid, erom_res); - if (error) - return (error); + struct bcma_nexus_softc *sc; + struct resource *erom_res; + int error; + int rid; + + sc = device_get_softc(dev); + + /* Map the EROM resource and enumerate the bus. */ + rid = 0; + erom_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, + sc->bcma_cid.enum_addr, + sc->bcma_cid.enum_addr + BCMA_EROM_TABLE_SIZE, + BCMA_EROM_TABLE_SIZE, RF_ACTIVE); + if (erom_res == NULL) { + device_printf(dev, "failed to allocate EROM resource\n"); + return (ENXIO); + } - /* Call our superclass' implementation */ - return (bcma_attach(dev)); + error = bcma_add_children(dev, erom_res, BCMA_EROM_TABLE_START); + bus_release_resource(dev, SYS_RES_MEMORY, rid, erom_res); + + if (error) + return (error); + + return (bcma_attach(dev)); +} + +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_1(bhnd, bcma_nexus_driver, bcma_nexus_methods, sizeof(struct bcma_softc), bcma_driver); -EARLY_DRIVER_MODULE(bcma_nexus, bhnd_soc, bcma_nexus_driver, bhnd_devclass, - NULL, NULL, BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE); - -MODULE_VERSION(bcma_nexus, 1); -MODULE_DEPEND(bcma_nexus, bcma, 1, 1, 1); -MODULE_DEPEND(bcma_nexus, bhnd_soc, 1, 1, 1); +DEFINE_CLASS_2(bhnd, bcma_nexus_driver, bcma_nexus_methods, + sizeof(struct bcma_nexus_softc), bhnd_nexus_driver, bcma_driver); + +DRIVER_MODULE(bcma_nexus, nexus, bcma_nexus_driver, bhnd_devclass, 0, 0); Added: head/sys/dev/bhnd/bhnd_nexus.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/bhnd/bhnd_nexus.c Sat Jun 4 19:53:47 2016 (r301410) @@ -0,0 +1,120 @@ +/*- + * Copyright (c) 2015-2016 Landon Fuller <landon@freebsd.org> + * 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + + +/* + * bhnd(4) driver mix-in providing shared common methods for + * bhnd bus devices attached via a root nexus. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/bus.h> +#include <sys/kernel.h> +#include <sys/module.h> +#include <sys/rman.h> +#include <sys/malloc.h> + +#include <machine/bus.h> + +#include <dev/bhnd/bhnd_ids.h> +#include <dev/bhnd/cores/chipc/chipcreg.h> + +#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 device_method_t bhnd_nexus_methods[] = { + /* bhnd interface */ + DEVMETHOD(bhnd_bus_activate_resource, bhnd_nexus_activate_resource), + DEVMETHOD(bhnd_bus_is_hw_disabled, bhnd_nexus_is_hw_disabled), + DEVMETHOD(bhnd_bus_get_attach_type, bhnd_nexus_get_attach_type), + + DEVMETHOD_END +}; + +DEFINE_CLASS_0(bhnd, bhnd_nexus_driver, bhnd_nexus_methods, + sizeof(struct bhnd_softc)); Copied and modified: head/sys/dev/bhnd/bhnd_nexusvar.h (from r301409, head/sys/dev/bhnd/soc/bhnd_soc.h) ============================================================================== --- head/sys/dev/bhnd/soc/bhnd_soc.h Sat Jun 4 19:39:05 2016 (r301409, copy source) +++ head/sys/dev/bhnd/bhnd_nexusvar.h Sat Jun 4 19:53:47 2016 (r301410) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2016 Michael Zhilin <mizhka@gmail.com> + * Copyright (c) 2016 Landon Fuller <landon@freebsd.org> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,27 +25,22 @@ * 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_SOC_BHND_SOC_H_ -#define _BHND_SOC_BHND_SOC_H_ -#define BHND_SOC_MAXNUM_CORES 0x20 -#define BHND_SOC_RAM_OFFSET 0x0 -#define BHND_SOC_RAM_SIZE 0x20000000 - -struct bhnd_soc_softc { - device_t dev; - device_t bridge; - device_t bus; - struct bhnd_chipid chipid; /* chip identification */ -}; - -struct bhnd_soc_devinfo { - struct resource_list resources; -}; +#ifndef _BHND_BHND_NEXUSVAR_H_ +#define _BHND_BHND_NEXUSVAR_H_ + +#include <sys/param.h> +#include <sys/kernel.h> +#include <sys/bus.h> +#include <sys/module.h> + +#include "bhndvar.h" + +DECLARE_CLASS(bhnd_nexus_driver); + +int bhnd_nexus_read_chipid(device_t dev, struct bhnd_chipid *chipid); -#endif /* _BHND_SOC_BHND_SOC_H_ */ +#endif /* _BHND_BHND_NEXUSVAR_H_ */ Modified: head/sys/dev/bhnd/siba/siba.c ============================================================================== --- head/sys/dev/bhnd/siba/siba.c Sat Jun 4 19:39:05 2016 (r301409) +++ head/sys/dev/bhnd/siba/siba.c Sat Jun 4 19:53:47 2016 (r301410) @@ -114,7 +114,7 @@ siba_attach(device_t dev) /* Allocate the config resource */ dinfo->cfg_rid[cfgidx] = 0; - dinfo->cfg[cfgidx] = bhnd_alloc_resource(dev, + dinfo->cfg[cfgidx] = BHND_BUS_ALLOC_RESOURCE(dev, dev, SYS_RES_MEMORY, &dinfo->cfg_rid[cfgidx], r_start, r_end, r_count, RF_ACTIVE); @@ -458,10 +458,6 @@ siba_register_addrspaces(device_t dev, s /* Fetch the address match register value */ adm = bus_read_4(r, adm_offset); - /* Skip disabled entries */ - if (adm & SIBA_AM_ADEN) - continue; - /* Parse the value */ if ((error = siba_parse_admatch(adm, &addr, &size))) { device_printf(dev, "failed to decode address " @@ -551,7 +547,7 @@ siba_add_children(device_t dev, const st ccid = bhnd_parse_chipid(ccreg, SIBA_ENUM_ADDR); if (!CHIPC_NCORES_MIN_HWREV(ccrev)) { - switch (device) { + switch (ccid.chip_id) { case BHND_CHIPID_BCM4306: ccid.ncores = 6; break; Modified: head/sys/dev/bhnd/siba/siba_nexus.c ============================================================================== --- head/sys/dev/bhnd/siba/siba_nexus.c Sat Jun 4 19:39:05 2016 (r301409) +++ head/sys/dev/bhnd/siba/siba_nexus.c Sat Jun 4 19:53:47 2016 (r301410) @@ -1,4 +1,5 @@ /*- + * Copyright (c) 2015-2016 Landon Fuller <landon@freebsd.org> * Copyright (c) 2007 Bruce M. Simpson. * All rights reserved. * @@ -28,217 +29,50 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> -#include <sys/systm.h> -#include <sys/bus.h> #include <sys/kernel.h> +#include <sys/bus.h> #include <sys/module.h> -#include <sys/rman.h> -#include <sys/malloc.h> #include <machine/bus.h> +#include <sys/rman.h> +#include <machine/resource.h> #include <dev/bhnd/bhnd_ids.h> -#include <dev/bhnd/cores/bhnd_chipcreg.h> +#include <dev/bhnd/bhnd_nexusvar.h> +#include <dev/bhnd/cores/chipc/chipcreg.h> -#include "sibareg.h" #include "sibavar.h" /* * Supports siba(4) attachment to a MIPS nexus bus. * - * This driver is a direct port of Bruce M. Simpson' original siba(4) to the - * bhnd(4) bus infrastructure. + * Derived from Bruce M. Simpson' original siba(4) driver. */ -/* - * TODO: De-mipsify this code. - * TODO: cpu clock calculation. -> move to siba_cc instance - * TODO: Hardwire IRQs for attached cores on siba at probe time. - * TODO: Support detach. - * TODO: Power management. - * TODO: code cleanup. - * TODO: Support deployments of siba other than as a system bus. - */ - -#ifndef MIPS_MEM_RID -#define MIPS_MEM_RID 0x20 -#endif - -extern int rman_debug; - -static struct rman mem_rman; /* XXX move to softc */ - -static int siba_debug = 1; -static const char descfmt[] = "Sonics SiliconBackplane rev %s"; -#define SIBA_DEVDESCLEN sizeof(descfmt) + 8 - -static int siba_nexus_activate_resource(device_t, device_t, int, int, - struct resource *); -static struct resource * - siba_nexus_alloc_resource(device_t, device_t, int, int *, - rman_res_t, rman_res_t, rman_res_t, u_int); -static int siba_nexus_attach(device_t); -#ifdef notyet -static uint8_t siba_nexus_getirq(uint16_t); -#endif -static int siba_nexus_probe(device_t); - struct siba_nexus_softc { struct siba_softc parent_sc; - - device_t siba_dev; /* Device ID */ struct bhnd_chipid siba_cid; - struct resource *siba_mem_res; - bus_space_tag_t siba_mem_bt; - bus_space_handle_t siba_mem_bh; - bus_addr_t siba_maddr; - bus_size_t siba_msize; }; -// TODO - depends on bhnd(4) IRQ support -#ifdef notyet -/* - * On the Sentry5, the system bus IRQs are the same as the - * MIPS IRQs. Particular cores are hardwired to certain IRQ lines. - */ -static uint8_t -siba_nexus_getirq(uint16_t devid) -{ - uint8_t irq; - - switch (devid) { - case BHND_COREID_CC: - irq = 0; - break; - case BHND_COREID_ENET: - irq = 1; - break; - case BHND_COREID_IPSEC: - irq = 2; - break; - case BHND_COREID_USB: - irq = 3; - break; - case BHND_COREID_PCI: - irq = 4; - break; -#if 0 - /* - * 5 is reserved for the MIPS on-chip timer interrupt; - * it is hard-wired by the tick driver. - */ - case BHND_COREID_MIPS: - case BHND_COREID_MIPS33: - irq = 5; - break; -#endif - default: - irq = 0xFF; /* this core does not need an irq */ - break; - } - - return (irq); -} -#endif - static int siba_nexus_probe(device_t dev) { - struct siba_nexus_softc *sc = device_get_softc(dev); - struct bhnd_core_info cc; - uint32_t idhi, idlo; - int error, rid; - - sc->siba_dev = dev; - - //rman_debug = 1; /* XXX */ - - /* - * Read the ChipCommon info using the hints the kernel - * was compiled with. - */ - rid = MIPS_MEM_RID; - sc->siba_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, - RF_ACTIVE); - if (sc->siba_mem_res == NULL) { - device_printf(dev, "unable to allocate probe aperture\n"); - return (ENXIO); - } - sc->siba_mem_bt = rman_get_bustag(sc->siba_mem_res); - sc->siba_mem_bh = rman_get_bushandle(sc->siba_mem_res); - sc->siba_maddr = rman_get_start(sc->siba_mem_res); - sc->siba_msize = rman_get_size(sc->siba_mem_res); - - if (siba_debug) { - device_printf(dev, "start %08x len %08x\n", - sc->siba_maddr, sc->siba_msize); - } - - idlo = bus_read_4(sc->siba_mem_res, SIBA_IDLOW); - idhi = bus_read_4(sc->siba_mem_res, SIBA_IDHIGH); - cc = siba_parse_core_info(idhi, 0, 0); - - if (siba_debug) { - device_printf(dev, "idhi = %08x\n", idhi); - device_printf(dev, " chipcore id = %08x\n", cc.device); - } + struct siba_nexus_softc *sc; + int error; - /* - * For now, check that the first core is the ChipCommon core. - */ - if (bhnd_core_class(&cc) != BHND_DEVCLASS_CC) { - if (siba_debug) - device_printf(dev, "first core is not ChipCommon\n"); - return (ENXIO); - } - - /* - * Determine backplane revision and set description string. - */ - uint32_t rev; - char *revp; - char descbuf[SIBA_DEVDESCLEN]; - - rev = SIBA_REG_GET(idlo, IDL_SBREV); - revp = "unknown"; - if (rev == SIBA_IDL_SBREV_2_2) - revp = "2.2"; - else if (rev == SIBA_IDL_SBREV_2_3) - revp = "2.3"; - - (void)snprintf(descbuf, sizeof(descbuf), descfmt, revp); - device_set_desc_copy(dev, descbuf); - - /* - * Determine how many cores are present on this siba bus, so - * that we may map them all. - */ - uint32_t ccidreg; - - ccidreg = bus_read_4(sc->siba_mem_res, CHIPC_ID); - sc->siba_cid = bhnd_parse_chipid(ccidreg, sc->siba_maddr); - if (siba_debug) { - device_printf(dev, "ccid = %08x, cc_id = %04x, cc_rev = %04x\n", - ccidreg, sc->siba_cid.chip_id, sc->siba_cid.chip_rev); - } + sc = device_get_softc(dev); - if (sc->siba_cid.ncores == 0) - sc->siba_cid.ncores = siba_get_ncores(&sc->siba_cid); - - if (siba_debug) { - device_printf(dev, "%d cores detected.\n", sc->siba_cid.ncores); - } + /* Read the ChipCommon info using the hints the kernel + * was compiled with. */ + if ((error = bhnd_nexus_read_chipid(dev, &sc->siba_cid))) + return (error); - /* - * Now we know how many cores are on this siba, release the - * mapping and allocate a new mapping spanning all cores on the bus. - */ - rid = MIPS_MEM_RID; - error = bus_release_resource(dev, SYS_RES_MEMORY, rid, - sc->siba_mem_res); - if (error != 0) { - device_printf(dev, "error %d releasing resource\n", 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); } return (0); @@ -247,52 +81,15 @@ siba_nexus_probe(device_t dev) static int siba_nexus_attach(device_t dev) { - struct siba_nexus_softc *sc = device_get_softc(dev); - uint32_t total; - int error, rid; + struct siba_nexus_softc *sc; + int error; - if (siba_debug) - printf("%s: entry\n", __func__); + sc = device_get_softc(dev); /* Enumerate the bus. */ - if ((error = siba_add_children(dev, &sc->siba_cid))) + if ((error = siba_add_children(dev, NULL))) { + device_printf(dev, "error %d enumerating children\n", error); return (error); - - /* Allocate full core aperture */ - total = sc->siba_cid.ncores; - sc->siba_mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, - sc->siba_maddr, sc->siba_maddr + total - 1, total, RF_ACTIVE); - if (sc->siba_mem_res == NULL) { - device_printf(dev, "unable to allocate entire aperture\n"); - return (ENXIO); - } - sc->siba_mem_bt = rman_get_bustag(sc->siba_mem_res); - sc->siba_mem_bh = rman_get_bushandle(sc->siba_mem_res); - sc->siba_maddr = rman_get_start(sc->siba_mem_res); - sc->siba_msize = rman_get_size(sc->siba_mem_res); - - if (siba_debug) { - device_printf(dev, "after remapping: start %08x len %08x\n", - sc->siba_maddr, sc->siba_msize); - } - bus_set_resource(dev, SYS_RES_MEMORY, rid, sc->siba_maddr, - sc->siba_msize); - - /* - * We need a manager for the space we claim on nexus to - * satisfy requests from children. - * We need to keep the source reservation we took because - * otherwise it may be claimed elsewhere. - * XXX move to softc - */ - mem_rman.rm_start = sc->siba_maddr; - mem_rman.rm_end = sc->siba_maddr + sc->siba_msize - 1; - mem_rman.rm_type = RMAN_ARRAY; - mem_rman.rm_descr = "SiBa I/O memory addresses"; - if (rman_init(&mem_rman) != 0 || - rman_manage_region(&mem_rman, mem_rman.rm_start, - mem_rman.rm_end) != 0) { - panic("%s: mem_rman", __func__); } return (siba_attach(dev)); @@ -304,150 +101,18 @@ siba_nexus_get_chipid(device_t dev, devi return (&sc->siba_cid); } -static struct resource * -siba_nexus_alloc_resource(device_t bus, device_t child, int type, int *rid, - rman_res_t start, rman_res_t end, rman_res_t count, u_int flags) -{ - struct resource *rv; - struct resource_list *rl; - struct resource_list_entry *rle; - int isdefault, needactivate; - -#if 0 - if (siba_debug) - printf("%s: entry\n", __func__); -#endif - - isdefault = (start == 0UL && end == ~0UL && count == 1); - needactivate = flags & RF_ACTIVE; - rl = BUS_GET_RESOURCE_LIST(bus, child); - rle = NULL; - - if (isdefault) { - rle = resource_list_find(rl, type, *rid); - if (rle == NULL) - return (NULL); - if (rle->res != NULL) - panic("%s: resource entry is busy", __func__); - start = rle->start; - end = rle->end; - count = rle->count; - } - - /* - * If the request is for a resource which we manage, - * attempt to satisfy the allocation ourselves. - */ - if (type == SYS_RES_MEMORY && - start >= mem_rman.rm_start && end <= mem_rman.rm_end) { - - rv = rman_reserve_resource(&mem_rman, start, end, count, - flags, child); - if (rv == 0) { - printf("%s: could not reserve resource\n", __func__); - return (0); - } - - rman_set_rid(rv, *rid); - - if (needactivate) { - if (bus_activate_resource(child, type, *rid, rv)) { - printf("%s: could not activate resource\n", - __func__); - rman_release_resource(rv); - return (0); - } - } - - return (rv); - } - - /* - * Pass the request to the parent, usually MIPS nexus. - */ - if (siba_debug) - printf("%s: proxying request to parent\n", __func__); - return (resource_list_alloc(rl, bus, child, type, rid, - start, end, count, flags)); -} - -/* - * The parent bus is responsible for resource activation; in the - * case of MIPS, this boils down to setting the virtual address and - * bus handle by mapping the physical address into KSEG1. - */ -static int -siba_nexus_activate_resource(device_t bus, device_t child, int type, int rid, - struct resource *r) -{ - return (BUS_ACTIVATE_RESOURCE(device_get_parent(bus), child, type, - rid, r)); -} - -// TODO - depends on bhnd(4) IRQ support -#ifdef notyet -static struct siba_devinfo * -siba_nexus_setup_devinfo(device_t dev, uint8_t idx) -{ - struct siba_nexus_softc *sc = device_get_softc(dev); - struct siba_devinfo *sdi; - uint32_t idlo, idhi, rev; - uint16_t vendorid, devid; - bus_addr_t baseaddr; - - sdi = malloc(sizeof(*sdi), M_DEVBUF, M_WAITOK | M_ZERO); - resource_list_init(&sdi->sdi_rl); - - idlo = siba_mips_read_4(sc, idx, SIBA_IDLOW); - idhi = siba_mips_read_4(sc, idx, SIBA_IDHIGH); - - vendorid = (idhi & SIBA_IDHIGH_VENDORMASK) >> - SIBA_IDHIGH_VENDOR_SHIFT; - devid = ((idhi & 0x8ff0) >> 4); - rev = (idhi & SIBA_IDHIGH_REVLO); - rev |= (idhi & SIBA_IDHIGH_REVHI) >> SIBA_IDHIGH_REVHI_SHIFT; - - sdi->sdi_vid = vendorid; - sdi->sdi_devid = devid; - sdi->sdi_rev = rev; - sdi->sdi_idx = idx; - sdi->sdi_irq = siba_getirq(devid); - - /* - * Determine memory window on bus and irq if one is needed. - */ - baseaddr = sc->siba_maddr + (idx * SIBA_CORE_SIZE); - resource_list_add(&sdi->sdi_rl, SYS_RES_MEMORY, - MIPS_MEM_RID, /* XXX */ - baseaddr, baseaddr + SIBA_CORE_LEN - 1, SIBA_CORE_LEN); - - if (sdi->sdi_irq != 0xff) { - resource_list_add(&sdi->sdi_rl, SYS_RES_IRQ, - 0, sdi->sdi_irq, sdi->sdi_irq, 1); - } - - return (sdi); -} -#endif - static device_method_t siba_nexus_methods[] = { /* Device interface */ - DEVMETHOD(device_attach, siba_nexus_attach), - DEVMETHOD(device_probe, siba_nexus_probe), - - /* Bus interface */ - DEVMETHOD(bus_activate_resource,siba_nexus_activate_resource), - DEVMETHOD(bus_alloc_resource, siba_nexus_alloc_resource), - DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), - DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), + DEVMETHOD(device_probe, siba_nexus_probe), + DEVMETHOD(device_attach, siba_nexus_attach), /* bhnd interface */ - DEVMETHOD(bhnd_get_chipid, siba_nexus_get_chipid), + DEVMETHOD(bhnd_bus_get_chipid, siba_nexus_get_chipid), DEVMETHOD_END }; -DEFINE_CLASS_1(bhnd, siba_nexus_driver, siba_nexus_methods, - sizeof(struct siba_nexus_softc), siba_driver); +DEFINE_CLASS_2(bhnd, siba_nexus_driver, siba_nexus_methods, + sizeof(struct siba_nexus_softc), bhnd_nexus_driver, siba_driver); -DRIVER_MODULE(siba_nexus, nexus, siba_driver, bhnd_devclass, 0, 0); +DRIVER_MODULE(siba_nexus, nexus, siba_nexus_driver, bhnd_devclass, 0, 0); Modified: head/sys/dev/bhnd/siba/siba_subr.c ============================================================================== --- head/sys/dev/bhnd/siba/siba_subr.c Sat Jun 4 19:39:05 2016 (r301409) +++ head/sys/dev/bhnd/siba/siba_subr.c Sat Jun 4 19:53:47 2016 (r301410) @@ -244,9 +244,9 @@ siba_append_dinfo_region(struct siba_dev struct siba_addrspace *sa; struct siba_port *port; rman_res_t r_size; - + /* Verify that base + size will not overflow */ - if (UINT32_MAX - size < base) + if (size > 0 && UINT32_MAX - (size - 1) < base) return (ERANGE); /* Verify that size - bus_reserved will not underflow */ @@ -276,7 +276,7 @@ siba_append_dinfo_region(struct siba_dev /* Populate the resource list */ r_size = size - bus_reserved; sa->sa_rid = resource_list_add_next(&dinfo->resources, SYS_RES_MEMORY, - base, base + r_size - 1, r_size); + base, base + (r_size - 1), r_size); /* Append to target port */ STAILQ_INSERT_TAIL(&port->sp_addrs, sa, sa_link); Modified: head/sys/mips/broadcom/files.broadcom ============================================================================== --- head/sys/mips/broadcom/files.broadcom Sat Jun 4 19:39:05 2016 (r301409) +++ head/sys/mips/broadcom/files.broadcom Sat Jun 4 19:53:47 2016 (r301410) @@ -17,31 +17,5 @@ mips/broadcom/uart_bus_chipc.c optional mips/broadcom/bcm_socinfo.c standard mips/broadcom/bcm_mipscore.c standard *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201606041953.u54JrmWA016305>