All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Peng Fan (OSS)" <peng.fan@oss.nxp.com>
To: sbabic@denx.de
Cc: festevam@gmail.com, u-boot@lists.denx.de, uboot-imx@nxp.com,
	Ji Luo <ji.luo@nxp.com>
Subject: [PATCH V2 23/26] imx: imx8ulp: reserve tee memory
Date: Wed,  6 Apr 2022 14:30:28 +0800	[thread overview]
Message-ID: <20220406063031.21960-24-peng.fan@oss.nxp.com> (raw)
In-Reply-To: <20220406063031.21960-1-peng.fan@oss.nxp.com>

From: Ji Luo <ji.luo@nxp.com>

The TEE memory should be reserved when TEE is present, so need
to runtime update dram bank and memory information according to
tee present or not.

Signed-off-by: Ji Luo <ji.luo@nxp.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 arch/arm/mach-imx/imx8ulp/soc.c | 102 +++++++++++++++++++++++++++++++-
 1 file changed, 100 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-imx/imx8ulp/soc.c b/arch/arm/mach-imx/imx8ulp/soc.c
index 569558c7d83..25b4fbd294e 100644
--- a/arch/arm/mach-imx/imx8ulp/soc.c
+++ b/arch/arm/mach-imx/imx8ulp/soc.c
@@ -413,6 +413,17 @@ static struct mm_region imx8ulp_arm64_mem_map[] = {
 
 struct mm_region *mem_map = imx8ulp_arm64_mem_map;
 
+static unsigned int imx8ulp_find_dram_entry_in_mem_map(void)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(imx8ulp_arm64_mem_map); i++)
+		if (imx8ulp_arm64_mem_map[i].phys == CONFIG_SYS_SDRAM_BASE)
+			return i;
+
+	hang();	/* Entry not found, this must never happen. */
+}
+
 /* simplify the page table size to enhance boot speed */
 #define MAX_PTE_ENTRIES		512
 #define MAX_MEM_MAP_REGIONS	16
@@ -444,19 +455,106 @@ u64 get_page_table_size(void)
 
 void enable_caches(void)
 {
-	/* TODO: add TEE memmap region */
+	/* If OPTEE runs, remove OPTEE memory from MMU table to avoid speculative prefetch */
+	if (rom_pointer[1]) {
+		/*
+		 * TEE are loaded, So the ddr bank structures
+		 * have been modified update mmu table accordingly
+		 */
+		int i = 0;
+		int entry = imx8ulp_find_dram_entry_in_mem_map();
+		u64 attrs = imx8ulp_arm64_mem_map[entry].attrs;
+
+		while (i < CONFIG_NR_DRAM_BANKS &&
+		       entry < ARRAY_SIZE(imx8ulp_arm64_mem_map)) {
+			if (gd->bd->bi_dram[i].start == 0)
+				break;
+			imx8ulp_arm64_mem_map[entry].phys = gd->bd->bi_dram[i].start;
+			imx8ulp_arm64_mem_map[entry].virt = gd->bd->bi_dram[i].start;
+			imx8ulp_arm64_mem_map[entry].size = gd->bd->bi_dram[i].size;
+			imx8ulp_arm64_mem_map[entry].attrs = attrs;
+			debug("Added memory mapping (%d): %llx %llx\n", entry,
+			      imx8ulp_arm64_mem_map[entry].phys, imx8ulp_arm64_mem_map[entry].size);
+			i++; entry++;
+		}
+	}
 
 	icache_enable();
 	dcache_enable();
 }
 
+__weak int board_phys_sdram_size(phys_size_t *size)
+{
+	if (!size)
+		return -EINVAL;
+
+	*size = PHYS_SDRAM_SIZE;
+	return 0;
+}
+
 int dram_init(void)
 {
-	gd->ram_size = PHYS_SDRAM_SIZE;
+	unsigned int entry = imx8ulp_find_dram_entry_in_mem_map();
+	phys_size_t sdram_size;
+	int ret;
+
+	ret = board_phys_sdram_size(&sdram_size);
+	if (ret)
+		return ret;
+
+	/* rom_pointer[1] contains the size of TEE occupies */
+	if (rom_pointer[1])
+		gd->ram_size = sdram_size - rom_pointer[1];
+	else
+		gd->ram_size = sdram_size;
+
+	/* also update the SDRAM size in the mem_map used externally */
+	imx8ulp_arm64_mem_map[entry].size = sdram_size;
+	return 0;
+}
+
+int dram_init_banksize(void)
+{
+	int bank = 0;
+	int ret;
+	phys_size_t sdram_size;
+
+	ret = board_phys_sdram_size(&sdram_size);
+	if (ret)
+		return ret;
+
+	gd->bd->bi_dram[bank].start = PHYS_SDRAM;
+	if (rom_pointer[1]) {
+		phys_addr_t optee_start = (phys_addr_t)rom_pointer[0];
+		phys_size_t optee_size = (size_t)rom_pointer[1];
+
+		gd->bd->bi_dram[bank].size = optee_start - gd->bd->bi_dram[bank].start;
+		if ((optee_start + optee_size) < (PHYS_SDRAM + sdram_size)) {
+			if (++bank >= CONFIG_NR_DRAM_BANKS) {
+				puts("CONFIG_NR_DRAM_BANKS is not enough\n");
+				return -1;
+			}
+
+			gd->bd->bi_dram[bank].start = optee_start + optee_size;
+			gd->bd->bi_dram[bank].size = PHYS_SDRAM +
+				sdram_size - gd->bd->bi_dram[bank].start;
+		}
+	} else {
+		gd->bd->bi_dram[bank].size = sdram_size;
+	}
 
 	return 0;
 }
 
+phys_size_t get_effective_memsize(void)
+{
+	/* return the first bank as effective memory */
+	if (rom_pointer[1])
+		return ((phys_addr_t)rom_pointer[0] - PHYS_SDRAM);
+
+	return gd->ram_size;
+}
+
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 void get_board_serial(struct tag_serialnr *serialnr)
 {
-- 
2.35.1


  parent reply	other threads:[~2022-04-06  5:56 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-06  6:30 [PATCH V2 00/26] imx: imx8ulp: misc update from downstream Peng Fan (OSS)
2022-04-06  6:30 ` [PATCH V2 01/26] imx: imx8ulp: Set COUNTER_FREQUENCY to 1Mhz Peng Fan (OSS)
2022-04-12 18:43   ` sbabic
2022-04-06  6:30 ` [PATCH V2 02/26] imx: imx8ulp: include pcc/cgc header in clock header Peng Fan (OSS)
2022-04-12 18:46   ` sbabic
2022-04-06  6:30 ` [PATCH V2 03/26] imx: imx8ulp: Add M33 handshake functions Peng Fan (OSS)
2022-04-12 18:46   ` sbabic
2022-04-06  6:30 ` [PATCH V2 04/26] imx: imx8ulp: clock: Add clock support for i3c controller Peng Fan (OSS)
2022-04-12 18:44   ` sbabic
2022-04-06  6:30 ` [PATCH V2 05/26] imx: imx8ulp: add CAAM clock entry Peng Fan (OSS)
2022-04-12 18:43   ` sbabic
2022-04-06  6:30 ` [PATCH V2 06/26] imx: imx8ulp_evk: Remove PMIC Bucks PWM mode settings Peng Fan (OSS)
2022-04-12 18:42   ` sbabic
2022-04-06  6:30 ` [PATCH V2 07/26] imx: imx8ulp: add ND/LD clock Peng Fan (OSS)
2022-04-12 18:43   ` sbabic
2022-04-06  6:30 ` [PATCH V2 08/26] imx: imx8ulp_evk: Skip init DDR for reboot in dual boot mode Peng Fan (OSS)
2022-04-12 18:45   ` sbabic
2022-04-06  6:30 ` [PATCH V2 09/26] imx: imx8ulp: cgc: Switch to NICLPAV to FRO192 before PLL4 init Peng Fan (OSS)
2022-04-12 18:45   ` sbabic
2022-04-06  6:30 ` [PATCH V2 10/26] imx: imx8ulp: enable MU0_B clk by default Peng Fan (OSS)
2022-04-12 18:46   ` sbabic
2022-04-06  6:30 ` [PATCH V2 11/26] misc: imx8ulp: Add OEM SRK Hash fuse support Peng Fan (OSS)
2022-04-12 18:46   ` sbabic
2022-04-06  6:30 ` [PATCH V2 12/26] imx: imx8ulp: Change LPAV assignment for dual boot Peng Fan (OSS)
2022-04-12 18:42   ` sbabic
2022-04-06  6:30 ` [PATCH V2 13/26] imx: imx8ulp: Load the lposc fuse " Peng Fan (OSS)
2022-04-12 18:47   ` sbabic
2022-04-06  6:30 ` [PATCH V2 14/26] misc: S400_API: add ahab_release_caam Peng Fan (OSS)
2022-04-12 18:41   ` sbabic
2022-04-06  6:30 ` [PATCH V2 15/26] misc: S400_API: Update S400 API for buffer dump Peng Fan (OSS)
2022-04-12 18:47   ` sbabic
2022-04-06  6:30 ` [PATCH V2 16/26] imx: imx8ulp: release CAAM for the Cortex-A35 Peng Fan (OSS)
2022-04-12 18:47   ` sbabic
2022-04-06  6:30 ` [PATCH V2 17/26] imx: imx8ulp_evk: Update LPDDR4 PHY settings Peng Fan (OSS)
2022-04-12 18:42   ` sbabic
2022-04-06  6:30 ` [PATCH V2 18/26] imx: imx8ulp_evk: call the handshake with M33 Peng Fan (OSS)
2022-04-12 18:47   ` sbabic
2022-04-06  6:30 ` [PATCH V2 19/26] imx: imx8ulp_evk: Power down the domains may used in u-boot Peng Fan (OSS)
2022-04-12 17:10   ` Stefano Babic
2022-04-13  3:00     ` Peng Fan (OSS)
2022-04-13  7:45       ` Stefano Babic
2022-04-06  6:30 ` [PATCH V2 20/26] imx: dynamic setting mmcdev and mmcroot Peng Fan (OSS)
2022-04-12 18:45   ` sbabic
2022-04-25 19:58   ` Tim Harvey
2022-04-26 11:24     ` Peng Fan (OSS)
2022-04-06  6:30 ` [PATCH V2 21/26] imx: imx8ulp_evk: Enable SD/MMC port auto detect Peng Fan (OSS)
2022-04-12 18:46   ` sbabic
2022-04-06  6:30 ` [PATCH V2 22/26] imx: imx8ulp: enable wdog_ad interrupt in CMC1 Peng Fan (OSS)
2022-04-12 18:47   ` sbabic
2022-04-06  6:30 ` Peng Fan (OSS) [this message]
2022-04-12 18:43   ` [PATCH V2 23/26] imx: imx8ulp: reserve tee memory sbabic
2022-04-06  6:30 ` [PATCH V2 24/26] imx: imx8ulp_evk: enlarge CONFIG_NR_DRAM_BANKS Peng Fan (OSS)
2022-04-12 18:43   ` sbabic
2022-04-06  6:30 ` [PATCH V2 25/26] imx: imx8ulp_evk: Enable multiple env storage devices Peng Fan (OSS)
2022-04-12 18:43   ` sbabic
2022-04-06  6:30 ` [PATCH V2 26/26] misc: imx8ulp: Update fuse driver Peng Fan (OSS)
2022-04-12 18:46   ` sbabic

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=20220406063031.21960-24-peng.fan@oss.nxp.com \
    --to=peng.fan@oss.nxp.com \
    --cc=festevam@gmail.com \
    --cc=ji.luo@nxp.com \
    --cc=sbabic@denx.de \
    --cc=u-boot@lists.denx.de \
    --cc=uboot-imx@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.