revert between 56095 -> 55830 in arch
[AROS.git] / arch / all-pc / kernel / platform_post.c
blobe53b305f25844f58213921e73fd66d5d8e0499f5
1 /*
2 Copyright © 2017-2018, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define __KERNEL_NOLIBBASE__
8 #include <proto/exec.h>
9 #include <proto/acpica.h>
10 #include <proto/kernel.h>
12 #include <aros/multiboot.h>
13 #include <aros/symbolsets.h>
14 #include <asm/cpu.h>
15 #include <asm/io.h>
16 #include <exec/lists.h>
17 #include <exec/resident.h>
19 #include <inttypes.h>
21 #include "kernel_base.h"
22 #include "kernel_debug.h"
23 #include "kernel_intern.h"
24 #include "kernel_ipi.h"
25 #include "acpi.h"
26 #include "apic.h"
27 #include "smp.h"
29 #define D(x)
31 /*
32 * This file contains code that is run once Exec has been brought up - and is launched
33 * via the RomTag/Autoinit routines in Exec.
35 * PlatformPostInit is run during RTF_SINGLETASK.
38 void PlatformPostInit(void)
40 D(bug("[Kernel] %s()\n", __func__));
44 Here we do the Platform configuration that requires a working "AROS" environment.
47 APTR PlatformAllocGDT(struct KernelBase *LIBBASE, apicid_t _APICID)
49 APTR GDTalloc;
51 GDTalloc = (APTR)AllocMem(GDT_SIZE + 128, MEMF_24BITDMA|MEMF_CLEAR);
52 GDTalloc = (APTR)AROS_ROUNDUP2((unsigned long)GDTalloc, 128);
53 D(bug("[Kernel] %s[%d]: GDT @ 0x%p\n", __func__, _APICID, GDTalloc));
55 return GDTalloc;
58 APTR PlatformAllocTLS(struct KernelBase *LIBBASE, apicid_t _APICID)
60 APTR TLSalloc = NULL;
62 TLSalloc = (APTR)AllocMem(TLS_SIZE + TLS_ALIGN, MEMF_24BITDMA|MEMF_CLEAR);
63 TLSalloc = (APTR)AROS_ROUNDUP2((unsigned long)TLSalloc, TLS_ALIGN);
65 D(bug("[Kernel] %s[%d]: TLS @ 0x%p\n", __func__, _APICID, TLSalloc));
67 return TLSalloc;
70 APTR PlatformAllocIDT(struct KernelBase *LIBBASE, apicid_t _APICID)
72 APTR IDTalloc;
74 IDTalloc = (APTR)AllocMem(IDT_SIZE + 256, MEMF_24BITDMA|MEMF_CLEAR);
75 IDTalloc = (APTR)AROS_ROUNDUP2((unsigned long)IDTalloc, 256);
77 D(bug("[Kernel] %s[%d]: Allocated IDT at 0x%p\n", __func__, _APICID, IDTalloc));
79 return IDTalloc;
83 * kernel.post is run during RTF_COLDSTART
84 * directly after exec.library.
86 * At this point exec is fully configured, and
87 * multitasking is enabled. It also means
88 * acpica's "full initialization" task will have
89 * been run.
92 extern void kernelpost_end(void);
94 static AROS_UFP3 (APTR, KernelPost,
95 AROS_UFPA(struct Library *, lh, D0),
96 AROS_UFPA(BPTR, segList, A0),
97 AROS_UFPA(struct ExecBase *, sysBase, A6));
99 static const TEXT kernelpost_namestring[] = "kernel.post";
100 static const TEXT kernelpost_versionstring[] = "kernel.post 1.1\n";
102 const struct Resident kernelpost_romtag =
104 RTC_MATCHWORD,
105 (struct Resident *)&kernelpost_romtag,
106 (APTR)&kernelpost_end,
107 RTF_COLDSTART,
109 NT_UNKNOWN,
110 115,
111 (STRPTR)kernelpost_namestring,
112 (STRPTR)kernelpost_versionstring,
113 (APTR)KernelPost
116 extern struct syscallx86_Handler x86_SCRebootHandler;
117 extern struct syscallx86_Handler x86_SCChangePMStateHandler;
119 #if 0
120 struct Hook test_ipi;
122 AROS_UFH3(void, test_ipi_hook,
123 AROS_UFHA(struct Hook *, hook, A0),
124 AROS_UFHA(APTR, object, A2),
125 AROS_UFHA(APTR, message, A1))
127 AROS_USERFUNC_INIT
129 int cpunum = KrnGetCPUNumber();
131 bug("%s: called on CPU %d, hook=%p, object=%p, message=%p\n", __func__, cpunum, hook, object, message);
133 AROS_USERFUNC_EXIT
135 #endif
137 static AROS_UFH3 (APTR, KernelPost,
138 AROS_UFHA(struct Library *, lh, D0),
139 AROS_UFHA(BPTR, segList, A0),
140 AROS_UFHA(struct ExecBase *, SysBase, A6)
143 AROS_USERFUNC_INIT
145 struct KernelBase *KernelBase;
146 struct PlatformData *pdata;
148 KernelBase = (struct KernelBase *)OpenResource("kernel.resource");
149 if (!KernelBase)
150 return NULL;
152 pdata = KernelBase->kb_PlatformData;
154 D(bug("[Kernel] %s: Checking for ACPI...\n", __func__));
156 ACPICABase = OpenLibrary("acpica.library", 0);
157 /* Probe for ACPI configuration */
158 if (ACPICABase)
159 acpi_Init(pdata);
161 D(bug("[Kernel] %s: Performing late system configuration...\n", __func__));
163 Disable();
165 // Add the default reboot/shutdown handlers if ACPI ones haven't been registered
166 krnAddSysCallHandler(pdata, &x86_SCRebootHandler, TRUE, FALSE);
167 krnAddSysCallHandler(pdata, &x86_SCChangePMStateHandler, TRUE, FALSE);
169 D(bug("[Kernel] %s: Attempting to bring up additional cores...\n", __func__));
170 smp_Initialize();
172 D(bug("[Kernel] %s: Initializing interrupt controllers...\n", __func__));
173 ictl_Initialize(KernelBase);
175 Enable();
177 D(bug("[Kernel] %s: Platform Initialization complete\n", __func__));
179 #if 0
180 bug("--- TESTING IPI CALL HOOK ---\n");
181 test_ipi.h_Entry = test_ipi_hook;
182 test_ipi.h_Data = KernelBase;
183 bug("--- SYNCHRONOUS IPI ---\n");
184 core_DoCallIPI(&test_ipi, (void*)TASKAFFINITY_ALL_BUT_SELF, 0, KernelBase);
185 bug("--- ASYNC IPI ---\n");
186 core_DoCallIPI(&test_ipi, (void*)TASKAFFINITY_ALL_BUT_SELF, 1, KernelBase);
187 #endif
189 AROS_USERFUNC_EXIT
191 return NULL;
194 void kernelpost_end(void) { };