1/* 2 * Copyright 2017, Data61 3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4 * ABN 41 687 119 230. 5 * 6 * This software may be distributed and modified according to the terms of 7 * the BSD 2-Clause license. Note that NO WARRANTY is provided. 8 * See "LICENSE_BSD2.txt" for details. 9 * 10 * @TAG(DATA61_BSD) 11 */ 12 13#pragma once 14 15#include <stdint.h> 16#include <stdlib.h> 17 18#include <platsupport/io.h> 19#include <platsupport/plat/acpi/regions.h> 20 21/* pack structs (do not align fields) */ 22#pragma pack(push,1) 23 24/******************* 25 *** ACPI tables *** 26 *******************/ 27 28/* Root System Descriptor Pointer "RSD PTR " */ 29typedef struct acpi_rsdp { 30 char signature[8]; 31 uint8_t checksum; /* checksum of bytes 0-19 */ 32 char oem_id[6]; 33 uint8_t revision; 34 uint32_t rsdt_address; 35 uint32_t length; 36 uint64_t xsdt_address; 37 uint8_t extended_checksum; /* checksum of entire table */ 38 char reserved[3]; 39} acpi_rsdp_t; 40 41/* Generic System Descriptor Table Header */ 42typedef struct acpi_header { 43 char signature[4]; 44 uint32_t length; 45 uint8_t revision; 46 uint8_t checksum; 47 char oem_id[6]; 48 char oem_table_id[8]; 49 uint32_t oem_revision; 50 char creator_id[4]; 51 uint32_t creator_revision; 52} acpi_header_t; 53 54/* Generic Address Structure Format */ 55typedef struct acpi_gastruct { 56 uint8_t space_id; 57 uint8_t reg_bit_width; 58 uint8_t reg_but_offset; 59 uint8_t size; 60 uint64_t address; 61} acpi_GAS_t; 62 63#pragma pack(pop) 64 65#include <platsupport/plat/acpi/tables/asf.h> 66#include <platsupport/plat/acpi/tables/boot.h> 67#include <platsupport/plat/acpi/tables/dmar.h> 68#include <platsupport/plat/acpi/tables/dsdt.h> 69#include <platsupport/plat/acpi/tables/ssdt.h> 70#include <platsupport/plat/acpi/tables/facs.h> 71#include <platsupport/plat/acpi/tables/fadt.h> 72#include <platsupport/plat/acpi/tables/hpet.h> 73#include <platsupport/plat/acpi/tables/rsdt.h> 74#include <platsupport/plat/acpi/tables/xsdt.h> 75#include <platsupport/plat/acpi/tables/spcr.h> 76#include <platsupport/plat/acpi/tables/spmi.h> 77#include <platsupport/plat/acpi/tables/hest.h> 78#include <platsupport/plat/acpi/tables/erst.h> 79#include <platsupport/plat/acpi/tables/bert.h> 80#include <platsupport/plat/acpi/tables/einj.h> 81#include <platsupport/plat/acpi/tables/mcfg.h> 82#include <platsupport/plat/acpi/tables/madt.h> 83 84/* acpi struct */ 85typedef struct acpi { 86 void *regions; 87 acpi_rsdp_t rsdp; 88 ps_io_mapper_t io_mapper; 89} acpi_t; 90 91/** 92 * Initiliase the ACPI library. 93 * 94 * This will: allocate internal data and parse the acpi tables, which are 95 * assumed to be in unmapped physical memory. 96 * This function assumes that malloc will work. 97 * Once completed, this function will only consume the virtual memory that it has malloced. 98 * This function should only be called once. 99 * 100 * @param io_mapper Interface for mapping physical addresses. see io.h 101 * 102 * returns: an acpi handle to call other function with. 103 */ 104acpi_t *acpi_init(ps_io_mapper_t io_mapper); 105 106/** 107 * Initiliase the ACPI library with given RSDP. 108 * 109 * @param io_mapper Interface for mapping physical addresses. see io.h 110 * @param rsdp RSDP object to parse the ACPI tables with 111 * 112 * returns: an acpi handle to call other function with. 113 */ 114acpi_t * acpi_init_with_rsdp(ps_io_mapper_t io_mapper, acpi_rsdp_t rsdp); 115 116/* 117 * Find a specific acpi table. 118 * 119 * @param acpi the handle returned from acpi_init. 120 * @param region the type of region you want to find. 121 * @return NULL if not found, a pointer to the acpi header in virtual memory on success. 122 */ 123acpi_header_t *acpi_find_region(acpi_t *acpi, region_type_t region); 124 125