xref: /DragonOS/kernel/src/arch/x86_64/driver/apic/c_adapter.rs (revision 83ed0ebc293d5a10245089f627f52770fd5b9dd4)
1 use super::{
2     apic_timer::{LocalApicTimer, LocalApicTimerIntrController},
3     ioapic::{ioapic_disable, ioapic_enable, ioapic_install, ioapic_uninstall},
4     CurrentApic, LocalAPIC,
5 };
6 
7 #[no_mangle]
8 unsafe extern "C" fn rs_apic_timer_install(irq_num: u8) {
9     LocalApicTimerIntrController.install(irq_num);
10 }
11 
12 #[no_mangle]
13 unsafe extern "C" fn rs_apic_timer_uninstall(_irq_num: u8) {
14     LocalApicTimerIntrController.uninstall();
15 }
16 
17 #[no_mangle]
18 unsafe extern "C" fn rs_apic_timer_enable(_irq_num: u8) {
19     LocalApicTimerIntrController.enable();
20 }
21 
22 #[no_mangle]
23 unsafe extern "C" fn rs_apic_timer_disable(_irq_num: u8) {
24     LocalApicTimerIntrController.disable();
25 }
26 
27 #[no_mangle]
28 unsafe extern "C" fn rs_apic_local_apic_edge_ack(_irq_num: u8) {
29     CurrentApic.send_eoi();
30 }
31 
32 /// 初始化bsp处理器的apic
33 #[no_mangle]
34 pub extern "C" fn rs_apic_init_bsp() -> i32 {
35     if CurrentApic.init_current_cpu() {
36         return 0;
37     }
38 
39     return -1;
40 }
41 
42 #[no_mangle]
43 pub extern "C" fn rs_apic_init_ap() -> i32 {
44     if CurrentApic.init_current_cpu() {
45         return 0;
46     }
47 
48     return -1;
49 }
50 
51 #[no_mangle]
52 unsafe extern "C" fn rs_ioapic_install(
53     vector: u8,
54     dest: u8,
55     level_triggered: bool,
56     active_high: bool,
57     dest_logic: bool,
58 ) -> i32 {
59     return ioapic_install(vector, dest, level_triggered, active_high, dest_logic)
60         .map(|_| 0)
61         .unwrap_or_else(|e| e.to_posix_errno());
62 }
63 
64 #[no_mangle]
65 unsafe extern "C" fn rs_ioapic_uninstall(vector: u8) {
66     ioapic_uninstall(vector);
67 }
68 
69 #[no_mangle]
70 unsafe extern "C" fn rs_ioapic_enable(vector: u8) {
71     ioapic_enable(vector);
72 }
73 
74 #[no_mangle]
75 unsafe extern "C" fn rs_ioapic_disable(vector: u8) {
76     ioapic_disable(vector);
77 }
78 
79 #[no_mangle]
80 unsafe extern "C" fn rs_apic_timer_handle_irq(_irq_num: u8) -> i32 {
81     return LocalApicTimer::handle_irq()
82         .map(|_| 0)
83         .unwrap_or_else(|e| e.to_posix_errno());
84 }
85