From: Andrew F. Davis Date: Mon, 10 Jul 2017 19:45:50 +0000 (-0500) Subject: arm: mach-omap2: Factor out common FDT fixup suport X-Git-Tag: v2017.09-rc1~164 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=03750231a84da904d6d2809a54d3147dee833f26;p=u-boot arm: mach-omap2: Factor out common FDT fixup suport Some of the fixups currently done for OMAP5 class boards are common to other OMAP family devices, move these to fdt-common.c. Signed-off-by: Andrew F. Davis --- diff --git a/arch/arm/include/asm/omap_common.h b/arch/arm/include/asm/omap_common.h index d2ca277772..ef5c481349 100644 --- a/arch/arm/include/asm/omap_common.h +++ b/arch/arm/include/asm/omap_common.h @@ -680,6 +680,11 @@ void omap_die_id(unsigned int *die_id); /* Initialize general purpose I2C(0) on the SoC */ void gpi2c_init(void); +/* Common FDT Fixups */ +int ft_hs_disable_rng(void *fdt, bd_t *bd); +int ft_hs_fixup_dram(void *fdt, bd_t *bd); +int ft_hs_add_tee(void *fdt, bd_t *bd); + /* ABB */ #define OMAP_ABB_NOMINAL_OPP 0 #define OMAP_ABB_FAST_OPP 1 diff --git a/arch/arm/include/asm/omap_sec_common.h b/arch/arm/include/asm/omap_sec_common.h index 79f1fbd2c1..76d0862270 100644 --- a/arch/arm/include/asm/omap_sec_common.h +++ b/arch/arm/include/asm/omap_sec_common.h @@ -27,6 +27,12 @@ u32 secure_rom_call(u32 service, u32 proc_id, u32 flag, ...); */ int secure_boot_verify_image(void **p_image, size_t *p_size); +/* + * Return the start of secure reserved RAM, if a default start address has + * not been configured then return a region at the end of the external DRAM. + */ +u32 get_sec_mem_start(void); + /* * Invoke a secure HAL API that allows configuration of the external memory * firewall regions. diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile index d43085ca98..d86643db34 100644 --- a/arch/arm/mach-omap2/Makefile +++ b/arch/arm/mach-omap2/Makefile @@ -45,4 +45,6 @@ obj-y += lowlevel_init.o obj-y += mem-common.o +obj-y += fdt-common.o + obj-$(CONFIG_TI_SECURE_DEVICE) += sec-common.o diff --git a/arch/arm/mach-omap2/fdt-common.c b/arch/arm/mach-omap2/fdt-common.c new file mode 100644 index 0000000000..297d4d4df5 --- /dev/null +++ b/arch/arm/mach-omap2/fdt-common.c @@ -0,0 +1,160 @@ +/* + * Copyright 2016-2017 Texas Instruments, Inc. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include + +#include +#include + +#ifdef CONFIG_TI_SECURE_DEVICE + +/* Give zero values if not already defined */ +#ifndef TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ +#define TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ (0) +#endif +#ifndef CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ +#define CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ (0) +#endif + +int ft_hs_disable_rng(void *fdt, bd_t *bd) +{ + const char *path; + int offs; + int ret; + + /* Make HW RNG reserved for secure world use */ + path = "/ocp/rng"; + offs = fdt_path_offset(fdt, path); + if (offs < 0) { + debug("Node %s not found.\n", path); + return 0; + } + ret = fdt_setprop_string(fdt, offs, + "status", "disabled"); + if (ret < 0) { + printf("Could not add status property to node %s: %s\n", + path, fdt_strerror(ret)); + return ret; + } + return 0; +} + +#if (CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE != 0) +/* + * fdt_pack_reg - pack address and size array into the "reg"-suitable stream + */ +static int fdt_pack_reg(const void *fdt, void *buf, u64 address, u64 size) +{ + int address_cells = fdt_address_cells(fdt, 0); + int size_cells = fdt_size_cells(fdt, 0); + char *p = buf; + + if (address_cells == 2) + *(fdt64_t *)p = cpu_to_fdt64(address); + else + *(fdt32_t *)p = cpu_to_fdt32(address); + p += 4 * address_cells; + + if (size_cells == 2) + *(fdt64_t *)p = cpu_to_fdt64(size); + else + *(fdt32_t *)p = cpu_to_fdt32(size); + p += 4 * size_cells; + + return p - (char *)buf; +} + +int ft_hs_fixup_dram(void *fdt, bd_t *bd) +{ + const char *path, *subpath; + int offs, len; + u32 sec_mem_start = get_sec_mem_start(); + u32 sec_mem_size = CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE; + fdt32_t address_cells = cpu_to_fdt32(fdt_address_cells(fdt, 0)); + fdt32_t size_cells = cpu_to_fdt32(fdt_size_cells(fdt, 0)); + u8 temp[16]; /* Up to 64-bit address + 64-bit size */ + + /* Delete any original secure_reserved node */ + path = "/reserved-memory/secure_reserved"; + offs = fdt_path_offset(fdt, path); + if (offs >= 0) + fdt_del_node(fdt, offs); + + /* Add new secure_reserved node */ + path = "/reserved-memory"; + offs = fdt_path_offset(fdt, path); + if (offs < 0) { + debug("Node %s not found\n", path); + path = "/"; + subpath = "reserved-memory"; + offs = fdt_path_offset(fdt, path); + offs = fdt_add_subnode(fdt, offs, subpath); + if (offs < 0) { + printf("Could not create %s%s node.\n", path, subpath); + return 1; + } + path = "/reserved-memory"; + offs = fdt_path_offset(fdt, path); + + fdt_setprop(fdt, offs, "#address-cells", &address_cells, sizeof(address_cells)); + fdt_setprop(fdt, offs, "#size-cells", &size_cells, sizeof(size_cells)); + fdt_setprop(fdt, offs, "ranges", NULL, 0); + } + + subpath = "secure_reserved"; + offs = fdt_add_subnode(fdt, offs, subpath); + if (offs < 0) { + printf("Could not create %s%s node.\n", path, subpath); + return 1; + } + + fdt_setprop_string(fdt, offs, "compatible", "ti,secure-memory"); + fdt_setprop_string(fdt, offs, "status", "okay"); + fdt_setprop(fdt, offs, "no-map", NULL, 0); + len = fdt_pack_reg(fdt, temp, sec_mem_start, sec_mem_size); + fdt_setprop(fdt, offs, "reg", temp, len); + + return 0; +} +#else +int ft_hs_fixup_dram(void *fdt, bd_t *bd) { return 0; } +#endif + +int ft_hs_add_tee(void *fdt, bd_t *bd) +{ + const char *path, *subpath; + int offs; + + extern int tee_loaded; + if (!tee_loaded) + return 0; + + path = "/"; + offs = fdt_path_offset(fdt, path); + + subpath = "firmware"; + offs = fdt_add_subnode(fdt, offs, subpath); + if (offs < 0) { + printf("Could not create %s node.\n", subpath); + return 1; + } + + subpath = "optee"; + offs = fdt_add_subnode(fdt, offs, subpath); + if (offs < 0) { + printf("Could not create %s node.\n", subpath); + return 1; + } + + fdt_setprop_string(fdt, offs, "compatible", "linaro,optee-tz"); + fdt_setprop_string(fdt, offs, "method", "smc"); + + return 0; +} + +#endif diff --git a/arch/arm/mach-omap2/omap5/fdt.c b/arch/arm/mach-omap2/omap5/fdt.c index 7a3a8db517..1e556da9be 100644 --- a/arch/arm/mach-omap2/omap5/fdt.c +++ b/arch/arm/mach-omap2/omap5/fdt.c @@ -90,29 +90,6 @@ static int ft_hs_fixup_crossbar(void *fdt, bd_t *bd) return 0; } -static int ft_hs_disable_rng(void *fdt, bd_t *bd) -{ - const char *path; - int offs; - int ret; - - /* Make HW RNG reserved for secure world use */ - path = "/ocp/rng"; - offs = fdt_path_offset(fdt, path); - if (offs < 0) { - debug("Node %s not found.\n", path); - return 0; - } - ret = fdt_setprop_string(fdt, offs, - "status", "disabled"); - if (ret < 0) { - printf("Could not add status property to node %s: %s\n", - path, fdt_strerror(ret)); - return ret; - } - return 0; -} - #if ((TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ != 0) || \ (CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ != 0)) static int ft_hs_fixup_sram(void *fdt, bd_t *bd) @@ -153,102 +130,6 @@ static int ft_hs_fixup_sram(void *fdt, bd_t *bd) static int ft_hs_fixup_sram(void *fdt, bd_t *bd) { return 0; } #endif -#if (CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE != 0) -static int ft_hs_fixup_dram(void *fdt, bd_t *bd) -{ - const char *path, *subpath; - int offs; - u32 sec_mem_start = CONFIG_TI_SECURE_EMIF_REGION_START; - u32 sec_mem_size = CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE; - fdt64_t temp[2]; - fdt32_t two; - - /* If start address is zero, place at end of DRAM */ - if (0 == sec_mem_start) - sec_mem_start = - (CONFIG_SYS_SDRAM_BASE + - (omap_sdram_size() - sec_mem_size)); - - /* Delete any original secure_reserved node */ - path = "/reserved-memory/secure_reserved"; - offs = fdt_path_offset(fdt, path); - if (offs >= 0) - fdt_del_node(fdt, offs); - - /* Add new secure_reserved node */ - path = "/reserved-memory"; - offs = fdt_path_offset(fdt, path); - if (offs < 0) { - debug("Node %s not found\n", path); - path = "/"; - subpath = "reserved-memory"; - offs = fdt_path_offset(fdt, path); - offs = fdt_add_subnode(fdt, offs, subpath); - if (offs < 0) { - printf("Could not create %s%s node.\n", path, subpath); - return 1; - } - path = "/reserved-memory"; - offs = fdt_path_offset(fdt, path); - two = cpu_to_fdt32(2); - fdt_setprop(fdt, offs, "#address-cells", &two, sizeof(two)); - fdt_setprop(fdt, offs, "#size-cells", &two, sizeof(two)); - fdt_setprop(fdt, offs, "ranges", NULL, 0); - } - - subpath = "secure_reserved"; - offs = fdt_add_subnode(fdt, offs, subpath); - if (offs < 0) { - printf("Could not create %s%s node.\n", path, subpath); - return 1; - } - - temp[0] = cpu_to_fdt64(((u64)sec_mem_start)); - temp[1] = cpu_to_fdt64(((u64)sec_mem_size)); - fdt_setprop_string(fdt, offs, "compatible", - "ti,dra7-secure-memory"); - fdt_setprop_string(fdt, offs, "status", "okay"); - fdt_setprop(fdt, offs, "no-map", NULL, 0); - fdt_setprop(fdt, offs, "reg", temp, sizeof(temp)); - - return 0; -} -#else -static int ft_hs_fixup_dram(void *fdt, bd_t *bd) { return 0; } -#endif - -static int ft_hs_add_tee(void *fdt, bd_t *bd) -{ - const char *path, *subpath; - int offs; - - extern int tee_loaded; - if (!tee_loaded) - return 0; - - path = "/"; - offs = fdt_path_offset(fdt, path); - - subpath = "firmware"; - offs = fdt_add_subnode(fdt, offs, subpath); - if (offs < 0) { - printf("Could not create %s node.\n", subpath); - return 1; - } - - subpath = "optee"; - offs = fdt_add_subnode(fdt, offs, subpath); - if (offs < 0) { - printf("Could not create %s node.\n", subpath); - return 1; - } - - fdt_setprop_string(fdt, offs, "compatible", "linaro,optee-tz"); - fdt_setprop_string(fdt, offs, "method", "smc"); - - return 0; -} - static void ft_hs_fixups(void *fdt, bd_t *bd) { /* Check we are running on an HS/EMU device type */ diff --git a/arch/arm/mach-omap2/sec-common.c b/arch/arm/mach-omap2/sec-common.c index f230c9ea4e..030b36f332 100644 --- a/arch/arm/mach-omap2/sec-common.c +++ b/arch/arm/mach-omap2/sec-common.c @@ -176,7 +176,7 @@ auth_exit: return result; } -static u32 get_sec_mem_start(void) +u32 get_sec_mem_start(void) { u32 sec_mem_start = CONFIG_TI_SECURE_EMIF_REGION_START; u32 sec_mem_size = CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE;