replace nob with ms' build, move disk creation to build.bat, major comment cleanup, remove old and stupid tests, overhaul interrupt management with per-CPU vector allocation, affinity migration and safe teardown, add proper IOAPIC routing and PCI MSI/MSI-X/INTx support, migrate drivers to the new interrupt API, integrate ACPICA with a proper OS services layer, move ACPI firmware events, power button handling and S5 shutdown into acpi.sys, add parallel driver startup and atomic publication, replace PnP arrays with dynamic lists, redesign service startup again to be asynchronous, add delayed startup mode for services, allow omitting keys in services.ini, fix acpi ec deferred work handling, fix kernel threads having garbage exit code.

This commit is contained in:
maksw committed 2026-10-28 15:18:43 +01:00
1 parent d36f19509c
commit 36eef8f58d
696 files changed
+147281 -7530

No files matched your search

+106
View File
@@ -0,0 +1,106 @@
// Firmware root discovery for optional platform drivers.
#include <kernel/ke_firmware.h>
#include <ntlite/ddk/platform.h>
#include <ntlite/memory_map.h>
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <kernel/ke_debug.h>
#include <string.h>
#define KI_RSDP_V1_SIZE 20u
#define KI_RSDP_V2_SIZE 36u
#define KI_RSDP_MAX_SIZE 4096u
static uint64_t gAcpiRsdpPhysical;
static const char* gAcpiRootDiagnostic = "absent";
static uint8_t gAcpiRsdpRevision;
// Firmware roots must remain in reserved memory after ExitBootServices.
static bool KiFirmwareReservedSpan(const MEMORY_MAP* map, uint64_t start, uint32_t length) {
if (!map || map->Magic != MEMORY_MAP_MAGIC ||
map->RegionCount > MEMORY_MAX_REGIONS || !length || start > UINT64_MAX - length)
return false;
uint64_t end = start + length;
for (uint32_t i = 0; i < map->RegionCount; i++) {
const MEMORY_REGION* region = &map->Regions[i];
if (region->Type != MemoryReserved ||
region->Base > UINT64_MAX - region->Length)
continue;
if (start >= region->Base && end <= region->Base + region->Length)
return true;
}
return false;
}
static bool KiFirmwareChecksumValid(const uint8_t* bytes, uint32_t length) {
uint8_t sum = 0;
for (uint32_t i = 0; i < length; i++) sum = (uint8_t)(sum + bytes[i]);
return sum == 0;
}
void KeFirmwareInitialize(const BOOT_INFO* bootInfo) {
gAcpiRsdpPhysical = 0;
gAcpiRsdpRevision = 0;
gAcpiRootDiagnostic = "absent";
if (!bootInfo || !bootInfo->RsdpPhysical) return;
if (!bootInfo->PhysicalMapBase ||
!KiFirmwareReservedSpan(&bootInfo->MemoryMap,
bootInfo->RsdpPhysical, KI_RSDP_V1_SIZE) ||
bootInfo->RsdpPhysical > UINTPTR_MAX - bootInfo->PhysicalMapBase) {
gAcpiRootDiagnostic = "invalid physical range";
return;
}
const uint8_t* rsdp = (const uint8_t*)(bootInfo->PhysicalMapBase + bootInfo->RsdpPhysical);
if (memcmp(rsdp, "RSD PTR ", 8) != 0) {
gAcpiRootDiagnostic = "invalid signature";
return;
}
if (!KiFirmwareChecksumValid(rsdp, KI_RSDP_V1_SIZE)) {
gAcpiRootDiagnostic = "invalid legacy checksum";
return;
}
if (rsdp[15] >= 2u) {
if (!KiFirmwareReservedSpan(&bootInfo->MemoryMap,
bootInfo->RsdpPhysical, KI_RSDP_V2_SIZE)) {
gAcpiRootDiagnostic = "truncated extended root";
return;
}
uint32_t length;
memcpy(&length, rsdp + 20, sizeof(length));
if (length < KI_RSDP_V2_SIZE || length > KI_RSDP_MAX_SIZE ||
!KiFirmwareReservedSpan(&bootInfo->MemoryMap,
bootInfo->RsdpPhysical, length)) {
gAcpiRootDiagnostic = "invalid extended length";
return;
}
if (!KiFirmwareChecksumValid(rsdp, length)) {
gAcpiRootDiagnostic = "invalid extended checksum";
return;
}
}
gAcpiRsdpPhysical = (uint64_t)bootInfo->RsdpPhysical;
gAcpiRsdpRevision = rsdp[15];
gAcpiRootDiagnostic = "valid";
}
// A driver chooses its own ACPI interpreter and maps tables through the DDK.
__declspec(dllexport) KSTATUS KeFirmwareQueryAcpiRsdp(uint64_t* physicalAddressOut) {
if (!physicalAddressOut) return NTLSTATUS_INVALID_PARAMETER;
*physicalAddressOut = 0;
if (!gAcpiRsdpPhysical) return NTLSTATUS_NOT_SUPPORTED;
*physicalAddressOut = gAcpiRsdpPhysical;
return NTLSTATUS_SUCCESS;
}
// Reports the firmware handoff state through the normal kernel diagnostic stream.
void KeFirmwareLog(void) {
DbgPrint("firmware: ACPI RSDP %s phys=0x%016llX revision=%u\n",
gAcpiRootDiagnostic,
(unsigned long long)gAcpiRsdpPhysical,
(unsigned)gAcpiRsdpRevision);
}