acpi: uACPI, for interrupt routing, the power button and power-off

The firmware's AML is now interpreted. uACPI 6.1.1 (MIT) is fetched by
ports/uacpi, checksum-verified, and compiled into the kernel unmodified,
the same way lwIP is. kernel/acpi/host.c is its host layer: memory,
mapping, port and PCI config I/O, time, mutexes and events that spin
before the scheduler exists, the SCI, and an "acpi" thread for the
work the SCI defers.

PCI interrupts go where the board says. pci_init() now routes every
device's INTx through the root bridge's _PRT before drivers bind. It
follows link devices' _CRS, uses a bridge's own _PRT where the namespace
has one, and swizzles through bridges that don't. Before this, INTx
waited on the 8259's line number, which is the wrong pin in APIC mode.
irq_register() takes a trigger mode rather than a level/low flag,
because q35's links and most SCIs are level, active-high. The MADT's
interrupt source overrides are now parsed, and are what places the SCI.

The power button syncs the filesystems and powers off. shutdown() and
reboot() go through the firmware's S5 and reset register first, and
only then fall back to the emulators' ports, which a real board does
not answer.

Tested under QEMU: q35 with MSI off routes xHCI to GSI 22,
level/active-high, and it takes real interrupts with nothing polled.
system_powerdown powers off q35 and i440fx (QEMU exits 0), and q35
with 4 CPUs boots from NVMe with USB hot-plug working alongside.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S1giNvrHTrPMPw7V6x1kQ4
This commit is contained in:
Nexoniarz 2026-10-22 16:12:28 +02:00
commit 93f981c7ea
16 changed files with 1237 additions and 14 deletions

44
ports/uacpi/Makefile Normal file
View file

@ -0,0 +1,44 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# uACPI -- the ACPI AML interpreter. MIT; see LICENSE in the tarball and
# docs/licensing.md.
#
# Kernel code, like lwIP: nothing is installed into the sysroot. This
# directory fetches and unpacks a pinned release, and the top-level Makefile
# compiles its sources straight into the kernel against kernel/acpi/, which
# supplies everything uACPI asks of a host. That is why there is no build or
# install rule below and no dependency on musl.
#
# Chosen over ACPICA, which does the same job in roughly ten times the code
# and asks more of its host, and over writing an interpreter here: AML is a
# whole language, every firmware vendor's compiler emits its own dialect of
# it, and uACPI is tested against real machines' tables as a matter of course.
include ../mk/port.mk
UACPI_VERSION := 6.1.1
UACPI_URL := https://github.com/uACPI/uACPI/archive/refs/tags/$(UACPI_VERSION).tar.gz
UACPI_SHA256 := 40f2e278b2080e69f4eaa3384404944874d430e50b72c1066cab2ba476e2b769
TARBALL := $(DISTDIR)/uacpi-$(UACPI_VERSION).tar.gz
$(TARBALL): | $(DISTDIR)
curl -fsSL -o $@ $(UACPI_URL)
sh $(SHA256CHECK) "$(UACPI_SHA256)" "$@"
download: $(TARBALL)
$(SRCDIR): $(TARBALL)
mkdir -p $(PORTDIR)
cd $(PORTDIR) && tar xzf $(abspath $<)
mv $(PORTDIR)/uACPI-$(UACPI_VERSION) $@
# The kernel build depends on this directory existing, nothing more.
all: | $(SRCDIR)
install:
clean:
rm -rf $(PORTDIR)
distclean: clean
rm -f $(TARBALL)