x86_64: move ACPI driver to kext
This commit is contained in:
@@ -1,126 +0,0 @@
|
||||
#ifndef ARCH_ACPI_H_
|
||||
#define ARCH_ACPI_H_
|
||||
|
||||
#include <socks/compiler.h>
|
||||
#include <socks/status.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ACPI_MADT_LAPIC 0x00
|
||||
#define ACPI_MADT_IOAPIC 0x01
|
||||
#define ACPI_MADT_IRQSRC_OVERRIDE 0x02
|
||||
#define ACPI_MADT_LAPIC_OVERRIDE 0x05
|
||||
|
||||
#define ACPI_SIG_RSDP 0x2052545020445352ULL
|
||||
#define ACPI_SIG_FADT 0x50434146
|
||||
#define ACPI_SIG_MADT 0x43495041
|
||||
|
||||
#define AP_TRAMPOLINE_PADDR 0x8000
|
||||
#define LAPIC_IPI_STATUS_REG 0x0280
|
||||
#define LAPIC_IPI_DEST_REG 0x0310
|
||||
#define LAPIC_IPI_ICR_REG 0x0300
|
||||
|
||||
struct acpi_rsdp_10 {
|
||||
char r_sig[8];
|
||||
uint8_t r_chksum;
|
||||
char r_oem[6];
|
||||
uint8_t r_revision;
|
||||
uint32_t r_rsdt_ptr;
|
||||
} __packed;
|
||||
|
||||
struct acpi_rsdp_20 {
|
||||
struct acpi_rsdp_10 r_base;
|
||||
|
||||
uint32_t r_length;
|
||||
uint64_t r_xsdt_ptr;
|
||||
uint8_t r_chksum_ext;
|
||||
uint8_t r_reserved[3];
|
||||
} __packed;
|
||||
|
||||
struct acpi_rsdp {
|
||||
union {
|
||||
struct acpi_rsdp_10 rsdp_10;
|
||||
struct acpi_rsdp_20 rsdp_20;
|
||||
};
|
||||
} __packed;
|
||||
|
||||
struct acpi_sdt {
|
||||
char s_sig[4];
|
||||
uint32_t s_length;
|
||||
uint8_t s_revision;
|
||||
uint8_t s_chksum;
|
||||
char s_oem[6];
|
||||
char s_oem_table[8];
|
||||
uint32_t s_oem_revision;
|
||||
uint32_t s_creator;
|
||||
uint32_t s_creator_revision;
|
||||
} __packed;
|
||||
|
||||
struct acpi_rsdt {
|
||||
struct acpi_sdt r_header;
|
||||
uint32_t r_tables[1];
|
||||
} __packed;
|
||||
|
||||
struct acpi_xsdt {
|
||||
struct acpi_sdt x_header;
|
||||
uint64_t x_tables[1];
|
||||
} __packed;
|
||||
|
||||
struct acpi_madt {
|
||||
struct acpi_sdt m_base;
|
||||
uint32_t m_lapic_ptr;
|
||||
uint32_t m_flags;
|
||||
} __packed;
|
||||
|
||||
struct acpi_madt_record {
|
||||
uint8_t r_type;
|
||||
uint8_t r_length;
|
||||
} __packed;
|
||||
|
||||
struct acpi_madt_ioapic {
|
||||
uint8_t io_apic_id;
|
||||
uint8_t io_reserved;
|
||||
uint32_t io_address;
|
||||
uint32_t io_intbase;
|
||||
} __packed;
|
||||
|
||||
struct acpi_madt_irqsrc_override {
|
||||
uint8_t irq_bus;
|
||||
/* the irq vector as delivered from the APIC to the CPU */
|
||||
uint8_t irq_destvec;
|
||||
/* the irq vector as delivered from the hardware to the APIC */
|
||||
uint32_t irq_srcvec;
|
||||
uint16_t irq_flags;
|
||||
} __packed;
|
||||
|
||||
struct lapic_record {
|
||||
uint8_t l_cpu_id;
|
||||
uint8_t l_apic_id;
|
||||
uint32_t l_flags;
|
||||
} __packed;
|
||||
|
||||
struct lapic_override_record {
|
||||
uint16_t l_reserved;
|
||||
uint64_t l_lapic_ptr;
|
||||
} __packed;
|
||||
|
||||
|
||||
extern kern_status_t acpi_init(void);
|
||||
extern kern_status_t acpi_scan_cpu_topology(void);
|
||||
|
||||
extern kern_status_t ap_apic_init(void);
|
||||
extern kern_status_t apic_init(void);
|
||||
extern kern_status_t smp_init(void);
|
||||
|
||||
extern struct acpi_sdt *acpi_find_sdt(uint32_t sig);
|
||||
|
||||
extern void irq_ack(unsigned int vec);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,41 +0,0 @@
|
||||
#ifndef ARCH_ACPI_IOAPIC_HPP_
|
||||
#define ARCH_ACPI_IOAPIC_HPP_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <socks/status.h>
|
||||
#include <socks/queue.h>
|
||||
|
||||
namespace arch::acpi {
|
||||
struct io_apic {
|
||||
uint32_t *io_base = nullptr;
|
||||
unsigned int io_first_irq = 0;
|
||||
unsigned int io_nr_irq = 0;
|
||||
struct queue_entry io_entry;
|
||||
|
||||
struct irq_entry {
|
||||
uint64_t irq_vec : 8;
|
||||
uint64_t irq_delivery : 3;
|
||||
uint64_t irq_destmode : 1;
|
||||
uint64_t irq_status : 1;
|
||||
uint64_t irq_polarity : 1;
|
||||
uint64_t irq_irr : 1;
|
||||
uint64_t irq_triggermode : 1;
|
||||
uint64_t irq_mask : 1;
|
||||
uint64_t irq_resv : 39;
|
||||
uint64_t irq_dest : 8;
|
||||
};
|
||||
|
||||
io_apic(uint32_t *base, unsigned int first_irq);
|
||||
|
||||
uint32_t read(uint32_t reg);
|
||||
void write(uint32_t reg, uint32_t val);
|
||||
|
||||
kern_status_t read_irq(unsigned int index, irq_entry &entry);
|
||||
void write_irq(unsigned int index, const irq_entry &entry);
|
||||
void map_irq(unsigned int src, unsigned int dest, unsigned int dest_cpu = 0);
|
||||
void mask_irq(unsigned int vec);
|
||||
void unmask_irq(unsigned int vec, unsigned int dest_cpu = (unsigned int)-1);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,43 +0,0 @@
|
||||
#ifndef ARCH_ACPI_LOCAL_APIC_HPP_
|
||||
#define ARCH_ACPI_LOCAL_APIC_HPP_
|
||||
|
||||
#include <socks/status.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define APIC_LVT_INT_MASKED 0x10000
|
||||
#define APIC_LVT_TIMER_MODE_PERIODIC 0x20000
|
||||
|
||||
struct acpi_madt;
|
||||
|
||||
namespace arch::acpi {
|
||||
class local_apic {
|
||||
uint32_t *base_ = nullptr;
|
||||
|
||||
public:
|
||||
enum {
|
||||
EOI = 0xB0,
|
||||
IPI_STATUS = 0x280,
|
||||
IPI_ICR = 0x300,
|
||||
IPI_DEST = 0x310,
|
||||
LVT_TIMER = 0x320,
|
||||
TIMER_INITCOUNT = 0x380,
|
||||
TIMER_CURCOUNT = 0x390,
|
||||
TIMER_DIV = 0x3E0,
|
||||
};
|
||||
|
||||
local_apic(uint32_t *base = nullptr);
|
||||
|
||||
static kern_status_t find(struct acpi_madt *madt, local_apic& out);
|
||||
static local_apic& get(void);
|
||||
|
||||
uint32_t read(uint32_t reg);
|
||||
void write(uint32_t reg, uint32_t val);
|
||||
void ack();
|
||||
|
||||
uint32_t *ptr() const { return base_; }
|
||||
|
||||
void send_ipi(unsigned int dest, unsigned int data);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user