9#ifndef MAXOS_HARDWARECOMMUNICATION_APIC_H
10#define MAXOS_HARDWARECOMMUNICATION_APIC_H
12#include <libcommon/macros.h>
13#include <libcommon/port.h>
19namespace MaxOS::hardwarecommunication {
27 EXCLUDE_SELF = (1 << 1),
37 uint64_t m_apic_base = 0;
38 uint64_t m_apic_base_high = 0;
40 bool m_x2apic =
false;
46 [[nodiscard]] uint32_t
read(uint32_t reg)
const;
47 void write(uint32_t reg, uint32_t value)
const;
49 [[nodiscard]] uint32_t
id()
const;
51 void send_icr(uint32_t icr_low, uint32_t icr_high,
bool use_shorthand)
const;
53 void send_init(uint8_t apic_id,
bool assert)
const;
54 void send_startup(uint8_t apic_id, uint8_t vector)
const;
55 void send_interrupt(uint8_t apic_id, uint8_t vector,
size_t flags)
const;
67 typedef struct PACKED
MADT {
92 INTERRUPT_SOURCE_OVERRIDE,
95 APIC_ADDRESS_OVERRIDE,
126 } madt_processor_apic_t;
150 } redirection_entry_t;
183 } interrupt_redirect_t;
208 MADT* m_madt = {
nullptr };
209 uint64_t m_address = 0;
210 uint64_t m_address_high = 0;
211 uint32_t m_version = 0;
212 uint8_t m_max_redirect_entry = 0;
214 uint8_t m_override_array_size = 0;
215 Override m_override_array[0x10] = { };
224 [[nodiscard]] uint32_t
read(uint32_t reg)
const;
225 void write(uint32_t reg, uint32_t value)
const;
246 common::Port8BitSlow m_pic_master_command_port;
247 common::Port8BitSlow m_pic_master_data_port;
248 common::Port8BitSlow m_pic_slave_command_port;
249 common::Port8BitSlow m_pic_slave_data_port;
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...
LAPICSendInterruptFlags
Represents bitfield entries in the LAPIC flags.
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
void send_icr(uint32_t icr_low, uint32_t icr_high, bool use_shorthand) const
Send an Interrupt Command Register (ICR) to the local apic.
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.
void send_interrupt(uint8_t apic_id, uint8_t vector, size_t flags) const
Send an interrupt to a specific core.
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
Defines a PhysicalMemoryManager class for managing physical memory allocation and deallocation of pag...
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.