1/*
2 * Copyright (c) 2014 Wind River Systems, Inc.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7/**
8 * @file
9 * @brief CPU power management
10 *
11 * CPU power management routines.
12 */
13
14#include <zephyr/kernel_structs.h>
15#include <offsets_short.h>
16#include <zephyr/toolchain.h>
17#include <zephyr/linker/sections.h>
18#include <zephyr/arch/cpu.h>
19#include <zephyr/arch/arc/asm-compat/assembler.h>
20
21GTEXT(arch_cpu_idle)
22GTEXT(arch_cpu_atomic_idle)
23GDATA(z_arc_cpu_sleep_mode)
24
25SECTION_VAR(BSS, z_arc_cpu_sleep_mode)
26	.align 4
27	.word 0
28
29#ifndef CONFIG_ARCH_HAS_CUSTOM_CPU_IDLE
30/*
31 * @brief Put the CPU in low-power mode
32 *
33 * This function always exits with interrupts unlocked.
34 *
35 * void nanCpuIdle(void)
36 */
37
38SECTION_FUNC(TEXT, arch_cpu_idle)
39
40#ifdef CONFIG_TRACING
41	PUSHR blink
42	jl    sys_trace_idle
43	POPR blink
44#endif
45
46	/* z_arc_cpu_sleep_mode is 32 bit despite of platform bittnes */
47	ld r1, [z_arc_cpu_sleep_mode]
48	or r1, r1, (1 << 4) /* set IRQ-enabled bit */
49	sleep r1
50	j_s [blink]
51	nop
52#endif
53
54#ifndef CONFIG_ARCH_HAS_CUSTOM_CPU_ATOMIC_IDLE
55/*
56 * @brief Put the CPU in low-power mode, entered with IRQs locked
57 *
58 * This function exits with interrupts restored to <key>.
59 *
60 * void arch_cpu_atomic_idle(unsigned int key)
61 */
62
63SECTION_FUNC(TEXT, arch_cpu_atomic_idle)
64
65#ifdef CONFIG_TRACING
66	PUSHR blink
67	jl    sys_trace_idle
68	POPR blink
69#endif
70
71	/* z_arc_cpu_sleep_mode is 32 bit despite of platform bittnes */
72	ld r1, [z_arc_cpu_sleep_mode]
73	or r1, r1, (1 << 4) /* set IRQ-enabled bit */
74	sleep r1
75	j_s.d [blink]
76	seti r0
77#endif
78