1/*
2 * Copyright (c) 2019 Carlo Caione <ccaione@baylibre.com>
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7/*
8 * ARM64 Cortex-A power management
9 */
10
11#include <zephyr/toolchain.h>
12#include <zephyr/linker/sections.h>
13#include <zephyr/arch/cpu.h>
14
15_ASM_FILE_PROLOGUE
16#ifndef CONFIG_ARCH_HAS_CUSTOM_CPU_IDLE
17GTEXT(arch_cpu_idle)
18SECTION_FUNC(TEXT, arch_cpu_idle)
19#ifdef CONFIG_TRACING
20	str	lr, [sp, #-16]!
21	bl	sys_trace_idle
22	ldr	lr, [sp], #16
23#endif
24	dsb	sy
25	wfi
26	msr	daifclr, #(DAIFCLR_IRQ_BIT)
27	ret
28#endif
29
30#ifndef CONFIG_ARCH_HAS_CUSTOM_CPU_ATOMIC_IDLE
31GTEXT(arch_cpu_atomic_idle)
32SECTION_FUNC(TEXT, arch_cpu_atomic_idle)
33#ifdef CONFIG_TRACING
34	stp	x0, lr, [sp, #-16]!
35	bl	sys_trace_idle
36	ldp	x0, lr, [sp], #16
37#endif
38	msr	daifset, #(DAIFSET_IRQ_BIT)
39	isb
40	wfe
41	tst	x0, #(DAIF_IRQ_BIT)
42	beq	_irq_disabled
43	msr	daifclr, #(DAIFCLR_IRQ_BIT)
44_irq_disabled:
45	ret
46
47#endif
48