summaryrefslogtreecommitdiff
path: root/bsp/phytium/board/phytium_cpu.h
blob: 3da9793649e7a1bdfe82decd3b463c6795faccfa (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 * Copyright (c) 2006-2023, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Email: [email protected]
 *
 * Change Logs:
 * Date        Author       Notes
 * 2022-10-26  huanghe      first commit
 *
 */

#ifndef __PHYTIUM_CPU_H__
#define __PHYTIUM_CPU_H__

#include <rthw.h>
#include <rtthread.h>
#include <gicv3.h>
#include "fparameters.h"
#include "fio.h"
#include "faarch.h"
#include "tlb.h"

#ifdef RT_USING_SMART
#include"ioremap.h"
#endif

#define ARM_GIC_MAX_NR 1

#if defined(TARGET_FT2000_4) || defined(TARGET_D2000)
    #define MAX_HANDLERS 160
#endif

#if defined(TARGET_PE220X)
    #define MAX_HANDLERS 270
#endif

#if defined(TARGET_PD2408)
    #define MAX_HANDLERS 1024
#endif

#define GIC_IRQ_START 0
#define GIC_ACK_INTID_MASK 0x000003ff
#define RT_CORE_AFF(x) (CORE##x##_AFF | 0x80000000)

rt_uint64_t get_main_cpu_affval(void);

rt_inline rt_uint32_t platform_get_gic_dist_base(void)
{
    return GICV3_DISTRIBUTOR_BASE_ADDR;
}

/* the basic constants and interfaces needed by gic */
rt_inline uintptr_t platform_get_gic_redist_base(void)
{
    uintptr_t redis_base, mpidr_aff, gicr_typer_aff;
    mpidr_aff = (uintptr_t)(GetAffinity() & CORE_AFF_MASK);

    for (redis_base = GICV3_RD_BASE_ADDR; redis_base < GICV3_RD_BASE_ADDR + GICV3_RD_SIZE; redis_base += GICV3_RD_OFFSET)
    {
#ifdef RT_USING_SMART
        uintptr_t redis_base_virtual = (uintptr_t)rt_ioremap((void *)redis_base, GICV3_RD_OFFSET);
        rt_hw_tlb_invalidate_all();
        if (redis_base_virtual == 0)
        {
            continue;
        }
#if defined(TARGET_ARMV8_AARCH64)
        gicr_typer_aff = GIC_RDIST_TYPER(redis_base_virtual) >> 32;
#else
        gicr_typer_aff = GIC_RDIST_TYPER(redis_base_virtual + 0x4);
#endif
        if (mpidr_aff == gicr_typer_aff)
        {
            return redis_base_virtual;
        }
        else
        {
            rt_iounmap(redis_base_virtual);
        }
#else
#if defined(TARGET_ARMV8_AARCH64)
        gicr_typer_aff = GIC_RDIST_TYPER(redis_base) >> 32;
#else
        gicr_typer_aff = GIC_RDIST_TYPER(redis_base + 0x4);
#endif
        if (mpidr_aff == gicr_typer_aff)
        {
            return redis_base;
        }
#endif
    }

    return 0;
}


#if defined(TARGET_ARMV8_AARCH64)

rt_inline rt_uint32_t platform_get_gic_cpu_base(void)
{
    return 0; /* unused in gicv3 */
}

#endif


int phytium_cpu_id_mapping(int cpu_id);

#endif // !