armadaxp_start.S revision 1.3 1 1.3 matt /* $NetBSD: armadaxp_start.S,v 1.3 2014/03/29 14:53:57 matt 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.3 matt RCSID("$NetBSD: armadaxp_start.S,v 1.3 2014/03/29 14:53:57 matt 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.1 rkujawa /* build page table from scratch */
82 1.3 matt movw r0, #:lower16:STARTUP_PAGETABLE_ADDR
83 1.3 matt movt r0, #:upper16:STARTUP_PAGETABLE_ADDR
84 1.1 rkujawa adr r4, mmu_init_table
85 1.1 rkujawa b 3f
86 1.1 rkujawa
87 1.3 matt 2: str r3, [r0, r2]
88 1.1 rkujawa add r2, r2, #4
89 1.1 rkujawa add r3, r3, #(L1_S_SIZE)
90 1.1 rkujawa adds r1, r1, #-1
91 1.1 rkujawa bhi 2b
92 1.1 rkujawa 3:
93 1.1 rkujawa ldmia r4!, {r1,r2,r3} /* # of sections, VA, PA|attr */
94 1.1 rkujawa cmp r1, #0
95 1.3 matt bne 2b
96 1.1 rkujawa
97 1.3 matt mcr p15, 0, r0, c2, c0, 0 // Set TTBR0
98 1.3 matt #ifdef ARM_MMU_EXTENDED
99 1.3 matt mcr p15, 0, r0, c2, c0, 1 // Set TTBR1
100 1.3 matt mov r0, #TTBCR_S_N_1
101 1.3 matt #else
102 1.3 matt mov r0, #0
103 1.3 matt #endif
104 1.3 matt mcr p15, 0, r0, c2, c0, 2 // TTBCR write
105 1.3 matt
106 1.3 matt mov r0, #0
107 1.1 rkujawa mcr p15, 0, r0, c8, c7, 0 /* Flush TLB */
108 1.1 rkujawa
109 1.3 matt mcr p15, 0, r0, c13, c0, 1 // CONTEXTIDR write: Set ASID to 0
110 1.1 rkujawa
111 1.1 rkujawa /* Set the Domain Access register. Very important! */
112 1.1 rkujawa mov r0, #((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT)
113 1.3 matt mcr p15, 0, r0, c3, c0, 0 // DACR write
114 1.3 matt
115 1.3 matt #define CPU_CONTROL_SET (CPU_CONTROL_XP_ENABLE | CPU_CONTROL_IC_ENABLE \
116 1.3 matt | CPU_CONTROL_MMU_ENABLE | CPU_CONTROL_DC_ENABLE)
117 1.1 rkujawa
118 1.1 rkujawa /* Enable MMU */
119 1.1 rkujawa mrc p15, 0, r0, c1, c0, 0
120 1.3 matt movw r1, #:lower16:CPU_CONTROL_SET
121 1.3 matt #if (CPU_CONTROL_SET & 0xffff) != 0
122 1.3 matt movt r1, #:upper16:CPU_CONTROL_SET
123 1.3 matt #endif
124 1.3 matt orr r0, r0, r1
125 1.1 rkujawa mcr p15, 0, r0, c1, c0, 0
126 1.3 matt isb
127 1.3 matt dsb
128 1.1 rkujawa
129 1.1 rkujawa /* Jump to kernel code in TRUE VA */
130 1.3 matt movw ip, #:lower16:start
131 1.3 matt movt ip, #:upper16:start
132 1.3 matt bx ip
133 1.3 matt
134 1.1 rkujawa /* NOTREACHED */
135 1.1 rkujawa
136 1.1 rkujawa #define MMU_INIT(va,pa,n_sec,attr) \
137 1.1 rkujawa .word n_sec ; \
138 1.1 rkujawa .word 4*((va)>>L1_S_SHIFT) ; \
139 1.1 rkujawa .word (pa)|(attr) ;
140 1.1 rkujawa
141 1.1 rkujawa mmu_init_table:
142 1.1 rkujawa /* fill all table VA==PA */
143 1.1 rkujawa /* map SDRAM VA==PA, WT cacheable */
144 1.3 matt MMU_INIT(MEMSTART, MEMSTART, 64, L1_TYPE_S|L1_S_C|L1_S_AP_KRW)
145 1.3 matt
146 1.3 matt /* map VA 0x80000000..0x83ffffff to PA */
147 1.3 matt MMU_INIT(KERNEL_BASE_EXT, MEMSTART, 64, L1_TYPE_S|L1_S_C|L1_S_AP_KRW)
148 1.3 matt
149 1.1 rkujawa /*
150 1.1 rkujawa * In case of early start debugging it might be useful to map
151 1.1 rkujawa * SoC registers (for UART access).
152 1.1 rkujawa */
153 1.3 matt MMU_INIT(MARVELL_INTERREGS_PBASE, MARVELL_INTERREGS_PBASE, 1,
154 1.3 matt L1_TYPE_S|L1_S_PROTO|L1_S_AP_KRW)
155 1.3 matt MMU_INIT(MARVELL_INTERREGS_VBASE, MARVELL_INTERREGS_PBASE, 1,
156 1.3 matt L1_TYPE_S|L1_S_PROTO|L1_S_AP_KRW)
157 1.3 matt
158 1.1 rkujawa /* end of table */
159 1.1 rkujawa MMU_INIT(0, 0, 0, 0)
160