2016-03-18 20:07:33 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
|
|
|
|
*
|
2017-05-03 09:38:09 +01:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2016-03-18 20:07:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <arch.h>
|
|
|
|
#include <asm_macros.S>
|
|
|
|
#include <memctrl_v2.h>
|
2018-12-14 00:18:21 +00:00
|
|
|
#include <plat/common/common_def.h>
|
2016-03-18 20:07:33 +00:00
|
|
|
#include <tegra_def.h>
|
|
|
|
|
2017-11-10 18:26:57 +00:00
|
|
|
#define TEGRA186_STATE_SYSTEM_SUSPEND 0x5C7
|
|
|
|
#define TEGRA186_STATE_SYSTEM_RESUME 0x600D
|
2016-03-18 20:07:33 +00:00
|
|
|
#define TEGRA186_SMMU_CTX_SIZE 0x420
|
|
|
|
|
|
|
|
.globl tegra186_cpu_reset_handler
|
|
|
|
|
|
|
|
/* CPU reset handler routine */
|
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 tegra186_cpu_reset_handler _align=4
|
2017-11-10 18:26:57 +00:00
|
|
|
/* check if we are exiting system suspend state */
|
|
|
|
adr x0, __tegra186_system_suspend_state
|
|
|
|
ldr x1, [x0]
|
|
|
|
mov x2, #TEGRA186_STATE_SYSTEM_SUSPEND
|
|
|
|
lsl x2, x2, #16
|
|
|
|
add x2, x2, #TEGRA186_STATE_SYSTEM_SUSPEND
|
|
|
|
cmp x1, x2
|
|
|
|
bne boot_cpu
|
|
|
|
|
|
|
|
/* set system resume state */
|
|
|
|
mov x1, #TEGRA186_STATE_SYSTEM_RESUME
|
|
|
|
lsl x1, x1, #16
|
|
|
|
mov x2, #TEGRA186_STATE_SYSTEM_RESUME
|
|
|
|
add x1, x1, x2
|
|
|
|
str x1, [x0]
|
|
|
|
dsb sy
|
2016-03-18 20:07:33 +00:00
|
|
|
|
2017-11-10 18:26:57 +00:00
|
|
|
/* prepare to relocate to TZSRAM */
|
2016-03-18 20:07:33 +00:00
|
|
|
mov x0, #BL31_BASE
|
|
|
|
adr x1, __tegra186_cpu_reset_handler_end
|
|
|
|
adr x2, __tegra186_cpu_reset_handler_data
|
|
|
|
ldr x2, [x2, #8]
|
|
|
|
|
|
|
|
/* memcpy16 */
|
|
|
|
m_loop16:
|
|
|
|
cmp x2, #16
|
|
|
|
b.lt m_loop1
|
|
|
|
ldp x3, x4, [x1], #16
|
|
|
|
stp x3, x4, [x0], #16
|
|
|
|
sub x2, x2, #16
|
|
|
|
b m_loop16
|
|
|
|
/* copy byte per byte */
|
|
|
|
m_loop1:
|
|
|
|
cbz x2, boot_cpu
|
|
|
|
ldrb w3, [x1], #1
|
|
|
|
strb w3, [x0], #1
|
|
|
|
subs x2, x2, #1
|
|
|
|
b.ne m_loop1
|
|
|
|
|
|
|
|
boot_cpu:
|
|
|
|
adr x0, __tegra186_cpu_reset_handler_data
|
|
|
|
ldr x0, [x0]
|
|
|
|
br x0
|
|
|
|
endfunc tegra186_cpu_reset_handler
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tegra186 reset data (offset 0x0 - 0x430)
|
|
|
|
*
|
|
|
|
* 0x000: secure world's entrypoint
|
|
|
|
* 0x008: BL31 size (RO + RW)
|
|
|
|
* 0x00C: SMMU context start
|
|
|
|
* 0x42C: SMMU context end
|
|
|
|
*/
|
|
|
|
|
|
|
|
.align 4
|
|
|
|
.type __tegra186_cpu_reset_handler_data, %object
|
|
|
|
.globl __tegra186_cpu_reset_handler_data
|
|
|
|
__tegra186_cpu_reset_handler_data:
|
|
|
|
.quad tegra_secure_entrypoint
|
|
|
|
.quad __BL31_END__ - BL31_BASE
|
2017-11-08 22:45:08 +00:00
|
|
|
|
2017-11-10 18:26:57 +00:00
|
|
|
.globl __tegra186_system_suspend_state
|
|
|
|
__tegra186_system_suspend_state:
|
|
|
|
.quad 0
|
|
|
|
|
2017-11-08 22:45:08 +00:00
|
|
|
.align 4
|
2017-04-21 02:56:09 +01:00
|
|
|
.globl __tegra186_smmu_context
|
|
|
|
__tegra186_smmu_context:
|
2016-03-18 20:07:33 +00:00
|
|
|
.rept TEGRA186_SMMU_CTX_SIZE
|
|
|
|
.quad 0
|
|
|
|
.endr
|
|
|
|
.size __tegra186_cpu_reset_handler_data, \
|
|
|
|
. - __tegra186_cpu_reset_handler_data
|
|
|
|
|
|
|
|
.align 4
|
|
|
|
.globl __tegra186_cpu_reset_handler_end
|
|
|
|
__tegra186_cpu_reset_handler_end:
|
2017-10-25 19:52:07 +01:00
|
|
|
|
|
|
|
.globl tegra186_get_cpu_reset_handler_size
|
|
|
|
.globl tegra186_get_cpu_reset_handler_base
|
2017-11-08 22:45:08 +00:00
|
|
|
.globl tegra186_get_smmu_ctx_offset
|
2017-11-10 18:26:57 +00:00
|
|
|
.globl tegra186_set_system_suspend_entry
|
2017-10-25 19:52:07 +01:00
|
|
|
|
|
|
|
/* return size of the CPU reset handler */
|
|
|
|
func tegra186_get_cpu_reset_handler_size
|
|
|
|
adr x0, __tegra186_cpu_reset_handler_end
|
|
|
|
adr x1, tegra186_cpu_reset_handler
|
|
|
|
sub x0, x0, x1
|
|
|
|
ret
|
|
|
|
endfunc tegra186_get_cpu_reset_handler_size
|
|
|
|
|
|
|
|
/* return the start address of the CPU reset handler */
|
|
|
|
func tegra186_get_cpu_reset_handler_base
|
|
|
|
adr x0, tegra186_cpu_reset_handler
|
|
|
|
ret
|
|
|
|
endfunc tegra186_get_cpu_reset_handler_base
|
2017-11-08 22:45:08 +00:00
|
|
|
|
|
|
|
/* return the size of the SMMU context */
|
|
|
|
func tegra186_get_smmu_ctx_offset
|
|
|
|
adr x0, __tegra186_smmu_context
|
|
|
|
adr x1, tegra186_cpu_reset_handler
|
|
|
|
sub x0, x0, x1
|
|
|
|
ret
|
|
|
|
endfunc tegra186_get_smmu_ctx_offset
|
2017-11-10 18:26:57 +00:00
|
|
|
|
|
|
|
/* set system suspend state before SC7 entry */
|
|
|
|
func tegra186_set_system_suspend_entry
|
|
|
|
mov x0, #TEGRA_MC_BASE
|
|
|
|
mov x3, #MC_SECURITY_CFG3_0
|
|
|
|
ldr w1, [x0, x3]
|
|
|
|
lsl x1, x1, #32
|
|
|
|
mov x3, #MC_SECURITY_CFG0_0
|
|
|
|
ldr w2, [x0, x3]
|
|
|
|
orr x3, x1, x2 /* TZDRAM base */
|
|
|
|
adr x0, __tegra186_system_suspend_state
|
|
|
|
adr x1, tegra186_cpu_reset_handler
|
|
|
|
sub x2, x0, x1 /* offset in TZDRAM */
|
|
|
|
mov x0, #TEGRA186_STATE_SYSTEM_SUSPEND
|
|
|
|
lsl x0, x0, #16
|
|
|
|
add x0, x0, #TEGRA186_STATE_SYSTEM_SUSPEND
|
|
|
|
str x0, [x3, x2] /* set value in TZDRAM */
|
|
|
|
dsb sy
|
|
|
|
ret
|
|
|
|
endfunc tegra186_set_system_suspend_entry
|