1 /*
2 * Copyright (c) 2006-2022, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2023-02-21 GuEe-GUI replace with ofw
9 */
10 #include <rthw.h>
11 #include <rtthread.h>
12
13 #define DBG_TAG "cpu.aa64"
14 #define DBG_LVL DBG_INFO
15 #include <rtdbg.h>
16
17 #include <cpu.h>
18 #include <cpuport.h>
19
20 #include <ioremap.h>
21 #include <drivers/core/dm.h>
22
23 #ifdef RT_USING_OFW
24
25 static rt_uint64_t cpu_release_addr[RT_CPUS_NR];
26
spin_table_cpu_init(rt_uint32_t cpuid,void * param)27 static int spin_table_cpu_init(rt_uint32_t cpuid, void *param)
28 {
29 struct rt_ofw_node *cpu_np = param;
30
31 rt_ofw_prop_read_u64(cpu_np, "cpu-release-addr", &cpu_release_addr[cpuid]);
32
33 LOG_D("Using release address 0x%p for CPU %d", cpu_release_addr[cpuid], cpuid);
34
35 return 0;
36 }
37
spin_table_cpu_boot(rt_uint32_t cpuid,rt_uint64_t entry)38 static int spin_table_cpu_boot(rt_uint32_t cpuid, rt_uint64_t entry)
39 {
40 void *cpu_release_vaddr;
41
42 cpu_release_vaddr = rt_ioremap((void *)cpu_release_addr[cpuid], sizeof(cpu_release_addr[0]));
43
44 if (!cpu_release_vaddr)
45 {
46 LOG_E("IO remap failing");
47 return -1;
48 }
49
50 __asm__ volatile ("str %0, [%1]" ::"rZ"(entry), "r"(cpu_release_vaddr));
51 rt_hw_barrier(dsb, sy);
52 rt_hw_sev();
53
54 rt_iounmap(cpu_release_vaddr);
55
56 return 0;
57 }
58
59 struct cpu_ops_t cpu_spin_table_ops =
60 {
61 .method = "spin-table",
62 .cpu_init = spin_table_cpu_init,
63 .cpu_boot = spin_table_cpu_boot,
64 };
65 #endif
66