#include <libk/align.h>
#include <libk/std.h>
#include <limine/requests.h>
#include <mm/liballoc.h>
#include <sys/debug.h>
#include <sys/mm.h>
#include <uacpi/kernel_api.h>
#include <uacpi/status.h>

uacpi_status uacpi_kernel_get_rsdp (uacpi_phys_addr* out_rsdp_address) {
  struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
  struct limine_rsdp_response* rsdp = limine_rsdp_request.response;

  *out_rsdp_address = (uacpi_phys_addr)((uintptr_t)rsdp->address - (uintptr_t)hhdm->offset);

  return UACPI_STATUS_OK;
}

void* uacpi_kernel_map (uacpi_phys_addr addr, uacpi_size len) {
  (void)len;

  struct limine_hhdm_response* hhdm = limine_hhdm_request.response;

  return (void*)((uintptr_t)hhdm->offset + (uintptr_t)addr);
}

void uacpi_kernel_unmap (void* addr, uacpi_size len) {
  (void)addr;
  (void)len;
}

void uacpi_kernel_log (uacpi_log_level level, const uacpi_char* msg) {
  const char* prefix = NULL;

  switch (level) {
  case UACPI_LOG_DEBUG:
    prefix = "Debug";
    break;
  case UACPI_LOG_TRACE:
    prefix = "Trace";
    break;
  case UACPI_LOG_INFO:
    prefix = "Info";
    break;
  case UACPI_LOG_WARN:
    prefix = "Warning";
    break;
  case UACPI_LOG_ERROR:
    prefix = "Error";
    break;
  }

  DEBUG ("%s %s", prefix, msg);
}
