summaryrefslogtreecommitdiff
path: root/libcpu/aarch64/common/cpu_spin_table.c
blob: 2cae749a48123a63f46785c2170d4ecc227e1482 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 * Copyright (c) 2006-2022, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2023-02-21     GuEe-GUI     replace with ofw
 */
#include <rthw.h>
#include <rtthread.h>

#define DBG_TAG "cpu.aa64"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>

#include <cpu.h>
#include <cpuport.h>

#include <ioremap.h>
#include <drivers/core/dm.h>

#ifdef RT_USING_OFW

static rt_uint64_t cpu_release_addr[RT_CPUS_NR];

static int spin_table_cpu_init(rt_uint32_t cpuid, void *param)
{
   struct rt_ofw_node *cpu_np = param;

   rt_ofw_prop_read_u64(cpu_np, "cpu-release-addr", &cpu_release_addr[cpuid]);

   LOG_D("Using release address 0x%p for CPU %d", cpu_release_addr[cpuid], cpuid);

   return 0;
}

static int spin_table_cpu_boot(rt_uint32_t cpuid, rt_uint64_t entry)
{
    void *cpu_release_vaddr;

    cpu_release_vaddr = rt_ioremap((void *)cpu_release_addr[cpuid], sizeof(cpu_release_addr[0]));

    if (!cpu_release_vaddr)
    {
        LOG_E("IO remap failing");
        return -1;
    }

    __asm__ volatile ("str %0, [%1]" ::"rZ"(entry), "r"(cpu_release_vaddr));
    rt_hw_barrier(dsb, sy);
    rt_hw_sev();

    rt_iounmap(cpu_release_vaddr);

    return 0;
}

struct cpu_ops_t cpu_spin_table_ops =
{
    .method = "spin-table",
    .cpu_init = spin_table_cpu_init,
    .cpu_boot = spin_table_cpu_boot,
};
#endif