1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35#include <common.h>
36#include <asm/io.h>
37#include <asm/arch/sys_proto.h>
38#include <asm/arch/mem.h>
39#include <asm/cache.h>
40#include <asm/armv7.h>
41#include <asm/arch/gpio.h>
42
43
44extern omap3_sysinfo sysinfo;
45static void omap3_setup_aux_cr(void);
46static void omap3_invalidate_l2_cache_secure(void);
47
48static const struct gpio_bank gpio_bank_34xx[6] = {
49 { (void *)OMAP34XX_GPIO1_BASE, METHOD_GPIO_24XX },
50 { (void *)OMAP34XX_GPIO2_BASE, METHOD_GPIO_24XX },
51 { (void *)OMAP34XX_GPIO3_BASE, METHOD_GPIO_24XX },
52 { (void *)OMAP34XX_GPIO4_BASE, METHOD_GPIO_24XX },
53 { (void *)OMAP34XX_GPIO5_BASE, METHOD_GPIO_24XX },
54 { (void *)OMAP34XX_GPIO6_BASE, METHOD_GPIO_24XX },
55};
56
57const struct gpio_bank *const omap_gpio_bank = gpio_bank_34xx;
58
59
60
61
62
63static inline void delay(unsigned long loops)
64{
65 __asm__ volatile ("1:\n" "subs %0, %1, #1\n"
66 "bne 1b":"=r" (loops):"0"(loops));
67}
68
69
70
71
72
73
74void secure_unlock_mem(void)
75{
76 struct pm *pm_rt_ape_base = (struct pm *)PM_RT_APE_BASE_ADDR_ARM;
77 struct pm *pm_gpmc_base = (struct pm *)PM_GPMC_BASE_ADDR_ARM;
78 struct pm *pm_ocm_ram_base = (struct pm *)PM_OCM_RAM_BASE_ADDR_ARM;
79 struct pm *pm_iva2_base = (struct pm *)PM_IVA2_BASE_ADDR_ARM;
80 struct sms *sms_base = (struct sms *)OMAP34XX_SMS_BASE;
81
82
83 writel(UNLOCK_1, &pm_rt_ape_base->req_info_permission_1);
84 writel(UNLOCK_1, &pm_rt_ape_base->read_permission_0);
85 writel(UNLOCK_1, &pm_rt_ape_base->wirte_permission_0);
86 writel(UNLOCK_2, &pm_rt_ape_base->addr_match_1);
87
88 writel(UNLOCK_3, &pm_gpmc_base->req_info_permission_0);
89 writel(UNLOCK_3, &pm_gpmc_base->read_permission_0);
90 writel(UNLOCK_3, &pm_gpmc_base->wirte_permission_0);
91
92 writel(UNLOCK_3, &pm_ocm_ram_base->req_info_permission_0);
93 writel(UNLOCK_3, &pm_ocm_ram_base->read_permission_0);
94 writel(UNLOCK_3, &pm_ocm_ram_base->wirte_permission_0);
95 writel(UNLOCK_2, &pm_ocm_ram_base->addr_match_2);
96
97
98 writel(UNLOCK_3, &pm_iva2_base->req_info_permission_0);
99 writel(UNLOCK_3, &pm_iva2_base->read_permission_0);
100 writel(UNLOCK_3, &pm_iva2_base->wirte_permission_0);
101
102
103 writel(UNLOCK_1, &sms_base->rg_att0);
104}
105
106
107
108
109
110
111
112void secureworld_exit()
113{
114 unsigned long i;
115
116
117 __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 2":"=r"(i));
118
119 __asm__ __volatile__("orr %0, %0, #0xC00":"=r"(i));
120
121
122
123
124 __asm__ __volatile__("orr %0, %0, #0x70000":"=r"(i));
125 __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 2":"=r"(i));
126
127
128 __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
129 __asm__ __volatile__("orr %0, %0, #0x10":"=r"(i));
130 __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
131
132
133 __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 0":"=r"(i));
134 __asm__ __volatile__("orr %0, %0, #0x31":"=r"(i));
135 __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 0":"=r"(i));
136}
137
138
139
140
141
142
143void try_unlock_memory()
144{
145 int mode;
146 int in_sdram = is_running_in_sdram();
147
148
149
150
151
152 mode = get_device_type();
153 if (mode == GP_DEVICE)
154 secure_unlock_mem();
155
156
157
158
159
160
161
162
163 if ((mode <= EMU_DEVICE) && (get_boot_type() == 0x1F)
164 && (!in_sdram)) {
165 secure_unlock_mem();
166 secureworld_exit();
167 }
168
169 return;
170}
171
172
173
174
175
176
177void s_init(void)
178{
179 int in_sdram = is_running_in_sdram();
180
181 watchdog_init();
182
183 try_unlock_memory();
184
185
186 omap3_setup_aux_cr();
187
188#ifndef CONFIG_SYS_L2CACHE_OFF
189
190 omap3_invalidate_l2_cache_secure();
191#endif
192
193 set_muxconf_regs();
194 delay(100);
195
196 prcm_init();
197
198 per_clocks_enable();
199
200 if (!in_sdram)
201 mem_init();
202}
203
204
205
206
207
208void wait_for_command_complete(struct watchdog *wd_base)
209{
210 int pending = 1;
211 do {
212 pending = readl(&wd_base->wwps);
213 } while (pending);
214}
215
216
217
218
219
220void watchdog_init(void)
221{
222 struct watchdog *wd2_base = (struct watchdog *)WD2_BASE;
223 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
224
225
226
227
228
229
230
231
232 sr32(&prcm_base->fclken_wkup, 5, 1, 1);
233 sr32(&prcm_base->iclken_wkup, 5, 1, 1);
234 wait_on_value(ST_WDT2, 0x20, &prcm_base->idlest_wkup, 5);
235
236 writel(WD_UNLOCK1, &wd2_base->wspr);
237 wait_for_command_complete(wd2_base);
238 writel(WD_UNLOCK2, &wd2_base->wspr);
239}
240
241
242
243
244void abort(void)
245{
246}
247
248#ifdef CONFIG_NAND_OMAP_GPMC
249
250
251
252static int do_switch_ecc(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
253{
254 if (argc != 2)
255 goto usage;
256 if (strncmp(argv[1], "hw", 2) == 0)
257 omap_nand_switch_ecc(1);
258 else if (strncmp(argv[1], "sw", 2) == 0)
259 omap_nand_switch_ecc(0);
260 else
261 goto usage;
262
263 return 0;
264
265usage:
266 printf ("Usage: nandecc %s\n", cmdtp->usage);
267 return 1;
268}
269
270U_BOOT_CMD(
271 nandecc, 2, 1, do_switch_ecc,
272 "switch OMAP3 NAND ECC calculation algorithm",
273 "[hw/sw] - Switch between NAND hardware (hw) or software (sw) ecc algorithm"
274);
275
276#endif
277
278#ifdef CONFIG_DISPLAY_BOARDINFO
279
280
281
282int checkboard (void)
283{
284 char *mem_s ;
285
286 if (is_mem_sdr())
287 mem_s = "mSDR";
288 else
289 mem_s = "LPDDR";
290
291 printf("%s + %s/%s\n", sysinfo.board_string, mem_s,
292 sysinfo.nand_string);
293
294 return 0;
295}
296#endif
297
298static void omap3_emu_romcode_call(u32 service_id, u32 *parameters)
299{
300 u32 i, num_params = *parameters;
301 u32 *sram_scratch_space = (u32 *)OMAP3_PUBLIC_SRAM_SCRATCH_AREA;
302
303
304
305
306
307 for (i = 0; i < num_params; i++) {
308 __raw_writel(*parameters, sram_scratch_space);
309 parameters++;
310 sram_scratch_space++;
311 }
312
313
314 do_omap3_emu_romcode_call(service_id, OMAP3_PUBLIC_SRAM_SCRATCH_AREA);
315}
316
317static void omap3_update_aux_cr_secure(u32 set_bits, u32 clear_bits)
318{
319 u32 acr;
320
321
322 asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
323 acr &= ~clear_bits;
324 acr |= set_bits;
325
326 if (get_device_type() == GP_DEVICE) {
327 omap3_gp_romcode_call(OMAP3_GP_ROMCODE_API_WRITE_ACR,
328 acr);
329 } else {
330 struct emu_hal_params emu_romcode_params;
331 emu_romcode_params.num_params = 1;
332 emu_romcode_params.param1 = acr;
333 omap3_emu_romcode_call(OMAP3_EMU_HAL_API_WRITE_ACR,
334 (u32 *)&emu_romcode_params);
335 }
336}
337
338static void omap3_update_aux_cr(u32 set_bits, u32 clear_bits)
339{
340 u32 acr;
341
342
343 asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
344 acr &= ~clear_bits;
345 acr |= set_bits;
346
347
348 asm volatile ("mcr p15, 0, %0, c1, c0, 1" : : "r" (acr));
349}
350
351static void omap3_setup_aux_cr(void)
352{
353
354
355
356
357
358
359
360 omap3_update_aux_cr_secure(0xE0, 0);
361}
362
363#ifndef CONFIG_SYS_L2CACHE_OFF
364
365static void omap3_invalidate_l2_cache_secure(void)
366{
367 if (get_device_type() == GP_DEVICE) {
368 omap3_gp_romcode_call(OMAP3_GP_ROMCODE_API_L2_INVAL,
369 0);
370 } else {
371 struct emu_hal_params emu_romcode_params;
372 emu_romcode_params.num_params = 1;
373 emu_romcode_params.param1 = 0;
374 omap3_emu_romcode_call(OMAP3_EMU_HAL_API_L2_INVAL,
375 (u32 *)&emu_romcode_params);
376 }
377}
378
379void v7_outer_cache_enable(void)
380{
381
382 omap3_update_aux_cr_secure(0x2, 0);
383
384
385
386
387
388
389 omap3_update_aux_cr(0x2, 0);
390}
391
392void v7_outer_cache_disable(void)
393{
394
395 omap3_update_aux_cr_secure(0, 0x2);
396
397
398
399
400
401
402 omap3_update_aux_cr(0, 0x2);
403}
404#endif
405
406#ifndef CONFIG_SYS_DCACHE_OFF
407void enable_caches(void)
408{
409
410 dcache_enable();
411}
412#endif
413