]> git.sur5r.net Git - u-boot/blob - arch/arm/cpu/armv7/omap5/fdt.c
ARM: omap5: add hooks for cpu/SoC fdt fixups
[u-boot] / arch / arm / cpu / armv7 / omap5 / fdt.c
1 /*
2  * Copyright 2016 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 #include <malloc.h>
11
12 #include <asm/omap_common.h>
13 #include <asm/arch-omap5/sys_proto.h>
14
15 #ifdef CONFIG_TI_SECURE_DEVICE
16
17 /* Give zero values if not already defined */
18 #ifndef TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ
19 #define TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ (0)
20 #endif
21 #ifndef CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ
22 #define CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ (0)
23 #endif
24
25 static u32 hs_irq_skip[] = {
26         8,      /* Secure violation reporting interrupt */
27         15,     /* One interrupt for SDMA by secure world */
28         118     /* One interrupt for Crypto DMA by secure world */
29 };
30
31 static int ft_hs_fixup_crossbar(void *fdt, bd_t *bd)
32 {
33         const char *path;
34         int offs;
35         int ret;
36         int len, i, old_cnt, new_cnt;
37         u32 *temp;
38         const u32 *p_data;
39
40         /*
41          * Increase the size of the fdt
42          * so we have some breathing room
43          */
44         ret = fdt_increase_size(fdt, 512);
45         if (ret < 0) {
46                 printf("Could not increase size of device tree: %s\n",
47                        fdt_strerror(ret));
48                 return ret;
49         }
50
51         /* Reserve IRQs that are used/needed by secure world */
52         path = "/ocp/crossbar";
53         offs = fdt_path_offset(fdt, path);
54         if (offs < 0) {
55                 debug("Node %s not found.\n", path);
56                 return 0;
57         }
58
59         /* Get current entries */
60         p_data = fdt_getprop(fdt, offs, "ti,irqs-skip", &len);
61         if (p_data)
62                 old_cnt = len / sizeof(u32);
63         else
64                 old_cnt = 0;
65
66         new_cnt = sizeof(hs_irq_skip) /
67                                 sizeof(hs_irq_skip[0]);
68
69         /* Create new/updated skip list for HS parts */
70         temp = malloc(sizeof(u32) * (old_cnt + new_cnt));
71         for (i = 0; i < new_cnt; i++)
72                 temp[i] = cpu_to_fdt32(hs_irq_skip[i]);
73         for (i = 0; i < old_cnt; i++)
74                 temp[i + new_cnt] = p_data[i];
75
76         /* Blow away old data and set new data */
77         fdt_delprop(fdt, offs, "ti,irqs-skip");
78         ret = fdt_setprop(fdt, offs, "ti,irqs-skip",
79                           temp,
80                           (old_cnt + new_cnt) * sizeof(u32));
81         free(temp);
82
83         /* Check if the update worked */
84         if (ret < 0) {
85                 printf("Could not add ti,irqs-skip property to node %s: %s\n",
86                        path, fdt_strerror(ret));
87                 return ret;
88         }
89
90         return 0;
91 }
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 #if ((TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ != 0) || \
117     (CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ != 0))
118 static int ft_hs_fixup_sram(void *fdt, bd_t *bd)
119 {
120         const char *path;
121         int offs;
122         int ret;
123         u32 temp[2];
124
125         /*
126          * Update SRAM reservations on secure devices. The OCMC RAM
127          * is always reserved for secure use from the start of that
128          * memory region
129          */
130         path = "/ocp/ocmcram@40300000/sram-hs";
131         offs = fdt_path_offset(fdt, path);
132         if (offs < 0) {
133                 debug("Node %s not found.\n", path);
134                 return 0;
135         }
136
137         /* relative start offset */
138         temp[0] = cpu_to_fdt32(0);
139         /* reservation size */
140         temp[1] = cpu_to_fdt32(max(TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ,
141                                    CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ));
142         fdt_delprop(fdt, offs, "reg");
143         ret = fdt_setprop(fdt, offs, "reg", temp, 2 * sizeof(u32));
144         if (ret < 0) {
145                 printf("Could not add reg property to node %s: %s\n",
146                        path, fdt_strerror(ret));
147                 return ret;
148         }
149
150         return 0;
151 }
152 #else
153 static int ft_hs_fixup_sram(void *fdt, bd_t *bd) { return 0; }
154 #endif
155
156 static void ft_hs_fixups(void *fdt, bd_t *bd)
157 {
158         /* Check we are running on an HS/EMU device type */
159         if (GP_DEVICE != get_device_type()) {
160                 if ((ft_hs_fixup_crossbar(fdt, bd) == 0) &&
161                     (ft_hs_disable_rng(fdt, bd) == 0) &&
162                     (ft_hs_fixup_sram(fdt, bd) == 0))
163                         return;
164         } else {
165                 printf("ERROR: Incorrect device type (GP) detected!");
166         }
167         /* Fixup failed or wrong device type */
168         hang();
169 }
170 #else
171 static void ft_hs_fixups(void *fdt, bd_t *bd)
172 {
173 }
174 #endif
175
176 /*
177  * Place for general cpu/SoC FDT fixups. Board specific
178  * fixups should remain in the board files which is where
179  * this function should be called from.
180  */
181 void ft_cpu_setup(void *fdt, bd_t *bd)
182 {
183         ft_hs_fixups(fdt, bd);
184 }