From 331d40d7014d932ba7ebaf2450885d8dc427a023 Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Sat, 7 Aug 2021 16:00:31 +0800 Subject: arm: imx: add i.MX8ULP cpu type and helper Add i.MX8ULP cpu type and helpers. Signed-off-by: Peng Fan --- arch/arm/include/asm/arch-imx8ulp/sys_proto.h | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 arch/arm/include/asm/arch-imx8ulp/sys_proto.h (limited to 'arch/arm/include/asm/arch-imx8ulp/sys_proto.h') diff --git a/arch/arm/include/asm/arch-imx8ulp/sys_proto.h b/arch/arm/include/asm/arch-imx8ulp/sys_proto.h new file mode 100644 index 0000000000..cab12c218e --- /dev/null +++ b/arch/arm/include/asm/arch-imx8ulp/sys_proto.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2021 NXP + */ + +#ifndef __ARCH_IMX8ULP_SYS_PROTO_H +#define __ARCH_NMX8ULP_SYS_PROTO_H + +#include + +#endif -- cgit v1.2.3 From 77c3b9cc98cb1bfe719933d14cc6e9e279bcb34c Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Sat, 7 Aug 2021 16:00:33 +0800 Subject: arm: imx8ulp: support print cpu info Support print cpu info. the clock function has not been added, it will be added in following patches. Signed-off-by: Peng Fan --- arch/arm/include/asm/arch-imx8ulp/sys_proto.h | 3 ++ arch/arm/mach-imx/imx8ulp/soc.c | 58 +++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) (limited to 'arch/arm/include/asm/arch-imx8ulp/sys_proto.h') diff --git a/arch/arm/include/asm/arch-imx8ulp/sys_proto.h b/arch/arm/include/asm/arch-imx8ulp/sys_proto.h index cab12c218e..8894611a0f 100644 --- a/arch/arm/include/asm/arch-imx8ulp/sys_proto.h +++ b/arch/arm/include/asm/arch-imx8ulp/sys_proto.h @@ -8,4 +8,7 @@ #include +extern unsigned long rom_pointer[]; + +enum bt_mode get_boot_mode(void); #endif diff --git a/arch/arm/mach-imx/imx8ulp/soc.c b/arch/arm/mach-imx/imx8ulp/soc.c index b3679aefcb..dcb8dc019f 100644 --- a/arch/arm/mach-imx/imx8ulp/soc.c +++ b/arch/arm/mach-imx/imx8ulp/soc.c @@ -3,9 +3,67 @@ * Copyright 2021 NXP */ +#include +#include +#include #include +#include u32 get_cpu_rev(void) { return (MXC_CPU_IMX8ULP << 12) | CHIP_REV_1_0; } + +enum bt_mode get_boot_mode(void) +{ + u32 bt0_cfg = 0; + + bt0_cfg = readl(CMC0_RBASE + 0x80); + bt0_cfg &= (BT0CFG_LPBOOT_MASK | BT0CFG_DUALBOOT_MASK); + + if (!(bt0_cfg & BT0CFG_LPBOOT_MASK)) { + /* No low power boot */ + if (bt0_cfg & BT0CFG_DUALBOOT_MASK) + return DUAL_BOOT; + else + return SINGLE_BOOT; + } + + return LOW_POWER_BOOT; +} + +#if defined(CONFIG_DISPLAY_CPUINFO) +const char *get_imx_type(u32 imxtype) +{ + return "8ULP"; +} + +int print_cpuinfo(void) +{ + u32 cpurev; + char cause[18]; + + cpurev = get_cpu_rev(); + + printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n", + get_imx_type((cpurev & 0xFF000) >> 12), + (cpurev & 0x000F0) >> 4, (cpurev & 0x0000F) >> 0, + mxc_get_clock(MXC_ARM_CLK) / 1000000); + + printf("Boot mode: "); + switch (get_boot_mode()) { + case LOW_POWER_BOOT: + printf("Low power boot\n"); + break; + case DUAL_BOOT: + printf("Dual boot\n"); + break; + case SINGLE_BOOT: + default: + printf("Single boot\n"); + break; + } + + return 0; +} +#endif -- cgit v1.2.3 From 6f3858d732985f13c764ec29c1668d9f06941b6c Mon Sep 17 00:00:00 2001 From: Ye Li Date: Sat, 7 Aug 2021 16:00:39 +0800 Subject: arm: imx8ulp: add container support i.MX8ULP support using ROM API to load container image, it use same ROM API as i.MX8MN/MP, and use same container format as i.MX8QM/QXP. Signed-off-by: Ye Li Signed-off-by: Peng Fan --- arch/arm/include/asm/arch-imx8ulp/sys_proto.h | 2 + arch/arm/include/asm/mach-imx/image.h | 2 + arch/arm/include/asm/mach-imx/sys_proto.h | 2 +- arch/arm/mach-imx/Kconfig | 2 +- arch/arm/mach-imx/image-container.c | 42 ++++++- arch/arm/mach-imx/imx8ulp/soc.c | 2 + arch/arm/mach-imx/spl_imx_romapi.c | 172 ++++++++++++++++++++------ 7 files changed, 177 insertions(+), 47 deletions(-) (limited to 'arch/arm/include/asm/arch-imx8ulp/sys_proto.h') diff --git a/arch/arm/include/asm/arch-imx8ulp/sys_proto.h b/arch/arm/include/asm/arch-imx8ulp/sys_proto.h index 8894611a0f..a8f632f45e 100644 --- a/arch/arm/include/asm/arch-imx8ulp/sys_proto.h +++ b/arch/arm/include/asm/arch-imx8ulp/sys_proto.h @@ -10,5 +10,7 @@ extern unsigned long rom_pointer[]; +ulong spl_romapi_raw_seekable_read(u32 offset, u32 size, void *buf); +ulong spl_romapi_get_uboot_base(u32 image_offset, u32 rom_bt_dev); enum bt_mode get_boot_mode(void); #endif diff --git a/arch/arm/include/asm/mach-imx/image.h b/arch/arm/include/asm/mach-imx/image.h index 547beeb986..ee67ca96f4 100644 --- a/arch/arm/include/asm/mach-imx/image.h +++ b/arch/arm/include/asm/mach-imx/image.h @@ -64,4 +64,6 @@ struct generate_key_blob_hdr { u8 algorithm; u8 mode; } __packed; + +int get_container_size(ulong addr, u16 *header_length); #endif diff --git a/arch/arm/include/asm/mach-imx/sys_proto.h b/arch/arm/include/asm/mach-imx/sys_proto.h index e3ee58c9f8..444834995e 100644 --- a/arch/arm/include/asm/mach-imx/sys_proto.h +++ b/arch/arm/include/asm/mach-imx/sys_proto.h @@ -145,7 +145,7 @@ struct rproc_att { u32 size; /* size of reg range */ }; -#ifdef CONFIG_IMX8M +#if defined(CONFIG_IMX8M) || defined(CONFIG_IMX8ULP) struct rom_api { u16 ver; u16 tag; diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig index 26bfc5ccc4..c089664375 100644 --- a/arch/arm/mach-imx/Kconfig +++ b/arch/arm/mach-imx/Kconfig @@ -161,7 +161,7 @@ config DDRMC_VF610_CALIBRATION config SPL_IMX_ROMAPI_LOADADDR hex "Default load address to load image through ROM API" - depends on IMX8MN || IMX8MP + depends on IMX8MN || IMX8MP || IMX8ULP config IMX_DCD_ADDR hex "DCD Blocks location on the image" diff --git a/arch/arm/mach-imx/image-container.c b/arch/arm/mach-imx/image-container.c index 9e18f6630f..c3f62872c6 100644 --- a/arch/arm/mach-imx/image-container.c +++ b/arch/arm/mach-imx/image-container.c @@ -19,8 +19,9 @@ #define QSPI_DEV 1 #define NAND_DEV 2 #define QSPI_NOR_DEV 3 +#define ROM_API_DEV 4 -static int __get_container_size(ulong addr) +int get_container_size(ulong addr, u16 *header_length) { struct container_hdr *phdr; struct boot_img_t *img_entry; @@ -34,7 +35,9 @@ static int __get_container_size(ulong addr) return -EFAULT; } - max_offset = sizeof(struct container_hdr); + max_offset = phdr->length_lsb + (phdr->length_msb << 8); + if (header_length) + *header_length = max_offset; img_entry = (struct boot_img_t *)(addr + sizeof(struct container_hdr)); for (i = 0; i < phdr->num_images; i++) { @@ -60,7 +63,7 @@ static int __get_container_size(ulong addr) return max_offset; } -static int get_container_size(void *dev, int dev_type, unsigned long offset) +static int get_dev_container_size(void *dev, int dev_type, unsigned long offset, u16 *header_length) { u8 *buf = malloc(CONTAINER_HDR_ALIGNMENT); int ret = 0; @@ -115,7 +118,17 @@ static int get_container_size(void *dev, int dev_type, unsigned long offset) memcpy(buf, (const void *)offset, CONTAINER_HDR_ALIGNMENT); #endif - ret = __get_container_size((ulong)buf); +#ifdef CONFIG_SPL_BOOTROM_SUPPORT + if (dev_type == ROM_API_DEV) { + ret = spl_romapi_raw_seekable_read(offset, CONTAINER_HDR_ALIGNMENT, buf); + if (!ret) { + printf("Read container image from ROM API failed\n"); + return -EIO; + } + } +#endif + + ret = get_container_size((ulong)buf, header_length); free(buf); @@ -149,6 +162,8 @@ static unsigned long get_boot_device_offset(void *dev, int dev_type) offset = CONTAINER_HDR_NAND_OFFSET; } else if (dev_type == QSPI_NOR_DEV) { offset = CONTAINER_HDR_QSPI_OFFSET + 0x08000000; + } else if (dev_type == ROM_API_DEV) { + offset = (unsigned long)dev; } return offset; @@ -158,11 +173,12 @@ static int get_imageset_end(void *dev, int dev_type) { unsigned long offset1 = 0, offset2 = 0; int value_container[2]; + u16 hdr_length; offset1 = get_boot_device_offset(dev, dev_type); offset2 = CONTAINER_HDR_ALIGNMENT + offset1; - value_container[0] = get_container_size(dev, dev_type, offset1); + value_container[0] = get_dev_container_size(dev, dev_type, offset1, &hdr_length); if (value_container[0] < 0) { printf("Parse seco container failed %d\n", value_container[0]); return value_container[0]; @@ -170,7 +186,7 @@ static int get_imageset_end(void *dev, int dev_type) debug("seco container size 0x%x\n", value_container[0]); - value_container[1] = get_container_size(dev, dev_type, offset2); + value_container[1] = get_dev_container_size(dev, dev_type, offset2, &hdr_length); if (value_container[1] < 0) { debug("Parse scu container failed %d, only seco container\n", value_container[1]); @@ -247,3 +263,17 @@ unsigned long spl_nor_get_uboot_base(void) return end; } #endif + +#ifdef CONFIG_SPL_BOOTROM_SUPPORT +ulong spl_romapi_get_uboot_base(u32 image_offset, u32 rom_bt_dev) +{ + ulong end; + + end = get_imageset_end((void *)(ulong)image_offset, ROM_API_DEV); + end = ROUND(end, SZ_1K); + + printf("Load image from 0x%lx by ROM_API\n", end); + + return end; +} +#endif diff --git a/arch/arm/mach-imx/imx8ulp/soc.c b/arch/arm/mach-imx/imx8ulp/soc.c index f14c6b421a..3029589d5f 100644 --- a/arch/arm/mach-imx/imx8ulp/soc.c +++ b/arch/arm/mach-imx/imx8ulp/soc.c @@ -12,6 +12,8 @@ DECLARE_GLOBAL_DATA_PTR; +struct rom_api *g_rom_api = (struct rom_api *)0x1980; + u32 get_cpu_rev(void) { return (MXC_CPU_IMX8ULP << 12) | CHIP_REV_1_0; diff --git a/arch/arm/mach-imx/spl_imx_romapi.c b/arch/arm/mach-imx/spl_imx_romapi.c index d2085dabd3..d827de375a 100644 --- a/arch/arm/mach-imx/spl_imx_romapi.c +++ b/arch/arm/mach-imx/spl_imx_romapi.c @@ -10,11 +10,44 @@ #include #include #include - +#include #include DECLARE_GLOBAL_DATA_PTR; +/* Caller need ensure the offset and size to align with page size */ +ulong spl_romapi_raw_seekable_read(u32 offset, u32 size, void *buf) +{ + volatile gd_t *pgd = gd; + int ret; + + debug("%s 0x%x, size 0x%x\n", __func__, offset, size); + + ret = g_rom_api->download_image(buf, offset, size, + ((uintptr_t)buf) ^ offset ^ size); + + set_gd(pgd); + + if (ret == ROM_API_OKAY) + return size; + + printf("%s Failure when load 0x%x, size 0x%x\n", __func__, offset, size); + + return 0; +} + +ulong __weak spl_romapi_get_uboot_base(u32 image_offset, u32 rom_bt_dev) +{ + u32 offset; + + if (((rom_bt_dev >> 16) & 0xff) == BT_DEV_TYPE_FLEXSPINOR) + offset = CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR * 512; + else + offset = image_offset + CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR * 512 - 0x8000; + + return offset; +} + static int is_boot_from_stream_device(u32 boot) { u32 interface; @@ -34,25 +67,12 @@ static ulong spl_romapi_read_seekable(struct spl_load_info *load, void *buf) { u32 pagesize = *(u32 *)load->priv; - volatile gd_t *pgd = gd; ulong byte = count * pagesize; - int ret; u32 offset; offset = sector * pagesize; - debug("ROM API load from 0x%x, size 0x%x\n", offset, (u32)byte); - - ret = g_rom_api->download_image(buf, offset, byte, - ((uintptr_t)buf) ^ offset ^ byte); - set_gd(pgd); - - if (ret == ROM_API_OKAY) - return count; - - printf("ROM API Failure when load 0x%x\n", offset); - - return 0; + return spl_romapi_raw_seekable_read(offset, byte, buf) / pagesize; } static int spl_romapi_load_image_seekable(struct spl_image_info *spl_image, @@ -85,11 +105,7 @@ static int spl_romapi_load_image_seekable(struct spl_image_info *spl_image, printf("image offset 0x%x, pagesize 0x%x, ivt offset 0x%x\n", image_offset, pagesize, offset); - if (((rom_bt_dev >> 16) & 0xff) == BT_DEV_TYPE_FLEXSPINOR) - offset = CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR * 512; - else - offset = image_offset + - CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR * 512 - 0x8000; + offset = spl_romapi_get_uboot_base(image_offset, rom_bt_dev); size = ALIGN(sizeof(struct image_header), pagesize); ret = g_rom_api->download_image((u8 *)header, offset, size, @@ -102,16 +118,23 @@ static int spl_romapi_load_image_seekable(struct spl_image_info *spl_image, return -1; } - if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && - image_get_magic(header) == FDT_MAGIC) { + if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && image_get_magic(header) == FDT_MAGIC) { struct spl_load_info load; memset(&load, 0, sizeof(load)); load.bl_len = pagesize; load.read = spl_romapi_read_seekable; load.priv = &pagesize; - return spl_load_simple_fit(spl_image, &load, - offset / pagesize, header); + return spl_load_simple_fit(spl_image, &load, offset / pagesize, header); + } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) { + struct spl_load_info load; + + memset(&load, 0, sizeof(load)); + load.bl_len = pagesize; + load.read = spl_romapi_read_seekable; + load.priv = &pagesize; + + ret = spl_load_imx_container(spl_image, &load, offset / pagesize); } else { /* TODO */ puts("Can't support legacy image\n"); @@ -154,7 +177,7 @@ static ulong get_fit_image_size(void *fit) return last - (ulong)fit; } -u8 *search_fit_header(u8 *p, int size) +static u8 *search_fit_header(u8 *p, int size) { int i; @@ -165,6 +188,71 @@ u8 *search_fit_header(u8 *p, int size) return NULL; } +static u8 *search_container_header(u8 *p, int size) +{ + int i = 0; + u8 *hdr; + + for (i = 0; i < size; i += 4) { + hdr = p + i; + if (*(hdr + 3) == 0x87 && *hdr == 0 && (*(hdr + 1) != 0 || *(hdr + 2) != 0)) + return p + i; + } + + return NULL; +} + +static u8 *search_img_header(u8 *p, int size) +{ + if (IS_ENABLED(CONFIG_SPL_LOAD_FIT)) + return search_fit_header(p, size); + else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) + return search_container_header(p, size); + + return NULL; +} + +static u32 img_header_size(void) +{ + if (IS_ENABLED(CONFIG_SPL_LOAD_FIT)) + return sizeof(struct fdt_header); + else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) + return sizeof(struct container_hdr); + + return 0; +} + +static int img_info_size(void *img_hdr) +{ +#ifdef CONFIG_SPL_LOAD_FIT + return fit_get_size(img_hdr); +#elif defined CONFIG_SPL_LOAD_IMX_CONTAINER + struct container_hdr *container = img_hdr; + + return (container->length_lsb + (container->length_msb << 8)); +#else + return 0; +#endif +} + +static int img_total_size(void *img_hdr) +{ + if (IS_ENABLED(CONFIG_SPL_LOAD_FIT)) { + return get_fit_image_size(img_hdr); + } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) { + int total = get_container_size((ulong)img_hdr, NULL); + + if (total < 0) { + printf("invalid container image\n"); + return 0; + } + + return total; + } + + return 0; +} + static int spl_romapi_load_image_stream(struct spl_image_info *spl_image, struct spl_boot_device *bootdev) { @@ -174,7 +262,7 @@ static int spl_romapi_load_image_stream(struct spl_image_info *spl_image, int ret; int i = 0; u8 *p = (u8 *)CONFIG_SPL_IMX_ROMAPI_LOADADDR; - u8 *pfit = NULL; + u8 *phdr = NULL; int imagesize; int total; @@ -199,19 +287,19 @@ static int spl_romapi_load_image_stream(struct spl_image_info *spl_image, return -1; } - pfit = search_fit_header(p, pg); + phdr = search_img_header(p, pg); p += pg; - if (pfit) + if (phdr) break; } - if (!pfit) { - puts("Can't found uboot FIT image in 640K range \n"); + if (!phdr) { + puts("Can't found uboot image in 640K range\n"); return -1; } - if (p - pfit < sizeof(struct fdt_header)) { + if (p - phdr < img_header_size()) { ret = g_rom_api->download_image(p, 0, pg, ((uintptr_t)p) ^ pg); set_gd(pgd); @@ -223,11 +311,11 @@ static int spl_romapi_load_image_stream(struct spl_image_info *spl_image, p += pg; } - imagesize = fit_get_size(pfit); - printf("Find FIT header 0x&%p, size %d\n", pfit, imagesize); + imagesize = img_info_size(phdr); + printf("Find img info 0x&%p, size %d\n", phdr, imagesize); - if (p - pfit < imagesize) { - imagesize -= p - pfit; + if (p - phdr < imagesize) { + imagesize -= p - phdr; /*need pagesize hear after ROM fix USB problme*/ imagesize += pg - 1; imagesize /= pg; @@ -247,20 +335,21 @@ static int spl_romapi_load_image_stream(struct spl_image_info *spl_image, } } - total = get_fit_image_size(pfit); + total = img_total_size(phdr); total += 3; total &= ~0x3; - imagesize = total - (p - pfit); + imagesize = total - (p - phdr); imagesize += pagesize - 1; imagesize /= pagesize; imagesize *= pagesize; - printf("Download %d, total fit %d\n", imagesize, total); + printf("Download %d, Total size %d\n", imagesize, total); ret = g_rom_api->download_image(p, 0, imagesize, ((uintptr_t)p) ^ imagesize); + set_gd(pgd); if (ret != ROM_API_OKAY) printf("ROM download failure %d\n", imagesize); @@ -268,7 +357,12 @@ static int spl_romapi_load_image_stream(struct spl_image_info *spl_image, load.bl_len = 1; load.read = spl_ram_load_read; - return spl_load_simple_fit(spl_image, &load, (ulong)pfit, pfit); + if (IS_ENABLED(CONFIG_SPL_LOAD_FIT)) + return spl_load_simple_fit(spl_image, &load, (ulong)phdr, phdr); + else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) + return spl_load_imx_container(spl_image, &load, (ulong)phdr); + + return -1; } int board_return_to_bootrom(struct spl_image_info *spl_image, -- cgit v1.2.3 From 367ff4bc8461623234926c442c6560f323b87efa Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Sat, 7 Aug 2021 16:00:56 +0800 Subject: arm: imx8ulp: add rdc support There is xrdc inside i.MX8ULP, we need to configure permission to make sure AP non-secure world could access the resources. Signed-off-by: Peng Fan --- arch/arm/include/asm/arch-imx8ulp/sys_proto.h | 2 + arch/arm/mach-imx/imx8ulp/Makefile | 2 +- arch/arm/mach-imx/imx8ulp/rdc.c | 144 ++++++++++++++++++++++++++ 3 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 arch/arm/mach-imx/imx8ulp/rdc.c (limited to 'arch/arm/include/asm/arch-imx8ulp/sys_proto.h') diff --git a/arch/arm/include/asm/arch-imx8ulp/sys_proto.h b/arch/arm/include/asm/arch-imx8ulp/sys_proto.h index a8f632f45e..47ee46bdf4 100644 --- a/arch/arm/include/asm/arch-imx8ulp/sys_proto.h +++ b/arch/arm/include/asm/arch-imx8ulp/sys_proto.h @@ -13,4 +13,6 @@ extern unsigned long rom_pointer[]; ulong spl_romapi_raw_seekable_read(u32 offset, u32 size, void *buf); ulong spl_romapi_get_uboot_base(u32 image_offset, u32 rom_bt_dev); enum bt_mode get_boot_mode(void); +int xrdc_config_pdac(u32 bridge, u32 index, u32 dom, u32 perm); +int xrdc_config_pdac_openacc(u32 bridge, u32 index); #endif diff --git a/arch/arm/mach-imx/imx8ulp/Makefile b/arch/arm/mach-imx/imx8ulp/Makefile index 78c81d78bb..1ef6cd5c91 100644 --- a/arch/arm/mach-imx/imx8ulp/Makefile +++ b/arch/arm/mach-imx/imx8ulp/Makefile @@ -4,4 +4,4 @@ # obj-y += lowlevel_init.o -obj-y += soc.o clock.o iomux.o pcc.o cgc.o +obj-y += soc.o clock.o iomux.o pcc.o cgc.o rdc.o diff --git a/arch/arm/mach-imx/imx8ulp/rdc.c b/arch/arm/mach-imx/imx8ulp/rdc.c new file mode 100644 index 0000000000..7a098718da --- /dev/null +++ b/arch/arm/mach-imx/imx8ulp/rdc.c @@ -0,0 +1,144 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2020 NXP + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +#define XRDC_ADDR 0x292f0000 +#define MRC_OFFSET 0x2000 +#define MRC_STEP 0x200 + +#define SP(X) ((X) << 9) +#define SU(X) ((X) << 6) +#define NP(X) ((X) << 3) +#define NU(X) ((X) << 0) + +#define RWX 7 +#define RW 6 +#define R 4 +#define X 1 + +#define D7SEL_CODE (SP(RW) | SU(RW) | NP(RWX) | NU(RWX)) +#define D6SEL_CODE (SP(RW) | SU(RW) | NP(RWX)) +#define D5SEL_CODE (SP(RW) | SU(RWX)) +#define D4SEL_CODE SP(RWX) +#define D3SEL_CODE (SP(X) | SU(X) | NP(X) | NU(X)) +#define D0SEL_CODE 0 + +#define D7SEL_DAT (SP(RW) | SU(RW) | NP(RW) | NU(RW)) +#define D6SEL_DAT (SP(RW) | SU(RW) | NP(RW)) +#define D5SEL_DAT (SP(RW) | SU(RW) | NP(R) | NU(R)) +#define D4SEL_DAT (SP(RW) | SU(RW)) +#define D3SEL_DAT SP(RW) + +union dxsel_perm { + struct { + u8 dx; + u8 perm; + }; + + u32 dom_perm; +}; + +int xrdc_config_mrc_dx_perm(u32 mrc_con, u32 region, u32 dom, u32 dxsel) +{ + ulong w2_addr; + u32 val = 0; + + w2_addr = XRDC_ADDR + MRC_OFFSET + mrc_con * 0x200 + region * 0x20 + 0x8; + + val = (readl(w2_addr) & (~(7 << (3 * dom)))) | (dxsel << (3 * dom)); + writel(val, w2_addr); + + return 0; +} + +int xrdc_config_mrc_w0_w1(u32 mrc_con, u32 region, u32 w0, u32 size) +{ + ulong w0_addr, w1_addr; + + w0_addr = XRDC_ADDR + MRC_OFFSET + mrc_con * 0x200 + region * 0x20; + w1_addr = w0_addr + 4; + + if ((size % 32) != 0) + return -EINVAL; + + writel(w0 & ~0x1f, w0_addr); + writel(w0 + size - 1, w1_addr); + + return 0; +} + +int xrdc_config_mrc_w3_w4(u32 mrc_con, u32 region, u32 w3, u32 w4) +{ + ulong w3_addr = XRDC_ADDR + MRC_OFFSET + mrc_con * 0x200 + region * 0x20 + 0xC; + ulong w4_addr = w3_addr + 4; + + writel(w3, w3_addr); + writel(w4, w4_addr); + + return 0; +} + +int xrdc_config_pdac_openacc(u32 bridge, u32 index) +{ + ulong w0_addr; + u32 val; + + switch (bridge) { + case 3: + w0_addr = XRDC_ADDR + 0x1000 + 0x8 * index; + break; + case 4: + w0_addr = XRDC_ADDR + 0x1400 + 0x8 * index; + break; + case 5: + w0_addr = XRDC_ADDR + 0x1800 + 0x8 * index; + break; + default: + return -EINVAL; + } + writel(0xffffff, w0_addr); + + val = readl(w0_addr + 4); + writel(val | BIT(31), w0_addr + 4); + + return 0; +} + +int xrdc_config_pdac(u32 bridge, u32 index, u32 dom, u32 perm) +{ + ulong w0_addr; + u32 val; + + switch (bridge) { + case 3: + w0_addr = XRDC_ADDR + 0x1000 + 0x8 * index; + break; + case 4: + w0_addr = XRDC_ADDR + 0x1400 + 0x8 * index; + break; + case 5: + w0_addr = XRDC_ADDR + 0x1800 + 0x8 * index; + break; + default: + return -EINVAL; + } + val = readl(w0_addr); + writel((val & ~(0x7 << (dom * 3))) | (perm << (dom * 3)), w0_addr); + + val = readl(w0_addr + 4); + writel(val | BIT(31), w0_addr + 4); + + return 0; +} -- cgit v1.2.3 From 619412ab54d1b4c27f93663535dbb287b8368e12 Mon Sep 17 00:00:00 2001 From: Ye Li Date: Sat, 7 Aug 2021 16:01:01 +0800 Subject: arm: iMX8ULP: Add boot device relevant functions Read from ROM API to get current boot device. Signed-off-by: Ye Li Signed-off-by: Peng Fan --- arch/arm/include/asm/arch-imx8ulp/sys_proto.h | 1 + arch/arm/mach-imx/imx8ulp/soc.c | 84 +++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) (limited to 'arch/arm/include/asm/arch-imx8ulp/sys_proto.h') diff --git a/arch/arm/include/asm/arch-imx8ulp/sys_proto.h b/arch/arm/include/asm/arch-imx8ulp/sys_proto.h index 47ee46bdf4..1a142dce72 100644 --- a/arch/arm/include/asm/arch-imx8ulp/sys_proto.h +++ b/arch/arm/include/asm/arch-imx8ulp/sys_proto.h @@ -15,4 +15,5 @@ ulong spl_romapi_get_uboot_base(u32 image_offset, u32 rom_bt_dev); enum bt_mode get_boot_mode(void); int xrdc_config_pdac(u32 bridge, u32 index, u32 dom, u32 perm); int xrdc_config_pdac_openacc(u32 bridge, u32 index); +enum boot_device get_boot_device(void); #endif diff --git a/arch/arm/mach-imx/imx8ulp/soc.c b/arch/arm/mach-imx/imx8ulp/soc.c index 8828a94318..add4618440 100644 --- a/arch/arm/mach-imx/imx8ulp/soc.c +++ b/arch/arm/mach-imx/imx8ulp/soc.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,89 @@ DECLARE_GLOBAL_DATA_PTR; struct rom_api *g_rom_api = (struct rom_api *)0x1980; +enum boot_device get_boot_device(void) +{ + volatile gd_t *pgd = gd; + int ret; + u32 boot; + u16 boot_type; + u8 boot_instance; + enum boot_device boot_dev = SD1_BOOT; + + ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot, + ((uintptr_t)&boot) ^ QUERY_BT_DEV); + set_gd(pgd); + + if (ret != ROM_API_OKAY) { + puts("ROMAPI: failure at query_boot_info\n"); + return -1; + } + + boot_type = boot >> 16; + boot_instance = (boot >> 8) & 0xff; + + switch (boot_type) { + case BT_DEV_TYPE_SD: + boot_dev = boot_instance + SD1_BOOT; + break; + case BT_DEV_TYPE_MMC: + boot_dev = boot_instance + MMC1_BOOT; + break; + case BT_DEV_TYPE_NAND: + boot_dev = NAND_BOOT; + break; + case BT_DEV_TYPE_FLEXSPINOR: + boot_dev = QSPI_BOOT; + break; + case BT_DEV_TYPE_USB: + boot_dev = USB_BOOT; + break; + default: + break; + } + + return boot_dev; +} + +bool is_usb_boot(void) +{ + return get_boot_device() == USB_BOOT; +} + +#ifdef CONFIG_ENV_IS_IN_MMC +__weak int board_mmc_get_env_dev(int devno) +{ + return devno; +} + +int mmc_get_env_dev(void) +{ + volatile gd_t *pgd = gd; + int ret; + u32 boot; + u16 boot_type; + u8 boot_instance; + + ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot, + ((uintptr_t)&boot) ^ QUERY_BT_DEV); + set_gd(pgd); + + if (ret != ROM_API_OKAY) { + puts("ROMAPI: failure at query_boot_info\n"); + return CONFIG_SYS_MMC_ENV_DEV; + } + + boot_type = boot >> 16; + boot_instance = (boot >> 8) & 0xff; + + /* If not boot from sd/mmc, use default value */ + if (boot_type != BOOT_TYPE_SD && boot_type != BOOT_TYPE_MMC) + return env_get_ulong("mmcdev", 10, CONFIG_SYS_MMC_ENV_DEV); + + return board_mmc_get_env_dev(boot_instance); +} +#endif + u32 get_cpu_rev(void) { return (MXC_CPU_IMX8ULP << 12) | CHIP_REV_1_0; -- cgit v1.2.3