1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use crate::config::NUM_OF_CPU_PER_CLUSTER;

use armv9a::regs::*;

#[no_mangle]
pub extern "C" fn get_cpu_id() -> usize {
    let (cluster, core) = id();
    cluster * NUM_OF_CPU_PER_CLUSTER + core
}

#[inline(always)]
pub fn id() -> (usize, usize) {
    unsafe {
        (
            MPIDR_EL1.get_masked_value(MPIDR_EL1::AFF2) as usize,
            MPIDR_EL1.get_masked_value(MPIDR_EL1::AFF1) as usize,
        )
    }
}