apic: Added madt entry struct types

This also moves madt parsing to apic.c
This commit is contained in:
Michael Shaw 2023-02-28 19:51:37 -05:00
commit 57ed3eefe6
6 changed files with 130 additions and 41 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
*.o
*.d
kernel.elf
compile_commands.json

View file

@ -1,4 +1,57 @@
#include <kernel/common.h>
#include <kernel/acpi.h>
#include <dev/apic.h>
#include <stdio.h>
static void *madt_entries[0x20];
static int n_madt_entries = 0;
static const char *madt_entry_types[] = { "LAPIC",
"IOAPIC",
"IOAPIC_IRQ_SRC_OVRD",
"IOAPIC_NMI_SRC",
"LAPIC_NMI",
"LAPIC_ADDR_OVRD",
"INVALID",
"INVALID",
"INVALID",
"CPU_LOCAL_X2_APIC" };
int madt_parse_next_entry(int offset)
{
if ((unsigned)offset >= (__madt->h.length - 1))
return 0;
uint8_t *madt = (uint8_t *)__madt;
int type = madt[offset];
int len = madt[offset + 1];
printf("MADT Entry %d: %s\n", n_madt_entries, madt_entry_types[type]);
switch (type) {
case MADT_LAPIC:
break;
case MADT_IOAPIC:
break;
case MADT_IOAPIC_OVRD:
break;
case MADT_IOAPIC_NMI:
break;
case MADT_LAPIC_NMI:
break;
case MADT_LAPIC_OVRD:
break;
case MADT_X2_LAPIC:
break;
default:
printf("Unrecognized MADT entry #%d, type=%d\n", n_madt_entries,
type);
}
/* Add this entry to the list */
madt_entries[n_madt_entries] = madt;
n_madt_entries++;
return offset + len;
}

View file

@ -1,22 +1,83 @@
#ifndef _APIC_H_
#define _APIC_H_
#define MADT_LAPIC 0
#define MADT_IOAPIC 1
#define MADT_IOAPIC_OVRD 2
#define MADT_IOAPIC_NMI 3
#define MADT_LAPIC_NMI 4
#define MADT_LAPIC_OVRD 5
#define MADT_X2_LAPIC 9
#ifndef __ASM__
#include <kernel/common.h>
#include <kernel/acpi.h>
struct madt {
char signature[4];
uint32_t length;
uint8_t revision;
uint8_t checksum;
char oemid[6];
uint64_t oem_tableid;
uint32_t oem_rev;
uint32_t creator_id;
uint32_t creator_revision;
struct acpi_sdt_header h;
uint32_t lapic_addr;
uint32_t flags;
} PACKED;
} __attribute__((packed));
struct madt_header {
uint8_t type;
uint8_t length;
} PACKED;
struct madt_lapic {
struct madt_header h;
uint8_t acpi_cpu_id;
uint8_t apic_id;
uint32_t flags;
} PACKED;
struct madt_ioapic {
struct madt_header h;
uint8_t ioapic_id;
uint8_t reserved;
uint32_t ioapic_addr;
uint32_t intr_base;
} PACKED;
struct madt_ioapic_ovrd {
struct madt_header h;
uint8_t bus;
uint8_t irq;
uint32_t intr;
uint16_t flags;
} PACKED;
struct madt_ioapic_nmi {
struct madt_header h;
uint8_t nmi;
uint8_t reserved;
uint16_t flags;
uint32_t intr;
} PACKED;
struct madt_lapic_nmi {
struct madt_header h;
uint8_t acpi_cpu_id;
uint16_t flags;
uint8_t lint;
} PACKED;
struct madt_lapic_ovrd {
struct madt_header h;
uint16_t reserved;
uint64_t lapic_addr;
} PACKED;
struct madt_x2_lapic {
struct madt_header h;
uint16_t reserved;
uint32_t lapic_id;
uint32_t flags;
uint32_t acpi_id;
} PACKED;
int madt_parse_next_entry(int offset);
#endif /* __ASM__ */
#endif /* _APIC_H_ */

View file

@ -30,12 +30,6 @@ struct rsdt {
uint32_t sdt[];
} PACKED;
struct madt {
struct acpi_sdt_header h;
uint32_t lapic_addr;
uint32_t flags;
} PACKED;
void acpi_init();
extern struct madt *__madt;

View file

@ -3,6 +3,8 @@
#include <kernel/common.h>
#define MSR_APIC_BASE 0x1B
#ifndef __ASM__
uint64_t rdmsr(uint32_t msr);

View file

@ -1,4 +1,6 @@
#include <kernel/acpi.h>
#include <dev/apic.h>
#include <limine/limine.h>
#include <stdio.h>
@ -10,13 +12,6 @@ struct limine_rsdp_request rsdp_req = { .id = LIMINE_RSDP_REQUEST,
static struct rsdp *rsdp = NULL;
struct madt *__madt = NULL;
static const char *madt_entry_types[] = {
"LAPIC", "IOAPIC", "IOAPIC_IRQ_SRC_OVRD",
"IOAPIC_NMI_SRC", "LAPIC_NMI", "LAPIC_ADDR_OVRD",
"INVALID", "INVALID", "INVALID",
"CPU_LOCAL_X2-APIC"
};
void rsdt_print(struct rsdt *rsdt)
{
int num_sdt = (rsdt->h.length - sizeof(rsdt->h)) / 4;
@ -37,23 +32,6 @@ void rsdt_print(struct rsdt *rsdt)
}
}
int madt_parse_next_entry(int offset)
{
if ((unsigned)offset >= (__madt->h.length - 1))
return 0;
static int n = 0; /* Entry number */
uint8_t *madt = (uint8_t *)__madt;
int type = madt[offset];
int len = madt[offset + 1];
printf("MADT Entry %d: %s\n", n, madt_entry_types[type]);
n++;
return offset + len;
}
void acpi_init()
{
rsdp = (struct rsdp *)rsdp_req.response->address;