summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Zammit <damien@zamaudio.com>2020-04-24 22:05:26 +1000
committerDamien Zammit <damien@zamaudio.com>2020-04-24 22:17:44 +1000
commit65cd6b1796aa5bd62d04a23962b98c31c031e8d5 (patch)
tree085033f45d48dfb9fa102f18ebf3a5e349cd22a1
parent769b59414fdeb96608a87c32c6d1e67a2ec6c909 (diff)
acpica: Populate most of os layer stubs
-rw-r--r--acpica/Makefrag.am1
-rw-r--r--acpica/acpi_init.c412
2 files changed, 413 insertions, 0 deletions
diff --git a/acpica/Makefrag.am b/acpica/Makefrag.am
index 8b5e3c06..3b5a2426 100644
--- a/acpica/Makefrag.am
+++ b/acpica/Makefrag.am
@@ -95,6 +95,7 @@ libacpica_a_SOURCES = \
acpica/src/acpi/exresnte.c \
acpica/src/acpi/exresolv.c \
acpica/src/acpi/exresop.c \
+ acpica/src/acpi/exserial.c \
acpica/src/acpi/exstore.c \
acpica/src/acpi/exstoren.c \
acpica/src/acpi/exstorob.c \
diff --git a/acpica/acpi_init.c b/acpica/acpi_init.c
index 3899983d..5081b910 100644
--- a/acpica/acpi_init.c
+++ b/acpica/acpi_init.c
@@ -1,9 +1,421 @@
#include "acpi_init.h"
+#include <kern/timer.h> // clock
+#include <kern/printf.h> // *printf
+#include <vm/pmap.h> // vremap hack
+#include <vm/vm_kern.h> // kmem_alloc_wired
+#include <mach/vm_param.h> // kmem_cache
+#include <i386/pio.h>
+#define MACH_INCLUDE
+#include <linux/delay.h> // udelay
#define ACPI_MAX_TABLES 128
+// Lets keep the ACPI tables in this module
static struct acpi_table_desc initial_tables[ACPI_MAX_TABLES];
+static 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);
+
+ return (void *) addr;
+}
+
+void
+acpi_ds_dump_method_stack(acpi_status status, ...)
+// struct acpi_walk_state *walk_state,
+// union acpi_parse_object *op)
+{
+ return;
+}
+
+acpi_status
+acpi_os_create_cache(char *cache_name,
+ u16 object_size,
+ u16 max_depth, acpi_cache_t **return_cache)
+{
+ return (AE_OK);
+}
+
+acpi_status
+acpi_os_delete_cache(acpi_cache_t *cache)
+{
+ return (AE_OK);
+}
+
+acpi_status
+acpi_os_release_object(acpi_cache_t *cache, void *object)
+{
+ return (AE_OK);
+}
+
+void
+acpi_os_printf(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ acpi_os_vprintf(fmt, args);
+ va_end(args);
+}
+
+void
+acpi_os_vprintf(const char *fmt, va_list args)
+{
+ static char buffer[512];
+
+ vsnprintf(buffer, 512, fmt, args);
+ printf(buffer);
+}
+
+acpi_cpu_flags
+acpi_os_acquire_lock(acpi_spinlock lockp)
+{
+ simple_lock(lockp);
+ return 0;
+}
+
+void
+acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
+{
+ simple_unlock(lockp);
+}
+
+void
+acpi_os_delete_lock(acpi_spinlock handle)
+{
+ ACPI_FREE(handle);
+}
+
+acpi_status
+acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_semaphore * handle)
+{
+ printf("cant create semaphore\n");
+ return AE_NO_MEMORY;
+}
+
+acpi_status
+acpi_os_delete_semaphore(acpi_semaphore handle)
+{
+ return AE_OK;
+}
+
+acpi_status
+acpi_os_execute(acpi_execute_type type,
+ acpi_osd_exec_callback function, void *context)
+{
+ printf("XXX acpi_os_execute: not implemented\n");
+ return (AE_OK);
+}
+
+acpi_physical_address
+acpi_os_get_root_pointer(void)
+{
+ acpi_physical_address pa;
+
+ acpi_find_root_pointer(&pa);
+ return pa;
+}
+
+/* XXX: Supposed to be 64 bit free-running
+ * monotonic timer with 100ns granularity
+ * but we just pretend for now
+ */
+u64
+acpi_os_get_timer(void)
+{
+ time_value_t now;
+
+ timer_read(current_timer[0], &now);
+ return (u64)(now.microseconds * 10);
+}
+
+void *
+acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
+{
+ return pmap_hack (phys, size);
+}
+
+acpi_status
+acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
+{
+ u32 dummy;
+
+ if (!value)
+ value = &dummy;
+
+ *value = 0;
+ if (width <= 8) {
+ *(u8 *) value = inb(port);
+ } else if (width <= 16) {
+ *(u16 *) value = inw(port);
+ } else if (width <= 32) {
+ *(u32 *) value = inl(port);
+ } else {
+ printf("ACPI: read port invalid width\n");
+ }
+
+ return AE_OK;
+}
+
+acpi_status
+acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
+ acpi_string *new_val)
+{
+ if (!init_val || !new_val)
+ return AE_BAD_PARAMETER;
+
+ return AE_OK;
+}
+
+acpi_status
+acpi_os_signal(u32 function, void *info)
+{
+ switch (function) {
+ case ACPI_SIGNAL_FATAL:
+ printf("ACPI: Fatal opcode executed\n");
+ break;
+ case ACPI_SIGNAL_BREAKPOINT:
+ break;
+ default:
+ break;
+ }
+ return AE_OK;
+}
+
+acpi_status
+acpi_os_physical_table_override(struct acpi_table_header *existing_table,
+ acpi_physical_address *address,
+ u32 *table_length)
+{
+ return AE_OK;
+}
+
+acpi_status
+acpi_os_table_override(struct acpi_table_header *existing_table,
+ struct acpi_table_header **new_table)
+{
+ if (!existing_table || !new_table)
+ return AE_BAD_PARAMETER;
+
+ *new_table = NULL;
+ return AE_OK;
+}
+
+void
+acpi_os_unmap_memory(void *virt, acpi_size size)
+{
+ return;
+}
+
+static int
+acpi_os_read_iomem(void *virt_addr, u64 *value, u32 width)
+{
+
+ switch (width) {
+ case 8:
+ *(u8 *) value = *((volatile u8 *)virt_addr);
+ break;
+ case 16:
+ *(u16 *) value = *((volatile u16 *)virt_addr);
+ break;
+ case 32:
+ *(u32 *) value = *((volatile u32 *)virt_addr);
+ break;
+ case 64:
+ *(u64 *) value = *((volatile u64 *)virt_addr);
+ break;
+ default:
+ return EINVAL;
+ }
+ return 0;
+}
+
+acpi_status
+acpi_os_read_memory(acpi_physical_address phys_addr, u64 *value, u32 width)
+{
+ void *virt_addr;
+ unsigned int size = width / 8;
+ u64 dummy;
+ acpi_status err = AE_BAD_ADDRESS;
+
+ virt_addr = vremap (phys_addr, size);
+ if (!virt_addr)
+ return err;
+
+ if (!value)
+ value = &dummy;
+
+ if (!acpi_os_read_iomem (virt_addr, value, width))
+ err = AE_OK;
+
+ //munmap (virt_addr, size);
+
+ 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)
+{
+ udelay(1000 * ms);
+}
+
+void
+acpi_os_stall(u32 us)
+{
+ udelay(us);
+}
+
+void acpi_os_wait_events_complete(void)
+{
+ return;
+}
+
+acpi_status
+acpi_os_write_memory(acpi_physical_address phys_addr, u64 value, u32 width)
+{
+ void *virt_addr;
+ unsigned int size = width / 8;
+ acpi_status err = AE_OK;
+
+ virt_addr = vremap (phys_addr, size);
+ if (!virt_addr)
+ return AE_BAD_ADDRESS;
+
+ switch (width) {
+ case 8:
+ *((volatile u8 *)virt_addr) = (u8)value;
+ break;
+ case 16:
+ *((volatile u16 *)virt_addr) = (u16)value;
+ break;
+ case 32:
+ *((volatile u32 *)virt_addr) = (u32)value;
+ break;
+ case 64:
+ *((volatile u64 *)virt_addr) = value;
+ break;
+ default:
+ printf("ACPI: Bad write memory width\n");
+ err = AE_BAD_ADDRESS;
+ break;
+ }
+
+ //munmap (virt_addr, size);
+
+ return err;
+}
+
+acpi_status
+acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
+{
+ if (width <= 8) {
+ outb(port, value);
+ } else if (width <= 16) {
+ outw(port, value);
+ } else if (width <= 32) {
+ outl(port, value);
+ } else {
+ printf("ACPI: Bad write port width\n");
+ }
+
+ return AE_OK;
+}
+
+
+acpi_status
+acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
+ void *context)
+{
+ return AE_OK;
+}
+
+acpi_status
+acpi_os_remove_interrupt_handler(u32 gsi, acpi_osd_handler handler)
+{
+ return AE_OK;
+}
+
+acpi_status
+acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
+ u64 *value, u32 width)
+{
+ printf("ACPI: Tried to read pci config\n");
+ return AE_ERROR;
+}
+
+acpi_status
+acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
+ u64 value, u32 width)
+{
+ printf("ACPI: Tried to write pci config\n");
+ return AE_ERROR;
+}
+
+/*
+ * Missing symbols to implement:
+ *
+ * isdigit
+ * isprint
+ * isspace
+ * isxdigit
+ * tolower
+ * toupper
+ * x acpi_ds_dump_method_stack
+ * x acpi_os_acquire_lock
+ * x acpi_os_create_cache
+ * x acpi_os_create_semaphore
+ * x acpi_os_delete_cache
+ * x acpi_os_delete_lock
+ * x acpi_os_delete_semaphore
+ * x acpi_os_get_root_pointer
+ * x acpi_os_get_timer
+ * x acpi_os_map_memory
+ * x acpi_os_physical_table_override
+ * x acpi_os_predefined_override
+ * x acpi_os_printf
+ * x acpi_os_read_memory
+ * x acpi_os_read_port
+ * x acpi_os_release_lock
+ * x acpi_os_release_object
+ * x acpi_os_signal
+ * x acpi_os_signal_semaphore
+ * x acpi_os_sleep
+ * x acpi_os_stall
+ * x acpi_os_table_override
+ * x acpi_os_unmap_memory
+ * x acpi_os_vprintf
+ * x acpi_os_wait_events_complete
+ * x acpi_os_wait_semaphore
+ * x acpi_os_write_memory
+ * x acpi_os_write_port
+ * xx acpi_os_execute
+ * xx acpi_os_install_interrupt_handler
+ * xx acpi_os_read_pci_configuration
+ * xx acpi_os_remove_interrupt_handler
+ * xx acpi_os_write_pci_configuration
+ */
+
void acpi_init(void)
{
acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0);