furix
cute os
include/acpi.h
1395 bytes raw
1#ifndef FURIX_ACPI_H
2#define FURIX_ACPI_H
3
4#include <efi.h>
5#include <types.h>
6
7#define ACPI_MAX_APIC_IDS 256
8
9struct acpi_madt_info {
10 uint32_t cpu_count;
11 uint32_t ioapic_count;
12
13 /*
14 * firmware-reported processor IDs, which for a MADT using x2APIC entries are
15 * 32-bit and need not fit in a byte. kept as uint32_t rather than narrowed,
16 * because a truncated ID silently retargets an INIT/SIPI at the wrong CPU,
17 * which presents as an AP that never boots.
18 */
19 uint32_t apic_ids[ACPI_MAX_APIC_IDS];
20
21 /*
22 * dense 0..cpu_count-1 index into the per-CPU array, parallel to apic_ids.
23 *
24 * needed because x2APIC IDs may exceed the number of per-CPU slots we
25 * reserve, so the ID itself cannot be used as an array index. the BSP picks
26 * the slot and the trampoline is patched with it.
27 */
28 uint8_t slots[ACPI_MAX_APIC_IDS];
29};
30
31/* locate the RSDP via the UEFI config table and enumerate the MADT */
32bool acpi_madt_parse(const EFI_SYSTEM_TABLE *st, struct acpi_madt_info *out);
33
34/*
35 * number of processors the BSP must start, i.e. every MADT CPU except itself.
36 *
37 * a helper rather than open-coded `cpu_count - 1`: if the MADT lists no
38 * enabled local APIC at all, the subtraction wraps to UINT32_MAX and the
39 * bring-up loop spins looking for four billion processors.
40 */
41uint32_t acpi_madt_ap_count(const struct acpi_madt_info *madt);
42
43#endif /* FURIX_ACPI_H */