All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Peng Fan (OSS)" <peng.fan@oss.nxp.com>
To: sbabic@denx.de, festevam@gmail.com
Cc: uboot-imx@nxp.com, u-boot@lists.denx.de, Ye Li <ye.li@nxp.com>,
	Peng Fan <peng.fan@nxp.com>
Subject: [Patch V3 26/44] arm: imx8ulp: release and configure XRDC at early phase
Date: Mon, 19 Jul 2021 15:47:16 +0800	[thread overview]
Message-ID: <20210719074734.29170-27-peng.fan@oss.nxp.com> (raw)
In-Reply-To: <20210719074734.29170-1-peng.fan@oss.nxp.com>

From: Ye Li <ye.li@nxp.com>

Since S400 will set the memory of SPL image to R/X. We can't write
to any data in SPL image.

1. Set the parameters save/restore only for u-boot, not for SPL. to
   avoid write data.
2. Not use MU DM driver but directly call MU API to send release XRDC
   to S400 at early phase.
3. Configure the SPL image memory of SRAM2 to writable (R/W/X)

Signed-off-by: Ye Li <ye.li@nxp.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 arch/arm/include/asm/arch-imx8ulp/mu_hal.h | 12 ++++
 arch/arm/mach-imx/imx8ulp/lowlevel_init.S  | 10 +--
 arch/arm/mach-imx/imx8ulp/soc.c            | 84 ++++++++++++++++++++++
 drivers/misc/imx8ulp/imx8ulp_mu.c          | 36 +++++-----
 4 files changed, 118 insertions(+), 24 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-imx8ulp/mu_hal.h

diff --git a/arch/arm/include/asm/arch-imx8ulp/mu_hal.h b/arch/arm/include/asm/arch-imx8ulp/mu_hal.h
new file mode 100644
index 0000000000..10d966d5d4
--- /dev/null
+++ b/arch/arm/include/asm/arch-imx8ulp/mu_hal.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2021 NXP
+ */
+
+#ifndef __IMX8ULP_MU_HAL_H__
+#define __IMX8ULP_MU_HAL_H__
+
+void mu_hal_init(ulong base);
+int mu_hal_sendmsg(ulong base, u32 reg_index, u32 msg);
+int mu_hal_receivemsg(ulong base, u32 reg_index, u32 *msg);
+#endif
diff --git a/arch/arm/mach-imx/imx8ulp/lowlevel_init.S b/arch/arm/mach-imx/imx8ulp/lowlevel_init.S
index 7d81a75639..791c26407c 100644
--- a/arch/arm/mach-imx/imx8ulp/lowlevel_init.S
+++ b/arch/arm/mach-imx/imx8ulp/lowlevel_init.S
@@ -16,17 +16,11 @@ rom_pointer:
 
 .global save_boot_params
 save_boot_params:
+#ifndef CONFIG_SPL_BUILD
 	/* The firmware provided ATAG/FDT address can be found in r2/x0 */
 	adr	x0, rom_pointer
 	stp	x1, x2, [x0], #16
 	stp	x3, x4, [x0], #16
-
+#endif
 	/* Returns */
 	b	save_boot_params_ret
-
-.global restore_boot_params
-restore_boot_params:
-	adr	x0, rom_pointer
-	ldp	x1, x2, [x0], #16
-	ldp	x3, x4, [x0], #16
-	ret
diff --git a/arch/arm/mach-imx/imx8ulp/soc.c b/arch/arm/mach-imx/imx8ulp/soc.c
index 5e7bf57a62..62c02a6223 100644
--- a/arch/arm/mach-imx/imx8ulp/soc.c
+++ b/arch/arm/mach-imx/imx8ulp/soc.c
@@ -11,6 +11,10 @@
 #include <asm/mach-imx/boot_mode.h>
 #include <efi_loader.h>
 #include <spl.h>
+#include <asm/arch/s400_api.h>
+#include <asm/arch/mu_hal.h>
+#include <cpu_func.h>
+#include <asm/setup.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -340,9 +344,89 @@ static void set_core0_reset_vector(u32 entry)
 	setbits_le32(SIM1_BASE_ADDR + 0x8, (0x1 << 26));
 }
 
+static int release_xrdc(void)
+{
+	ulong s_mu_base = 0x27020000UL;
+	struct imx8ulp_s400_msg msg;
+	int ret;
+
+	msg.version = AHAB_VERSION;
+	msg.tag = AHAB_CMD_TAG;
+	msg.size = 2;
+	msg.command = AHAB_RELEASE_RDC_REQ_CID;
+	msg.data[0] = (0x78 << 8) | 0x2; /* A35 XRDC */
+
+	mu_hal_init(s_mu_base);
+	mu_hal_sendmsg(s_mu_base, 0, *((u32 *)&msg));
+	mu_hal_sendmsg(s_mu_base, 1, msg.data[0]);
+
+	ret = mu_hal_receivemsg(s_mu_base, 0, (u32 *)&msg);
+	if (!ret) {
+		ret = mu_hal_receivemsg(s_mu_base, 1, &msg.data[0]);
+		if (!ret)
+			return ret;
+
+		if ((msg.data[0] & 0xff) == 0)
+			return 0;
+		else
+			return -EIO;
+	}
+
+	return ret;
+}
+
+static void xrdc_mrc_region_set_access(int mrc_index, u32 addr, u32 access)
+{
+	ulong xrdc_base = 0x292f0000, off;
+	u32 mrgd[5];
+	u8 mrcfg, j, region_num;
+	u8 dsel;
+
+	mrcfg = readb(xrdc_base + 0x140 + mrc_index);
+	region_num = mrcfg & 0x1f;
+
+	for (j = 0; j < region_num; j++) {
+		off = 0x2000 + mrc_index * 0x200 + j * 0x20;
+
+		mrgd[0] = readl(xrdc_base + off);
+		mrgd[1] = readl(xrdc_base + off + 4);
+		mrgd[2] = readl(xrdc_base + off + 8);
+		mrgd[3] = readl(xrdc_base + off + 0xc);
+		mrgd[4] = readl(xrdc_base + off + 0x10);
+
+		debug("MRC [%u][%u]\n", mrc_index, j);
+		debug("0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
+		      mrgd[0], mrgd[1], mrgd[2], mrgd[3], mrgd[4]);
+
+		/* hit */
+		if (addr >= mrgd[0] && addr <= mrgd[1]) {
+			/* find domain 7 DSEL */
+			dsel = (mrgd[2] >> 21) & 0x7;
+			if (dsel == 1) {
+				mrgd[4] &= ~0xFFF;
+				mrgd[4] |= (access & 0xFFF);
+			} else if (dsel == 2) {
+				mrgd[4] &= ~0xFFF0000;
+				mrgd[4] |= ((access & 0xFFF) << 16);
+			}
+
+			/* not handle other cases, since S400 only set ACCESS1 and 2 */
+			writel(mrgd[4], xrdc_base + off + 0x10);
+			return;
+		}
+	}
+}
+
 int arch_cpu_init(void)
 {
 	if (IS_ENABLED(CONFIG_SPL_BUILD)) {
+		/* Disable wdog */
+		init_wdog();
+
+		/* release xrdc, then allow A35 to write SRAM2 */
+		release_xrdc();
+		xrdc_mrc_region_set_access(2, CONFIG_SPL_TEXT_BASE, 0xE00);
+
 		clock_init();
 	} else {
 		/* reconfigure core0 reset vector to ROM */
diff --git a/drivers/misc/imx8ulp/imx8ulp_mu.c b/drivers/misc/imx8ulp/imx8ulp_mu.c
index f3ca5473e3..913ebe7ad3 100644
--- a/drivers/misc/imx8ulp/imx8ulp_mu.c
+++ b/drivers/misc/imx8ulp/imx8ulp_mu.c
@@ -42,24 +42,27 @@ struct imx8ulp_mu {
 #define MU_TR_COUNT		4
 #define MU_RR_COUNT		4
 
-static inline void mu_hal_init(struct mu_type *base)
+void mu_hal_init(ulong base)
 {
-	writel(0, &base->tcr);
-	writel(0, &base->rcr);
+	struct mu_type *mu_base = (struct mu_type *)base;
+
+	writel(0, &mu_base->tcr);
+	writel(0, &mu_base->rcr);
 }
 
-static int mu_hal_sendmsg(struct mu_type *base, u32 reg_index, u32 msg)
+int mu_hal_sendmsg(ulong base, u32 reg_index, u32 msg)
 {
+	struct mu_type *mu_base = (struct mu_type *)base;
 	u32 mask = MU_SR_TE0_MASK << reg_index;
 	u32 val;
 	int ret;
 
 	assert(reg_index < MU_TR_COUNT);
 
-	debug("sendmsg sr 0x%x\n", readl(&base->sr));
+	debug("sendmsg sr 0x%x\n", readl(&mu_base->sr));
 
 	/* Wait TX register to be empty. */
-	ret = readl_poll_timeout(&base->tsr, val, val & mask, 10000);
+	ret = readl_poll_timeout(&mu_base->tsr, val, val & mask, 10000);
 	if (ret < 0) {
 		debug("%s timeout\n", __func__);
 		return -ETIMEDOUT;
@@ -67,29 +70,30 @@ static int mu_hal_sendmsg(struct mu_type *base, u32 reg_index, u32 msg)
 
 	debug("tr[%d] 0x%x\n", reg_index, msg);
 
-	writel(msg, &base->tr[reg_index]);
+	writel(msg, &mu_base->tr[reg_index]);
 
 	return 0;
 }
 
-static int mu_hal_receivemsg(struct mu_type *base, u32 reg_index, u32 *msg)
+int mu_hal_receivemsg(ulong base, u32 reg_index, u32 *msg)
 {
+	struct mu_type *mu_base = (struct mu_type *)base;
 	u32 mask = MU_SR_RF0_MASK << reg_index;
 	u32 val;
 	int ret;
 
 	assert(reg_index < MU_TR_COUNT);
 
-	debug("receivemsg sr 0x%x\n", readl(&base->sr));
+	debug("receivemsg sr 0x%x\n", readl(&mu_base->sr));
 
 	/* Wait RX register to be full. */
-	ret = readl_poll_timeout(&base->rsr, val, val & mask, 10000);
+	ret = readl_poll_timeout(&mu_base->rsr, val, val & mask, 10000);
 	if (ret < 0) {
 		debug("%s timeout\n", __func__);
 		return -ETIMEDOUT;
 	}
 
-	*msg = readl(&base->rr[reg_index]);
+	*msg = readl(&mu_base->rr[reg_index]);
 
 	debug("rr[%d] 0x%x\n", reg_index, *msg);
 
@@ -106,7 +110,7 @@ static int imx8ulp_mu_read(struct mu_type *base, void *data)
 		return -EINVAL;
 
 	/* Read first word */
-	ret = mu_hal_receivemsg(base, 0, (u32 *)msg);
+	ret = mu_hal_receivemsg((ulong)base, 0, (u32 *)msg);
 	if (ret)
 		return ret;
 	count++;
@@ -119,7 +123,7 @@ static int imx8ulp_mu_read(struct mu_type *base, void *data)
 
 	/* Read remaining words */
 	while (count < msg->size) {
-		ret = mu_hal_receivemsg(base, count % MU_RR_COUNT,
+		ret = mu_hal_receivemsg((ulong)base, count % MU_RR_COUNT,
 					&msg->data[count - 1]);
 		if (ret)
 			return ret;
@@ -143,14 +147,14 @@ static int imx8ulp_mu_write(struct mu_type *base, void *data)
 		return -EINVAL;
 
 	/* Write first word */
-	ret = mu_hal_sendmsg(base, 0, *((u32 *)msg));
+	ret = mu_hal_sendmsg((ulong)base, 0, *((u32 *)msg));
 	if (ret)
 		return ret;
 	count++;
 
 	/* Write remaining words */
 	while (count < msg->size) {
-		ret = mu_hal_sendmsg(base, count % MU_TR_COUNT,
+		ret = mu_hal_sendmsg((ulong)base, count % MU_TR_COUNT,
 				     msg->data[count - 1]);
 		if (ret)
 			return ret;
@@ -207,7 +211,7 @@ static int imx8ulp_mu_probe(struct udevice *dev)
 	debug("mu base 0x%lx\n", (ulong)priv->base);
 
 	/* U-Boot not enable interrupts, so need to enable RX interrupts */
-	mu_hal_init(priv->base);
+	mu_hal_init((ulong)priv->base);
 
 	gd->arch.s400_dev = dev;
 
-- 
2.30.0


  parent reply	other threads:[~2021-07-19  7:18 UTC|newest]

Thread overview: 90+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-19  7:46 [Patch V3 00/44] imx: add i.MX8ULP support Peng Fan (OSS)
2021-07-19  7:46 ` [Patch V3 01/44] arm: imx: add i.MX8ULP basic Kconfig option Peng Fan (OSS)
2021-07-20 14:58   ` sbabic
2021-07-19  7:46 ` [Patch V3 02/44] arm: imx: add i.MX8ULP cpu type and helper Peng Fan (OSS)
2021-07-20 14:56   ` sbabic
2021-07-19  7:46 ` [Patch V3 03/44] arm: imx: sys_proto: move boot mode define to common header Peng Fan (OSS)
2021-07-20 14:58   ` sbabic
2021-07-19  7:46 ` [Patch V3 04/44] arm: imx8ulp: support print cpu info Peng Fan (OSS)
2021-07-20 14:58   ` sbabic
2021-07-19  7:46 ` [Patch V3 05/44] imx: imx8ulp: add get reset cause Peng Fan (OSS)
2021-07-20 14:58   ` sbabic
2021-07-19  7:46 ` [Patch V3 06/44] arm: imx: basic i.MX8ULP support Peng Fan (OSS)
2021-07-20 14:56   ` sbabic
2021-07-19  7:46 ` [Patch V3 07/44] arm: imx8: Move container parser and image to mach-imx common folder Peng Fan (OSS)
2021-07-20 14:58   ` sbabic
2021-07-19  7:46 ` [Patch V3 08/44] arm: imx8: Move container image header file to mach-imx Peng Fan (OSS)
2021-07-20 14:57   ` sbabic
2021-07-19  7:46 ` [Patch V3 09/44] arm: imx: parse-container: guard included header files Peng Fan (OSS)
2021-07-20 14:56   ` sbabic
2021-07-19  7:47 ` [Patch V3 10/44] arm: imx8ulp: add container support Peng Fan (OSS)
2021-07-20 14:57   ` sbabic
2021-07-19  7:47 ` [Patch V3 11/44] arm: imx: move container Kconfig under mach-imx Peng Fan (OSS)
2021-07-20 14:56   ` sbabic
2021-07-19  7:47 ` [Patch V3 12/44] driver: misc: Add MU and S400 API to communicate with Sentinel Peng Fan (OSS)
2021-07-20 14:57   ` sbabic
2021-07-19  7:47 ` [Patch V3 13/44] net: fec_mxc: support i.MX8ULP Peng Fan (OSS)
2021-07-20 14:57   ` sbabic
2021-07-19  7:47 ` [Patch V3 14/44] pinctrl: Add pinctrl driver for imx8ulp Peng Fan (OSS)
2021-07-20 14:56   ` sbabic
2021-07-19  7:47 ` [Patch V3 15/44] driver: serial: fsl_lpuart: support i.MX8ULP Peng Fan (OSS)
2021-07-20 14:58   ` sbabic
2021-07-19  7:47 ` [Patch V3 16/44] arm: imx8ulp: add clock support Peng Fan (OSS)
2021-07-20 14:56   ` sbabic
2021-07-19  7:47 ` [Patch V3 17/44] drivers: mmc: fsl_esdhc_imx: support i.MX8ULP Peng Fan (OSS)
2021-07-20 14:58   ` sbabic
2021-07-19  7:47 ` [Patch V3 18/44] arm: imx8ulp: soc: Change to use CMC1 to get bootcfg Peng Fan (OSS)
2021-07-20 14:57   ` sbabic
2021-07-19  7:47 ` [Patch V3 19/44] arm: imx8ulp: Enable full L2 cache in SPL Peng Fan (OSS)
2021-07-20 14:57   ` sbabic
2021-07-19  7:47 ` [Patch V3 20/44] arm: imx8ulp: disable wdog3 Peng Fan (OSS)
2021-07-20 14:56   ` sbabic
2021-07-19  7:47 ` [Patch V3 21/44] arm: imx8ulp: Update the reset vector in u-boot Peng Fan (OSS)
2021-07-20 14:59   ` sbabic
2021-07-19  7:47 ` [Patch V3 22/44] drivers: misc: s400_api: Update S400_SUCCESS_IND to 0xd6 Peng Fan (OSS)
2021-07-20 14:57   ` sbabic
2021-07-19  7:47 ` [Patch V3 23/44] drivers: misc: imx8ulp: Add S400 API for image authentication Peng Fan (OSS)
2021-07-20 14:56   ` sbabic
2021-07-19  7:47 ` [Patch V3 24/44] drivers: misc: imx8ulp: Update S400 API for release RDC Peng Fan (OSS)
2021-07-20 14:58   ` sbabic
2021-07-19  7:47 ` [Patch V3 25/44] drivers: misc: s400_api: Update API for fuse read and write Peng Fan (OSS)
2021-07-20 14:57   ` sbabic
2021-07-19  7:47 ` Peng Fan (OSS) [this message]
2021-07-20 14:56   ` [Patch V3 26/44] arm: imx8ulp: release and configure XRDC at early phase sbabic
2021-07-19  7:47 ` [Patch V3 27/44] arm: imx8ulp: add rdc support Peng Fan (OSS)
2021-07-20 14:57   ` sbabic
2021-07-19  7:47 ` [Patch V3 28/44] arm: imx8ulp: add trdc release request Peng Fan (OSS)
2021-07-20 14:57   ` sbabic
2021-07-19  7:47 ` [Patch V3 29/44] arm: imx8ulp: release trdc and assign lpav from RTD to APD Peng Fan (OSS)
2021-07-20 14:58   ` sbabic
2021-07-19  7:47 ` [Patch V3 30/44] imx8ulp: unify rdc functions Peng Fan (OSS)
2021-07-20 14:56   ` sbabic
2021-07-19  7:47 ` [Patch V3 31/44] arm: imx8ulp: Probe the S400 MU device in arch init Peng Fan (OSS)
2021-07-20 14:58   ` sbabic
2021-07-19  7:47 ` [Patch V3 32/44] arm: iMX8ULP: Add boot device relevant functions Peng Fan (OSS)
2021-07-20 14:57   ` sbabic
2021-07-19  7:47 ` [Patch V3 33/44] arm: imx8ulp: Allocate DCNANO and MIPI_DSI to AD domain Peng Fan (OSS)
2021-07-20 14:56   ` sbabic
2021-07-19  7:47 ` [Patch V3 34/44] arm: imx8ulp: add dummy imx_get_mac_from_fuse Peng Fan (OSS)
2021-07-20 14:56   ` sbabic
2021-07-19  7:47 ` [Patch V3 35/44] arm: imx8ulp: add iomuxc support Peng Fan (OSS)
2021-07-20 14:58   ` sbabic
2021-07-19  7:47 ` [Patch V3 36/44] driver: misc: imx8ulp: Add fuse driver for imx8ulp Peng Fan (OSS)
2021-07-20 14:59   ` sbabic
2021-07-19  7:47 ` [Patch V3 37/44] imx8ulp: soc: correct reset cause Peng Fan (OSS)
2021-07-20 14:57   ` sbabic
2021-07-19  7:47 ` [Patch V3 38/44] imx8ulp: Use DGO_GP5 to get boot config Peng Fan (OSS)
2021-07-20 14:57   ` sbabic
2021-07-19  7:47 ` [Patch V3 39/44] imx8ulp: Add workaround for eMMC boot Peng Fan (OSS)
2021-07-20 14:58   ` sbabic
2021-07-19  7:47 ` [Patch V3 40/44] imx8ulp: move struct mu_type to common header Peng Fan (OSS)
2021-07-20 14:58   ` sbabic
2021-07-19  7:47 ` [Patch V3 41/44] imx8ulp: add upower api support Peng Fan (OSS)
2021-07-20 14:58   ` sbabic
2021-07-19  7:47 ` [Patch V3 42/44] ddr: Add DDR driver for iMX8ULP Peng Fan (OSS)
2021-07-20 14:56   ` sbabic
2021-07-19  7:47 ` [Patch V3 43/44] arm: dts: add i.MX8ULP dtsi Peng Fan (OSS)
2021-07-20 14:58   ` sbabic
2021-07-19  7:47 ` [Patch V3 44/44] arm: imx: add i.MX8ULP EVK support Peng Fan (OSS)
2021-07-20 14:58   ` sbabic
2021-07-19  7:59 ` [Patch V3 00/44] imx: add i.MX8ULP support Stefano Babic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210719074734.29170-27-peng.fan@oss.nxp.com \
    --to=peng.fan@oss.nxp.com \
    --cc=festevam@gmail.com \
    --cc=peng.fan@nxp.com \
    --cc=sbabic@denx.de \
    --cc=u-boot@lists.denx.de \
    --cc=uboot-imx@nxp.com \
    --cc=ye.li@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.