PatchworkOS
Loading...
Searching...
No Matches
apic.h File Reference
#include <kernel/acpi/tables.h>
#include <kernel/cpu/interrupt.h>
#include <kernel/defs.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  ioapic_version_t
 IO APIC Version Structure. More...
 
struct  ioapic_redirect_entry_t
 IO APIC Redirection Entry Structure. More...
 
struct  ioapic_redirect_entry_t::PACKED
 

Macros

#define LAPIC_REG_ICR1_ID_OFFSET   24
 The offset at which the lapic id is stored in the LAPIC_REG_ID register.
 
#define IOAPIC_REG_REDIRECTION(pin, high)   (0x10 + (pin) * 2 + (high))
 Macro to get the redirection entry register for a specific pin.
 
#define APIC_TIMER_TICKS_FIXED_POINT_OFFSET   32
 APIC Timer Ticks Fixed Point Offset.
 

Typedefs

typedef struct cpu cpu_t
 
typedef uint8_t lapic_id_t
 Local APIC ID type.
 
typedef uint32_t ioapic_gsi_t
 IO APIC Global System Interrupt type.
 

Enumerations

enum  apic_timer_mode_t {
  APIC_TIMER_MASKED = 0x10000 ,
  APIC_TIMER_PERIODIC = 0x20000 ,
  APIC_TIMER_ONE_SHOT = 0x00000
}
 APIC Timer Modes. More...
 
enum  apic_timer_divider_t {
  APIC_TIMER_DIV_16 = 0x3 ,
  APIC_TIMER_DIV_32 = 0x4 ,
  APIC_TIMER_DIV_64 = 0x5 ,
  APIC_TIMER_DIV_128 = 0x6 ,
  APIC_TIMER_DIV_DEFAULT = APIC_TIMER_DIV_16
}
 APIC Timer Divider Values. More...
 
enum  lapic_msr_flags_t {
  LAPIC_MSR_ENABLE = 0x800 ,
  LAPIC_MSR_BSP = 0x100
}
 Local APIC MSR Flags. More...
 
enum  lapic_register_t {
  LAPIC_REG_ID = 0x020 ,
  LAPIC_REG_VERSION = 0x030 ,
  LAPIC_REG_TASK_PRIORITY = 0x080 ,
  LAPIC_REG_ARBITRATION_PRIORITY = 0x090 ,
  LAPIC_REG_PROCESSOR_PRIORITY = 0x0A0 ,
  LAPIC_REG_EOI = 0x0B0 ,
  LAPIC_REG_REMOTE_READ = 0x0C0 ,
  LAPIC_REG_LOGICAL_DEST = 0x0D0 ,
  LAPIC_REG_DEST_FORMAT = 0x0E0 ,
  LAPIC_REG_SPURIOUS = 0x0F0 ,
  LAPIC_REG_ISR_BASE = 0x100 ,
  LAPIC_REG_TMR_BASE = 0x180 ,
  LAPIC_REG_IRR_BASE = 0x200 ,
  LAPIC_REG_ERROR_STATUS = 0x280 ,
  LAPIC_REG_LVT_CMCI = 0x2F0 ,
  LAPIC_REG_ICR0 = 0x300 ,
  LAPIC_REG_ICR1 = 0x310 ,
  LAPIC_REG_LVT_TIMER = 0x320 ,
  LAPIC_REG_LVT_THERMAL = 0x330 ,
  LAPIC_REG_LVT_PERFCTR = 0x340 ,
  LAPIC_REG_LVT_LINT0 = 0x350 ,
  LAPIC_REG_LVT_LINT1 = 0x360 ,
  LAPIC_REG_LVT_ERROR = 0x370 ,
  LAPIC_REG_TIMER_INITIAL_COUNT = 0x380 ,
  LAPIC_REG_TIMER_CURRENT_COUNT = 0x390 ,
  LAPIC_REG_TIMER_DIVIDER = 0x3E0
}
 Local APIC Registers. More...
 
enum  lapic_flags_t {
  LAPIC_SPURIOUS_ENABLE = (1 << 8) ,
  LAPIC_LVT_MASKED = (1 << 16)
}
 Local APIC Flags. More...
 
enum  lapic_icr_delivery_mode_t {
  LAPIC_ICR_FIXED = (0 << 8) ,
  LAPIC_ICR_LOWEST_PRIORITY = (1 << 8) ,
  LAPIC_ICR_SMI = (2 << 8) ,
  LAPIC_ICR_NMI = (4 << 8) ,
  LAPIC_ICR_INIT = (5 << 8) ,
  LAPIC_ICR_STARTUP = (6 << 8)
}
 Local APIC ICR Delivery Modes. More...
 
enum  lapic_icr_flags_t { LAPIC_ICR_CLEAR_INIT_LEVEL = (1 << 14) }
 Local APIC ICR Flags. More...
 
enum  ioapic_mmio_register_t {
  IOAPIC_MMIO_REG_SELECT = 0x00 ,
  IOAPIC_MMIO_REG_DATA = 0x10
}
 IO APIC Memory Mapped Registers. More...
 
enum  ioapic_register_t { IOAPIC_REG_VERSION = 0x01 }
 IO APIC Registers. More...
 
enum  ioapic_delivery_mode_t {
  IOAPIC_DELIVERY_NORMAL = 0 ,
  IOAPIC_DELIVERY_LOW_PRIO = 1 ,
  IOAPIC_DELIVERY_SMI = 2 ,
  IOAPIC_DELIVERY_NMI = 4 ,
  IOAPIC_DELIVERY_INIT = 5 ,
  IOAPIC_DELIVERY_EXTERNAL = 7
}
 IO APIC Delivery Modes. More...
 
enum  ioapic_destination_mode_t {
  IOAPIC_DESTINATION_PHYSICAL = 0 ,
  IOAPIC_DESTINATION_LOGICAL = 1
}
 IO APIC Destination Modes. More...
 
enum  ioapic_trigger_mode_t {
  IOAPIC_TRIGGER_EDGE = 0 ,
  IOAPIC_TRIGGER_LEVEL = 1
}
 IO APIC Trigger Modes. More...
 
enum  ioapic_polarity_t {
  IOAPIC_POLARITY_HIGH = 0 ,
  IOAPIC_POLARITY_LOW = 1
}
 IO APIC Polarity Modes. More...
 

Functions

void apic_timer_one_shot (interrupt_t vector, uint32_t ticks)
 Configure the apic timer in one-shot mode.
 
uint64_t apic_timer_ticks_per_ns (void)
 Apic timer ticks per nanosecond.
 
void lapic_cpu_init (void)
 Initialize the local apic for the current cpu.
 
lapic_id_t lapic_self_id (void)
 Get the lapic id of the current cpu.
 
void lapic_write (lapic_register_t reg, uint32_t value)
 Write to a local apic register.
 
uint32_t lapic_read (lapic_register_t reg)
 Read from a local apic register.
 
void lapic_send_init (lapic_id_t id)
 Send an INIT IPI to a local apic.
 
void lapic_send_sipi (lapic_id_t id, void *entryPoint)
 Send a Startup IPI to a local apic.
 
void lapic_send_ipi (lapic_id_t id, interrupt_t vector)
 Send an Inter-Processor Interrupt (IPI) to a local apic.
 
void lapic_eoi (void)
 Send an End Of Interrupt (EOI) signal to the local apic.
 
uint32_t ioapic_read (ioapic_t *ioapic, ioapic_register_t reg)
 Read from an IOAPIC register.
 
void ioapic_write (ioapic_t *ioapic, ioapic_register_t reg, uint32_t value)
 Write to an IOAPIC register.
 
ioapic_version_t ioapic_get_version (ioapic_t *ioapic)
 Get the IOAPIC version.
 
ioapic_tioapic_from_gsi (ioapic_gsi_t gsi)
 Get the IOAPIC id responsible for a given GSI.
 
void ioapic_set_redirect (interrupt_t vector, ioapic_gsi_t gsi, ioapic_delivery_mode_t deliveryMode, ioapic_polarity_t polarity, ioapic_trigger_mode_t triggerMode, cpu_t *cpu, bool enable)
 Set an IOAPIC redirection entry.
 

Typedef Documentation

◆ cpu_t

typedef struct cpu cpu_t

Definition at line 9 of file apic.h.