Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Jul 2017 16:30:16 +0000 (UTC)
From:      Andrew Turner <andrew@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r320894 - in head/sys: arm/arm arm/conf arm/freescale/imx arm/include arm/ti arm/ti/omap4 arm/xilinx conf
Message-ID:  <201707111630.v6BGUGis067140@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: andrew
Date: Tue Jul 11 16:30:16 2017
New Revision: 320894
URL: https://svnweb.freebsd.org/changeset/base/320894

Log:
  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

Added:
  head/sys/arm/arm/platform_pl310_if.m   (contents, props changed)
Modified:
  head/sys/arm/arm/pl310.c
  head/sys/arm/arm/platform.c
  head/sys/arm/conf/GENERIC
  head/sys/arm/freescale/imx/imx6_machdep.c
  head/sys/arm/freescale/imx/imx6_machdep.h
  head/sys/arm/freescale/imx/imx6_pl310.c
  head/sys/arm/include/pl310.h
  head/sys/arm/include/platformvar.h
  head/sys/arm/ti/omap4/omap4_l2cache.c
  head/sys/arm/ti/omap4/omap4_machdep.h
  head/sys/arm/ti/ti_machdep.c
  head/sys/arm/xilinx/zy7_l2cache.c
  head/sys/arm/xilinx/zy7_machdep.c
  head/sys/arm/xilinx/zy7_machdep.h
  head/sys/conf/files.arm

Modified: head/sys/arm/arm/pl310.c
==============================================================================
--- head/sys/arm/arm/pl310.c	Tue Jul 11 12:35:44 2017	(r320893)
+++ head/sys/arm/arm/pl310.c	Tue Jul 11 16:30:16 2017	(r320894)
@@ -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:
@@ -88,6 +95,29 @@ static struct ofw_compat_data compat_data[] = {
 	{"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)

Modified: head/sys/arm/arm/platform.c
==============================================================================
--- head/sys/arm/arm/platform.c	Tue Jul 11 12:35:44 2017	(r320893)
+++ head/sys/arm/arm/platform.c	Tue Jul 11 16:30:16 2017	(r320894)
@@ -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)
 {

Added: head/sys/arm/arm/platform_pl310_if.m
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/arm/arm/platform_pl310_if.m	Tue Jul 11 16:30:16 2017	(r320894)
@@ -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;

Modified: head/sys/arm/conf/GENERIC
==============================================================================
--- head/sys/arm/conf/GENERIC	Tue Jul 11 12:35:44 2017	(r320893)
+++ head/sys/arm/conf/GENERIC	Tue Jul 11 16:30:16 2017	(r320894)
@@ -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

Modified: head/sys/arm/freescale/imx/imx6_machdep.c
==============================================================================
--- head/sys/arm/freescale/imx/imx6_machdep.c	Tue Jul 11 12:35:44 2017	(r320893)
+++ head/sys/arm/freescale/imx/imx6_machdep.c	Tue Jul 11 16:30:16 2017	(r320894)
@@ -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;
@@ -320,6 +321,8 @@ static platform_method_t imx6_methods[] = {
 	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,
 };

Modified: head/sys/arm/freescale/imx/imx6_machdep.h
==============================================================================
--- head/sys/arm/freescale/imx/imx6_machdep.h	Tue Jul 11 12:35:44 2017	(r320893)
+++ head/sys/arm/freescale/imx/imx6_machdep.h	Tue Jul 11 16:30:16 2017	(r320894)
@@ -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 */

Modified: head/sys/arm/freescale/imx/imx6_pl310.c
==============================================================================
--- head/sys/arm/freescale/imx/imx6_pl310.c	Tue Jul 11 12:35:44 2017	(r320893)
+++ head/sys/arm/freescale/imx/imx6_pl310.c	Tue Jul 11 16:30:16 2017	(r320894)
@@ -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);
-}
-

Modified: head/sys/arm/include/pl310.h
==============================================================================
--- head/sys/arm/include/pl310.h	Tue Jul 11 12:35:44 2017	(r320893)
+++ head/sys/arm/include/pl310.h	Tue Jul 11 16:30:16 2017	(r320894)
@@ -181,8 +181,10 @@ pl310_write4(struct pl310_softc *sc, bus_size_t off, u
 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_ */

Modified: head/sys/arm/include/platformvar.h
==============================================================================
--- head/sys/arm/include/platformvar.h	Tue Jul 11 12:35:44 2017	(r320893)
+++ head/sys/arm/include/platformvar.h	Tue Jul 11 16:30:16 2017	(r320894)
@@ -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_ */

Modified: head/sys/arm/ti/omap4/omap4_l2cache.c
==============================================================================
--- head/sys/arm/ti/omap4/omap4_l2cache.c	Tue Jul 11 12:35:44 2017	(r320893)
+++ head/sys/arm/ti/omap4/omap4_l2cache.c	Tue Jul 11 16:30:16 2017	(r320894)
@@ -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);
 }

Modified: head/sys/arm/ti/omap4/omap4_machdep.h
==============================================================================
--- head/sys/arm/ti/omap4/omap4_machdep.h	Tue Jul 11 12:35:44 2017	(r320893)
+++ head/sys/arm/ti/omap4/omap4_machdep.h	Tue Jul 11 16:30:16 2017	(r320894)
@@ -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_ */

Modified: head/sys/arm/ti/ti_machdep.c
==============================================================================
--- head/sys/arm/ti/ti_machdep.c	Tue Jul 11 12:35:44 2017	(r320893)
+++ head/sys/arm/ti/ti_machdep.c	Tue Jul 11 16:30:16 2017	(r320894)
@@ -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);

Modified: head/sys/arm/xilinx/zy7_l2cache.c
==============================================================================
--- head/sys/arm/xilinx/zy7_l2cache.c	Tue Jul 11 12:35:44 2017	(r320893)
+++ head/sys/arm/xilinx/zy7_l2cache.c	Tue Jul 11 16:30:16 2017	(r320894)
@@ -39,22 +39,13 @@ __FBSDID("$FreeBSD$");
 
 #include <machine/bus.h>
 #include <machine/pl310.h>
+#include <machine/platformvar.h>
 
-void
-platform_pl310_init(struct pl310_softc *softc)
-{
-}
+#include <arm/xilinx/zy7_machdep.h>
 
-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);
 }

Modified: head/sys/arm/xilinx/zy7_machdep.c
==============================================================================
--- head/sys/arm/xilinx/zy7_machdep.c	Tue Jul 11 12:35:44 2017	(r320893)
+++ head/sys/arm/xilinx/zy7_machdep.c	Tue Jul 11 16:30:16 2017	(r320894)
@@ -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);
 
@@ -92,6 +93,8 @@ static platform_method_t zynq7_methods[] = {
 	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,
 };

Modified: head/sys/arm/xilinx/zy7_machdep.h
==============================================================================
--- head/sys/arm/xilinx/zy7_machdep.h	Tue Jul 11 12:35:44 2017	(r320893)
+++ head/sys/arm/xilinx/zy7_machdep.h	Tue Jul 11 16:30:16 2017	(r320894)
@@ -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_ */

Modified: head/sys/conf/files.arm
==============================================================================
--- head/sys/conf/files.arm	Tue Jul 11 12:35:44 2017	(r320893)
+++ head/sys/conf/files.arm	Tue Jul 11 16:30:16 2017	(r320894)
@@ -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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201707111630.v6BGUGis067140>