MOS Source Code
Loading...
Searching...
No Matches
apic.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2// Common header for LAPIC and IOAPIC
3
4#pragma once
5
6#include <mos/types.h>
7
8#define APIC_REG_LAPIC_ID 0x20
19
25
33
34void lapic_enable(void);
35void lapic_interrupt(u8 vec, u8 dest, lapic_delivery_mode_t delivery_mode, lapic_dest_mode_t dest_mode, lapic_shorthand_t shorthand);
36void lapic_interrupt_full(u8 vec, u8 dest, lapic_delivery_mode_t dliv_mode, lapic_dest_mode_t dstmode, bool lvl, bool trigger, lapic_shorthand_t sh);
37
38u32 lapic_read32(u32 offset);
39u64 lapic_read64(u32 offset);
40void lapic_write32(u32 offset, u32 value);
41void lapic_write64(u32 offset, u64 value);
42
43void lapic_eoi(void);
44
46{
47 // https://stackoverflow.com/a/71756491
48 // https://github.com/rust-osdev/apic/blob/master/src/registers.rs
49 // shift 24 because the ID is in the upper 8 bits
50 return lapic_read32(APIC_REG_LAPIC_ID) >> 24;
51}
52
58
64
65void ioapic_init(void);
66void ioapic_enable_with_mode(u32 irq, u32 cpu, ioapic_trigger_mode_t trigger_mode, ioapic_polarity_t polarity);
67void ioapic_disable(u32 irq);
68
69void lapic_set_timer(u32 initial_count);
70
void ioapic_init(void)
Definition ioapic.c:93
should_inline void ioapic_enable_interrupt(u32 irq, u32 lapic_id)
Definition apic.h:71
void lapic_interrupt(u8 vec, u8 dest, lapic_delivery_mode_t delivery_mode, lapic_dest_mode_t dest_mode, lapic_shorthand_t shorthand)
Definition lapic.c:111
void lapic_set_timer(u32 initial_count)
Definition lapic.c:151
ioapic_polarity_t
Definition apic.h:60
@ IOAPIC_POLARITY_ACTIVE_HIGH
Definition apic.h:61
@ IOAPIC_POLARITY_ACTIVE_LOW
Definition apic.h:62
lapic_delivery_mode_t
Definition apic.h:10
@ APIC_DELIVER_MODE_SMI
Definition apic.h:13
@ APIC_DELIVER_MODE_NORMAL
Definition apic.h:11
@ APIC_DELIVER_MODE_INIT_DEASSERT
Definition apic.h:16
@ APIC_DELIVER_MODE_INIT
Definition apic.h:15
@ APIC_DELIVER_MODE_NMI
Definition apic.h:14
@ APIC_DELIVER_MODE_STARTUP
Definition apic.h:17
@ APIC_DELIVER_MODE_LOWEST_PRIORITY
Definition apic.h:12
void lapic_eoi(void)
Definition lapic.c:158
void lapic_write32(u32 offset, u32 value)
Definition lapic.c:72
should_inline u8 lapic_get_id(void)
Definition apic.h:45
u32 lapic_read32(u32 offset)
Definition lapic.c:56
#define APIC_REG_LAPIC_ID
Definition apic.h:8
lapic_shorthand_t
Definition apic.h:27
@ LAPIC_SHORTHAND_ALL
Definition apic.h:30
@ LAPIC_SHORTHAND_NONE
Definition apic.h:28
@ LAPIC_SHORTHAND_SELF
Definition apic.h:29
@ LAPIC_SHORTHAND_ALL_EXCLUDING_SELF
Definition apic.h:31
lapic_dest_mode_t
Definition apic.h:21
@ LAPIC_DEST_MODE_LOGICAL
Definition apic.h:23
@ LAPIC_DEST_MODE_PHYSICAL
Definition apic.h:22
void lapic_interrupt_full(u8 vec, u8 dest, lapic_delivery_mode_t dliv_mode, lapic_dest_mode_t dstmode, bool lvl, bool trigger, lapic_shorthand_t sh)
Definition lapic.c:94
void lapic_write64(u32 offset, u64 value)
Definition lapic.c:79
u64 lapic_read64(u32 offset)
Definition lapic.c:63
void ioapic_disable(u32 irq)
Definition ioapic.c:139
ioapic_trigger_mode_t
Definition apic.h:54
@ IOAPIC_TRIGGER_MODE_LEVEL
Definition apic.h:56
@ IOAPIC_TRIGGER_MODE_EDGE
Definition apic.h:55
void lapic_enable(void)
Definition lapic.c:136
void ioapic_enable_with_mode(u32 irq, u32 cpu, ioapic_trigger_mode_t trigger_mode, ioapic_polarity_t polarity)
Definition ioapic.c:125
#define should_inline
Definition mos_global.h:37
unsigned int u32
Definition types.h:21
unsigned long long u64
Definition types.h:23
unsigned char u8
Definition types.h:19