blob: 3f9f135bcb2dcc78bf338d8bbf91d0fa162b3807 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +09002/*
Masahiro Yamadaa7c901f2016-07-22 13:38:31 +09003 * Copyright (C) 2012-2015 Panasonic Corporation
4 * Copyright (C) 2015-2016 Socionext Inc.
5 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +09006 */
7
8#include <config.h>
9#include <linux/linkage.h>
Masahiro Yamada951ed552015-02-27 02:27:06 +090010#include <linux/sizes.h>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090011#include <asm/system.h>
Masahiro Yamadaefdf3402016-01-09 01:51:13 +090012
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090013ENTRY(lowlevel_init)
14 mov r8, lr @ persevere link reg across call
15
16 /*
17 * The UniPhier Boot ROM loads SPL code to the L2 cache.
18 * But CPUs can only do instruction fetch now because start.S has
19 * cleared C and M bits.
20 * First we need to turn on MMU and Dcache again to get back
21 * data access to L2.
22 */
Masahiro Yamada5d3d9962015-03-23 00:07:30 +090023 mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register)
24 orr r0, r0, #(CR_C | CR_M) @ enable MMU and Dcache
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090025 mcr p15, 0, r0, c1, c0, 0
26
Masahiro Yamada6ba10942017-08-13 09:01:14 +090027#ifdef CONFIG_DEBUG_LL
28 bl debug_ll_init
29#endif
30
Masahiro Yamada3a1e4422016-06-24 11:51:38 +090031 bl setup_init_ram @ RAM area for stack and page table
Masahiro Yamada1c1646a2016-02-02 21:11:29 +090032
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090033 /*
34 * Now we are using the page table embedded in the Boot ROM.
Masahiro Yamadad3c14612017-08-13 09:01:13 +090035 * What we need to do next is to create a page table and switch
36 * over to it.
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090037 */
Masahiro Yamada1c1646a2016-02-02 21:11:29 +090038 bl create_page_table
Hans de Goede076e8412016-04-09 13:53:48 +020039 bl __v7_flush_dcache_all
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090040
41 /* Disable MMU and Dcache before switching Page Table */
Masahiro Yamada5d3d9962015-03-23 00:07:30 +090042 mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090043 bic r0, r0, #(CR_C | CR_M) @ disable MMU and Dcache
44 mcr p15, 0, r0, c1, c0, 0
45
46 bl enable_mmu
47
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090048 mov lr, r8 @ restore link
49 mov pc, lr @ back to my caller
50ENDPROC(lowlevel_init)
51
52ENTRY(enable_mmu)
53 mrc p15, 0, r0, c2, c0, 2 @ TTBCR (Translation Table Base Control Register)
54 bic r0, r0, #0x37
55 orr r0, r0, #0x20 @ disable TTBR1
56 mcr p15, 0, r0, c2, c0, 2
57
Masahiro Yamada1c1646a2016-02-02 21:11:29 +090058 orr r0, r12, #0x8 @ Outer Cacheability for table walks: WBWA
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090059 mcr p15, 0, r0, c2, c0, 0 @ TTBR0
60
61 mov r0, #0
62 mcr p15, 0, r0, c8, c7, 0 @ invalidate TLBs
63
64 mov r0, #-1 @ manager for all domains (No permission check)
65 mcr p15, 0, r0, c3, c0, 0 @ DACR (Domain Access Control Register)
66
67 dsb
68 isb
69 /*
70 * MMU on:
71 * TLBs was already invalidated in "../start.S"
72 * So, we don't need to invalidate it here.
73 */
Masahiro Yamada5d3d9962015-03-23 00:07:30 +090074 mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090075 orr r0, r0, #(CR_C | CR_M) @ MMU and Dcache enable
76 mcr p15, 0, r0, c1, c0, 0
77
78 mov pc, lr
79ENDPROC(enable_mmu)
80
Masahiro Yamada951ed552015-02-27 02:27:06 +090081/*
82 * For PH1-Pro4 or older SoCs, the size of WAY is 32KB.
83 * It is large enough for tmp RAM.
84 */
Masahiro Yamada1c1646a2016-02-02 21:11:29 +090085#define BOOT_RAM_SIZE (SZ_32K)
86#define BOOT_RAM_BASE ((CONFIG_SPL_STACK) - (BOOT_RAM_SIZE))
Masahiro Yamada6caf51c2016-08-10 16:08:39 +090087#define BOOT_RAM_WAYS (0x00000100) @ way 8
88
89#define SSCO_BASE 0x506c0000
90#define SSCOPE 0x244
91#define SSCOQM 0x248
92#define SSCOQAD 0x24c
93#define SSCOQSZ 0x250
94#define SSCOQWN 0x258
95#define SSCOPPQSEF 0x25c
96#define SSCOLPQS 0x260
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090097
98ENTRY(setup_init_ram)
Masahiro Yamada6caf51c2016-08-10 16:08:39 +090099 ldr r1, = SSCO_BASE
100
101 /* Touch to zero for the boot way */
1020: ldr r0, = 0x00408006 @ touch to zero with address range
103 str r0, [r1, #SSCOQM]
Masahiro Yamada1c1646a2016-02-02 21:11:29 +0900104 ldr r0, = BOOT_RAM_BASE
Masahiro Yamada6caf51c2016-08-10 16:08:39 +0900105 str r0, [r1, #SSCOQAD]
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900106 ldr r0, = BOOT_RAM_SIZE
Masahiro Yamada6caf51c2016-08-10 16:08:39 +0900107 str r0, [r1, #SSCOQSZ]
108 ldr r0, = BOOT_RAM_WAYS
109 str r0, [r1, #SSCOQWN]
110 ldr r0, [r1, #SSCOPPQSEF]
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900111 cmp r0, #0 @ check if the command is successfully set
Masahiro Yamada5d3d9962015-03-23 00:07:30 +0900112 bne 0b @ try again if an error occurs
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900113
Masahiro Yamada6caf51c2016-08-10 16:08:39 +09001141: ldr r0, [r1, #SSCOLPQS]
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900115 cmp r0, #0x4
116 bne 1b @ wait until the operation is completed
Masahiro Yamada6caf51c2016-08-10 16:08:39 +0900117 str r0, [r1, #SSCOLPQS] @ clear the complete notification flag
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900118
119 mov pc, lr
120ENDPROC(setup_init_ram)
Masahiro Yamada1c1646a2016-02-02 21:11:29 +0900121
122#define DEVICE 0x00002002 /* Non-shareable Device */
123#define NORMAL 0x0000000e /* Normal Memory Write-Back, No Write-Allocate */
124
125ENTRY(create_page_table)
126 ldr r0, = DEVICE
127 ldr r1, = BOOT_RAM_BASE
128 mov r12, r1 @ r12 is preserved during D-cache flush
1290: str r0, [r1], #4 @ specify all the sections as Device
130 adds r0, r0, #0x00100000
131 bcc 0b
132
133 ldr r0, = NORMAL
134 str r0, [r12] @ mark the first section as Normal
135 add r0, r0, #0x00100000
136 str r0, [r12, #4] @ mark the second section as Normal
137 mov pc, lr
138ENDPROC(create_page_table)