Browse Source

ACPI: single thread OS Locks/Semaphores; disable OsOverride*.

This is how Minix and in some cases netBSD implement these ops.

If there's only one thread then locks/semaphores
are a no nop. We can go crazy later with multithreading
if we think that's a good idea.

And the OS does not override anything, so
set the return pointer to nil or 0.

With this change, you can now add -a to your flags and
your kernel will boot with the ACPI init stuff enabled.

No more panics. It's a start.

Here's the pxelinux.cfg for booting with ACPI:

label harvey.32bit
	kernel mboot.c32
	append harvey.32bit fs=192.168.28.128 auth=127.0.0.1 nobootprompt=tcp nvram=/boot/nvram nvrlen=512 nvroff=0   -a

default harvey.32bit

Note the -a.

Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
Ronald G. Minnich 7 years ago
parent
commit
594164b2f2

+ 2 - 6
sys/include/acpi/acpica/platform/acharvey.h

@@ -49,7 +49,9 @@
 #undef ACPI_USE_STANDARD_HEADERS
 
 #ifdef __KERNEL__
+/* TODO: multithreaded ACPI. But single thread is fine for now. */
 #else
+#endif				/* __KERNEL__ */
 
 #define ACPI_FLUSH_CPU_CACHE()
 #define ACPI_CAST_PTHREAD_T(pthread) ((acpi_thread_id) (pthread))
@@ -70,11 +72,5 @@
 #define __cdecl
 #endif
 
-#endif				/* __KERNEL__ */
-
-/* ACPI uses #defines instead of typedefs. We use a typedef to avoid any weirdness with
- * cpp expansion. */
-typedef Lock* Lock_t;
-#define ACPI_SPINLOCK Lock_t
 
 #endif				/* __ACHARVEY_H__ */

+ 8 - 16
sys/src/9/amd64/devacpi.c

@@ -497,13 +497,15 @@ AcpiOsGetPhysicalAddress (
 	return AE_OK;
 }
 
+/* This is the single threaded version of
+ * these functions. This is now NetBSD does it. */
 ACPI_STATUS
 AcpiOsCreateSemaphore (
     UINT32                  MaxUnits,
     UINT32                  InitialUnits,
     ACPI_SEMAPHORE          *OutHandle)
 {
-	panic("%s", __func__);
+	*OutHandle = (ACPI_SEMAPHORE) 1;
 	return AE_OK;
 }
 
@@ -511,7 +513,6 @@ ACPI_STATUS
 AcpiOsDeleteSemaphore (
     ACPI_SEMAPHORE          Handle)
 {
-	panic("%s", __func__);
 	return AE_OK;
 }
 
@@ -521,7 +522,6 @@ AcpiOsWaitSemaphore (
     UINT32                  Units,
     UINT16                  Timeout)
 {
-	panic("%s", __func__);
 	return AE_OK;
 }
 
@@ -530,18 +530,15 @@ AcpiOsSignalSemaphore (
     ACPI_SEMAPHORE          Handle,
     UINT32                  Units)
 {
-	panic("%s", __func__);
 	return AE_OK;
 }
 
+/* this is the single threaded case and as minix shows there is nothing to do. */
 ACPI_STATUS
 AcpiOsCreateLock (
     ACPI_SPINLOCK           *OutHandle)
 {
-	ACPI_SPINLOCK l = mallocz(sizeof(ACPI_SPINLOCK), 1);
-	if (l == nil)
-		return AE_NO_MEMORY;
-	*OutHandle = l;
+	*OutHandle = nil;
 	return AE_OK;
 }
 
@@ -549,15 +546,12 @@ void
 AcpiOsDeleteLock (
     ACPI_SPINLOCK           Handle)
 {
-	free(Handle);
 }
 
 ACPI_CPU_FLAGS
 AcpiOsAcquireLock (
     ACPI_SPINLOCK           Handle)
 {
-	panic("figure out flags");
-	ilock(Handle);
 	return 0;
 }
 
@@ -566,8 +560,6 @@ AcpiOsReleaseLock (
     ACPI_SPINLOCK           Handle,
     ACPI_CPU_FLAGS          Flags)
 {
-	panic("figure out flags");
-	iunlock(Handle);
 }
 
 ACPI_STATUS
@@ -687,7 +679,7 @@ AcpiOsPredefinedOverride (
     const ACPI_PREDEFINED_NAMES *InitVal,
     ACPI_STRING                 *NewVal)
 {
-	panic("%s", __func__);
+	*NewVal = nil;
 	return AE_OK;
 }
 
@@ -696,7 +688,7 @@ AcpiOsTableOverride (
     ACPI_TABLE_HEADER       *ExistingTable,
     ACPI_TABLE_HEADER       **NewTable)
 {
-	panic("%s", __func__);
+	*NewTable = nil;
 	return AE_OK;
 }
 
@@ -706,7 +698,7 @@ AcpiOsPhysicalTableOverride (
     ACPI_PHYSICAL_ADDRESS   *NewAddress,
     UINT32                  *NewTableLength)
 {
-	panic("%s", __func__);
+	*NewAddress = (ACPI_PHYSICAL_ADDRESS)nil;
 	return AE_OK;
 }
 

+ 2 - 0
sys/src/libacpi/acpica/kacpiflags.json

@@ -4,11 +4,13 @@
 		        "-DACPI_DEBUGGER",
 		        "-DACPI_DEBUG_OUTPUT",
 		        "-D__HARVEY__",
+		        "-D__KERNEL__",
 		        "-U_LINUX",
 		        "-U__linux__",
 			"-Wno-unused-function",
 			"-Wno-unused-variable",
 			"-I", "/sys/include/acpi/acpica",
+			"-I", "/sys/src/9",
 			"-mcmodel=kernel",
 			"-O0",
 			"-mno-red-zone",

+ 1 - 1
sys/src/libacpi/acpica/klibacpi.json

@@ -1,5 +1,5 @@
 {
-	"Libacpi": {
+	"Klibacpi": {
 		"Projects": [
 			"components/kbuild.json"
 		],