/** Returns a boolean to indicate whether SEV is enabled @retval TRUE SEV is enabled @retval FALSE SEV is not enabled **/ STATIC BOOLEAN EFIAPI InternalMemEncryptSevIsEnabled ( VOID ) { UINT32 RegEax; MSR_SEV_STATUS_REGISTER Msr; CPUID_MEMORY_ENCRYPTION_INFO_EAX Eax; // // Check if memory encryption leaf exist // AsmCpuid (CPUID_EXTENDED_FUNCTION, &RegEax, NULL, NULL, NULL); if (RegEax >= CPUID_MEMORY_ENCRYPTION_INFO) { // // CPUID Fn8000_001F[EAX] Bit 1 (Sev supported) // AsmCpuid (CPUID_MEMORY_ENCRYPTION_INFO, &Eax.Uint32, NULL, NULL, NULL); if (Eax.Bits.SevBit) { // // Check MSR_0xC0010131 Bit 0 (Sev Enabled) // Msr.Uint32 = AsmReadMsr32 (MSR_SEV_STATUS); if (Msr.Bits.SevBit) { return TRUE; } } } return FALSE; }
/** Read from a local APIC register. This function reads from a local APIC register either in xAPIC or x2APIC mode. It is required that in xAPIC mode wider registers (64-bit or 256-bit) must be accessed using multiple 32-bit loads or stores, so this function only performs 32-bit read. @param MmioOffset The MMIO offset of the local APIC register in xAPIC mode. It must be 16-byte aligned. @return 32-bit Value read from the register. **/ UINT32 EFIAPI ReadLocalApicReg ( IN UINTN MmioOffset ) { UINT32 MsrIndex; ASSERT ((MmioOffset & 0xf) == 0); if (GetApicMode () == LOCAL_APIC_MODE_XAPIC) { return MmioRead32 (PcdGet32 (PcdCpuLocalApicBaseAddress) + MmioOffset); } else { // // DFR is not supported in x2APIC mode. // ASSERT (MmioOffset != XAPIC_ICR_DFR_OFFSET); // // Note that in x2APIC mode, ICR is a 64-bit MSR that needs special treatment. It // is not supported in this function for simplicity. // ASSERT (MmioOffset != XAPIC_ICR_HIGH_OFFSET); MsrIndex = (UINT32)(MmioOffset >> 4) + X2APIC_MSR_BASE_ADDRESS; return AsmReadMsr32 (MsrIndex); } }