Commit 60f666e22c37a2d3b430570f7bb3591b79680204

Authored by Andrew F. Davis
Committed by Lokesh Vutla
1 parent 51754ac94a

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>

Showing 6 changed files with 155 additions and 120 deletions Side-by-side Diff

arch/arm/include/asm/omap_common.h
... ... @@ -662,6 +662,11 @@
662 662 /* Initialize general purpose I2C(0) on the SoC */
663 663 void gpi2c_init(void);
664 664  
  665 +/* Common FDT Fixups */
  666 +int ft_hs_disable_rng(void *fdt, bd_t *bd);
  667 +int ft_hs_fixup_dram(void *fdt, bd_t *bd);
  668 +int ft_hs_add_tee(void *fdt, bd_t *bd);
  669 +
665 670 /* ABB */
666 671 #define OMAP_ABB_NOMINAL_OPP 0
667 672 #define OMAP_ABB_FAST_OPP 1
arch/arm/include/asm/omap_sec_common.h
... ... @@ -28,6 +28,12 @@
28 28 int secure_boot_verify_image(void **p_image, size_t *p_size);
29 29  
30 30 /*
  31 + * Return the start of secure reserved RAM, if a default start address has
  32 + * not been configured then return a region at the end of the external DRAM.
  33 + */
  34 +u32 get_sec_mem_start(void);
  35 +
  36 +/*
31 37 * Invoke a secure HAL API that allows configuration of the external memory
32 38 * firewall regions.
33 39 */
arch/arm/mach-omap2/Makefile
... ... @@ -42,5 +42,7 @@
42 42  
43 43 obj-y += mem-common.o
44 44  
  45 +obj-y += fdt-common.o
  46 +
45 47 obj-$(CONFIG_TI_SECURE_DEVICE) += sec-common.o
arch/arm/mach-omap2/fdt-common.c
  1 +/*
  2 + * Copyright 2016-2017 Texas Instruments, Inc.
  3 + *
  4 + * SPDX-License-Identifier: GPL-2.0+
  5 + */
  6 +
  7 +#include <common.h>
  8 +#include <libfdt.h>
  9 +#include <fdt_support.h>
  10 +
  11 +#include <asm/omap_common.h>
  12 +#include <asm/omap_sec_common.h>
  13 +
  14 +#ifdef CONFIG_TI_SECURE_DEVICE
  15 +
  16 +/* Give zero values if not already defined */
  17 +#ifndef TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ
  18 +#define TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ (0)
  19 +#endif
  20 +#ifndef CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ
  21 +#define CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ (0)
  22 +#endif
  23 +
  24 +int ft_hs_disable_rng(void *fdt, bd_t *bd)
  25 +{
  26 + const char *path;
  27 + int offs;
  28 + int ret;
  29 +
  30 + /* Make HW RNG reserved for secure world use */
  31 + path = "/ocp/rng";
  32 + offs = fdt_path_offset(fdt, path);
  33 + if (offs < 0) {
  34 + debug("Node %s not found.\n", path);
  35 + return 0;
  36 + }
  37 + ret = fdt_setprop_string(fdt, offs,
  38 + "status", "disabled");
  39 + if (ret < 0) {
  40 + printf("Could not add status property to node %s: %s\n",
  41 + path, fdt_strerror(ret));
  42 + return ret;
  43 + }
  44 + return 0;
  45 +}
  46 +
  47 +#if (CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE != 0)
  48 +int ft_hs_fixup_dram(void *fdt, bd_t *bd)
  49 +{
  50 + const char *path, *subpath;
  51 + int offs;
  52 + u32 sec_mem_start = get_sec_mem_start();
  53 + u32 sec_mem_size = CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE;
  54 + fdt64_t temp[2];
  55 + fdt32_t cells;
  56 +
  57 + /* Delete any original secure_reserved node */
  58 + path = "/reserved-memory/secure_reserved";
  59 + offs = fdt_path_offset(fdt, path);
  60 + if (offs >= 0)
  61 + fdt_del_node(fdt, offs);
  62 +
  63 + /* Add new secure_reserved node */
  64 + path = "/reserved-memory";
  65 + offs = fdt_path_offset(fdt, path);
  66 + if (offs < 0) {
  67 + debug("Node %s not found\n", path);
  68 + path = "/";
  69 + subpath = "reserved-memory";
  70 + offs = fdt_path_offset(fdt, path);
  71 + offs = fdt_add_subnode(fdt, offs, subpath);
  72 + if (offs < 0) {
  73 + printf("Could not create %s%s node.\n", path, subpath);
  74 + return 1;
  75 + }
  76 + path = "/reserved-memory";
  77 + offs = fdt_path_offset(fdt, path);
  78 +#ifdef CONFIG_ARMV7_LPAE
  79 + cells = cpu_to_fdt32(2);
  80 +#else
  81 + cells = cpu_to_fdt32(1);
  82 +#endif
  83 + fdt_setprop(fdt, offs, "#address-cells", &cells, sizeof(cells));
  84 + fdt_setprop(fdt, offs, "#size-cells", &cells, sizeof(cells));
  85 + fdt_setprop(fdt, offs, "ranges", NULL, 0);
  86 + }
  87 +
  88 + subpath = "secure_reserved";
  89 + offs = fdt_add_subnode(fdt, offs, subpath);
  90 + if (offs < 0) {
  91 + printf("Could not create %s%s node.\n", path, subpath);
  92 + return 1;
  93 + }
  94 +
  95 + temp[0] = cpu_to_fdt64(((u64)sec_mem_start));
  96 + temp[1] = cpu_to_fdt64(((u64)sec_mem_size));
  97 + fdt_setprop_string(fdt, offs, "compatible",
  98 + "ti,dra7-secure-memory");
  99 + fdt_setprop_string(fdt, offs, "status", "okay");
  100 + fdt_setprop(fdt, offs, "no-map", NULL, 0);
  101 + fdt_setprop(fdt, offs, "reg", temp, sizeof(temp));
  102 +
  103 + return 0;
  104 +}
  105 +#else
  106 +int ft_hs_fixup_dram(void *fdt, bd_t *bd) { return 0; }
  107 +#endif
  108 +
  109 +int ft_hs_add_tee(void *fdt, bd_t *bd)
  110 +{
  111 + const char *path, *subpath;
  112 + int offs;
  113 +
  114 + extern int tee_loaded;
  115 + if (!tee_loaded)
  116 + return 0;
  117 +
  118 + path = "/";
  119 + offs = fdt_path_offset(fdt, path);
  120 +
  121 + subpath = "firmware";
  122 + offs = fdt_add_subnode(fdt, offs, subpath);
  123 + if (offs < 0) {
  124 + printf("Could not create %s node.\n", subpath);
  125 + return 1;
  126 + }
  127 +
  128 + subpath = "optee";
  129 + offs = fdt_add_subnode(fdt, offs, subpath);
  130 + if (offs < 0) {
  131 + printf("Could not create %s node.\n", subpath);
  132 + return 1;
  133 + }
  134 +
  135 + fdt_setprop_string(fdt, offs, "compatible", "linaro,optee-tz");
  136 + fdt_setprop_string(fdt, offs, "method", "smc");
  137 +
  138 + return 0;
  139 +}
  140 +
  141 +#endif
arch/arm/mach-omap2/omap5/fdt.c
... ... @@ -90,29 +90,6 @@
90 90 return 0;
91 91 }
92 92  
93   -static int ft_hs_disable_rng(void *fdt, bd_t *bd)
94   -{
95   - const char *path;
96   - int offs;
97   - int ret;
98   -
99   - /* Make HW RNG reserved for secure world use */
100   - path = "/ocp/rng";
101   - offs = fdt_path_offset(fdt, path);
102   - if (offs < 0) {
103   - debug("Node %s not found.\n", path);
104   - return 0;
105   - }
106   - ret = fdt_setprop_string(fdt, offs,
107   - "status", "disabled");
108   - if (ret < 0) {
109   - printf("Could not add status property to node %s: %s\n",
110   - path, fdt_strerror(ret));
111   - return ret;
112   - }
113   - return 0;
114   -}
115   -
116 93 #if ((TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ != 0) || \
117 94 (CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ != 0))
118 95 static int ft_hs_fixup_sram(void *fdt, bd_t *bd)
... ... @@ -152,102 +129,6 @@
152 129 #else
153 130 static int ft_hs_fixup_sram(void *fdt, bd_t *bd) { return 0; }
154 131 #endif
155   -
156   -#if (CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE != 0)
157   -static int ft_hs_fixup_dram(void *fdt, bd_t *bd)
158   -{
159   - const char *path, *subpath;
160   - int offs;
161   - u32 sec_mem_start = CONFIG_TI_SECURE_EMIF_REGION_START;
162   - u32 sec_mem_size = CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE;
163   - fdt64_t temp[2];
164   - fdt32_t two;
165   -
166   - /* If start address is zero, place at end of DRAM */
167   - if (0 == sec_mem_start)
168   - sec_mem_start =
169   - (CONFIG_SYS_SDRAM_BASE +
170   - (omap_sdram_size() - sec_mem_size));
171   -
172   - /* Delete any original secure_reserved node */
173   - path = "/reserved-memory/secure_reserved";
174   - offs = fdt_path_offset(fdt, path);
175   - if (offs >= 0)
176   - fdt_del_node(fdt, offs);
177   -
178   - /* Add new secure_reserved node */
179   - path = "/reserved-memory";
180   - offs = fdt_path_offset(fdt, path);
181   - if (offs < 0) {
182   - debug("Node %s not found\n", path);
183   - path = "/";
184   - subpath = "reserved-memory";
185   - offs = fdt_path_offset(fdt, path);
186   - offs = fdt_add_subnode(fdt, offs, subpath);
187   - if (offs < 0) {
188   - printf("Could not create %s%s node.\n", path, subpath);
189   - return 1;
190   - }
191   - path = "/reserved-memory";
192   - offs = fdt_path_offset(fdt, path);
193   - two = cpu_to_fdt32(2);
194   - fdt_setprop(fdt, offs, "#address-cells", &two, sizeof(two));
195   - fdt_setprop(fdt, offs, "#size-cells", &two, sizeof(two));
196   - fdt_setprop(fdt, offs, "ranges", NULL, 0);
197   - }
198   -
199   - subpath = "secure_reserved";
200   - offs = fdt_add_subnode(fdt, offs, subpath);
201   - if (offs < 0) {
202   - printf("Could not create %s%s node.\n", path, subpath);
203   - return 1;
204   - }
205   -
206   - temp[0] = cpu_to_fdt64(((u64)sec_mem_start));
207   - temp[1] = cpu_to_fdt64(((u64)sec_mem_size));
208   - fdt_setprop_string(fdt, offs, "compatible",
209   - "ti,dra7-secure-memory");
210   - fdt_setprop_string(fdt, offs, "status", "okay");
211   - fdt_setprop(fdt, offs, "no-map", NULL, 0);
212   - fdt_setprop(fdt, offs, "reg", temp, sizeof(temp));
213   -
214   - return 0;
215   -}
216   -#else
217   -static int ft_hs_fixup_dram(void *fdt, bd_t *bd) { return 0; }
218   -#endif
219   -
220   -static int ft_hs_add_tee(void *fdt, bd_t *bd)
221   -{
222   - const char *path, *subpath;
223   - int offs;
224   -
225   - extern int tee_loaded;
226   - if (!tee_loaded)
227   - return 0;
228   -
229   - path = "/";
230   - offs = fdt_path_offset(fdt, path);
231   -
232   - subpath = "firmware";
233   - offs = fdt_add_subnode(fdt, offs, subpath);
234   - if (offs < 0) {
235   - printf("Could not create %s node.\n", subpath);
236   - return 1;
237   - }
238   -
239   - subpath = "optee";
240   - offs = fdt_add_subnode(fdt, offs, subpath);
241   - if (offs < 0) {
242   - printf("Could not create %s node.\n", subpath);
243   - return 1;
244   - }
245   -
246   - fdt_setprop_string(fdt, offs, "compatible", "linaro,optee-tz");
247   - fdt_setprop_string(fdt, offs, "method", "smc");
248   -
249   - return 0;
250   -}
251 132  
252 133 static void ft_hs_fixups(void *fdt, bd_t *bd)
253 134 {
arch/arm/mach-omap2/sec-common.c
... ... @@ -174,7 +174,7 @@
174 174 return result;
175 175 }
176 176  
177   -static u32 get_sec_mem_start(void)
  177 +u32 get_sec_mem_start(void)
178 178 {
179 179 u32 sec_mem_start = CONFIG_TI_SECURE_EMIF_REGION_START;
180 180 u32 sec_mem_size = CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE;