9#ifndef MAXOS_HARDWARECOMMUNICATION_APIC_H
10#define MAXOS_HARDWARECOMMUNICATION_APIC_H
12#include <common/macros.h>
18namespace MaxOS::hardwarecommunication {
27 uint64_t m_apic_base { };
28 uint64_t m_apic_base_high { };
36 [[nodiscard]] uint32_t
read(uint32_t reg)
const;
37 void write(uint32_t reg, uint32_t value)
const;
39 [[nodiscard]] uint32_t
id()
const;
42 void send_init(uint8_t apic_id,
bool assert)
const;
43 void send_startup(uint8_t apic_id, uint8_t vector)
const;
55 typedef struct PACKED
MADT {
80 INTERRUPT_SOURCE_OVERRIDE,
83 APIC_ADDRESS_OVERRIDE,
114 } madt_processor_apic_t;
138 } redirection_entry_t;
171 } interrupt_redirect_t;
196 MADT* m_madt = {
nullptr };
197 uint64_t m_address = 0;
198 uint64_t m_address_high = 0;
199 uint32_t m_version = 0;
200 uint8_t m_max_redirect_entry = 0;
202 uint8_t m_override_array_size = 0;
203 Override m_override_array[0x10] = { };
212 [[nodiscard]] uint32_t
read(uint32_t reg)
const;
213 void write(uint32_t reg, uint32_t value)
const;
Defines an Advanced Configuration And Power Interface (ACPI class for handling ACPI table parsing and...
MADT_TYPE
The types of MADT entries.
DeliveryMode
How the interrupt should be delivered (can it override others etc). Set fixed/lowest priority for nor...
Handles ACPI table parsing and retrieval.
Handles both the Local APIC (boot core) and IO APIC.
IOAPIC * io_apic() const
Get the io apic.
~AdvancedProgrammableInterruptController()
Destroy the Advanced Programmable Interrupt Controller object and frees the Local APIC and IO APIC.
LocalAPIC * local_apic() const
Get the local apic.
Handles the IO APIC in the system (one per system)
void write(uint32_t reg, uint32_t value) const
write a value to an IO Apic register
void set_redirect(interrupt_redirect_t *redirect)
Redirect a system interrupt to a different IRQ.
MADTEntry * get_madt_item(MADT_TYPE type, uint8_t index)
Get an item in the MADT.
void set_redirect_mask(uint8_t index, bool mask)
Enables/Disables an interrupt redirect by masking it.
uint32_t read(uint32_t reg) const
read a value from a IO Apic register
Handles the local APIC for the current core.
void send_eoi() const
Acknowledge that the interrupt has been handled, allowing the PIC to process the next interrupt.
void write(uint32_t reg, uint32_t value) const
write a value to the apic register using the MSR or memory I/O depending on the local apic version
uint32_t id() const
Get the id of the local apic.
LocalAPIC()
Construct a new Local APIC object and map the APIC base address to the higher half if needed as well ...
void send_startup(uint8_t apic_id, uint8_t vector) const
send the start up IPI to another apic
uint32_t read(uint32_t reg) const
read a value from the apic register using the MSR or memory I/O depending on the local apic version
void send_init(uint8_t apic_id, bool assert) const
send the init IPI to another apic
Handles 8 bit ports (slow)
Defines a PhysicalMemoryManager class for managing physical memory allocation and deallocation of pag...
Defines classes for handling hardware communication ports (8, 16, and 32 bit)
Defines how an interrupt input is redirected to a specific processor via the I/O APIC.
uint8_t index
Where in the IO APIC redirection table this redirect should be placed.
uint8_t interrupt
The interrupt number to trigger when this redirect is used.
uint32_t flags
Configuration flags for the interrupt (see MADT override flags)
bool mask
Should the interrupt be disabled initially.
uint8_t type
The type of redirect (should be 0 for normal interrupts)
uint8_t destination
The ID of the core the interrupt should be sent to.
An item in the MADT table.
uint8_t type
The type of the MADT entry (see MADT_TYPE)
uint8_t length
How many bytes this entry takes up (including the type and length fields)
An entry in the MADT table describing an IO APIC.
uint8_t reserved
Reserved.
uint8_t io_apic_id
The ID of the IO APIC.
uint32_t io_apic_address
The physical address of the IO APIC.
uint32_t global_system_interrupt_base
The first GSI number that this IO APIC handles.
An entry in the MADT table describing a processor local APIC.
uint8_t processor_id
The ID for the core.
uint8_t apic_id
The ID for the APIC that the core uses.
uint32_t flags
Flags indicating the status of the core (bit 0 = core enabled, bit 1 = can be enabled)
Multiple APIC Description Table (MADT) (ACPI 2 or higher). Provides information about the APICs in th...
uint32_t local_apic_address
The physical address of the local APIC.
ACPISDTHeader header
Common ACPI SDT header.
uint32_t flags
Flags indicating the capabilities of the system (1 = Legacy PICs are present)
Specifies how a specific interrupt source is mapped to a global system interrupt.
uint8_t source
The interrupt source number on the specified bus.
uint32_t global_system_interrupt
The global system interrupt that the source is mapped to.
uint8_t bus
Identifies the hardware bus the interrupt comes from (0 = ISA, 1 = PCI)
uint16_t flags
Flags describing the polarity and trigger mode of the interrupt source (see MADT override flags)
Packed because the bitfields should be one uint64_t together.
uint64_t destination_mode
How to interpret the destination field (0 = means its the core ID, 1 = means a bitmask of cores)
uint64_t mask
Whether the interrupt is disabled or not.
uint64_t delivery_mode
How the interrupt will be delvied to the core(s) (see DeliveryMode)
uint64_t destination
The core(s) the interrupt should be sent to (interpreted based on destination_mode)
uint64_t trigger_mode
How the electrical signal is interpreted (0 = edge triggered, 1 = level triggered) (must match the MA...
uint64_t delivery_status
Indicates whether, when setting this entry, the interrupt is still being sent.
uint64_t vector
The interrupt that will be triggered when this redirection entry is used.
uint64_t reserved
Reserved bits (should be zero)
uint64_t pin_polarity
Defines the electrical signal that indicates an active interrupt line (0 = high active,...
An IO APIC redirection entry. Describes how an interrupt is routed.
uint64_t raw
The raw 64-bit value of the redirection entry.