github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/vmm/include/vmm_acpi.h (about) 1 /* 2 * Copyright (c) 2013 Intel Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * Unless required by applicable law or agreed to in writing, software 9 * distributed under the License is distributed on an "AS IS" BASIS, 10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 * See the License for the specific language governing permissions and 12 * limitations under the License. 13 */ 14 15 #ifndef _VMM_ACPI_H_ 16 #define _VMM_ACPI_H_ 17 18 #define ACPI_PM1_CNTRL_REG_A 0 19 #define ACPI_PM1_CNTRL_REG_B 1 20 #define ACPI_PM1_CNTRL_REG_COUNT 2 21 22 #define ACPI_NAME_SIZE 4 23 #define ACPI_OEM_ID_SIZE 6 24 #define ACPI_OEM_TABLE_ID_SIZE 8 25 26 #define ACPI_STATE_UNKNOWN (UINT8) 0xFF 27 28 #define ACPI_STATE_S0 (UINT8) 0 29 #define ACPI_STATE_S1 (UINT8) 1 30 #define ACPI_STATE_S2 (UINT8) 2 31 #define ACPI_STATE_S3 (UINT8) 3 32 #define ACPI_STATE_S4 (UINT8) 4 33 #define ACPI_STATE_S5 (UINT8) 5 34 #define ACPI_S_STATES_MAX ACPI_STATE_S5 35 #define ACPI_S_STATE_COUNT 6 36 37 /* 38 * Values for description table header signatures. Useful because they make 39 * it more difficult to inadvertently type in the wrong signature. 40 */ 41 #define ACPI_SIG_DSDT "DSDT" /* Differentiated System Description Table */ 42 #define ACPI_SIG_FADT "FACP" /* Fixed ACPI Description Table */ 43 #define ACPI_SIG_FACS "FACS" /* Firmware ACPI Control Structure */ 44 #define ACPI_SIG_PSDT "PSDT" /* Persistent System Description Table */ 45 #define ACPI_SIG_RSDP "RSD PTR " /* Root System Description Pointer */ 46 #define ACPI_SIG_RSDT "RSDT" /* Root System Description Table */ 47 #define ACPI_SIG_XSDT "XSDT" /* Extended System Description Table */ 48 #define ACPI_SIG_SSDT "SSDT" /* Secondary System Description Table */ 49 #define ACPI_RSDP_NAME "RSDP" /* Short name for RSDP, not signature */ 50 #define ACPI_SIG_DMAR "DMAR" /* DMA Remapping table */ 51 52 /* RSDP scan step */ 53 #define ACPI_RSDP_SCAN_STEP 16 54 55 /* RSDP checksums */ 56 57 #define ACPI_RSDP_CHECKSUM_LENGTH 20 58 #define ACPI_RSDP_XCHECKSUM_LENGTH 36 59 60 /* 61 * All tables and structures must be byte-packed to match the ACPI 62 * specification, since the tables are provided by the system BIOS 63 */ 64 #pragma pack(1) 65 66 67 /* 68 * These are the ACPI tables that are directly consumed by the subsystem. 69 * 70 * The RSDP and FACS do not use the common ACPI table header. All other ACPI 71 * tables use the header. 72 * 73 * Note about bitfields: The UINT8 type is used for bitfields in ACPI tables. 74 * This is the only type that is even remotely portable. Anything else is not 75 * portable, so do not use any other bitfield types. 76 */ 77 78 /* 79 * 80 * ACPI Table Header. This common header is used by all tables except the 81 * RSDP and FACS. The define is used for direct inclusion of header into 82 * other ACPI tables 83 * 84 */ 85 86 typedef struct acpi_table_header 87 { 88 char Signature[ACPI_NAME_SIZE]; /* ASCII table signature */ 89 UINT32 Length; /* Length of table in bytes, including this header */ 90 UINT8 Revision; /* ACPI Specification minor version # */ 91 UINT8 Checksum; /* To make sum of entire table == 0 */ 92 char OemId[ACPI_OEM_ID_SIZE]; /* ASCII OEM identification */ 93 char OemTableId[ACPI_OEM_TABLE_ID_SIZE]; /* ASCII OEM table identification */ 94 UINT32 OemRevision; /* OEM revision number */ 95 char AslCompilerId[ACPI_NAME_SIZE]; /* ASCII ASL compiler vendor ID */ 96 UINT32 AslCompilerRevision; /* ASL compiler version */ 97 98 } ACPI_TABLE_HEADER; 99 100 101 /* 102 * GAS - Generic Address Structure (ACPI 2.0+) 103 * 104 * Note: Since this structure is used in the ACPI tables, it is byte aligned. 105 * If misalignment is not supported, access to the Address field must be 106 * performed with care. 107 */ 108 typedef struct acpi_generic_address 109 { 110 UINT8 SpaceId; /* Address space where struct or register exists */ 111 UINT8 BitWidth; /* Size in bits of given register */ 112 UINT8 BitOffset; /* Bit offset within the register */ 113 UINT8 AccessWidth; /* Minimum Access size (ACPI 3.0) */ 114 UINT64 Address; /* 64-bit address of struct or register */ 115 } ACPI_GENERIC_ADDRESS; 116 117 118 /* 119 * RSDP - Root System Description Pointer (Signature is "RSD PTR ") 120 */ 121 122 123 typedef struct acpi_table_rsdp 124 { 125 char Signature[8]; /* ACPI signature, contains "RSD PTR " */ 126 UINT8 Checksum; /* ACPI 1.0 checksum */ 127 char OemId[ACPI_OEM_ID_SIZE]; /* OEM identification */ 128 UINT8 Revision; /* Must be (0) for ACPI 1.0 or (2) for ACPI 2.0+ */ 129 UINT32 RsdtPhysicalAddress; /* 32-bit physical address of the RSDT */ 130 UINT32 Length; /* Table length in bytes, including header (ACPI 2.0+) */ 131 UINT64 XsdtPhysicalAddress; /* 64-bit physical address of the XSDT (ACPI 2.0+) */ 132 UINT8 ExtendedChecksum; /* Checksum of entire table (ACPI 2.0+) */ 133 UINT8 Reserved[3]; /* Reserved, must be zero */ 134 135 } ACPI_TABLE_RSDP; 136 137 /* 138 * FACS - Firmware ACPI Control Structure (FACS) 139 */ 140 141 typedef struct acpi_table_facs 142 { 143 char Signature[4]; /* ASCII table signature */ 144 UINT32 Length; /* Length of structure, in bytes */ 145 UINT32 HardwareSignature; /* Hardware configuration signature */ 146 UINT32 FirmwareWakingVector; /* 32-bit physical address of the Firmware Waking Vector */ 147 UINT32 GlobalLock; /* Global Lock for shared hardware resources */ 148 UINT32 Flags; 149 UINT64 XFirmwareWakingVector; /* 64-bit version of the Firmware Waking Vector (ACPI 2.0+) */ 150 UINT8 Version; /* Version of this table (ACPI 2.0+) */ 151 UINT8 Reserved[31]; /* Reserved, must be zero */ 152 } ACPI_TABLE_FACS; 153 154 155 /* 156 * FADT - Fixed ACPI Description Table (Signature "FACP") 157 */ 158 159 /* Fields common to all versions of the FADT */ 160 161 typedef struct acpi_table_fadt 162 { 163 ACPI_TABLE_HEADER Header; /* Common ACPI table header */ 164 UINT32 Facs; /* 32-bit physical address of FACS */ 165 UINT32 Dsdt; /* 32-bit physical address of DSDT */ 166 UINT8 Model; /* System Interrupt Model (ACPI 1.0) - not used in ACPI 2.0+ */ 167 UINT8 PreferredProfile; /* Conveys preferred power management profile to OSPM. */ 168 UINT16 SciInterrupt; /* System vector of SCI interrupt */ 169 UINT32 SmiCommand; /* 32-bit Port address of SMI command port */ 170 UINT8 AcpiEnable; /* Value to write to smi_cmd to enable ACPI */ 171 UINT8 AcpiDisable; /* Value to write to smi_cmd to disable ACPI */ 172 UINT8 S4BiosRequest; /* Value to write to SMI CMD to enter S4BIOS state */ 173 UINT8 PstateControl; /* Processor performance state control*/ 174 UINT32 Pm1aEventBlock; /* 32-bit Port address of Power Mgt 1a Event Reg Blk */ 175 UINT32 Pm1bEventBlock; /* 32-bit Port address of Power Mgt 1b Event Reg Blk */ 176 UINT32 Pm1aControlBlock; /* 32-bit Port address of Power Mgt 1a Control Reg Blk */ 177 UINT32 Pm1bControlBlock; /* 32-bit Port address of Power Mgt 1b Control Reg Blk */ 178 UINT32 Pm2ControlBlock; /* 32-bit Port address of Power Mgt 2 Control Reg Blk */ 179 UINT32 PmTimerBlock; /* 32-bit Port address of Power Mgt Timer Ctrl Reg Blk */ 180 UINT32 Gpe0Block; /* 32-bit Port address of General Purpose Event 0 Reg Blk */ 181 UINT32 Gpe1Block; /* 32-bit Port address of General Purpose Event 1 Reg Blk */ 182 UINT8 Pm1EventLength; /* Byte Length of ports at Pm1xEventBlock */ 183 UINT8 Pm1ControlLength; /* Byte Length of ports at Pm1xControlBlock */ 184 UINT8 Pm2ControlLength; /* Byte Length of ports at Pm2ControlBlock */ 185 UINT8 PmTimerLength; /* Byte Length of ports at PmTimerBlock */ 186 UINT8 Gpe0BlockLength; /* Byte Length of ports at Gpe0Block */ 187 UINT8 Gpe1BlockLength; /* Byte Length of ports at Gpe1Block */ 188 UINT8 Gpe1Base; /* Offset in GPE number space where GPE1 events start */ 189 UINT8 CstControl; /* Support for the _CST object and C States change notification */ 190 UINT16 C2Latency; /* Worst case HW latency to enter/exit C2 state */ 191 UINT16 C3Latency; /* Worst case HW latency to enter/exit C3 state */ 192 UINT16 FlushSize; /* Processor's memory cache line width, in bytes */ 193 UINT16 FlushStride; /* Number of flush strides that need to be read */ 194 UINT8 DutyOffset; /* Processor duty cycle index in processor's P_CNT reg*/ 195 UINT8 DutyWidth; /* Processor duty cycle value bit width in P_CNT register.*/ 196 UINT8 DayAlarm; /* Index to day-of-month alarm in RTC CMOS RAM */ 197 UINT8 MonthAlarm; /* Index to month-of-year alarm in RTC CMOS RAM */ 198 UINT8 Century; /* Index to century in RTC CMOS RAM */ 199 UINT16 BootFlags; /* IA-PC Boot Architecture Flags. See Table 5-10 for description */ 200 UINT8 Reserved; /* Reserved, must be zero */ 201 UINT32 Flags; /* Miscellaneous flag bits (see below for individual flags) */ 202 ACPI_GENERIC_ADDRESS ResetRegister; /* 64-bit address of the Reset register */ 203 UINT8 ResetValue; /* Value to write to the ResetRegister port to reset the system */ 204 UINT8 Reserved4[3]; /* Reserved, must be zero */ 205 UINT64 XFacs; /* 64-bit physical address of FACS */ 206 UINT64 XDsdt; /* 64-bit physical address of DSDT */ 207 ACPI_GENERIC_ADDRESS XPm1aEventBlock; /* 64-bit Extended Power Mgt 1a Event Reg Blk address */ 208 ACPI_GENERIC_ADDRESS XPm1bEventBlock; /* 64-bit Extended Power Mgt 1b Event Reg Blk address */ 209 ACPI_GENERIC_ADDRESS XPm1aControlBlock; /* 64-bit Extended Power Mgt 1a Control Reg Blk address */ 210 ACPI_GENERIC_ADDRESS XPm1bControlBlock; /* 64-bit Extended Power Mgt 1b Control Reg Blk address */ 211 ACPI_GENERIC_ADDRESS XPm2ControlBlock; /* 64-bit Extended Power Mgt 2 Control Reg Blk address */ 212 ACPI_GENERIC_ADDRESS XPmTimerBlock; /* 64-bit Extended Power Mgt Timer Ctrl Reg Blk address */ 213 ACPI_GENERIC_ADDRESS XGpe0Block; /* 64-bit Extended General Purpose Event 0 Reg Blk address */ 214 ACPI_GENERIC_ADDRESS XGpe1Block; /* 64-bit Extended General Purpose Event 1 Reg Blk address */ 215 216 } ACPI_TABLE_FADT; 217 218 219 /* FADT flags */ 220 221 #define ACPI_FADT_WBINVD (1) /* 00: The wbinvd instruction works properly */ 222 #define ACPI_FADT_WBINVD_FLUSH (1<<1) /* 01: The wbinvd flushes but does not invalidate */ 223 #define ACPI_FADT_C1_SUPPORTED (1<<2) /* 02: All processors support C1 state */ 224 #define ACPI_FADT_C2_MP_SUPPORTED (1<<3) /* 03: C2 state works on MP system */ 225 #define ACPI_FADT_POWER_BUTTON (1<<4) /* 04: Power button is handled as a generic feature */ 226 #define ACPI_FADT_SLEEP_BUTTON (1<<5) /* 05: Sleep button is handled as a generic feature, or not present */ 227 #define ACPI_FADT_FIXED_RTC (1<<6) /* 06: RTC wakeup stat not in fixed register space */ 228 #define ACPI_FADT_S4_RTC_WAKE (1<<7) /* 07: RTC wakeup stat not possible from S4 */ 229 #define ACPI_FADT_32BIT_TIMER (1<<8) /* 08: tmr_val is 32 bits 0=24-bits */ 230 #define ACPI_FADT_DOCKING_SUPPORTED (1<<9) /* 09: Docking supported */ 231 #define ACPI_FADT_RESET_REGISTER (1<<10) /* 10: System reset via the FADT RESET_REG supported */ 232 #define ACPI_FADT_SEALED_CASE (1<<11) /* 11: No internal expansion capabilities and case is sealed */ 233 #define ACPI_FADT_HEADLESS (1<<12) /* 12: No local video capabilities or local input devices */ 234 #define ACPI_FADT_SLEEP_TYPE (1<<13) /* 13: Must execute native instruction after writing SLP_TYPx register */ 235 #define ACPI_FADT_PCI_EXPRESS_WAKE (1<<14) /* 14: System supports PCIEXP_WAKE (STS/EN) bits (ACPI 3.0) */ 236 #define ACPI_FADT_PLATFORM_CLOCK (1<<15) /* 15: OSPM should use platform-provided timer (ACPI 3.0) */ 237 #define ACPI_FADT_S4_RTC_VALID (1<<16) /* 16: Contents of RTC_STS valid after S4 wake (ACPI 3.0) */ 238 #define ACPI_FADT_REMOTE_POWER_ON (1<<17) /* 17: System is compatible with remote power on (ACPI 3.0) */ 239 #define ACPI_FADT_APIC_CLUSTER (1<<18) /* 18: All local APICs must use cluster model (ACPI 3.0) */ 240 #define ACPI_FADT_APIC_PHYSICAL (1<<19) /* 19: All local xAPICs must use physical dest mode (ACPI 3.0) */ 241 242 243 /* Reset to default packing */ 244 245 #pragma pack() 246 247 int vmm_acpi_init(HVA address); 248 ACPI_TABLE_HEADER * vmm_acpi_locate_table(char *sig); 249 UINT16 vmm_acpi_smi_cmd_port(void); 250 UINT8 vmm_acpi_pm_port_size(void); 251 UINT32 vmm_acpi_pm_port_a(void); 252 UINT32 vmm_acpi_pm_port_b(void); 253 unsigned vmm_acpi_sleep_type_to_state(unsigned pm_reg_id, unsigned sleep_type); 254 int vmm_acpi_waking_vector(UINT32 *p_waking_vector, UINT64 *p_extended_waking_vector); 255 256 typedef void (*vmm_acpi_callback)(void); 257 BOOLEAN vmm_acpi_register_platform_suspend_callback(vmm_acpi_callback suspend_cb); 258 BOOLEAN vmm_acpi_register_platform_resume_callback(vmm_acpi_callback resume_cb); 259 260 #endif // _ACPI_H_ 261