Skip to content

Commit

Permalink
acpi: init FADT table and get boot flags
Browse files Browse the repository at this point in the history
Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
  • Loading branch information
wipawel authored and bjoernd committed Aug 30, 2021
1 parent d7b4917 commit 62c321a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 15 deletions.
20 changes: 20 additions & 0 deletions common/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <page.h>
#include <pagetable.h>
#include <percpu.h>
#include <setup.h>
#include <string.h>

acpi_table_t *acpi_tables[128];
Expand Down Expand Up @@ -218,6 +219,19 @@ static const char *madt_int_trigger_names[] = {
[ACPI_MADT_INT_TRIGGER_LT] = "Level",
};

static int process_fadt(void) {
acpi_fadt_rev1_t *fadt = (acpi_fadt_rev1_t *) acpi_find_table(FADT_SIGNATURE);

if (!fadt)
return -1;

boot_flags.legacy_devs = !!(fadt->boot_flags & ACPI_FADT_LEGACY_DEVICES);
boot_flags.i8042 = !!(fadt->boot_flags & ACPI_FADT_8042);
boot_flags.vga = !(fadt->boot_flags & ACPI_FADT_NO_VGA);

return 0;
}

static int process_madt_entries(unsigned bsp_cpu_id) {
acpi_madt_t *madt = (acpi_madt_t *) acpi_find_table(MADT_SIGNATURE);
acpi_madt_entry_t *entry;
Expand Down Expand Up @@ -371,6 +385,7 @@ int init_acpi(unsigned bsp_cpu_id) {
unsigned acpi_nr_tables;
rsdt_t *rsdt = NULL;
xsdt_t *xsdt = NULL;
int rc;

printk("Initializing ACPI support\n");

Expand Down Expand Up @@ -415,5 +430,10 @@ int init_acpi(unsigned bsp_cpu_id) {
}

acpi_dump_tables();

rc = process_fadt();
if (rc < 0)
return rc;

return process_madt_entries(bsp_cpu_id);
}
45 changes: 31 additions & 14 deletions include/acpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#define RSDT_SIGNATURE (('R') | ('S' << 8) | ('D' << 16) | ('T' << 24))
#define XSDT_SIGNATURE (('X') | ('S' << 8) | ('D' << 16) | ('T' << 24))
#define MADT_SIGNATURE (('A') | ('P' << 8) | ('I' << 16) | ('C' << 24))
#define FADT_SIGNATURE (('F') | ('A' << 8) | ('C' << 16) | ('P' << 24))

/* ACPI common table header */
struct acpi_table_hdr {
Expand Down Expand Up @@ -87,18 +88,28 @@ struct acpi_table {
} __packed;
typedef struct acpi_table acpi_table_t;

/* Generic Address Structure */
struct acpi_gas {
uint8_t address_space;
uint8_t bit_width;
uint8_t bit_offset;
uint8_t access_size;
uint64_t address;
} __packed;
typedef struct acpi_gas acpi_gas_t;

struct acpi_fadt_rev1 {
acpi_table_hdr_t header;
uint32_t firmware_ctrl; /* Physical address of FACS */
uint32_t dsdt; /* Physical address of DSDT */
uint8_t model;
uint8_t rsvd1;
uint8_t preferred_profile;
uint16_t sci_int; /* SCI interrupt vector */
uint32_t smi_cmd; /* SMI command port address */
uint8_t acpi_enable;
uint8_t acpi_disable;
uint8_t S4bios_req;
uint8_t rsvd2; /* Must be zero */
uint8_t pstate_ctrl;
uint32_t pm1a_evt_blk;
uint32_t pm1b_evt_blk;
uint32_t pm1a_ctrl_blk;
Expand All @@ -114,7 +125,7 @@ struct acpi_fadt_rev1 {
uint8_t gpe0_blk_len;
uint8_t gpe1_blk_len;
uint8_t gpe1_base;
uint8_t rsvd3;
uint8_t cst_ctrl;
uint16_t plvl2_lat;
uint16_t plvl3_lat;
uint16_t flush_size;
Expand All @@ -124,20 +135,16 @@ struct acpi_fadt_rev1 {
uint8_t day_alrm;
uint8_t mon_alrm;
uint8_t century;
uint8_t rsvd4[3];
uint16_t boot_flags;
uint8_t rsvd;
uint32_t flags;
acpi_gas_t reset_reg;
uint8_t reset_val;
uint16_t arm_boot_flags;
uint8_t minor_rev;
} __packed;
typedef struct acpi_fadt_rev1 acpi_fadt_rev1_t;

/* Generic Address Structure */
struct acpi_gas {
uint8_t address_space;
uint8_t bit_width;
uint8_t bit_offset;
uint8_t access_size;
uint64_t address;
} __packed;
typedef struct acpi_gas acpi_gas_t;

struct acpi_fadt_rev2 {
acpi_fadt_rev1_t rev1;
uint64_t x_firmware_ctrl;
Expand All @@ -153,6 +160,16 @@ struct acpi_fadt_rev2 {
} __packed;
typedef struct acpi_fadt_rev2 acpi_fadt_rev2_t;

enum acpi_fadt_boot_flags {
ACPI_FADT_LEGACY_DEVICES = 1,
ACPI_FADT_8042 = 2,
ACPI_FADT_NO_VGA = 4,
ACPI_FADT_NO_MSI = 8,
ACPI_FADT_NO_ASPM = 16,
ACPI_FADT_NO_CMOS_RTC = 32,
};
typedef enum acpi_fadt_boot_flags acpi_fadt_boot_flags_t;

struct acpi_madt_entry {
uint8_t type;
uint8_t len;
Expand Down
3 changes: 2 additions & 1 deletion include/setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
#include <mm/pmm.h>

struct boot_flags {
uint64_t virt : 1, rsvd : 63;
uint64_t virt : 1, legacy_devs : 1, i8042 : 1, vga : 1, msi : 1, aspm : 1, rtc : 1,
rsvd : 57;
};
typedef struct boot_flags boot_flags_t;

Expand Down

0 comments on commit 62c321a

Please sign in to comment.