2017-05-24 01:49:26 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <arch.h>
|
|
|
|
#include <asm_macros.S>
|
|
|
|
#include <cortex_a53.h>
|
|
|
|
#include <hi6220.h>
|
|
|
|
#include <hisi_sram_map.h>
|
|
|
|
|
|
|
|
.global pm_asm_code
|
|
|
|
.global pm_asm_code_end
|
|
|
|
.global v7_asm
|
|
|
|
.global v7_asm_end
|
|
|
|
|
Add new alignment parameter to func assembler macro
Assembler programmers are used to being able to define functions with a
specific aligment with a pattern like this:
.align X
myfunction:
However, this pattern is subtly broken when instead of a direct label
like 'myfunction:', you use the 'func myfunction' macro that's standard
in Trusted Firmware. Since the func macro declares a new section for the
function, the .align directive written above it actually applies to the
*previous* section in the assembly file, and the function it was
supposed to apply to is linked with default alignment.
An extreme case can be seen in Rockchip's plat_helpers.S which contains
this code:
[...]
endfunc plat_crash_console_putc
.align 16
func platform_cpu_warmboot
[...]
This assembles into the following plat_helpers.o:
Sections:
Idx Name Size [...] Algn
9 .text.plat_crash_console_putc 00010000 [...] 2**16
10 .text.platform_cpu_warmboot 00000080 [...] 2**3
As can be seen, the *previous* function actually got the alignment
constraint, and it is also 64KB big even though it contains only two
instructions, because the .align directive at the end of its section
forces the assembler to insert a giant sled of NOPs. The function we
actually wanted to align has the default constraint. This code only
works at all because the linker just happens to put the two functions
right behind each other when linking the final image, and since the end
of plat_crash_console_putc is aligned the start of platform_cpu_warmboot
will also be. But it still wastes almost 64KB of image space
unnecessarily, and it will break under certain circumstances (e.g. if
the plat_crash_console_putc function becomes unused and its section gets
garbage-collected out).
There's no real way to fix this with the existing func macro. Code like
func myfunc
.align X
happens to do the right thing, but is still not really correct code
(because the function label is inserted before the .align directive, so
the assembler is technically allowed to insert padding at the beginning
of the function which would then get executed as instructions if the
function was called). Therefore, this patch adds a new parameter with a
default value to the func macro that allows overriding its alignment.
Also fix up all existing instances of this dangerous antipattern.
Change-Id: I5696a07e2fde896f21e0e83644c95b7b6ac79a10
Signed-off-by: Julius Werner <jwerner@chromium.org>
2017-08-01 23:16:36 +01:00
|
|
|
func pm_asm_code _align=3
|
2017-05-24 01:49:26 +01:00
|
|
|
mov x0, 0
|
|
|
|
msr oslar_el1, x0
|
|
|
|
|
2017-08-10 14:26:36 +01:00
|
|
|
mrs x0, CORTEX_A53_CPUACTLR_EL1
|
|
|
|
bic x0, x0, #(CORTEX_A53_CPUACTLR_EL1_RADIS | \
|
|
|
|
CORTEX_A53_CPUACTLR_EL1_L1RADIS)
|
2017-05-24 01:49:26 +01:00
|
|
|
orr x0, x0, #0x180000
|
|
|
|
orr x0, x0, #0xe000
|
2017-08-10 14:26:36 +01:00
|
|
|
msr CORTEX_A53_CPUACTLR_EL1, x0
|
2017-05-24 01:49:26 +01:00
|
|
|
|
|
|
|
mrs x3, actlr_el3
|
|
|
|
orr x3, x3, #ACTLR_EL3_L2ECTLR_BIT
|
|
|
|
msr actlr_el3, x3
|
|
|
|
|
|
|
|
mrs x3, actlr_el2
|
|
|
|
orr x3, x3, #ACTLR_EL2_L2ECTLR_BIT
|
|
|
|
msr actlr_el2, x3
|
|
|
|
|
|
|
|
ldr x3, =PWRCTRL_ACPU_ASM_D_ARM_PARA_AD
|
|
|
|
mrs x0, mpidr_el1
|
|
|
|
and x1, x0, #MPIDR_CPU_MASK
|
|
|
|
and x0, x0, #MPIDR_CLUSTER_MASK
|
|
|
|
add x0, x1, x0, LSR #6
|
|
|
|
pen: ldr x4, [x3, x0, LSL #3]
|
|
|
|
cbz x4, pen
|
|
|
|
|
|
|
|
mov x0, #0x0
|
|
|
|
mov x1, #0x0
|
|
|
|
mov x2, #0x0
|
|
|
|
mov x3, #0x0
|
|
|
|
br x4
|
|
|
|
|
|
|
|
.ltorg
|
|
|
|
|
|
|
|
pm_asm_code_end:
|
|
|
|
endfunc pm_asm_code
|
|
|
|
|
|
|
|
/*
|
|
|
|
* By default, all cores in Hi6220 reset with aarch32 mode.
|
|
|
|
* Now hardcode ARMv7 instructions to execute warm reset for
|
|
|
|
* switching aarch64 mode.
|
|
|
|
*/
|
|
|
|
.align 3
|
|
|
|
.section .rodata.v7_asm, "aS"
|
|
|
|
v7_asm:
|
|
|
|
.word 0xE1A00000 // nop
|
|
|
|
.word 0xE3A02003 // mov r2, #3
|
|
|
|
.word 0xEE0C2F50 // mcr 15, 0, r2, cr12, cr0, {2}
|
|
|
|
.word 0xE320F003 // wfi
|
|
|
|
|
|
|
|
.ltorg
|
|
|
|
v7_asm_end:
|