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 <afd@ti.com>
This commit is contained in:
Andrew F. Davis 2017-07-10 14:45:50 -05:00 committed by Tom Rini
parent 3348e0c0a6
commit 03750231a8
6 changed files with 174 additions and 120 deletions

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -0,0 +1,160 @@
/*
* Copyright 2016-2017 Texas Instruments, Inc.
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <libfdt.h>
#include <fdt_support.h>
#include <asm/omap_common.h>
#include <asm/omap_sec_common.h>
#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

View File

@ -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 */

View File

@ -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;