Index: sys/arm/arm/pl310.c =================================================================== --- sys/arm/arm/pl310.c +++ 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: @@ -89,6 +96,29 @@ {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: sys/arm/arm/platform.c =================================================================== --- sys/arm/arm/platform.c +++ 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: sys/arm/arm/platform_pl310_if.m =================================================================== --- /dev/null +++ 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: sys/arm/conf/GENERIC =================================================================== --- sys/arm/conf/GENERIC +++ 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: sys/arm/freescale/imx/imx6_machdep.h =================================================================== --- sys/arm/freescale/imx/imx6_machdep.h +++ sys/arm/freescale/imx/imx6_machdep.h @@ -26,10 +26,13 @@ * $FreeBSD$ */ -#ifndef IMX6_MP_H -#define IMX6_MP_H +#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_MP_H */ +#endif /* IMX6_MACHDEP_H */ Index: sys/arm/freescale/imx/imx6_machdep.c =================================================================== --- sys/arm/freescale/imx/imx6_machdep.c +++ sys/arm/freescale/imx/imx6_machdep.c @@ -50,9 +50,10 @@ #include #include -#include +#include #include "platform_if.h" +#include "platform_pl310_if.h" static platform_attach_t imx6_attach; static platform_devmap_init_t imx6_devmap_init; @@ -324,6 +325,8 @@ PLATFORMMETHOD(platform_mp_setmaxid, imx6_mp_setmaxid), #endif + PLATFORMMETHOD(platform_pl310_init, imx6_pl310_init), + PLATFORMMETHOD_END, }; Index: sys/arm/freescale/imx/imx6_mp.c =================================================================== --- sys/arm/freescale/imx/imx6_mp.c +++ sys/arm/freescale/imx/imx6_mp.c @@ -44,7 +44,7 @@ #include #include -#include +#include #define SCU_PHYSBASE 0x00a00000 #define SCU_SIZE 0x00001000 Index: sys/arm/freescale/imx/imx6_pl310.c =================================================================== --- sys/arm/freescale/imx/imx6_pl310.c +++ 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: sys/arm/include/pl310.h =================================================================== --- sys/arm/include/pl310.h +++ 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: sys/arm/include/platformvar.h =================================================================== --- sys/arm/include/platformvar.h +++ 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: sys/arm/ti/omap4/omap4_l2cache.c =================================================================== --- sys/arm/ti/omap4/omap4_l2cache.c +++ 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: sys/arm/ti/omap4/omap4_machdep.h =================================================================== --- sys/arm/ti/omap4/omap4_machdep.h +++ sys/arm/ti/omap4/omap4_machdep.h @@ -25,9 +25,17 @@ * $FreeBSD$ */ -#ifndef _OMAP4_MP_H_ -#define _OMAP4_MP_H_ +#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); -#endif /* _OMAP4_MP_H_ */ + +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: sys/arm/ti/omap4/omap4_mp.c =================================================================== --- sys/arm/ti/omap4/omap4_mp.c +++ sys/arm/ti/omap4/omap4_mp.c @@ -41,8 +41,8 @@ #include #include +#include #include -#include void omap4_mp_setmaxid(platform_t plat) Index: sys/arm/ti/ti_machdep.c =================================================================== --- sys/arm/ti/ti_machdep.c +++ sys/arm/ti/ti_machdep.c @@ -53,12 +53,14 @@ #include #include -#include +#include #include #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: sys/arm/xilinx/zy7_l2cache.c =================================================================== --- sys/arm/xilinx/zy7_l2cache.c +++ sys/arm/xilinx/zy7_l2cache.c @@ -39,22 +39,13 @@ #include #include +#include -void -platform_pl310_init(struct pl310_softc *softc) -{ -} - -void -platform_pl310_write_ctrl(struct pl310_softc *sc, uint32_t val) -{ +#include - pl310_write4(sc, PL310_CTRL, val); -} +#include "platform_pl310_if.h" 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: sys/arm/xilinx/zy7_machdep.h =================================================================== --- sys/arm/xilinx/zy7_machdep.h +++ sys/arm/xilinx/zy7_machdep.h @@ -25,10 +25,14 @@ * $FreeBSD$ */ -#ifndef _ZY7_MP_H_ -#define _ZY7_MP_H_ +#ifndef _ZY7_MACHDEP_H_ +#define _ZY7_MACHDEP_H_ + +struct pl310_softc; void zynq7_mp_setmaxid(platform_t); void zynq7_mp_start_ap(platform_t); -#endif /* _ZY7_MP_H_ */ +void zynq7_pl310_init(platform_t, struct pl310_softc *); + +#endif /* _ZY7_MACHDEP_H_ */ Index: sys/arm/xilinx/zy7_machdep.c =================================================================== --- sys/arm/xilinx/zy7_machdep.c +++ sys/arm/xilinx/zy7_machdep.c @@ -51,10 +51,11 @@ #include #include -#include +#include #include #include "platform_if.h" +#include "platform_pl310_if.h" void (*zynq7_cpu_reset)(void); @@ -93,6 +94,8 @@ PLATFORMMETHOD(platform_mp_start_ap, zynq7_mp_start_ap), #endif + PLATFORMMETHOD(platform_pl310_init, zynq7_pl310_init), + PLATFORMMETHOD_END, }; Index: sys/arm/xilinx/zy7_mp.c =================================================================== --- sys/arm/xilinx/zy7_mp.c +++ sys/arm/xilinx/zy7_mp.c @@ -42,7 +42,7 @@ #include #include -#include +#include #include #define ZYNQ7_CPU1_ENTRY 0xfffffff0 Index: sys/conf/files.arm =================================================================== --- sys/conf/files.arm +++ 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