2015-11-25 18:01:02 +01:00
|
|
|
/** @file
|
|
|
|
ACPI CPU Data initialization module
|
|
|
|
|
|
|
|
This module initializes the ACPI_CPU_DATA structure and registers the address
|
|
|
|
of this structure in the PcdCpuS3DataAddress PCD. This is a generic/simple
|
|
|
|
version of this module. It does not provide a machine check handler or CPU
|
|
|
|
register initialization tables for ACPI S3 resume. It also only supports the
|
|
|
|
number of CPUs reported by the MP Services Protocol, so this module does not
|
|
|
|
support hot plug CPUs. This module can be copied into a CPU specific package
|
|
|
|
and customized if these additional features are required.
|
|
|
|
|
2017-03-07 07:32:28 +01:00
|
|
|
Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved.<BR>
|
2015-11-25 18:01:02 +01:00
|
|
|
Copyright (c) 2015, Red Hat, Inc.
|
|
|
|
|
2019-04-04 01:07:22 +02:00
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
2015-11-25 18:01:02 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <PiDxe.h>
|
|
|
|
|
|
|
|
#include <AcpiCpuData.h>
|
|
|
|
|
|
|
|
#include <Library/BaseLib.h>
|
|
|
|
#include <Library/BaseMemoryLib.h>
|
|
|
|
#include <Library/UefiBootServicesTableLib.h>
|
|
|
|
#include <Library/DebugLib.h>
|
|
|
|
#include <Library/MtrrLib.h>
|
2018-08-10 04:41:04 +02:00
|
|
|
#include <Library/MemoryAllocationLib.h>
|
2015-11-25 18:01:02 +01:00
|
|
|
|
|
|
|
#include <Protocol/MpService.h>
|
|
|
|
#include <Guid/EventGroup.h>
|
|
|
|
|
|
|
|
//
|
|
|
|
// Data structure used to allocate ACPI_CPU_DATA and its supporting structures
|
|
|
|
//
|
|
|
|
typedef struct {
|
|
|
|
ACPI_CPU_DATA AcpiCpuData;
|
|
|
|
MTRR_SETTINGS MtrrTable;
|
|
|
|
IA32_DESCRIPTOR GdtrProfile;
|
|
|
|
IA32_DESCRIPTOR IdtrProfile;
|
|
|
|
} ACPI_CPU_DATA_EX;
|
|
|
|
|
|
|
|
/**
|
2018-08-10 04:53:45 +02:00
|
|
|
Allocate EfiACPIMemoryNVS memory.
|
2015-11-25 18:01:02 +01:00
|
|
|
|
|
|
|
@param[in] Size Size of memory to allocate.
|
|
|
|
|
|
|
|
@return Allocated address for output.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID *
|
2018-08-10 04:53:45 +02:00
|
|
|
AllocateAcpiNvsMemory (
|
2015-11-25 18:01:02 +01:00
|
|
|
IN UINTN Size
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_PHYSICAL_ADDRESS Address;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
VOID *Buffer;
|
|
|
|
|
|
|
|
Status = gBS->AllocatePages (
|
2018-08-10 04:53:45 +02:00
|
|
|
AllocateAnyPages,
|
2015-11-25 18:01:02 +01:00
|
|
|
EfiACPIMemoryNVS,
|
|
|
|
EFI_SIZE_TO_PAGES (Size),
|
|
|
|
&Address
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Buffer = (VOID *)(UINTN)Address;
|
|
|
|
ZeroMem (Buffer, Size);
|
|
|
|
|
|
|
|
return Buffer;
|
|
|
|
}
|
|
|
|
|
2018-08-10 04:41:04 +02:00
|
|
|
/**
|
|
|
|
Allocate memory and clean it with zero.
|
|
|
|
|
|
|
|
@param[in] Size Size of memory to allocate.
|
|
|
|
|
|
|
|
@return Allocated address for output.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID *
|
|
|
|
AllocateZeroPages (
|
|
|
|
IN UINTN Size
|
|
|
|
)
|
|
|
|
{
|
|
|
|
VOID *Buffer;
|
|
|
|
|
|
|
|
Buffer = AllocatePages (EFI_SIZE_TO_PAGES (Size));
|
|
|
|
if (Buffer != NULL) {
|
|
|
|
ZeroMem (Buffer, Size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Buffer;
|
|
|
|
}
|
2015-11-25 18:01:02 +01:00
|
|
|
/**
|
|
|
|
Callback function executed when the EndOfDxe event group is signaled.
|
|
|
|
|
2016-07-20 16:18:32 +02:00
|
|
|
We delay allocating StartupVector and saving the MTRR settings until BDS signals EndOfDxe.
|
2015-11-25 18:01:02 +01:00
|
|
|
|
|
|
|
@param[in] Event Event whose notification function is being invoked.
|
|
|
|
@param[out] Context Pointer to the MTRR_SETTINGS buffer to fill in.
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
2016-07-20 16:18:32 +02:00
|
|
|
CpuS3DataOnEndOfDxe (
|
2015-11-25 18:01:02 +01:00
|
|
|
IN EFI_EVENT Event,
|
|
|
|
OUT VOID *Context
|
|
|
|
)
|
|
|
|
{
|
2016-07-20 16:18:32 +02:00
|
|
|
EFI_STATUS Status;
|
|
|
|
ACPI_CPU_DATA_EX *AcpiCpuDataEx;
|
|
|
|
|
|
|
|
AcpiCpuDataEx = (ACPI_CPU_DATA_EX *) Context;
|
|
|
|
//
|
|
|
|
// Allocate a 4KB reserved page below 1MB
|
|
|
|
//
|
|
|
|
AcpiCpuDataEx->AcpiCpuData.StartupVector = BASE_1MB - 1;
|
|
|
|
Status = gBS->AllocatePages (
|
|
|
|
AllocateMaxAddress,
|
|
|
|
EfiReservedMemoryType,
|
|
|
|
1,
|
|
|
|
&AcpiCpuDataEx->AcpiCpuData.StartupVector
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
2015-11-25 18:01:02 +01:00
|
|
|
DEBUG ((EFI_D_VERBOSE, "%a\n", __FUNCTION__));
|
2016-07-20 16:18:32 +02:00
|
|
|
MtrrGetAllMtrrs (&AcpiCpuDataEx->MtrrTable);
|
2015-11-25 18:01:02 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Close event, so it will not be invoked again.
|
|
|
|
//
|
|
|
|
gBS->CloseEvent (Event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
The entry function of the CpuS3Data driver.
|
|
|
|
|
|
|
|
Allocate and initialize all fields of the ACPI_CPU_DATA structure except the
|
|
|
|
MTRR settings. Register an event notification on gEfiEndOfDxeEventGroupGuid
|
|
|
|
to capture the ACPI_CPU_DATA MTRR settings. The PcdCpuS3DataAddress is set
|
|
|
|
to the address that ACPI_CPU_DATA is allocated at.
|
|
|
|
|
|
|
|
@param[in] ImageHandle The firmware allocated handle for the EFI image.
|
|
|
|
@param[in] SystemTable A pointer to the EFI System Table.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The entry point is executed successfully.
|
2016-07-18 05:31:28 +02:00
|
|
|
@retval EFI_UNSUPPORTED Do not support ACPI S3.
|
2015-11-25 18:01:02 +01:00
|
|
|
@retval other Some error occurs when executing this entry point.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
CpuS3DataInitialize (
|
|
|
|
IN EFI_HANDLE ImageHandle,
|
|
|
|
IN EFI_SYSTEM_TABLE *SystemTable
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
ACPI_CPU_DATA_EX *AcpiCpuDataEx;
|
|
|
|
ACPI_CPU_DATA *AcpiCpuData;
|
|
|
|
EFI_MP_SERVICES_PROTOCOL *MpServices;
|
|
|
|
UINTN NumberOfCpus;
|
|
|
|
UINTN NumberOfEnabledProcessors;
|
|
|
|
VOID *Stack;
|
|
|
|
UINTN TableSize;
|
|
|
|
CPU_REGISTER_TABLE *RegisterTable;
|
|
|
|
UINTN Index;
|
|
|
|
EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer;
|
|
|
|
UINTN GdtSize;
|
|
|
|
UINTN IdtSize;
|
|
|
|
VOID *Gdt;
|
|
|
|
VOID *Idt;
|
|
|
|
EFI_EVENT Event;
|
2017-03-07 12:39:27 +01:00
|
|
|
ACPI_CPU_DATA *OldAcpiCpuData;
|
2015-11-25 18:01:02 +01:00
|
|
|
|
2016-07-18 05:31:28 +02:00
|
|
|
if (!PcdGetBool (PcdAcpiS3Enable)) {
|
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
2017-03-07 12:39:27 +01:00
|
|
|
//
|
|
|
|
// Set PcdCpuS3DataAddress to the base address of the ACPI_CPU_DATA structure
|
|
|
|
//
|
|
|
|
OldAcpiCpuData = (ACPI_CPU_DATA *) (UINTN) PcdGet64 (PcdCpuS3DataAddress);
|
|
|
|
|
2018-08-10 04:41:04 +02:00
|
|
|
AcpiCpuDataEx = AllocateZeroPages (sizeof (ACPI_CPU_DATA_EX));
|
2015-11-25 18:01:02 +01:00
|
|
|
ASSERT (AcpiCpuDataEx != NULL);
|
|
|
|
AcpiCpuData = &AcpiCpuDataEx->AcpiCpuData;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get MP Services Protocol
|
|
|
|
//
|
|
|
|
Status = gBS->LocateProtocol (
|
|
|
|
&gEfiMpServiceProtocolGuid,
|
|
|
|
NULL,
|
|
|
|
(VOID **)&MpServices
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the number of CPUs
|
|
|
|
//
|
|
|
|
Status = MpServices->GetNumberOfProcessors (
|
|
|
|
MpServices,
|
|
|
|
&NumberOfCpus,
|
|
|
|
&NumberOfEnabledProcessors
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
AcpiCpuData->NumberOfCpus = (UINT32)NumberOfCpus;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Initialize ACPI_CPU_DATA fields
|
|
|
|
//
|
|
|
|
AcpiCpuData->StackSize = PcdGet32 (PcdCpuApStackSize);
|
|
|
|
AcpiCpuData->ApMachineCheckHandlerBase = 0;
|
|
|
|
AcpiCpuData->ApMachineCheckHandlerSize = 0;
|
|
|
|
AcpiCpuData->GdtrProfile = (EFI_PHYSICAL_ADDRESS)(UINTN)&AcpiCpuDataEx->GdtrProfile;
|
|
|
|
AcpiCpuData->IdtrProfile = (EFI_PHYSICAL_ADDRESS)(UINTN)&AcpiCpuDataEx->IdtrProfile;
|
|
|
|
AcpiCpuData->MtrrTable = (EFI_PHYSICAL_ADDRESS)(UINTN)&AcpiCpuDataEx->MtrrTable;
|
|
|
|
|
|
|
|
//
|
2018-08-10 04:53:45 +02:00
|
|
|
// Allocate stack space for all CPUs.
|
|
|
|
// Use ACPI NVS memory type because this data will be directly used by APs
|
|
|
|
// in S3 resume phase in long mode. Also during S3 resume, the stack buffer
|
|
|
|
// will only be used as scratch space. i.e. we won't read anything from it
|
|
|
|
// before we write to it, in PiSmmCpuDxeSmm.
|
2015-11-25 18:01:02 +01:00
|
|
|
//
|
2018-08-10 04:53:45 +02:00
|
|
|
Stack = AllocateAcpiNvsMemory (NumberOfCpus * AcpiCpuData->StackSize);
|
2015-11-25 18:01:02 +01:00
|
|
|
ASSERT (Stack != NULL);
|
|
|
|
AcpiCpuData->StackAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)Stack;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the boot processor's GDT and IDT
|
|
|
|
//
|
|
|
|
AsmReadGdtr (&AcpiCpuDataEx->GdtrProfile);
|
|
|
|
AsmReadIdtr (&AcpiCpuDataEx->IdtrProfile);
|
|
|
|
|
|
|
|
//
|
2018-08-10 04:41:04 +02:00
|
|
|
// Allocate GDT and IDT and copy current GDT and IDT contents
|
2015-11-25 18:01:02 +01:00
|
|
|
//
|
|
|
|
GdtSize = AcpiCpuDataEx->GdtrProfile.Limit + 1;
|
|
|
|
IdtSize = AcpiCpuDataEx->IdtrProfile.Limit + 1;
|
2018-08-10 04:41:04 +02:00
|
|
|
Gdt = AllocateZeroPages (GdtSize + IdtSize);
|
2015-11-25 18:01:02 +01:00
|
|
|
ASSERT (Gdt != NULL);
|
|
|
|
Idt = (VOID *)((UINTN)Gdt + GdtSize);
|
|
|
|
CopyMem (Gdt, (VOID *)AcpiCpuDataEx->GdtrProfile.Base, GdtSize);
|
|
|
|
CopyMem (Idt, (VOID *)AcpiCpuDataEx->IdtrProfile.Base, IdtSize);
|
|
|
|
AcpiCpuDataEx->GdtrProfile.Base = (UINTN)Gdt;
|
|
|
|
AcpiCpuDataEx->IdtrProfile.Base = (UINTN)Idt;
|
|
|
|
|
2017-03-07 12:39:27 +01:00
|
|
|
if (OldAcpiCpuData != NULL) {
|
|
|
|
AcpiCpuData->RegisterTable = OldAcpiCpuData->RegisterTable;
|
|
|
|
AcpiCpuData->PreSmmInitRegisterTable = OldAcpiCpuData->PreSmmInitRegisterTable;
|
2018-10-17 03:01:15 +02:00
|
|
|
AcpiCpuData->ApLocation = OldAcpiCpuData->ApLocation;
|
|
|
|
CopyMem (&AcpiCpuData->CpuStatus, &OldAcpiCpuData->CpuStatus, sizeof (CPU_STATUS_INFORMATION));
|
2017-03-07 12:39:27 +01:00
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// Allocate buffer for empty RegisterTable and PreSmmInitRegisterTable for all CPUs
|
|
|
|
//
|
|
|
|
TableSize = 2 * NumberOfCpus * sizeof (CPU_REGISTER_TABLE);
|
2018-08-10 04:41:04 +02:00
|
|
|
RegisterTable = (CPU_REGISTER_TABLE *)AllocateZeroPages (TableSize);
|
2017-03-07 12:39:27 +01:00
|
|
|
ASSERT (RegisterTable != NULL);
|
|
|
|
|
|
|
|
for (Index = 0; Index < NumberOfCpus; Index++) {
|
|
|
|
Status = MpServices->GetProcessorInfo (
|
2015-11-25 18:01:02 +01:00
|
|
|
MpServices,
|
|
|
|
Index,
|
|
|
|
&ProcessorInfoBuffer
|
|
|
|
);
|
2017-03-07 12:39:27 +01:00
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
RegisterTable[Index].InitialApicId = (UINT32)ProcessorInfoBuffer.ProcessorId;
|
|
|
|
RegisterTable[Index].TableLength = 0;
|
|
|
|
RegisterTable[Index].AllocatedSize = 0;
|
|
|
|
RegisterTable[Index].RegisterTableEntry = 0;
|
|
|
|
|
|
|
|
RegisterTable[NumberOfCpus + Index].InitialApicId = (UINT32)ProcessorInfoBuffer.ProcessorId;
|
|
|
|
RegisterTable[NumberOfCpus + Index].TableLength = 0;
|
|
|
|
RegisterTable[NumberOfCpus + Index].AllocatedSize = 0;
|
|
|
|
RegisterTable[NumberOfCpus + Index].RegisterTableEntry = 0;
|
|
|
|
}
|
|
|
|
AcpiCpuData->RegisterTable = (EFI_PHYSICAL_ADDRESS)(UINTN)RegisterTable;
|
|
|
|
AcpiCpuData->PreSmmInitRegisterTable = (EFI_PHYSICAL_ADDRESS)(UINTN)(RegisterTable + NumberOfCpus);
|
2015-11-25 18:01:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Set PcdCpuS3DataAddress to the base address of the ACPI_CPU_DATA structure
|
|
|
|
//
|
|
|
|
Status = PcdSet64S (PcdCpuS3DataAddress, (UINT64)(UINTN)AcpiCpuData);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Register EFI_END_OF_DXE_EVENT_GROUP_GUID event.
|
2016-07-20 16:18:32 +02:00
|
|
|
// The notification function allocates StartupVector and saves MTRRs for ACPI_CPU_DATA
|
2015-11-25 18:01:02 +01:00
|
|
|
//
|
|
|
|
Status = gBS->CreateEventEx (
|
|
|
|
EVT_NOTIFY_SIGNAL,
|
|
|
|
TPL_CALLBACK,
|
2016-07-20 16:18:32 +02:00
|
|
|
CpuS3DataOnEndOfDxe,
|
|
|
|
AcpiCpuData,
|
2015-11-25 18:01:02 +01:00
|
|
|
&gEfiEndOfDxeEventGroupGuid,
|
|
|
|
&Event
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|