summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-09-15 12:04:08 -0400
committerIan Moffett <ian@osmora.org>2025-09-15 12:04:08 -0400
commitfa8bf187448d93e5c4c0ddeaf6c7fbb384d1b946 (patch)
treef3fce2ad413cb5763f01b6d53e1f49d8f307238c
parentf7b9f5b81c0eab172f2090daedc5f212c84d247a (diff)
kernel/amd64: Move ioapic_read_madt() to acpi_subr
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--src/sys/acpi/acpi_subr.c40
-rw-r--r--src/sys/arch/amd64/mainbus/ioapic.c48
-rw-r--r--src/sys/include/acpi/acpi.h16
3 files changed, 58 insertions, 46 deletions
diff --git a/src/sys/acpi/acpi_subr.c b/src/sys/acpi/acpi_subr.c
index eab1f4f..d953fd5 100644
--- a/src/sys/acpi/acpi_subr.c
+++ b/src/sys/acpi/acpi_subr.c
@@ -27,6 +27,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include <sys/panic.h>
#include <acpi/acpi.h>
#include <vm/vm.h>
#include <string.h>
@@ -64,3 +65,42 @@ acpi_query(const char *query)
return NULL;
}
+
+/*
+ * Read a MADT entry
+ */
+int
+acpi_read_madt(uint32_t type, int(*cb)(struct apic_header *, size_t arg),
+ size_t arg)
+{
+ static struct acpi_madt *madt = NULL;
+ uint8_t *cur, *end;
+ int retval = -1;
+ struct apic_header *apichdr;
+
+ /* Try to read the MADT table */
+ if (madt == NULL) {
+ madt = acpi_query("APIC");
+ }
+ if (madt == NULL) {
+ panic("ioapic_read_madt: failed to get MADT\n");
+ }
+
+ cur = (uint8_t *)(madt + 1);
+ end = (uint8_t *)madt + madt->hdr.length;
+ while (cur < end) {
+ apichdr = (void *)cur;
+ if (apichdr->type == type) {
+ retval = cb(apichdr, arg);
+ }
+
+ /* If the entry was found, stop */
+ if (retval >= 0) {
+ return retval;
+ }
+
+ cur += apichdr->length;
+ }
+
+ return -1;
+}
diff --git a/src/sys/arch/amd64/mainbus/ioapic.c b/src/sys/arch/amd64/mainbus/ioapic.c
index 95ef55a..acb7a0c 100644
--- a/src/sys/arch/amd64/mainbus/ioapic.c
+++ b/src/sys/arch/amd64/mainbus/ioapic.c
@@ -37,7 +37,6 @@
#include <machine/ioapicvar.h>
static struct ioapic *ioapic = NULL;
-static struct acpi_madt *madt = NULL;
static struct apic_header *override = NULL;
/*
@@ -126,49 +125,6 @@ ioapic_write_redentry(const union ioapic_redentry *entry, uint8_t index)
}
/*
- * Read a MADT entry
- *
- * @type: Type that we should scan for
- * @cb: Callback (returns 0 if entry is found)
- * @arg: Optional argument
- *
- * Returns the callback return value, on success,
- * otherwise a less than zero value on failure.
- */
-static int
-ioapic_read_madt(uint32_t type, int(*cb)(struct apic_header *, size_t arg),
- size_t arg)
-{
- uint8_t *cur, *end;
- int retval = -1;
- struct apic_header *apichdr;
-
- /* Try to read the MADT table */
- madt = acpi_query("APIC");
- if (madt == NULL) {
- panic("ioapic_read_madt: failed to get MADT\n");
- }
-
- cur = (uint8_t *)(madt + 1);
- end = (uint8_t *)madt + madt->hdr.length;
- while (cur < end) {
- apichdr = (void *)cur;
- if (apichdr->type == type) {
- retval = cb(apichdr, arg);
- }
-
- /* If the entry was found, stop */
- if (retval >= 0) {
- return retval;
- }
-
- cur += apichdr->length;
- }
-
- return -1;
-}
-
-/*
* Set the I/O APIC MMIO base address
*/
static int
@@ -220,7 +176,7 @@ ioapic_route_vec(uint8_t irq, uint8_t vector)
union ioapic_redentry redent;
int gsi;
- gsi = ioapic_read_madt(
+ gsi = acpi_read_madt(
APIC_TYPE_INTERRUPT_OVERRIDE,
__irq_to_gsi,
irq
@@ -242,7 +198,7 @@ ioapic_init(void)
uint8_t ver, nredir;
if (ioapic == NULL) {
- ioapic_read_madt(
+ acpi_read_madt(
APIC_TYPE_IO_APIC,
__ioapic_callback,
0
diff --git a/src/sys/include/acpi/acpi.h b/src/sys/include/acpi/acpi.h
index ebc2129..16c1653 100644
--- a/src/sys/include/acpi/acpi.h
+++ b/src/sys/include/acpi/acpi.h
@@ -74,4 +74,20 @@ void *acpi_query(const char *query);
*/
int acpi_early_init(void);
+
+/*
+ * Read a MADT entry
+ *
+ * @type: Type that we should scan for
+ * @cb: Callback (returns 0 if entry is found)
+ * @arg: Optional argument
+ *
+ * Returns the callback return value, on success,
+ * otherwise a less than zero value on failure.
+ */
+int acpi_read_madt(
+ uint32_t type, int(*cb)(struct apic_header *, size_t arg),
+ size_t arg
+);
+
#endif /* !_MACHINE_ACPI_H_ */