2 Copyright © 2017-2018, The AROS Development Team. All rights reserved.
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>
17 #include "kernel_base.h"
18 #include "kernel_debug.h"
19 #include "kernel_intern.h"
20 #include "kernel_syscall.h"
24 #include "apic_ia32.h"
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
;
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
) {
51 res
= CALLHOOKPKT((struct Hook
*)hook
, (APTR
)sh
, data
);
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
;
71 D(bug("[Kernel:ACPI] %s(0x%p)\n", __func__
, pdata
));
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.
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
;
119 D(bug("[Kernel:ACPI] %s: Failed! status %08x\n", __func__
, Status
));
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
);
132 CALLHOOKPKT((struct Hook
*)&acpiTableHook
->acpith_Hook
, (APTR
)acpiTSData
.acpits_Table
, &acpiTSData
);
138 bug("[Kernel:ACPI] BUG: missing Table name @ 0x%p", acpiTableHook
);
141 bug("[Kernel:ACPI] System Total APICs: %d", pdata
->kb_ACPI
->acpi_apicCnt
);
144 bug(", %d usable", pdata
->kb_APIC
->apic_count
);
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
)));