armadaxp_start.S revision 1.4 1 1.4 hsuenaga /* $NetBSD: armadaxp_start.S,v 1.4 2015/04/15 10:15:40 hsuenaga Exp $ */
2 1.1 rkujawa /*******************************************************************************
3 1.1 rkujawa Copyright (C) Marvell International Ltd. and its affiliates
4 1.1 rkujawa
5 1.1 rkujawa Developed by Semihalf
6 1.1 rkujawa
7 1.1 rkujawa ********************************************************************************
8 1.1 rkujawa Marvell BSD License
9 1.1 rkujawa
10 1.1 rkujawa If you received this File from Marvell, you may opt to use, redistribute and/or
11 1.1 rkujawa modify this File under the following licensing terms.
12 1.1 rkujawa Redistribution and use in source and binary forms, with or without modification,
13 1.1 rkujawa are permitted provided that the following conditions are met:
14 1.1 rkujawa
15 1.1 rkujawa * Redistributions of source code must retain the above copyright notice,
16 1.1 rkujawa this list of conditions and the following disclaimer.
17 1.1 rkujawa
18 1.1 rkujawa * Redistributions in binary form must reproduce the above copyright
19 1.1 rkujawa notice, this list of conditions and the following disclaimer in the
20 1.1 rkujawa documentation and/or other materials provided with the distribution.
21 1.1 rkujawa
22 1.1 rkujawa * Neither the name of Marvell nor the names of its contributors may be
23 1.1 rkujawa used to endorse or promote products derived from this software without
24 1.1 rkujawa specific prior written permission.
25 1.1 rkujawa
26 1.1 rkujawa THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
27 1.1 rkujawa ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28 1.1 rkujawa WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 1.1 rkujawa DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
30 1.1 rkujawa ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 1.1 rkujawa (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 1.1 rkujawa LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
33 1.1 rkujawa ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 1.1 rkujawa (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 1.1 rkujawa SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 1.1 rkujawa
37 1.1 rkujawa *******************************************************************************/
38 1.1 rkujawa
39 1.1 rkujawa #include "opt_cputypes.h"
40 1.1 rkujawa
41 1.1 rkujawa #include <machine/asm.h>
42 1.1 rkujawa #include <arm/armreg.h>
43 1.3 matt #include <evbarm/marvell/marvellreg.h>
44 1.3 matt #include <evbarm/marvell/marvellvar.h>
45 1.3 matt #include "assym.h"
46 1.1 rkujawa
47 1.4 hsuenaga RCSID("$NetBSD: armadaxp_start.S,v 1.4 2015/04/15 10:15:40 hsuenaga Exp $")
48 1.1 rkujawa
49 1.3 matt #ifdef KERNEL_BASES_EQUAL
50 1.3 matt #error KERNEL_BASE_VIRT should not equal KERNEL_BASE_PHYS
51 1.3 matt #endif
52 1.1 rkujawa
53 1.1 rkujawa /*
54 1.1 rkujawa * We don't want to hard-code some basic things like RAM start etc.
55 1.1 rkujawa * Hence, it is important to set the following options to resanoable values
56 1.1 rkujawa * in std.armadaxp configuration file.
57 1.1 rkujawa */
58 1.1 rkujawa #if !defined(STARTUP_PAGETABLE_ADDR)
59 1.1 rkujawa #error STARTUP_PAGETABLE_ADDR not defined. Please define it in std.armadaxp
60 1.1 rkujawa #elif !defined(MEMSTART)
61 1.1 rkujawa #error MEMSTART not defined. Please define it in std.armadaxp
62 1.1 rkujawa #endif
63 1.1 rkujawa
64 1.3 matt .section .start,"ax",%progbits
65 1.1 rkujawa
66 1.1 rkujawa .global _C_LABEL(armadaxp_start)
67 1.1 rkujawa _C_LABEL(armadaxp_start):
68 1.1 rkujawa /* Move into supervisor mode and disable IRQs/FIQs. */
69 1.3 matt cpsid if, #PSR_SVC32_MODE
70 1.3 matt
71 1.1 rkujawa /* Disable MMU for a while */
72 1.1 rkujawa mrc p15, 0, r2, c1, c0, 0
73 1.3 matt movw r1, #(CPU_CONTROL_MMU_ENABLE | CPU_CONTROL_DC_ENABLE |\
74 1.3 matt CPU_CONTROL_WBUF_ENABLE | CPU_CONTROL_IC_ENABLE |\
75 1.3 matt CPU_CONTROL_BPRD_ENABLE)
76 1.3 matt bic r2, r2, r1
77 1.1 rkujawa mcr p15, 0, r2, c1, c0, 0
78 1.3 matt dsb
79 1.3 matt isb
80 1.1 rkujawa
81 1.4 hsuenaga /* Save U-Boot arguments */
82 1.4 hsuenaga adr r4, uboot_regs_pa
83 1.4 hsuenaga stmia r4!, {r0, r1, r2, r3}
84 1.4 hsuenaga
85 1.1 rkujawa /* build page table from scratch */
86 1.3 matt movw r0, #:lower16:STARTUP_PAGETABLE_ADDR
87 1.3 matt movt r0, #:upper16:STARTUP_PAGETABLE_ADDR
88 1.1 rkujawa adr r4, mmu_init_table
89 1.1 rkujawa b 3f
90 1.1 rkujawa
91 1.3 matt 2: str r3, [r0, r2]
92 1.1 rkujawa add r2, r2, #4
93 1.1 rkujawa add r3, r3, #(L1_S_SIZE)
94 1.1 rkujawa adds r1, r1, #-1
95 1.1 rkujawa bhi 2b
96 1.1 rkujawa 3:
97 1.1 rkujawa ldmia r4!, {r1,r2,r3} /* # of sections, VA, PA|attr */
98 1.1 rkujawa cmp r1, #0
99 1.3 matt bne 2b
100 1.1 rkujawa
101 1.3 matt mcr p15, 0, r0, c2, c0, 0 // Set TTBR0
102 1.3 matt #ifdef ARM_MMU_EXTENDED
103 1.3 matt mcr p15, 0, r0, c2, c0, 1 // Set TTBR1
104 1.3 matt mov r0, #TTBCR_S_N_1
105 1.3 matt #else
106 1.3 matt mov r0, #0
107 1.3 matt #endif
108 1.3 matt mcr p15, 0, r0, c2, c0, 2 // TTBCR write
109 1.3 matt
110 1.3 matt mov r0, #0
111 1.1 rkujawa mcr p15, 0, r0, c8, c7, 0 /* Flush TLB */
112 1.1 rkujawa
113 1.3 matt mcr p15, 0, r0, c13, c0, 1 // CONTEXTIDR write: Set ASID to 0
114 1.1 rkujawa
115 1.1 rkujawa /* Set the Domain Access register. Very important! */
116 1.1 rkujawa mov r0, #((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT)
117 1.3 matt mcr p15, 0, r0, c3, c0, 0 // DACR write
118 1.3 matt
119 1.3 matt #define CPU_CONTROL_SET (CPU_CONTROL_XP_ENABLE | CPU_CONTROL_IC_ENABLE \
120 1.3 matt | CPU_CONTROL_MMU_ENABLE | CPU_CONTROL_DC_ENABLE)
121 1.1 rkujawa
122 1.1 rkujawa /* Enable MMU */
123 1.1 rkujawa mrc p15, 0, r0, c1, c0, 0
124 1.3 matt movw r1, #:lower16:CPU_CONTROL_SET
125 1.3 matt #if (CPU_CONTROL_SET & 0xffff) != 0
126 1.3 matt movt r1, #:upper16:CPU_CONTROL_SET
127 1.3 matt #endif
128 1.3 matt orr r0, r0, r1
129 1.1 rkujawa mcr p15, 0, r0, c1, c0, 0
130 1.3 matt isb
131 1.3 matt dsb
132 1.1 rkujawa
133 1.1 rkujawa /* Jump to kernel code in TRUE VA */
134 1.3 matt movw ip, #:lower16:start
135 1.3 matt movt ip, #:upper16:start
136 1.3 matt bx ip
137 1.3 matt
138 1.1 rkujawa /* NOTREACHED */
139 1.1 rkujawa
140 1.4 hsuenaga .global _C_LABEL(uboot_regs_pa)
141 1.4 hsuenaga uboot_regs_pa:
142 1.4 hsuenaga .space 16 /* r0, r1, r2, r3 */
143 1.4 hsuenaga
144 1.1 rkujawa #define MMU_INIT(va,pa,n_sec,attr) \
145 1.1 rkujawa .word n_sec ; \
146 1.1 rkujawa .word 4*((va)>>L1_S_SHIFT) ; \
147 1.1 rkujawa .word (pa)|(attr) ;
148 1.1 rkujawa
149 1.1 rkujawa mmu_init_table:
150 1.1 rkujawa /* fill all table VA==PA */
151 1.1 rkujawa /* map SDRAM VA==PA, WT cacheable */
152 1.3 matt MMU_INIT(MEMSTART, MEMSTART, 64, L1_TYPE_S|L1_S_C|L1_S_AP_KRW)
153 1.3 matt
154 1.3 matt /* map VA 0x80000000..0x83ffffff to PA */
155 1.3 matt MMU_INIT(KERNEL_BASE_EXT, MEMSTART, 64, L1_TYPE_S|L1_S_C|L1_S_AP_KRW)
156 1.3 matt
157 1.1 rkujawa /*
158 1.1 rkujawa * In case of early start debugging it might be useful to map
159 1.1 rkujawa * SoC registers (for UART access).
160 1.1 rkujawa */
161 1.3 matt MMU_INIT(MARVELL_INTERREGS_PBASE, MARVELL_INTERREGS_PBASE, 1,
162 1.3 matt L1_TYPE_S|L1_S_PROTO|L1_S_AP_KRW)
163 1.3 matt MMU_INIT(MARVELL_INTERREGS_VBASE, MARVELL_INTERREGS_PBASE, 1,
164 1.3 matt L1_TYPE_S|L1_S_PROTO|L1_S_AP_KRW)
165 1.3 matt
166 1.1 rkujawa /* end of table */
167 1.1 rkujawa MMU_INIT(0, 0, 0, 0)
168