blob: 1448f144e7fb9c441902e2728f572aa91f405157 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Catalin Marinas55bdd692010-05-21 18:06:41 +01002/*
3 * linux/arch/arm/mm/proc-v7m.S
4 *
5 * Copyright (C) 2008 ARM Ltd.
6 * Copyright (C) 2001 Deep Blue Solutions Ltd.
7 *
Catalin Marinas55bdd692010-05-21 18:06:41 +01008 * This is the "shell" of the ARMv7-M processor support.
9 */
10#include <linux/linkage.h>
11#include <asm/assembler.h>
Ezequiel Garciaa4124e72015-11-04 17:08:37 +010012#include <asm/memory.h>
Catalin Marinas55bdd692010-05-21 18:06:41 +010013#include <asm/v7m.h>
14#include "proc-macros.S"
15
16ENTRY(cpu_v7m_proc_init)
Russell King6ebbf2c2014-06-30 16:29:12 +010017 ret lr
Catalin Marinas55bdd692010-05-21 18:06:41 +010018ENDPROC(cpu_v7m_proc_init)
19
20ENTRY(cpu_v7m_proc_fin)
Russell King6ebbf2c2014-06-30 16:29:12 +010021 ret lr
Catalin Marinas55bdd692010-05-21 18:06:41 +010022ENDPROC(cpu_v7m_proc_fin)
23
24/*
25 * cpu_v7m_reset(loc)
26 *
27 * Perform a soft reset of the system. Put the CPU into the
28 * same state as it would be if it had been reset, and branch
29 * to what would be the reset vector.
30 *
31 * - loc - location to jump to for soft reset
32 */
33 .align 5
34ENTRY(cpu_v7m_reset)
Russell King6ebbf2c2014-06-30 16:29:12 +010035 ret r0
Catalin Marinas55bdd692010-05-21 18:06:41 +010036ENDPROC(cpu_v7m_reset)
37
38/*
39 * cpu_v7m_do_idle()
40 *
41 * Idle the processor (eg, wait for interrupt).
42 *
43 * IRQs are already disabled.
44 */
45ENTRY(cpu_v7m_do_idle)
46 wfi
Russell King6ebbf2c2014-06-30 16:29:12 +010047 ret lr
Catalin Marinas55bdd692010-05-21 18:06:41 +010048ENDPROC(cpu_v7m_do_idle)
49
50ENTRY(cpu_v7m_dcache_clean_area)
Russell King6ebbf2c2014-06-30 16:29:12 +010051 ret lr
Catalin Marinas55bdd692010-05-21 18:06:41 +010052ENDPROC(cpu_v7m_dcache_clean_area)
53
54/*
55 * There is no MMU, so here is nothing to do.
56 */
57ENTRY(cpu_v7m_switch_mm)
Russell King6ebbf2c2014-06-30 16:29:12 +010058 ret lr
Catalin Marinas55bdd692010-05-21 18:06:41 +010059ENDPROC(cpu_v7m_switch_mm)
60
61.globl cpu_v7m_suspend_size
62.equ cpu_v7m_suspend_size, 0
63
64#ifdef CONFIG_ARM_CPU_SUSPEND
65ENTRY(cpu_v7m_do_suspend)
Russell King6ebbf2c2014-06-30 16:29:12 +010066 ret lr
Catalin Marinas55bdd692010-05-21 18:06:41 +010067ENDPROC(cpu_v7m_do_suspend)
68
69ENTRY(cpu_v7m_do_resume)
Russell King6ebbf2c2014-06-30 16:29:12 +010070 ret lr
Catalin Marinas55bdd692010-05-21 18:06:41 +010071ENDPROC(cpu_v7m_do_resume)
72#endif
73
Jonathan Austin6a8146f2016-08-30 17:34:00 +010074ENTRY(cpu_cm7_dcache_clean_area)
75 dcache_line_size r2, r3
76 movw r3, #:lower16:BASEADDR_V7M_SCB + V7M_SCB_DCCMVAC
77 movt r3, #:upper16:BASEADDR_V7M_SCB + V7M_SCB_DCCMVAC
78
791: str r0, [r3] @ clean D entry
80 add r0, r0, r2
81 subs r1, r1, r2
82 bhi 1b
83 dsb
84 ret lr
85ENDPROC(cpu_cm7_dcache_clean_area)
86
87ENTRY(cpu_cm7_proc_fin)
88 movw r2, #:lower16:(BASEADDR_V7M_SCB + V7M_SCB_CCR)
89 movt r2, #:upper16:(BASEADDR_V7M_SCB + V7M_SCB_CCR)
90 ldr r0, [r2]
91 bic r0, r0, #(V7M_SCB_CCR_DC | V7M_SCB_CCR_IC)
92 str r0, [r2]
93 ret lr
94ENDPROC(cpu_cm7_proc_fin)
95
Nicolas Pitre544457f2016-11-01 21:58:36 +010096 .section ".init.text", #alloc, #execinstr
Catalin Marinas55bdd692010-05-21 18:06:41 +010097
Jonathan Austin6a8146f2016-08-30 17:34:00 +010098__v7m_cm7_setup:
99 mov r8, #(V7M_SCB_CCR_DC | V7M_SCB_CCR_IC| V7M_SCB_CCR_BP)
100 b __v7m_setup_cont
Catalin Marinas55bdd692010-05-21 18:06:41 +0100101/*
102 * __v7m_setup
103 *
104 * This should be able to cover all ARMv7-M cores.
105 */
106__v7m_setup:
Jonathan Austin6a8146f2016-08-30 17:34:00 +0100107 mov r8, 0
108
109__v7m_setup_cont:
Catalin Marinas55bdd692010-05-21 18:06:41 +0100110 @ Configure the vector table base address
111 ldr r0, =BASEADDR_V7M_SCB
112 ldr r12, =vector_table
113 str r12, [r0, V7M_SCB_VTOR]
114
115 @ enable UsageFault, BusFault and MemManage fault.
116 ldr r5, [r0, #V7M_SCB_SHCSR]
117 orr r5, #(V7M_SCB_SHCSR_USGFAULTENA | V7M_SCB_SHCSR_BUSFAULTENA | V7M_SCB_SHCSR_MEMFAULTENA)
118 str r5, [r0, #V7M_SCB_SHCSR]
119
120 @ Lower the priority of the SVC and PendSV exceptions
121 mov r5, #0x80000000
122 str r5, [r0, V7M_SCB_SHPR2] @ set SVC priority
123 mov r5, #0x00800000
124 str r5, [r0, V7M_SCB_SHPR3] @ set PendSV priority
125
Ezequiel Garciaa4124e72015-11-04 17:08:37 +0100126 @ SVC to switch to handler mode. Notice that this requires sp to
127 @ point to writeable memory because the processor saves
128 @ some registers to the stack.
Russell King14327c62015-04-21 14:17:25 +0100129 badr r1, 1f
Catalin Marinas55bdd692010-05-21 18:06:41 +0100130 ldr r5, [r12, #11 * 4] @ read the SVC vector entry
131 str r1, [r12, #11 * 4] @ write the temporary SVC vector entry
Torgue Alexandre8e026762016-08-31 09:14:14 +0100132 dsb
Catalin Marinas55bdd692010-05-21 18:06:41 +0100133 mov r6, lr @ save LR
Ezequiel Garciaa4124e72015-11-04 17:08:37 +0100134 ldr sp, =init_thread_union + THREAD_START_SP
Vladimir Murzinb70cd402017-04-24 10:41:53 +0100135 stmia sp, {r0-r3, r12}
Catalin Marinas55bdd692010-05-21 18:06:41 +0100136 cpsie i
137 svc #0
1381: cpsid i
Vladimir Murzin72cd4062019-01-25 15:18:37 +0100139 ldr r0, =exc_ret
140 orr lr, lr, #EXC_RET_THREADMODE_PROCESSSTACK
141 str lr, [r0]
Vladimir Murzinb70cd402017-04-24 10:41:53 +0100142 ldmia sp, {r0-r3, r12}
Catalin Marinas55bdd692010-05-21 18:06:41 +0100143 str r5, [r12, #11 * 4] @ restore the original SVC vector entry
144 mov lr, r6 @ restore LR
Catalin Marinas55bdd692010-05-21 18:06:41 +0100145
146 @ Special-purpose control register
147 mov r1, #1
148 msr control, r1 @ Thread mode has unpriviledged access
149
Jonathan Austin6a8146f2016-08-30 17:34:00 +0100150 @ Configure caches (if implemented)
151 teq r8, #0
Stefan Agnere44fc382019-02-18 00:57:38 +0100152 stmiane sp, {r0-r6, lr} @ v7m_invalidate_l1 touches r0-r6
Jonathan Austin6a8146f2016-08-30 17:34:00 +0100153 blne v7m_invalidate_l1
154 teq r8, #0 @ re-evalutae condition
Stefan Agnere44fc382019-02-18 00:57:38 +0100155 ldmiane sp, {r0-r6, lr}
Jonathan Austin6a8146f2016-08-30 17:34:00 +0100156
Catalin Marinas55bdd692010-05-21 18:06:41 +0100157 @ Configure the System Control Register to ensure 8-byte stack alignment
158 @ Note the STKALIGN bit is either RW or RAO.
Jonathan Austinbc0ee9d2016-08-30 17:31:22 +0100159 ldr r0, [r0, V7M_SCB_CCR] @ system control register
160 orr r0, #V7M_SCB_CCR_STKALIGN
Jonathan Austin6a8146f2016-08-30 17:34:00 +0100161 orr r0, r0, r8
162
Russell King6ebbf2c2014-06-30 16:29:12 +0100163 ret lr
Catalin Marinas55bdd692010-05-21 18:06:41 +0100164ENDPROC(__v7m_setup)
165
Jonathan Austin6a8146f2016-08-30 17:34:00 +0100166/*
167 * Cortex-M7 processor functions
168 */
169 globl_equ cpu_cm7_proc_init, cpu_v7m_proc_init
170 globl_equ cpu_cm7_reset, cpu_v7m_reset
171 globl_equ cpu_cm7_do_idle, cpu_v7m_do_idle
172 globl_equ cpu_cm7_switch_mm, cpu_v7m_switch_mm
173
Catalin Marinas55bdd692010-05-21 18:06:41 +0100174 define_processor_functions v7m, dabort=nommu_early_abort, pabort=legacy_pabort, nommu=1
Jonathan Austin6a8146f2016-08-30 17:34:00 +0100175 define_processor_functions cm7, dabort=nommu_early_abort, pabort=legacy_pabort, nommu=1
Catalin Marinas55bdd692010-05-21 18:06:41 +0100176
177 .section ".rodata"
178 string cpu_arch_name, "armv7m"
179 string cpu_elf_name "v7m"
180 string cpu_v7m_name "ARMv7-M"
181
Ard Biesheuvelbf357062015-03-18 07:29:32 +0100182 .section ".proc.info.init", #alloc
Catalin Marinas55bdd692010-05-21 18:06:41 +0100183
Jonathan Austinc3a6bcb2016-08-30 17:32:42 +0100184.macro __v7m_proc name, initfunc, cache_fns = nop_cache_fns, hwcaps = 0, proc_fns = v7m_processor_functions
185 .long 0 /* proc_info_list.__cpu_mm_mmu_flags */
186 .long 0 /* proc_info_list.__cpu_io_mmu_flags */
187 initfn \initfunc, \name
188 .long cpu_arch_name
189 .long cpu_elf_name
190 .long HWCAP_HALF | HWCAP_THUMB | HWCAP_FAST_MULT | \hwcaps
191 .long cpu_v7m_name
192 .long \proc_fns
193 .long 0 /* proc_info_list.tlb */
194 .long 0 /* proc_info_list.user */
195 .long \cache_fns
196.endm
197
198 /*
Jonathan Austin6a8146f2016-08-30 17:34:00 +0100199 * Match ARM Cortex-M7 processor.
200 */
201 .type __v7m_cm7_proc_info, #object
202__v7m_cm7_proc_info:
203 .long 0x410fc270 /* ARM Cortex-M7 0xC27 */
204 .long 0xff0ffff0 /* Mask off revision, patch release */
205 __v7m_proc __v7m_cm7_proc_info, __v7m_cm7_setup, hwcaps = HWCAP_EDSP, cache_fns = v7m_cache_fns, proc_fns = cm7_processor_functions
206 .size __v7m_cm7_proc_info, . - __v7m_cm7_proc_info
207
208 /*
Jonathan Austinc3a6bcb2016-08-30 17:32:42 +0100209 * Match ARM Cortex-M4 processor.
210 */
211 .type __v7m_cm4_proc_info, #object
212__v7m_cm4_proc_info:
213 .long 0x410fc240 /* ARM Cortex-M4 0xC24 */
214 .long 0xff0ffff0 /* Mask off revision, patch release */
215 __v7m_proc __v7m_cm4_proc_info, __v7m_setup, hwcaps = HWCAP_EDSP
216 .size __v7m_cm4_proc_info, . - __v7m_cm4_proc_info
217
218 /*
219 * Match ARM Cortex-M3 processor.
220 */
221 .type __v7m_cm3_proc_info, #object
222__v7m_cm3_proc_info:
223 .long 0x410fc230 /* ARM Cortex-M3 0xC23 */
224 .long 0xff0ffff0 /* Mask off revision, patch release */
225 __v7m_proc __v7m_cm3_proc_info, __v7m_setup
226 .size __v7m_cm3_proc_info, . - __v7m_cm3_proc_info
227
Catalin Marinas55bdd692010-05-21 18:06:41 +0100228 /*
229 * Match any ARMv7-M processor core.
230 */
231 .type __v7m_proc_info, #object
232__v7m_proc_info:
233 .long 0x000f0000 @ Required ID value
234 .long 0x000f0000 @ Mask for ID
Jonathan Austinc3a6bcb2016-08-30 17:32:42 +0100235 __v7m_proc __v7m_proc_info, __v7m_setup
Catalin Marinas55bdd692010-05-21 18:06:41 +0100236 .size __v7m_proc_info, . - __v7m_proc_info
237