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
use axplat::init::InitIf;
use log::debug;
use crate::{console, driver};
struct InitIfImpl;
#[impl_plat_interface]
impl InitIf for InitIfImpl {
/// Initializes the platform at the early stage for the primary core.
///
/// This function should be called immediately after the kernel has booted,
/// and performed earliest platform configuration and initialization (e.g.,
/// early console, clocking).
///
/// # Arguments
///
/// * `cpu_id` is the logical CPU ID (0, 1, ..., N-1, N is the number of CPU
/// cores on the platform).
/// * `arg` is passed from the bootloader (typically the device tree blob
/// address).
///
/// # Before calling this function
///
/// * CPU is booted in the kernel mode.
/// * Early page table is set up, virtual memory is enabled.
/// * CPU-local data is initialized.
///
/// # After calling this function
///
/// * Exception & interrupt handlers are set up.
/// * Early console is initialized.
/// * Current monotonic time and wall time can be obtained.
fn init_early(_cpu_id: usize, _arg: usize) {
console::setup_early();
axcpu::init::init_trap();
crate::mem::setup();
}
/// Initializes the platform at the early stage for secondary cores.
///
/// See [`init_early`] for details.
#[cfg(feature = "smp")]
fn init_early_secondary(_cpu_id: usize) {
axcpu::init::init_trap();
}
/// Initializes the platform at the later stage for the primary core.
///
/// This function should be called after the kernel has done part of its
/// initialization (e.g, logging, memory management), and finalized the rest of
/// platform configuration and initialization.
///
/// # Arguments
///
/// * `cpu_id` is the logical CPU ID (0, 1, ..., N-1, N is the number of CPU
/// cores on the platform).
/// * `arg` is passed from the bootloader (typically the device tree blob
/// address).
///
/// # Before calling this function
///
/// * Kernel logging is initialized.
/// * Fine-grained kernel page table is set up (if applicable).
/// * Physical memory allocation is initialized (if applicable).
///
/// # After calling this function
///
/// * Interrupt controller is initialized (if applicable).
/// * Timer interrupts are enabled (if applicable).
/// * Other platform devices are initialized.
fn init_later(_cpu_id: usize, _arg: usize) {
somehal::mem::flush_tlb(None);
#[cfg(feature = "smp")]
crate::smp::init();
unsafe extern "C" {
fn _percpu_start();
}
crate::time::enable();
debug!("drivers setup...");
driver::setup();
#[cfg(feature = "irq")]
{
crate::irq::init();
crate::irq::init_current_cpu();
crate::time::enable_irqs();
}
}
/// Initializes the platform at the later stage for secondary cores.
///
/// See [`init_later`] for details.
#[cfg(feature = "smp")]
fn init_later_secondary(_cpu_id: usize) {
somehal::mem::flush_tlb(None);
crate::time::enable();
#[cfg(feature = "irq")]
{
crate::irq::init_current_cpu();
crate::time::enable_irqs();
}
}
}