summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Zammit <damien@zamaudio.com>2020-04-26 13:32:10 +1000
committerDamien Zammit <damien@zamaudio.com>2020-04-26 13:32:10 +1000
commit367315daa533976f87e30106def84b12913a6803 (patch)
treed18c1e39079b5685e6c6ce506f168a4b93dde66c
parentaad7f5cadf8f036c31bb6bd3f4f20bd5706c63cd (diff)
acpica: Remove most dependencies on linux/ glue
-rw-r--r--acpica/acpi_init.c130
-rw-r--r--acpica/src/include/acpi/platform/acgnu.h15
-rw-r--r--acpica/src/include/acpi/platform/acgnuex.h4
3 files changed, 118 insertions, 31 deletions
diff --git a/acpica/acpi_init.c b/acpica/acpi_init.c
index 4999bbf3..3a34a565 100644
--- a/acpica/acpi_init.c
+++ b/acpica/acpi_init.c
@@ -1,18 +1,38 @@
#include "acpi_init.h"
-#include <kern/timer.h> // clock
-#include <kern/printf.h> // *printf
+#include <kern/timer.h> // timer
+#include <kern/printf.h> // vsnprintf
+#include <kern/assert.h>
#include <vm/vm_kern.h> // kmem_alloc_wired
-#include <mach/vm_param.h> // kmem_cache
+#include <vm/pmap.h> // hack
#include <i386/pio.h>
+#include <stddef.h>
#define MACH_INCLUDE
#include <linux/delay.h> // udelay
-#include <linux/kernel.h> // printk && vremap/vfree
#define ACPI_MAX_TABLES 128
// Lets keep the ACPI tables in this module
static struct acpi_table_desc initial_tables[ACPI_MAX_TABLES];
+
+void *
+pmap_hack (unsigned long offset, unsigned long size)
+{
+ vm_offset_t addr;
+ kern_return_t ret;
+
+ ret = kmem_alloc_wired (kernel_map, &addr, round_page (size));
+ if (ret != KERN_SUCCESS)
+ return NULL;
+
+ (void) pmap_map_bd (addr, offset, offset + round_page (size),
+ VM_PROT_READ | VM_PROT_WRITE);
+
+ /* XXX remember mapping somewhere so we can free it? */
+
+ return (void *) addr;
+}
+
int
islower (char c)
{
@@ -67,6 +87,50 @@ isprint(char c)
return ((c <= 126) && (c >= 32));
}
+
+
+inline char *
+strncat(char * dest,const char * src,size_t count)
+{
+int d0, d1, d2, d3;
+__asm__ __volatile__(
+ "cld\n\t"
+ "repne\n\t"
+ "scasb\n\t"
+ "decl %1\n\t"
+ "movl %8,%3\n"
+ "1:\tdecl %3\n\t"
+ "js 2f\n\t"
+ "lodsb\n\t"
+ "stosb\n\t"
+ "testb %%al,%%al\n\t"
+ "jne 1b\n"
+ "2:\txorl %2,%2\n\t"
+ "stosb"
+ : "=&S" (d0), "=&D" (d1), "=&a" (d2), "=&c" (d3)
+ : "0" (src),"1" (dest),"2" (0),"3" (0xffffffff), "g" (count)
+ : "memory");
+return dest;
+}
+
+inline char *
+strcat(char * dest,const char * src)
+{
+int d0, d1, d2, d3;
+__asm__ __volatile__(
+ "cld\n\t"
+ "repne\n\t"
+ "scasb\n\t"
+ "decl %1\n"
+ "1:\tlodsb\n\t"
+ "stosb\n\t"
+ "testb %%al,%%al\n\t"
+ "jne 1b"
+ : "=&S" (d0), "=&D" (d1), "=&a" (d2), "=&c" (d3)
+ : "0" (src), "1" (dest), "2" (0), "3" (0xffffffff):"memory");
+return dest;
+}
+
void
acpi_ds_dump_method_stack(acpi_status status, ...)
// struct acpi_walk_state *walk_state,
@@ -80,12 +144,14 @@ acpi_os_create_cache(char *cache_name,
u16 object_size,
u16 max_depth, acpi_cache_t **return_cache)
{
+ kmem_cache_init (*return_cache, cache_name, object_size, 0, NULL, 0);
return (AE_OK);
}
acpi_status
acpi_os_delete_cache(acpi_cache_t *cache)
{
+ slab_collect ();
return (AE_OK);
}
@@ -98,6 +164,7 @@ acpi_os_purge_cache(acpi_cache_t *cache)
acpi_status
acpi_os_release_object(acpi_cache_t *cache, void *object)
{
+ kmem_cache_free (cache, (vm_offset_t)object);
return (AE_OK);
}
@@ -116,7 +183,7 @@ acpi_os_vprintf(const char *fmt, va_list args)
static char buffer[512];
vsnprintf(buffer, 512, fmt, args);
- printk(buffer);
+ printf(buffer);
}
acpi_cpu_flags
@@ -138,16 +205,42 @@ acpi_os_delete_lock(acpi_spinlock handle)
ACPI_FREE(handle);
}
+/* FIXME: Need proper semaphores */
acpi_status
acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_semaphore * handle)
{
- acpi_os_printf("cant create semaphore\n");
- return AE_NO_MEMORY;
+ acpi_spinlock *lockp = (acpi_spinlock *)handle;
+
+ assert (max_units <= 1);
+ assert (initial_units <= 1);
+
+ acpi_os_create_lock (lockp);
+
+ if (initial_units == 1)
+ acpi_os_acquire_lock (*lockp);
+
+ return AE_OK;
}
acpi_status
acpi_os_delete_semaphore(acpi_semaphore handle)
{
+ acpi_os_delete_lock ((acpi_spinlock)handle);
+ return AE_OK;
+}
+
+acpi_status
+acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
+{
+ return AE_OK;
+}
+
+acpi_status
+acpi_os_signal_semaphore(acpi_handle handle, u32 units)
+{
+ assert (units <= 1);
+ if (units == 1)
+ acpi_os_release_lock ((acpi_spinlock)handle, 0);
return AE_OK;
}
@@ -184,9 +277,9 @@ acpi_os_get_timer(void)
void *
acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
{
- ptrdiff_t into_page = phys % PAGE_SIZE;
+ uintptr_t into_page = phys % PAGE_SIZE;
uintptr_t nearest_page = (uintptr_t)trunc_page(phys);
- void *ret = vremap (nearest_page, size + into_page);
+ void *ret = pmap_hack (nearest_page, size + into_page);
if (!ret) {
acpi_os_printf("Can't map memory 0x%llx\n", phys);
}
@@ -272,7 +365,7 @@ acpi_os_unmap_memory(void *virt, acpi_size size)
//FIXME crashes: vfree (freeme);
}
-static int
+static acpi_status
acpi_os_read_iomem(void *virt_addr, u64 *value, u32 width)
{
@@ -290,9 +383,9 @@ acpi_os_read_iomem(void *virt_addr, u64 *value, u32 width)
*(u64 *) value = *((volatile u64 *)virt_addr);
break;
default:
- return EINVAL;
+ return AE_ERROR;
}
- return 0;
+ return AE_OK;
}
acpi_status
@@ -318,19 +411,6 @@ acpi_os_read_memory(acpi_physical_address phys_addr, u64 *value, u32 width)
return err;
}
-acpi_status
-acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
-{
- return AE_OK;
-}
-
-acpi_status
-acpi_os_signal_semaphore(acpi_handle handle, u32 units)
-{
- return AE_OK;
-}
-
-
void
acpi_os_sleep(u64 ms)
{
diff --git a/acpica/src/include/acpi/platform/acgnu.h b/acpica/src/include/acpi/platform/acgnu.h
index 5cd65d0d..55186762 100644
--- a/acpica/src/include/acpi/platform/acgnu.h
+++ b/acpica/src/include/acpi/platform/acgnu.h
@@ -24,11 +24,18 @@
#define ACPI_MUTEX_DEBUG
#endif
-#include <kern/lock.h> // simple_lock
+#include <kern/lock.h>
#include <kern/ipc_kobject.h>
-
-#define MACH_INCLUDE
-#include <linux/malloc.h> // kmalloc kfree
+#include <kern/kalloc.h>
+#include <string.h>
+typedef uint8_t u8;
+typedef uint16_t u16;
+typedef uint32_t u32;
+typedef uint64_t u64;
+typedef int8_t s8;
+typedef int16_t s16;
+typedef int32_t s32;
+typedef int64_t s64;
#define ACPI_INIT_FUNCTION
diff --git a/acpica/src/include/acpi/platform/acgnuex.h b/acpica/src/include/acpi/platform/acgnuex.h
index 1e3429dd..aa2ee88d 100644
--- a/acpica/src/include/acpi/platform/acgnuex.h
+++ b/acpica/src/include/acpi/platform/acgnuex.h
@@ -12,7 +12,7 @@ acpi_status acpi_os_terminate(void);
static inline void *acpi_os_allocate(acpi_size size)
{
- return linux_kmalloc(size, GFP_ATOMIC);
+ return (void *)kalloc (size);
}
static inline void *acpi_os_allocate_zeroed(acpi_size size)
@@ -24,7 +24,7 @@ static inline void *acpi_os_allocate_zeroed(acpi_size size)
static inline void acpi_os_free(void *memory)
{
- linux_kfree(memory);
+ //kfree (memory, /* howbig? */);
}
static inline void *acpi_os_acquire_object(acpi_cache_t * cache)