-
-
Notifications
You must be signed in to change notification settings - Fork 645
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[metal] Locate some ACPI tables, for later hardware detection
Specifically the code now tries to find the ACPI RSDP, RSDT/XSDT, FADT, & MADT tables, whether in legacy BIOS bootup mode or in a UEFI bootup. These are useful for figuring out how to (re)enable asynchronous interrupts in legacy 8259 PIC mode.
- Loading branch information
tkchia
committed
Oct 25, 2023
1 parent
9f6fdf9
commit 84dfeb5
Showing
16 changed files
with
889 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ | ||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ | ||
╞══════════════════════════════════════════════════════════════════════════════╡ | ||
│ This is free and unencumbered software released into the public domain. │ | ||
│ │ | ||
│ Anyone is free to copy, modify, publish, use, compile, sell, or │ | ||
│ distribute this software, either in source code form or as a compiled │ | ||
│ binary, for any purpose, commercial or non-commercial, and by any │ | ||
│ means. │ | ||
│ │ | ||
│ In jurisdictions that recognize copyright laws, the author or authors │ | ||
│ of this software dedicate any and all copyright interest in the │ | ||
│ software to the public domain. We make this dedication for the benefit │ | ||
│ of the public at large and to the detriment of our heirs and │ | ||
│ successors. We intend this dedication to be an overt act of │ | ||
│ relinquishment in perpetuity of all present and future rights to this │ | ||
│ software under copyright law. │ | ||
│ │ | ||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │ | ||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │ | ||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │ | ||
│ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR │ | ||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │ | ||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │ | ||
│ OTHER DEALINGS IN THE SOFTWARE. │ | ||
╚─────────────────────────────────────────────────────────────────────────────*/ | ||
#include "libc/dce.h" | ||
#include "libc/irq/acpi.internal.h" | ||
#include "libc/macros.internal.h" | ||
#include "libc/runtime/pc.internal.h" | ||
|
||
.init.start 312,_init_acpi_fadt | ||
push %rdi | ||
push %rsi | ||
call _AcpiFadtInit | ||
pop %rsi | ||
pop %rdi | ||
.init.end 312,_init_acpi_fadt | ||
.data | ||
_AcpiBootFlags: | ||
.short kAcpiFadtLegacyDevices | kAcpiFadt8042 | ||
.endobj _AcpiBootFlags,globl | ||
.previous |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ | ||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ | ||
╞══════════════════════════════════════════════════════════════════════════════╡ | ||
│ This is free and unencumbered software released into the public domain. │ | ||
│ │ | ||
│ Anyone is free to copy, modify, publish, use, compile, sell, or │ | ||
│ distribute this software, either in source code form or as a compiled │ | ||
│ binary, for any purpose, commercial or non-commercial, and by any │ | ||
│ means. │ | ||
│ │ | ||
│ In jurisdictions that recognize copyright laws, the author or authors │ | ||
│ of this software dedicate any and all copyright interest in the │ | ||
│ software to the public domain. We make this dedication for the benefit │ | ||
│ of the public at large and to the detriment of our heirs and │ | ||
│ successors. We intend this dedication to be an overt act of │ | ||
│ relinquishment in perpetuity of all present and future rights to this │ | ||
│ software under copyright law. │ | ||
│ │ | ||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │ | ||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │ | ||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │ | ||
│ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR │ | ||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │ | ||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │ | ||
│ OTHER DEALINGS IN THE SOFTWARE. │ | ||
╚─────────────────────────────────────────────────────────────────────────────*/ | ||
#include "libc/dce.h" | ||
#include "libc/intrin/kprintf.h" | ||
#include "libc/irq/acpi.internal.h" | ||
|
||
#ifdef __x86_64__ | ||
|
||
textstartup static void _AcpiDsdtInit(uintptr_t dsdt_phy) { | ||
const AcpiTableDsdt *dsdt; | ||
size_t length; | ||
if (!dsdt_phy) { | ||
KWARNF("FADT: no DSDT"); | ||
return; | ||
} | ||
dsdt = _AcpiMapTable(dsdt_phy); | ||
KINFOF("FADT: DSDT @ %p", dsdt); | ||
length = dsdt->Header.Length; | ||
if (length <= offsetof(AcpiTableDsdt, Aml)) { | ||
KWARNF("DSDT: no AML?"); | ||
return; | ||
} | ||
/* TODO: parse AML to discover hardware configuration */ | ||
} | ||
|
||
textstartup void _AcpiFadtInit(void) { | ||
if (IsMetal()) { | ||
const AcpiTableFadt *fadt; | ||
size_t length; | ||
uint16_t flags; | ||
uintptr_t dsdt_phy = 0; | ||
if (!_AcpiSuccess(_AcpiGetTable("FACP", 0, (void **)&fadt))) { | ||
KINFOF("no FADT found"); | ||
return; | ||
} | ||
length = fadt->Header.Length; | ||
KINFOF("FADT @ %p,+%#zx", fadt, length); | ||
_Static_assert(offsetof(AcpiTableFadt, Dsdt) == 40); | ||
_Static_assert(offsetof(AcpiTableFadt, BootFlags) == 109); | ||
_Static_assert(offsetof(AcpiTableFadt, XDsdt) == 140); | ||
if (length >= offsetof(AcpiTableFadt, BootFlags) + sizeof(fadt->BootFlags)) | ||
{ | ||
_AcpiBootFlags = flags = fadt->BootFlags; | ||
KINFOF("FADT: boot flags %#x", (unsigned)flags); | ||
} | ||
if (length >= offsetof(AcpiTableFadt, XDsdt) + sizeof(fadt->XDsdt) && | ||
fadt->XDsdt) { | ||
dsdt_phy = fadt->XDsdt; | ||
} else if (length >= offsetof(AcpiTableFadt, Dsdt) + sizeof(fadt->Dsdt)) { | ||
dsdt_phy = fadt->Dsdt; | ||
} | ||
_AcpiDsdtInit(dsdt_phy); | ||
} | ||
} | ||
|
||
#endif /* __x86_64__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ | ||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ | ||
╞══════════════════════════════════════════════════════════════════════════════╡ | ||
│ This is free and unencumbered software released into the public domain. │ | ||
│ │ | ||
│ Anyone is free to copy, modify, publish, use, compile, sell, or │ | ||
│ distribute this software, either in source code form or as a compiled │ | ||
│ binary, for any purpose, commercial or non-commercial, and by any │ | ||
│ means. │ | ||
│ │ | ||
│ In jurisdictions that recognize copyright laws, the author or authors │ | ||
│ of this software dedicate any and all copyright interest in the │ | ||
│ software to the public domain. We make this dedication for the benefit │ | ||
│ of the public at large and to the detriment of our heirs and │ | ||
│ successors. We intend this dedication to be an overt act of │ | ||
│ relinquishment in perpetuity of all present and future rights to this │ | ||
│ software under copyright law. │ | ||
│ │ | ||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │ | ||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │ | ||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │ | ||
│ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR │ | ||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │ | ||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │ | ||
│ OTHER DEALINGS IN THE SOFTWARE. │ | ||
╚─────────────────────────────────────────────────────────────────────────────*/ | ||
#include "libc/dce.h" | ||
#include "libc/irq/acpi.internal.h" | ||
#include "libc/macros.internal.h" | ||
#include "libc/runtime/pc.internal.h" | ||
|
||
.init.start 311,_init_acpi_madt | ||
push %rdi | ||
push %rsi | ||
call _AcpiMadtInit | ||
pop %rsi | ||
pop %rdi | ||
.init.end 311,_init_acpi_madt | ||
.data | ||
_AcpiMadtFlags: | ||
.long kAcpiMadtPcAtCompat | ||
.endobj _AcpiMadtFlags,globl | ||
.previous | ||
.bss | ||
_AcpiNumIoApics: | ||
.skip 8 | ||
.endobj _AcpiNumIoApics,globl | ||
_AcpiIoApics: | ||
.skip 8 | ||
.endobj _AcpiIoApics,globl | ||
.previous |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ | ||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ | ||
╞══════════════════════════════════════════════════════════════════════════════╡ | ||
│ This is free and unencumbered software released into the public domain. │ | ||
│ │ | ||
│ Anyone is free to copy, modify, publish, use, compile, sell, or │ | ||
│ distribute this software, either in source code form or as a compiled │ | ||
│ binary, for any purpose, commercial or non-commercial, and by any │ | ||
│ means. │ | ||
│ │ | ||
│ In jurisdictions that recognize copyright laws, the author or authors │ | ||
│ of this software dedicate any and all copyright interest in the │ | ||
│ software to the public domain. We make this dedication for the benefit │ | ||
│ of the public at large and to the detriment of our heirs and │ | ||
│ successors. We intend this dedication to be an overt act of │ | ||
│ relinquishment in perpetuity of all present and future rights to this │ | ||
│ software under copyright law. │ | ||
│ │ | ||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │ | ||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │ | ||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │ | ||
│ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR │ | ||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │ | ||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │ | ||
│ OTHER DEALINGS IN THE SOFTWARE. │ | ||
╚─────────────────────────────────────────────────────────────────────────────*/ | ||
#include "libc/dce.h" | ||
#include "libc/inttypes.h" | ||
#include "libc/irq/acpi.internal.h" | ||
|
||
#ifdef __x86_64__ | ||
|
||
textstartup void _AcpiMadtInit(void) { | ||
if (IsMetal()) { | ||
const AcpiTableMadt *madt; | ||
size_t length, num_io_apics = 0; | ||
const char *madt_end, *p; | ||
const AcpiSubtableHeader *h; | ||
const AcpiMadtIoApic **icp; | ||
uint32_t flags; | ||
if (!_AcpiSuccess(_AcpiGetTable("APIC", 0, (void **)&madt))) { | ||
KINFOF("no MADT found"); | ||
return; | ||
} | ||
length = madt->Header.Length; | ||
if (length < sizeof(*madt)) { | ||
KDIEF("MADT has short length %#zx", length); | ||
} | ||
_AcpiMadtFlags = flags = madt->Flags; | ||
KINFOF("MADT @ %p, flags %#" PRIx32, madt, flags); | ||
madt_end = (char *)madt + length; | ||
p = madt->Subtable; | ||
while (p != madt_end) { | ||
h = (const AcpiSubtableHeader *)p; | ||
switch (h->Type) { | ||
case kAcpiMadtIoApic: | ||
++num_io_apics; | ||
} | ||
p += h->Length; | ||
} | ||
KINFOF("MADT: %zu I/O APIC(s)", num_io_apics); | ||
icp = _AcpiOsAllocate(num_io_apics * sizeof(const AcpiMadtIoApic *)); | ||
if (icp) { | ||
_AcpiIoApics = icp; | ||
p = madt->Subtable; | ||
while (p != madt_end) { | ||
h = (const AcpiSubtableHeader *)p; | ||
switch (h->Type) { | ||
case kAcpiMadtIoApic: | ||
*icp++ = (const AcpiMadtIoApic *)p; | ||
} | ||
p += h->Length; | ||
} | ||
_AcpiNumIoApics = num_io_apics; | ||
} else { | ||
KWARNF("MADT: no memory for I/O APICs"); | ||
} | ||
} | ||
} | ||
|
||
#endif /* __x86_64__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ | ||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ | ||
╞══════════════════════════════════════════════════════════════════════════════╡ | ||
│ This is free and unencumbered software released into the public domain. │ | ||
│ │ | ||
│ Anyone is free to copy, modify, publish, use, compile, sell, or │ | ||
│ distribute this software, either in source code form or as a compiled │ | ||
│ binary, for any purpose, commercial or non-commercial, and by any │ | ||
│ means. │ | ||
│ │ | ||
│ In jurisdictions that recognize copyright laws, the author or authors │ | ||
│ of this software dedicate any and all copyright interest in the │ | ||
│ software to the public domain. We make this dedication for the benefit │ | ||
│ of the public at large and to the detriment of our heirs and │ | ||
│ successors. We intend this dedication to be an overt act of │ | ||
│ relinquishment in perpetuity of all present and future rights to this │ | ||
│ software under copyright law. │ | ||
│ │ | ||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │ | ||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │ | ||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │ | ||
│ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR │ | ||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │ | ||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │ | ||
│ OTHER DEALINGS IN THE SOFTWARE. │ | ||
╚─────────────────────────────────────────────────────────────────────────────*/ | ||
#include "libc/dce.h" | ||
#include "libc/irq/acpi.internal.h" | ||
#include "libc/macros.internal.h" | ||
#include "libc/runtime/pc.internal.h" | ||
|
||
.init.start 310,_init_acpi_xsdt | ||
push %rdi | ||
push %rsi | ||
call _AcpiXsdtInit | ||
pop %rsi | ||
pop %rdi | ||
.init.end 310,_init_acpi_xsdt | ||
.bss | ||
_AcpiXsdtNumEntries: | ||
.skip 8 | ||
.endobj _AcpiXsdtNumEntries,globl | ||
_AcpiXsdtEntries: | ||
.skip 8 | ||
.endobj _AcpiXsdtEntries,globl | ||
.previous |
Oops, something went wrong.