Index: head/sys/arm/arm/pl310.c =================================================================== --- head/sys/arm/arm/pl310.c +++ head/sys/arm/arm/pl310.c @@ -42,11 +42,18 @@ #include #include +#ifdef PLATFORM +#include +#endif #include #include #include +#ifdef PLATFORM +#include "platform_pl310_if.h" +#endif + /* * Define this if you need to disable PL310 for debugging purpose * Spec: @@ -88,6 +95,29 @@ {"arm,pl310-cache", true}, {NULL, false} }; + +#ifdef PLATFORM +static void +platform_pl310_init(struct pl310_softc *sc) +{ + + PLATFORM_PL310_INIT(platform_obj(), sc); +} + +static void +platform_pl310_write_ctrl(struct pl310_softc *sc, uint32_t val) +{ + + PLATFORM_PL310_WRITE_CTRL(platform_obj(), sc, val); +} + +static void +platform_pl310_write_debug(struct pl310_softc *sc, uint32_t val) +{ + + PLATFORM_PL310_WRITE_DEBUG(platform_obj(), sc, val); +} +#endif static void pl310_print_config(struct pl310_softc *sc) Index: head/sys/arm/arm/platform.c =================================================================== --- head/sys/arm/arm/platform.c +++ head/sys/arm/arm/platform.c @@ -77,6 +77,13 @@ static delay_func platform_delay; +platform_t +platform_obj(void) +{ + + return (plat_obj); +} + void platform_probe_and_attach(void) { Index: head/sys/arm/arm/platform_pl310_if.m =================================================================== --- head/sys/arm/arm/platform_pl310_if.m +++ head/sys/arm/arm/platform_pl310_if.m @@ -0,0 +1,84 @@ +#- +# Copyright (c) 2017 Andrew Turner +# 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. +# +# $FreeBSD$ +# + +#include +#include +#include +#include + +#include +#include +#include + +INTERFACE platform_pl310; + +HEADER { + struct pl310_softc; +}; + +CODE { + static void platform_pl310_default_write_ctrl(platform_t plat, + struct pl310_softc *sc, uint32_t val) + { + pl310_write4(sc, PL310_CTRL, val); + } + + static void platform_pl310_default_write_debug(platform_t plat, + struct pl310_softc *sc, uint32_t val) + { + pl310_write4(sc, PL310_DEBUG_CTRL, val); + } +}; + +/** + * Initialize the pl310, e.g. to configure the prefetch control. The following + * write functions may have already been called so they must not rely on + * this function. + */ +METHOD void init { + platform_t _plat; + struct pl310_softc *sc; +}; + +/** + * Write to the Control Register. + */ +METHOD void write_ctrl { + platform_t _plat; + struct pl310_softc *sc; + uint32_t val; +} DEFAULT platform_pl310_default_write_ctrl; + +/** + * Write to the Debug Control Register. + */ +METHOD void write_debug { + platform_t _plat; + struct pl310_softc *sc; + uint32_t val; +} DEFAULT platform_pl310_default_write_debug; Index: head/sys/arm/conf/GENERIC =================================================================== --- head/sys/arm/conf/GENERIC +++ head/sys/arm/conf/GENERIC @@ -116,6 +116,7 @@ device snp device md # Memory "disks" device random # Entropy device +device pl310 # PL310 L2 cache controller device psci # I2C support Index: head/sys/arm/freescale/imx/imx6_machdep.h =================================================================== --- head/sys/arm/freescale/imx/imx6_machdep.h +++ head/sys/arm/freescale/imx/imx6_machdep.h @@ -29,7 +29,10 @@ #ifndef IMX6_MACHDEP_H #define IMX6_MACHDEP_H +struct pl310_softc; + void imx6_mp_start_ap(platform_t); void imx6_mp_setmaxid(platform_t); +void imx6_pl310_init(platform_t, struct pl310_softc *); #endif /* IMX6_MACHDEP_H */ Index: head/sys/arm/freescale/imx/imx6_machdep.c =================================================================== --- head/sys/arm/freescale/imx/imx6_machdep.c +++ head/sys/arm/freescale/imx/imx6_machdep.c @@ -53,6 +53,7 @@ #include #include "platform_if.h" +#include "platform_pl310_if.h" static platform_attach_t imx6_attach; static platform_devmap_init_t imx6_devmap_init; @@ -320,6 +321,8 @@ PLATFORMMETHOD(platform_mp_start_ap, imx6_mp_start_ap), PLATFORMMETHOD(platform_mp_setmaxid, imx6_mp_setmaxid), #endif + + PLATFORMMETHOD(platform_pl310_init, imx6_pl310_init), PLATFORMMETHOD_END, }; Index: head/sys/arm/freescale/imx/imx6_pl310.c =================================================================== --- head/sys/arm/freescale/imx/imx6_pl310.c +++ head/sys/arm/freescale/imx/imx6_pl310.c @@ -40,9 +40,14 @@ #include #include +#include +#include + +#include "platform_pl310_if.h" + void -platform_pl310_init(struct pl310_softc *sc) +imx6_pl310_init(platform_t plat, struct pl310_softc *sc) { uint32_t reg; @@ -58,18 +63,3 @@ pl310_set_ram_latency(sc, PL310_TAG_RAM_CTRL, 4, 2, 3); pl310_set_ram_latency(sc, PL310_DATA_RAM_CTRL, 4, 2, 3); } - -void -platform_pl310_write_ctrl(struct pl310_softc *sc, uint32_t val) -{ - - pl310_write4(sc, PL310_CTRL, val); -} - -void -platform_pl310_write_debug(struct pl310_softc *sc, uint32_t val) -{ - - pl310_write4(sc, PL310_DEBUG_CTRL, val); -} - Index: head/sys/arm/include/pl310.h =================================================================== --- head/sys/arm/include/pl310.h +++ head/sys/arm/include/pl310.h @@ -181,8 +181,10 @@ void pl310_set_ram_latency(struct pl310_softc *sc, uint32_t which_reg, uint32_t read, uint32_t write, uint32_t setup); +#ifndef PLATFORM void platform_pl310_init(struct pl310_softc *); void platform_pl310_write_ctrl(struct pl310_softc *, uint32_t); void platform_pl310_write_debug(struct pl310_softc *, uint32_t); +#endif #endif /* PL310_H_ */ Index: head/sys/arm/include/platformvar.h =================================================================== --- head/sys/arm/include/platformvar.h +++ head/sys/arm/include/platformvar.h @@ -114,6 +114,11 @@ #endif +/* + * Helper to get the platform object + */ +platform_t platform_obj(void); + bool arm_tmr_timed_wait(platform_t, int); #endif /* _MACHINE_PLATFORMVAR_H_ */ Index: head/sys/arm/ti/omap4/omap4_l2cache.c =================================================================== --- head/sys/arm/ti/omap4/omap4_l2cache.c +++ head/sys/arm/ti/omap4/omap4_l2cache.c @@ -32,13 +32,18 @@ #include #include -#include -#include #include #include +#include +#include +#include +#include + +#include "platform_pl310_if.h" + void -platform_pl310_init(struct pl310_softc *sc) +omap4_pl310_init(platform_t plat, struct pl310_softc *sc) { uint32_t aux, prefetch; @@ -70,13 +75,15 @@ } void -platform_pl310_write_ctrl(struct pl310_softc *sc, uint32_t val) +omap4_pl310_write_ctrl(platform_t plat, struct pl310_softc *sc, uint32_t val) { + ti_smc0(val, 0, L2CACHE_WRITE_CTRL_REG); } void -platform_pl310_write_debug(struct pl310_softc *sc, uint32_t val) +omap4_pl310_write_debug(platform_t plat, struct pl310_softc *sc, uint32_t val) { + ti_smc0(val, 0, L2CACHE_WRITE_DEBUG_REG); } Index: head/sys/arm/ti/omap4/omap4_machdep.h =================================================================== --- head/sys/arm/ti/omap4/omap4_machdep.h +++ head/sys/arm/ti/omap4/omap4_machdep.h @@ -28,7 +28,13 @@ #ifndef _OMAP4_MACHDEP_H_ #define _OMAP4_MACHDEP_H_ +struct pl310_softc; + void omap4_mp_setmaxid(platform_t plat); void omap4_mp_start_ap(platform_t plat); + +void omap4_pl310_init(platform_t, struct pl310_softc *); +void omap4_pl310_write_ctrl(platform_t, struct pl310_softc *, uint32_t); +void omap4_pl310_write_debug(platform_t, struct pl310_softc *, uint32_t); #endif /* _OMAP4_MACHDEP_H_ */ Index: head/sys/arm/ti/ti_machdep.c =================================================================== --- head/sys/arm/ti/ti_machdep.c +++ head/sys/arm/ti/ti_machdep.c @@ -59,6 +59,8 @@ #include "platform_if.h" #if defined(SOC_OMAP4) +#include "platform_pl310_if.h" + static platform_attach_t omap4_attach; static platform_devmap_init_t ti_omap4_devmap_init; #endif @@ -139,6 +141,11 @@ PLATFORMMETHOD(platform_mp_start_ap, omap4_mp_start_ap), PLATFORMMETHOD(platform_mp_setmaxid, omap4_mp_setmaxid), #endif + + PLATFORMMETHOD(platform_pl310_init, omap4_pl310_init), + PLATFORMMETHOD(platform_pl310_write_ctrl, omap4_pl310_write_ctrl), + PLATFORMMETHOD(platform_pl310_write_debug, omap4_pl310_write_debug), + PLATFORMMETHOD_END, }; FDT_PLATFORM_DEF(omap4, "omap4", 0, "ti,omap4430", 200); Index: head/sys/arm/xilinx/zy7_l2cache.c =================================================================== --- head/sys/arm/xilinx/zy7_l2cache.c +++ head/sys/arm/xilinx/zy7_l2cache.c @@ -39,22 +39,13 @@ #include #include +#include -void -platform_pl310_init(struct pl310_softc *softc) -{ -} +#include -void -platform_pl310_write_ctrl(struct pl310_softc *sc, uint32_t val) -{ +#include "platform_pl310_if.h" - pl310_write4(sc, PL310_CTRL, val); -} - void -platform_pl310_write_debug(struct pl310_softc *sc, uint32_t val) +zynq7_pl310_init(platform_t plat, struct pl310_softc *softc) { - - pl310_write4(sc, PL310_DEBUG_CTRL, val); } Index: head/sys/arm/xilinx/zy7_machdep.h =================================================================== --- head/sys/arm/xilinx/zy7_machdep.h +++ head/sys/arm/xilinx/zy7_machdep.h @@ -28,7 +28,11 @@ #ifndef _ZY7_MACHDEP_H_ #define _ZY7_MACHDEP_H_ +struct pl310_softc; + void zynq7_mp_setmaxid(platform_t); void zynq7_mp_start_ap(platform_t); + +void zynq7_pl310_init(platform_t, struct pl310_softc *); #endif /* _ZY7_MACHDEP_H_ */ Index: head/sys/arm/xilinx/zy7_machdep.c =================================================================== --- head/sys/arm/xilinx/zy7_machdep.c +++ head/sys/arm/xilinx/zy7_machdep.c @@ -55,6 +55,7 @@ #include #include "platform_if.h" +#include "platform_pl310_if.h" void (*zynq7_cpu_reset)(void); @@ -92,6 +93,8 @@ PLATFORMMETHOD(platform_mp_setmaxid, zynq7_mp_setmaxid), PLATFORMMETHOD(platform_mp_start_ap, zynq7_mp_start_ap), #endif + + PLATFORMMETHOD(platform_pl310_init, zynq7_pl310_init), PLATFORMMETHOD_END, }; Index: head/sys/conf/files.arm =================================================================== --- head/sys/conf/files.arm +++ head/sys/conf/files.arm @@ -84,6 +84,7 @@ arm/arm/pl310.c optional pl310 arm/arm/platform.c optional platform arm/arm/platform_if.m optional platform +arm/arm/platform_pl310_if.m optional platform pl310 arm/arm/pmap-v4.c optional !armv6 arm/arm/pmap-v6.c optional armv6 arm/arm/pmu.c optional pmu | fdt hwpmc