revert between 56095 -> 55830 in arch
[AROS.git] / arch / all-pc / kernel / acpi.c
blob639279c0ef3fba97047a49b9735ea83097a3ced4
1 /*
2 Copyright © 2017-2018, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/asmcall.h>
7 #include <proto/exec.h>
8 #include <proto/acpica.h>
9 #define __KERNEL_NOLIBBASE__
10 #include <proto/kernel.h>
12 #include <aros/symbolsets.h>
14 #include <inttypes.h>
15 #include <string.h>
17 #include "kernel_base.h"
18 #include "kernel_debug.h"
19 #include "kernel_intern.h"
20 #include "kernel_syscall.h"
22 #include "acpi.h"
23 #include "apic.h"
24 #include "apic_ia32.h"
25 #include "i8259a.h"
27 #define D(x)
29 /************************************************************************************************/
30 /************************************************************************************************
31 ACPI Functions used by kernel.resource from outside this file ..
32 ************************************************************************************************/
33 /************************************************************************************************/
35 THIS_PROGRAM_HANDLES_SYMBOLSET(KERNEL__ACPISUPPORT)
36 DECLARESET(KERNEL__ACPISUPPORT)
38 int acpi_ScanTableEntries(CONST ACPI_TABLE_HEADER *table, ULONG thl, UINT8 type, const struct Hook *hook, APTR data)
40 UINT8 *table_end = (UINT8 *)table + table->Length;
41 UINT8 *table_entry = (UINT8 *)table + thl;
42 int count;
44 for (count = 0; table_entry < table_end; table_entry += ((ACPI_SUBTABLE_HEADER *)table_entry)->Length) {
45 ACPI_SUBTABLE_HEADER *sh = (ACPI_SUBTABLE_HEADER *)table_entry;
46 if (sh->Type == (UINT8)type) {
47 BOOL res;
48 if (hook == NULL)
49 res = TRUE;
50 else
51 res = CALLHOOKPKT((struct Hook *)hook, (APTR)sh, data);
52 if (res)
53 count++;
57 return count;
60 /* Initialize ACPI */
61 void acpi_Init(struct PlatformData *pdata)
63 acpi_supportinit_t *acpisupportInit;
64 void **supportmoduleinit = (void **)SETNAME(KERNEL__ACPISUPPORT);
65 struct ACPI_TABLE_HOOK *acpiTableHook = NULL;
66 struct ACPI_TABLESCAN_DATA acpiTSData;
67 char *tableLast = NULL;
68 ACPI_STATUS Status;
69 int pos;
71 D(bug("[Kernel:ACPI] %s(0x%p)\n", __func__, pdata));
73 if (!pdata->kb_ACPI)
75 if ((pdata->kb_ACPI = (struct ACPIData *)AllocMem(sizeof(struct ACPIData), MEMF_CLEAR)) != NULL)
77 D(icintrid_t xtpicICInstID;)
79 NEWLIST(&pdata->kb_ACPI->acpi_tablehooks);
81 D(bug("[Kernel:ACPI] %s: Preparing ACPI support modules...\n", __func__));
82 for (pos = 1; supportmoduleinit[pos] != NULL; pos++)
84 acpisupportInit = (acpi_supportinit_t *)supportmoduleinit[pos];
85 D(bug("[Kernel:ACPI] %s: acpisupportInit @ 0x%p \n", __func__, acpisupportInit));
86 acpisupportInit(pdata);
87 D(bug("[Kernel:ACPI] %s: returned!\n", __func__));
90 while (NULL != FindTask("ACPICA_InitTask"))
92 D(bug("[Kernel:ACPI] %s: Waiting for ACPI to finish Initializing...\n", __func__));
94 * N.B: We do not have a scheduling heartbeat at this
95 * point, so we must co-operatively yield CPU time to
96 * let the ACPICA Init task run.
98 KrnSchedule();
101 if (!IsListEmpty(&pdata->kb_ACPI->acpi_tablehooks))
103 D(bug("[Kernel:ACPI] %s: Processing Table Handler Hooks...\n", __func__));
104 ForeachNode(&pdata->kb_ACPI->acpi_tablehooks, acpiTableHook)
106 if (acpiTableHook->acpith_Node.ln_Name)
108 D(bug("[Kernel:ACPI] %s: Table Hooks @ 0x%p for '%s'\n", __func__, acpiTableHook, acpiTableHook->acpith_Node.ln_Name));
109 if ((!tableLast) || (tableLast != acpiTableHook->acpith_Node.ln_Name))
111 D(bug("[Kernel:ACPI] %s: Trying to obtain Table...\n", __func__));
112 acpiTSData.acpits_Table = NULL;
113 if (AE_OK == (Status = AcpiGetTable(acpiTableHook->acpith_Node.ln_Name, 1, (ACPI_TABLE_HEADER **)&acpiTSData.acpits_Table)))
115 tableLast = acpiTableHook->acpith_Node.ln_Name;
117 else
119 D(bug("[Kernel:ACPI] %s: Failed! status %08x\n", __func__, Status));
120 tableLast = NULL;
124 D(bug("[Kernel:ACPI] %s: Table @ 0x%p\n", __func__, acpiTSData.acpits_Table));
125 if (acpiTSData.acpits_Table)
127 acpiTSData.acpits_UserData = acpiTableHook->acpith_UserData;
128 if (acpiTableHook->acpith_HeaderLen)
129 acpi_ScanTableEntries(acpiTSData.acpits_Table, acpiTableHook->acpith_HeaderLen, acpiTableHook->acpith_EntryType, &acpiTableHook->acpith_Hook, &acpiTSData);
130 else
132 CALLHOOKPKT((struct Hook *)&acpiTableHook->acpith_Hook, (APTR)acpiTSData.acpits_Table, &acpiTSData);
136 else
138 bug("[Kernel:ACPI] BUG: missing Table name @ 0x%p", acpiTableHook);
141 bug("[Kernel:ACPI] System Total APICs: %d", pdata->kb_ACPI->acpi_apicCnt);
142 if (pdata->kb_APIC)
144 bug(", %d usable", pdata->kb_APIC->apic_count);
146 bug("\n");
149 /* Initialize legacy 8259A PIC if present. */
150 if ((pdata->kb_APIC) && (pdata->kb_APIC->flags & APF_8259))
152 D(xtpicICInstID =) krnAddInterruptController(KernelBase, &i8259a_IntrController);
153 D(bug("[Kernel:ACPI] %s: Registered i8259A IC ID #%d:%d\n", __func__, ICINTR_ICID(xtpicICInstID), ICINTR_INST(xtpicICInstID)));