summaryrefslogtreecommitdiff
path: root/bsp/qemu-vexpress-a9/drivers/secondary_cpu.c
blob: c4ac0c8d2973c4e30fea0c572dcc0e59f4c2612d (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
66
67
68
69
70
71
72
73
74
75
/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2018-11-22     Jesven       first version
 */

#include <rthw.h>
#include <rtthread.h>
#include <stdint.h>

#include "board.h"
#include "gic.h"
#include "drv_timer.h"

#ifdef RT_USING_SMP
#include <interrupt.h>

#ifdef RT_USING_SMART
#include <mmu.h>
#endif

static void rt_hw_timer2_isr(int vector, void *param)
{
    rt_tick_increase();
    /* clear interrupt */
    timer_clear_pending(0);
}

void rt_hw_secondary_cpu_up(void)
{
    volatile void **plat_boot_reg = (volatile void **)0x10000034;
    char *entry = (char *)rt_secondary_cpu_entry;

#ifdef RT_USING_SMART
    plat_boot_reg = (volatile void **)rt_hw_mmu_map(&mmu_info, 0, (void *)plat_boot_reg, 0x1000, MMU_MAP_K_RW);
    if (!plat_boot_reg)
    {
        /* failed */
        return;
    }
    entry += PV_OFFSET;
#endif
    *plat_boot_reg-- = (void *)(size_t)-1;
    *plat_boot_reg = (void *)entry;
    rt_hw_dsb();
    rt_hw_ipi_send(0, 1 << 1);
}

/* Interface */
void rt_hw_secondary_cpu_bsp_start(void)
{
    rt_hw_vector_init();

    rt_hw_spin_lock(&_cpus_lock);

    arm_gic_cpu_init(0, 0);
    arm_gic_set_cpu(0, IRQ_PBA8_TIMER0_1, 0x2);

    timer_init(0, 10000);
    rt_hw_interrupt_install(IRQ_PBA8_TIMER0_1, rt_hw_timer2_isr, RT_NULL, "tick");
    rt_hw_interrupt_umask(IRQ_PBA8_TIMER0_1);

    rt_system_scheduler_start();
}

void rt_hw_secondary_cpu_idle_exec(void)
{
     asm volatile ("wfe":::"memory", "cc");
}

#endif