Add external PLATFORM access on arm, and use it in the pl310 driver.

This allows multiple instances of SoCs that use the pl310 driver to be
built within the same kernel:

 * Add access to the platform_t object from outside platform.c
 * Use this with the pl310 driver

There is a new platform_pl310 interface to replace the existing code. SoCs
need to implement the init method, and if they have special requirements to
write to the two registers we care about will also need to implement the
write_ctrl and write_debug methods.

Differential Revision:	https://reviews.freebsd.org/D11546
This commit is contained in:
Andrew Turner 2017-07-11 16:30:16 +00:00
parent f08b46d9da
commit 75f48c23ea
16 changed files with 180 additions and 36 deletions

View File

@ -42,11 +42,18 @@ __FBSDID("$FreeBSD$");
#include <machine/bus.h>
#include <machine/pl310.h>
#ifdef PLATFORM
#include <machine/platformvar.h>
#endif
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
#ifdef PLATFORM
#include "platform_pl310_if.h"
#endif
/*
* Define this if you need to disable PL310 for debugging purpose
* Spec:
@ -89,6 +96,29 @@ static struct ofw_compat_data compat_data[] = {
{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)
{

View File

@ -77,6 +77,13 @@ SET_DECLARE(platform_set, platform_def_t);
static delay_func platform_delay;
platform_t
platform_obj(void)
{
return (plat_obj);
}
void
platform_probe_and_attach(void)
{

View File

@ -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 <sys/bus.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/rman.h>
#include <machine/bus.h>
#include <machine/pl310.h>
#include <machine/platformvar.h>
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;

View File

@ -116,6 +116,7 @@ device pty
device snp
device md # Memory "disks"
device random # Entropy device
device pl310 # PL310 L2 cache controller
device psci
# I2C support

View File

@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$");
#include <arm/freescale/imx/imx6_machdep.h>
#include "platform_if.h"
#include "platform_pl310_if.h"
static platform_attach_t imx6_attach;
static platform_devmap_init_t imx6_devmap_init;
@ -321,6 +322,8 @@ static platform_method_t imx6_methods[] = {
PLATFORMMETHOD(platform_mp_setmaxid, imx6_mp_setmaxid),
#endif
PLATFORMMETHOD(platform_pl310_init, imx6_pl310_init),
PLATFORMMETHOD_END,
};

View File

@ -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 */

View File

@ -40,9 +40,14 @@ __FBSDID("$FreeBSD$");
#include <machine/bus.h>
#include <machine/pl310.h>
#include <machine/platformvar.h>
#include <arm/freescale/imx/imx6_machdep.h>
#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 @@ platform_pl310_init(struct pl310_softc *sc)
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);
}

View File

@ -181,8 +181,10 @@ pl310_write4(struct pl310_softc *sc, bus_size_t off, uint32_t val)
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_ */

View File

@ -114,6 +114,11 @@ DATA_SET(platform_set, VAR_NAME ## _platform)
#endif
/*
* Helper to get the platform object
*/
platform_t platform_obj(void);
bool arm_tmr_timed_wait(platform_t, int);
#endif /* _MACHINE_PLATFORMVAR_H_ */

View File

@ -32,13 +32,18 @@ __FBSDID("$FreeBSD$");
#include <sys/lock.h>
#include <sys/mutex.h>
#include <arm/ti/ti_smc.h>
#include <arm/ti/omap4/omap4_smc.h>
#include <machine/bus.h>
#include <machine/pl310.h>
#include <machine/platformvar.h>
#include <arm/ti/ti_smc.h>
#include <arm/ti/omap4/omap4_machdep.h>
#include <arm/ti/omap4/omap4_smc.h>
#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 @@ platform_pl310_init(struct pl310_softc *sc)
}
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);
}

View File

@ -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_ */

View File

@ -59,6 +59,8 @@ __FBSDID("$FreeBSD$");
#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 @@ static platform_method_t omap4_methods[] = {
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);

View File

@ -39,22 +39,13 @@ __FBSDID("$FreeBSD$");
#include <machine/bus.h>
#include <machine/pl310.h>
#include <machine/platformvar.h>
#include <arm/xilinx/zy7_machdep.h>
#include "platform_pl310_if.h"
void
platform_pl310_init(struct pl310_softc *softc)
zynq7_pl310_init(platform_t plat, struct pl310_softc *softc)
{
}
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);
}

View File

@ -55,6 +55,7 @@ __FBSDID("$FreeBSD$");
#include <arm/xilinx/zy7_reg.h>
#include "platform_if.h"
#include "platform_pl310_if.h"
void (*zynq7_cpu_reset)(void);
@ -93,6 +94,8 @@ static platform_method_t zynq7_methods[] = {
PLATFORMMETHOD(platform_mp_start_ap, zynq7_mp_start_ap),
#endif
PLATFORMMETHOD(platform_pl310_init, zynq7_pl310_init),
PLATFORMMETHOD_END,
};

View File

@ -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_ */

View File

@ -84,6 +84,7 @@ arm/arm/pl190.c optional pl190
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