λ

furix

cute os

settings

include/acpi.h

1395 bytes raw

#ifndef FURIX_ACPI_H
#define FURIX_ACPI_H

#include <efi.h>
#include <types.h>

#define ACPI_MAX_APIC_IDS 256

struct acpi_madt_info {
  uint32_t cpu_count;
  uint32_t ioapic_count;

  /*
   * firmware-reported processor IDs, which for a MADT using x2APIC entries are
   * 32-bit and need not fit in a byte. kept as uint32_t rather than narrowed,
   * because a truncated ID silently retargets an INIT/SIPI at the wrong CPU,
   * which presents as an AP that never boots.
   */
  uint32_t apic_ids[ACPI_MAX_APIC_IDS];

  /*
   * dense 0..cpu_count-1 index into the per-CPU array, parallel to apic_ids.
   *
   * needed because x2APIC IDs may exceed the number of per-CPU slots we
   * reserve, so the ID itself cannot be used as an array index. the BSP picks
   * the slot and the trampoline is patched with it.
   */
  uint8_t slots[ACPI_MAX_APIC_IDS];
};

/* locate the RSDP via the UEFI config table and enumerate the MADT */
bool acpi_madt_parse(const EFI_SYSTEM_TABLE *st, struct acpi_madt_info *out);

/*
 * number of processors the BSP must start, i.e. every MADT CPU except itself.
 *
 * a helper rather than open-coded `cpu_count - 1`: if the MADT lists no
 * enabled local APIC at all, the subtraction wraps to UINT32_MAX and the
 * bring-up loop spins looking for four billion processors.
 */
uint32_t acpi_madt_ap_count(const struct acpi_madt_info *madt);

#endif /* FURIX_ACPI_H */