text: /*
   * Copyright (c) 2021, Dylan Cleaver <dylancleaver@yahoo.com>
   *
   * SPDX-License-Identifier: BSD-2-Clause
   */
  
  #ifndef ACPI_H
  #define ACPI_H
  
  #include <stdint.h>
  
  
  struct rsdp_descriptor
  {
      char signature[8];
      uint8_t checksum;
      char oem_id[6];
      uint8_t revision;
      uint32_t rsdt_address;
  } __attribute__((packed));
  
  
  struct acpi_sdt_header
  {
      char signature[4];
      uint32_t length;
      uint8_t revision;
      uint8_t checksum;
      char oem_id[6];
      char oem_table_id[8];
      uint32_t oem_revision;
      uint32_t creator_id;
      uint32_t creator_revision;
  } __attribute__((packed));
  
  
  struct rsdt_header
  {
      char signature[4];
      uint32_t length;
      uint8_t revision;
      uint8_t checksum;
      char oem_id[6];
      char oem_table_id[8];
      uint32_t oem_revision;
      uint32_t creator_id;
      uint32_t creater_revision;
      uint32_t other_sdt_header_addr;
  } __attribute__((packed));
  
  
  struct mcfg_header
  {
      struct acpi_sdt_header h;
      uint64_t reserved;
  } __attribute__((packed));
  
  
  struct generic_address_structure
  {
      uint8_t address_space;
      uint8_t bit_width;
      uint8_t bit_offset;
      uint8_t access_size;
      uint64_t address;
  };
  
  
  struct fadt_data
  {
      struct acpi_sdt_header h;
      uint32_t firmware_ctrl;
      uint32_t dsdt;
  
      uint8_t reserved;
  
      uint8_t preferred_power_mgmt_profile;
      uint16_t sci_interrupt;
      uint32_t smi_command_port;
  
      uint8_t acpi_enable;
      uint8_t acpi_disable;
      uint8_t S4BIOS_REQ;
      uint8_t pstate_control;
  
      uint32_t pm1a_event_block;
      uint32_t pm1b_event_block;
      uint32_t pm1a_control_block;
      uint32_t pm1b_control_block;
      uint32_t pm2_control_block;
      uint32_t pm_timer_block;
      uint32_t gpe0_block;
      uint32_t gpe1_block;
  
      uint8_t pm1_event_length;
      uint8_t pm1_control_length;
      uint8_t pm2_control_length;
      uint8_t pm_timer_length;
      uint8_t gpe0_length;
      uint8_t gpe1_length;
      uint8_t gpe1_base;
      uint8_t c_state_control;
  
      uint16_t worst_c2_latency;
      uint16_t worst_c3_latency;
      uint16_t flush_size;
      uint16_t flush_stride;
  
      uint8_t duty_offset;
      uint8_t duty_width;
      uint8_t duty_alarm;
      uint8_t month_alarm;
      uint8_t century;
  
      uint16_t boot_architecture_flags;
  
      uint8_t reserved2;
  
      uint32_t flags;
  
      struct generic_address_structure reset_register;
      uint8_t reset_value;
  
      uint8_t reserved3[3];
  
      uint64_t x_firmware_control;
      uint64_t x_dsdt;
  
      struct generic_address_structure x_pm1a_event_block;
      struct generic_address_structure x_pm1b_event_block;
      struct generic_address_structure x_pm1a_control_block;
      struct generic_address_structure x_pm1b_control_block;
      struct generic_address_structure x_pm2_control_block;
      struct generic_address_structure x_pm_timer_block;
      struct generic_address_structure x_gpe0_block;
      struct generic_address_structure x_gpe1_block;
  } __attribute__((packed));
  
  struct rsdp_descriptor *acpi_get_rsdp(uint32_t mboot_addr);
  struct rsdt_header *acpi_get_rsdt(uint32_t addr);
  struct acpi_sdt_header *acpi_get_sdt_header(const char *table_name);
  void acpi_init(uint32_t mboot_addr);
  
  #endif
  