MonkOS  v0.1
A simple 64-bit operating system (x86_64)
acpi.c File Reference

Advanced configuration and power interface (ACPI) tables. More...

#include <core.h>
#include <libc/string.h>
#include <kernel/debug/log.h>
#include <kernel/mem/acpi.h>
#include <kernel/mem/kmem.h>
#include <kernel/mem/paging.h>
#include <kernel/mem/pmap.h>
#include <kernel/x86/cpu.h>

Go to the source code of this file.

Data Structures

struct  btable_t
 A structure used to track the state of the temporary page table generated by the boot loader. More...
 
struct  acpi_rsdp
 
struct  acpi_rsdt
 
struct  acpi_xsdt
 
struct  acpi
 

Macros

#define SIGNATURE_RSDP   0x2052545020445352ll
 
#define SIGNATURE_MADT   0x43495041
 
#define SIGNATURE_BOOT   0x544f4f42
 
#define SIGNATURE_FADT   0x50434146
 
#define SIGNATURE_HPET   0x54455048
 
#define SIGNATURE_MCFG   0x4746434d
 
#define SIGNATURE_SRAT   0x54415253
 
#define SIGNATURE_SSDT   0x54445353
 
#define SIGNATURE_WAET   0x54454157
 
#define PAGE_ALIGN_DOWN(a)   ((a) & ~(PAGE_SIZE - 1))
 
#define PAGE_ALIGN_UP(a)   (((a) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
 

Functions

static void read_fadt (const struct acpi_hdr *hdr)
 
static void read_madt (const struct acpi_hdr *hdr)
 
static void read_mcfg (const struct acpi_hdr *hdr)
 
static void read_table (const struct acpi_hdr *hdr)
 
static bool is_mapped (btable_t *btable, uint64_t addr)
 
static uint64_t alloc_page (btable_t *btable)
 
static void create_page (btable_t *btable, uint64_t addr, uint64_t flags)
 
static void map_range (btable_t *btable, uint64_t addr, uint64_t size, uint64_t flags)
 
static void map_table (btable_t *btable, const struct acpi_hdr *hdr)
 
static void read_xsdt (btable_t *btable)
 
static void read_rsdt (btable_t *btable)
 
static const struct acpi_rsdpfind_rsdp (uint64_t addr, uint64_t size)
 
void acpi_init ()
 Find and parse all available ACPI tables. More...
 
int acpi_version ()
 Return the ACPI version number. More...
 
const struct acpi_fadtacpi_fadt ()
 Return a pointer to the ACPI fixed ACPI description table. More...
 
const struct acpi_madtacpi_madt ()
 Return a pointer to the ACPI multiple APIC description table (MADT). More...
 
static const void * madt_find (enum acpi_madt_type type, const void *prev)
 
const struct acpi_madt_local_apicacpi_next_local_apic (const struct acpi_madt_local_apic *prev)
 Return a pointer to the next Local APIC structure entry in the MADT table. More...
 
const struct acpi_madt_io_apicacpi_next_io_apic (const struct acpi_madt_io_apic *prev)
 Return a pointer to the next I/O APIC structure entry in the MADT table. More...
 
const struct acpi_madt_isoacpi_next_iso (const struct acpi_madt_iso *prev)
 Return a pointer to the next Interrupt Source Override (ISO) structure entry in the MADT table. More...
 
const struct acpi_mcfg_addracpi_next_mcfg_addr (const struct acpi_mcfg_addr *prev)
 Return a pointer to the next Mapped Configuration (MCFG) address entry, used for PCIe. More...
 

Variables

struct acpi_rsdp PACKSTRUCT
 
static struct acpi acpi
 

Detailed Description

Advanced configuration and power interface (ACPI) tables.

Definition in file acpi.c.


Data Structure Documentation

struct btable_t

A structure used to track the state of the temporary page table generated by the boot loader.

The ACPI code updates it to access the memory stored in ACPI tables.

Definition at line 36 of file acpi.c.

Data Fields
page_t * root The top-level (PML4) page table.
page_t * next_page The next page to use when allocating.
page_t * term_page Just beyond the last available page.
struct acpi_rsdp

Definition at line 43 of file acpi.c.

Data Fields
char signature[8] Contains "RSD PTR ".
uint8_t checksum Covers up to (and including) ptr_rsdt.
char oemid[6] Supplied by the OEM.
uint8_t revision 0=1.0, 1=2.0, 2=3.0
uint32_t ptr_rsdt 32-bit pointer to RSDT table
uint32_t length RSDT table length, including header.
uint64_t ptr_xsdt 64-bit pointer to XSDT table
uint8_t checksum_ex Covers entire rsdp structure.
uint8_t reserved[3]
struct acpi_rsdt

Definition at line 58 of file acpi.c.

Data Fields
struct acpi_hdr hdr
uint32_t ptr_table[1] Pointers to other ACPI tables.
struct acpi_xsdt

Definition at line 64 of file acpi.c.

Data Fields
struct acpi_hdr hdr
uint64_t ptr_table[1] Pointers to other ACPI tables.
struct acpi

Definition at line 70 of file acpi.c.

Data Fields
int version
const struct acpi_rsdp * rsdp
const struct acpi_rsdt * rsdt
const struct acpi_xsdt * xsdt
const struct acpi_fadt * fadt
const struct acpi_madt * madt
const struct acpi_mcfg * mcfg

Macro Definition Documentation

#define SIGNATURE_RSDP   0x2052545020445352ll

Definition at line 19 of file acpi.c.

Referenced by find_rsdp().

#define SIGNATURE_MADT   0x43495041

Definition at line 20 of file acpi.c.

Referenced by read_table().

#define SIGNATURE_BOOT   0x544f4f42

Definition at line 21 of file acpi.c.

#define SIGNATURE_FADT   0x50434146

Definition at line 22 of file acpi.c.

Referenced by read_table().

#define SIGNATURE_HPET   0x54455048

Definition at line 23 of file acpi.c.

#define SIGNATURE_MCFG   0x4746434d

Definition at line 24 of file acpi.c.

Referenced by read_table().

#define SIGNATURE_SRAT   0x54415253

Definition at line 25 of file acpi.c.

#define SIGNATURE_SSDT   0x54445353

Definition at line 26 of file acpi.c.

#define SIGNATURE_WAET   0x54454157

Definition at line 27 of file acpi.c.

#define PAGE_ALIGN_DOWN (   a)    ((a) & ~(PAGE_SIZE - 1))

Definition at line 30 of file acpi.c.

Referenced by acpi_init(), map_range(), and map_table().

#define PAGE_ALIGN_UP (   a)    (((a) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))

Definition at line 31 of file acpi.c.

Referenced by map_range(), and map_table().

Function Documentation

static void read_fadt ( const struct acpi_hdr hdr)
static

Definition at line 84 of file acpi.c.

Referenced by read_table().

static void read_madt ( const struct acpi_hdr hdr)
static

Definition at line 91 of file acpi.c.

Referenced by read_table().

static void read_mcfg ( const struct acpi_hdr hdr)
static

Definition at line 98 of file acpi.c.

Referenced by read_table().

static void read_table ( const struct acpi_hdr hdr)
static

Definition at line 105 of file acpi.c.

Referenced by read_rsdt(), and read_xsdt().

static bool is_mapped ( btable_t btable,
uint64_t  addr 
)
static

Definition at line 124 of file acpi.c.

Referenced by map_range().

static uint64_t alloc_page ( btable_t btable)
static

Definition at line 152 of file acpi.c.

Referenced by create_page().

static void create_page ( btable_t btable,
uint64_t  addr,
uint64_t  flags 
)
static

Definition at line 163 of file acpi.c.

Referenced by map_range().

static void map_range ( btable_t btable,
uint64_t  addr,
uint64_t  size,
uint64_t  flags 
)
static

Definition at line 187 of file acpi.c.

Referenced by map_table().

static void map_table ( btable_t btable,
const struct acpi_hdr hdr 
)
static

Definition at line 202 of file acpi.c.

Referenced by acpi_init(), read_rsdt(), and read_xsdt().

static void read_xsdt ( btable_t btable)
static

Definition at line 223 of file acpi.c.

Referenced by acpi_init().

static void read_rsdt ( btable_t btable)
static

Definition at line 245 of file acpi.c.

Referenced by acpi_init().

static const struct acpi_rsdp* find_rsdp ( uint64_t  addr,
uint64_t  size 
)
static

Definition at line 267 of file acpi.c.

Referenced by acpi_init().

void acpi_init ( )

Find and parse all available ACPI tables.

Definition at line 281 of file acpi.c.

Referenced by kmain().

int acpi_version ( )

Return the ACPI version number.

Returns
The ACPI version number (1 through 5).

Definition at line 352 of file acpi.c.

const struct acpi_fadt* acpi_fadt ( )

Return a pointer to the ACPI fixed ACPI description table.

Returns
A pointer to the non-extended FADT structure.

Definition at line 358 of file acpi.c.

const struct acpi_madt* acpi_madt ( )

Return a pointer to the ACPI multiple APIC description table (MADT).

Returns
A pointer to the MADT structure.

Definition at line 364 of file acpi.c.

Referenced by cmd_display_apic().

static const void* madt_find ( enum acpi_madt_type  type,
const void *  prev 
)
static

Definition at line 370 of file acpi.c.

Referenced by acpi_next_io_apic(), acpi_next_iso(), and acpi_next_local_apic().

const struct acpi_madt_local_apic* acpi_next_local_apic ( const struct acpi_madt_local_apic prev)

Return a pointer to the next Local APIC structure entry in the MADT table.

Parameters
[in]prevPointer to the local APIC returned by a previous call to this function. Pass NULL for the first call.
Returns
A pointer to a the next local APIC structure, or NULL if none remain.

Definition at line 398 of file acpi.c.

Referenced by cmd_display_apic().

const struct acpi_madt_io_apic* acpi_next_io_apic ( const struct acpi_madt_io_apic prev)

Return a pointer to the next I/O APIC structure entry in the MADT table.

Parameters
[in]prevPointer to the I/O APIC returned by a previous call to this function. Pass NULL for the first call.
Returns
A pointer to a the next I/O APIC structure, or NULL if none remain.

Definition at line 405 of file acpi.c.

Referenced by acpi_init(), and cmd_display_apic().

const struct acpi_madt_iso* acpi_next_iso ( const struct acpi_madt_iso prev)

Return a pointer to the next Interrupt Source Override (ISO) structure entry in the MADT table.

Parameters
[in]prevPointer to the ISO returned by a previous call to this function. Pass NULL for the first call.
Returns
A pointer to a the next ISO structure, or NULL if none remain.

Definition at line 412 of file acpi.c.

Referenced by cmd_display_apic().

const struct acpi_mcfg_addr* acpi_next_mcfg_addr ( const struct acpi_mcfg_addr prev)

Return a pointer to the next Mapped Configuration (MCFG) address entry, used for PCIe.

Parameters
[in]prevPointer to the MCFG entry returned by a previous call to this function. Pass NULL for the first call.
Returns
A pointer to a the next MCFG entry, or NULL if none remain.

Definition at line 419 of file acpi.c.

Referenced by cmd_display_pcie().

Variable Documentation

struct acpi_xsdt PACKSTRUCT
struct acpi acpi
static

Definition at line 81 of file acpi.c.