The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
acpi.c File Reference
#include "acpi.h"
#include "arch/arch.h"
#include "arch/x86/cpu/io.h"
#include "common/memory.h"
#include "common/string.h"
#include "drivers/pci/pci.h"
#include "kernel/klog/klog.h"
#include "kernel/memory/mmio.h"
#include "kernel/memory/phys.h"

Macros

#define SDT_HEADER_SIZE   36
 the ACPI static tables (ACPI specification, chapter 5.2).
#define TABLE_MAX_SIZE   (256u * 1024u)
#define MADT_LAPIC   0
#define MADT_IOAPIC   1
#define MADT_ISO   2
#define MADT_LAPIC_OVERRIDE   5
#define MADT_PCAT_COMPAT   0x1u
#define LAPIC_ENABLED   0x1u
#define LAPIC_ONLINE_OK   0x2u
#define FADT_RESET_REG_SUP   (1u << 10)

Functions

bool acpi_find_s5 (const uint8_t *aml, uint32_t length, uint8_t *type_a, uint8_t *type_b)
 find the S5 sleep types in DSDT bytes (the AML of "Name (_S5, Package () {a, b, ...})"), without an AML interpreter.
bool acpi_init (const boot_info_t *boot)
 find and read the tables.
const acpi_info_t * acpi_info (void)
 what acpi_init found (present is false if it found nothing).
uint32_t acpi_irq_to_gsi (uint8_t irq, bool *active_low, bool *level)
 the global system interrupt of a legacy ISA IRQ, after the MADT overrides (for example IRQ 0 is often GSI 2).
void acpi_power_off (void)
 turn the machine off: the ACPI S5 state (the _S5 sleep types into the PM1 control registers), then the QEMU and Bochs ports.
void acpi_reboot (void)
 restart the machine: the FADT reset register, then the keyboard controller, then a triple fault.

Macro Definition Documentation

◆ SDT_HEADER_SIZE

#define SDT_HEADER_SIZE   36

the ACPI static tables (ACPI specification, chapter 5.2).

the RSDP points to the RSDT (32-bit table addresses) and, from ACPI 2.0, to the XSDT (64-bit table addresses). each table starts with a 36-byte header with a signature, a length and a checksum (all bytes add up to 0). the tables are in reserved or ACPI memory, which is not always in the direct map, so the kernel maps each table with ioremap.

◆ TABLE_MAX_SIZE

#define TABLE_MAX_SIZE   (256u * 1024u)

◆ MADT_LAPIC

#define MADT_LAPIC   0

◆ MADT_IOAPIC

#define MADT_IOAPIC   1

◆ MADT_ISO

#define MADT_ISO   2

◆ MADT_LAPIC_OVERRIDE

#define MADT_LAPIC_OVERRIDE   5

◆ MADT_PCAT_COMPAT

#define MADT_PCAT_COMPAT   0x1u

◆ LAPIC_ENABLED

#define LAPIC_ENABLED   0x1u

◆ LAPIC_ONLINE_OK

#define LAPIC_ONLINE_OK   0x2u

◆ FADT_RESET_REG_SUP

#define FADT_RESET_REG_SUP   (1u << 10)

Function Documentation

◆ acpi_find_s5()

bool acpi_find_s5 ( const uint8_t * aml,
uint32_t length,
uint8_t * type_a,
uint8_t * type_b )

find the S5 sleep types in DSDT bytes (the AML of "Name (_S5, Package () {a, b, ...})"), without an AML interpreter.

Returns
false if there is no such package.

◆ acpi_init()

bool acpi_init ( const boot_info_t * boot)

find and read the tables.

the RSDP comes from the bootloader if it gave one, else from a scan of the BIOS areas. call after mmio_init.

Parameters
bootthe boot information (rsdp, rsdp_size).
Returns
true if the tables were found.

◆ acpi_info()

const acpi_info_t * acpi_info ( void )

what acpi_init found (present is false if it found nothing).

◆ acpi_irq_to_gsi()

uint32_t acpi_irq_to_gsi ( uint8_t irq,
bool * active_low,
bool * level )

the global system interrupt of a legacy ISA IRQ, after the MADT overrides (for example IRQ 0 is often GSI 2).

Parameters
irqan ISA IRQ, 0 to 15.
active_lowreceives the polarity (may be NULL).
levelreceives the trigger mode (may be NULL).

◆ acpi_power_off()

void acpi_power_off ( void )

turn the machine off: the ACPI S5 state (the _S5 sleep types into the PM1 control registers), then the QEMU and Bochs ports.

if all fail, the CPU halts.

◆ acpi_reboot()

void acpi_reboot ( void )

restart the machine: the FADT reset register, then the keyboard controller, then a triple fault.

does not return.