2

ACPI Standard Description Tables

Free lines C/C++ 1 revisions 142 7 months ago 7 months ago
#pragma once
#include <stdint.h>

namespace ACPI {
    struct sign_8_type {
      char sign[8];
      char dummy[8]; //add for easier iteration (RSD PTR is alwas on a 16 byte boundary)
    };

    struct sign_4_type {
      char sign[4];
    };

namespace SDT {

    struct RSDP{
    char Signature[8];
    uint8_t Checksum;
    char OEMID[6];
    uint8_t Revision;
    uint32_t RsdtAddress;
    } __attribute__ ((packed));

    struct RSDP20 {
    RSDP firstPart;
    
    uint32_t Length;
    uint64_t XsdtAddress;
    uint8_t ExtendedChecksum;
    uint8_t reserved[3];
    } __attribute__ ((packed));

    struct ACPISDTHeader {
      char Signature[4];
      uint32_t Length;
      uint8_t Revision;
      uint8_t Checksum;
      char OEMID[6];
      char OEMTableID[8];
      uint32_t OEMRevision;
      uint32_t CreatorID;
      uint32_t CreatorRevision;
    } __attribute__ ((packed));

    typedef ACPISDTHeader generic_sdt;

    struct BER { //Boot error Region
      uint32_t BlockStatus;
      uint32_t RawDataOffset;
      uint32_t RawDataLenght;
      uint32_t DataLength;
      uint32_t ErrorSeverity;
      uint8_t GenericErrorData[1]; //treated as array for now, will be handled by a wrapper class later
    } __attribute__ ((packed));

    struct BERT {
     ACPISDTHeader h;
     uint32_t BootErrorRegionLength;
     uint64_t BooErrorRegion; 
    } __attribute__ ((packed));

    struct CPEP {
      ACPISDTHeader h;
      uint32_t Reserved; //MUST be 0
      uint8_t ProcessorStructure[1]; //handled by a wrapper class
    } __attribute__ ((packed));

    struct DSDT {
      ACPISDTHeader h;
      uint8_t DefinitionBlock[1]; //handled by wrapper class
    } __attribute__ ((packed));

    struct GENERIC_MADT_ENTRY {
      uint8_t EntryType;
      uint8_t RecordLength;
    } __attribute__ ((packed));
 
    struct MADT_ENTRY_TYPE_0 {
      GENERIC_MADT_ENTRY h;
      uint8_t ACPIProcessorID;
      uint8_t ACPIID;
      uint32_t Flags; 
    } __attribute__ ((packed));

    struct MADT_ENTRY_TYPE_1 {
      GENERIC_MADT_ENTRY h;
      uint8_t IOApicID;
      uint8_t Reserved;
      uint64_t IOAcpiAddr;
      uint64_t GlobalSystemInterruptBase;
    } __attribute__ ((packed));

    struct MADT_ENTRY_TYPE_2 {
      GENERIC_MADT_ENTRY h;
      uint8_t BusSource;
      uint8_t IRQSource;
      uint32_t GlobalSystemInterrupt;
      uint16_t Flags;
    } __attribute__ ((packed));

    struct MADT_ENTRY_TYPE_3 { //local APIC NMI structure
      GENERIC_MADT_ENTRY h;
      uint16_t Flags;
      uint32_t GlobalSystemInterrupt;
    } __attribute__ ((packed));

    struct MADT_ENTRY_TYPE_4 {
      GENERIC_MADT_ENTRY h;
      uint8_t ACPIProcessorID; //0xFF ^= all processors
      uint16_t Flags;
      uint8_t LINT; //1 or 0
    } __attribute__ ((packed));

    struct MADT_ENTRY_TYPE_5 {
      GENERIC_MADT_ENTRY h;
      uint16_t Reserved;
      uint64_t LocalAPICAddr;
    } __attribute__ ((packed));

    struct MADT_ENTRY_TYPE_6 {
      GENERIC_MADT_ENTRY h;
      uint8_t APICID;
      uint8_t Reserved;
      uint32_t GlobalSystemInterruptBase;
      uint64_t IOSAPICAdress;
    } __attribute__ ((packed));

    struct MADT_ENTRY_TYPE_7{
      GENERIC_MADT_ENTRY h;
      uint8_t ACPIProcessorID;
      uint8_t LocalSAPICID;
      uint8_t LocalSAPICEID;
      uint8_t Reserved[3]; //must be set to zero!!
      uint32_t Flags;
      uint32_t ACPIProcessorUIDValue;
      uint8_t ACPIProcessorUIDString [1]; //to be understood by the wrapper
    } __attribute__ ((packed));

    struct MADT_ENTRY_TYPE_8 {
      GENERIC_MADT_ENTRY h;
      uint16_t Flags;
      uint8_t InterruptType;
      uint8_t ProcessorID;
      uint8_t ProcessorEID;
      uint8_t IOSAPICVector;
      uint32_t GlobalSystemInterrupt;
      uint32_t PlatformInterruptSourceFlags;
    } __attribute__ ((packed));

    struct MADT_ENTRY_TYPE_9 {
      GENERIC_MADT_ENTRY h;
      uint16_t Reserved; //must be set to zero;
      uint32_t X2APICID;
      uint32_t Flags;
      uint32_t ACPIProcessorUID;
    } __attribute__ ((packed));

    struct MADT_ENTRY_TYPE_10 {
      GENERIC_MADT_ENTRY h;
      uint16_t Flags;
      uint32_t ACPIProcessorUID;
      uint8_t LocalX2APICLint;
      uint8_t Reserved[3];
    } __attribute__ ((packed));

    struct MADT_ENTRY_TYPE_11 {
      GENERIC_MADT_ENTRY h;
      uint16_t Reserved; //must be set to zero
      uint32_t GICID;
      uint32_t ACPIProcessorUID;
      uint32_t Flags;
    } __attribute__ ((packed));

    struct MADT_ENTRY_TYPE_12 {
      GENERIC_MADT_ENTRY h;
      uint16_t Reserved_1;
      uint32_t GICID;
      uint64_t PhysicalBaseAdress;
      uint32_t SystemVectorBase;
      uint32_t Reserved_2;
    } __attribute__ ((packed));

    struct MADT {
      ACPISDTHeader h;
      uint32_t LocalApicAddress;
      uint32_t Flags;
      uint8_t Entries[1];
    } __attribute__ ((packed));

    struct RSDT {
      ACPISDTHeader h;
      uint32_t PointerToOtherSDT[1];
    } __attribute__ ((packed));

    struct XSDT {
      ACPISDTHeader h;
      uint64_t PointerToOtherSDT[1];
    } __attribute__ ((packed));

    struct GenericAddressStructure
    {
      uint8_t AddressSpace;
      uint8_t BitWidth;
      uint8_t BitOffset;
      uint8_t AccessSize;
      uint64_t Address;
    };

    struct FADT
    {
        uint32_t FirmwareCtrl;
        uint32_t Dsdt;
     
        // field used in ACPI 1.0; no longer in use, for compatibility only
        uint8_t  Reserved;
     
        uint8_t  PreferredPowerManagementProfile;
        uint16_t SCI_Interrupt;
        uint32_t SMI_CommandPort;
        uint8_t  AcpiEnable;
        uint8_t  AcpiDisable;
        uint8_t  S4BIOS_REQ;
        uint8_t  PSTATE_Control;
        uint32_t PM1aEventBlock;
        uint32_t PM1bEventBlock;
        uint32_t PM1aControlBlock;
        uint32_t PM1bControlBlock;
        uint32_t PM2ControlBlock;
        uint32_t PMTimerBlock;
        uint32_t GPE0Block;
        uint32_t GPE1Block;
        uint8_t  PM1EventLength;
        uint8_t  PM1ControlLength;
        uint8_t  PM2ControlLength;
        uint8_t  PMTimerLength;
        uint8_t  GPE0Length;
        uint8_t  GPE1Length;
        uint8_t  GPE1Base;
        uint8_t  CStateControl;
        uint16_t WorstC2Latency;
        uint16_t WorstC3Latency;
        uint16_t FlushSize;
        uint16_t FlushStride;
        uint8_t  DutyOffset;
        uint8_t  DutyWidth;
        uint8_t  DayAlarm;
        uint8_t  MonthAlarm;
        uint8_t  Century;
     
        // reserved in ACPI 1.0; used since ACPI 2.0+
        uint16_t BootArchitectureFlags;
     
        uint8_t  Reserved2;
        uint32_t Flags;
     
        // 12 byte structure; see below for details
        GenericAddressStructure ResetReg;
     
        uint8_t  ResetValue;
        uint8_t  Reserved3[3];
     
        // 64bit pointers - Available on ACPI 2.0+
        uint64_t                X_FirmwareControl;
        uint64_t                X_Dsdt;
     
        GenericAddressStructure X_PM1aEventBlock;
        GenericAddressStructure X_PM1bEventBlock;
        GenericAddressStructure X_PM1aControlBlock;
        GenericAddressStructure X_PM1bControlBlock;
        GenericAddressStructure X_PM2ControlBlock;
        GenericAddressStructure X_PMTimerBlock;
        GenericAddressStructure X_GPE0Block;
        GenericAddressStructure X_GPE1Block;
    };
}
}