OvmfPkg: Apply uncrustify changes

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737

Apply uncrustify changes to .c/.h files in the OvmfPkg package

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Andrew Fish <afish@apple.com>
This commit is contained in:
Michael Kubacki
2021-12-05 14:54:09 -08:00
committed by mergify[bot]
parent d1050b9dff
commit ac0a286f4d
445 changed files with 30894 additions and 26369 deletions

View File

@ -11,12 +11,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// //
// The handle onto which the Timer Architectural Protocol will be installed // The handle onto which the Timer Architectural Protocol will be installed
// //
EFI_HANDLE mTimerHandle = NULL; EFI_HANDLE mTimerHandle = NULL;
// //
// The Timer Architectural Protocol that this driver produces // The Timer Architectural Protocol that this driver produces
// //
EFI_TIMER_ARCH_PROTOCOL mTimer = { EFI_TIMER_ARCH_PROTOCOL mTimer = {
TimerDriverRegisterHandler, TimerDriverRegisterHandler,
TimerDriverSetTimerPeriod, TimerDriverSetTimerPeriod,
TimerDriverGetTimerPeriod, TimerDriverGetTimerPeriod,
@ -26,7 +26,7 @@ EFI_TIMER_ARCH_PROTOCOL mTimer = {
// //
// Pointer to the CPU Architectural Protocol instance // Pointer to the CPU Architectural Protocol instance
// //
EFI_CPU_ARCH_PROTOCOL *mCpu; EFI_CPU_ARCH_PROTOCOL *mCpu;
// //
// Pointer to the Legacy 8259 Protocol instance // Pointer to the Legacy 8259 Protocol instance
@ -37,16 +37,17 @@ EFI_LEGACY_8259_PROTOCOL *mLegacy8259;
// The notification function to call on every timer interrupt. // The notification function to call on every timer interrupt.
// A bug in the compiler prevents us from initializing this here. // A bug in the compiler prevents us from initializing this here.
// //
EFI_TIMER_NOTIFY mTimerNotifyFunction; EFI_TIMER_NOTIFY mTimerNotifyFunction;
// //
// The current period of the timer interrupt // The current period of the timer interrupt
// //
volatile UINT64 mTimerPeriod = 0; volatile UINT64 mTimerPeriod = 0;
// //
// Worker Functions // Worker Functions
// //
/** /**
Sets the counter value for Timer #0 in a legacy 8254 timer. Sets the counter value for Timer #0 in a legacy 8254 timer.
@ -71,11 +72,11 @@ SetPitCount (
VOID VOID
EFIAPI EFIAPI
TimerInterruptHandler ( TimerInterruptHandler (
IN EFI_EXCEPTION_TYPE InterruptType, IN EFI_EXCEPTION_TYPE InterruptType,
IN EFI_SYSTEM_CONTEXT SystemContext IN EFI_SYSTEM_CONTEXT SystemContext
) )
{ {
EFI_TPL OriginalTPL; EFI_TPL OriginalTPL;
OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL); OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);
@ -133,11 +134,11 @@ TimerDriverRegisterHandler (
// //
// Check for invalid parameters // Check for invalid parameters
// //
if (NotifyFunction == NULL && mTimerNotifyFunction == NULL) { if ((NotifyFunction == NULL) && (mTimerNotifyFunction == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (NotifyFunction != NULL && mTimerNotifyFunction != NULL) { if ((NotifyFunction != NULL) && (mTimerNotifyFunction != NULL)) {
return EFI_ALREADY_STARTED; return EFI_ALREADY_STARTED;
} }
@ -203,29 +204,30 @@ TimerDriverSetTimerPeriod (
// //
mLegacy8259->DisableIrq (mLegacy8259, Efi8259Irq0); mLegacy8259->DisableIrq (mLegacy8259, Efi8259Irq0);
} else { } else {
// //
// Convert TimerPeriod into 8254 counts // Convert TimerPeriod into 8254 counts
// //
TimerCount = DivU64x32 (MultU64x32 (119318, (UINT32) TimerPeriod) + 500000, 1000000); TimerCount = DivU64x32 (MultU64x32 (119318, (UINT32)TimerPeriod) + 500000, 1000000);
// //
// Check for overflow // Check for overflow
// //
if (TimerCount >= 65536) { if (TimerCount >= 65536) {
TimerCount = 0; TimerCount = 0;
TimerPeriod = MAX_TIMER_TICK_DURATION; TimerPeriod = MAX_TIMER_TICK_DURATION;
} }
// //
// Program the 8254 timer with the new count value // Program the 8254 timer with the new count value
// //
SetPitCount ((UINT16) TimerCount); SetPitCount ((UINT16)TimerCount);
// //
// Enable timer interrupt // Enable timer interrupt
// //
mLegacy8259->EnableIrq (mLegacy8259, Efi8259Irq0, FALSE); mLegacy8259->EnableIrq (mLegacy8259, Efi8259Irq0, FALSE);
} }
// //
// Save the new timer period // Save the new timer period
// //
@ -253,8 +255,8 @@ TimerDriverSetTimerPeriod (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
TimerDriverGetTimerPeriod ( TimerDriverGetTimerPeriod (
IN EFI_TIMER_ARCH_PROTOCOL *This, IN EFI_TIMER_ARCH_PROTOCOL *This,
OUT UINT64 *TimerPeriod OUT UINT64 *TimerPeriod
) )
{ {
if (TimerPeriod == NULL) { if (TimerPeriod == NULL) {
@ -353,13 +355,13 @@ TimerDriverInitialize (
// //
// Find the CPU architectural protocol. // Find the CPU architectural protocol.
// //
Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **) &mCpu); Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&mCpu);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
// //
// Find the Legacy8259 protocol. // Find the Legacy8259 protocol.
// //
Status = gBS->LocateProtocol (&gEfiLegacy8259ProtocolGuid, NULL, (VOID **) &mLegacy8259); Status = gBS->LocateProtocol (&gEfiLegacy8259ProtocolGuid, NULL, (VOID **)&mLegacy8259);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
// //
@ -372,7 +374,7 @@ TimerDriverInitialize (
// Get the interrupt vector number corresponding to IRQ0 from the 8259 driver // Get the interrupt vector number corresponding to IRQ0 from the 8259 driver
// //
TimerVector = 0; TimerVector = 0;
Status = mLegacy8259->GetVector (mLegacy8259, Efi8259Irq0, (UINT8 *) &TimerVector); Status = mLegacy8259->GetVector (mLegacy8259, Efi8259Irq0, (UINT8 *)&TimerVector);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
// //
@ -392,11 +394,11 @@ TimerDriverInitialize (
// //
Status = gBS->InstallMultipleProtocolInterfaces ( Status = gBS->InstallMultipleProtocolInterfaces (
&mTimerHandle, &mTimerHandle,
&gEfiTimerArchProtocolGuid, &mTimer, &gEfiTimerArchProtocolGuid,
&mTimer,
NULL NULL
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return Status; return Status;
} }

View File

@ -32,17 +32,18 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// //
// The maximum tick duration for 8254 timer // The maximum tick duration for 8254 timer
// //
#define MAX_TIMER_TICK_DURATION 549254 #define MAX_TIMER_TICK_DURATION 549254
// //
// The default timer tick duration is set to 10 ms = 100000 100 ns units // The default timer tick duration is set to 10 ms = 100000 100 ns units
// //
#define DEFAULT_TIMER_TICK_DURATION 100000 #define DEFAULT_TIMER_TICK_DURATION 100000
#define TIMER_CONTROL_PORT 0x43 #define TIMER_CONTROL_PORT 0x43
#define TIMER0_COUNT_PORT 0x40 #define TIMER0_COUNT_PORT 0x40
// //
// Function Prototypes // Function Prototypes
// //
/** /**
Initialize the Timer Architectural Protocol driver Initialize the Timer Architectural Protocol driver
@ -153,8 +154,8 @@ TimerDriverSetTimerPeriod (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
TimerDriverGetTimerPeriod ( TimerDriverGetTimerPeriod (
IN EFI_TIMER_ARCH_PROTOCOL *This, IN EFI_TIMER_ARCH_PROTOCOL *This,
OUT UINT64 *TimerPeriod OUT UINT64 *TimerPeriod
) )
; ;

View File

@ -26,15 +26,15 @@ EFI_LEGACY_8259_PROTOCOL mInterrupt8259 = {
// //
// Global for the handle that the Legacy 8259 Protocol is installed // Global for the handle that the Legacy 8259 Protocol is installed
// //
EFI_HANDLE m8259Handle = NULL; EFI_HANDLE m8259Handle = NULL;
UINT8 mMasterBase = 0xff; UINT8 mMasterBase = 0xff;
UINT8 mSlaveBase = 0xff; UINT8 mSlaveBase = 0xff;
EFI_8259_MODE mMode = Efi8259ProtectedMode; EFI_8259_MODE mMode = Efi8259ProtectedMode;
UINT16 mProtectedModeMask = 0xffff; UINT16 mProtectedModeMask = 0xffff;
UINT16 mLegacyModeMask; UINT16 mLegacyModeMask;
UINT16 mProtectedModeEdgeLevel = 0x0000; UINT16 mProtectedModeEdgeLevel = 0x0000;
UINT16 mLegacyModeEdgeLevel; UINT16 mLegacyModeEdgeLevel;
// //
// Worker Functions // Worker Functions
@ -55,10 +55,10 @@ Interrupt8259WriteMask (
IN UINT16 EdgeLevel IN UINT16 EdgeLevel
) )
{ {
IoWrite8 (LEGACY_8259_MASK_REGISTER_MASTER, (UINT8) Mask); IoWrite8 (LEGACY_8259_MASK_REGISTER_MASTER, (UINT8)Mask);
IoWrite8 (LEGACY_8259_MASK_REGISTER_SLAVE, (UINT8) (Mask >> 8)); IoWrite8 (LEGACY_8259_MASK_REGISTER_SLAVE, (UINT8)(Mask >> 8));
IoWrite8 (LEGACY_8259_EDGE_LEVEL_TRIGGERED_REGISTER_MASTER, (UINT8) EdgeLevel); IoWrite8 (LEGACY_8259_EDGE_LEVEL_TRIGGERED_REGISTER_MASTER, (UINT8)EdgeLevel);
IoWrite8 (LEGACY_8259_EDGE_LEVEL_TRIGGERED_REGISTER_SLAVE, (UINT8) (EdgeLevel >> 8)); IoWrite8 (LEGACY_8259_EDGE_LEVEL_TRIGGERED_REGISTER_SLAVE, (UINT8)(EdgeLevel >> 8));
} }
/** /**
@ -83,14 +83,14 @@ Interrupt8259ReadMask (
MasterValue = IoRead8 (LEGACY_8259_MASK_REGISTER_MASTER); MasterValue = IoRead8 (LEGACY_8259_MASK_REGISTER_MASTER);
SlaveValue = IoRead8 (LEGACY_8259_MASK_REGISTER_SLAVE); SlaveValue = IoRead8 (LEGACY_8259_MASK_REGISTER_SLAVE);
*Mask = (UINT16) (MasterValue | (SlaveValue << 8)); *Mask = (UINT16)(MasterValue | (SlaveValue << 8));
} }
if (EdgeLevel != NULL) { if (EdgeLevel != NULL) {
MasterValue = IoRead8 (LEGACY_8259_EDGE_LEVEL_TRIGGERED_REGISTER_MASTER); MasterValue = IoRead8 (LEGACY_8259_EDGE_LEVEL_TRIGGERED_REGISTER_MASTER);
SlaveValue = IoRead8 (LEGACY_8259_EDGE_LEVEL_TRIGGERED_REGISTER_SLAVE); SlaveValue = IoRead8 (LEGACY_8259_EDGE_LEVEL_TRIGGERED_REGISTER_SLAVE);
*EdgeLevel = (UINT16) (MasterValue | (SlaveValue << 8)); *EdgeLevel = (UINT16)(MasterValue | (SlaveValue << 8));
} }
} }
@ -117,8 +117,8 @@ Interrupt8259SetVectorBase (
IN UINT8 SlaveBase IN UINT8 SlaveBase
) )
{ {
UINT8 Mask; UINT8 Mask;
EFI_TPL OriginalTpl; EFI_TPL OriginalTpl;
OriginalTpl = gBS->RaiseTPL (TPL_HIGH_LEVEL); OriginalTpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);
// //
@ -416,9 +416,9 @@ Interrupt8259GetVector (
} }
if (Irq <= Efi8259Irq7) { if (Irq <= Efi8259Irq7) {
*Vector = (UINT8) (mMasterBase + Irq); *Vector = (UINT8)(mMasterBase + Irq);
} else { } else {
*Vector = (UINT8) (mSlaveBase + (Irq - Efi8259Irq8)); *Vector = (UINT8)(mSlaveBase + (Irq - Efi8259Irq8));
} }
return EFI_SUCCESS; return EFI_SUCCESS;
@ -447,11 +447,11 @@ Interrupt8259EnableIrq (
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
mProtectedModeMask = (UINT16) (mProtectedModeMask & ~(1 << Irq)); mProtectedModeMask = (UINT16)(mProtectedModeMask & ~(1 << Irq));
if (LevelTriggered) { if (LevelTriggered) {
mProtectedModeEdgeLevel = (UINT16) (mProtectedModeEdgeLevel | (1 << Irq)); mProtectedModeEdgeLevel = (UINT16)(mProtectedModeEdgeLevel | (1 << Irq));
} else { } else {
mProtectedModeEdgeLevel = (UINT16) (mProtectedModeEdgeLevel & ~(1 << Irq)); mProtectedModeEdgeLevel = (UINT16)(mProtectedModeEdgeLevel & ~(1 << Irq));
} }
Interrupt8259WriteMask (mProtectedModeMask, mProtectedModeEdgeLevel); Interrupt8259WriteMask (mProtectedModeMask, mProtectedModeEdgeLevel);
@ -480,9 +480,9 @@ Interrupt8259DisableIrq (
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
mProtectedModeMask = (UINT16) (mProtectedModeMask | (1 << Irq)); mProtectedModeMask = (UINT16)(mProtectedModeMask | (1 << Irq));
mProtectedModeEdgeLevel = (UINT16) (mProtectedModeEdgeLevel & ~(1 << Irq)); mProtectedModeEdgeLevel = (UINT16)(mProtectedModeEdgeLevel & ~(1 << Irq));
Interrupt8259WriteMask (mProtectedModeMask, mProtectedModeEdgeLevel); Interrupt8259WriteMask (mProtectedModeMask, mProtectedModeEdgeLevel);
@ -507,14 +507,14 @@ Interrupt8259GetInterruptLine (
OUT UINT8 *Vector OUT UINT8 *Vector
) )
{ {
EFI_PCI_IO_PROTOCOL *PciIo; EFI_PCI_IO_PROTOCOL *PciIo;
UINT8 InterruptLine; UINT8 InterruptLine;
EFI_STATUS Status; EFI_STATUS Status;
Status = gBS->HandleProtocol ( Status = gBS->HandleProtocol (
PciHandle, PciHandle,
&gEfiPciIoProtocolGuid, &gEfiPciIoProtocolGuid,
(VOID **) &PciIo (VOID **)&PciIo
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
@ -583,8 +583,8 @@ Install8259 (
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_8259_IRQ Irq; EFI_8259_IRQ Irq;
// //
// Initialze mask values from PCDs // Initialze mask values from PCDs

View File

@ -22,11 +22,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// 8259 Hardware definitions // 8259 Hardware definitions
#define LEGACY_MODE_BASE_VECTOR_MASTER 0x08 #define LEGACY_MODE_BASE_VECTOR_MASTER 0x08
#define LEGACY_MODE_BASE_VECTOR_SLAVE 0x70 #define LEGACY_MODE_BASE_VECTOR_SLAVE 0x70
#define PROTECTED_MODE_BASE_VECTOR_MASTER 0x68 #define PROTECTED_MODE_BASE_VECTOR_MASTER 0x68
#define PROTECTED_MODE_BASE_VECTOR_SLAVE 0x70 #define PROTECTED_MODE_BASE_VECTOR_SLAVE 0x70
#define LEGACY_8259_CONTROL_REGISTER_MASTER 0x20 #define LEGACY_8259_CONTROL_REGISTER_MASTER 0x20
#define LEGACY_8259_MASK_REGISTER_MASTER 0x21 #define LEGACY_8259_MASK_REGISTER_MASTER 0x21
@ -35,7 +35,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#define LEGACY_8259_EDGE_LEVEL_TRIGGERED_REGISTER_MASTER 0x4D0 #define LEGACY_8259_EDGE_LEVEL_TRIGGERED_REGISTER_MASTER 0x4D0
#define LEGACY_8259_EDGE_LEVEL_TRIGGERED_REGISTER_SLAVE 0x4D1 #define LEGACY_8259_EDGE_LEVEL_TRIGGERED_REGISTER_SLAVE 0x4D1
#define LEGACY_8259_EOI 0x20 #define LEGACY_8259_EOI 0x20
// Protocol Function Prototypes // Protocol Function Prototypes

View File

@ -13,8 +13,8 @@
#include <Protocol/PciIo.h> // EFI_PCI_IO_PROTOCOL #include <Protocol/PciIo.h> // EFI_PCI_IO_PROTOCOL
typedef struct { typedef struct {
EFI_PCI_IO_PROTOCOL *PciIo; EFI_PCI_IO_PROTOCOL *PciIo;
UINT64 PciAttributes; UINT64 PciAttributes;
} ORIGINAL_ATTRIBUTES; } ORIGINAL_ATTRIBUTES;
typedef struct S3_CONTEXT S3_CONTEXT; typedef struct S3_CONTEXT S3_CONTEXT;
@ -22,51 +22,50 @@ typedef struct S3_CONTEXT S3_CONTEXT;
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
InstallQemuFwCfgTables ( InstallQemuFwCfgTables (
IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol
); );
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
InstallAcpiTables ( InstallAcpiTables (
IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable
); );
VOID VOID
EnablePciDecoding ( EnablePciDecoding (
OUT ORIGINAL_ATTRIBUTES **OriginalAttributes, OUT ORIGINAL_ATTRIBUTES **OriginalAttributes,
OUT UINTN *Count OUT UINTN *Count
); );
VOID VOID
RestorePciDecoding ( RestorePciDecoding (
IN ORIGINAL_ATTRIBUTES *OriginalAttributes, IN ORIGINAL_ATTRIBUTES *OriginalAttributes,
IN UINTN Count IN UINTN Count
); );
EFI_STATUS EFI_STATUS
AllocateS3Context ( AllocateS3Context (
OUT S3_CONTEXT **S3Context, OUT S3_CONTEXT **S3Context,
IN UINTN WritePointerCount IN UINTN WritePointerCount
); );
VOID VOID
ReleaseS3Context ( ReleaseS3Context (
IN S3_CONTEXT *S3Context IN S3_CONTEXT *S3Context
); );
EFI_STATUS EFI_STATUS
SaveCondensedWritePointerToS3Context ( SaveCondensedWritePointerToS3Context (
IN OUT S3_CONTEXT *S3Context, IN OUT S3_CONTEXT *S3Context,
IN UINT16 PointerItem, IN UINT16 PointerItem,
IN UINT8 PointerSize, IN UINT8 PointerSize,
IN UINT32 PointerOffset, IN UINT32 PointerOffset,
IN UINT64 PointerValue IN UINT64 PointerValue
); );
EFI_STATUS EFI_STATUS
TransferS3ContextToBootScript ( TransferS3ContextToBootScript (
IN S3_CONTEXT *S3Context IN S3_CONTEXT *S3Context
); );
#endif #endif

View File

@ -14,20 +14,18 @@
#include "AcpiPlatform.h" #include "AcpiPlatform.h"
// //
// Condensed structure for capturing the fw_cfg operations -- select, skip, // Condensed structure for capturing the fw_cfg operations -- select, skip,
// write -- inherent in executing a QEMU_LOADER_WRITE_POINTER command. // write -- inherent in executing a QEMU_LOADER_WRITE_POINTER command.
// //
typedef struct { typedef struct {
UINT16 PointerItem; // resolved from QEMU_LOADER_WRITE_POINTER.PointerFile UINT16 PointerItem; // resolved from QEMU_LOADER_WRITE_POINTER.PointerFile
UINT8 PointerSize; // copied as-is from QEMU_LOADER_WRITE_POINTER UINT8 PointerSize; // copied as-is from QEMU_LOADER_WRITE_POINTER
UINT32 PointerOffset; // copied as-is from QEMU_LOADER_WRITE_POINTER UINT32 PointerOffset; // copied as-is from QEMU_LOADER_WRITE_POINTER
UINT64 PointerValue; // resolved from QEMU_LOADER_WRITE_POINTER.PointeeFile UINT64 PointerValue; // resolved from QEMU_LOADER_WRITE_POINTER.PointeeFile
// and QEMU_LOADER_WRITE_POINTER.PointeeOffset // and QEMU_LOADER_WRITE_POINTER.PointeeOffset
} CONDENSED_WRITE_POINTER; } CONDENSED_WRITE_POINTER;
// //
// Context structure to accumulate CONDENSED_WRITE_POINTER objects from // Context structure to accumulate CONDENSED_WRITE_POINTER objects from
// QEMU_LOADER_WRITE_POINTER commands. // QEMU_LOADER_WRITE_POINTER commands.
@ -36,27 +34,25 @@ typedef struct {
// context structure is released, all pointed-to objects must be released too. // context structure is released, all pointed-to objects must be released too.
// //
struct S3_CONTEXT { struct S3_CONTEXT {
CONDENSED_WRITE_POINTER *WritePointers; // one array element per processed CONDENSED_WRITE_POINTER *WritePointers; // one array element per processed
// QEMU_LOADER_WRITE_POINTER // QEMU_LOADER_WRITE_POINTER
// command // command
UINTN Allocated; // number of elements allocated for UINTN Allocated; // number of elements allocated for
// WritePointers // WritePointers
UINTN Used; // number of elements populated in UINTN Used; // number of elements populated in
// WritePointers // WritePointers
}; };
// //
// Scratch buffer, allocated in EfiReservedMemoryType type memory, for the ACPI // Scratch buffer, allocated in EfiReservedMemoryType type memory, for the ACPI
// S3 Boot Script opcodes to work on. // S3 Boot Script opcodes to work on.
// //
#pragma pack (1) #pragma pack (1)
typedef union { typedef union {
UINT64 PointerValue; // filled in from CONDENSED_WRITE_POINTER.PointerValue UINT64 PointerValue; // filled in from CONDENSED_WRITE_POINTER.PointerValue
} SCRATCH_BUFFER; } SCRATCH_BUFFER;
#pragma pack () #pragma pack ()
/** /**
Allocate an S3_CONTEXT object. Allocate an S3_CONTEXT object.
@ -75,12 +71,12 @@ typedef union {
**/ **/
EFI_STATUS EFI_STATUS
AllocateS3Context ( AllocateS3Context (
OUT S3_CONTEXT **S3Context, OUT S3_CONTEXT **S3Context,
IN UINTN WritePointerCount IN UINTN WritePointerCount
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
S3_CONTEXT *Context; S3_CONTEXT *Context;
if (WritePointerCount == 0) { if (WritePointerCount == 0) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
@ -91,15 +87,17 @@ AllocateS3Context (
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
Context->WritePointers = AllocatePool (WritePointerCount * Context->WritePointers = AllocatePool (
sizeof *Context->WritePointers); WritePointerCount *
sizeof *Context->WritePointers
);
if (Context->WritePointers == NULL) { if (Context->WritePointers == NULL) {
Status = EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
goto FreeContext; goto FreeContext;
} }
Context->Allocated = WritePointerCount; Context->Allocated = WritePointerCount;
*S3Context = Context; *S3Context = Context;
return EFI_SUCCESS; return EFI_SUCCESS;
FreeContext: FreeContext:
@ -108,7 +106,6 @@ FreeContext:
return Status; return Status;
} }
/** /**
Release an S3_CONTEXT object. Release an S3_CONTEXT object.
@ -116,14 +113,13 @@ FreeContext:
**/ **/
VOID VOID
ReleaseS3Context ( ReleaseS3Context (
IN S3_CONTEXT *S3Context IN S3_CONTEXT *S3Context
) )
{ {
FreePool (S3Context->WritePointers); FreePool (S3Context->WritePointers);
FreePool (S3Context); FreePool (S3Context);
} }
/** /**
Save the information necessary to replicate a QEMU_LOADER_WRITE_POINTER Save the information necessary to replicate a QEMU_LOADER_WRITE_POINTER
command during S3 resume, in condensed format. command during S3 resume, in condensed format.
@ -158,31 +154,38 @@ ReleaseS3Context (
**/ **/
EFI_STATUS EFI_STATUS
SaveCondensedWritePointerToS3Context ( SaveCondensedWritePointerToS3Context (
IN OUT S3_CONTEXT *S3Context, IN OUT S3_CONTEXT *S3Context,
IN UINT16 PointerItem, IN UINT16 PointerItem,
IN UINT8 PointerSize, IN UINT8 PointerSize,
IN UINT32 PointerOffset, IN UINT32 PointerOffset,
IN UINT64 PointerValue IN UINT64 PointerValue
) )
{ {
CONDENSED_WRITE_POINTER *Condensed; CONDENSED_WRITE_POINTER *Condensed;
if (S3Context->Used == S3Context->Allocated) { if (S3Context->Used == S3Context->Allocated) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
Condensed = S3Context->WritePointers + S3Context->Used;
Condensed = S3Context->WritePointers + S3Context->Used;
Condensed->PointerItem = PointerItem; Condensed->PointerItem = PointerItem;
Condensed->PointerSize = PointerSize; Condensed->PointerSize = PointerSize;
Condensed->PointerOffset = PointerOffset; Condensed->PointerOffset = PointerOffset;
Condensed->PointerValue = PointerValue; Condensed->PointerValue = PointerValue;
DEBUG ((DEBUG_VERBOSE, "%a: 0x%04x/[0x%08x+%d] := 0x%Lx (%Lu)\n", DEBUG ((
__FUNCTION__, PointerItem, PointerOffset, PointerSize, PointerValue, DEBUG_VERBOSE,
(UINT64)S3Context->Used)); "%a: 0x%04x/[0x%08x+%d] := 0x%Lx (%Lu)\n",
__FUNCTION__,
PointerItem,
PointerOffset,
PointerSize,
PointerValue,
(UINT64)S3Context->Used
));
++S3Context->Used; ++S3Context->Used;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION provided to QemuFwCfgS3Lib. FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION provided to QemuFwCfgS3Lib.
**/ **/
@ -190,31 +193,33 @@ STATIC
VOID VOID
EFIAPI EFIAPI
AppendFwCfgBootScript ( AppendFwCfgBootScript (
IN OUT VOID *Context OPTIONAL, IN OUT VOID *Context OPTIONAL,
IN OUT VOID *ExternalScratchBuffer IN OUT VOID *ExternalScratchBuffer
) )
{ {
S3_CONTEXT *S3Context; S3_CONTEXT *S3Context;
SCRATCH_BUFFER *ScratchBuffer; SCRATCH_BUFFER *ScratchBuffer;
UINTN Index; UINTN Index;
S3Context = Context; S3Context = Context;
ScratchBuffer = ExternalScratchBuffer; ScratchBuffer = ExternalScratchBuffer;
for (Index = 0; Index < S3Context->Used; ++Index) { for (Index = 0; Index < S3Context->Used; ++Index) {
CONST CONDENSED_WRITE_POINTER *Condensed; CONST CONDENSED_WRITE_POINTER *Condensed;
RETURN_STATUS Status; RETURN_STATUS Status;
Condensed = &S3Context->WritePointers[Index]; Condensed = &S3Context->WritePointers[Index];
Status = QemuFwCfgS3ScriptSkipBytes (Condensed->PointerItem, Status = QemuFwCfgS3ScriptSkipBytes (
Condensed->PointerOffset); Condensed->PointerItem,
Condensed->PointerOffset
);
if (RETURN_ERROR (Status)) { if (RETURN_ERROR (Status)) {
goto FatalError; goto FatalError;
} }
ScratchBuffer->PointerValue = Condensed->PointerValue; ScratchBuffer->PointerValue = Condensed->PointerValue;
Status = QemuFwCfgS3ScriptWriteBytes (-1, Condensed->PointerSize); Status = QemuFwCfgS3ScriptWriteBytes (-1, Condensed->PointerSize);
if (RETURN_ERROR (Status)) { if (RETURN_ERROR (Status)) {
goto FatalError; goto FatalError;
} }
@ -230,7 +235,6 @@ FatalError:
CpuDeadLoop (); CpuDeadLoop ();
} }
/** /**
Translate and append the information from an S3_CONTEXT object to the ACPI S3 Translate and append the information from an S3_CONTEXT object to the ACPI S3
Boot Script. Boot Script.
@ -253,17 +257,20 @@ FatalError:
**/ **/
EFI_STATUS EFI_STATUS
TransferS3ContextToBootScript ( TransferS3ContextToBootScript (
IN S3_CONTEXT *S3Context IN S3_CONTEXT *S3Context
) )
{ {
RETURN_STATUS Status; RETURN_STATUS Status;
if (S3Context->Used == 0) { if (S3Context->Used == 0) {
ReleaseS3Context (S3Context); ReleaseS3Context (S3Context);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
Status = QemuFwCfgS3CallWhenBootScriptReady (AppendFwCfgBootScript, Status = QemuFwCfgS3CallWhenBootScriptReady (
S3Context, sizeof (SCRATCH_BUFFER)); AppendFwCfgBootScript,
S3Context,
sizeof (SCRATCH_BUFFER)
);
return (EFI_STATUS)Status; return (EFI_STATUS)Status;
} }

View File

@ -21,49 +21,50 @@ FindAcpiTableProtocol (
VOID VOID
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_ACPI_TABLE_PROTOCOL *AcpiTable; EFI_ACPI_TABLE_PROTOCOL *AcpiTable;
Status = gBS->LocateProtocol ( Status = gBS->LocateProtocol (
&gEfiAcpiTableProtocolGuid, &gEfiAcpiTableProtocolGuid,
NULL, NULL,
(VOID**)&AcpiTable (VOID **)&AcpiTable
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return AcpiTable; return AcpiTable;
} }
STATIC STATIC
VOID VOID
EFIAPI EFIAPI
OnRootBridgesConnected ( OnRootBridgesConnected (
IN EFI_EVENT Event, IN EFI_EVENT Event,
IN VOID *Context IN VOID *Context
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
DEBUG ((DEBUG_INFO, DEBUG ((
DEBUG_INFO,
"%a: root bridges have been connected, installing ACPI tables\n", "%a: root bridges have been connected, installing ACPI tables\n",
__FUNCTION__)); __FUNCTION__
));
Status = InstallAcpiTables (FindAcpiTableProtocol ()); Status = InstallAcpiTables (FindAcpiTableProtocol ());
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: InstallAcpiTables: %r\n", __FUNCTION__, Status)); DEBUG ((DEBUG_ERROR, "%a: InstallAcpiTables: %r\n", __FUNCTION__, Status));
} }
gBS->CloseEvent (Event); gBS->CloseEvent (Event);
} }
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
AcpiPlatformEntryPoint ( AcpiPlatformEntryPoint (
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_EVENT RootBridgesConnected; EFI_EVENT RootBridgesConnected;
// //
// If the platform doesn't support PCI, or PCI enumeration has been disabled, // If the platform doesn't support PCI, or PCI enumeration has been disabled,
@ -71,8 +72,12 @@ AcpiPlatformEntryPoint (
// the full functionality. // the full functionality.
// //
if (PcdGetBool (PcdPciDisableBusEnumeration)) { if (PcdGetBool (PcdPciDisableBusEnumeration)) {
DEBUG ((DEBUG_INFO, "%a: PCI or its enumeration disabled, installing " DEBUG ((
"ACPI tables\n", __FUNCTION__)); DEBUG_INFO,
"%a: PCI or its enumeration disabled, installing "
"ACPI tables\n",
__FUNCTION__
));
return InstallAcpiTables (FindAcpiTableProtocol ()); return InstallAcpiTables (FindAcpiTableProtocol ());
} }
@ -82,13 +87,20 @@ AcpiPlatformEntryPoint (
// setup. (Note that we're a DXE_DRIVER; our entry point function is invoked // setup. (Note that we're a DXE_DRIVER; our entry point function is invoked
// strictly before BDS is entered and can connect the root bridges.) // strictly before BDS is entered and can connect the root bridges.)
// //
Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_CALLBACK, Status = gBS->CreateEventEx (
OnRootBridgesConnected, NULL /* Context */, EVT_NOTIFY_SIGNAL,
&gRootBridgesConnectedEventGroupGuid, &RootBridgesConnected); TPL_CALLBACK,
OnRootBridgesConnected,
NULL /* Context */,
&gRootBridgesConnectedEventGroupGuid,
&RootBridgesConnected
);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, DEBUG ((
DEBUG_INFO,
"%a: waiting for root bridges to be connected, registered callback\n", "%a: waiting for root bridges to be connected, registered callback\n",
__FUNCTION__)); __FUNCTION__
));
} }
return Status; return Status;

View File

@ -13,7 +13,6 @@
#include "AcpiPlatform.h" #include "AcpiPlatform.h"
/** /**
Collect all PciIo protocol instances in the system. Save their original Collect all PciIo protocol instances in the system. Save their original
attributes, and enable IO and MMIO decoding for each. attributes, and enable IO and MMIO decoding for each.
@ -40,15 +39,15 @@
**/ **/
VOID VOID
EnablePciDecoding ( EnablePciDecoding (
OUT ORIGINAL_ATTRIBUTES **OriginalAttributes, OUT ORIGINAL_ATTRIBUTES **OriginalAttributes,
OUT UINTN *Count OUT UINTN *Count
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINTN NoHandles; UINTN NoHandles;
EFI_HANDLE *Handles; EFI_HANDLE *Handles;
ORIGINAL_ATTRIBUTES *OrigAttrs; ORIGINAL_ATTRIBUTES *OrigAttrs;
UINTN Idx; UINTN Idx;
*OriginalAttributes = NULL; *OriginalAttributes = NULL;
*Count = 0; *Count = 0;
@ -61,8 +60,13 @@ EnablePciDecoding (
return; return;
} }
Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiPciIoProtocolGuid, Status = gBS->LocateHandleBuffer (
NULL /* SearchKey */, &NoHandles, &Handles); ByProtocol,
&gEfiPciIoProtocolGuid,
NULL /* SearchKey */,
&NoHandles,
&Handles
);
if (Status == EFI_NOT_FOUND) { if (Status == EFI_NOT_FOUND) {
// //
// No PCI devices were found on either of the root bridges. We're done. // No PCI devices were found on either of the root bridges. We're done.
@ -71,49 +75,75 @@ EnablePciDecoding (
} }
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "%a: LocateHandleBuffer(): %r\n", __FUNCTION__, DEBUG ((
Status)); DEBUG_WARN,
"%a: LocateHandleBuffer(): %r\n",
__FUNCTION__,
Status
));
return; return;
} }
OrigAttrs = AllocatePool (NoHandles * sizeof *OrigAttrs); OrigAttrs = AllocatePool (NoHandles * sizeof *OrigAttrs);
if (OrigAttrs == NULL) { if (OrigAttrs == NULL) {
DEBUG ((DEBUG_WARN, "%a: AllocatePool(): out of resources\n", DEBUG ((
__FUNCTION__)); DEBUG_WARN,
"%a: AllocatePool(): out of resources\n",
__FUNCTION__
));
goto FreeHandles; goto FreeHandles;
} }
for (Idx = 0; Idx < NoHandles; ++Idx) { for (Idx = 0; Idx < NoHandles; ++Idx) {
EFI_PCI_IO_PROTOCOL *PciIo; EFI_PCI_IO_PROTOCOL *PciIo;
UINT64 Attributes; UINT64 Attributes;
// //
// Look up PciIo on the handle and stash it // Look up PciIo on the handle and stash it
// //
Status = gBS->HandleProtocol (Handles[Idx], &gEfiPciIoProtocolGuid, Status = gBS->HandleProtocol (
(VOID**)&PciIo); Handles[Idx],
&gEfiPciIoProtocolGuid,
(VOID **)&PciIo
);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
OrigAttrs[Idx].PciIo = PciIo; OrigAttrs[Idx].PciIo = PciIo;
// //
// Stash the current attributes // Stash the current attributes
// //
Status = PciIo->Attributes (PciIo, EfiPciIoAttributeOperationGet, 0, Status = PciIo->Attributes (
&OrigAttrs[Idx].PciAttributes); PciIo,
EfiPciIoAttributeOperationGet,
0,
&OrigAttrs[Idx].PciAttributes
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "%a: EfiPciIoAttributeOperationGet: %r\n", DEBUG ((
__FUNCTION__, Status)); DEBUG_WARN,
"%a: EfiPciIoAttributeOperationGet: %r\n",
__FUNCTION__,
Status
));
goto RestoreAttributes; goto RestoreAttributes;
} }
// //
// Retrieve supported attributes // Retrieve supported attributes
// //
Status = PciIo->Attributes (PciIo, EfiPciIoAttributeOperationSupported, 0, Status = PciIo->Attributes (
&Attributes); PciIo,
EfiPciIoAttributeOperationSupported,
0,
&Attributes
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "%a: EfiPciIoAttributeOperationSupported: %r\n", DEBUG ((
__FUNCTION__, Status)); DEBUG_WARN,
"%a: EfiPciIoAttributeOperationSupported: %r\n",
__FUNCTION__,
Status
));
goto RestoreAttributes; goto RestoreAttributes;
} }
@ -121,11 +151,19 @@ EnablePciDecoding (
// Enable IO and MMIO decoding // Enable IO and MMIO decoding
// //
Attributes &= EFI_PCI_IO_ATTRIBUTE_IO | EFI_PCI_IO_ATTRIBUTE_MEMORY; Attributes &= EFI_PCI_IO_ATTRIBUTE_IO | EFI_PCI_IO_ATTRIBUTE_MEMORY;
Status = PciIo->Attributes (PciIo, EfiPciIoAttributeOperationEnable, Status = PciIo->Attributes (
Attributes, NULL); PciIo,
EfiPciIoAttributeOperationEnable,
Attributes,
NULL
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "%a: EfiPciIoAttributeOperationEnable: %r\n", DEBUG ((
__FUNCTION__, Status)); DEBUG_WARN,
"%a: EfiPciIoAttributeOperationEnable: %r\n",
__FUNCTION__,
Status
));
goto RestoreAttributes; goto RestoreAttributes;
} }
} }
@ -141,19 +179,20 @@ EnablePciDecoding (
RestoreAttributes: RestoreAttributes:
while (Idx > 0) { while (Idx > 0) {
--Idx; --Idx;
OrigAttrs[Idx].PciIo->Attributes (OrigAttrs[Idx].PciIo, OrigAttrs[Idx].PciIo->Attributes (
OrigAttrs[Idx].PciIo,
EfiPciIoAttributeOperationSet, EfiPciIoAttributeOperationSet,
OrigAttrs[Idx].PciAttributes, OrigAttrs[Idx].PciAttributes,
NULL NULL
); );
} }
FreePool (OrigAttrs); FreePool (OrigAttrs);
FreeHandles: FreeHandles:
FreePool (Handles); FreePool (Handles);
} }
/** /**
Restore the original PCI attributes saved with EnablePciDecoding(). Restore the original PCI attributes saved with EnablePciDecoding().
@ -171,11 +210,11 @@ FreeHandles:
**/ **/
VOID VOID
RestorePciDecoding ( RestorePciDecoding (
IN ORIGINAL_ATTRIBUTES *OriginalAttributes, IN ORIGINAL_ATTRIBUTES *OriginalAttributes,
IN UINTN Count IN UINTN Count
) )
{ {
UINTN Idx; UINTN Idx;
ASSERT ((OriginalAttributes == NULL) == (Count == 0)); ASSERT ((OriginalAttributes == NULL) == (Count == 0));
if (OriginalAttributes == NULL) { if (OriginalAttributes == NULL) {
@ -190,5 +229,6 @@ RestorePciDecoding (
NULL NULL
); );
} }
FreePool (OriginalAttributes); FreePool (OriginalAttributes);
} }

File diff suppressed because it is too large Load Diff

View File

@ -23,10 +23,10 @@
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
InstallAcpiTables ( InstallAcpiTables (
IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
Status = InstallQemuFwCfgTables (AcpiTable); Status = InstallQemuFwCfgTables (AcpiTable);
return Status; return Status;

View File

@ -42,25 +42,25 @@
#define SEV_CMDLINE_HASH_GUID \ #define SEV_CMDLINE_HASH_GUID \
(GUID) { 0x97d02dd8, 0xbd20, 0x4c94, { 0xaa, 0x78, 0xe7, 0x71, 0x4d, 0x36, 0xab, 0x2a } } (GUID) { 0x97d02dd8, 0xbd20, 0x4c94, { 0xaa, 0x78, 0xe7, 0x71, 0x4d, 0x36, 0xab, 0x2a } }
STATIC CONST EFI_GUID mSevKernelHashGuid = SEV_KERNEL_HASH_GUID; STATIC CONST EFI_GUID mSevKernelHashGuid = SEV_KERNEL_HASH_GUID;
STATIC CONST EFI_GUID mSevInitrdHashGuid = SEV_INITRD_HASH_GUID; STATIC CONST EFI_GUID mSevInitrdHashGuid = SEV_INITRD_HASH_GUID;
STATIC CONST EFI_GUID mSevCmdlineHashGuid = SEV_CMDLINE_HASH_GUID; STATIC CONST EFI_GUID mSevCmdlineHashGuid = SEV_CMDLINE_HASH_GUID;
#pragma pack (1) #pragma pack (1)
typedef struct { typedef struct {
GUID Guid; GUID Guid;
UINT16 Len; UINT16 Len;
UINT8 Data[]; UINT8 Data[];
} HASH_TABLE; } HASH_TABLE;
#pragma pack () #pragma pack ()
STATIC HASH_TABLE *mHashesTable; STATIC HASH_TABLE *mHashesTable;
STATIC UINT16 mHashesTableSize; STATIC UINT16 mHashesTableSize;
STATIC STATIC
CONST GUID* CONST GUID *
FindBlobEntryGuid ( FindBlobEntryGuid (
IN CONST CHAR16 *BlobName IN CONST CHAR16 *BlobName
) )
{ {
if (StrCmp (BlobName, L"kernel") == 0) { if (StrCmp (BlobName, L"kernel") == 0) {
@ -88,26 +88,32 @@ FindBlobEntryGuid (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
VerifyBlob ( VerifyBlob (
IN CONST CHAR16 *BlobName, IN CONST CHAR16 *BlobName,
IN CONST VOID *Buf, IN CONST VOID *Buf,
IN UINT32 BufSize IN UINT32 BufSize
) )
{ {
CONST GUID *Guid; CONST GUID *Guid;
INT32 Remaining; INT32 Remaining;
HASH_TABLE *Entry; HASH_TABLE *Entry;
if (mHashesTable == NULL || mHashesTableSize == 0) { if ((mHashesTable == NULL) || (mHashesTableSize == 0)) {
DEBUG ((DEBUG_ERROR, DEBUG ((
DEBUG_ERROR,
"%a: Verifier called but no hashes table discoverd in MEMFD\n", "%a: Verifier called but no hashes table discoverd in MEMFD\n",
__FUNCTION__)); __FUNCTION__
));
return EFI_ACCESS_DENIED; return EFI_ACCESS_DENIED;
} }
Guid = FindBlobEntryGuid (BlobName); Guid = FindBlobEntryGuid (BlobName);
if (Guid == NULL) { if (Guid == NULL) {
DEBUG ((DEBUG_ERROR, "%a: Unknown blob name \"%s\"\n", __FUNCTION__, DEBUG ((
BlobName)); DEBUG_ERROR,
"%a: Unknown blob name \"%s\"\n",
__FUNCTION__,
BlobName
));
return EFI_ACCESS_DENIED; return EFI_ACCESS_DENIED;
} }
@ -118,10 +124,11 @@ VerifyBlob (
for (Entry = mHashesTable, Remaining = mHashesTableSize; for (Entry = mHashesTable, Remaining = mHashesTableSize;
Remaining >= sizeof *Entry && Remaining >= Entry->Len; Remaining >= sizeof *Entry && Remaining >= Entry->Len;
Remaining -= Entry->Len, Remaining -= Entry->Len,
Entry = (HASH_TABLE *)((UINT8 *)Entry + Entry->Len)) { Entry = (HASH_TABLE *)((UINT8 *)Entry + Entry->Len))
UINTN EntrySize; {
EFI_STATUS Status; UINTN EntrySize;
UINT8 Hash[SHA256_DIGEST_SIZE]; EFI_STATUS Status;
UINT8 Hash[SHA256_DIGEST_SIZE];
if (!CompareGuid (&Entry->Guid, Guid)) { if (!CompareGuid (&Entry->Guid, Guid)) {
continue; continue;
@ -131,8 +138,13 @@ VerifyBlob (
EntrySize = Entry->Len - sizeof Entry->Guid - sizeof Entry->Len; EntrySize = Entry->Len - sizeof Entry->Guid - sizeof Entry->Len;
if (EntrySize != SHA256_DIGEST_SIZE) { if (EntrySize != SHA256_DIGEST_SIZE) {
DEBUG ((DEBUG_ERROR, "%a: Hash has the wrong size %d != %d\n", DEBUG ((
__FUNCTION__, EntrySize, SHA256_DIGEST_SIZE)); DEBUG_ERROR,
"%a: Hash has the wrong size %d != %d\n",
__FUNCTION__,
EntrySize,
SHA256_DIGEST_SIZE
));
return EFI_ACCESS_DENIED; return EFI_ACCESS_DENIED;
} }
@ -144,18 +156,31 @@ VerifyBlob (
if (CompareMem (Entry->Data, Hash, EntrySize) == 0) { if (CompareMem (Entry->Data, Hash, EntrySize) == 0) {
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
DEBUG ((DEBUG_INFO, "%a: Hash comparison succeeded for \"%s\"\n", DEBUG ((
__FUNCTION__, BlobName)); DEBUG_INFO,
"%a: Hash comparison succeeded for \"%s\"\n",
__FUNCTION__,
BlobName
));
} else { } else {
Status = EFI_ACCESS_DENIED; Status = EFI_ACCESS_DENIED;
DEBUG ((DEBUG_ERROR, "%a: Hash comparison failed for \"%s\"\n", DEBUG ((
__FUNCTION__, BlobName)); DEBUG_ERROR,
"%a: Hash comparison failed for \"%s\"\n",
__FUNCTION__,
BlobName
));
} }
return Status; return Status;
} }
DEBUG ((DEBUG_ERROR, "%a: Hash GUID %g not found in table\n", __FUNCTION__, DEBUG ((
Guid)); DEBUG_ERROR,
"%a: Hash GUID %g not found in table\n",
__FUNCTION__,
Guid
));
return EFI_ACCESS_DENIED; return EFI_ACCESS_DENIED;
} }
@ -174,29 +199,38 @@ BlobVerifierLibSevHashesConstructor (
VOID VOID
) )
{ {
HASH_TABLE *Ptr; HASH_TABLE *Ptr;
UINT32 Size; UINT32 Size;
mHashesTable = NULL; mHashesTable = NULL;
mHashesTableSize = 0; mHashesTableSize = 0;
Ptr = (void *)(UINTN)FixedPcdGet64 (PcdQemuHashTableBase); Ptr = (void *)(UINTN)FixedPcdGet64 (PcdQemuHashTableBase);
Size = FixedPcdGet32 (PcdQemuHashTableSize); Size = FixedPcdGet32 (PcdQemuHashTableSize);
if (Ptr == NULL || Size < sizeof *Ptr || if ((Ptr == NULL) || (Size < sizeof *Ptr) ||
!CompareGuid (&Ptr->Guid, &SEV_HASH_TABLE_GUID) || !CompareGuid (&Ptr->Guid, &SEV_HASH_TABLE_GUID) ||
Ptr->Len < sizeof *Ptr || Ptr->Len > Size) { (Ptr->Len < sizeof *Ptr) || (Ptr->Len > Size))
{
return RETURN_SUCCESS; return RETURN_SUCCESS;
} }
DEBUG ((DEBUG_INFO, "%a: Found injected hashes table in secure location\n", DEBUG ((
__FUNCTION__)); DEBUG_INFO,
"%a: Found injected hashes table in secure location\n",
__FUNCTION__
));
mHashesTable = (HASH_TABLE *)Ptr->Data; mHashesTable = (HASH_TABLE *)Ptr->Data;
mHashesTableSize = Ptr->Len - sizeof Ptr->Guid - sizeof Ptr->Len; mHashesTableSize = Ptr->Len - sizeof Ptr->Guid - sizeof Ptr->Len;
DEBUG ((DEBUG_VERBOSE, "%a: mHashesTable=0x%p, Size=%u\n", __FUNCTION__, DEBUG ((
mHashesTable, mHashesTableSize)); DEBUG_VERBOSE,
"%a: mHashesTable=0x%p, Size=%u\n",
__FUNCTION__,
mHashesTable,
mHashesTableSize
));
return RETURN_SUCCESS; return RETURN_SUCCESS;
} }

View File

@ -8,16 +8,16 @@
#include <Library/UefiBootServicesTableLib.h> #include <Library/UefiBootServicesTableLib.h>
#include <Guid/ConfidentialComputingSecret.h> #include <Guid/ConfidentialComputingSecret.h>
STATIC CONFIDENTIAL_COMPUTING_SECRET_LOCATION mSecretDxeTable = { STATIC CONFIDENTIAL_COMPUTING_SECRET_LOCATION mSecretDxeTable = {
FixedPcdGet32 (PcdSevLaunchSecretBase), FixedPcdGet32 (PcdSevLaunchSecretBase),
FixedPcdGet32 (PcdSevLaunchSecretSize), FixedPcdGet32 (PcdSevLaunchSecretSize),
}; };
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
InitializeSecretDxe( InitializeSecretDxe (
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
return gBS->InstallConfigurationTable ( return gBS->InstallConfigurationTable (

View File

@ -22,8 +22,8 @@
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
AmdSevDxeEntryPoint ( AmdSevDxeEntryPoint (
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -48,11 +48,12 @@ AmdSevDxeEntryPoint (
Status = gDS->GetMemorySpaceMap (&NumEntries, &AllDescMap); Status = gDS->GetMemorySpaceMap (&NumEntries, &AllDescMap);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
for (Index = 0; Index < NumEntries; Index++) { for (Index = 0; Index < NumEntries; Index++) {
CONST EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Desc; CONST EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Desc;
Desc = &AllDescMap[Index]; Desc = &AllDescMap[Index];
if (Desc->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo || if ((Desc->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) ||
Desc->GcdMemoryType == EfiGcdMemoryTypeNonExistent) { (Desc->GcdMemoryType == EfiGcdMemoryTypeNonExistent))
{
Status = MemEncryptSevClearMmioPageEncMask ( Status = MemEncryptSevClearMmioPageEncMask (
0, 0,
Desc->BaseAddress, Desc->BaseAddress,
@ -101,8 +102,8 @@ AmdSevDxeEntryPoint (
// is completed (See OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c). // is completed (See OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c).
// //
if (FeaturePcdGet (PcdSmmSmramRequire)) { if (FeaturePcdGet (PcdSmmSmramRequire)) {
UINTN MapPagesBase; UINTN MapPagesBase;
UINTN MapPagesCount; UINTN MapPagesCount;
Status = MemEncryptSevLocateInitialSmramSaveStateMapPages ( Status = MemEncryptSevLocateInitialSmramSaveStateMapPages (
&MapPagesBase, &MapPagesBase,
@ -123,8 +124,12 @@ AmdSevDxeEntryPoint (
MapPagesCount // NumPages MapPagesCount // NumPages
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: MemEncryptSevClearPageEncMask(): %r\n", DEBUG ((
__FUNCTION__, Status)); DEBUG_ERROR,
"%a: MemEncryptSevClearPageEncMask(): %r\n",
__FUNCTION__,
Status
));
ASSERT (FALSE); ASSERT (FALSE);
CpuDeadLoop (); CpuDeadLoop ();
} }

View File

@ -13,10 +13,10 @@
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
InstallAcpiTable ( InstallAcpiTable (
IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol, IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol,
IN VOID *AcpiTableBuffer, IN VOID *AcpiTableBuffer,
IN UINTN AcpiTableBufferSize, IN UINTN AcpiTableBufferSize,
OUT UINTN *TableKey OUT UINTN *TableKey
) )
{ {
return AcpiProtocol->InstallAcpiTable ( return AcpiProtocol->InstallAcpiTable (
@ -27,7 +27,6 @@ InstallAcpiTable (
); );
} }
/** /**
Locate the first instance of a protocol. If the protocol requested is an Locate the first instance of a protocol. If the protocol requested is an
FV protocol, then it will return the first FV that contains the ACPI table FV protocol, then it will return the first FV that contains the ACPI table
@ -42,18 +41,18 @@ InstallAcpiTable (
**/ **/
EFI_STATUS EFI_STATUS
LocateFvInstanceWithTables ( LocateFvInstanceWithTables (
OUT EFI_FIRMWARE_VOLUME2_PROTOCOL **Instance OUT EFI_FIRMWARE_VOLUME2_PROTOCOL **Instance
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_HANDLE *HandleBuffer; EFI_HANDLE *HandleBuffer;
UINTN NumberOfHandles; UINTN NumberOfHandles;
EFI_FV_FILETYPE FileType; EFI_FV_FILETYPE FileType;
UINT32 FvStatus; UINT32 FvStatus;
EFI_FV_FILE_ATTRIBUTES Attributes; EFI_FV_FILE_ATTRIBUTES Attributes;
UINTN Size; UINTN Size;
UINTN Index; UINTN Index;
EFI_FIRMWARE_VOLUME2_PROTOCOL *FvInstance; EFI_FIRMWARE_VOLUME2_PROTOCOL *FvInstance;
FvStatus = 0; FvStatus = 0;
@ -61,12 +60,12 @@ LocateFvInstanceWithTables (
// Locate protocol. // Locate protocol.
// //
Status = gBS->LocateHandleBuffer ( Status = gBS->LocateHandleBuffer (
ByProtocol, ByProtocol,
&gEfiFirmwareVolume2ProtocolGuid, &gEfiFirmwareVolume2ProtocolGuid,
NULL, NULL,
&NumberOfHandles, &NumberOfHandles,
&HandleBuffer &HandleBuffer
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
// //
// Defined errors at this time are not found and out of resources. // Defined errors at this time are not found and out of resources.
@ -83,10 +82,10 @@ LocateFvInstanceWithTables (
// This should not fail because of LocateHandleBuffer // This should not fail because of LocateHandleBuffer
// //
Status = gBS->HandleProtocol ( Status = gBS->HandleProtocol (
HandleBuffer[Index], HandleBuffer[Index],
&gEfiFirmwareVolume2ProtocolGuid, &gEfiFirmwareVolume2ProtocolGuid,
(VOID**) &FvInstance (VOID **)&FvInstance
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
// //
@ -94,7 +93,7 @@ LocateFvInstanceWithTables (
// //
Status = FvInstance->ReadFile ( Status = FvInstance->ReadFile (
FvInstance, FvInstance,
(EFI_GUID*)PcdGetPtr (PcdAcpiTableStorageFile), (EFI_GUID *)PcdGetPtr (PcdAcpiTableStorageFile),
NULL, NULL,
&Size, &Size,
&FileType, &FileType,
@ -124,7 +123,6 @@ LocateFvInstanceWithTables (
return Status; return Status;
} }
/** /**
Find ACPI tables in an FV and install them. Find ACPI tables in an FV and install them.
@ -140,18 +138,18 @@ LocateFvInstanceWithTables (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
InstallOvmfFvTables ( InstallOvmfFvTables (
IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_FIRMWARE_VOLUME2_PROTOCOL *FwVol; EFI_FIRMWARE_VOLUME2_PROTOCOL *FwVol;
INTN Instance; INTN Instance;
EFI_ACPI_COMMON_HEADER *CurrentTable; EFI_ACPI_COMMON_HEADER *CurrentTable;
UINTN TableHandle; UINTN TableHandle;
UINT32 FvStatus; UINT32 FvStatus;
UINTN TableSize; UINTN TableSize;
UINTN Size; UINTN Size;
EFI_ACPI_TABLE_INSTALL_ACPI_TABLE TableInstallFunction; EFI_ACPI_TABLE_INSTALL_ACPI_TABLE TableInstallFunction;
Instance = 0; Instance = 0;
CurrentTable = NULL; CurrentTable = NULL;
@ -171,19 +169,19 @@ InstallOvmfFvTables (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_ABORTED; return EFI_ABORTED;
} }
ASSERT (FwVol != NULL); ASSERT (FwVol != NULL);
// //
// Read tables from the storage file. // Read tables from the storage file.
// //
while (Status == EFI_SUCCESS) { while (Status == EFI_SUCCESS) {
Status = FwVol->ReadSection ( Status = FwVol->ReadSection (
FwVol, FwVol,
(EFI_GUID*)PcdGetPtr (PcdAcpiTableStorageFile), (EFI_GUID *)PcdGetPtr (PcdAcpiTableStorageFile),
EFI_SECTION_RAW, EFI_SECTION_RAW,
Instance, Instance,
(VOID**) &CurrentTable, (VOID **)&CurrentTable,
&Size, &Size,
&FvStatus &FvStatus
); );
@ -193,7 +191,7 @@ InstallOvmfFvTables (
// //
TableHandle = 0; TableHandle = 0;
TableSize = ((EFI_ACPI_DESCRIPTION_HEADER *) CurrentTable)->Length; TableSize = ((EFI_ACPI_DESCRIPTION_HEADER *)CurrentTable)->Length;
ASSERT (Size >= TableSize); ASSERT (Size >= TableSize);
// //
@ -240,13 +238,12 @@ InstallOvmfFvTables (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
InstallAcpiTables ( InstallAcpiTables (
IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
Status = InstallOvmfFvTables (AcpiTable); Status = InstallOvmfFvTables (AcpiTable);
return Status; return Status;
} }

View File

@ -22,8 +22,8 @@
#include <IndustryStandard/Acpi.h> #include <IndustryStandard/Acpi.h>
typedef struct { typedef struct {
EFI_PCI_IO_PROTOCOL *PciIo; EFI_PCI_IO_PROTOCOL *PciIo;
UINT64 PciAttributes; UINT64 PciAttributes;
} ORIGINAL_ATTRIBUTES; } ORIGINAL_ATTRIBUTES;
typedef struct S3_CONTEXT S3_CONTEXT; typedef struct S3_CONTEXT S3_CONTEXT;
@ -31,43 +31,43 @@ typedef struct S3_CONTEXT S3_CONTEXT;
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
InstallAcpiTable ( InstallAcpiTable (
IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol, IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol,
IN VOID *AcpiTableBuffer, IN VOID *AcpiTableBuffer,
IN UINTN AcpiTableBufferSize, IN UINTN AcpiTableBufferSize,
OUT UINTN *TableKey OUT UINTN *TableKey
); );
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
BhyveInstallAcpiTable( BhyveInstallAcpiTable (
IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol, IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol,
IN VOID *AcpiTableBuffer, IN VOID *AcpiTableBuffer,
IN UINTN AcpiTableBufferSize, IN UINTN AcpiTableBufferSize,
OUT UINTN *TableKey OUT UINTN *TableKey
); );
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
InstallXenTables ( InstallXenTables (
IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol
); );
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
InstallAcpiTables ( InstallAcpiTables (
IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable
); );
VOID VOID
EnablePciDecoding ( EnablePciDecoding (
OUT ORIGINAL_ATTRIBUTES **OriginalAttributes, OUT ORIGINAL_ATTRIBUTES **OriginalAttributes,
OUT UINTN *Count OUT UINTN *Count
); );
VOID VOID
RestorePciDecoding ( RestorePciDecoding (
IN ORIGINAL_ATTRIBUTES *OriginalAttributes, IN ORIGINAL_ATTRIBUTES *OriginalAttributes,
IN UINTN Count IN UINTN Count
); );
#endif /* _ACPI_PLATFORM_H_INCLUDED_ */ #endif /* _ACPI_PLATFORM_H_INCLUDED_ */

View File

@ -16,28 +16,28 @@ STATIC
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
BhyveInstallAcpiMadtTable ( BhyveInstallAcpiMadtTable (
IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol, IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol,
IN VOID *AcpiTableBuffer, IN VOID *AcpiTableBuffer,
IN UINTN AcpiTableBufferSize, IN UINTN AcpiTableBufferSize,
OUT UINTN *TableKey OUT UINTN *TableKey
) )
{ {
UINT32 CpuCount; UINT32 CpuCount;
UINTN cSize; UINTN cSize;
UINTN NewBufferSize; UINTN NewBufferSize;
EFI_ACPI_1_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER *Madt; EFI_ACPI_1_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER *Madt;
EFI_ACPI_1_0_PROCESSOR_LOCAL_APIC_STRUCTURE *LocalApic; EFI_ACPI_1_0_PROCESSOR_LOCAL_APIC_STRUCTURE *LocalApic;
EFI_ACPI_1_0_IO_APIC_STRUCTURE *IoApic; EFI_ACPI_1_0_IO_APIC_STRUCTURE *IoApic;
EFI_ACPI_1_0_INTERRUPT_SOURCE_OVERRIDE_STRUCTURE *Iso; EFI_ACPI_1_0_INTERRUPT_SOURCE_OVERRIDE_STRUCTURE *Iso;
VOID *Ptr; VOID *Ptr;
UINTN Loop; UINTN Loop;
EFI_STATUS Status; EFI_STATUS Status;
ASSERT (AcpiTableBufferSize >= sizeof (EFI_ACPI_DESCRIPTION_HEADER)); ASSERT (AcpiTableBufferSize >= sizeof (EFI_ACPI_DESCRIPTION_HEADER));
// Query the host for the number of vCPUs // Query the host for the number of vCPUs
CpuCount = 0; CpuCount = 0;
cSize = sizeof(CpuCount); cSize = sizeof (CpuCount);
if (BhyveFwCtlGet ("hw.ncpu", &CpuCount, &cSize) == RETURN_SUCCESS) { if (BhyveFwCtlGet ("hw.ncpu", &CpuCount, &cSize) == RETURN_SUCCESS) {
DEBUG ((DEBUG_INFO, "Retrieved CpuCount %d\n", CpuCount)); DEBUG ((DEBUG_INFO, "Retrieved CpuCount %d\n", CpuCount));
ASSERT (CpuCount >= 1); ASSERT (CpuCount >= 1);
@ -57,44 +57,45 @@ BhyveInstallAcpiMadtTable (
} }
CopyMem (&(Madt->Header), AcpiTableBuffer, sizeof (EFI_ACPI_DESCRIPTION_HEADER)); CopyMem (&(Madt->Header), AcpiTableBuffer, sizeof (EFI_ACPI_DESCRIPTION_HEADER));
Madt->Header.Length = (UINT32) NewBufferSize; Madt->Header.Length = (UINT32)NewBufferSize;
Madt->LocalApicAddress = 0xFEE00000; Madt->LocalApicAddress = 0xFEE00000;
Madt->Flags = EFI_ACPI_1_0_PCAT_COMPAT; Madt->Flags = EFI_ACPI_1_0_PCAT_COMPAT;
Ptr = Madt + 1; Ptr = Madt + 1;
LocalApic = Ptr; LocalApic = Ptr;
for (Loop = 0; Loop < CpuCount; ++Loop) { for (Loop = 0; Loop < CpuCount; ++Loop) {
LocalApic->Type = EFI_ACPI_1_0_PROCESSOR_LOCAL_APIC; LocalApic->Type = EFI_ACPI_1_0_PROCESSOR_LOCAL_APIC;
LocalApic->Length = sizeof (*LocalApic); LocalApic->Length = sizeof (*LocalApic);
LocalApic->AcpiProcessorId = (UINT8) Loop; LocalApic->AcpiProcessorId = (UINT8)Loop;
LocalApic->ApicId = (UINT8) Loop; LocalApic->ApicId = (UINT8)Loop;
LocalApic->Flags = 1; // enabled LocalApic->Flags = 1; // enabled
++LocalApic; ++LocalApic;
} }
Ptr = LocalApic; Ptr = LocalApic;
IoApic = Ptr; IoApic = Ptr;
IoApic->Type = EFI_ACPI_1_0_IO_APIC; IoApic->Type = EFI_ACPI_1_0_IO_APIC;
IoApic->Length = sizeof (*IoApic); IoApic->Length = sizeof (*IoApic);
IoApic->IoApicId = (UINT8) CpuCount; IoApic->IoApicId = (UINT8)CpuCount;
IoApic->Reserved = EFI_ACPI_RESERVED_BYTE; IoApic->Reserved = EFI_ACPI_RESERVED_BYTE;
IoApic->IoApicAddress = 0xFEC00000; IoApic->IoApicAddress = 0xFEC00000;
IoApic->SystemVectorBase = 0x00000000; IoApic->SystemVectorBase = 0x00000000;
Ptr = IoApic + 1; Ptr = IoApic + 1;
// //
// IRQ0 (8254 Timer) => IRQ2 (PIC) Interrupt Source Override Structure // IRQ0 (8254 Timer) => IRQ2 (PIC) Interrupt Source Override Structure
// //
Iso = Ptr; Iso = Ptr;
Iso->Type = EFI_ACPI_1_0_INTERRUPT_SOURCE_OVERRIDE; Iso->Type = EFI_ACPI_1_0_INTERRUPT_SOURCE_OVERRIDE;
Iso->Length = sizeof (*Iso); Iso->Length = sizeof (*Iso);
Iso->Bus = 0x00; // ISA Iso->Bus = 0x00; // ISA
Iso->Source = 0x00; // IRQ0 Iso->Source = 0x00; // IRQ0
Iso->GlobalSystemInterruptVector = 0x00000002; Iso->GlobalSystemInterruptVector = 0x00000002;
Iso->Flags = 0x0000; // Conforms to specs of the bus Iso->Flags = 0x0000; // Conforms to specs of the bus
Ptr = Iso + 1; Ptr = Iso + 1;
ASSERT ((UINTN) ((UINT8 *)Ptr - (UINT8 *)Madt) == NewBufferSize); ASSERT ((UINTN)((UINT8 *)Ptr - (UINT8 *)Madt) == NewBufferSize);
Status = InstallAcpiTable (AcpiProtocol, Madt, NewBufferSize, TableKey); Status = InstallAcpiTable (AcpiProtocol, Madt, NewBufferSize, TableKey);
FreePool (Madt); FreePool (Madt);
@ -105,22 +106,22 @@ BhyveInstallAcpiMadtTable (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
BhyveInstallAcpiTable ( BhyveInstallAcpiTable (
IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol, IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol,
IN VOID *AcpiTableBuffer, IN VOID *AcpiTableBuffer,
IN UINTN AcpiTableBufferSize, IN UINTN AcpiTableBufferSize,
OUT UINTN *TableKey OUT UINTN *TableKey
) )
{ {
EFI_ACPI_DESCRIPTION_HEADER *Hdr; EFI_ACPI_DESCRIPTION_HEADER *Hdr;
EFI_ACPI_TABLE_INSTALL_ACPI_TABLE TableInstallFunction; EFI_ACPI_TABLE_INSTALL_ACPI_TABLE TableInstallFunction;
Hdr = (EFI_ACPI_DESCRIPTION_HEADER*) AcpiTableBuffer; Hdr = (EFI_ACPI_DESCRIPTION_HEADER *)AcpiTableBuffer;
switch (Hdr->Signature) { switch (Hdr->Signature) {
case EFI_ACPI_1_0_APIC_SIGNATURE: case EFI_ACPI_1_0_APIC_SIGNATURE:
TableInstallFunction = BhyveInstallAcpiMadtTable; TableInstallFunction = BhyveInstallAcpiMadtTable;
break; break;
default: default:
TableInstallFunction = InstallAcpiTable; TableInstallFunction = InstallAcpiTable;
} }
return TableInstallFunction ( return TableInstallFunction (

View File

@ -16,49 +16,50 @@ FindAcpiTableProtocol (
VOID VOID
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_ACPI_TABLE_PROTOCOL *AcpiTable; EFI_ACPI_TABLE_PROTOCOL *AcpiTable;
Status = gBS->LocateProtocol ( Status = gBS->LocateProtocol (
&gEfiAcpiTableProtocolGuid, &gEfiAcpiTableProtocolGuid,
NULL, NULL,
(VOID**)&AcpiTable (VOID **)&AcpiTable
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return AcpiTable; return AcpiTable;
} }
STATIC STATIC
VOID VOID
EFIAPI EFIAPI
OnRootBridgesConnected ( OnRootBridgesConnected (
IN EFI_EVENT Event, IN EFI_EVENT Event,
IN VOID *Context IN VOID *Context
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
DEBUG ((DEBUG_INFO, DEBUG ((
DEBUG_INFO,
"%a: root bridges have been connected, installing ACPI tables\n", "%a: root bridges have been connected, installing ACPI tables\n",
__FUNCTION__)); __FUNCTION__
));
Status = InstallAcpiTables (FindAcpiTableProtocol ()); Status = InstallAcpiTables (FindAcpiTableProtocol ());
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: InstallAcpiTables: %r\n", __FUNCTION__, Status)); DEBUG ((DEBUG_ERROR, "%a: InstallAcpiTables: %r\n", __FUNCTION__, Status));
} }
gBS->CloseEvent (Event); gBS->CloseEvent (Event);
} }
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
AcpiPlatformEntryPoint ( AcpiPlatformEntryPoint (
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_EVENT RootBridgesConnected; EFI_EVENT RootBridgesConnected;
// //
// If the platform doesn't support PCI, or PCI enumeration has been disabled, // If the platform doesn't support PCI, or PCI enumeration has been disabled,
@ -66,8 +67,12 @@ AcpiPlatformEntryPoint (
// the full functionality. // the full functionality.
// //
if (PcdGetBool (PcdPciDisableBusEnumeration)) { if (PcdGetBool (PcdPciDisableBusEnumeration)) {
DEBUG ((DEBUG_INFO, "%a: PCI or its enumeration disabled, installing " DEBUG ((
"ACPI tables\n", __FUNCTION__)); DEBUG_INFO,
"%a: PCI or its enumeration disabled, installing "
"ACPI tables\n",
__FUNCTION__
));
return InstallAcpiTables (FindAcpiTableProtocol ()); return InstallAcpiTables (FindAcpiTableProtocol ());
} }
@ -77,13 +82,20 @@ AcpiPlatformEntryPoint (
// setup. (Note that we're a DXE_DRIVER; our entry point function is invoked // setup. (Note that we're a DXE_DRIVER; our entry point function is invoked
// strictly before BDS is entered and can connect the root bridges.) // strictly before BDS is entered and can connect the root bridges.)
// //
Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_CALLBACK, Status = gBS->CreateEventEx (
OnRootBridgesConnected, NULL /* Context */, EVT_NOTIFY_SIGNAL,
&gRootBridgesConnectedEventGroupGuid, &RootBridgesConnected); TPL_CALLBACK,
OnRootBridgesConnected,
NULL /* Context */,
&gRootBridgesConnectedEventGroupGuid,
&RootBridgesConnected
);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, DEBUG ((
DEBUG_INFO,
"%a: waiting for root bridges to be connected, registered callback\n", "%a: waiting for root bridges to be connected, registered callback\n",
__FUNCTION__)); __FUNCTION__
));
} }
return Status; return Status;

View File

@ -11,7 +11,6 @@
#include "AcpiPlatform.h" #include "AcpiPlatform.h"
/** /**
Collect all PciIo protocol instances in the system. Save their original Collect all PciIo protocol instances in the system. Save their original
attributes, and enable IO and MMIO decoding for each. attributes, and enable IO and MMIO decoding for each.
@ -38,15 +37,15 @@
**/ **/
VOID VOID
EnablePciDecoding ( EnablePciDecoding (
OUT ORIGINAL_ATTRIBUTES **OriginalAttributes, OUT ORIGINAL_ATTRIBUTES **OriginalAttributes,
OUT UINTN *Count OUT UINTN *Count
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINTN NoHandles; UINTN NoHandles;
EFI_HANDLE *Handles; EFI_HANDLE *Handles;
ORIGINAL_ATTRIBUTES *OrigAttrs; ORIGINAL_ATTRIBUTES *OrigAttrs;
UINTN Idx; UINTN Idx;
*OriginalAttributes = NULL; *OriginalAttributes = NULL;
*Count = 0; *Count = 0;
@ -59,8 +58,13 @@ EnablePciDecoding (
return; return;
} }
Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiPciIoProtocolGuid, Status = gBS->LocateHandleBuffer (
NULL /* SearchKey */, &NoHandles, &Handles); ByProtocol,
&gEfiPciIoProtocolGuid,
NULL /* SearchKey */,
&NoHandles,
&Handles
);
if (Status == EFI_NOT_FOUND) { if (Status == EFI_NOT_FOUND) {
// //
// No PCI devices were found on either of the root bridges. We're done. // No PCI devices were found on either of the root bridges. We're done.
@ -69,49 +73,75 @@ EnablePciDecoding (
} }
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "%a: LocateHandleBuffer(): %r\n", __FUNCTION__, DEBUG ((
Status)); DEBUG_WARN,
"%a: LocateHandleBuffer(): %r\n",
__FUNCTION__,
Status
));
return; return;
} }
OrigAttrs = AllocatePool (NoHandles * sizeof *OrigAttrs); OrigAttrs = AllocatePool (NoHandles * sizeof *OrigAttrs);
if (OrigAttrs == NULL) { if (OrigAttrs == NULL) {
DEBUG ((DEBUG_WARN, "%a: AllocatePool(): out of resources\n", DEBUG ((
__FUNCTION__)); DEBUG_WARN,
"%a: AllocatePool(): out of resources\n",
__FUNCTION__
));
goto FreeHandles; goto FreeHandles;
} }
for (Idx = 0; Idx < NoHandles; ++Idx) { for (Idx = 0; Idx < NoHandles; ++Idx) {
EFI_PCI_IO_PROTOCOL *PciIo; EFI_PCI_IO_PROTOCOL *PciIo;
UINT64 Attributes; UINT64 Attributes;
// //
// Look up PciIo on the handle and stash it // Look up PciIo on the handle and stash it
// //
Status = gBS->HandleProtocol (Handles[Idx], &gEfiPciIoProtocolGuid, Status = gBS->HandleProtocol (
(VOID**)&PciIo); Handles[Idx],
&gEfiPciIoProtocolGuid,
(VOID **)&PciIo
);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
OrigAttrs[Idx].PciIo = PciIo; OrigAttrs[Idx].PciIo = PciIo;
// //
// Stash the current attributes // Stash the current attributes
// //
Status = PciIo->Attributes (PciIo, EfiPciIoAttributeOperationGet, 0, Status = PciIo->Attributes (
&OrigAttrs[Idx].PciAttributes); PciIo,
EfiPciIoAttributeOperationGet,
0,
&OrigAttrs[Idx].PciAttributes
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "%a: EfiPciIoAttributeOperationGet: %r\n", DEBUG ((
__FUNCTION__, Status)); DEBUG_WARN,
"%a: EfiPciIoAttributeOperationGet: %r\n",
__FUNCTION__,
Status
));
goto RestoreAttributes; goto RestoreAttributes;
} }
// //
// Retrieve supported attributes // Retrieve supported attributes
// //
Status = PciIo->Attributes (PciIo, EfiPciIoAttributeOperationSupported, 0, Status = PciIo->Attributes (
&Attributes); PciIo,
EfiPciIoAttributeOperationSupported,
0,
&Attributes
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "%a: EfiPciIoAttributeOperationSupported: %r\n", DEBUG ((
__FUNCTION__, Status)); DEBUG_WARN,
"%a: EfiPciIoAttributeOperationSupported: %r\n",
__FUNCTION__,
Status
));
goto RestoreAttributes; goto RestoreAttributes;
} }
@ -119,11 +149,19 @@ EnablePciDecoding (
// Enable IO and MMIO decoding // Enable IO and MMIO decoding
// //
Attributes &= EFI_PCI_IO_ATTRIBUTE_IO | EFI_PCI_IO_ATTRIBUTE_MEMORY; Attributes &= EFI_PCI_IO_ATTRIBUTE_IO | EFI_PCI_IO_ATTRIBUTE_MEMORY;
Status = PciIo->Attributes (PciIo, EfiPciIoAttributeOperationEnable, Status = PciIo->Attributes (
Attributes, NULL); PciIo,
EfiPciIoAttributeOperationEnable,
Attributes,
NULL
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "%a: EfiPciIoAttributeOperationEnable: %r\n", DEBUG ((
__FUNCTION__, Status)); DEBUG_WARN,
"%a: EfiPciIoAttributeOperationEnable: %r\n",
__FUNCTION__,
Status
));
goto RestoreAttributes; goto RestoreAttributes;
} }
} }
@ -139,19 +177,20 @@ EnablePciDecoding (
RestoreAttributes: RestoreAttributes:
while (Idx > 0) { while (Idx > 0) {
--Idx; --Idx;
OrigAttrs[Idx].PciIo->Attributes (OrigAttrs[Idx].PciIo, OrigAttrs[Idx].PciIo->Attributes (
OrigAttrs[Idx].PciIo,
EfiPciIoAttributeOperationSet, EfiPciIoAttributeOperationSet,
OrigAttrs[Idx].PciAttributes, OrigAttrs[Idx].PciAttributes,
NULL NULL
); );
} }
FreePool (OrigAttrs); FreePool (OrigAttrs);
FreeHandles: FreeHandles:
FreePool (Handles); FreePool (Handles);
} }
/** /**
Restore the original PCI attributes saved with EnablePciDecoding(). Restore the original PCI attributes saved with EnablePciDecoding().
@ -169,11 +208,11 @@ FreeHandles:
**/ **/
VOID VOID
RestorePciDecoding ( RestorePciDecoding (
IN ORIGINAL_ATTRIBUTES *OriginalAttributes, IN ORIGINAL_ATTRIBUTES *OriginalAttributes,
IN UINTN Count IN UINTN Count
) )
{ {
UINTN Idx; UINTN Idx;
ASSERT ((OriginalAttributes == NULL) == (Count == 0)); ASSERT ((OriginalAttributes == NULL) == (Count == 0));
if (OriginalAttributes == NULL) { if (OriginalAttributes == NULL) {
@ -188,5 +227,6 @@ RestorePciDecoding (
NULL NULL
); );
} }
FreePool (OriginalAttributes); FreePool (OriginalAttributes);
} }

View File

@ -20,53 +20,53 @@
// //
// ACPI table information used to initialize tables. // ACPI table information used to initialize tables.
// //
#define EFI_ACPI_OEM_ID 'B','H','Y','V','E',' ' // OEMID 6 bytes long #define EFI_ACPI_OEM_ID 'B','H','Y','V','E',' ' // OEMID 6 bytes long
#define EFI_ACPI_OEM_REVISION 0x1 #define EFI_ACPI_OEM_REVISION 0x1
#define EFI_ACPI_CREATOR_ID SIGNATURE_32('B','H','Y','V') #define EFI_ACPI_CREATOR_ID SIGNATURE_32('B','H','Y','V')
#define EFI_ACPI_CREATOR_REVISION 0x00000001 #define EFI_ACPI_CREATOR_REVISION 0x00000001
#define INT_MODEL 0x01 #define INT_MODEL 0x01
#define SCI_INT_VECTOR 0x0009 #define SCI_INT_VECTOR 0x0009
#define SMI_CMD_IO_PORT 0xB2 #define SMI_CMD_IO_PORT 0xB2
#define ACPI_ENABLE 0xA0 #define ACPI_ENABLE 0xA0
#define ACPI_DISABLE 0xA1 #define ACPI_DISABLE 0xA1
#define S4BIOS_REQ 0x00 #define S4BIOS_REQ 0x00
#define PM1a_EVT_BLK 0x00000400 /* TNXXX */ #define PM1a_EVT_BLK 0x00000400 /* TNXXX */
#define PM1b_EVT_BLK 0x00000000 #define PM1b_EVT_BLK 0x00000000
#define PM1a_CNT_BLK 0x00000404 /* TNXXX */ #define PM1a_CNT_BLK 0x00000404 /* TNXXX */
#define PM1b_CNT_BLK 0x00000000 #define PM1b_CNT_BLK 0x00000000
#define PM2_CNT_BLK 0x00000000 #define PM2_CNT_BLK 0x00000000
#define PM_TMR_BLK 0x00000408 #define PM_TMR_BLK 0x00000408
#define GPE0_BLK 0x00000000 #define GPE0_BLK 0x00000000
#define GPE1_BLK 0x00000000 #define GPE1_BLK 0x00000000
#define PM1_EVT_LEN 0x04 #define PM1_EVT_LEN 0x04
#define PM1_CNT_LEN 0x02 #define PM1_CNT_LEN 0x02
#define PM2_CNT_LEN 0x00 #define PM2_CNT_LEN 0x00
#define PM_TM_LEN 0x04 #define PM_TM_LEN 0x04
#define GPE0_BLK_LEN 0x00 #define GPE0_BLK_LEN 0x00
#define GPE1_BLK_LEN 0x00 #define GPE1_BLK_LEN 0x00
#define GPE1_BASE 0x00 #define GPE1_BASE 0x00
#define RESERVED 0x00 #define RESERVED 0x00
#define P_LVL2_LAT 0x0000 #define P_LVL2_LAT 0x0000
#define P_LVL3_LAT 0x0000 #define P_LVL3_LAT 0x0000
#define FLUSH_SIZE 0x0000 #define FLUSH_SIZE 0x0000
#define FLUSH_STRIDE 0x0000 #define FLUSH_STRIDE 0x0000
#define DUTY_OFFSET 0x00 #define DUTY_OFFSET 0x00
#define DUTY_WIDTH 0x00 #define DUTY_WIDTH 0x00
#define DAY_ALRM 0x00 #define DAY_ALRM 0x00
#define MON_ALRM 0x00 #define MON_ALRM 0x00
#define CENTURY 0x32 #define CENTURY 0x32
#define IAPC_BOOT_ARCH 0x12 /* 8042 present, disable PCIe ASPM */ #define IAPC_BOOT_ARCH 0x12 /* 8042 present, disable PCIe ASPM */
#define FACP_FLAGS (EFI_ACPI_1_0_WBINVD | EFI_ACPI_1_0_PROC_C1 | \ #define FACP_FLAGS (EFI_ACPI_1_0_WBINVD | EFI_ACPI_1_0_PROC_C1 | \
EFI_ACPI_1_0_SLP_BUTTON | EFI_ACPI_1_0_TMR_VAL_EXT | \ EFI_ACPI_1_0_SLP_BUTTON | EFI_ACPI_1_0_TMR_VAL_EXT | \
EFI_ACPI_2_0_RESET_REG_SUP | \ EFI_ACPI_2_0_RESET_REG_SUP | \
EFI_ACPI_3_0_FORCE_APIC_PHYSICAL_DESTINATION_MODE) EFI_ACPI_3_0_FORCE_APIC_PHYSICAL_DESTINATION_MODE)
#define FACP_RESET_REG { \ #define FACP_RESET_REG { \
EFI_ACPI_3_0_SYSTEM_IO, /* Address Space ID */ \ EFI_ACPI_3_0_SYSTEM_IO, /* Address Space ID */ \
8, /* Bit Width */ \ 8, /* Bit Width */ \
0, /* Bit Offset */ \ 0, /* Bit Offset */ \
EFI_ACPI_3_0_BYTE, /* Byte Access */ \ EFI_ACPI_3_0_BYTE, /* Byte Access */ \
0xCF9 /* I/O Port */ \ 0xCF9 /* I/O Port */ \
} }
#define FACP_RESET_VAL 0x6 #define FACP_RESET_VAL 0x6
#endif #endif

View File

@ -30,17 +30,17 @@ EmuGopComponentNameGetDriverName (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
EmuGopComponentNameGetControllerName ( EmuGopComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL, IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language, IN CHAR8 *Language,
OUT CHAR16 **ControllerName OUT CHAR16 **ControllerName
); );
// //
// EFI Component Name Protocol // EFI Component Name Protocol
// //
EFI_COMPONENT_NAME_PROTOCOL gEmuGopComponentName = { EFI_COMPONENT_NAME_PROTOCOL gEmuGopComponentName = {
EmuGopComponentNameGetDriverName, EmuGopComponentNameGetDriverName,
EmuGopComponentNameGetControllerName, EmuGopComponentNameGetControllerName,
"eng" "eng"
@ -49,19 +49,17 @@ EFI_COMPONENT_NAME_PROTOCOL gEmuGopComponentName = {
// //
// EFI Component Name 2 Protocol // EFI Component Name 2 Protocol
// //
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gEmuGopComponentName2 = { GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gEmuGopComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) EmuGopComponentNameGetDriverName, (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)EmuGopComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) EmuGopComponentNameGetControllerName, (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)EmuGopComponentNameGetControllerName,
"en" "en"
}; };
EFI_UNICODE_STRING_TABLE mEmuGopDriverNameTable[] = {
EFI_UNICODE_STRING_TABLE mEmuGopDriverNameTable[] = {
{ "eng", L"Emulator GOP Driver" }, { "eng", L"Emulator GOP Driver" },
{ NULL , NULL } { NULL, NULL }
}; };
/** /**
Retrieves a Unicode string that is the user readable name of the driver. Retrieves a Unicode string that is the user readable name of the driver.
@ -118,7 +116,6 @@ EmuGopComponentNameGetDriverName (
); );
} }
/** /**
Retrieves a Unicode string that is the user readable name of the controller Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver. that is being managed by a driver.
@ -190,11 +187,11 @@ EmuGopComponentNameGetDriverName (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
EmuGopComponentNameGetControllerName ( EmuGopComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL, IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language, IN CHAR8 *Language,
OUT CHAR16 **ControllerName OUT CHAR16 **ControllerName
) )
{ {
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;

View File

@ -31,27 +31,27 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <IndustryStandard/Pci.h> #include <IndustryStandard/Pci.h>
#define GRAPHICS_OUTPUT_INVALID_MODE_NUMBER 0xffff #define GRAPHICS_OUTPUT_INVALID_MODE_NUMBER 0xffff
typedef struct { typedef struct {
UINT32 HorizontalResolution; UINT32 HorizontalResolution;
UINT32 VerticalResolution; UINT32 VerticalResolution;
UINT32 ColorDepth; UINT32 ColorDepth;
UINT32 RefreshRate; UINT32 RefreshRate;
} GOP_MODE_DATA; } GOP_MODE_DATA;
#define PIXEL_RED_SHIFT 0 #define PIXEL_RED_SHIFT 0
#define PIXEL_GREEN_SHIFT 3 #define PIXEL_GREEN_SHIFT 3
#define PIXEL_BLUE_SHIFT 6 #define PIXEL_BLUE_SHIFT 6
#define PIXEL_RED_MASK (BIT7 | BIT6 | BIT5) #define PIXEL_RED_MASK (BIT7 | BIT6 | BIT5)
#define PIXEL_GREEN_MASK (BIT4 | BIT3 | BIT2) #define PIXEL_GREEN_MASK (BIT4 | BIT3 | BIT2)
#define PIXEL_BLUE_MASK (BIT1 | BIT0) #define PIXEL_BLUE_MASK (BIT1 | BIT0)
#define PIXEL_TO_COLOR_BYTE(pixel, mask, shift) ((UINT8) ((pixel & mask) << shift)) #define PIXEL_TO_COLOR_BYTE(pixel, mask, shift) ((UINT8) ((pixel & mask) << shift))
#define PIXEL_TO_RED_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_RED_MASK, PIXEL_RED_SHIFT) #define PIXEL_TO_RED_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_RED_MASK, PIXEL_RED_SHIFT)
#define PIXEL_TO_GREEN_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_GREEN_MASK, PIXEL_GREEN_SHIFT) #define PIXEL_TO_GREEN_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_GREEN_MASK, PIXEL_GREEN_SHIFT)
#define PIXEL_TO_BLUE_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_BLUE_MASK, PIXEL_BLUE_SHIFT) #define PIXEL_TO_BLUE_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_BLUE_MASK, PIXEL_BLUE_SHIFT)
#define RGB_BYTES_TO_PIXEL(Red, Green, Blue) \ #define RGB_BYTES_TO_PIXEL(Red, Green, Blue) \
(UINT8) ( (((Red) >> PIXEL_RED_SHIFT) & PIXEL_RED_MASK) | \ (UINT8) ( (((Red) >> PIXEL_RED_SHIFT) & PIXEL_RED_MASK) | \
@ -62,61 +62,60 @@ typedef struct {
#define PIXEL24_GREEN_MASK 0x0000ff00 #define PIXEL24_GREEN_MASK 0x0000ff00
#define PIXEL24_BLUE_MASK 0x000000ff #define PIXEL24_BLUE_MASK 0x000000ff
extern EFI_DRIVER_BINDING_PROTOCOL gEmuGopDriverBinding; extern EFI_DRIVER_BINDING_PROTOCOL gEmuGopDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gEmuGopComponentName; extern EFI_COMPONENT_NAME_PROTOCOL gEmuGopComponentName;
#define EMU_UGA_CLASS_NAME L"EmuGopWindow" #define EMU_UGA_CLASS_NAME L"EmuGopWindow"
#define GOP_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('G', 'o', 'p', 'N') #define GOP_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('G', 'o', 'p', 'N')
typedef struct { typedef struct {
UINT64 Signature; UINT64 Signature;
EFI_HANDLE Handle; EFI_HANDLE Handle;
EFI_PCI_IO_PROTOCOL *PciIo; EFI_PCI_IO_PROTOCOL *PciIo;
EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput; EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput;
EFI_DEVICE_PATH_PROTOCOL *GopDevicePath; EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;
EFI_UNICODE_STRING_TABLE *ControllerNameTable; EFI_UNICODE_STRING_TABLE *ControllerNameTable;
// //
// GOP Private Data for QueryMode () // GOP Private Data for QueryMode ()
// //
GOP_MODE_DATA *ModeData; GOP_MODE_DATA *ModeData;
UINT64 FbAddr; UINT64 FbAddr;
UINT32 FbSize; UINT32 FbSize;
} GOP_PRIVATE_DATA; } GOP_PRIVATE_DATA;
#define GOP_PRIVATE_DATA_FROM_THIS(a) \ #define GOP_PRIVATE_DATA_FROM_THIS(a) \
CR(a, GOP_PRIVATE_DATA, GraphicsOutput, GOP_PRIVATE_DATA_SIGNATURE) CR(a, GOP_PRIVATE_DATA, GraphicsOutput, GOP_PRIVATE_DATA_SIGNATURE)
typedef struct { typedef struct {
UINT32 FbSize; UINT32 FbSize;
UINT16 Width; UINT16 Width;
UINT16 Height; UINT16 Height;
UINT16 Depth; UINT16 Depth;
UINT16 RefreshRate; UINT16 RefreshRate;
} BHYVE_FBUF_MEMREGS; } BHYVE_FBUF_MEMREGS;
// //
// Global Protocol Variables // Global Protocol Variables
// //
extern EFI_DRIVER_BINDING_PROTOCOL gEmuGopDriverBinding; extern EFI_DRIVER_BINDING_PROTOCOL gEmuGopDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gEmuGopComponentName; extern EFI_COMPONENT_NAME_PROTOCOL gEmuGopComponentName;
extern EFI_COMPONENT_NAME2_PROTOCOL gEmuGopComponentName2; extern EFI_COMPONENT_NAME2_PROTOCOL gEmuGopComponentName2;
// //
// Gop Hardware abstraction internal worker functions // Gop Hardware abstraction internal worker functions
// //
EFI_STATUS EFI_STATUS
EmuGopConstructor ( EmuGopConstructor (
IN GOP_PRIVATE_DATA *Private IN GOP_PRIVATE_DATA *Private
); );
EFI_STATUS EFI_STATUS
EmuGopDestructor ( EmuGopDestructor (
IN GOP_PRIVATE_DATA *Private IN GOP_PRIVATE_DATA *Private
); );
VOID VOID
@ -129,21 +128,21 @@ ShutdownGopEvent (
VOID VOID
BhyveSetGraphicsMode ( BhyveSetGraphicsMode (
GOP_PRIVATE_DATA *Private, GOP_PRIVATE_DATA *Private,
UINT16 Width, UINT16 Width,
UINT16 Height, UINT16 Height,
UINT16 Depth UINT16 Depth
); );
VOID VOID
BhyveGetMemregs ( BhyveGetMemregs (
GOP_PRIVATE_DATA *Private, GOP_PRIVATE_DATA *Private,
BHYVE_FBUF_MEMREGS *Memregs BHYVE_FBUF_MEMREGS *Memregs
); );
VOID VOID
InstallVbeShim ( InstallVbeShim (
IN CONST CHAR16 *CardName, IN CONST CHAR16 *CardName,
IN EFI_PHYSICAL_ADDRESS FrameBufferBase IN EFI_PHYSICAL_ADDRESS FrameBufferBase
); );
#endif /* _GOP_H_ */ #endif /* _GOP_H_ */

View File

@ -13,13 +13,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
STATIC VOID STATIC VOID
BhyveGetGraphicsMode ( BhyveGetGraphicsMode (
EFI_PCI_IO_PROTOCOL *PciIo, EFI_PCI_IO_PROTOCOL *PciIo,
UINT16 *Width, UINT16 *Width,
UINT16 *Height, UINT16 *Height,
UINT16 *Depth UINT16 *Depth
); );
/** /**
Tests to see if this driver supports a given controller. If a child device is provided, Tests to see if this driver supports a given controller. If a child device is provided,
it further tests to see if this driver supports creating a handle for the specified child device. it further tests to see if this driver supports creating a handle for the specified child device.
@ -65,15 +64,15 @@ BhyveGetGraphicsMode (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
EmuGopDriverBindingSupported ( EmuGopDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Handle, IN EFI_HANDLE Handle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_PCI_IO_PROTOCOL *PciIo; EFI_PCI_IO_PROTOCOL *PciIo;
PCI_TYPE00 Pci; PCI_TYPE00 Pci;
UINT16 Width, Height, Depth; UINT16 Width, Height, Depth;
// //
// Open the IO Abstraction(s) needed to perform the supported test // Open the IO Abstraction(s) needed to perform the supported test
@ -81,7 +80,7 @@ EmuGopDriverBindingSupported (
Status = gBS->OpenProtocol ( Status = gBS->OpenProtocol (
Handle, Handle,
&gEfiPciIoProtocolGuid, &gEfiPciIoProtocolGuid,
(VOID **) &PciIo, (VOID **)&PciIo,
This->DriverBindingHandle, This->DriverBindingHandle,
Handle, Handle,
EFI_OPEN_PROTOCOL_BY_DRIVER EFI_OPEN_PROTOCOL_BY_DRIVER
@ -107,11 +106,11 @@ EmuGopDriverBindingSupported (
} }
Status = EFI_UNSUPPORTED; Status = EFI_UNSUPPORTED;
if (Pci.Hdr.VendorId == 0xFB5D && Pci.Hdr.DeviceId == 0x40FB) { if ((Pci.Hdr.VendorId == 0xFB5D) && (Pci.Hdr.DeviceId == 0x40FB)) {
DEBUG((DEBUG_INFO, "BHYVE framebuffer device detected\n")); DEBUG ((DEBUG_INFO, "BHYVE framebuffer device detected\n"));
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
BhyveGetGraphicsMode(PciIo, &Width, &Height, &Depth); BhyveGetGraphicsMode (PciIo, &Width, &Height, &Depth);
PcdSet32S (PcdVideoHorizontalResolution, Width); PcdSet32S (PcdVideoHorizontalResolution, Width);
PcdSet32S (PcdVideoVerticalResolution, Height); PcdSet32S (PcdVideoVerticalResolution, Height);
} }
@ -121,16 +120,15 @@ Done:
// Close the PCI I/O Protocol // Close the PCI I/O Protocol
// //
gBS->CloseProtocol ( gBS->CloseProtocol (
Handle, Handle,
&gEfiPciIoProtocolGuid, &gEfiPciIoProtocolGuid,
This->DriverBindingHandle, This->DriverBindingHandle,
Handle Handle
); );
return Status; return Status;
} }
/** /**
Starts a device controller or a bus controller. Starts a device controller or a bus controller.
@ -169,25 +167,25 @@ Done:
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
EmuGopDriverBindingStart ( EmuGopDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Handle, IN EFI_HANDLE Handle,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
) )
{ {
BHYVE_FBUF_MEMREGS Memregs; BHYVE_FBUF_MEMREGS Memregs;
GOP_PRIVATE_DATA *Private; GOP_PRIVATE_DATA *Private;
EFI_STATUS Status; EFI_STATUS Status;
EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *MmioDesc; EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *MmioDesc;
// //
// Allocate Private context data for SGO inteface. // Allocate Private context data for SGO inteface.
// //
Private = NULL; Private = NULL;
Status = gBS->AllocatePool ( Status = gBS->AllocatePool (
EfiBootServicesData, EfiBootServicesData,
sizeof (GOP_PRIVATE_DATA), sizeof (GOP_PRIVATE_DATA),
(VOID **)&Private (VOID **)&Private
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto Done; goto Done;
} }
@ -204,7 +202,7 @@ EmuGopDriverBindingStart (
Status = gBS->OpenProtocol ( Status = gBS->OpenProtocol (
Handle, Handle,
&gEfiPciIoProtocolGuid, &gEfiPciIoProtocolGuid,
(VOID **) &Private->PciIo, (VOID **)&Private->PciIo,
This->DriverBindingHandle, This->DriverBindingHandle,
Handle, Handle,
EFI_OPEN_PROTOCOL_BY_DRIVER EFI_OPEN_PROTOCOL_BY_DRIVER
@ -217,24 +215,30 @@ EmuGopDriverBindingStart (
// Check if fbuf mmio BAR is present // Check if fbuf mmio BAR is present
// //
MmioDesc = NULL; MmioDesc = NULL;
Status = Private->PciIo->GetBarAttributes ( Status = Private->PciIo->GetBarAttributes (
Private->PciIo, Private->PciIo,
PCI_BAR_IDX0, PCI_BAR_IDX0,
NULL, NULL,
(VOID**) &MmioDesc (VOID **)&MmioDesc
); );
if (EFI_ERROR (Status) || if (EFI_ERROR (Status) ||
MmioDesc->ResType != ACPI_ADDRESS_SPACE_TYPE_MEM) { (MmioDesc->ResType != ACPI_ADDRESS_SPACE_TYPE_MEM))
{
DEBUG ((DEBUG_INFO, "BHYVE GOP: No mmio bar\n")); DEBUG ((DEBUG_INFO, "BHYVE GOP: No mmio bar\n"));
} else { } else {
DEBUG ((DEBUG_INFO, "BHYVE GOP: Using mmio bar @ 0x%lx\n", DEBUG ((
MmioDesc->AddrRangeMin)); DEBUG_INFO,
BhyveGetMemregs(Private, &Memregs); "BHYVE GOP: Using mmio bar @ 0x%lx\n",
MmioDesc->AddrRangeMin
));
BhyveGetMemregs (Private, &Memregs);
Private->FbSize = Memregs.FbSize; Private->FbSize = Memregs.FbSize;
} }
if (MmioDesc != NULL) { if (MmioDesc != NULL) {
FreePool (MmioDesc); FreePool (MmioDesc);
} }
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto Done; goto Done;
} }
@ -243,18 +247,22 @@ EmuGopDriverBindingStart (
// Check if fbuf frame-buffer BAR is present // Check if fbuf frame-buffer BAR is present
// //
MmioDesc = NULL; MmioDesc = NULL;
Status = Private->PciIo->GetBarAttributes ( Status = Private->PciIo->GetBarAttributes (
Private->PciIo, Private->PciIo,
PCI_BAR_IDX1, PCI_BAR_IDX1,
NULL, NULL,
(VOID**) &MmioDesc (VOID **)&MmioDesc
); );
if (EFI_ERROR (Status) || if (EFI_ERROR (Status) ||
MmioDesc->ResType != ACPI_ADDRESS_SPACE_TYPE_MEM) { (MmioDesc->ResType != ACPI_ADDRESS_SPACE_TYPE_MEM))
{
DEBUG ((DEBUG_INFO, "BHYVE GOP: No frame-buffer bar\n")); DEBUG ((DEBUG_INFO, "BHYVE GOP: No frame-buffer bar\n"));
} else { } else {
DEBUG ((DEBUG_INFO, "BHYVE GOP: Using frame-buffer bar @ 0x%lx\n", DEBUG ((
MmioDesc->AddrRangeMin)); DEBUG_INFO,
"BHYVE GOP: Using frame-buffer bar @ 0x%lx\n",
MmioDesc->AddrRangeMin
));
Private->FbAddr = MmioDesc->AddrRangeMin; Private->FbAddr = MmioDesc->AddrRangeMin;
// XXX assert BAR is >= size // XXX assert BAR is >= size
} }
@ -262,12 +270,17 @@ EmuGopDriverBindingStart (
if (MmioDesc != NULL) { if (MmioDesc != NULL) {
FreePool (MmioDesc); FreePool (MmioDesc);
} }
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto Done; goto Done;
} }
DEBUG ((DEBUG_INFO, "BHYVE GOP: Framebuf addr 0x%lx, size %x\n", DEBUG ((
Private->FbAddr, Private->FbSize)); DEBUG_INFO,
"BHYVE GOP: Framebuf addr 0x%lx, size %x\n",
Private->FbAddr,
Private->FbSize
));
Status = EmuGopConstructor (Private); Status = EmuGopConstructor (Private);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
@ -279,18 +292,19 @@ EmuGopDriverBindingStart (
// //
Status = gBS->InstallMultipleProtocolInterfaces ( Status = gBS->InstallMultipleProtocolInterfaces (
&Private->Handle, &Private->Handle,
&gEfiGraphicsOutputProtocolGuid, &Private->GraphicsOutput, &gEfiGraphicsOutputProtocolGuid,
&Private->GraphicsOutput,
NULL NULL
); );
DEBUG((DEBUG_INFO, "BHYVE framebuffer device started\n")); DEBUG ((DEBUG_INFO, "BHYVE framebuffer device started\n"));
// //
// Install int10 handler // Install int10 handler
// //
#ifndef CSM_ENABLE #ifndef CSM_ENABLE
InstallVbeShim (L"Framebuffer", Private->FbAddr); InstallVbeShim (L"Framebuffer", Private->FbAddr);
#endif #endif
Done: Done:
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
@ -309,8 +323,6 @@ Done:
return Status; return Status;
} }
/** /**
Stops a device controller or a bus controller. Stops a device controller or a bus controller.
@ -346,11 +358,11 @@ EmuGopDriverBindingStop (
IN EFI_HANDLE *ChildHandleBuffer IN EFI_HANDLE *ChildHandleBuffer
) )
{ {
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
EFI_STATUS Status; EFI_STATUS Status;
GOP_PRIVATE_DATA *Private; GOP_PRIVATE_DATA *Private;
DEBUG((DEBUG_INFO, "BHYVE framebuffer device stopping\n")); DEBUG ((DEBUG_INFO, "BHYVE framebuffer device stopping\n"));
Status = gBS->OpenProtocol ( Status = gBS->OpenProtocol (
Handle, Handle,
@ -377,7 +389,8 @@ EmuGopDriverBindingStop (
// //
Status = gBS->UninstallMultipleProtocolInterfaces ( Status = gBS->UninstallMultipleProtocolInterfaces (
Private->Handle, Private->Handle,
&gEfiGraphicsOutputProtocolGuid, &Private->GraphicsOutput, &gEfiGraphicsOutputProtocolGuid,
&Private->GraphicsOutput,
NULL NULL
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
@ -390,11 +403,11 @@ EmuGopDriverBindingStop (
} }
gBS->CloseProtocol ( gBS->CloseProtocol (
Handle, Handle,
&gEfiPciIoProtocolGuid, &gEfiPciIoProtocolGuid,
This->DriverBindingHandle, This->DriverBindingHandle,
Private->Handle Private->Handle
); );
// //
// Free our instance data // Free our instance data
@ -402,18 +415,16 @@ EmuGopDriverBindingStop (
FreeUnicodeStringTable (Private->ControllerNameTable); FreeUnicodeStringTable (Private->ControllerNameTable);
gBS->FreePool (Private); gBS->FreePool (Private);
} }
return Status; return Status;
} }
/// ///
/// This protocol provides the services required to determine if a driver supports a given controller. /// This protocol provides the services required to determine if a driver supports a given controller.
/// If a controller is supported, then it also provides routines to start and stop the controller. /// If a controller is supported, then it also provides routines to start and stop the controller.
/// ///
EFI_DRIVER_BINDING_PROTOCOL gEmuGopDriverBinding = { EFI_DRIVER_BINDING_PROTOCOL gEmuGopDriverBinding = {
EmuGopDriverBindingSupported, EmuGopDriverBindingSupported,
EmuGopDriverBindingStart, EmuGopDriverBindingStart,
EmuGopDriverBindingStop, EmuGopDriverBindingStop,
@ -422,8 +433,6 @@ EFI_DRIVER_BINDING_PROTOCOL gEmuGopDriverBinding = {
NULL NULL
}; };
/** /**
The user Entry Point for module EmuGop. The user code starts with this function. The user Entry Point for module EmuGop. The user code starts with this function.
@ -437,11 +446,11 @@ EFI_DRIVER_BINDING_PROTOCOL gEmuGopDriverBinding = {
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
InitializeEmuGop ( InitializeEmuGop (
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
Status = EfiLibInstallDriverBindingComponentName2 ( Status = EfiLibInstallDriverBindingComponentName2 (
ImageHandle, ImageHandle,
@ -453,33 +462,31 @@ InitializeEmuGop (
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return Status; return Status;
} }
STATIC VOID STATIC VOID
BhyveGetGraphicsMode ( BhyveGetGraphicsMode (
EFI_PCI_IO_PROTOCOL *PciIo, EFI_PCI_IO_PROTOCOL *PciIo,
UINT16 *Width, UINT16 *Width,
UINT16 *Height, UINT16 *Height,
UINT16 *Depth UINT16 *Depth
) )
{ {
BHYVE_FBUF_MEMREGS BhyveRegs; BHYVE_FBUF_MEMREGS BhyveRegs;
UINT64 Offset; UINT64 Offset;
EFI_STATUS Status; EFI_STATUS Status;
Offset = (UINT64)&BhyveRegs.Width - (UINT64)&BhyveRegs; Offset = (UINT64)&BhyveRegs.Width - (UINT64)&BhyveRegs;
Status = PciIo->Mem.Read ( Status = PciIo->Mem.Read (
PciIo, PciIo,
EfiPciIoWidthUint16, EfiPciIoWidthUint16,
PCI_BAR_IDX0, PCI_BAR_IDX0,
Offset, Offset,
3, 3,
&BhyveRegs.Width &BhyveRegs.Width
); );
*Width = BhyveRegs.Width; *Width = BhyveRegs.Width;
*Height = BhyveRegs.Height; *Height = BhyveRegs.Height;
@ -493,51 +500,56 @@ BhyveGetGraphicsMode (
VOID VOID
BhyveSetGraphicsMode ( BhyveSetGraphicsMode (
GOP_PRIVATE_DATA *Private, GOP_PRIVATE_DATA *Private,
UINT16 Width, UINT16 Width,
UINT16 Height, UINT16 Height,
UINT16 Depth UINT16 Depth
) )
{ {
BHYVE_FBUF_MEMREGS BhyveRegs; BHYVE_FBUF_MEMREGS BhyveRegs;
UINT64 Offset; UINT64 Offset;
EFI_STATUS Status; EFI_STATUS Status;
DEBUG ((DEBUG_INFO, "BHYVE Set Graphics Mode: w %d, h %d\n", Width, Height)); DEBUG ((DEBUG_INFO, "BHYVE Set Graphics Mode: w %d, h %d\n", Width, Height));
BhyveRegs.Width = Width; BhyveRegs.Width = Width;
BhyveRegs.Height = Height; BhyveRegs.Height = Height;
BhyveRegs.Depth = Depth; BhyveRegs.Depth = Depth;
Offset = (UINT64)&BhyveRegs.Width - (UINT64)&BhyveRegs; Offset = (UINT64)&BhyveRegs.Width - (UINT64)&BhyveRegs;
Status = Private->PciIo->Mem.Write ( Status = Private->PciIo->Mem.Write (
Private->PciIo, Private->PciIo,
EfiPciIoWidthUint16, EfiPciIoWidthUint16,
PCI_BAR_IDX0, PCI_BAR_IDX0,
Offset, Offset,
3, 3,
&BhyveRegs.Width &BhyveRegs.Width
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
} }
VOID VOID
BhyveGetMemregs ( BhyveGetMemregs (
GOP_PRIVATE_DATA *Private, GOP_PRIVATE_DATA *Private,
BHYVE_FBUF_MEMREGS *Memregs BHYVE_FBUF_MEMREGS *Memregs
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
Status = Private->PciIo->Mem.Read ( Status = Private->PciIo->Mem.Read (
Private->PciIo, Private->PciIo,
EfiPciIoWidthUint32, EfiPciIoWidthUint32,
PCI_BAR_IDX0, PCI_BAR_IDX0,
0, 0,
3, 3,
Memregs Memregs
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
DEBUG ((DEBUG_INFO, "BHYVE Get Memregs, size %d width %d height %d\n", DEBUG ((
Memregs->FbSize, Memregs->Width, Memregs->Height)); DEBUG_INFO,
"BHYVE Get Memregs, size %d width %d height %d\n",
Memregs->FbSize,
Memregs->Width,
Memregs->Height
));
} }

View File

@ -22,45 +22,48 @@ Abstract:
#include "Gop.h" #include "Gop.h"
#include <Library/FrameBufferBltLib.h> #include <Library/FrameBufferBltLib.h>
EFI_EVENT mGopScreenExitBootServicesEvent;
EFI_EVENT mGopScreenExitBootServicesEvent; GOP_MODE_DATA mGopModeData[] = {
{ 0, 0, 32, 0 }, // Filled in with user-spec'd resolution
GOP_MODE_DATA mGopModeData[] = { { 1024, 768, 32, 0 },
{ 0, 0, 32, 0 }, // Filled in with user-spec'd resolution { 800, 600, 32, 0 },
{ 1024, 768, 32, 0 }, { 640, 480, 32, 0 }
{ 800, 600, 32, 0 }, };
{ 640, 480, 32, 0 }
};
STATIC STATIC
VOID VOID
BhyveGopCompleteModeInfo ( BhyveGopCompleteModeInfo (
IN GOP_MODE_DATA *ModeData, IN GOP_MODE_DATA *ModeData,
OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info
) )
{ {
Info->Version = 0; Info->Version = 0;
if (ModeData->ColorDepth == 8) { if (ModeData->ColorDepth == 8) {
Info->PixelFormat = PixelBitMask; Info->PixelFormat = PixelBitMask;
Info->PixelInformation.RedMask = PIXEL_RED_MASK; Info->PixelInformation.RedMask = PIXEL_RED_MASK;
Info->PixelInformation.GreenMask = PIXEL_GREEN_MASK; Info->PixelInformation.GreenMask = PIXEL_GREEN_MASK;
Info->PixelInformation.BlueMask = PIXEL_BLUE_MASK; Info->PixelInformation.BlueMask = PIXEL_BLUE_MASK;
Info->PixelInformation.ReservedMask = 0; Info->PixelInformation.ReservedMask = 0;
} else if (ModeData->ColorDepth == 24) { } else if (ModeData->ColorDepth == 24) {
Info->PixelFormat = PixelBitMask; Info->PixelFormat = PixelBitMask;
Info->PixelInformation.RedMask = PIXEL24_RED_MASK; Info->PixelInformation.RedMask = PIXEL24_RED_MASK;
Info->PixelInformation.GreenMask = PIXEL24_GREEN_MASK; Info->PixelInformation.GreenMask = PIXEL24_GREEN_MASK;
Info->PixelInformation.BlueMask = PIXEL24_BLUE_MASK; Info->PixelInformation.BlueMask = PIXEL24_BLUE_MASK;
Info->PixelInformation.ReservedMask = 0; Info->PixelInformation.ReservedMask = 0;
} else if (ModeData->ColorDepth == 32) { } else if (ModeData->ColorDepth == 32) {
DEBUG ((DEBUG_INFO, "%dx%d PixelBlueGreenRedReserved8BitPerColor\n", DEBUG ((
ModeData->HorizontalResolution, ModeData->VerticalResolution)); DEBUG_INFO,
"%dx%d PixelBlueGreenRedReserved8BitPerColor\n",
ModeData->HorizontalResolution,
ModeData->VerticalResolution
));
Info->PixelFormat = PixelBlueGreenRedReserved8BitPerColor; Info->PixelFormat = PixelBlueGreenRedReserved8BitPerColor;
} }
Info->PixelsPerScanLine = Info->HorizontalResolution; Info->PixelsPerScanLine = Info->HorizontalResolution;
} }
/** /**
Returns information for an available graphics mode that the graphics device Returns information for an available graphics mode that the graphics device
and the set of active video output devices supports. and the set of active video output devices supports.
@ -91,7 +94,7 @@ EmuGopQuerytMode (
Private = GOP_PRIVATE_DATA_FROM_THIS (This); Private = GOP_PRIVATE_DATA_FROM_THIS (This);
if (Info == NULL || SizeOfInfo == NULL || (UINTN) ModeNumber >= This->Mode->MaxMode) { if ((Info == NULL) || (SizeOfInfo == NULL) || ((UINTN)ModeNumber >= This->Mode->MaxMode)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -102,18 +105,16 @@ EmuGopQuerytMode (
*SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION); *SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
ModeData = &Private->ModeData[ModeNumber]; ModeData = &Private->ModeData[ModeNumber];
(*Info)->Version = 0; (*Info)->Version = 0;
(*Info)->HorizontalResolution = ModeData->HorizontalResolution; (*Info)->HorizontalResolution = ModeData->HorizontalResolution;
(*Info)->VerticalResolution = ModeData->VerticalResolution; (*Info)->VerticalResolution = ModeData->VerticalResolution;
(*Info)->PixelFormat = PixelBitMask; (*Info)->PixelFormat = PixelBitMask;
(*Info)->PixelsPerScanLine = (*Info)->HorizontalResolution; (*Info)->PixelsPerScanLine = (*Info)->HorizontalResolution;
BhyveGopCompleteModeInfo(ModeData, *Info); BhyveGopCompleteModeInfo (ModeData, *Info);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Set the video device into the specified mode and clears the visible portions of Set the video device into the specified mode and clears the visible portions of
the output display to black. the output display to black.
@ -127,7 +128,7 @@ EmuGopQuerytMode (
**/ **/
FRAME_BUFFER_CONFIGURE *fbconf; FRAME_BUFFER_CONFIGURE *fbconf;
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
@ -136,37 +137,38 @@ EmuGopSetMode (
IN UINT32 ModeNumber IN UINT32 ModeNumber
) )
{ {
GOP_PRIVATE_DATA *Private; GOP_PRIVATE_DATA *Private;
GOP_MODE_DATA *ModeData; GOP_MODE_DATA *ModeData;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL Fill; EFI_GRAPHICS_OUTPUT_BLT_PIXEL Fill;
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info; EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
UINTN confsize = 0; UINTN confsize = 0;
fbconf = NULL; fbconf = NULL;
Private = GOP_PRIVATE_DATA_FROM_THIS (This); Private = GOP_PRIVATE_DATA_FROM_THIS (This);
if (ModeNumber >= This->Mode->MaxMode) { if (ModeNumber >= This->Mode->MaxMode) {
// Tell bhyve that we are switching out of vesa // Tell bhyve that we are switching out of vesa
BhyveSetGraphicsMode(Private, 0, 0, 0); BhyveSetGraphicsMode (Private, 0, 0, 0);
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
DEBUG ((DEBUG_INFO, "BHYVE GopSetMode %d\n", ModeNumber)); DEBUG ((DEBUG_INFO, "BHYVE GopSetMode %d\n", ModeNumber));
ModeData = &Private->ModeData[ModeNumber]; ModeData = &Private->ModeData[ModeNumber];
This->Mode->Mode = ModeNumber; This->Mode->Mode = ModeNumber;
Private->GraphicsOutput.Mode->Info->HorizontalResolution = ModeData->HorizontalResolution; Private->GraphicsOutput.Mode->Info->HorizontalResolution = ModeData->HorizontalResolution;
Private->GraphicsOutput.Mode->Info->VerticalResolution = ModeData->VerticalResolution; Private->GraphicsOutput.Mode->Info->VerticalResolution = ModeData->VerticalResolution;
Private->GraphicsOutput.Mode->Info->PixelsPerScanLine = ModeData->HorizontalResolution; Private->GraphicsOutput.Mode->Info->PixelsPerScanLine = ModeData->HorizontalResolution;
Info = This->Mode->Info; Info = This->Mode->Info;
BhyveGopCompleteModeInfo(ModeData, Info); BhyveGopCompleteModeInfo (ModeData, Info);
This->Mode->Info->HorizontalResolution = ModeData->HorizontalResolution; This->Mode->Info->HorizontalResolution = ModeData->HorizontalResolution;
This->Mode->Info->VerticalResolution = ModeData->VerticalResolution; This->Mode->Info->VerticalResolution = ModeData->VerticalResolution;
This->Mode->SizeOfInfo = sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION); This->Mode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
This->Mode->FrameBufferBase = Private->GraphicsOutput.Mode->FrameBufferBase; This->Mode->FrameBufferBase = Private->GraphicsOutput.Mode->FrameBufferBase;
/* /*
This->Mode->FrameBufferSize = Info->HorizontalResolution * Info->VerticalResolution This->Mode->FrameBufferSize = Info->HorizontalResolution * Info->VerticalResolution
@ -175,18 +177,24 @@ EmuGopSetMode (
This->Mode->FrameBufferSize = Private->FbSize; This->Mode->FrameBufferSize = Private->FbSize;
DEBUG ((DEBUG_INFO, "BHYVE GOP FrameBufferBase: 0x%x, FrameBufferSize: 0x%x\n", This->Mode->FrameBufferBase, This->Mode->FrameBufferSize)); DEBUG ((DEBUG_INFO, "BHYVE GOP FrameBufferBase: 0x%x, FrameBufferSize: 0x%x\n", This->Mode->FrameBufferBase, This->Mode->FrameBufferSize));
BhyveSetGraphicsMode(Private, (UINT16)ModeData->HorizontalResolution, (UINT16)ModeData->VerticalResolution, (UINT16)ModeData->ColorDepth); BhyveSetGraphicsMode (Private, (UINT16)ModeData->HorizontalResolution, (UINT16)ModeData->VerticalResolution, (UINT16)ModeData->ColorDepth);
RETURN_STATUS ret = FrameBufferBltConfigure ( RETURN_STATUS ret = FrameBufferBltConfigure (
(VOID*)(UINTN) This->Mode->FrameBufferBase, (VOID *)(UINTN)This->Mode->FrameBufferBase,
This->Mode->Info, fbconf, &confsize This->Mode->Info,
); fbconf,
if (ret == EFI_BUFFER_TOO_SMALL || ret == EFI_INVALID_PARAMETER) { &confsize
fbconf = AllocatePool(confsize); );
ret = FrameBufferBltConfigure(
(VOID*)(UINTN)This->Mode->FrameBufferBase, if ((ret == EFI_BUFFER_TOO_SMALL) || (ret == EFI_INVALID_PARAMETER)) {
This->Mode->Info, fbconf, &confsize); fbconf = AllocatePool (confsize);
ASSERT(ret == EFI_SUCCESS); ret = FrameBufferBltConfigure (
(VOID *)(UINTN)This->Mode->FrameBufferBase,
This->Mode->Info,
fbconf,
&confsize
);
ASSERT (ret == EFI_SUCCESS);
} }
Fill.Red = 0; Fill.Red = 0;
@ -207,8 +215,6 @@ EmuGopSetMode (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Blt a rectangle of pixels on the graphics screen. Blt stands for BLock Transfer. Blt a rectangle of pixels on the graphics screen. Blt stands for BLock Transfer.
@ -232,26 +238,26 @@ EmuGopSetMode (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
EmuGopBlt ( EmuGopBlt (
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This, IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer OPTIONAL, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer OPTIONAL,
IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation, IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
IN UINTN SourceX, IN UINTN SourceX,
IN UINTN SourceY, IN UINTN SourceY,
IN UINTN DestinationX, IN UINTN DestinationX,
IN UINTN DestinationY, IN UINTN DestinationY,
IN UINTN Width, IN UINTN Width,
IN UINTN Height, IN UINTN Height,
IN UINTN Delta OPTIONAL IN UINTN Delta OPTIONAL
) )
{ {
EFI_TPL OriginalTPL; EFI_TPL OriginalTPL;
EFI_STATUS Status; EFI_STATUS Status;
if ((UINT32)BltOperation >= EfiGraphicsOutputBltOperationMax) { if ((UINT32)BltOperation >= EfiGraphicsOutputBltOperationMax) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (Width == 0 || Height == 0) { if ((Width == 0) || (Height == 0)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -263,27 +269,27 @@ EmuGopBlt (
OriginalTPL = gBS->RaiseTPL (TPL_NOTIFY); OriginalTPL = gBS->RaiseTPL (TPL_NOTIFY);
switch (BltOperation) { switch (BltOperation) {
case EfiBltVideoToBltBuffer: case EfiBltVideoToBltBuffer:
case EfiBltBufferToVideo: case EfiBltBufferToVideo:
case EfiBltVideoFill: case EfiBltVideoFill:
case EfiBltVideoToVideo: case EfiBltVideoToVideo:
Status = FrameBufferBlt ( Status = FrameBufferBlt (
fbconf, fbconf,
BltBuffer, BltBuffer,
BltOperation, BltOperation,
SourceX, SourceX,
SourceY, SourceY,
DestinationX, DestinationX,
DestinationY, DestinationY,
Width, Width,
Height, Height,
Delta Delta
); );
break; break;
default: default:
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
ASSERT (FALSE); ASSERT (FALSE);
} }
gBS->RestoreTPL (OriginalTPL); gBS->RestoreTPL (OriginalTPL);
@ -291,25 +297,24 @@ EmuGopBlt (
return Status; return Status;
} }
// //
// Construction and Destruction functions // Construction and Destruction functions
// //
EFI_STATUS EFI_STATUS
EmuGopConstructor ( EmuGopConstructor (
GOP_PRIVATE_DATA *Private GOP_PRIVATE_DATA *Private
) )
{ {
// Set mode 0 to be the requested resolution // Set mode 0 to be the requested resolution
mGopModeData[0].HorizontalResolution = PcdGet32 ( PcdVideoHorizontalResolution); mGopModeData[0].HorizontalResolution = PcdGet32 (PcdVideoHorizontalResolution);
mGopModeData[0].VerticalResolution = PcdGet32 ( PcdVideoVerticalResolution ); mGopModeData[0].VerticalResolution = PcdGet32 (PcdVideoVerticalResolution);
Private->ModeData = mGopModeData; Private->ModeData = mGopModeData;
Private->GraphicsOutput.QueryMode = EmuGopQuerytMode; Private->GraphicsOutput.QueryMode = EmuGopQuerytMode;
Private->GraphicsOutput.SetMode = EmuGopSetMode; Private->GraphicsOutput.SetMode = EmuGopSetMode;
Private->GraphicsOutput.Blt = EmuGopBlt; Private->GraphicsOutput.Blt = EmuGopBlt;
// //
// Allocate buffer for Graphics Output Protocol mode information // Allocate buffer for Graphics Output Protocol mode information
@ -318,35 +323,33 @@ EmuGopConstructor (
if (Private->GraphicsOutput.Mode == NULL) { if (Private->GraphicsOutput.Mode == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
Private->GraphicsOutput.Mode->Info = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION)); Private->GraphicsOutput.Mode->Info = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
if (Private->GraphicsOutput.Mode->Info == NULL) { if (Private->GraphicsOutput.Mode->Info == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
DEBUG ((DEBUG_INFO, "BHYVE Gop Constructor\n")); DEBUG ((DEBUG_INFO, "BHYVE Gop Constructor\n"));
Private->GraphicsOutput.Mode->MaxMode = sizeof(mGopModeData) / sizeof(GOP_MODE_DATA); Private->GraphicsOutput.Mode->MaxMode = sizeof (mGopModeData) / sizeof (GOP_MODE_DATA);
// //
// Till now, we have no idea about the window size. // Till now, we have no idea about the window size.
// //
Private->GraphicsOutput.Mode->Mode = GRAPHICS_OUTPUT_INVALID_MODE_NUMBER; Private->GraphicsOutput.Mode->Mode = GRAPHICS_OUTPUT_INVALID_MODE_NUMBER;
Private->GraphicsOutput.Mode->Info->Version = 0; Private->GraphicsOutput.Mode->Info->Version = 0;
Private->GraphicsOutput.Mode->Info->HorizontalResolution = 0; Private->GraphicsOutput.Mode->Info->HorizontalResolution = 0;
Private->GraphicsOutput.Mode->Info->VerticalResolution = 0; Private->GraphicsOutput.Mode->Info->VerticalResolution = 0;
Private->GraphicsOutput.Mode->Info->PixelFormat = PixelBitMask; Private->GraphicsOutput.Mode->Info->PixelFormat = PixelBitMask;
Private->GraphicsOutput.Mode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION); Private->GraphicsOutput.Mode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
Private->GraphicsOutput.Mode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) Private->FbAddr; Private->GraphicsOutput.Mode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS)Private->FbAddr;
Private->GraphicsOutput.Mode->FrameBufferSize = Private->FbSize; Private->GraphicsOutput.Mode->FrameBufferSize = Private->FbSize;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
EFI_STATUS EFI_STATUS
EmuGopDestructor ( EmuGopDestructor (
GOP_PRIVATE_DATA *Private GOP_PRIVATE_DATA *Private
) )
{ {
// //
@ -356,6 +359,7 @@ EmuGopDestructor (
if (Private->GraphicsOutput.Mode->Info != NULL) { if (Private->GraphicsOutput.Mode->Info != NULL) {
FreePool (Private->GraphicsOutput.Mode->Info); FreePool (Private->GraphicsOutput.Mode->Info);
} }
FreePool (Private->GraphicsOutput.Mode); FreePool (Private->GraphicsOutput.Mode);
Private->GraphicsOutput.Mode = NULL; Private->GraphicsOutput.Mode = NULL;
} }
@ -363,13 +367,13 @@ EmuGopDestructor (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
VOID VOID
EFIAPI EFIAPI
ShutdownGopEvent ( ShutdownGopEvent (
IN EFI_EVENT Event, IN EFI_EVENT Event,
IN VOID *Context IN VOID *Context
) )
/*++ /*++
Routine Description: Routine Description:

View File

@ -28,8 +28,8 @@
#pragma pack (1) #pragma pack (1)
typedef struct { typedef struct {
UINT16 Offset; UINT16 Offset;
UINT16 Segment; UINT16 Segment;
} IVT_ENTRY; } IVT_ENTRY;
#pragma pack () #pragma pack ()
@ -37,52 +37,49 @@ typedef struct {
// This string is displayed by Windows 2008 R2 SP1 in the Screen Resolution, // This string is displayed by Windows 2008 R2 SP1 in the Screen Resolution,
// Advanced Settings dialog. It should be short. // Advanced Settings dialog. It should be short.
// //
STATIC CONST CHAR8 mProductRevision[] = "2.0"; STATIC CONST CHAR8 mProductRevision[] = "2.0";
#define NUM_VBE_MODES 3 #define NUM_VBE_MODES 3
STATIC CONST UINT16 vbeModeIds[] = { STATIC CONST UINT16 vbeModeIds[] = {
0x13f, // 640x480x32 0x13f, // 640x480x32
0x140, // 800x600x32 0x140, // 800x600x32
0x141 // 1024x768x32 0x141 // 1024x768x32
}; };
// Modes can be toggled with bit-0 // Modes can be toggled with bit-0
#define VBE_MODE_ENABLED 0x00BB #define VBE_MODE_ENABLED 0x00BB
#define VBE_MODE_DISABLED 0x00BA #define VBE_MODE_DISABLED 0x00BA
STATIC VBE2_MODE_INFO vbeModes[] = { STATIC VBE2_MODE_INFO vbeModes[] = {
{ // 0x13f 640x480x32 { // 0x13f 640x480x32
// ModeAttr - BytesPerScanLine // ModeAttr - BytesPerScanLine
VBE_MODE_DISABLED, 0x07, 0x00, 0x40, 0x40, 0xA000, 0x00, 0x0000, 640*4, VBE_MODE_DISABLED, 0x07, 0x00, 0x40, 0x40, 0xA000, 0x00, 0x0000, 640*4,
// Width, Height..., Vbe3 // Width, Height..., Vbe3
640, 480, 16, 8, 1, 32, 1, 0x06, 0, 0, 1, 640, 480, 16, 8, 1, 32, 1, 0x06, 0, 0, 1,
// Masks // Masks
0x08, 0x10, 0x08, 0x08, 0x08, 0x00, 0x08, 0x18, 0x00, 0x08, 0x10, 0x08, 0x08, 0x08, 0x00, 0x08, 0x18, 0x00,
// Framebuffer // Framebuffer
0xdeadbeef, 0x0000, 0x0000 0xdeadbeef, 0x0000, 0x0000
}, },
{ // 0x140 800x600x32 { // 0x140 800x600x32
// ModeAttr - BytesPerScanLine // ModeAttr - BytesPerScanLine
VBE_MODE_DISABLED, 0x07, 0x00, 0x40, 0x40, 0xA000, 0x00, 0x0000, 800*4, VBE_MODE_DISABLED, 0x07, 0x00, 0x40, 0x40, 0xA000, 0x00, 0x0000, 800*4,
// Width, Height..., Vbe3 // Width, Height..., Vbe3
800, 600, 16, 8, 1, 32, 1, 0x06, 0, 0, 1, 800, 600, 16, 8, 1, 32, 1, 0x06, 0, 0, 1,
// Masks // Masks
0x08, 0x10, 0x08, 0x08, 0x08, 0x00, 0x08, 0x18, 0x00, 0x08, 0x10, 0x08, 0x08, 0x08, 0x00, 0x08, 0x18, 0x00,
// Framebuffer // Framebuffer
0xdeadbeef, 0x0000, 0x0000 0xdeadbeef, 0x0000, 0x0000
}, },
{ // 0x141 1024x768x32 { // 0x141 1024x768x32
// ModeAttr - BytesPerScanLine // ModeAttr - BytesPerScanLine
VBE_MODE_ENABLED, 0x07, 0x00, 0x40, 0x40, 0xA000, 0x00, 0x0000, 1024*4, VBE_MODE_ENABLED, 0x07, 0x00, 0x40, 0x40, 0xA000, 0x00, 0x0000, 1024*4,
// Width, Height..., Vbe3 // Width, Height..., Vbe3
1024, 768, 16, 8, 1, 32, 1, 0x06, 0, 0, 1, 1024, 768, 16, 8, 1, 32, 1, 0x06, 0, 0, 1,
// Masks // Masks
0x08, 0x10, 0x08, 0x08, 0x08, 0x00, 0x08, 0x18, 0x00, 0x08, 0x10, 0x08, 0x08, 0x08, 0x00, 0x08, 0x18, 0x00,
// Framebuffer // Framebuffer
0xdeadbeef, 0x0000, 0x0000 0xdeadbeef, 0x0000, 0x0000
} }
}; };
@ -98,23 +95,23 @@ STATIC VBE2_MODE_INFO vbeModes[] = {
**/ **/
VOID VOID
InstallVbeShim ( InstallVbeShim (
IN CONST CHAR16 *CardName, IN CONST CHAR16 *CardName,
IN EFI_PHYSICAL_ADDRESS FrameBufferBase IN EFI_PHYSICAL_ADDRESS FrameBufferBase
) )
{ {
EFI_PHYSICAL_ADDRESS Segment0, SegmentC, SegmentF; EFI_PHYSICAL_ADDRESS Segment0, SegmentC, SegmentF;
UINTN Segment0Pages; UINTN Segment0Pages;
IVT_ENTRY *Int0x10; IVT_ENTRY *Int0x10;
EFI_STATUS Status; EFI_STATUS Status;
UINTN Pam1Address; UINTN Pam1Address;
UINT8 Pam1; UINT8 Pam1;
UINTN SegmentCPages; UINTN SegmentCPages;
VBE_INFO *VbeInfoFull; VBE_INFO *VbeInfoFull;
VBE_INFO_BASE *VbeInfo; VBE_INFO_BASE *VbeInfo;
UINT8 *Ptr; UINT8 *Ptr;
UINTN Printed; UINTN Printed;
VBE_MODE_INFO *VbeModeInfo; VBE_MODE_INFO *VbeModeInfo;
UINTN i; UINTN i;
Segment0 = 0x00000; Segment0 = 0x00000;
SegmentC = 0xC0000; SegmentC = 0xC0000;
@ -130,11 +127,15 @@ InstallVbeShim (
// //
Segment0Pages = 1; Segment0Pages = 1;
Int0x10 = (IVT_ENTRY *)(UINTN)Segment0 + 0x10; Int0x10 = (IVT_ENTRY *)(UINTN)Segment0 + 0x10;
Status = gBS->AllocatePages (AllocateAddress, EfiBootServicesCode, Status = gBS->AllocatePages (
Segment0Pages, &Segment0); AllocateAddress,
EfiBootServicesCode,
Segment0Pages,
&Segment0
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
EFI_PHYSICAL_ADDRESS Handler; EFI_PHYSICAL_ADDRESS Handler;
// //
// Check if a video BIOS handler has been installed previously -- we // Check if a video BIOS handler has been installed previously -- we
@ -142,9 +143,14 @@ InstallVbeShim (
// it's already present. // it's already present.
// //
Handler = (Int0x10->Segment << 4) + Int0x10->Offset; Handler = (Int0x10->Segment << 4) + Int0x10->Offset;
if (Handler >= SegmentC && Handler < SegmentF) { if ((Handler >= SegmentC) && (Handler < SegmentF)) {
DEBUG ((DEBUG_VERBOSE, "%a: Video BIOS handler found at %04x:%04x\n", DEBUG ((
__FUNCTION__, Int0x10->Segment, Int0x10->Offset)); DEBUG_VERBOSE,
"%a: Video BIOS handler found at %04x:%04x\n",
__FUNCTION__,
Int0x10->Segment,
Int0x10->Offset
));
return; return;
} }
@ -152,8 +158,12 @@ InstallVbeShim (
// Otherwise we'll overwrite the Int10h vector, even though we may not own // Otherwise we'll overwrite the Int10h vector, even though we may not own
// the page at zero. // the page at zero.
// //
DEBUG ((DEBUG_VERBOSE, "%a: failed to allocate page at zero: %r\n", DEBUG ((
__FUNCTION__, Status)); DEBUG_VERBOSE,
"%a: failed to allocate page at zero: %r\n",
__FUNCTION__,
Status
));
} else { } else {
// //
// We managed to allocate the page at zero. SVN r14218 guarantees that it // We managed to allocate the page at zero. SVN r14218 guarantees that it
@ -203,14 +213,15 @@ InstallVbeShim (
VbeInfo->Capabilities = BIT1 | BIT0; // DAC can be switched into 8-bit mode VbeInfo->Capabilities = BIT1 | BIT0; // DAC can be switched into 8-bit mode
VbeInfo->ModeListAddress = (UINT32)SegmentC << 12 | (UINT16)((UINTN)Ptr-SegmentC); VbeInfo->ModeListAddress = (UINT32)SegmentC << 12 | (UINT16)((UINTN)Ptr-SegmentC);
for (i = 0; i < NUM_VBE_MODES; i ++) { for (i = 0; i < NUM_VBE_MODES; i++) {
*(UINT16*)Ptr = vbeModeIds[i]; // mode number *(UINT16 *)Ptr = vbeModeIds[i]; // mode number
Ptr += 2; Ptr += 2;
} }
*(UINT16*)Ptr = 0xFFFF; // mode list terminator
Ptr += 2;
VbeInfo->VideoMem64K = (UINT16)((1024 * 768 * 4 + 65535) / 65536); *(UINT16 *)Ptr = 0xFFFF; // mode list terminator
Ptr += 2;
VbeInfo->VideoMem64K = (UINT16)((1024 * 768 * 4 + 65535) / 65536);
VbeInfo->OemSoftwareVersion = 0x0200; VbeInfo->OemSoftwareVersion = 0x0200;
VbeInfo->VendorNameAddress = (UINT32)SegmentC << 12 | (UINT16)((UINTN)Ptr-SegmentC); VbeInfo->VendorNameAddress = (UINT32)SegmentC << 12 | (UINT16)((UINTN)Ptr-SegmentC);
@ -218,9 +229,12 @@ InstallVbeShim (
Ptr += 5; Ptr += 5;
VbeInfo->ProductNameAddress = (UINT32)SegmentC << 12 | (UINT16)((UINTN)Ptr-SegmentC); VbeInfo->ProductNameAddress = (UINT32)SegmentC << 12 | (UINT16)((UINTN)Ptr-SegmentC);
Printed = AsciiSPrint ((CHAR8 *)Ptr, Printed = AsciiSPrint (
sizeof VbeInfoFull->Buffer - (Ptr - VbeInfoFull->Buffer), "%s", (CHAR8 *)Ptr,
CardName); sizeof VbeInfoFull->Buffer - (Ptr - VbeInfoFull->Buffer),
"%s",
CardName
);
Ptr += Printed + 1; Ptr += Printed + 1;
VbeInfo->ProductRevAddress = (UINT32)SegmentC << 12 | (UINT16)((UINTN)Ptr-SegmentC); VbeInfo->ProductRevAddress = (UINT32)SegmentC << 12 | (UINT16)((UINTN)Ptr-SegmentC);
@ -234,7 +248,7 @@ InstallVbeShim (
// Fill in the VBE MODE INFO structure list // Fill in the VBE MODE INFO structure list
// //
VbeModeInfo = (VBE_MODE_INFO *)(VbeInfoFull + 1); VbeModeInfo = (VBE_MODE_INFO *)(VbeInfoFull + 1);
Ptr = (UINT8 *)VbeModeInfo; Ptr = (UINT8 *)VbeModeInfo;
for (i = 0; i < NUM_VBE_MODES; i++) { for (i = 0; i < NUM_VBE_MODES; i++) {
vbeModes[i].LfbAddress = (UINT32)FrameBufferBase; vbeModes[i].LfbAddress = (UINT32)FrameBufferBase;
CopyMem (Ptr, &vbeModes[i], 0x32); CopyMem (Ptr, &vbeModes[i], 0x32);
@ -251,9 +265,14 @@ InstallVbeShim (
// //
// Second, point the Int10h vector at the shim. // Second, point the Int10h vector at the shim.
// //
Int0x10->Segment = (UINT16) ((UINT32)SegmentC >> 4); Int0x10->Segment = (UINT16)((UINT32)SegmentC >> 4);
Int0x10->Offset = (UINT16) ((UINTN) (VbeModeInfo + 1) - SegmentC); Int0x10->Offset = (UINT16)((UINTN)(VbeModeInfo + 1) - SegmentC);
DEBUG ((DEBUG_INFO, "%a: VBE shim installed to %x:%x\n", DEBUG ((
__FUNCTION__, Int0x10->Segment, Int0x10->Offset)); DEBUG_INFO,
"%a: VBE shim installed to %x:%x\n",
__FUNCTION__,
Int0x10->Segment,
Int0x10->Offset
));
} }

File diff suppressed because it is too large Load Diff

View File

@ -30,8 +30,8 @@ AmdSevInitialize (
VOID VOID
) )
{ {
UINT64 EncryptionMask; UINT64 EncryptionMask;
RETURN_STATUS PcdStatus; RETURN_STATUS PcdStatus;
// //
// Check if SEV is enabled // Check if SEV is enabled
@ -44,7 +44,7 @@ AmdSevInitialize (
// Set Memory Encryption Mask PCD // Set Memory Encryption Mask PCD
// //
EncryptionMask = MemEncryptSevGetEncryptionMask (); EncryptionMask = MemEncryptSevGetEncryptionMask ();
PcdStatus = PcdSet64S (PcdPteMemoryEncryptionAddressOrMask, EncryptionMask); PcdStatus = PcdSet64S (PcdPteMemoryEncryptionAddressOrMask, EncryptionMask);
ASSERT_RETURN_ERROR (PcdStatus); ASSERT_RETURN_ERROR (PcdStatus);
DEBUG ((DEBUG_INFO, "SEV is enabled (mask 0x%lx)\n", EncryptionMask)); DEBUG ((DEBUG_INFO, "SEV is enabled (mask 0x%lx)\n", EncryptionMask));
@ -67,9 +67,9 @@ AmdSevInitialize (
// hypervisor. // hypervisor.
// //
if (FeaturePcdGet (PcdSmmSmramRequire) && (mBootMode != BOOT_ON_S3_RESUME)) { if (FeaturePcdGet (PcdSmmSmramRequire) && (mBootMode != BOOT_ON_S3_RESUME)) {
RETURN_STATUS LocateMapStatus; RETURN_STATUS LocateMapStatus;
UINTN MapPagesBase; UINTN MapPagesBase;
UINTN MapPagesCount; UINTN MapPagesCount;
LocateMapStatus = MemEncryptSevLocateInitialSmramSaveStateMapPages ( LocateMapStatus = MemEncryptSevLocateInitialSmramSaveStateMapPages (
&MapPagesBase, &MapPagesBase,

View File

@ -29,7 +29,7 @@ STATIC
VOID VOID
EFIAPI EFIAPI
ClearCache ( ClearCache (
IN OUT VOID *WorkSpace IN OUT VOID *WorkSpace
) )
{ {
WriteBackInvalidateDataCache (); WriteBackInvalidateDataCache ();
@ -56,8 +56,8 @@ ClearCacheOnMpServicesAvailable (
IN VOID *Ppi IN VOID *Ppi
) )
{ {
EFI_PEI_MP_SERVICES_PPI *MpServices; EFI_PEI_MP_SERVICES_PPI *MpServices;
EFI_STATUS Status; EFI_STATUS Status;
DEBUG ((DEBUG_INFO, "%a: %a\n", gEfiCallerBaseName, __FUNCTION__)); DEBUG ((DEBUG_INFO, "%a: %a\n", gEfiCallerBaseName, __FUNCTION__));
@ -65,15 +65,15 @@ ClearCacheOnMpServicesAvailable (
// Clear cache on all the APs in parallel. // Clear cache on all the APs in parallel.
// //
MpServices = Ppi; MpServices = Ppi;
Status = MpServices->StartupAllAPs ( Status = MpServices->StartupAllAPs (
(CONST EFI_PEI_SERVICES **)PeiServices, (CONST EFI_PEI_SERVICES **)PeiServices,
MpServices, MpServices,
ClearCache, // Procedure ClearCache, // Procedure
FALSE, // SingleThread FALSE, // SingleThread
0, // TimeoutInMicroSeconds: inf. 0, // TimeoutInMicroSeconds: inf.
NULL // ProcedureArgument NULL // ProcedureArgument
); );
if (EFI_ERROR (Status) && Status != EFI_NOT_STARTED) { if (EFI_ERROR (Status) && (Status != EFI_NOT_STARTED)) {
DEBUG ((DEBUG_ERROR, "%a: StartupAllAps(): %r\n", __FUNCTION__, Status)); DEBUG ((DEBUG_ERROR, "%a: StartupAllAps(): %r\n", __FUNCTION__, Status));
return Status; return Status;
} }
@ -89,7 +89,7 @@ ClearCacheOnMpServicesAvailable (
// Notification object for registering the callback, for when // Notification object for registering the callback, for when
// EFI_PEI_MP_SERVICES_PPI becomes available. // EFI_PEI_MP_SERVICES_PPI becomes available.
// //
STATIC CONST EFI_PEI_NOTIFY_DESCRIPTOR mMpServicesNotify = { STATIC CONST EFI_PEI_NOTIFY_DESCRIPTOR mMpServicesNotify = {
EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | // Flags EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | // Flags
EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
&gEfiPeiMpServicesPpiGuid, // Guid &gEfiPeiMpServicesPpiGuid, // Guid
@ -101,11 +101,15 @@ InstallClearCacheCallback (
VOID VOID
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
Status = PeiServicesNotifyPpi (&mMpServicesNotify); Status = PeiServicesNotifyPpi (&mMpServicesNotify);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to set up MP Services callback: %r\n", DEBUG ((
__FUNCTION__, Status)); DEBUG_ERROR,
"%a: failed to set up MP Services callback: %r\n",
__FUNCTION__,
Status
));
} }
} }

View File

@ -6,7 +6,6 @@
**/ **/
#include "Cmos.h" #include "Cmos.h"
#include "Library/IoLib.h" #include "Library/IoLib.h"
@ -24,14 +23,13 @@
UINT8 UINT8
EFIAPI EFIAPI
CmosRead8 ( CmosRead8 (
IN UINTN Index IN UINTN Index
) )
{ {
IoWrite8 (0x70, (UINT8) Index); IoWrite8 (0x70, (UINT8)Index);
return IoRead8 (0x71); return IoRead8 (0x71);
} }
/** /**
Writes 8-bits of CMOS data. Writes 8-bits of CMOS data.
@ -47,12 +45,11 @@ CmosRead8 (
UINT8 UINT8
EFIAPI EFIAPI
CmosWrite8 ( CmosWrite8 (
IN UINTN Index, IN UINTN Index,
IN UINT8 Value IN UINT8 Value
) )
{ {
IoWrite8 (0x70, (UINT8) Index); IoWrite8 (0x70, (UINT8)Index);
IoWrite8 (0x71, Value); IoWrite8 (0x71, Value);
return Value; return Value;
} }

View File

@ -23,7 +23,7 @@
UINT8 UINT8
EFIAPI EFIAPI
CmosRead8 ( CmosRead8 (
IN UINTN Index IN UINTN Index
); );
/** /**
@ -41,10 +41,8 @@ CmosRead8 (
UINT8 UINT8
EFIAPI EFIAPI
CmosWrite8 ( CmosWrite8 (
IN UINTN Index, IN UINTN Index,
IN UINT8 Value IN UINT8 Value
); );
#endif /* _CMOS_H_ */ #endif /* _CMOS_H_ */

View File

@ -13,7 +13,6 @@
#include <Library/PcdLib.h> #include <Library/PcdLib.h>
#include <Library/PeiServicesLib.h> #include <Library/PeiServicesLib.h>
/** /**
Publish PEI & DXE (Decompressed) Memory based FVs to let PEI Publish PEI & DXE (Decompressed) Memory based FVs to let PEI
and DXE know about them. and DXE know about them.
@ -26,7 +25,7 @@ PeiFvInitialization (
VOID VOID
) )
{ {
BOOLEAN SecureS3Needed; BOOLEAN SecureS3Needed;
DEBUG ((DEBUG_INFO, "Platform PEI Firmware Volume Initialization\n")); DEBUG ((DEBUG_INFO, "Platform PEI Firmware Volume Initialization\n"));
@ -67,7 +66,7 @@ PeiFvInitialization (
// of DXEFV, so let's keep away the OS from there too. // of DXEFV, so let's keep away the OS from there too.
// //
if (SecureS3Needed) { if (SecureS3Needed) {
UINT32 DxeMemFvEnd; UINT32 DxeMemFvEnd;
DxeMemFvEnd = PcdGet32 (PcdOvmfDxeMemFvBase) + DxeMemFvEnd = PcdGet32 (PcdOvmfDxeMemFvBase) +
PcdGet32 (PcdOvmfDxeMemFvSize); PcdGet32 (PcdOvmfDxeMemFvSize);
@ -83,7 +82,7 @@ PeiFvInitialization (
// //
PeiServicesInstallFvInfoPpi ( PeiServicesInstallFvInfoPpi (
NULL, NULL,
(VOID *)(UINTN) PcdGet32 (PcdOvmfDxeMemFvBase), (VOID *)(UINTN)PcdGet32 (PcdOvmfDxeMemFvBase),
PcdGet32 (PcdOvmfDxeMemFvSize), PcdGet32 (PcdOvmfDxeMemFvSize),
NULL, NULL,
NULL NULL
@ -91,4 +90,3 @@ PeiFvInitialization (
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@ -36,22 +36,22 @@ Module Name:
#include "Platform.h" #include "Platform.h"
#include "Cmos.h" #include "Cmos.h"
UINT8 mPhysMemAddressWidth; UINT8 mPhysMemAddressWidth;
STATIC UINT32 mS3AcpiReservedMemoryBase; STATIC UINT32 mS3AcpiReservedMemoryBase;
STATIC UINT32 mS3AcpiReservedMemorySize; STATIC UINT32 mS3AcpiReservedMemorySize;
STATIC UINT16 mQ35TsegMbytes; STATIC UINT16 mQ35TsegMbytes;
BOOLEAN mQ35SmramAtDefaultSmbase = FALSE; BOOLEAN mQ35SmramAtDefaultSmbase = FALSE;
VOID VOID
Q35TsegMbytesInitialization ( Q35TsegMbytesInitialization (
VOID VOID
) )
{ {
UINT16 ExtendedTsegMbytes; UINT16 ExtendedTsegMbytes;
RETURN_STATUS PcdStatus; RETURN_STATUS PcdStatus;
if (mHostBridgeDevId != INTEL_Q35_MCH_DEVICE_ID) { if (mHostBridgeDevId != INTEL_Q35_MCH_DEVICE_ID) {
DEBUG (( DEBUG ((
@ -100,14 +100,13 @@ Q35TsegMbytesInitialization (
mQ35TsegMbytes = ExtendedTsegMbytes; mQ35TsegMbytes = ExtendedTsegMbytes;
} }
UINT32 UINT32
GetSystemMemorySizeBelow4gb ( GetSystemMemorySizeBelow4gb (
VOID VOID
) )
{ {
UINT8 Cmos0x34; UINT8 Cmos0x34;
UINT8 Cmos0x35; UINT8 Cmos0x35;
// //
// CMOS 0x34/0x35 specifies the system memory above 16 MB. // CMOS 0x34/0x35 specifies the system memory above 16 MB.
@ -118,20 +117,19 @@ GetSystemMemorySizeBelow4gb (
// into the calculation to get the total memory size. // into the calculation to get the total memory size.
// //
Cmos0x34 = (UINT8) CmosRead8 (0x34); Cmos0x34 = (UINT8)CmosRead8 (0x34);
Cmos0x35 = (UINT8) CmosRead8 (0x35); Cmos0x35 = (UINT8)CmosRead8 (0x35);
return (UINT32) (((UINTN)((Cmos0x35 << 8) + Cmos0x34) << 16) + SIZE_16MB); return (UINT32)(((UINTN)((Cmos0x35 << 8) + Cmos0x34) << 16) + SIZE_16MB);
} }
STATIC STATIC
UINT64 UINT64
GetSystemMemorySizeAbove4gb ( GetSystemMemorySizeAbove4gb (
) )
{ {
UINT32 Size; UINT32 Size;
UINTN CmosIndex; UINTN CmosIndex;
// //
// CMOS 0x5b-0x5d specifies the system memory above 4GB MB. // CMOS 0x5b-0x5d specifies the system memory above 4GB MB.
@ -143,13 +141,12 @@ GetSystemMemorySizeAbove4gb (
Size = 0; Size = 0;
for (CmosIndex = 0x5d; CmosIndex >= 0x5b; CmosIndex--) { for (CmosIndex = 0x5d; CmosIndex >= 0x5b; CmosIndex--) {
Size = (UINT32) (Size << 8) + (UINT32) CmosRead8 (CmosIndex); Size = (UINT32)(Size << 8) + (UINT32)CmosRead8 (CmosIndex);
} }
return LShiftU64 (Size, 16); return LShiftU64 (Size, 16);
} }
/** /**
Return the highest address that DXE could possibly use, plus one. Return the highest address that DXE could possibly use, plus one.
**/ **/
@ -159,9 +156,9 @@ GetFirstNonAddress (
VOID VOID
) )
{ {
UINT64 FirstNonAddress; UINT64 FirstNonAddress;
UINT64 Pci64Base, Pci64Size; UINT64 Pci64Base, Pci64Size;
RETURN_STATUS PcdStatus; RETURN_STATUS PcdStatus;
FirstNonAddress = BASE_4GB + GetSystemMemorySizeAbove4gb (); FirstNonAddress = BASE_4GB + GetSystemMemorySizeAbove4gb ();
@ -170,11 +167,12 @@ GetFirstNonAddress (
// resources to 32-bit anyway. See DegradeResource() in // resources to 32-bit anyway. See DegradeResource() in
// "PciResourceSupport.c". // "PciResourceSupport.c".
// //
#ifdef MDE_CPU_IA32 #ifdef MDE_CPU_IA32
if (!FeaturePcdGet (PcdDxeIplSwitchToLongMode)) { if (!FeaturePcdGet (PcdDxeIplSwitchToLongMode)) {
return FirstNonAddress; return FirstNonAddress;
} }
#endif
#endif
// //
// Otherwise, in order to calculate the highest address plus one, we must // Otherwise, in order to calculate the highest address plus one, we must
@ -184,8 +182,11 @@ GetFirstNonAddress (
if (Pci64Size == 0) { if (Pci64Size == 0) {
if (mBootMode != BOOT_ON_S3_RESUME) { if (mBootMode != BOOT_ON_S3_RESUME) {
DEBUG ((DEBUG_INFO, "%a: disabling 64-bit PCI host aperture\n", DEBUG ((
__FUNCTION__)); DEBUG_INFO,
"%a: disabling 64-bit PCI host aperture\n",
__FUNCTION__
));
PcdStatus = PcdSet64S (PcdPciMmio64Size, 0); PcdStatus = PcdSet64S (PcdPciMmio64Size, 0);
ASSERT_RETURN_ERROR (PcdStatus); ASSERT_RETURN_ERROR (PcdStatus);
} }
@ -224,8 +225,13 @@ GetFirstNonAddress (
PcdStatus = PcdSet64S (PcdPciMmio64Size, Pci64Size); PcdStatus = PcdSet64S (PcdPciMmio64Size, Pci64Size);
ASSERT_RETURN_ERROR (PcdStatus); ASSERT_RETURN_ERROR (PcdStatus);
DEBUG ((DEBUG_INFO, "%a: Pci64Base=0x%Lx Pci64Size=0x%Lx\n", DEBUG ((
__FUNCTION__, Pci64Base, Pci64Size)); DEBUG_INFO,
"%a: Pci64Base=0x%Lx Pci64Size=0x%Lx\n",
__FUNCTION__,
Pci64Base,
Pci64Size
));
} }
// //
@ -235,7 +241,6 @@ GetFirstNonAddress (
return FirstNonAddress; return FirstNonAddress;
} }
/** /**
Initialize the mPhysMemAddressWidth variable, based on guest RAM size. Initialize the mPhysMemAddressWidth variable, based on guest RAM size.
**/ **/
@ -244,7 +249,7 @@ AddressWidthInitialization (
VOID VOID
) )
{ {
UINT64 FirstNonAddress; UINT64 FirstNonAddress;
// //
// As guest-physical memory size grows, the permanent PEI RAM requirements // As guest-physical memory size grows, the permanent PEI RAM requirements
@ -272,10 +277,10 @@ AddressWidthInitialization (
if (mPhysMemAddressWidth <= 36) { if (mPhysMemAddressWidth <= 36) {
mPhysMemAddressWidth = 36; mPhysMemAddressWidth = 36;
} }
ASSERT (mPhysMemAddressWidth <= 48); ASSERT (mPhysMemAddressWidth <= 48);
} }
/** /**
Calculate the cap for the permanent PEI memory. Calculate the cap for the permanent PEI memory.
**/ **/
@ -285,21 +290,22 @@ GetPeiMemoryCap (
VOID VOID
) )
{ {
BOOLEAN Page1GSupport; BOOLEAN Page1GSupport;
UINT32 RegEax; UINT32 RegEax;
UINT32 RegEdx; UINT32 RegEdx;
UINT32 Pml4Entries; UINT32 Pml4Entries;
UINT32 PdpEntries; UINT32 PdpEntries;
UINTN TotalPages; UINTN TotalPages;
// //
// If DXE is 32-bit, then just return the traditional 64 MB cap. // If DXE is 32-bit, then just return the traditional 64 MB cap.
// //
#ifdef MDE_CPU_IA32 #ifdef MDE_CPU_IA32
if (!FeaturePcdGet (PcdDxeIplSwitchToLongMode)) { if (!FeaturePcdGet (PcdDxeIplSwitchToLongMode)) {
return SIZE_64MB; return SIZE_64MB;
} }
#endif
#endif
// //
// Dependent on physical address width, PEI memory allocations can be // Dependent on physical address width, PEI memory allocations can be
@ -320,7 +326,7 @@ GetPeiMemoryCap (
if (mPhysMemAddressWidth <= 39) { if (mPhysMemAddressWidth <= 39) {
Pml4Entries = 1; Pml4Entries = 1;
PdpEntries = 1 << (mPhysMemAddressWidth - 30); PdpEntries = 1 << (mPhysMemAddressWidth - 30);
ASSERT (PdpEntries <= 0x200); ASSERT (PdpEntries <= 0x200);
} else { } else {
Pml4Entries = 1 << (mPhysMemAddressWidth - 39); Pml4Entries = 1 << (mPhysMemAddressWidth - 39);
@ -329,7 +335,7 @@ GetPeiMemoryCap (
} }
TotalPages = Page1GSupport ? Pml4Entries + 1 : TotalPages = Page1GSupport ? Pml4Entries + 1 :
(PdpEntries + 1) * Pml4Entries + 1; (PdpEntries + 1) * Pml4Entries + 1;
ASSERT (TotalPages <= 0x40201); ASSERT (TotalPages <= 0x40201);
// //
@ -340,7 +346,6 @@ GetPeiMemoryCap (
return (UINT32)(EFI_PAGES_TO_SIZE (TotalPages) + SIZE_64MB); return (UINT32)(EFI_PAGES_TO_SIZE (TotalPages) + SIZE_64MB);
} }
/** /**
Publish PEI core memory Publish PEI core memory
@ -352,11 +357,11 @@ PublishPeiMemory (
VOID VOID
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS MemoryBase; EFI_PHYSICAL_ADDRESS MemoryBase;
UINT64 MemorySize; UINT64 MemorySize;
UINT32 LowerMemorySize; UINT32 LowerMemorySize;
UINT32 PeiMemoryCap; UINT32 PeiMemoryCap;
LowerMemorySize = GetSystemMemorySizeBelow4gb (); LowerMemorySize = GetSystemMemorySizeBelow4gb ();
if (FeaturePcdGet (PcdSmmSmramRequire)) { if (FeaturePcdGet (PcdSmmSmramRequire)) {
@ -373,10 +378,10 @@ PublishPeiMemory (
// //
if (mS3Supported) { if (mS3Supported) {
mS3AcpiReservedMemorySize = SIZE_512KB + mS3AcpiReservedMemorySize = SIZE_512KB +
mMaxCpuCount * mMaxCpuCount *
PcdGet32 (PcdCpuApStackSize); PcdGet32 (PcdCpuApStackSize);
mS3AcpiReservedMemoryBase = LowerMemorySize - mS3AcpiReservedMemorySize; mS3AcpiReservedMemoryBase = LowerMemorySize - mS3AcpiReservedMemorySize;
LowerMemorySize = mS3AcpiReservedMemoryBase; LowerMemorySize = mS3AcpiReservedMemoryBase;
} }
if (mBootMode == BOOT_ON_S3_RESUME) { if (mBootMode == BOOT_ON_S3_RESUME) {
@ -384,8 +389,13 @@ PublishPeiMemory (
MemorySize = mS3AcpiReservedMemorySize; MemorySize = mS3AcpiReservedMemorySize;
} else { } else {
PeiMemoryCap = GetPeiMemoryCap (); PeiMemoryCap = GetPeiMemoryCap ();
DEBUG ((DEBUG_INFO, "%a: mPhysMemAddressWidth=%d PeiMemoryCap=%u KB\n", DEBUG ((
__FUNCTION__, mPhysMemAddressWidth, PeiMemoryCap >> 10)); DEBUG_INFO,
"%a: mPhysMemAddressWidth=%d PeiMemoryCap=%u KB\n",
__FUNCTION__,
mPhysMemAddressWidth,
PeiMemoryCap >> 10
));
// //
// Determine the range of memory to use during PEI // Determine the range of memory to use during PEI
@ -398,8 +408,8 @@ PublishPeiMemory (
// shouldn't overlap with that HOB. // shouldn't overlap with that HOB.
// //
MemoryBase = mS3Supported && FeaturePcdGet (PcdSmmSmramRequire) ? MemoryBase = mS3Supported && FeaturePcdGet (PcdSmmSmramRequire) ?
PcdGet32 (PcdOvmfDecompressionScratchEnd) : PcdGet32 (PcdOvmfDecompressionScratchEnd) :
PcdGet32 (PcdOvmfDxeMemFvBase) + PcdGet32 (PcdOvmfDxeMemFvSize); PcdGet32 (PcdOvmfDxeMemFvBase) + PcdGet32 (PcdOvmfDxeMemFvSize);
MemorySize = LowerMemorySize - MemoryBase; MemorySize = LowerMemorySize - MemoryBase;
if (MemorySize > PeiMemoryCap) { if (MemorySize > PeiMemoryCap) {
MemoryBase = LowerMemorySize - PeiMemoryCap; MemoryBase = LowerMemorySize - PeiMemoryCap;
@ -410,13 +420,12 @@ PublishPeiMemory (
// //
// Publish this memory to the PEI Core // Publish this memory to the PEI Core
// //
Status = PublishSystemMemory(MemoryBase, MemorySize); Status = PublishSystemMemory (MemoryBase, MemorySize);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return Status; return Status;
} }
/** /**
Peform Memory Detection for QEMU / KVM Peform Memory Detection for QEMU / KVM
@ -427,10 +436,10 @@ QemuInitializeRam (
VOID VOID
) )
{ {
UINT64 LowerMemorySize; UINT64 LowerMemorySize;
UINT64 UpperMemorySize; UINT64 UpperMemorySize;
MTRR_SETTINGS MtrrSettings; MTRR_SETTINGS MtrrSettings;
EFI_STATUS Status; EFI_STATUS Status;
DEBUG ((DEBUG_INFO, "%a called\n", __FUNCTION__)); DEBUG ((DEBUG_INFO, "%a called\n", __FUNCTION__));
@ -469,12 +478,15 @@ QemuInitializeRam (
AddMemoryRangeHob (0, BASE_512KB + BASE_128KB); AddMemoryRangeHob (0, BASE_512KB + BASE_128KB);
if (FeaturePcdGet (PcdSmmSmramRequire)) { if (FeaturePcdGet (PcdSmmSmramRequire)) {
UINT32 TsegSize; UINT32 TsegSize;
TsegSize = mQ35TsegMbytes * SIZE_1MB; TsegSize = mQ35TsegMbytes * SIZE_1MB;
AddMemoryRangeHob (BASE_1MB, LowerMemorySize - TsegSize); AddMemoryRangeHob (BASE_1MB, LowerMemorySize - TsegSize);
AddReservedMemoryBaseSizeHob (LowerMemorySize - TsegSize, TsegSize, AddReservedMemoryBaseSizeHob (
TRUE); LowerMemorySize - TsegSize,
TsegSize,
TRUE
);
} else { } else {
AddMemoryRangeHob (BASE_1MB, LowerMemorySize); AddMemoryRangeHob (BASE_1MB, LowerMemorySize);
} }
@ -516,16 +528,22 @@ QemuInitializeRam (
// //
// Set memory range from 640KB to 1MB to uncacheable // Set memory range from 640KB to 1MB to uncacheable
// //
Status = MtrrSetMemoryAttribute (BASE_512KB + BASE_128KB, Status = MtrrSetMemoryAttribute (
BASE_1MB - (BASE_512KB + BASE_128KB), CacheUncacheable); BASE_512KB + BASE_128KB,
BASE_1MB - (BASE_512KB + BASE_128KB),
CacheUncacheable
);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
// //
// Set memory range from the "top of lower RAM" (RAM below 4GB) to 4GB as // Set memory range from the "top of lower RAM" (RAM below 4GB) to 4GB as
// uncacheable // uncacheable
// //
Status = MtrrSetMemoryAttribute (LowerMemorySize, Status = MtrrSetMemoryAttribute (
SIZE_4GB - LowerMemorySize, CacheUncacheable); LowerMemorySize,
SIZE_4GB - LowerMemorySize,
CacheUncacheable
);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
} }
} }
@ -541,7 +559,7 @@ InitializeRamRegions (
{ {
QemuInitializeRam (); QemuInitializeRam ();
if (mS3Supported && mBootMode != BOOT_ON_S3_RESUME) { if (mS3Supported && (mBootMode != BOOT_ON_S3_RESUME)) {
// //
// This is the memory range that will be used for PEI on S3 resume // This is the memory range that will be used for PEI on S3 resume
// //
@ -571,7 +589,7 @@ InitializeRamRegions (
EfiACPIMemoryNVS EfiACPIMemoryNVS
); );
#ifdef MDE_CPU_X64 #ifdef MDE_CPU_X64
// //
// Reserve the initial page tables built by the reset vector code. // Reserve the initial page tables built by the reset vector code.
// //
@ -579,11 +597,11 @@ InitializeRamRegions (
// resume, it must be reserved as ACPI NVS. // resume, it must be reserved as ACPI NVS.
// //
BuildMemoryAllocationHob ( BuildMemoryAllocationHob (
(EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfSecPageTablesBase), (EFI_PHYSICAL_ADDRESS)(UINTN)PcdGet32 (PcdOvmfSecPageTablesBase),
(UINT64)(UINTN) PcdGet32 (PcdOvmfSecPageTablesSize), (UINT64)(UINTN)PcdGet32 (PcdOvmfSecPageTablesSize),
EfiACPIMemoryNVS EfiACPIMemoryNVS
); );
#endif #endif
} }
if (mBootMode != BOOT_ON_S3_RESUME) { if (mBootMode != BOOT_ON_S3_RESUME) {
@ -599,18 +617,18 @@ InitializeRamRegions (
// such that they would overlap the LockBox storage. // such that they would overlap the LockBox storage.
// //
ZeroMem ( ZeroMem (
(VOID*)(UINTN) PcdGet32 (PcdOvmfLockBoxStorageBase), (VOID *)(UINTN)PcdGet32 (PcdOvmfLockBoxStorageBase),
(UINTN) PcdGet32 (PcdOvmfLockBoxStorageSize) (UINTN)PcdGet32 (PcdOvmfLockBoxStorageSize)
); );
BuildMemoryAllocationHob ( BuildMemoryAllocationHob (
(EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfLockBoxStorageBase), (EFI_PHYSICAL_ADDRESS)(UINTN)PcdGet32 (PcdOvmfLockBoxStorageBase),
(UINT64)(UINTN) PcdGet32 (PcdOvmfLockBoxStorageSize), (UINT64)(UINTN)PcdGet32 (PcdOvmfLockBoxStorageSize),
mS3Supported ? EfiACPIMemoryNVS : EfiBootServicesData mS3Supported ? EfiACPIMemoryNVS : EfiBootServicesData
); );
} }
if (FeaturePcdGet (PcdSmmSmramRequire)) { if (FeaturePcdGet (PcdSmmSmramRequire)) {
UINT32 TsegSize; UINT32 TsegSize;
// //
// Make sure the TSEG area that we reported as a reserved memory resource // Make sure the TSEG area that we reported as a reserved memory resource
@ -618,7 +636,7 @@ InitializeRamRegions (
// //
TsegSize = mQ35TsegMbytes * SIZE_1MB; TsegSize = mQ35TsegMbytes * SIZE_1MB;
BuildMemoryAllocationHob ( BuildMemoryAllocationHob (
GetSystemMemorySizeBelow4gb() - TsegSize, GetSystemMemorySizeBelow4gb () - TsegSize,
TsegSize, TsegSize,
EfiReservedMemoryType EfiReservedMemoryType
); );

View File

@ -36,7 +36,7 @@
#include "Platform.h" #include "Platform.h"
#include "Cmos.h" #include "Cmos.h"
EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = { EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = {
{ EfiACPIMemoryNVS, 0x004 }, { EfiACPIMemoryNVS, 0x004 },
{ EfiACPIReclaimMemory, 0x008 }, { EfiACPIReclaimMemory, 0x008 },
{ EfiReservedMemoryType, 0x004 }, { EfiReservedMemoryType, 0x004 },
@ -47,8 +47,7 @@ EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = {
{ EfiMaxMemoryType, 0x000 } { EfiMaxMemoryType, 0x000 }
}; };
EFI_PEI_PPI_DESCRIPTOR mPpiBootMode[] = {
EFI_PEI_PPI_DESCRIPTOR mPpiBootMode[] = {
{ {
EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
&gEfiPeiMasterBootModePpiGuid, &gEfiPeiMasterBootModePpiGuid,
@ -56,27 +55,26 @@ EFI_PEI_PPI_DESCRIPTOR mPpiBootMode[] = {
} }
}; };
UINT16 mHostBridgeDevId;
UINT16 mHostBridgeDevId; EFI_BOOT_MODE mBootMode = BOOT_WITH_FULL_CONFIGURATION;
EFI_BOOT_MODE mBootMode = BOOT_WITH_FULL_CONFIGURATION; BOOLEAN mS3Supported = FALSE;
BOOLEAN mS3Supported = FALSE; UINT32 mMaxCpuCount;
UINT32 mMaxCpuCount;
VOID VOID
AddIoMemoryBaseSizeHob ( AddIoMemoryBaseSizeHob (
EFI_PHYSICAL_ADDRESS MemoryBase, EFI_PHYSICAL_ADDRESS MemoryBase,
UINT64 MemorySize UINT64 MemorySize
) )
{ {
BuildResourceDescriptorHob ( BuildResourceDescriptorHob (
EFI_RESOURCE_MEMORY_MAPPED_IO, EFI_RESOURCE_MEMORY_MAPPED_IO,
EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_PRESENT |
EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
EFI_RESOURCE_ATTRIBUTE_TESTED, EFI_RESOURCE_ATTRIBUTE_TESTED,
MemoryBase, MemoryBase,
MemorySize MemorySize
); );
@ -84,23 +82,23 @@ AddIoMemoryBaseSizeHob (
VOID VOID
AddReservedMemoryBaseSizeHob ( AddReservedMemoryBaseSizeHob (
EFI_PHYSICAL_ADDRESS MemoryBase, EFI_PHYSICAL_ADDRESS MemoryBase,
UINT64 MemorySize, UINT64 MemorySize,
BOOLEAN Cacheable BOOLEAN Cacheable
) )
{ {
BuildResourceDescriptorHob ( BuildResourceDescriptorHob (
EFI_RESOURCE_MEMORY_RESERVED, EFI_RESOURCE_MEMORY_RESERVED,
EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_PRESENT |
EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
(Cacheable ? (Cacheable ?
EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE | EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE : EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE :
0 0
) | ) |
EFI_RESOURCE_ATTRIBUTE_TESTED, EFI_RESOURCE_ATTRIBUTE_TESTED,
MemoryBase, MemoryBase,
MemorySize MemorySize
); );
@ -108,53 +106,50 @@ AddReservedMemoryBaseSizeHob (
VOID VOID
AddIoMemoryRangeHob ( AddIoMemoryRangeHob (
EFI_PHYSICAL_ADDRESS MemoryBase, EFI_PHYSICAL_ADDRESS MemoryBase,
EFI_PHYSICAL_ADDRESS MemoryLimit EFI_PHYSICAL_ADDRESS MemoryLimit
) )
{ {
AddIoMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryBase)); AddIoMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryBase));
} }
VOID VOID
AddMemoryBaseSizeHob ( AddMemoryBaseSizeHob (
EFI_PHYSICAL_ADDRESS MemoryBase, EFI_PHYSICAL_ADDRESS MemoryBase,
UINT64 MemorySize UINT64 MemorySize
) )
{ {
BuildResourceDescriptorHob ( BuildResourceDescriptorHob (
EFI_RESOURCE_SYSTEM_MEMORY, EFI_RESOURCE_SYSTEM_MEMORY,
EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_PRESENT |
EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE | EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE | EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
EFI_RESOURCE_ATTRIBUTE_TESTED, EFI_RESOURCE_ATTRIBUTE_TESTED,
MemoryBase, MemoryBase,
MemorySize MemorySize
); );
} }
VOID VOID
AddMemoryRangeHob ( AddMemoryRangeHob (
EFI_PHYSICAL_ADDRESS MemoryBase, EFI_PHYSICAL_ADDRESS MemoryBase,
EFI_PHYSICAL_ADDRESS MemoryLimit EFI_PHYSICAL_ADDRESS MemoryLimit
) )
{ {
AddMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryBase)); AddMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - MemoryBase));
} }
VOID VOID
MemMapInitialization ( MemMapInitialization (
VOID VOID
) )
{ {
UINT64 PciIoBase; UINT64 PciIoBase;
UINT64 PciIoSize; UINT64 PciIoSize;
RETURN_STATUS PcdStatus; RETURN_STATUS PcdStatus;
PciIoBase = 0xC000; PciIoBase = 0xC000;
PciIoSize = 0x4000; PciIoSize = 0x4000;
@ -165,7 +160,7 @@ MemMapInitialization (
BuildGuidDataHob ( BuildGuidDataHob (
&gEfiMemoryTypeInformationGuid, &gEfiMemoryTypeInformationGuid,
mDefaultMemoryTypeInformation, mDefaultMemoryTypeInformation,
sizeof(mDefaultMemoryTypeInformation) sizeof (mDefaultMemoryTypeInformation)
); );
// //
@ -179,7 +174,7 @@ MemMapInitialization (
UINT32 PciBase; UINT32 PciBase;
UINT32 PciSize; UINT32 PciSize;
TopOfLowRam = GetSystemMemorySizeBelow4gb (); TopOfLowRam = GetSystemMemorySizeBelow4gb ();
PciExBarBase = 0; PciExBarBase = 0;
if (mHostBridgeDevId == INTEL_Q35_MCH_DEVICE_ID) { if (mHostBridgeDevId == INTEL_Q35_MCH_DEVICE_ID) {
// //
@ -192,8 +187,9 @@ MemMapInitialization (
PciBase = (UINT32)(PciExBarBase + SIZE_256MB); PciBase = (UINT32)(PciExBarBase + SIZE_256MB);
} else { } else {
PciBase = (UINT32)PcdGet64 (PcdPciMmio32Base); PciBase = (UINT32)PcdGet64 (PcdPciMmio32Base);
if (PciBase == 0) if (PciBase == 0) {
PciBase = (TopOfLowRam < BASE_2GB) ? BASE_2GB : TopOfLowRam; PciBase = (TopOfLowRam < BASE_2GB) ? BASE_2GB : TopOfLowRam;
}
} }
// //
@ -242,10 +238,14 @@ MemMapInitialization (
// uncacheable reserved memory right here. // uncacheable reserved memory right here.
// //
AddReservedMemoryBaseSizeHob (PciExBarBase, SIZE_256MB, FALSE); AddReservedMemoryBaseSizeHob (PciExBarBase, SIZE_256MB, FALSE);
BuildMemoryAllocationHob (PciExBarBase, SIZE_256MB, BuildMemoryAllocationHob (
EfiReservedMemoryType); PciExBarBase,
SIZE_256MB,
EfiReservedMemoryType
);
} }
AddIoMemoryBaseSizeHob (PcdGet32(PcdCpuLocalApicBaseAddress), SIZE_1MB);
AddIoMemoryBaseSizeHob (PcdGet32 (PcdCpuLocalApicBaseAddress), SIZE_1MB);
// //
// On Q35, the IO Port space is available for PCI resource allocations from // On Q35, the IO Port space is available for PCI resource allocations from
@ -287,8 +287,8 @@ PciExBarInitialization (
) )
{ {
union { union {
UINT64 Uint64; UINT64 Uint64;
UINT32 Uint32[2]; UINT32 Uint32[2];
} PciExBarBase; } PciExBarBase;
// //
@ -327,13 +327,13 @@ MiscInitialization (
VOID VOID
) )
{ {
UINTN PmCmd; UINTN PmCmd;
UINTN Pmba; UINTN Pmba;
UINT32 PmbaAndVal; UINT32 PmbaAndVal;
UINT32 PmbaOrVal; UINT32 PmbaOrVal;
UINTN AcpiCtlReg; UINTN AcpiCtlReg;
UINT8 AcpiEnBit; UINT8 AcpiEnBit;
RETURN_STATUS PcdStatus; RETURN_STATUS PcdStatus;
// //
// Disable A20 Mask // Disable A20 Mask
@ -370,11 +370,16 @@ MiscInitialization (
AcpiEnBit = ICH9_ACPI_CNTL_ACPI_EN; AcpiEnBit = ICH9_ACPI_CNTL_ACPI_EN;
break; break;
default: default:
DEBUG ((DEBUG_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n", DEBUG ((
__FUNCTION__, mHostBridgeDevId)); DEBUG_ERROR,
"%a: Unknown Host Bridge Device ID: 0x%04x\n",
__FUNCTION__,
mHostBridgeDevId
));
ASSERT (FALSE); ASSERT (FALSE);
return; return;
} }
PcdStatus = PcdSet16S (PcdOvmfHostBridgePciDevId, mHostBridgeDevId); PcdStatus = PcdSet16S (PcdOvmfHostBridgePciDevId, mHostBridgeDevId);
ASSERT_RETURN_ERROR (PcdStatus); ASSERT_RETURN_ERROR (PcdStatus);
@ -417,17 +422,17 @@ MiscInitialization (
} }
} }
VOID VOID
BootModeInitialization ( BootModeInitialization (
VOID VOID
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
if (CmosRead8 (0xF) == 0xFE) { if (CmosRead8 (0xF) == 0xFE) {
mBootMode = BOOT_ON_S3_RESUME; mBootMode = BOOT_ON_S3_RESUME;
} }
CmosWrite8 (0xF, 0x00); CmosWrite8 (0xF, 0x00);
Status = PeiServicesSetBootMode (mBootMode); Status = PeiServicesSetBootMode (mBootMode);
@ -437,13 +442,12 @@ BootModeInitialization (
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
} }
VOID VOID
ReserveEmuVariableNvStore ( ReserveEmuVariableNvStore (
) )
{ {
EFI_PHYSICAL_ADDRESS VariableStore; EFI_PHYSICAL_ADDRESS VariableStore;
RETURN_STATUS PcdStatus; RETURN_STATUS PcdStatus;
// //
// Allocate storage for NV variables early on so it will be // Allocate storage for NV variables early on so it will be
@ -453,25 +457,25 @@ ReserveEmuVariableNvStore (
// //
VariableStore = VariableStore =
(EFI_PHYSICAL_ADDRESS)(UINTN) (EFI_PHYSICAL_ADDRESS)(UINTN)
AllocateRuntimePages ( AllocateRuntimePages (
EFI_SIZE_TO_PAGES (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)) EFI_SIZE_TO_PAGES (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize))
); );
DEBUG ((DEBUG_INFO, DEBUG ((
"Reserved variable store memory: 0x%lX; size: %dkb\n", DEBUG_INFO,
VariableStore, "Reserved variable store memory: 0x%lX; size: %dkb\n",
(2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)) / 1024 VariableStore,
)); (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)) / 1024
));
PcdStatus = PcdSet64S (PcdEmuVariableNvStoreReserved, VariableStore); PcdStatus = PcdSet64S (PcdEmuVariableNvStoreReserved, VariableStore);
ASSERT_RETURN_ERROR (PcdStatus); ASSERT_RETURN_ERROR (PcdStatus);
} }
VOID VOID
DebugDumpCmos ( DebugDumpCmos (
VOID VOID
) )
{ {
UINT32 Loop; UINT32 Loop;
DEBUG ((DEBUG_INFO, "CMOS:\n")); DEBUG ((DEBUG_INFO, "CMOS:\n"));
@ -479,6 +483,7 @@ DebugDumpCmos (
if ((Loop % 0x10) == 0) { if ((Loop % 0x10) == 0) {
DEBUG ((DEBUG_INFO, "%02x:", Loop)); DEBUG ((DEBUG_INFO, "%02x:", Loop));
} }
DEBUG ((DEBUG_INFO, " %02x", CmosRead8 (Loop))); DEBUG ((DEBUG_INFO, " %02x", CmosRead8 (Loop)));
if ((Loop % 0x10) == 0xf) { if ((Loop % 0x10) == 0xf) {
DEBUG ((DEBUG_INFO, "\n")); DEBUG ((DEBUG_INFO, "\n"));
@ -486,27 +491,34 @@ DebugDumpCmos (
} }
} }
VOID VOID
S3Verification ( S3Verification (
VOID VOID
) )
{ {
#if defined (MDE_CPU_X64) #if defined (MDE_CPU_X64)
if (FeaturePcdGet (PcdSmmSmramRequire) && mS3Supported) { if (FeaturePcdGet (PcdSmmSmramRequire) && mS3Supported) {
DEBUG ((DEBUG_ERROR, DEBUG ((
"%a: S3Resume2Pei doesn't support X64 PEI + SMM yet.\n", __FUNCTION__)); DEBUG_ERROR,
DEBUG ((DEBUG_ERROR, "%a: S3Resume2Pei doesn't support X64 PEI + SMM yet.\n",
__FUNCTION__
));
DEBUG ((
DEBUG_ERROR,
"%a: Please disable S3 on the QEMU command line (see the README),\n", "%a: Please disable S3 on the QEMU command line (see the README),\n",
__FUNCTION__)); __FUNCTION__
DEBUG ((DEBUG_ERROR, ));
"%a: or build OVMF with \"OvmfPkgIa32X64.dsc\".\n", __FUNCTION__)); DEBUG ((
DEBUG_ERROR,
"%a: or build OVMF with \"OvmfPkgIa32X64.dsc\".\n",
__FUNCTION__
));
ASSERT (FALSE); ASSERT (FALSE);
CpuDeadLoop (); CpuDeadLoop ();
} }
#endif
}
#endif
}
/** /**
Fetch the number of boot CPUs from QEMU and expose it to UefiCpuPkg modules. Fetch the number of boot CPUs from QEMU and expose it to UefiCpuPkg modules.
@ -517,8 +529,8 @@ MaxCpuCountInitialization (
VOID VOID
) )
{ {
UINT16 ProcessorCount = 0; UINT16 ProcessorCount = 0;
RETURN_STATUS PcdStatus; RETURN_STATUS PcdStatus;
// //
// If the fw_cfg key or fw_cfg entirely is unavailable, load mMaxCpuCount // If the fw_cfg key or fw_cfg entirely is unavailable, load mMaxCpuCount
@ -528,6 +540,7 @@ MaxCpuCountInitialization (
mMaxCpuCount = PcdGet32 (PcdCpuMaxLogicalProcessorNumber); mMaxCpuCount = PcdGet32 (PcdCpuMaxLogicalProcessorNumber);
return; return;
} }
// //
// Otherwise, set mMaxCpuCount to the value reported by QEMU. // Otherwise, set mMaxCpuCount to the value reported by QEMU.
// //
@ -542,11 +555,14 @@ MaxCpuCountInitialization (
ASSERT_RETURN_ERROR (PcdStatus); ASSERT_RETURN_ERROR (PcdStatus);
PcdStatus = PcdSet32S (PcdCpuApInitTimeOutInMicroSeconds, MAX_UINT32); PcdStatus = PcdSet32S (PcdCpuApInitTimeOutInMicroSeconds, MAX_UINT32);
ASSERT_RETURN_ERROR (PcdStatus); ASSERT_RETURN_ERROR (PcdStatus);
DEBUG ((DEBUG_INFO, "%a: QEMU reports %d processor(s)\n", __FUNCTION__, DEBUG ((
ProcessorCount)); DEBUG_INFO,
"%a: QEMU reports %d processor(s)\n",
__FUNCTION__,
ProcessorCount
));
} }
/** /**
Perform Platform PEI initialization. Perform Platform PEI initialization.
@ -596,6 +612,7 @@ InitializePlatform (
if (!FeaturePcdGet (PcdSmmSmramRequire)) { if (!FeaturePcdGet (PcdSmmSmramRequire)) {
ReserveEmuVariableNvStore (); ReserveEmuVariableNvStore ();
} }
PeiFvInitialization (); PeiFvInitialization ();
MemMapInitialization (); MemMapInitialization ();
NoexecDxeInitialization (); NoexecDxeInitialization ();

View File

@ -14,33 +14,33 @@
VOID VOID
AddIoMemoryBaseSizeHob ( AddIoMemoryBaseSizeHob (
EFI_PHYSICAL_ADDRESS MemoryBase, EFI_PHYSICAL_ADDRESS MemoryBase,
UINT64 MemorySize UINT64 MemorySize
); );
VOID VOID
AddIoMemoryRangeHob ( AddIoMemoryRangeHob (
EFI_PHYSICAL_ADDRESS MemoryBase, EFI_PHYSICAL_ADDRESS MemoryBase,
EFI_PHYSICAL_ADDRESS MemoryLimit EFI_PHYSICAL_ADDRESS MemoryLimit
); );
VOID VOID
AddMemoryBaseSizeHob ( AddMemoryBaseSizeHob (
EFI_PHYSICAL_ADDRESS MemoryBase, EFI_PHYSICAL_ADDRESS MemoryBase,
UINT64 MemorySize UINT64 MemorySize
); );
VOID VOID
AddMemoryRangeHob ( AddMemoryRangeHob (
EFI_PHYSICAL_ADDRESS MemoryBase, EFI_PHYSICAL_ADDRESS MemoryBase,
EFI_PHYSICAL_ADDRESS MemoryLimit EFI_PHYSICAL_ADDRESS MemoryLimit
); );
VOID VOID
AddReservedMemoryBaseSizeHob ( AddReservedMemoryBaseSizeHob (
EFI_PHYSICAL_ADDRESS MemoryBase, EFI_PHYSICAL_ADDRESS MemoryBase,
UINT64 MemorySize, UINT64 MemorySize,
BOOLEAN Cacheable BOOLEAN Cacheable
); );
VOID VOID
@ -113,25 +113,25 @@ AmdSevInitialize (
VOID VOID
); );
extern BOOLEAN mXen; extern BOOLEAN mXen;
VOID VOID
XenPublishRamRegions ( XenPublishRamRegions (
VOID VOID
); );
extern EFI_BOOT_MODE mBootMode; extern EFI_BOOT_MODE mBootMode;
extern BOOLEAN mS3Supported; extern BOOLEAN mS3Supported;
extern UINT8 mPhysMemAddressWidth; extern UINT8 mPhysMemAddressWidth;
extern UINT32 mMaxCpuCount; extern UINT32 mMaxCpuCount;
extern UINT16 mHostBridgeDevId; extern UINT16 mHostBridgeDevId;
extern BOOLEAN mQ35SmramAtDefaultSmbase; extern BOOLEAN mQ35SmramAtDefaultSmbase;
extern UINT32 mQemuUc32Base; extern UINT32 mQemuUc32Base;
#endif // _PLATFORM_PEI_H_INCLUDED_ #endif // _PLATFORM_PEI_H_INCLUDED_

View File

@ -7,8 +7,8 @@
#include "SmbiosPlatformDxe.h" #include "SmbiosPlatformDxe.h"
#define BHYVE_SMBIOS_PHYSICAL_ADDRESS 0x000F0000 #define BHYVE_SMBIOS_PHYSICAL_ADDRESS 0x000F0000
#define BHYVE_SMBIOS_PHYSICAL_END 0x000FFFFF #define BHYVE_SMBIOS_PHYSICAL_END 0x000FFFFF
/** /**
Locates the bhyve SMBIOS data if it exists Locates the bhyve SMBIOS data if it exists
@ -24,18 +24,17 @@ GetBhyveSmbiosTables (
UINT8 *BhyveSmbiosPtr; UINT8 *BhyveSmbiosPtr;
SMBIOS_TABLE_ENTRY_POINT *BhyveSmbiosEntryPointStructure; SMBIOS_TABLE_ENTRY_POINT *BhyveSmbiosEntryPointStructure;
for (BhyveSmbiosPtr = (UINT8*)(UINTN) BHYVE_SMBIOS_PHYSICAL_ADDRESS; for (BhyveSmbiosPtr = (UINT8 *)(UINTN)BHYVE_SMBIOS_PHYSICAL_ADDRESS;
BhyveSmbiosPtr < (UINT8*)(UINTN) BHYVE_SMBIOS_PHYSICAL_END; BhyveSmbiosPtr < (UINT8 *)(UINTN)BHYVE_SMBIOS_PHYSICAL_END;
BhyveSmbiosPtr += 0x10) { BhyveSmbiosPtr += 0x10)
{
BhyveSmbiosEntryPointStructure = (SMBIOS_TABLE_ENTRY_POINT *) BhyveSmbiosPtr; BhyveSmbiosEntryPointStructure = (SMBIOS_TABLE_ENTRY_POINT *)BhyveSmbiosPtr;
if (!AsciiStrnCmp ((CHAR8 *) BhyveSmbiosEntryPointStructure->AnchorString, "_SM_", 4) &&
!AsciiStrnCmp ((CHAR8 *) BhyveSmbiosEntryPointStructure->IntermediateAnchorString, "_DMI_", 5) &&
IsEntryPointStructureValid (BhyveSmbiosEntryPointStructure)) {
if (!AsciiStrnCmp ((CHAR8 *)BhyveSmbiosEntryPointStructure->AnchorString, "_SM_", 4) &&
!AsciiStrnCmp ((CHAR8 *)BhyveSmbiosEntryPointStructure->IntermediateAnchorString, "_DMI_", 5) &&
IsEntryPointStructureValid (BhyveSmbiosEntryPointStructure))
{
return BhyveSmbiosEntryPointStructure; return BhyveSmbiosEntryPointStructure;
} }
} }

View File

@ -20,34 +20,34 @@
// //
#pragma pack(1) #pragma pack(1)
typedef struct { typedef struct {
SMBIOS_TABLE_TYPE0 Base; SMBIOS_TABLE_TYPE0 Base;
UINT8 Strings[sizeof(TYPE0_STRINGS)]; UINT8 Strings[sizeof (TYPE0_STRINGS)];
} OVMF_TYPE0; } OVMF_TYPE0;
#pragma pack() #pragma pack()
STATIC CONST OVMF_TYPE0 mOvmfDefaultType0 = { STATIC CONST OVMF_TYPE0 mOvmfDefaultType0 = {
{ {
// SMBIOS_STRUCTURE Hdr // SMBIOS_STRUCTURE Hdr
{ {
EFI_SMBIOS_TYPE_BIOS_INFORMATION, // UINT8 Type EFI_SMBIOS_TYPE_BIOS_INFORMATION, // UINT8 Type
sizeof (SMBIOS_TABLE_TYPE0), // UINT8 Length sizeof (SMBIOS_TABLE_TYPE0), // UINT8 Length
}, },
1, // SMBIOS_TABLE_STRING Vendor 1, // SMBIOS_TABLE_STRING Vendor
2, // SMBIOS_TABLE_STRING BiosVersion 2, // SMBIOS_TABLE_STRING BiosVersion
0xE800,// UINT16 BiosSegment 0xE800, // UINT16 BiosSegment
3, // SMBIOS_TABLE_STRING BiosReleaseDate 3, // SMBIOS_TABLE_STRING BiosReleaseDate
0, // UINT8 BiosSize 0, // UINT8 BiosSize
{ // MISC_BIOS_CHARACTERISTICS BiosCharacteristics { // MISC_BIOS_CHARACTERISTICS BiosCharacteristics
0, // Reserved :2 0, // Reserved :2
0, // Unknown :1 0, // Unknown :1
1, // BiosCharacteristicsNotSupported :1 1, // BiosCharacteristicsNotSupported :1
// Remaining BiosCharacteristics bits left unset :60 // Remaining BiosCharacteristics bits left unset :60
}, },
{ // BIOSCharacteristicsExtensionBytes[2] { // BIOSCharacteristicsExtensionBytes[2]
0, // BiosReserved 0, // BiosReserved
0x1C // SystemReserved = VirtualMachineSupported | 0x1C // SystemReserved = VirtualMachineSupported |
// UefiSpecificationSupported | // UefiSpecificationSupported |
// TargetContentDistributionEnabled // TargetContentDistributionEnabled
}, },
0, // UINT8 SystemBiosMajorRelease 0, // UINT8 SystemBiosMajorRelease
0, // UINT8 SystemBiosMinorRelease 0, // UINT8 SystemBiosMinorRelease
@ -58,7 +58,6 @@ STATIC CONST OVMF_TYPE0 mOvmfDefaultType0 = {
TYPE0_STRINGS TYPE0_STRINGS
}; };
/** /**
Validates the SMBIOS entry point structure Validates the SMBIOS entry point structure
@ -73,17 +72,17 @@ IsEntryPointStructureValid (
IN SMBIOS_TABLE_ENTRY_POINT *EntryPointStructure IN SMBIOS_TABLE_ENTRY_POINT *EntryPointStructure
) )
{ {
UINTN Index; UINTN Index;
UINT8 Length; UINT8 Length;
UINT8 Checksum; UINT8 Checksum;
UINT8 *BytePtr; UINT8 *BytePtr;
BytePtr = (UINT8*) EntryPointStructure; BytePtr = (UINT8 *)EntryPointStructure;
Length = EntryPointStructure->EntryPointLength; Length = EntryPointStructure->EntryPointLength;
Checksum = 0; Checksum = 0;
for (Index = 0; Index < Length; Index++) { for (Index = 0; Index < Length; Index++) {
Checksum = Checksum + (UINT8) BytePtr[Index]; Checksum = Checksum + (UINT8)BytePtr[Index];
} }
if (Checksum != 0) { if (Checksum != 0) {
@ -93,7 +92,6 @@ IsEntryPointStructureValid (
} }
} }
/** /**
Get SMBIOS record length. Get SMBIOS record length.
@ -102,7 +100,7 @@ IsEntryPointStructureValid (
**/ **/
UINTN UINTN
SmbiosTableLength ( SmbiosTableLength (
IN SMBIOS_STRUCTURE_POINTER SmbiosTable IN SMBIOS_STRUCTURE_POINTER SmbiosTable
) )
{ {
CHAR8 *AChar; CHAR8 *AChar;
@ -114,14 +112,14 @@ SmbiosTableLength (
// Each structure shall be terminated by a double-null (SMBIOS spec.7.1) // Each structure shall be terminated by a double-null (SMBIOS spec.7.1)
// //
while ((*AChar != 0) || (*(AChar + 1) != 0)) { while ((*AChar != 0) || (*(AChar + 1) != 0)) {
AChar ++; AChar++;
} }
Length = ((UINTN)AChar - (UINTN)SmbiosTable.Raw + 2); Length = ((UINTN)AChar - (UINTN)SmbiosTable.Raw + 2);
return Length; return Length;
} }
/** /**
Install all structures from the given SMBIOS structures block Install all structures from the given SMBIOS structures block
@ -131,8 +129,8 @@ SmbiosTableLength (
**/ **/
EFI_STATUS EFI_STATUS
InstallAllStructures ( InstallAllStructures (
IN EFI_SMBIOS_PROTOCOL *Smbios, IN EFI_SMBIOS_PROTOCOL *Smbios,
IN UINT8 *TableAddress IN UINT8 *TableAddress
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -152,12 +150,12 @@ InstallAllStructures (
// Log the SMBIOS data for this structure // Log the SMBIOS data for this structure
// //
SmbiosHandle = SmbiosTable.Hdr->Handle; SmbiosHandle = SmbiosTable.Hdr->Handle;
Status = Smbios->Add ( Status = Smbios->Add (
Smbios, Smbios,
NULL, NULL,
&SmbiosHandle, &SmbiosHandle,
(EFI_SMBIOS_TABLE_HEADER*) SmbiosTable.Raw (EFI_SMBIOS_TABLE_HEADER *)SmbiosTable.Raw
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
if (SmbiosTable.Hdr->Type == 0) { if (SmbiosTable.Hdr->Type == 0) {
@ -175,19 +173,18 @@ InstallAllStructures (
// Add OVMF default Type 0 (BIOS Information) table // Add OVMF default Type 0 (BIOS Information) table
// //
SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED; SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
Status = Smbios->Add ( Status = Smbios->Add (
Smbios, Smbios,
NULL, NULL,
&SmbiosHandle, &SmbiosHandle,
(EFI_SMBIOS_TABLE_HEADER*) &mOvmfDefaultType0 (EFI_SMBIOS_TABLE_HEADER *)&mOvmfDefaultType0
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Installs SMBIOS information for OVMF Installs SMBIOS information for OVMF
@ -201,8 +198,8 @@ InstallAllStructures (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
SmbiosTablePublishEntry ( SmbiosTablePublishEntry (
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -216,7 +213,7 @@ SmbiosTablePublishEntry (
Status = gBS->LocateProtocol ( Status = gBS->LocateProtocol (
&gEfiSmbiosProtocolGuid, &gEfiSmbiosProtocolGuid,
NULL, NULL,
(VOID**)&Smbios (VOID **)&Smbios
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
@ -227,7 +224,7 @@ SmbiosTablePublishEntry (
// //
EntryPointStructure = GetBhyveSmbiosTables (); EntryPointStructure = GetBhyveSmbiosTables ();
if (EntryPointStructure != NULL) { if (EntryPointStructure != NULL) {
SmbiosTables = (UINT8*)(UINTN)EntryPointStructure->TableAddress; SmbiosTables = (UINT8 *)(UINTN)EntryPointStructure->TableAddress;
} }
if (SmbiosTables != NULL) { if (SmbiosTables != NULL) {

View File

@ -21,7 +21,6 @@
#include <Library/MemoryAllocationLib.h> #include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h> #include <Library/UefiBootServicesTableLib.h>
/** /**
Locates the bhyve SMBIOS data if it exists Locates the bhyve SMBIOS data if it exists
@ -33,7 +32,6 @@ GetBhyveSmbiosTables (
VOID VOID
); );
/** /**
Validates the SMBIOS entry point structure Validates the SMBIOS entry point structure

View File

@ -19,10 +19,10 @@
#pragma pack (1) #pragma pack (1)
typedef struct { typedef struct {
UINT8 Type; UINT8 Type;
UINT8 Size; UINT8 Size;
UINT16 MachineType; UINT16 MachineType;
UINT32 EntryPoint; UINT32 EntryPoint;
} PE_COMPAT_TYPE1; } PE_COMPAT_TYPE1;
#pragma pack () #pragma pack ()
@ -30,9 +30,9 @@ STATIC
BOOLEAN BOOLEAN
EFIAPI EFIAPI
IsImageSupported ( IsImageSupported (
IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This, IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This,
IN UINT16 ImageType, IN UINT16 ImageType,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL IN EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL
) )
{ {
return ImageType == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION; return ImageType == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION;
@ -42,16 +42,16 @@ STATIC
EFI_IMAGE_ENTRY_POINT EFI_IMAGE_ENTRY_POINT
EFIAPI EFIAPI
GetCompatEntryPoint ( GetCompatEntryPoint (
IN EFI_PHYSICAL_ADDRESS ImageBase IN EFI_PHYSICAL_ADDRESS ImageBase
) )
{ {
EFI_IMAGE_DOS_HEADER *DosHdr; EFI_IMAGE_DOS_HEADER *DosHdr;
UINTN PeCoffHeaderOffset; UINTN PeCoffHeaderOffset;
EFI_IMAGE_NT_HEADERS32 *Pe32; EFI_IMAGE_NT_HEADERS32 *Pe32;
EFI_IMAGE_SECTION_HEADER *Section; EFI_IMAGE_SECTION_HEADER *Section;
UINTN NumberOfSections; UINTN NumberOfSections;
PE_COMPAT_TYPE1 *PeCompat; PE_COMPAT_TYPE1 *PeCompat;
UINTN PeCompatEnd; UINTN PeCompatEnd;
DosHdr = (EFI_IMAGE_DOS_HEADER *)(UINTN)ImageBase; DosHdr = (EFI_IMAGE_DOS_HEADER *)(UINTN)ImageBase;
if (DosHdr->e_magic != EFI_IMAGE_DOS_SIGNATURE) { if (DosHdr->e_magic != EFI_IMAGE_DOS_SIGNATURE) {
@ -59,7 +59,7 @@ GetCompatEntryPoint (
} }
PeCoffHeaderOffset = DosHdr->e_lfanew; PeCoffHeaderOffset = DosHdr->e_lfanew;
Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)ImageBase + PeCoffHeaderOffset); Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)ImageBase + PeCoffHeaderOffset);
Section = (EFI_IMAGE_SECTION_HEADER *)((UINTN)&Pe32->OptionalHeader + Section = (EFI_IMAGE_SECTION_HEADER *)((UINTN)&Pe32->OptionalHeader +
Pe32->FileHeader.SizeOfOptionalHeader); Pe32->FileHeader.SizeOfOptionalHeader);
@ -70,22 +70,25 @@ GetCompatEntryPoint (
// //
// Dereference the section contents to find the mixed mode entry point // Dereference the section contents to find the mixed mode entry point
// //
PeCompat = (PE_COMPAT_TYPE1 *)((UINTN)ImageBase + Section->VirtualAddress); PeCompat = (PE_COMPAT_TYPE1 *)((UINTN)ImageBase + Section->VirtualAddress);
PeCompatEnd = (UINTN)(VOID *)PeCompat + Section->Misc.VirtualSize; PeCompatEnd = (UINTN)(VOID *)PeCompat + Section->Misc.VirtualSize;
while (PeCompat->Type != 0 && (UINTN)(VOID *)PeCompat < PeCompatEnd) { while (PeCompat->Type != 0 && (UINTN)(VOID *)PeCompat < PeCompatEnd) {
if (PeCompat->Type == 1 && if ((PeCompat->Type == 1) &&
PeCompat->Size >= sizeof (PE_COMPAT_TYPE1) && (PeCompat->Size >= sizeof (PE_COMPAT_TYPE1)) &&
EFI_IMAGE_MACHINE_TYPE_SUPPORTED (PeCompat->MachineType)) { EFI_IMAGE_MACHINE_TYPE_SUPPORTED (PeCompat->MachineType))
{
return (EFI_IMAGE_ENTRY_POINT)((UINTN)ImageBase + PeCompat->EntryPoint); return (EFI_IMAGE_ENTRY_POINT)((UINTN)ImageBase + PeCompat->EntryPoint);
} }
PeCompat = (PE_COMPAT_TYPE1 *)((UINTN)PeCompat + PeCompat->Size); PeCompat = (PE_COMPAT_TYPE1 *)((UINTN)PeCompat + PeCompat->Size);
ASSERT ((UINTN)(VOID *)PeCompat < PeCompatEnd); ASSERT ((UINTN)(VOID *)PeCompat < PeCompatEnd);
} }
} }
Section++; Section++;
} }
return NULL; return NULL;
} }
@ -93,13 +96,13 @@ STATIC
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
RegisterImage ( RegisterImage (
IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This, IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This,
IN EFI_PHYSICAL_ADDRESS ImageBase, IN EFI_PHYSICAL_ADDRESS ImageBase,
IN UINT64 ImageSize, IN UINT64 ImageSize,
IN OUT EFI_IMAGE_ENTRY_POINT *EntryPoint IN OUT EFI_IMAGE_ENTRY_POINT *EntryPoint
) )
{ {
EFI_IMAGE_ENTRY_POINT CompatEntryPoint; EFI_IMAGE_ENTRY_POINT CompatEntryPoint;
CompatEntryPoint = GetCompatEntryPoint (ImageBase); CompatEntryPoint = GetCompatEntryPoint (ImageBase);
if (CompatEntryPoint == NULL) { if (CompatEntryPoint == NULL) {
@ -114,14 +117,14 @@ STATIC
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
UnregisterImage ( UnregisterImage (
IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This, IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This,
IN EFI_PHYSICAL_ADDRESS ImageBase IN EFI_PHYSICAL_ADDRESS ImageBase
) )
{ {
return EFI_SUCCESS; return EFI_SUCCESS;
} }
STATIC EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL mCompatLoaderPeCoffEmuProtocol = { STATIC EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL mCompatLoaderPeCoffEmuProtocol = {
IsImageSupported, IsImageSupported,
RegisterImage, RegisterImage,
UnregisterImage, UnregisterImage,
@ -136,8 +139,10 @@ CompatImageLoaderDxeEntryPoint (
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
return gBS->InstallProtocolInterface (&ImageHandle, return gBS->InstallProtocolInterface (
&ImageHandle,
&gEdkiiPeCoffImageEmulatorProtocolGuid, &gEdkiiPeCoffImageEmulatorProtocolGuid,
EFI_NATIVE_INTERFACE, EFI_NATIVE_INTERFACE,
&mCompatLoaderPeCoffEmuProtocol); &mCompatLoaderPeCoffEmuProtocol
);
} }

View File

@ -18,6 +18,6 @@ typedef UINT32 APIC_ID;
// //
// The PrintLib conversion specification for formatting an APIC_ID. // The PrintLib conversion specification for formatting an APIC_ID.
// //
#define FMT_APIC_ID "0x%08x" #define FMT_APIC_ID "0x%08x"
#endif // APIC_ID_H_ #endif // APIC_ID_H_

View File

@ -28,19 +28,19 @@
// //
// We use this protocol for accessing IO Ports. // We use this protocol for accessing IO Ports.
// //
STATIC EFI_MM_CPU_IO_PROTOCOL *mMmCpuIo; STATIC EFI_MM_CPU_IO_PROTOCOL *mMmCpuIo;
// //
// The following protocol is used to report the addition or removal of a CPU to // The following protocol is used to report the addition or removal of a CPU to
// the SMM CPU driver (PiSmmCpuDxeSmm). // the SMM CPU driver (PiSmmCpuDxeSmm).
// //
STATIC EFI_SMM_CPU_SERVICE_PROTOCOL *mMmCpuService; STATIC EFI_SMM_CPU_SERVICE_PROTOCOL *mMmCpuService;
// //
// These structures serve as communication side-channels between the // These structures serve as communication side-channels between the
// EFI_SMM_CPU_SERVICE_PROTOCOL consumer (i.e., this driver) and provider // EFI_SMM_CPU_SERVICE_PROTOCOL consumer (i.e., this driver) and provider
// (i.e., PiSmmCpuDxeSmm). // (i.e., PiSmmCpuDxeSmm).
// //
STATIC CPU_HOT_PLUG_DATA *mCpuHotPlugData; STATIC CPU_HOT_PLUG_DATA *mCpuHotPlugData;
STATIC CPU_HOT_EJECT_DATA *mCpuHotEjectData; STATIC CPU_HOT_EJECT_DATA *mCpuHotEjectData;
// //
// SMRAM arrays for fetching the APIC IDs of processors with pending events (of // SMRAM arrays for fetching the APIC IDs of processors with pending events (of
// known event types), for the time of just one MMI. // known event types), for the time of just one MMI.
@ -56,18 +56,18 @@ STATIC CPU_HOT_EJECT_DATA *mCpuHotEjectData;
// in a single MMI. The numbers of used (populated) elements in the arrays are // in a single MMI. The numbers of used (populated) elements in the arrays are
// determined on every MMI separately. // determined on every MMI separately.
// //
STATIC APIC_ID *mPluggedApicIds; STATIC APIC_ID *mPluggedApicIds;
STATIC APIC_ID *mToUnplugApicIds; STATIC APIC_ID *mToUnplugApicIds;
STATIC UINT32 *mToUnplugSelectors; STATIC UINT32 *mToUnplugSelectors;
// //
// Address of the non-SMRAM reserved memory page that contains the Post-SMM Pen // Address of the non-SMRAM reserved memory page that contains the Post-SMM Pen
// for hot-added CPUs. // for hot-added CPUs.
// //
STATIC UINT32 mPostSmmPenAddress; STATIC UINT32 mPostSmmPenAddress;
// //
// Represents the registration of the CPU Hotplug MMI handler. // Represents the registration of the CPU Hotplug MMI handler.
// //
STATIC EFI_HANDLE mDispatchHandle; STATIC EFI_HANDLE mDispatchHandle;
/** /**
Process CPUs that have been hot-added, per QemuCpuhpCollectApicIds(). Process CPUs that have been hot-added, per QemuCpuhpCollectApicIds().
@ -93,13 +93,13 @@ STATIC EFI_HANDLE mDispatchHandle;
STATIC STATIC
EFI_STATUS EFI_STATUS
ProcessHotAddedCpus ( ProcessHotAddedCpus (
IN APIC_ID *PluggedApicIds, IN APIC_ID *PluggedApicIds,
IN UINT32 PluggedCount IN UINT32 PluggedCount
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINT32 PluggedIdx; UINT32 PluggedIdx;
UINT32 NewSlot; UINT32 NewSlot;
// //
// The Post-SMM Pen need not be reinstalled multiple times within a single // The Post-SMM Pen need not be reinstalled multiple times within a single
@ -110,11 +110,11 @@ ProcessHotAddedCpus (
SmbaseReinstallPostSmmPen (mPostSmmPenAddress); SmbaseReinstallPostSmmPen (mPostSmmPenAddress);
PluggedIdx = 0; PluggedIdx = 0;
NewSlot = 0; NewSlot = 0;
while (PluggedIdx < PluggedCount) { while (PluggedIdx < PluggedCount) {
APIC_ID NewApicId; APIC_ID NewApicId;
UINT32 CheckSlot; UINT32 CheckSlot;
UINTN NewProcessorNumberByProtocol; UINTN NewProcessorNumberByProtocol;
NewApicId = PluggedApicIds[PluggedIdx]; NewApicId = PluggedApicIds[PluggedIdx];
@ -123,14 +123,21 @@ ProcessHotAddedCpus (
// //
for (CheckSlot = 0; for (CheckSlot = 0;
CheckSlot < mCpuHotPlugData->ArrayLength; CheckSlot < mCpuHotPlugData->ArrayLength;
CheckSlot++) { CheckSlot++)
{
if (mCpuHotPlugData->ApicId[CheckSlot] == NewApicId) { if (mCpuHotPlugData->ApicId[CheckSlot] == NewApicId) {
break; break;
} }
} }
if (CheckSlot < mCpuHotPlugData->ArrayLength) { if (CheckSlot < mCpuHotPlugData->ArrayLength) {
DEBUG ((DEBUG_VERBOSE, "%a: APIC ID " FMT_APIC_ID " was hot-plugged " DEBUG ((
"before; ignoring it\n", __FUNCTION__, NewApicId)); DEBUG_VERBOSE,
"%a: APIC ID " FMT_APIC_ID " was hot-plugged "
"before; ignoring it\n",
__FUNCTION__,
NewApicId
));
PluggedIdx++; PluggedIdx++;
continue; continue;
} }
@ -139,12 +146,18 @@ ProcessHotAddedCpus (
// Find the first empty slot in CPU_HOT_PLUG_DATA. // Find the first empty slot in CPU_HOT_PLUG_DATA.
// //
while (NewSlot < mCpuHotPlugData->ArrayLength && while (NewSlot < mCpuHotPlugData->ArrayLength &&
mCpuHotPlugData->ApicId[NewSlot] != MAX_UINT64) { mCpuHotPlugData->ApicId[NewSlot] != MAX_UINT64)
{
NewSlot++; NewSlot++;
} }
if (NewSlot == mCpuHotPlugData->ArrayLength) { if (NewSlot == mCpuHotPlugData->ArrayLength) {
DEBUG ((DEBUG_ERROR, "%a: no room for APIC ID " FMT_APIC_ID "\n", DEBUG ((
__FUNCTION__, NewApicId)); DEBUG_ERROR,
"%a: no room for APIC ID " FMT_APIC_ID "\n",
__FUNCTION__,
NewApicId
));
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
@ -156,8 +169,11 @@ ProcessHotAddedCpus (
// //
// Relocate the SMBASE of the new CPU. // Relocate the SMBASE of the new CPU.
// //
Status = SmbaseRelocate (NewApicId, mCpuHotPlugData->SmBase[NewSlot], Status = SmbaseRelocate (
mPostSmmPenAddress); NewApicId,
mCpuHotPlugData->SmBase[NewSlot],
mPostSmmPenAddress
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto RevokeNewSlot; goto RevokeNewSlot;
} }
@ -165,18 +181,31 @@ ProcessHotAddedCpus (
// //
// Add the new CPU with EFI_SMM_CPU_SERVICE_PROTOCOL. // Add the new CPU with EFI_SMM_CPU_SERVICE_PROTOCOL.
// //
Status = mMmCpuService->AddProcessor (mMmCpuService, NewApicId, Status = mMmCpuService->AddProcessor (
&NewProcessorNumberByProtocol); mMmCpuService,
NewApicId,
&NewProcessorNumberByProtocol
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: AddProcessor(" FMT_APIC_ID "): %r\n", DEBUG ((
__FUNCTION__, NewApicId, Status)); DEBUG_ERROR,
"%a: AddProcessor(" FMT_APIC_ID "): %r\n",
__FUNCTION__,
NewApicId,
Status
));
goto RevokeNewSlot; goto RevokeNewSlot;
} }
DEBUG ((DEBUG_INFO, "%a: hot-added APIC ID " FMT_APIC_ID ", SMBASE 0x%Lx, " DEBUG ((
"EFI_SMM_CPU_SERVICE_PROTOCOL assigned number %Lu\n", __FUNCTION__, DEBUG_INFO,
NewApicId, (UINT64)mCpuHotPlugData->SmBase[NewSlot], "%a: hot-added APIC ID " FMT_APIC_ID ", SMBASE 0x%Lx, "
(UINT64)NewProcessorNumberByProtocol)); "EFI_SMM_CPU_SERVICE_PROTOCOL assigned number %Lu\n",
__FUNCTION__,
NewApicId,
(UINT64)mCpuHotPlugData->SmBase[NewSlot],
(UINT64)NewProcessorNumberByProtocol
));
NewSlot++; NewSlot++;
PluggedIdx++; PluggedIdx++;
@ -210,11 +239,11 @@ CheckIfBsp (
VOID VOID
) )
{ {
MSR_IA32_APIC_BASE_REGISTER ApicBaseMsr; MSR_IA32_APIC_BASE_REGISTER ApicBaseMsr;
BOOLEAN IsBsp; BOOLEAN IsBsp;
ApicBaseMsr.Uint64 = AsmReadMsr64 (MSR_IA32_APIC_BASE); ApicBaseMsr.Uint64 = AsmReadMsr64 (MSR_IA32_APIC_BASE);
IsBsp = (BOOLEAN)(ApicBaseMsr.Bits.BSP == 1); IsBsp = (BOOLEAN)(ApicBaseMsr.Bits.BSP == 1);
return IsBsp; return IsBsp;
} }
@ -238,13 +267,13 @@ CheckIfBsp (
VOID VOID
EFIAPI EFIAPI
EjectCpu ( EjectCpu (
IN UINTN ProcessorNum IN UINTN ProcessorNum
) )
{ {
UINT64 QemuSelector; UINT64 QemuSelector;
if (CheckIfBsp ()) { if (CheckIfBsp ()) {
UINT32 Idx; UINT32 Idx;
for (Idx = 0; Idx < mCpuHotEjectData->ArrayLength; Idx++) { for (Idx = 0; Idx < mCpuHotEjectData->ArrayLength; Idx++) {
QemuSelector = mCpuHotEjectData->QemuSelectorMap[Idx]; QemuSelector = mCpuHotEjectData->QemuSelectorMap[Idx];
@ -258,7 +287,7 @@ EjectCpu (
// //
// Tell QEMU to context-switch it out. // Tell QEMU to context-switch it out.
// //
QemuCpuhpWriteCpuSelector (mMmCpuIo, (UINT32) QemuSelector); QemuCpuhpWriteCpuSelector (mMmCpuIo, (UINT32)QemuSelector);
QemuCpuhpWriteCpuStatus (mMmCpuIo, QEMU_CPUHP_STAT_EJECT); QemuCpuhpWriteCpuStatus (mMmCpuIo, QEMU_CPUHP_STAT_EJECT);
// //
@ -277,8 +306,14 @@ EjectCpu (
mCpuHotEjectData->QemuSelectorMap[Idx] = mCpuHotEjectData->QemuSelectorMap[Idx] =
CPU_EJECT_QEMU_SELECTOR_INVALID; CPU_EJECT_QEMU_SELECTOR_INVALID;
DEBUG ((DEBUG_INFO, "%a: Unplugged ProcessorNum %u, " DEBUG ((
"QemuSelector %Lu\n", __FUNCTION__, Idx, QemuSelector)); DEBUG_INFO,
"%a: Unplugged ProcessorNum %u, "
"QemuSelector %Lu\n",
__FUNCTION__,
Idx,
QemuSelector
));
} }
} }
@ -330,7 +365,7 @@ EjectCpu (
// //
// Keep them penned here until the BSP tells QEMU to eject them. // Keep them penned here until the BSP tells QEMU to eject them.
// //
for (;;) { for ( ; ;) {
DisableInterrupts (); DisableInterrupts ();
CpuSleep (); CpuSleep ();
} }
@ -371,21 +406,21 @@ EjectCpu (
STATIC STATIC
EFI_STATUS EFI_STATUS
UnplugCpus ( UnplugCpus (
IN APIC_ID *ToUnplugApicIds, IN APIC_ID *ToUnplugApicIds,
IN UINT32 *ToUnplugSelectors, IN UINT32 *ToUnplugSelectors,
IN UINT32 ToUnplugCount IN UINT32 ToUnplugCount
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINT32 ToUnplugIdx; UINT32 ToUnplugIdx;
UINT32 EjectCount; UINT32 EjectCount;
UINTN ProcessorNum; UINTN ProcessorNum;
ToUnplugIdx = 0; ToUnplugIdx = 0;
EjectCount = 0; EjectCount = 0;
while (ToUnplugIdx < ToUnplugCount) { while (ToUnplugIdx < ToUnplugCount) {
APIC_ID RemoveApicId; APIC_ID RemoveApicId;
UINT32 QemuSelector; UINT32 QemuSelector;
RemoveApicId = ToUnplugApicIds[ToUnplugIdx]; RemoveApicId = ToUnplugApicIds[ToUnplugIdx];
QemuSelector = ToUnplugSelectors[ToUnplugIdx]; QemuSelector = ToUnplugSelectors[ToUnplugIdx];
@ -404,7 +439,8 @@ UnplugCpus (
for (ProcessorNum = 0; for (ProcessorNum = 0;
ProcessorNum < mCpuHotPlugData->ArrayLength; ProcessorNum < mCpuHotPlugData->ArrayLength;
ProcessorNum++) { ProcessorNum++)
{
if (mCpuHotPlugData->ApicId[ProcessorNum] == RemoveApicId) { if (mCpuHotPlugData->ApicId[ProcessorNum] == RemoveApicId) {
break; break;
} }
@ -414,8 +450,13 @@ UnplugCpus (
// Ignore the unplug if APIC ID not found // Ignore the unplug if APIC ID not found
// //
if (ProcessorNum == mCpuHotPlugData->ArrayLength) { if (ProcessorNum == mCpuHotPlugData->ArrayLength) {
DEBUG ((DEBUG_VERBOSE, "%a: did not find APIC ID " FMT_APIC_ID DEBUG ((
" to unplug\n", __FUNCTION__, RemoveApicId)); DEBUG_VERBOSE,
"%a: did not find APIC ID " FMT_APIC_ID
" to unplug\n",
__FUNCTION__,
RemoveApicId
));
ToUnplugIdx++; ToUnplugIdx++;
continue; continue;
} }
@ -425,13 +466,19 @@ UnplugCpus (
// //
Status = mMmCpuService->RemoveProcessor (mMmCpuService, ProcessorNum); Status = mMmCpuService->RemoveProcessor (mMmCpuService, ProcessorNum);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: RemoveProcessor(" FMT_APIC_ID "): %r\n", DEBUG ((
__FUNCTION__, RemoveApicId, Status)); DEBUG_ERROR,
"%a: RemoveProcessor(" FMT_APIC_ID "): %r\n",
__FUNCTION__,
RemoveApicId,
Status
));
return Status; return Status;
} }
if (mCpuHotEjectData->QemuSelectorMap[ProcessorNum] != if (mCpuHotEjectData->QemuSelectorMap[ProcessorNum] !=
CPU_EJECT_QEMU_SELECTOR_INVALID) { CPU_EJECT_QEMU_SELECTOR_INVALID)
{
// //
// mCpuHotEjectData->QemuSelectorMap[ProcessorNum] is set to // mCpuHotEjectData->QemuSelectorMap[ProcessorNum] is set to
// CPU_EJECT_QEMU_SELECTOR_INVALID when mCpuHotEjectData->QemuSelectorMap // CPU_EJECT_QEMU_SELECTOR_INVALID when mCpuHotEjectData->QemuSelectorMap
@ -442,9 +489,15 @@ UnplugCpus (
// never match more than one APIC ID -- nor, by transitivity, designate // never match more than one APIC ID -- nor, by transitivity, designate
// more than one QemuSelector -- in a single invocation of UnplugCpus(). // more than one QemuSelector -- in a single invocation of UnplugCpus().
// //
DEBUG ((DEBUG_ERROR, "%a: ProcessorNum %Lu maps to QemuSelector %Lu, " DEBUG ((
"cannot also map to %u\n", __FUNCTION__, (UINT64)ProcessorNum, DEBUG_ERROR,
mCpuHotEjectData->QemuSelectorMap[ProcessorNum], QemuSelector)); "%a: ProcessorNum %Lu maps to QemuSelector %Lu, "
"cannot also map to %u\n",
__FUNCTION__,
(UINT64)ProcessorNum,
mCpuHotEjectData->QemuSelectorMap[ProcessorNum],
QemuSelector
));
return EFI_ALREADY_STARTED; return EFI_ALREADY_STARTED;
} }
@ -454,9 +507,15 @@ UnplugCpus (
// //
mCpuHotEjectData->QemuSelectorMap[ProcessorNum] = (UINT64)QemuSelector; mCpuHotEjectData->QemuSelectorMap[ProcessorNum] = (UINT64)QemuSelector;
DEBUG ((DEBUG_INFO, "%a: Started hot-unplug on ProcessorNum %Lu, APIC ID " DEBUG ((
FMT_APIC_ID ", QemuSelector %u\n", __FUNCTION__, (UINT64)ProcessorNum, DEBUG_INFO,
RemoveApicId, QemuSelector)); "%a: Started hot-unplug on ProcessorNum %Lu, APIC ID "
FMT_APIC_ID ", QemuSelector %u\n",
__FUNCTION__,
(UINT64)ProcessorNum,
RemoveApicId,
QemuSelector
));
EjectCount++; EjectCount++;
ToUnplugIdx++; ToUnplugIdx++;
@ -539,16 +598,16 @@ STATIC
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
CpuHotplugMmi ( CpuHotplugMmi (
IN EFI_HANDLE DispatchHandle, IN EFI_HANDLE DispatchHandle,
IN CONST VOID *Context OPTIONAL, IN CONST VOID *Context OPTIONAL,
IN OUT VOID *CommBuffer OPTIONAL, IN OUT VOID *CommBuffer OPTIONAL,
IN OUT UINTN *CommBufferSize OPTIONAL IN OUT UINTN *CommBufferSize OPTIONAL
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINT8 ApmControl; UINT8 ApmControl;
UINT32 PluggedCount; UINT32 PluggedCount;
UINT32 ToUnplugCount; UINT32 ToUnplugCount;
// //
// Assert that we are entering this function due to our root MMI handler // Assert that we are entering this function due to our root MMI handler
@ -565,11 +624,20 @@ CpuHotplugMmi (
// Read the MMI command value from the APM Control Port, to see if this is an // Read the MMI command value from the APM Control Port, to see if this is an
// MMI we should care about. // MMI we should care about.
// //
Status = mMmCpuIo->Io.Read (mMmCpuIo, MM_IO_UINT8, ICH9_APM_CNT, 1, Status = mMmCpuIo->Io.Read (
&ApmControl); mMmCpuIo,
MM_IO_UINT8,
ICH9_APM_CNT,
1,
&ApmControl
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to read ICH9_APM_CNT: %r\n", __FUNCTION__, DEBUG ((
Status)); DEBUG_ERROR,
"%a: failed to read ICH9_APM_CNT: %r\n",
__FUNCTION__,
Status
));
// //
// We couldn't even determine if the MMI was for us or not. // We couldn't even determine if the MMI was for us or not.
// //
@ -628,21 +696,20 @@ Fatal:
return EFI_INTERRUPT_PENDING; return EFI_INTERRUPT_PENDING;
} }
// //
// Entry point function of this driver. // Entry point function of this driver.
// //
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
CpuHotplugEntry ( CpuHotplugEntry (
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINTN Len; UINTN Len;
UINTN Size; UINTN Size;
UINTN SizeSel; UINTN SizeSel;
// //
// This module should only be included when SMM support is required. // This module should only be included when SMM support is required.
@ -663,17 +730,28 @@ CpuHotplugEntry (
// First, collect the protocols needed later. All of these protocols are // First, collect the protocols needed later. All of these protocols are
// listed in our module DEPEX. // listed in our module DEPEX.
// //
Status = gMmst->MmLocateProtocol (&gEfiMmCpuIoProtocolGuid, Status = gMmst->MmLocateProtocol (
NULL /* Registration */, (VOID **)&mMmCpuIo); &gEfiMmCpuIoProtocolGuid,
NULL /* Registration */,
(VOID **)&mMmCpuIo
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: locate MmCpuIo: %r\n", __FUNCTION__, Status)); DEBUG ((DEBUG_ERROR, "%a: locate MmCpuIo: %r\n", __FUNCTION__, Status));
goto Fatal; goto Fatal;
} }
Status = gMmst->MmLocateProtocol (&gEfiSmmCpuServiceProtocolGuid,
NULL /* Registration */, (VOID **)&mMmCpuService); Status = gMmst->MmLocateProtocol (
&gEfiSmmCpuServiceProtocolGuid,
NULL /* Registration */,
(VOID **)&mMmCpuService
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: locate MmCpuService: %r\n", __FUNCTION__, DEBUG ((
Status)); DEBUG_ERROR,
"%a: locate MmCpuService: %r\n",
__FUNCTION__,
Status
));
goto Fatal; goto Fatal;
} }
@ -684,7 +762,7 @@ CpuHotplugEntry (
// - PcdCpuHotEjectDataAddress to CPU_HOT_EJECT_DATA in SMRAM, if the // - PcdCpuHotEjectDataAddress to CPU_HOT_EJECT_DATA in SMRAM, if the
// possible CPU count is greater than 1. // possible CPU count is greater than 1.
// //
mCpuHotPlugData = (VOID *)(UINTN)PcdGet64 (PcdCpuHotPlugDataAddress); mCpuHotPlugData = (VOID *)(UINTN)PcdGet64 (PcdCpuHotPlugDataAddress);
mCpuHotEjectData = (VOID *)(UINTN)PcdGet64 (PcdCpuHotEjectDataAddress); mCpuHotEjectData = (VOID *)(UINTN)PcdGet64 (PcdCpuHotEjectDataAddress);
if (mCpuHotPlugData == NULL) { if (mCpuHotPlugData == NULL) {
@ -692,6 +770,7 @@ CpuHotplugEntry (
DEBUG ((DEBUG_ERROR, "%a: CPU_HOT_PLUG_DATA: %r\n", __FUNCTION__, Status)); DEBUG ((DEBUG_ERROR, "%a: CPU_HOT_PLUG_DATA: %r\n", __FUNCTION__, Status));
goto Fatal; goto Fatal;
} }
// //
// If the possible CPU count is 1, there's nothing for this driver to do. // If the possible CPU count is 1, there's nothing for this driver to do.
// //
@ -706,6 +785,7 @@ CpuHotplugEntry (
} else { } else {
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
} }
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: CPU_HOT_EJECT_DATA: %r\n", __FUNCTION__, Status)); DEBUG ((DEBUG_ERROR, "%a: CPU_HOT_EJECT_DATA: %r\n", __FUNCTION__, Status));
goto Fatal; goto Fatal;
@ -716,25 +796,38 @@ CpuHotplugEntry (
// //
if (RETURN_ERROR (SafeUintnSub (mCpuHotPlugData->ArrayLength, 1, &Len)) || if (RETURN_ERROR (SafeUintnSub (mCpuHotPlugData->ArrayLength, 1, &Len)) ||
RETURN_ERROR (SafeUintnMult (sizeof (APIC_ID), Len, &Size)) || RETURN_ERROR (SafeUintnMult (sizeof (APIC_ID), Len, &Size)) ||
RETURN_ERROR (SafeUintnMult (sizeof (UINT32), Len, &SizeSel))) { RETURN_ERROR (SafeUintnMult (sizeof (UINT32), Len, &SizeSel)))
{
Status = EFI_ABORTED; Status = EFI_ABORTED;
DEBUG ((DEBUG_ERROR, "%a: invalid CPU_HOT_PLUG_DATA\n", __FUNCTION__)); DEBUG ((DEBUG_ERROR, "%a: invalid CPU_HOT_PLUG_DATA\n", __FUNCTION__));
goto Fatal; goto Fatal;
} }
Status = gMmst->MmAllocatePool (EfiRuntimeServicesData, Size,
(VOID **)&mPluggedApicIds); Status = gMmst->MmAllocatePool (
EfiRuntimeServicesData,
Size,
(VOID **)&mPluggedApicIds
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: MmAllocatePool(): %r\n", __FUNCTION__, Status)); DEBUG ((DEBUG_ERROR, "%a: MmAllocatePool(): %r\n", __FUNCTION__, Status));
goto Fatal; goto Fatal;
} }
Status = gMmst->MmAllocatePool (EfiRuntimeServicesData, Size,
(VOID **)&mToUnplugApicIds); Status = gMmst->MmAllocatePool (
EfiRuntimeServicesData,
Size,
(VOID **)&mToUnplugApicIds
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: MmAllocatePool(): %r\n", __FUNCTION__, Status)); DEBUG ((DEBUG_ERROR, "%a: MmAllocatePool(): %r\n", __FUNCTION__, Status));
goto ReleasePluggedApicIds; goto ReleasePluggedApicIds;
} }
Status = gMmst->MmAllocatePool (EfiRuntimeServicesData, SizeSel,
(VOID **)&mToUnplugSelectors); Status = gMmst->MmAllocatePool (
EfiRuntimeServicesData,
SizeSel,
(VOID **)&mToUnplugSelectors
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: MmAllocatePool(): %r\n", __FUNCTION__, Status)); DEBUG ((DEBUG_ERROR, "%a: MmAllocatePool(): %r\n", __FUNCTION__, Status));
goto ReleaseToUnplugApicIds; goto ReleaseToUnplugApicIds;
@ -743,8 +836,10 @@ CpuHotplugEntry (
// //
// Allocate the Post-SMM Pen for hot-added CPUs. // Allocate the Post-SMM Pen for hot-added CPUs.
// //
Status = SmbaseAllocatePostSmmPen (&mPostSmmPenAddress, Status = SmbaseAllocatePostSmmPen (
SystemTable->BootServices); &mPostSmmPenAddress,
SystemTable->BootServices
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto ReleaseToUnplugSelectors; goto ReleaseToUnplugSelectors;
} }
@ -776,8 +871,12 @@ CpuHotplugEntry (
QemuCpuhpWriteCommand (mMmCpuIo, QEMU_CPUHP_CMD_GET_PENDING); QemuCpuhpWriteCommand (mMmCpuIo, QEMU_CPUHP_CMD_GET_PENDING);
if (QemuCpuhpReadCommandData2 (mMmCpuIo) != 0) { if (QemuCpuhpReadCommandData2 (mMmCpuIo) != 0) {
Status = EFI_NOT_FOUND; Status = EFI_NOT_FOUND;
DEBUG ((DEBUG_ERROR, "%a: modern CPU hotplug interface: %r\n", DEBUG ((
__FUNCTION__, Status)); DEBUG_ERROR,
"%a: modern CPU hotplug interface: %r\n",
__FUNCTION__,
Status
));
goto ReleasePostSmmPen; goto ReleasePostSmmPen;
} }
@ -790,8 +889,12 @@ CpuHotplugEntry (
&mDispatchHandle &mDispatchHandle
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: MmiHandlerRegister(): %r\n", __FUNCTION__, DEBUG ((
Status)); DEBUG_ERROR,
"%a: MmiHandlerRegister(): %r\n",
__FUNCTION__,
Status
));
goto ReleasePostSmmPen; goto ReleasePostSmmPen;
} }

View File

@ -29,18 +29,18 @@ typedef struct {
// This field is intentionally wider than APIC_ID (UINT32) because we need a // This field is intentionally wider than APIC_ID (UINT32) because we need a
// "gate locked" value that is different from all possible APIC_IDs. // "gate locked" value that is different from all possible APIC_IDs.
// //
UINT64 ApicIdGate; UINT64 ApicIdGate;
// //
// The new SMBASE value for the hot-added CPU to set in the SMRAM Save State // The new SMBASE value for the hot-added CPU to set in the SMRAM Save State
// Map, before leaving SMM with the RSM instruction. // Map, before leaving SMM with the RSM instruction.
// //
UINT32 NewSmbase; UINT32 NewSmbase;
// //
// The hot-added CPU sets this field to 1 right before executing the RSM // The hot-added CPU sets this field to 1 right before executing the RSM
// instruction. This tells the SMM Monarch to proceed to polling the last // instruction. This tells the SMM Monarch to proceed to polling the last
// byte of the normal RAM reserved page (Post-SMM Pen). // byte of the normal RAM reserved page (Post-SMM Pen).
// //
UINT8 AboutToLeaveSmm; UINT8 AboutToLeaveSmm;
} FIRST_SMI_HANDLER_CONTEXT; } FIRST_SMI_HANDLER_CONTEXT;
#pragma pack () #pragma pack ()

View File

@ -21,83 +21,86 @@
UINT32 UINT32
QemuCpuhpReadCommandData2 ( QemuCpuhpReadCommandData2 (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo
) )
{ {
UINT32 CommandData2; UINT32 CommandData2;
EFI_STATUS Status; EFI_STATUS Status;
CommandData2 = 0; CommandData2 = 0;
Status = MmCpuIo->Io.Read ( Status = MmCpuIo->Io.Read (
MmCpuIo, MmCpuIo,
MM_IO_UINT32, MM_IO_UINT32,
ICH9_CPU_HOTPLUG_BASE + QEMU_CPUHP_R_CMD_DATA2, ICH9_CPU_HOTPLUG_BASE + QEMU_CPUHP_R_CMD_DATA2,
1, 1,
&CommandData2 &CommandData2
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, Status)); DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, Status));
ASSERT (FALSE); ASSERT (FALSE);
CpuDeadLoop (); CpuDeadLoop ();
} }
return CommandData2; return CommandData2;
} }
UINT8 UINT8
QemuCpuhpReadCpuStatus ( QemuCpuhpReadCpuStatus (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo
) )
{ {
UINT8 CpuStatus; UINT8 CpuStatus;
EFI_STATUS Status; EFI_STATUS Status;
CpuStatus = 0; CpuStatus = 0;
Status = MmCpuIo->Io.Read ( Status = MmCpuIo->Io.Read (
MmCpuIo, MmCpuIo,
MM_IO_UINT8, MM_IO_UINT8,
ICH9_CPU_HOTPLUG_BASE + QEMU_CPUHP_R_CPU_STAT, ICH9_CPU_HOTPLUG_BASE + QEMU_CPUHP_R_CPU_STAT,
1, 1,
&CpuStatus &CpuStatus
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, Status)); DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, Status));
ASSERT (FALSE); ASSERT (FALSE);
CpuDeadLoop (); CpuDeadLoop ();
} }
return CpuStatus; return CpuStatus;
} }
UINT32 UINT32
QemuCpuhpReadCommandData ( QemuCpuhpReadCommandData (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo
) )
{ {
UINT32 CommandData; UINT32 CommandData;
EFI_STATUS Status; EFI_STATUS Status;
CommandData = 0; CommandData = 0;
Status = MmCpuIo->Io.Read ( Status = MmCpuIo->Io.Read (
MmCpuIo, MmCpuIo,
MM_IO_UINT32, MM_IO_UINT32,
ICH9_CPU_HOTPLUG_BASE + QEMU_CPUHP_RW_CMD_DATA, ICH9_CPU_HOTPLUG_BASE + QEMU_CPUHP_RW_CMD_DATA,
1, 1,
&CommandData &CommandData
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, Status)); DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, Status));
ASSERT (FALSE); ASSERT (FALSE);
CpuDeadLoop (); CpuDeadLoop ();
} }
return CommandData; return CommandData;
} }
VOID VOID
QemuCpuhpWriteCpuSelector ( QemuCpuhpWriteCpuSelector (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo, IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT32 Selector IN UINT32 Selector
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
Status = MmCpuIo->Io.Write ( Status = MmCpuIo->Io.Write (
MmCpuIo, MmCpuIo,
@ -115,11 +118,11 @@ QemuCpuhpWriteCpuSelector (
VOID VOID
QemuCpuhpWriteCpuStatus ( QemuCpuhpWriteCpuStatus (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo, IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT8 CpuStatus IN UINT8 CpuStatus
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
Status = MmCpuIo->Io.Write ( Status = MmCpuIo->Io.Write (
MmCpuIo, MmCpuIo,
@ -137,11 +140,11 @@ QemuCpuhpWriteCpuStatus (
VOID VOID
QemuCpuhpWriteCommand ( QemuCpuhpWriteCommand (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo, IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT8 Command IN UINT8 Command
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
Status = MmCpuIo->Io.Write ( Status = MmCpuIo->Io.Write (
MmCpuIo, MmCpuIo,
@ -206,33 +209,33 @@ QemuCpuhpWriteCommand (
**/ **/
EFI_STATUS EFI_STATUS
QemuCpuhpCollectApicIds ( QemuCpuhpCollectApicIds (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo, IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT32 PossibleCpuCount, IN UINT32 PossibleCpuCount,
IN UINT32 ApicIdCount, IN UINT32 ApicIdCount,
OUT APIC_ID *PluggedApicIds, OUT APIC_ID *PluggedApicIds,
OUT UINT32 *PluggedCount, OUT UINT32 *PluggedCount,
OUT APIC_ID *ToUnplugApicIds, OUT APIC_ID *ToUnplugApicIds,
OUT UINT32 *ToUnplugSelectors, OUT UINT32 *ToUnplugSelectors,
OUT UINT32 *ToUnplugCount OUT UINT32 *ToUnplugCount
) )
{ {
UINT32 CurrentSelector; UINT32 CurrentSelector;
if (PossibleCpuCount == 0 || ApicIdCount == 0) { if ((PossibleCpuCount == 0) || (ApicIdCount == 0)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
*PluggedCount = 0; *PluggedCount = 0;
*ToUnplugCount = 0; *ToUnplugCount = 0;
CurrentSelector = 0; CurrentSelector = 0;
do { do {
UINT32 PendingSelector; UINT32 PendingSelector;
UINT8 CpuStatus; UINT8 CpuStatus;
APIC_ID *ExtendIds; APIC_ID *ExtendIds;
UINT32 *ExtendSels; UINT32 *ExtendSels;
UINT32 *ExtendCount; UINT32 *ExtendCount;
APIC_ID NewApicId; APIC_ID NewApicId;
// //
// Write CurrentSelector (which is valid) to the CPU selector register. // Write CurrentSelector (which is valid) to the CPU selector register.
@ -259,10 +262,17 @@ QemuCpuhpCollectApicIds (
QemuCpuhpWriteCommand (MmCpuIo, QEMU_CPUHP_CMD_GET_PENDING); QemuCpuhpWriteCommand (MmCpuIo, QEMU_CPUHP_CMD_GET_PENDING);
PendingSelector = QemuCpuhpReadCommandData (MmCpuIo); PendingSelector = QemuCpuhpReadCommandData (MmCpuIo);
if (PendingSelector < CurrentSelector) { if (PendingSelector < CurrentSelector) {
DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=%u PendingSelector=%u: " DEBUG ((
"wrap-around\n", __FUNCTION__, CurrentSelector, PendingSelector)); DEBUG_VERBOSE,
"%a: CurrentSelector=%u PendingSelector=%u: "
"wrap-around\n",
__FUNCTION__,
CurrentSelector,
PendingSelector
));
break; break;
} }
CurrentSelector = PendingSelector; CurrentSelector = PendingSelector;
// //
@ -274,16 +284,26 @@ QemuCpuhpCollectApicIds (
// The "insert" event guarantees the "enabled" status; plus it excludes // The "insert" event guarantees the "enabled" status; plus it excludes
// the "fw_remove" event. // the "fw_remove" event.
// //
if ((CpuStatus & QEMU_CPUHP_STAT_ENABLED) == 0 || if (((CpuStatus & QEMU_CPUHP_STAT_ENABLED) == 0) ||
(CpuStatus & QEMU_CPUHP_STAT_FW_REMOVE) != 0) { ((CpuStatus & QEMU_CPUHP_STAT_FW_REMOVE) != 0))
DEBUG ((DEBUG_ERROR, "%a: CurrentSelector=%u CpuStatus=0x%x: " {
"inconsistent CPU status\n", __FUNCTION__, CurrentSelector, DEBUG ((
CpuStatus)); DEBUG_ERROR,
"%a: CurrentSelector=%u CpuStatus=0x%x: "
"inconsistent CPU status\n",
__FUNCTION__,
CurrentSelector,
CpuStatus
));
return EFI_PROTOCOL_ERROR; return EFI_PROTOCOL_ERROR;
} }
DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=%u: insert\n", __FUNCTION__, DEBUG ((
CurrentSelector)); DEBUG_VERBOSE,
"%a: CurrentSelector=%u: insert\n",
__FUNCTION__,
CurrentSelector
));
ExtendIds = PluggedApicIds; ExtendIds = PluggedApicIds;
ExtendSels = NULL; ExtendSels = NULL;
@ -293,14 +313,23 @@ QemuCpuhpCollectApicIds (
// "fw_remove" event guarantees "enabled". // "fw_remove" event guarantees "enabled".
// //
if ((CpuStatus & QEMU_CPUHP_STAT_ENABLED) == 0) { if ((CpuStatus & QEMU_CPUHP_STAT_ENABLED) == 0) {
DEBUG ((DEBUG_ERROR, "%a: CurrentSelector=%u CpuStatus=0x%x: " DEBUG ((
"inconsistent CPU status\n", __FUNCTION__, CurrentSelector, DEBUG_ERROR,
CpuStatus)); "%a: CurrentSelector=%u CpuStatus=0x%x: "
"inconsistent CPU status\n",
__FUNCTION__,
CurrentSelector,
CpuStatus
));
return EFI_PROTOCOL_ERROR; return EFI_PROTOCOL_ERROR;
} }
DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=%u: fw_remove\n", DEBUG ((
__FUNCTION__, CurrentSelector)); DEBUG_VERBOSE,
"%a: CurrentSelector=%u: fw_remove\n",
__FUNCTION__,
CurrentSelector
));
ExtendIds = ToUnplugApicIds; ExtendIds = ToUnplugApicIds;
ExtendSels = ToUnplugSelectors; ExtendSels = ToUnplugSelectors;
@ -309,15 +338,23 @@ QemuCpuhpCollectApicIds (
// //
// Let the OSPM deal with the "remove" event. // Let the OSPM deal with the "remove" event.
// //
DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=%u: remove (ignored)\n", DEBUG ((
__FUNCTION__, CurrentSelector)); DEBUG_VERBOSE,
"%a: CurrentSelector=%u: remove (ignored)\n",
__FUNCTION__,
CurrentSelector
));
ExtendIds = NULL; ExtendIds = NULL;
ExtendSels = NULL; ExtendSels = NULL;
ExtendCount = NULL; ExtendCount = NULL;
} else { } else {
DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=%u: no event\n", DEBUG ((
__FUNCTION__, CurrentSelector)); DEBUG_VERBOSE,
"%a: CurrentSelector=%u: no event\n",
__FUNCTION__,
CurrentSelector
));
break; break;
} }
@ -334,15 +371,22 @@ QemuCpuhpCollectApicIds (
DEBUG ((DEBUG_ERROR, "%a: APIC ID array too small\n", __FUNCTION__)); DEBUG ((DEBUG_ERROR, "%a: APIC ID array too small\n", __FUNCTION__));
return EFI_BUFFER_TOO_SMALL; return EFI_BUFFER_TOO_SMALL;
} }
QemuCpuhpWriteCommand (MmCpuIo, QEMU_CPUHP_CMD_GET_ARCH_ID); QemuCpuhpWriteCommand (MmCpuIo, QEMU_CPUHP_CMD_GET_ARCH_ID);
NewApicId = QemuCpuhpReadCommandData (MmCpuIo); NewApicId = QemuCpuhpReadCommandData (MmCpuIo);
DEBUG ((DEBUG_VERBOSE, "%a: ApicId=" FMT_APIC_ID "\n", __FUNCTION__, DEBUG ((
NewApicId)); DEBUG_VERBOSE,
"%a: ApicId=" FMT_APIC_ID "\n",
__FUNCTION__,
NewApicId
));
if (ExtendSels != NULL) { if (ExtendSels != NULL) {
ExtendSels[(*ExtendCount)] = CurrentSelector; ExtendSels[(*ExtendCount)] = CurrentSelector;
} }
ExtendIds[(*ExtendCount)++] = NewApicId; ExtendIds[(*ExtendCount)++] = NewApicId;
} }
// //
// We've processed the CPU with (known) pending events, but we must never // We've processed the CPU with (known) pending events, but we must never
// clear events. Therefore we need to advance past this CPU manually; // clear events. Therefore we need to advance past this CPU manually;
@ -352,7 +396,12 @@ QemuCpuhpCollectApicIds (
CurrentSelector++; CurrentSelector++;
} while (CurrentSelector < PossibleCpuCount); } while (CurrentSelector < PossibleCpuCount);
DEBUG ((DEBUG_VERBOSE, "%a: PluggedCount=%u ToUnplugCount=%u\n", DEBUG ((
__FUNCTION__, *PluggedCount, *ToUnplugCount)); DEBUG_VERBOSE,
"%a: PluggedCount=%u ToUnplugCount=%u\n",
__FUNCTION__,
*PluggedCount,
*ToUnplugCount
));
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@ -22,47 +22,47 @@
UINT32 UINT32
QemuCpuhpReadCommandData2 ( QemuCpuhpReadCommandData2 (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo
); );
UINT8 UINT8
QemuCpuhpReadCpuStatus ( QemuCpuhpReadCpuStatus (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo
); );
UINT32 UINT32
QemuCpuhpReadCommandData ( QemuCpuhpReadCommandData (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo
); );
VOID VOID
QemuCpuhpWriteCpuSelector ( QemuCpuhpWriteCpuSelector (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo, IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT32 Selector IN UINT32 Selector
); );
VOID VOID
QemuCpuhpWriteCpuStatus ( QemuCpuhpWriteCpuStatus (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo, IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT8 CpuStatus IN UINT8 CpuStatus
); );
VOID VOID
QemuCpuhpWriteCommand ( QemuCpuhpWriteCommand (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo, IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT8 Command IN UINT8 Command
); );
EFI_STATUS EFI_STATUS
QemuCpuhpCollectApicIds ( QemuCpuhpCollectApicIds (
IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo, IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo,
IN UINT32 PossibleCpuCount, IN UINT32 PossibleCpuCount,
IN UINT32 ApicIdCount, IN UINT32 ApicIdCount,
OUT APIC_ID *PluggedApicIds, OUT APIC_ID *PluggedApicIds,
OUT UINT32 *PluggedCount, OUT UINT32 *PluggedCount,
OUT APIC_ID *ToUnplugApicIds, OUT APIC_ID *ToUnplugApicIds,
OUT UINT32 *ToUnplugSelectors, OUT UINT32 *ToUnplugSelectors,
OUT UINT32 *ToUnplugCount OUT UINT32 *ToUnplugCount
); );
#endif // QEMU_CPUHP_H_ #endif // QEMU_CPUHP_H_

View File

@ -18,10 +18,10 @@
#include "Smbase.h" #include "Smbase.h"
extern CONST UINT8 mPostSmmPen[]; extern CONST UINT8 mPostSmmPen[];
extern CONST UINT16 mPostSmmPenSize; extern CONST UINT16 mPostSmmPenSize;
extern CONST UINT8 mFirstSmiHandler[]; extern CONST UINT8 mFirstSmiHandler[];
extern CONST UINT16 mFirstSmiHandlerSize; extern CONST UINT16 mFirstSmiHandlerSize;
/** /**
Allocate a non-SMRAM reserved memory page for the Post-SMM Pen for hot-added Allocate a non-SMRAM reserved memory page for the Post-SMM Pen for hot-added
@ -46,12 +46,12 @@ extern CONST UINT16 mFirstSmiHandlerSize;
**/ **/
EFI_STATUS EFI_STATUS
SmbaseAllocatePostSmmPen ( SmbaseAllocatePostSmmPen (
OUT UINT32 *PenAddress, OUT UINT32 *PenAddress,
IN CONST EFI_BOOT_SERVICES *BootServices IN CONST EFI_BOOT_SERVICES *BootServices
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS Address; EFI_PHYSICAL_ADDRESS Address;
// //
// The pen code must fit in one page, and the last byte must remain free for // The pen code must fit in one page, and the last byte must remain free for
@ -59,14 +59,23 @@ SmbaseAllocatePostSmmPen (
// //
if (mPostSmmPenSize >= EFI_PAGE_SIZE) { if (mPostSmmPenSize >= EFI_PAGE_SIZE) {
Status = EFI_BAD_BUFFER_SIZE; Status = EFI_BAD_BUFFER_SIZE;
DEBUG ((DEBUG_ERROR, "%a: mPostSmmPenSize=%u: %r\n", __FUNCTION__, DEBUG ((
mPostSmmPenSize, Status)); DEBUG_ERROR,
"%a: mPostSmmPenSize=%u: %r\n",
__FUNCTION__,
mPostSmmPenSize,
Status
));
return Status; return Status;
} }
Address = BASE_1MB - 1; Address = BASE_1MB - 1;
Status = BootServices->AllocatePages (AllocateMaxAddress, Status = BootServices->AllocatePages (
EfiReservedMemoryType, 1, &Address); AllocateMaxAddress,
EfiReservedMemoryType,
1,
&Address
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: AllocatePages(): %r\n", __FUNCTION__, Status)); DEBUG ((DEBUG_ERROR, "%a: AllocatePages(): %r\n", __FUNCTION__, Status));
return Status; return Status;
@ -90,7 +99,7 @@ SmbaseAllocatePostSmmPen (
**/ **/
VOID VOID
SmbaseReinstallPostSmmPen ( SmbaseReinstallPostSmmPen (
IN UINT32 PenAddress IN UINT32 PenAddress
) )
{ {
CopyMem ((VOID *)(UINTN)PenAddress, mPostSmmPen, mPostSmmPenSize); CopyMem ((VOID *)(UINTN)PenAddress, mPostSmmPen, mPostSmmPenSize);
@ -110,8 +119,8 @@ SmbaseReinstallPostSmmPen (
**/ **/
VOID VOID
SmbaseReleasePostSmmPen ( SmbaseReleasePostSmmPen (
IN UINT32 PenAddress, IN UINT32 PenAddress,
IN CONST EFI_BOOT_SERVICES *BootServices IN CONST EFI_BOOT_SERVICES *BootServices
) )
{ {
BootServices->FreePages (PenAddress, 1); BootServices->FreePages (PenAddress, 1);
@ -133,12 +142,15 @@ SmbaseInstallFirstSmiHandler (
VOID VOID
) )
{ {
FIRST_SMI_HANDLER_CONTEXT *Context; FIRST_SMI_HANDLER_CONTEXT *Context;
CopyMem ((VOID *)(UINTN)(SMM_DEFAULT_SMBASE + SMM_HANDLER_OFFSET), CopyMem (
mFirstSmiHandler, mFirstSmiHandlerSize); (VOID *)(UINTN)(SMM_DEFAULT_SMBASE + SMM_HANDLER_OFFSET),
mFirstSmiHandler,
mFirstSmiHandlerSize
);
Context = (VOID *)(UINTN)SMM_DEFAULT_SMBASE; Context = (VOID *)(UINTN)SMM_DEFAULT_SMBASE;
Context->ApicIdGate = MAX_UINT64; Context->ApicIdGate = MAX_UINT64;
} }
@ -184,25 +196,31 @@ SmbaseInstallFirstSmiHandler (
**/ **/
EFI_STATUS EFI_STATUS
SmbaseRelocate ( SmbaseRelocate (
IN APIC_ID ApicId, IN APIC_ID ApicId,
IN UINTN Smbase, IN UINTN Smbase,
IN UINT32 PenAddress IN UINT32 PenAddress
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
volatile UINT8 *SmmVacated; volatile UINT8 *SmmVacated;
volatile FIRST_SMI_HANDLER_CONTEXT *Context; volatile FIRST_SMI_HANDLER_CONTEXT *Context;
UINT64 ExchangeResult; UINT64 ExchangeResult;
if (Smbase > MAX_UINT32) { if (Smbase > MAX_UINT32) {
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
DEBUG ((DEBUG_ERROR, "%a: ApicId=" FMT_APIC_ID " Smbase=0x%Lx: %r\n", DEBUG ((
__FUNCTION__, ApicId, (UINT64)Smbase, Status)); DEBUG_ERROR,
"%a: ApicId=" FMT_APIC_ID " Smbase=0x%Lx: %r\n",
__FUNCTION__,
ApicId,
(UINT64)Smbase,
Status
));
return Status; return Status;
} }
SmmVacated = (UINT8 *)(UINTN)PenAddress + (EFI_PAGE_SIZE - 1); SmmVacated = (UINT8 *)(UINTN)PenAddress + (EFI_PAGE_SIZE - 1);
Context = (VOID *)(UINTN)SMM_DEFAULT_SMBASE; Context = (VOID *)(UINTN)SMM_DEFAULT_SMBASE;
// //
// Clear AboutToLeaveSmm, so we notice when the hot-added CPU is just about // Clear AboutToLeaveSmm, so we notice when the hot-added CPU is just about
@ -261,12 +279,21 @@ SmbaseRelocate (
// //
// Un-gate SMBASE relocation for the hot-added CPU whose APIC ID is ApicId. // Un-gate SMBASE relocation for the hot-added CPU whose APIC ID is ApicId.
// //
ExchangeResult = InterlockedCompareExchange64 (&Context->ApicIdGate, ExchangeResult = InterlockedCompareExchange64 (
MAX_UINT64, ApicId); &Context->ApicIdGate,
MAX_UINT64,
ApicId
);
if (ExchangeResult != MAX_UINT64) { if (ExchangeResult != MAX_UINT64) {
Status = EFI_PROTOCOL_ERROR; Status = EFI_PROTOCOL_ERROR;
DEBUG ((DEBUG_ERROR, "%a: ApicId=" FMT_APIC_ID " ApicIdGate=0x%Lx: %r\n", DEBUG ((
__FUNCTION__, ApicId, ExchangeResult, Status)); DEBUG_ERROR,
"%a: ApicId=" FMT_APIC_ID " ApicIdGate=0x%Lx: %r\n",
__FUNCTION__,
ApicId,
ExchangeResult,
Status
));
return Status; return Status;
} }

View File

@ -16,19 +16,19 @@
EFI_STATUS EFI_STATUS
SmbaseAllocatePostSmmPen ( SmbaseAllocatePostSmmPen (
OUT UINT32 *PenAddress, OUT UINT32 *PenAddress,
IN CONST EFI_BOOT_SERVICES *BootServices IN CONST EFI_BOOT_SERVICES *BootServices
); );
VOID VOID
SmbaseReinstallPostSmmPen ( SmbaseReinstallPostSmmPen (
IN UINT32 PenAddress IN UINT32 PenAddress
); );
VOID VOID
SmbaseReleasePostSmmPen ( SmbaseReleasePostSmmPen (
IN UINT32 PenAddress, IN UINT32 PenAddress,
IN CONST EFI_BOOT_SERVICES *BootServices IN CONST EFI_BOOT_SERVICES *BootServices
); );
VOID VOID
@ -38,9 +38,9 @@ SmbaseInstallFirstSmiHandler (
EFI_STATUS EFI_STATUS
SmbaseRelocate ( SmbaseRelocate (
IN APIC_ID ApicId, IN APIC_ID ApicId,
IN UINTN Smbase, IN UINTN Smbase,
IN UINT32 PenAddress IN UINT32 PenAddress
); );
#endif // SMBASE_H_ #endif // SMBASE_H_

View File

@ -34,10 +34,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// Data structure used to allocate ACPI_CPU_DATA and its supporting structures // Data structure used to allocate ACPI_CPU_DATA and its supporting structures
// //
typedef struct { typedef struct {
ACPI_CPU_DATA AcpiCpuData; ACPI_CPU_DATA AcpiCpuData;
MTRR_SETTINGS MtrrTable; MTRR_SETTINGS MtrrTable;
IA32_DESCRIPTOR GdtrProfile; IA32_DESCRIPTOR GdtrProfile;
IA32_DESCRIPTOR IdtrProfile; IA32_DESCRIPTOR IdtrProfile;
} ACPI_CPU_DATA_EX; } ACPI_CPU_DATA_EX;
/** /**
@ -57,12 +57,12 @@ AllocateAcpiNvsMemory (
EFI_STATUS Status; EFI_STATUS Status;
VOID *Buffer; VOID *Buffer;
Status = gBS->AllocatePages ( Status = gBS->AllocatePages (
AllocateAnyPages, AllocateAnyPages,
EfiACPIMemoryNVS, EfiACPIMemoryNVS,
EFI_SIZE_TO_PAGES (Size), EFI_SIZE_TO_PAGES (Size),
&Address &Address
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return NULL; return NULL;
} }
@ -86,7 +86,7 @@ AllocateZeroPages (
IN UINTN Size IN UINTN Size
) )
{ {
VOID *Buffer; VOID *Buffer;
Buffer = AllocatePages (EFI_SIZE_TO_PAGES (Size)); Buffer = AllocatePages (EFI_SIZE_TO_PAGES (Size));
if (Buffer != NULL) { if (Buffer != NULL) {
@ -95,6 +95,7 @@ AllocateZeroPages (
return Buffer; return Buffer;
} }
/** /**
Callback function executed when the EndOfDxe event group is signaled. Callback function executed when the EndOfDxe event group is signaled.
@ -110,20 +111,20 @@ CpuS3DataOnEndOfDxe (
OUT VOID *Context OUT VOID *Context
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
ACPI_CPU_DATA_EX *AcpiCpuDataEx; ACPI_CPU_DATA_EX *AcpiCpuDataEx;
AcpiCpuDataEx = (ACPI_CPU_DATA_EX *) Context; AcpiCpuDataEx = (ACPI_CPU_DATA_EX *)Context;
// //
// Allocate a 4KB reserved page below 1MB // Allocate a 4KB reserved page below 1MB
// //
AcpiCpuDataEx->AcpiCpuData.StartupVector = BASE_1MB - 1; AcpiCpuDataEx->AcpiCpuData.StartupVector = BASE_1MB - 1;
Status = gBS->AllocatePages ( Status = gBS->AllocatePages (
AllocateMaxAddress, AllocateMaxAddress,
EfiReservedMemoryType, EfiReservedMemoryType,
1, 1,
&AcpiCpuDataEx->AcpiCpuData.StartupVector &AcpiCpuDataEx->AcpiCpuData.StartupVector
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
DEBUG ((DEBUG_VERBOSE, "%a\n", __FUNCTION__)); DEBUG ((DEBUG_VERBOSE, "%a\n", __FUNCTION__));
@ -158,18 +159,18 @@ CpuS3DataInitialize (
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
ACPI_CPU_DATA_EX *AcpiCpuDataEx; ACPI_CPU_DATA_EX *AcpiCpuDataEx;
ACPI_CPU_DATA *AcpiCpuData; ACPI_CPU_DATA *AcpiCpuData;
EFI_MP_SERVICES_PROTOCOL *MpServices; EFI_MP_SERVICES_PROTOCOL *MpServices;
UINTN NumberOfCpus; UINTN NumberOfCpus;
VOID *Stack; VOID *Stack;
UINTN GdtSize; UINTN GdtSize;
UINTN IdtSize; UINTN IdtSize;
VOID *Gdt; VOID *Gdt;
VOID *Idt; VOID *Idt;
EFI_EVENT Event; EFI_EVENT Event;
ACPI_CPU_DATA *OldAcpiCpuData; ACPI_CPU_DATA *OldAcpiCpuData;
if (!PcdGetBool (PcdAcpiS3Enable)) { if (!PcdGetBool (PcdAcpiS3Enable)) {
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
@ -178,7 +179,7 @@ CpuS3DataInitialize (
// //
// Set PcdCpuS3DataAddress to the base address of the ACPI_CPU_DATA structure // Set PcdCpuS3DataAddress to the base address of the ACPI_CPU_DATA structure
// //
OldAcpiCpuData = (ACPI_CPU_DATA *) (UINTN) PcdGet64 (PcdCpuS3DataAddress); OldAcpiCpuData = (ACPI_CPU_DATA *)(UINTN)PcdGet64 (PcdCpuS3DataAddress);
AcpiCpuDataEx = AllocateZeroPages (sizeof (ACPI_CPU_DATA_EX)); AcpiCpuDataEx = AllocateZeroPages (sizeof (ACPI_CPU_DATA_EX));
ASSERT (AcpiCpuDataEx != NULL); ASSERT (AcpiCpuDataEx != NULL);
@ -187,7 +188,7 @@ CpuS3DataInitialize (
if (PcdGetBool (PcdQ35SmramAtDefaultSmbase)) { if (PcdGetBool (PcdQ35SmramAtDefaultSmbase)) {
NumberOfCpus = PcdGet32 (PcdCpuMaxLogicalProcessorNumber); NumberOfCpus = PcdGet32 (PcdCpuMaxLogicalProcessorNumber);
} else { } else {
UINTN NumberOfEnabledProcessors; UINTN NumberOfEnabledProcessors;
// //
// Get MP Services Protocol // Get MP Services Protocol
@ -209,6 +210,7 @@ CpuS3DataInitialize (
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
} }
AcpiCpuData->NumberOfCpus = (UINT32)NumberOfCpus; AcpiCpuData->NumberOfCpus = (UINT32)NumberOfCpus;
// //
@ -217,9 +219,9 @@ CpuS3DataInitialize (
AcpiCpuData->StackSize = PcdGet32 (PcdCpuApStackSize); AcpiCpuData->StackSize = PcdGet32 (PcdCpuApStackSize);
AcpiCpuData->ApMachineCheckHandlerBase = 0; AcpiCpuData->ApMachineCheckHandlerBase = 0;
AcpiCpuData->ApMachineCheckHandlerSize = 0; AcpiCpuData->ApMachineCheckHandlerSize = 0;
AcpiCpuData->GdtrProfile = (EFI_PHYSICAL_ADDRESS)(UINTN)&AcpiCpuDataEx->GdtrProfile; AcpiCpuData->GdtrProfile = (EFI_PHYSICAL_ADDRESS)(UINTN)&AcpiCpuDataEx->GdtrProfile;
AcpiCpuData->IdtrProfile = (EFI_PHYSICAL_ADDRESS)(UINTN)&AcpiCpuDataEx->IdtrProfile; AcpiCpuData->IdtrProfile = (EFI_PHYSICAL_ADDRESS)(UINTN)&AcpiCpuDataEx->IdtrProfile;
AcpiCpuData->MtrrTable = (EFI_PHYSICAL_ADDRESS)(UINTN)&AcpiCpuDataEx->MtrrTable; AcpiCpuData->MtrrTable = (EFI_PHYSICAL_ADDRESS)(UINTN)&AcpiCpuDataEx->MtrrTable;
// //
// Allocate stack space for all CPUs. // Allocate stack space for all CPUs.
@ -243,7 +245,7 @@ CpuS3DataInitialize (
// //
GdtSize = AcpiCpuDataEx->GdtrProfile.Limit + 1; GdtSize = AcpiCpuDataEx->GdtrProfile.Limit + 1;
IdtSize = AcpiCpuDataEx->IdtrProfile.Limit + 1; IdtSize = AcpiCpuDataEx->IdtrProfile.Limit + 1;
Gdt = AllocateZeroPages (GdtSize + IdtSize); Gdt = AllocateZeroPages (GdtSize + IdtSize);
ASSERT (Gdt != NULL); ASSERT (Gdt != NULL);
Idt = (VOID *)((UINTN)Gdt + GdtSize); Idt = (VOID *)((UINTN)Gdt + GdtSize);
CopyMem (Gdt, (VOID *)AcpiCpuDataEx->GdtrProfile.Base, GdtSize); CopyMem (Gdt, (VOID *)AcpiCpuDataEx->GdtrProfile.Base, GdtSize);

File diff suppressed because it is too large Load Diff

View File

@ -42,88 +42,88 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// position of RGB in the frame buffer is specified in the VBE Mode information // position of RGB in the frame buffer is specified in the VBE Mode information
// //
typedef struct { typedef struct {
UINT8 Position; // Position of the color UINT8 Position; // Position of the color
UINT8 Mask; // The number of bits expressed as a mask UINT8 Mask; // The number of bits expressed as a mask
} BIOS_VIDEO_COLOR_PLACEMENT; } BIOS_VIDEO_COLOR_PLACEMENT;
// //
// BIOS Graphics Output Graphical Mode Data // BIOS Graphics Output Graphical Mode Data
// //
typedef struct { typedef struct {
UINT16 VbeModeNumber; UINT16 VbeModeNumber;
UINT16 BytesPerScanLine; UINT16 BytesPerScanLine;
VOID *LinearFrameBuffer; VOID *LinearFrameBuffer;
UINTN FrameBufferSize; UINTN FrameBufferSize;
UINT32 HorizontalResolution; UINT32 HorizontalResolution;
UINT32 VerticalResolution; UINT32 VerticalResolution;
UINT32 ColorDepth; UINT32 ColorDepth;
UINT32 RefreshRate; UINT32 RefreshRate;
UINT32 BitsPerPixel; UINT32 BitsPerPixel;
BIOS_VIDEO_COLOR_PLACEMENT Red; BIOS_VIDEO_COLOR_PLACEMENT Red;
BIOS_VIDEO_COLOR_PLACEMENT Green; BIOS_VIDEO_COLOR_PLACEMENT Green;
BIOS_VIDEO_COLOR_PLACEMENT Blue; BIOS_VIDEO_COLOR_PLACEMENT Blue;
BIOS_VIDEO_COLOR_PLACEMENT Reserved; BIOS_VIDEO_COLOR_PLACEMENT Reserved;
EFI_GRAPHICS_PIXEL_FORMAT PixelFormat; EFI_GRAPHICS_PIXEL_FORMAT PixelFormat;
EFI_PIXEL_BITMASK PixelBitMask; EFI_PIXEL_BITMASK PixelBitMask;
} BIOS_VIDEO_MODE_DATA; } BIOS_VIDEO_MODE_DATA;
// //
// BIOS video child handle private data Structure // BIOS video child handle private data Structure
// //
#define BIOS_VIDEO_DEV_SIGNATURE SIGNATURE_32 ('B', 'V', 'M', 'p') #define BIOS_VIDEO_DEV_SIGNATURE SIGNATURE_32 ('B', 'V', 'M', 'p')
typedef struct { typedef struct {
UINTN Signature; UINTN Signature;
EFI_HANDLE Handle; EFI_HANDLE Handle;
// //
// Consumed Protocols // Consumed Protocols
// //
EFI_PCI_IO_PROTOCOL *PciIo; EFI_PCI_IO_PROTOCOL *PciIo;
EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;
// //
// Produced Protocols // Produced Protocols
// //
EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput; EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput;
EFI_EDID_DISCOVERED_PROTOCOL EdidDiscovered; EFI_EDID_DISCOVERED_PROTOCOL EdidDiscovered;
EFI_EDID_ACTIVE_PROTOCOL EdidActive; EFI_EDID_ACTIVE_PROTOCOL EdidActive;
EFI_VGA_MINI_PORT_PROTOCOL VgaMiniPort; EFI_VGA_MINI_PORT_PROTOCOL VgaMiniPort;
// //
// General fields // General fields
// //
BOOLEAN VgaCompatible; BOOLEAN VgaCompatible;
BOOLEAN ProduceGraphicsOutput; BOOLEAN ProduceGraphicsOutput;
// //
// Graphics Output Protocol related fields // Graphics Output Protocol related fields
// //
BOOLEAN HardwareNeedsStarting; BOOLEAN HardwareNeedsStarting;
UINTN CurrentMode; UINTN CurrentMode;
UINTN MaxMode; UINTN MaxMode;
BIOS_VIDEO_MODE_DATA *ModeData; BIOS_VIDEO_MODE_DATA *ModeData;
UINT8 *LineBuffer; UINT8 *LineBuffer;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *VbeFrameBuffer; EFI_GRAPHICS_OUTPUT_BLT_PIXEL *VbeFrameBuffer;
UINT8 *VgaFrameBuffer; UINT8 *VgaFrameBuffer;
// //
// VESA Bios Extensions related fields // VESA Bios Extensions related fields
// //
UINTN NumberOfPagesBelow1MB; // Number of 4KB pages in PagesBelow1MB UINTN NumberOfPagesBelow1MB; // Number of 4KB pages in PagesBelow1MB
EFI_PHYSICAL_ADDRESS PagesBelow1MB; // Buffer for all VBE Information Blocks EFI_PHYSICAL_ADDRESS PagesBelow1MB; // Buffer for all VBE Information Blocks
VESA_BIOS_EXTENSIONS_INFORMATION_BLOCK *VbeInformationBlock; // 0x200 bytes. Must be allocated below 1MB VESA_BIOS_EXTENSIONS_INFORMATION_BLOCK *VbeInformationBlock; // 0x200 bytes. Must be allocated below 1MB
VESA_BIOS_EXTENSIONS_MODE_INFORMATION_BLOCK *VbeModeInformationBlock; // 0x100 bytes. Must be allocated below 1MB VESA_BIOS_EXTENSIONS_MODE_INFORMATION_BLOCK *VbeModeInformationBlock; // 0x100 bytes. Must be allocated below 1MB
VESA_BIOS_EXTENSIONS_EDID_DATA_BLOCK *VbeEdidDataBlock; // 0x80 bytes. Must be allocated below 1MB VESA_BIOS_EXTENSIONS_EDID_DATA_BLOCK *VbeEdidDataBlock; // 0x80 bytes. Must be allocated below 1MB
VESA_BIOS_EXTENSIONS_CRTC_INFORMATION_BLOCK *VbeCrtcInformationBlock; // 59 bytes. Must be allocated below 1MB VESA_BIOS_EXTENSIONS_CRTC_INFORMATION_BLOCK *VbeCrtcInformationBlock; // 59 bytes. Must be allocated below 1MB
UINTN VbeSaveRestorePages; // Number of 4KB pages in VbeSaveRestoreBuffer UINTN VbeSaveRestorePages; // Number of 4KB pages in VbeSaveRestoreBuffer
EFI_PHYSICAL_ADDRESS VbeSaveRestoreBuffer; // Must be allocated below 1MB EFI_PHYSICAL_ADDRESS VbeSaveRestoreBuffer; // Must be allocated below 1MB
// //
// Status code // Status code
// //
EFI_DEVICE_PATH_PROTOCOL *GopDevicePath; EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;
EFI_EVENT ExitBootServicesEvent; EFI_EVENT ExitBootServicesEvent;
} BIOS_VIDEO_DEV; } BIOS_VIDEO_DEV;
#define BIOS_VIDEO_DEV_FROM_PCI_IO_THIS(a) CR (a, BIOS_VIDEO_DEV, PciIo, BIOS_VIDEO_DEV_SIGNATURE) #define BIOS_VIDEO_DEV_FROM_PCI_IO_THIS(a) CR (a, BIOS_VIDEO_DEV, PciIo, BIOS_VIDEO_DEV_SIGNATURE)
@ -164,7 +164,6 @@ BiosVideoDriverBindingSupported (
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
); );
/** /**
Install Graphics Output Protocol onto VGA device handles. Install Graphics Output Protocol onto VGA device handles.
@ -184,7 +183,6 @@ BiosVideoDriverBindingStart (
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
); );
/** /**
Stop. Stop.
@ -223,7 +221,6 @@ BiosVideoCheckForVbe (
IN OUT BIOS_VIDEO_DEV *BiosVideoPrivate IN OUT BIOS_VIDEO_DEV *BiosVideoPrivate
); );
/** /**
Check for VGA device. Check for VGA device.
@ -237,9 +234,6 @@ BiosVideoCheckForVga (
IN OUT BIOS_VIDEO_DEV *BiosVideoPrivate IN OUT BIOS_VIDEO_DEV *BiosVideoPrivate
); );
/** /**
Release resource for BIOS video instance. Release resource for BIOS video instance.
@ -282,7 +276,6 @@ BiosVideoGraphicsOutputQueryMode (
OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info
); );
/** /**
Graphics Output protocol interface to set video mode. Graphics Output protocol interface to set video mode.
@ -298,11 +291,10 @@ BiosVideoGraphicsOutputQueryMode (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
BiosVideoGraphicsOutputSetMode ( BiosVideoGraphicsOutputSetMode (
IN EFI_GRAPHICS_OUTPUT_PROTOCOL * This, IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
IN UINT32 ModeNumber IN UINT32 ModeNumber
); );
/** /**
Graphics Output protocol instance to block transfer for VBE device. Graphics Output protocol instance to block transfer for VBE device.
@ -345,7 +337,6 @@ BiosVideoGraphicsOutputVbeBlt (
IN UINTN Delta IN UINTN Delta
); );
/** /**
Graphics Output protocol instance to block transfer for VGA device. Graphics Output protocol instance to block transfer for VGA device.
@ -419,50 +410,50 @@ BiosVideoVgaMiniPortSetMode (
VOID VOID
EFIAPI EFIAPI
BiosVideoNotifyExitBootServices ( BiosVideoNotifyExitBootServices (
IN EFI_EVENT Event, IN EFI_EVENT Event,
IN VOID *Context IN VOID *Context
); );
// //
// Standard VGA Definitions // Standard VGA Definitions
// //
#define VGA_HORIZONTAL_RESOLUTION 640 #define VGA_HORIZONTAL_RESOLUTION 640
#define VGA_VERTICAL_RESOLUTION 480 #define VGA_VERTICAL_RESOLUTION 480
#define VGA_NUMBER_OF_BIT_PLANES 4 #define VGA_NUMBER_OF_BIT_PLANES 4
#define VGA_PIXELS_PER_BYTE 8 #define VGA_PIXELS_PER_BYTE 8
#define VGA_BYTES_PER_SCAN_LINE (VGA_HORIZONTAL_RESOLUTION / VGA_PIXELS_PER_BYTE) #define VGA_BYTES_PER_SCAN_LINE (VGA_HORIZONTAL_RESOLUTION / VGA_PIXELS_PER_BYTE)
#define VGA_BYTES_PER_BIT_PLANE (VGA_VERTICAL_RESOLUTION * VGA_BYTES_PER_SCAN_LINE) #define VGA_BYTES_PER_BIT_PLANE (VGA_VERTICAL_RESOLUTION * VGA_BYTES_PER_SCAN_LINE)
#define VGA_GRAPHICS_CONTROLLER_ADDRESS_REGISTER 0x3ce #define VGA_GRAPHICS_CONTROLLER_ADDRESS_REGISTER 0x3ce
#define VGA_GRAPHICS_CONTROLLER_DATA_REGISTER 0x3cf #define VGA_GRAPHICS_CONTROLLER_DATA_REGISTER 0x3cf
#define VGA_GRAPHICS_CONTROLLER_SET_RESET_REGISTER 0x00 #define VGA_GRAPHICS_CONTROLLER_SET_RESET_REGISTER 0x00
#define VGA_GRAPHICS_CONTROLLER_ENABLE_SET_RESET_REGISTER 0x01 #define VGA_GRAPHICS_CONTROLLER_ENABLE_SET_RESET_REGISTER 0x01
#define VGA_GRAPHICS_CONTROLLER_COLOR_COMPARE_REGISTER 0x02 #define VGA_GRAPHICS_CONTROLLER_COLOR_COMPARE_REGISTER 0x02
#define VGA_GRAPHICS_CONTROLLER_DATA_ROTATE_REGISTER 0x03 #define VGA_GRAPHICS_CONTROLLER_DATA_ROTATE_REGISTER 0x03
#define VGA_GRAPHICS_CONTROLLER_FUNCTION_REPLACE 0x00 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_REPLACE 0x00
#define VGA_GRAPHICS_CONTROLLER_FUNCTION_AND 0x08 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_AND 0x08
#define VGA_GRAPHICS_CONTROLLER_FUNCTION_OR 0x10 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_OR 0x10
#define VGA_GRAPHICS_CONTROLLER_FUNCTION_XOR 0x18 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_XOR 0x18
#define VGA_GRAPHICS_CONTROLLER_READ_MAP_SELECT_REGISTER 0x04 #define VGA_GRAPHICS_CONTROLLER_READ_MAP_SELECT_REGISTER 0x04
#define VGA_GRAPHICS_CONTROLLER_MODE_REGISTER 0x05 #define VGA_GRAPHICS_CONTROLLER_MODE_REGISTER 0x05
#define VGA_GRAPHICS_CONTROLLER_READ_MODE_0 0x00 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_0 0x00
#define VGA_GRAPHICS_CONTROLLER_READ_MODE_1 0x08 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_1 0x08
#define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_0 0x00 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_0 0x00
#define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_1 0x01 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_1 0x01
#define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_2 0x02 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_2 0x02
#define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_3 0x03 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_3 0x03
#define VGA_GRAPHICS_CONTROLLER_MISCELLANEOUS_REGISTER 0x06 #define VGA_GRAPHICS_CONTROLLER_MISCELLANEOUS_REGISTER 0x06
#define VGA_GRAPHICS_CONTROLLER_COLOR_DONT_CARE_REGISTER 0x07 #define VGA_GRAPHICS_CONTROLLER_COLOR_DONT_CARE_REGISTER 0x07
#define VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER 0x08 #define VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER 0x08
/** /**
Install child handles if the Handle supports MBR format. Install child handles if the Handle supports MBR format.
@ -500,9 +491,9 @@ BiosVideoChildHandleInstall (
**/ **/
EFI_STATUS EFI_STATUS
BiosVideoChildHandleUninstall ( BiosVideoChildHandleUninstall (
EFI_DRIVER_BINDING_PROTOCOL *This, EFI_DRIVER_BINDING_PROTOCOL *This,
EFI_HANDLE Controller, EFI_HANDLE Controller,
EFI_HANDLE Handle EFI_HANDLE Handle
); );
/** /**
@ -529,4 +520,5 @@ BOOLEAN
HasChildHandle ( HasChildHandle (
IN EFI_HANDLE Controller IN EFI_HANDLE Controller
); );
#endif #endif

View File

@ -11,6 +11,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// //
// EFI Component Name Functions // EFI Component Name Functions
// //
/** /**
Retrieves a Unicode string that is the user readable name of the driver. Retrieves a Unicode string that is the user readable name of the driver.
@ -58,7 +59,6 @@ BiosVideoComponentNameGetDriverName (
OUT CHAR16 **DriverName OUT CHAR16 **DriverName
); );
/** /**
Retrieves a Unicode string that is the user readable name of the controller Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver. that is being managed by a driver.
@ -130,14 +130,13 @@ BiosVideoComponentNameGetDriverName (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
BiosVideoComponentNameGetControllerName ( BiosVideoComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL, IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language, IN CHAR8 *Language,
OUT CHAR16 **ControllerName OUT CHAR16 **ControllerName
); );
// //
// EFI Component Name Protocol // EFI Component Name Protocol
// //
@ -150,14 +149,13 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gBiosVideoComponentNa
// //
// EFI Component Name 2 Protocol // EFI Component Name 2 Protocol
// //
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gBiosVideoComponentName2 = { GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gBiosVideoComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) BiosVideoComponentNameGetDriverName, (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)BiosVideoComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) BiosVideoComponentNameGetControllerName, (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)BiosVideoComponentNameGetControllerName,
"en" "en"
}; };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mBiosVideoDriverNameTable[] = {
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mBiosVideoDriverNameTable[] = {
{ {
"eng;en", "eng;en",
L"BIOS[INT10] Video Driver" L"BIOS[INT10] Video Driver"
@ -295,11 +293,11 @@ BiosVideoComponentNameGetDriverName (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
BiosVideoComponentNameGetControllerName ( BiosVideoComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL, IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language, IN CHAR8 *Language,
OUT CHAR16 **ControllerName OUT CHAR16 **ControllerName
) )
{ {
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;

View File

@ -16,7 +16,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// //
// VESA BIOS Extensions status codes // VESA BIOS Extensions status codes
// //
#define VESA_BIOS_EXTENSIONS_STATUS_SUCCESS 0x004f #define VESA_BIOS_EXTENSIONS_STATUS_SUCCESS 0x004f
// //
// VESA BIOS Extensions Services // VESA BIOS Extensions Services
@ -52,7 +52,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
AX = Return Status AX = Return Status
--*/ --*/
#define VESA_BIOS_EXTENSIONS_SET_MODE 0x4f02 #define VESA_BIOS_EXTENSIONS_SET_MODE 0x4f02
/*++ /*++
@ -97,7 +97,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
= 1 - Memory not cleared at last mode set = 1 - Memory not cleared at last mode set
--*/ --*/
#define VESA_BIOS_EXTENSIONS_SAVE_RESTORE_STATE 0x4f04 #define VESA_BIOS_EXTENSIONS_SAVE_RESTORE_STATE 0x4f04
/*++ /*++
@ -158,89 +158,89 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// //
// Timing data from EDID data block // Timing data from EDID data block
// //
#define VESA_BIOS_EXTENSIONS_EDID_BLOCK_SIZE 128 #define VESA_BIOS_EXTENSIONS_EDID_BLOCK_SIZE 128
#define VESA_BIOS_EXTENSIONS_EDID_ESTABLISHED_TIMING_MAX_NUMBER 17 #define VESA_BIOS_EXTENSIONS_EDID_ESTABLISHED_TIMING_MAX_NUMBER 17
// //
// Established Timings: 24 possible resolutions // Established Timings: 24 possible resolutions
// Standard Timings: 8 possible resolutions // Standard Timings: 8 possible resolutions
// Detailed Timings: 4 possible resolutions // Detailed Timings: 4 possible resolutions
// //
#define VESA_BIOS_EXTENSIONS_EDID_TIMING_MAX_NUMBER 36 #define VESA_BIOS_EXTENSIONS_EDID_TIMING_MAX_NUMBER 36
// //
// Timing data size for Established Timings, Standard Timings and Detailed Timings // Timing data size for Established Timings, Standard Timings and Detailed Timings
// //
#define VESA_BIOS_EXTENSIONS_ESTABLISHED_TIMING_SIZE 3 #define VESA_BIOS_EXTENSIONS_ESTABLISHED_TIMING_SIZE 3
#define VESA_BIOS_EXTENSIONS_STANDARD_TIMING_SIZE 16 #define VESA_BIOS_EXTENSIONS_STANDARD_TIMING_SIZE 16
#define VESA_BIOS_EXTENSIONS_DETAILED_TIMING_EACH_DESCRIPTOR_SIZE 18 #define VESA_BIOS_EXTENSIONS_DETAILED_TIMING_EACH_DESCRIPTOR_SIZE 18
#define VESA_BIOS_EXTENSIONS_DETAILED_TIMING_DESCRIPTOR_MAX_SIZE 72 #define VESA_BIOS_EXTENSIONS_DETAILED_TIMING_DESCRIPTOR_MAX_SIZE 72
typedef struct { typedef struct {
UINT16 HorizontalResolution; UINT16 HorizontalResolution;
UINT16 VerticalResolution; UINT16 VerticalResolution;
UINT16 RefreshRate; UINT16 RefreshRate;
} VESA_BIOS_EXTENSIONS_EDID_TIMING; } VESA_BIOS_EXTENSIONS_EDID_TIMING;
typedef struct { typedef struct {
UINT32 ValidNumber; UINT32 ValidNumber;
UINT32 Key[VESA_BIOS_EXTENSIONS_EDID_TIMING_MAX_NUMBER]; UINT32 Key[VESA_BIOS_EXTENSIONS_EDID_TIMING_MAX_NUMBER];
} VESA_BIOS_EXTENSIONS_VALID_EDID_TIMING; } VESA_BIOS_EXTENSIONS_VALID_EDID_TIMING;
typedef struct { typedef struct {
UINT8 Header[8]; //EDID header "00 FF FF FF FF FF FF 00" UINT8 Header[8]; // EDID header "00 FF FF FF FF FF FF 00"
UINT16 ManufactureName; //EISA 3-character ID UINT16 ManufactureName; // EISA 3-character ID
UINT16 ProductCode; //Vendor assigned code UINT16 ProductCode; // Vendor assigned code
UINT32 SerialNumber; //32-bit serial number UINT32 SerialNumber; // 32-bit serial number
UINT8 WeekOfManufacture; //Week number UINT8 WeekOfManufacture; // Week number
UINT8 YearOfManufacture; //Year UINT8 YearOfManufacture; // Year
UINT8 EdidVersion; //EDID Structure Version UINT8 EdidVersion; // EDID Structure Version
UINT8 EdidRevision; //EDID Structure Revision UINT8 EdidRevision; // EDID Structure Revision
UINT8 VideoInputDefinition; UINT8 VideoInputDefinition;
UINT8 MaxHorizontalImageSize; //cm UINT8 MaxHorizontalImageSize; // cm
UINT8 MaxVerticalImageSize; //cm UINT8 MaxVerticalImageSize; // cm
UINT8 DisplayTransferCharacteristic; UINT8 DisplayTransferCharacteristic;
UINT8 FeatureSupport; UINT8 FeatureSupport;
UINT8 RedGreenLowBits; //Rx1 Rx0 Ry1 Ry0 Gx1 Gx0 Gy1Gy0 UINT8 RedGreenLowBits; // Rx1 Rx0 Ry1 Ry0 Gx1 Gx0 Gy1Gy0
UINT8 BlueWhiteLowBits; //Bx1 Bx0 By1 By0 Wx1 Wx0 Wy1 Wy0 UINT8 BlueWhiteLowBits; // Bx1 Bx0 By1 By0 Wx1 Wx0 Wy1 Wy0
UINT8 RedX; //Red-x Bits 9 - 2 UINT8 RedX; // Red-x Bits 9 - 2
UINT8 RedY; //Red-y Bits 9 - 2 UINT8 RedY; // Red-y Bits 9 - 2
UINT8 GreenX; //Green-x Bits 9 - 2 UINT8 GreenX; // Green-x Bits 9 - 2
UINT8 GreenY; //Green-y Bits 9 - 2 UINT8 GreenY; // Green-y Bits 9 - 2
UINT8 BlueX; //Blue-x Bits 9 - 2 UINT8 BlueX; // Blue-x Bits 9 - 2
UINT8 BlueY; //Blue-y Bits 9 - 2 UINT8 BlueY; // Blue-y Bits 9 - 2
UINT8 WhiteX; //White-x Bits 9 - 2 UINT8 WhiteX; // White-x Bits 9 - 2
UINT8 WhiteY; //White-x Bits 9 - 2 UINT8 WhiteY; // White-x Bits 9 - 2
UINT8 EstablishedTimings[VESA_BIOS_EXTENSIONS_ESTABLISHED_TIMING_SIZE]; UINT8 EstablishedTimings[VESA_BIOS_EXTENSIONS_ESTABLISHED_TIMING_SIZE];
UINT8 StandardTimingIdentification[VESA_BIOS_EXTENSIONS_STANDARD_TIMING_SIZE]; UINT8 StandardTimingIdentification[VESA_BIOS_EXTENSIONS_STANDARD_TIMING_SIZE];
UINT8 DetailedTimingDescriptions[VESA_BIOS_EXTENSIONS_DETAILED_TIMING_DESCRIPTOR_MAX_SIZE]; UINT8 DetailedTimingDescriptions[VESA_BIOS_EXTENSIONS_DETAILED_TIMING_DESCRIPTOR_MAX_SIZE];
UINT8 ExtensionFlag; //Number of (optional) 128-byte EDID extension blocks to follow UINT8 ExtensionFlag; // Number of (optional) 128-byte EDID extension blocks to follow
UINT8 Checksum; UINT8 Checksum;
} VESA_BIOS_EXTENSIONS_EDID_DATA_BLOCK; } VESA_BIOS_EXTENSIONS_EDID_DATA_BLOCK;
// //
// Super VGA Information Block // Super VGA Information Block
// //
typedef struct { typedef struct {
UINT32 VESASignature; // 'VESA' 4 byte signature UINT32 VESASignature; // 'VESA' 4 byte signature
UINT16 VESAVersion; // VBE version number UINT16 VESAVersion; // VBE version number
UINT32 OEMStringPtr; // Pointer to OEM string UINT32 OEMStringPtr; // Pointer to OEM string
UINT32 Capabilities; // Capabilities of video card UINT32 Capabilities; // Capabilities of video card
UINT32 VideoModePtr; // Pointer to an array of 16-bit supported modes values terminated by 0xFFFF UINT32 VideoModePtr; // Pointer to an array of 16-bit supported modes values terminated by 0xFFFF
UINT16 TotalMemory; // Number of 64kb memory blocks UINT16 TotalMemory; // Number of 64kb memory blocks
UINT16 OemSoftwareRev; // VBE implementation Software revision UINT16 OemSoftwareRev; // VBE implementation Software revision
UINT32 OemVendorNamePtr; // VbeFarPtr to Vendor Name String UINT32 OemVendorNamePtr; // VbeFarPtr to Vendor Name String
UINT32 OemProductNamePtr; // VbeFarPtr to Product Name String UINT32 OemProductNamePtr; // VbeFarPtr to Product Name String
UINT32 OemProductRevPtr; // VbeFarPtr to Product Revision String UINT32 OemProductRevPtr; // VbeFarPtr to Product Revision String
UINT8 Reserved[222]; // Reserved for VBE implementation scratch area UINT8 Reserved[222]; // Reserved for VBE implementation scratch area
UINT8 OemData[256]; // Data area for OEM strings. Pad to 512 byte block size UINT8 OemData[256]; // Data area for OEM strings. Pad to 512 byte block size
} VESA_BIOS_EXTENSIONS_INFORMATION_BLOCK; } VESA_BIOS_EXTENSIONS_INFORMATION_BLOCK;
// //
// Super VGA Information Block VESASignature values // Super VGA Information Block VESASignature values
// //
#define VESA_BIOS_EXTENSIONS_VESA_SIGNATURE SIGNATURE_32 ('V', 'E', 'S', 'A') #define VESA_BIOS_EXTENSIONS_VESA_SIGNATURE SIGNATURE_32 ('V', 'E', 'S', 'A')
#define VESA_BIOS_EXTENSIONS_VBE2_SIGNATURE SIGNATURE_32 ('V', 'B', 'E', '2') #define VESA_BIOS_EXTENSIONS_VBE2_SIGNATURE SIGNATURE_32 ('V', 'B', 'E', '2')
// //
// Super VGA Information Block VESAVersion values // Super VGA Information Block VESAVersion values
@ -252,13 +252,13 @@ typedef struct {
// //
// Super VGA Information Block Capabilities field bit definitions // Super VGA Information Block Capabilities field bit definitions
// //
#define VESA_BIOS_EXTENSIONS_CAPABILITY_8_BIT_DAC 0x01 // 0: DAC width is fixed at 6 bits/color #define VESA_BIOS_EXTENSIONS_CAPABILITY_8_BIT_DAC 0x01 // 0: DAC width is fixed at 6 bits/color
// 1: DAC width switchable to 8 bits/color // 1: DAC width switchable to 8 bits/color
// //
#define VESA_BIOS_EXTENSIONS_CAPABILITY_NOT_VGA 0x02 // 0: Controller is VGA compatible #define VESA_BIOS_EXTENSIONS_CAPABILITY_NOT_VGA 0x02 // 0: Controller is VGA compatible
// 1: Controller is not VGA compatible // 1: Controller is not VGA compatible
// //
#define VESA_BIOS_EXTENSIONS_CAPABILITY_NOT_NORMAL_RAMDAC 0x04 // 0: Normal RAMDAC operation #define VESA_BIOS_EXTENSIONS_CAPABILITY_NOT_NORMAL_RAMDAC 0x04 // 0: Normal RAMDAC operation
// 1: Use blank bit in function 9 to program RAMDAC // 1: Use blank bit in function 9 to program RAMDAC
// //
#define VESA_BIOS_EXTENSIONS_CAPABILITY_STEREOSCOPIC 0x08 // 0: No hardware stereoscopic signal support #define VESA_BIOS_EXTENSIONS_CAPABILITY_STEREOSCOPIC 0x08 // 0: No hardware stereoscopic signal support
@ -269,10 +269,10 @@ typedef struct {
// //
// Super VGA mode number bite field definitions // Super VGA mode number bite field definitions
// //
#define VESA_BIOS_EXTENSIONS_MODE_NUMBER_VESA 0x0100 // 0: Not a VESA defined VBE mode #define VESA_BIOS_EXTENSIONS_MODE_NUMBER_VESA 0x0100 // 0: Not a VESA defined VBE mode
// 1: A VESA defined VBE mode // 1: A VESA defined VBE mode
// //
#define VESA_BIOS_EXTENSIONS_MODE_NUMBER_REFRESH_CONTROL_USER 0x0800 // 0: Use current BIOS default referesh rate #define VESA_BIOS_EXTENSIONS_MODE_NUMBER_REFRESH_CONTROL_USER 0x0800 // 0: Use current BIOS default referesh rate
// 1: Use the user specified CRTC values for refresh rate // 1: Use the user specified CRTC values for refresh rate
// //
#define VESA_BIOS_EXTENSIONS_MODE_NUMBER_LINEAR_FRAME_BUFFER 0x4000 // 0: Use a banked/windowed frame buffer #define VESA_BIOS_EXTENSIONS_MODE_NUMBER_LINEAR_FRAME_BUFFER 0x4000 // 0: Use a banked/windowed frame buffer
@ -283,7 +283,7 @@ typedef struct {
// //
// Super VGA Information Block mode list terminator value // Super VGA Information Block mode list terminator value
// //
#define VESA_BIOS_EXTENSIONS_END_OF_MODE_LIST 0xffff #define VESA_BIOS_EXTENSIONS_END_OF_MODE_LIST 0xffff
// //
// Window Function // Window Function
@ -301,60 +301,60 @@ typedef struct {
// //
// Manadory fields for all VESA Bios Extensions revisions // Manadory fields for all VESA Bios Extensions revisions
// //
UINT16 ModeAttributes; // Mode attributes UINT16 ModeAttributes; // Mode attributes
UINT8 WinAAttributes; // Window A attributes UINT8 WinAAttributes; // Window A attributes
UINT8 WinBAttributes; // Window B attributes UINT8 WinBAttributes; // Window B attributes
UINT16 WinGranularity; // Window granularity in k UINT16 WinGranularity; // Window granularity in k
UINT16 WinSize; // Window size in k UINT16 WinSize; // Window size in k
UINT16 WinASegment; // Window A segment UINT16 WinASegment; // Window A segment
UINT16 WinBSegment; // Window B segment UINT16 WinBSegment; // Window B segment
UINT32 WindowFunction; // Pointer to window function UINT32 WindowFunction; // Pointer to window function
UINT16 BytesPerScanLine; // Bytes per scanline UINT16 BytesPerScanLine; // Bytes per scanline
// //
// Manadory fields for VESA Bios Extensions 1.2 and above // Manadory fields for VESA Bios Extensions 1.2 and above
// //
UINT16 XResolution; // Horizontal resolution UINT16 XResolution; // Horizontal resolution
UINT16 YResolution; // Vertical resolution UINT16 YResolution; // Vertical resolution
UINT8 XCharSize; // Character cell width UINT8 XCharSize; // Character cell width
UINT8 YCharSize; // Character cell height UINT8 YCharSize; // Character cell height
UINT8 NumberOfPlanes; // Number of memory planes UINT8 NumberOfPlanes; // Number of memory planes
UINT8 BitsPerPixel; // Bits per pixel UINT8 BitsPerPixel; // Bits per pixel
UINT8 NumberOfBanks; // Number of CGA style banks UINT8 NumberOfBanks; // Number of CGA style banks
UINT8 MemoryModel; // Memory model type UINT8 MemoryModel; // Memory model type
UINT8 BankSize; // Size of CGA style banks UINT8 BankSize; // Size of CGA style banks
UINT8 NumberOfImagePages; // Number of images pages UINT8 NumberOfImagePages; // Number of images pages
UINT8 Reserved1; // Reserved UINT8 Reserved1; // Reserved
UINT8 RedMaskSize; // Size of direct color red mask UINT8 RedMaskSize; // Size of direct color red mask
UINT8 RedFieldPosition; // Bit posn of lsb of red mask UINT8 RedFieldPosition; // Bit posn of lsb of red mask
UINT8 GreenMaskSize; // Size of direct color green mask UINT8 GreenMaskSize; // Size of direct color green mask
UINT8 GreenFieldPosition; // Bit posn of lsb of green mask UINT8 GreenFieldPosition; // Bit posn of lsb of green mask
UINT8 BlueMaskSize; // Size of direct color blue mask UINT8 BlueMaskSize; // Size of direct color blue mask
UINT8 BlueFieldPosition; // Bit posn of lsb of blue mask UINT8 BlueFieldPosition; // Bit posn of lsb of blue mask
UINT8 RsvdMaskSize; // Size of direct color res mask UINT8 RsvdMaskSize; // Size of direct color res mask
UINT8 RsvdFieldPosition; // Bit posn of lsb of res mask UINT8 RsvdFieldPosition; // Bit posn of lsb of res mask
UINT8 DirectColorModeInfo; // Direct color mode attributes UINT8 DirectColorModeInfo; // Direct color mode attributes
// //
// Manadory fields for VESA Bios Extensions 2.0 and above // Manadory fields for VESA Bios Extensions 2.0 and above
// //
UINT32 PhysBasePtr; // Physical Address for flat memory frame buffer UINT32 PhysBasePtr; // Physical Address for flat memory frame buffer
UINT32 Reserved2; // Reserved UINT32 Reserved2; // Reserved
UINT16 Reserved3; // Reserved UINT16 Reserved3; // Reserved
// //
// Manadory fields for VESA Bios Extensions 3.0 and above // Manadory fields for VESA Bios Extensions 3.0 and above
// //
UINT16 LinBytesPerScanLine; // Bytes/scan line for linear modes UINT16 LinBytesPerScanLine; // Bytes/scan line for linear modes
UINT8 BnkNumberOfImagePages; // Number of images for banked modes UINT8 BnkNumberOfImagePages; // Number of images for banked modes
UINT8 LinNumberOfImagePages; // Number of images for linear modes UINT8 LinNumberOfImagePages; // Number of images for linear modes
UINT8 LinRedMaskSize; // Size of direct color red mask (linear mode) UINT8 LinRedMaskSize; // Size of direct color red mask (linear mode)
UINT8 LinRedFieldPosition; // Bit posiiton of lsb of red mask (linear modes) UINT8 LinRedFieldPosition; // Bit posiiton of lsb of red mask (linear modes)
UINT8 LinGreenMaskSize; // Size of direct color green mask (linear mode) UINT8 LinGreenMaskSize; // Size of direct color green mask (linear mode)
UINT8 LinGreenFieldPosition; // Bit posiiton of lsb of green mask (linear modes) UINT8 LinGreenFieldPosition; // Bit posiiton of lsb of green mask (linear modes)
UINT8 LinBlueMaskSize; // Size of direct color blue mask (linear mode) UINT8 LinBlueMaskSize; // Size of direct color blue mask (linear mode)
UINT8 LinBlueFieldPosition; // Bit posiiton of lsb of blue mask (linear modes) UINT8 LinBlueFieldPosition; // Bit posiiton of lsb of blue mask (linear modes)
UINT8 LinRsvdMaskSize; // Size of direct color reserved mask (linear mode) UINT8 LinRsvdMaskSize; // Size of direct color reserved mask (linear mode)
UINT8 LinRsvdFieldPosition; // Bit posiiton of lsb of reserved mask (linear modes) UINT8 LinRsvdFieldPosition; // Bit posiiton of lsb of reserved mask (linear modes)
UINT32 MaxPixelClock; // Maximum pixel clock (in Hz) for graphics mode UINT32 MaxPixelClock; // Maximum pixel clock (in Hz) for graphics mode
UINT8 Pad[190]; // Pad to 256 byte block size UINT8 Pad[190]; // Pad to 256 byte block size
} VESA_BIOS_EXTENSIONS_MODE_INFORMATION_BLOCK; } VESA_BIOS_EXTENSIONS_MODE_INFORMATION_BLOCK;
// //
@ -363,31 +363,31 @@ typedef struct {
#define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_HARDWARE 0x0001 // 0: Mode not supported in handware #define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_HARDWARE 0x0001 // 0: Mode not supported in handware
// 1: Mode supported in handware // 1: Mode supported in handware
// //
#define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_TTY 0x0004 // 0: TTY Output functions not supported by BIOS #define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_TTY 0x0004 // 0: TTY Output functions not supported by BIOS
// 1: TTY Output functions supported by BIOS // 1: TTY Output functions supported by BIOS
// //
#define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_COLOR 0x0008 // 0: Monochrome mode #define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_COLOR 0x0008 // 0: Monochrome mode
// 1: Color mode // 1: Color mode
// //
#define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_GRAPHICS 0x0010 // 0: Text mode #define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_GRAPHICS 0x0010 // 0: Text mode
// 1: Graphics mode // 1: Graphics mode
// //
#define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_NOT_VGA 0x0020 // 0: VGA compatible mode #define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_NOT_VGA 0x0020 // 0: VGA compatible mode
// 1: Not a VGA compatible mode // 1: Not a VGA compatible mode
// //
#define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_NOT_WINDOWED 0x0040 // 0: VGA compatible windowed memory mode #define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_NOT_WINDOWED 0x0040 // 0: VGA compatible windowed memory mode
// 1: Not a VGA compatible windowed memory mode // 1: Not a VGA compatible windowed memory mode
// //
#define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER 0x0080 // 0: No linear fram buffer mode available #define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER 0x0080 // 0: No linear fram buffer mode available
// 1: Linear frame buffer mode available // 1: Linear frame buffer mode available
// //
#define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_DOUBLE_SCAN 0x0100 // 0: No double scan mode available #define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_DOUBLE_SCAN 0x0100 // 0: No double scan mode available
// 1: Double scan mode available // 1: Double scan mode available
// //
#define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_INTERLACED 0x0200 // 0: No interlaced mode is available #define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_INTERLACED 0x0200 // 0: No interlaced mode is available
// 1: Interlaced mode is available // 1: Interlaced mode is available
// //
#define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_NO_TRIPPLE_BUFFER 0x0400 // 0: No hardware triple buffer mode support available #define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_NO_TRIPPLE_BUFFER 0x0400 // 0: No hardware triple buffer mode support available
// 1: Hardware triple buffer mode support available // 1: Hardware triple buffer mode support available
// //
#define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_STEREOSCOPIC 0x0800 // 0: No hardware steroscopic display support #define VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_STEREOSCOPIC 0x0800 // 0: No hardware steroscopic display support
@ -398,7 +398,7 @@ typedef struct {
// //
// Super VGA Mode Information Block WinAAttribite/WinBAttributes field bit definitions // Super VGA Mode Information Block WinAAttribite/WinBAttributes field bit definitions
// //
#define VESA_BIOS_EXTENSIONS_WINX_ATTRIBUTE_RELOCATABLE 0x01 // 0: Single non-relocatable window only #define VESA_BIOS_EXTENSIONS_WINX_ATTRIBUTE_RELOCATABLE 0x01 // 0: Single non-relocatable window only
// 1: Relocatable window(s) are supported // 1: Relocatable window(s) are supported
// //
#define VESA_BIOS_EXTENSIONS_WINX_ATTRIBUTE_READABLE 0x02 // 0: Window is not readable #define VESA_BIOS_EXTENSIONS_WINX_ATTRIBUTE_READABLE 0x02 // 0: Window is not readable
@ -418,38 +418,38 @@ typedef struct {
// Super VGA Memory Models // Super VGA Memory Models
// //
typedef enum { typedef enum {
MemPL = 3, // Planar memory model MemPL = 3, // Planar memory model
MemPK = 4, // Packed pixel memory model MemPK = 4, // Packed pixel memory model
MemRGB= 6, // Direct color RGB memory model MemRGB = 6, // Direct color RGB memory model
MemYUV= 7 // Direct color YUV memory model MemYUV = 7 // Direct color YUV memory model
} VESA_BIOS_EXTENSIONS_MEMORY_MODELS; } VESA_BIOS_EXTENSIONS_MEMORY_MODELS;
// //
// Super VGA CRTC Information Block // Super VGA CRTC Information Block
// //
typedef struct { typedef struct {
UINT16 HorizontalTotal; // Horizontal total in pixels UINT16 HorizontalTotal; // Horizontal total in pixels
UINT16 HorizontalSyncStart; // Horizontal sync start in pixels UINT16 HorizontalSyncStart; // Horizontal sync start in pixels
UINT16 HorizontalSyncEnd; // Horizontal sync end in pixels UINT16 HorizontalSyncEnd; // Horizontal sync end in pixels
UINT16 VericalTotal; // Vertical total in pixels UINT16 VericalTotal; // Vertical total in pixels
UINT16 VericalSyncStart; // Vertical sync start in pixels UINT16 VericalSyncStart; // Vertical sync start in pixels
UINT16 VericalSyncEnd; // Vertical sync end in pixels UINT16 VericalSyncEnd; // Vertical sync end in pixels
UINT8 Flags; // Flags (Interlaced/DoubleScan/etc). UINT8 Flags; // Flags (Interlaced/DoubleScan/etc).
UINT32 PixelClock; // Pixel clock in units of Hz UINT32 PixelClock; // Pixel clock in units of Hz
UINT16 RefreshRate; // Refresh rate in units of 0.01 Hz UINT16 RefreshRate; // Refresh rate in units of 0.01 Hz
UINT8 Reserved[40]; // Pad UINT8 Reserved[40]; // Pad
} VESA_BIOS_EXTENSIONS_CRTC_INFORMATION_BLOCK; } VESA_BIOS_EXTENSIONS_CRTC_INFORMATION_BLOCK;
#define VESA_BIOS_EXTENSIONS_CRTC_FLAGS_DOUBLE_SCAN 0x01 // 0: Graphics mode is not souble scanned #define VESA_BIOS_EXTENSIONS_CRTC_FLAGS_DOUBLE_SCAN 0x01 // 0: Graphics mode is not souble scanned
// 1: Graphics mode is double scanned // 1: Graphics mode is double scanned
// //
#define VESA_BIOS_EXTENSIONS_CRTC_FLAGSINTERLACED 0x02 // 0: Graphics mode is not interlaced #define VESA_BIOS_EXTENSIONS_CRTC_FLAGSINTERLACED 0x02 // 0: Graphics mode is not interlaced
// 1: Graphics mode is interlaced // 1: Graphics mode is interlaced
// //
#define VESA_BIOS_EXTENSIONS_CRTC_HORIZONTAL_SYNC_NEGATIVE 0x04 // 0: Horizontal sync polarity is positive(+) #define VESA_BIOS_EXTENSIONS_CRTC_HORIZONTAL_SYNC_NEGATIVE 0x04 // 0: Horizontal sync polarity is positive(+)
// 0: Horizontal sync polarity is negative(-) // 0: Horizontal sync polarity is negative(-)
// //
#define VESA_BIOS_EXTENSIONS_CRTC_VERITICAL_SYNC_NEGATIVE 0x08 // 0: Verical sync polarity is positive(+) #define VESA_BIOS_EXTENSIONS_CRTC_VERITICAL_SYNC_NEGATIVE 0x08 // 0: Verical sync polarity is positive(+)
// 0: Verical sync polarity is negative(-) // 0: Verical sync polarity is negative(-)
// //
// Turn off byte packing of data structures // Turn off byte packing of data structures

View File

@ -29,4 +29,3 @@ CsmSupportLibConstructor (
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@ -46,4 +46,3 @@ LegacyBiosPlatformInstall (
); );
#endif #endif

View File

@ -12,25 +12,24 @@
// //
// Handle for the Legacy Interrupt Protocol instance produced by this driver // Handle for the Legacy Interrupt Protocol instance produced by this driver
// //
STATIC EFI_HANDLE mLegacyInterruptHandle = NULL; STATIC EFI_HANDLE mLegacyInterruptHandle = NULL;
// //
// Legacy Interrupt Device number (0x01 on piix4, 0x1f on q35/mch) // Legacy Interrupt Device number (0x01 on piix4, 0x1f on q35/mch)
// //
STATIC UINT8 mLegacyInterruptDevice; STATIC UINT8 mLegacyInterruptDevice;
// //
// The Legacy Interrupt Protocol instance produced by this driver // The Legacy Interrupt Protocol instance produced by this driver
// //
STATIC EFI_LEGACY_INTERRUPT_PROTOCOL mLegacyInterrupt = { STATIC EFI_LEGACY_INTERRUPT_PROTOCOL mLegacyInterrupt = {
GetNumberPirqs, GetNumberPirqs,
GetLocation, GetLocation,
ReadPirq, ReadPirq,
WritePirq WritePirq
}; };
STATIC UINT8 PirqReg[MAX_PIRQ_NUMBER] = { PIRQA, PIRQB, PIRQC, PIRQD, PIRQE, PIRQF, PIRQG, PIRQH }; STATIC UINT8 PirqReg[MAX_PIRQ_NUMBER] = { PIRQA, PIRQB, PIRQC, PIRQD, PIRQE, PIRQF, PIRQG, PIRQH };
/** /**
Return the number of PIRQs supported by this chipset. Return the number of PIRQs supported by this chipset.
@ -53,7 +52,6 @@ GetNumberPirqs (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Return PCI location of this device. Return PCI location of this device.
$PIR table requires this info. $PIR table requires this info.
@ -82,7 +80,6 @@ GetLocation (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Builds the PCI configuration address for the register specified by PirqNumber Builds the PCI configuration address for the register specified by PirqNumber
@ -95,12 +92,12 @@ GetAddress (
UINT8 PirqNumber UINT8 PirqNumber
) )
{ {
return PCI_LIB_ADDRESS( return PCI_LIB_ADDRESS (
LEGACY_INT_BUS, LEGACY_INT_BUS,
mLegacyInterruptDevice, mLegacyInterruptDevice,
LEGACY_INT_FUNC, LEGACY_INT_FUNC,
PirqReg[PirqNumber] PirqReg[PirqNumber]
); );
} }
/** /**
@ -127,12 +124,11 @@ ReadPirq (
} }
*PirqData = PciRead8 (GetAddress (PirqNumber)); *PirqData = PciRead8 (GetAddress (PirqNumber));
*PirqData = (UINT8) (*PirqData & 0x7f); *PirqData = (UINT8)(*PirqData & 0x7f);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Write the given PIRQ register Write the given PIRQ register
@ -160,7 +156,6 @@ WritePirq (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Initialize Legacy Interrupt support Initialize Legacy Interrupt support
@ -178,7 +173,7 @@ LegacyInterruptInstall (
// //
// Make sure the Legacy Interrupt Protocol is not already installed in the system // Make sure the Legacy Interrupt Protocol is not already installed in the system
// //
ASSERT_PROTOCOL_ALREADY_INSTALLED(NULL, &gEfiLegacyInterruptProtocolGuid); ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiLegacyInterruptProtocolGuid);
// //
// Query Host Bridge DID to determine platform type, then set device number // Query Host Bridge DID to determine platform type, then set device number
@ -192,8 +187,12 @@ LegacyInterruptInstall (
mLegacyInterruptDevice = LEGACY_INT_DEV_Q35; mLegacyInterruptDevice = LEGACY_INT_DEV_Q35;
break; break;
default: default:
DEBUG ((DEBUG_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n", DEBUG ((
__FUNCTION__, HostBridgeDevId)); DEBUG_ERROR,
"%a: Unknown Host Bridge Device ID: 0x%04x\n",
__FUNCTION__,
HostBridgeDevId
));
ASSERT (FALSE); ASSERT (FALSE);
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
@ -207,8 +206,7 @@ LegacyInterruptInstall (
&mLegacyInterrupt, &mLegacyInterrupt,
NULL NULL
); );
ASSERT_EFI_ERROR(Status); ASSERT_EFI_ERROR (Status);
return Status; return Status;
} }

View File

@ -20,23 +20,22 @@
#include <Library/UefiBootServicesTableLib.h> #include <Library/UefiBootServicesTableLib.h>
#include <OvmfPlatforms.h> #include <OvmfPlatforms.h>
#define LEGACY_INT_BUS 0
#define LEGACY_INT_BUS 0
#define LEGACY_INT_DEV_PIIX4 0x01 #define LEGACY_INT_DEV_PIIX4 0x01
#define LEGACY_INT_DEV_Q35 0x1f #define LEGACY_INT_DEV_Q35 0x1f
#define LEGACY_INT_FUNC 0 #define LEGACY_INT_FUNC 0
#define PIRQN 0x00 // PIRQ Null #define PIRQN 0x00 // PIRQ Null
#define PIRQA 0x60 #define PIRQA 0x60
#define PIRQB 0x61 #define PIRQB 0x61
#define PIRQC 0x62 #define PIRQC 0x62
#define PIRQD 0x63 #define PIRQD 0x63
#define PIRQE 0x68 #define PIRQE 0x68
#define PIRQF 0x69 #define PIRQF 0x69
#define PIRQG 0x6A #define PIRQG 0x6A
#define PIRQH 0x6B #define PIRQH 0x6B
#define MAX_PIRQ_NUMBER 8 #define MAX_PIRQ_NUMBER 8
/** /**
Return the number of PIRQs supported by this chipset. Return the number of PIRQs supported by this chipset.
@ -114,4 +113,3 @@ WritePirq (
); );
#endif #endif

View File

@ -9,15 +9,15 @@
#include "LegacyPlatform.h" #include "LegacyPlatform.h"
EFI_SETUP_BBS_MAP mSetupBbsMap[] = { EFI_SETUP_BBS_MAP mSetupBbsMap[] = {
{ 1, 2, 1, 1 }, // ATA HardDrive { 1, 2, 1, 1 }, // ATA HardDrive
{ 2, 3, 1, 1 }, // ATAPI CDROM { 2, 3, 1, 1 }, // ATAPI CDROM
{ 3, 0x80, 2, 0 }, // PXE { 3, 0x80, 2, 0 }, // PXE
{ 4, 1, 0, 6 }, // USB Floppy { 4, 1, 0, 6 }, // USB Floppy
{ 4, 2, 0, 6 }, // USB HDD { 4, 2, 0, 6 }, // USB HDD
{ 4, 3, 0, 6 }, // USB CD { 4, 3, 0, 6 }, // USB CD
{ 4, 1, 0, 0 }, // USB ZIP Bugbug since Class/SubClass code is uninitialized { 4, 1, 0, 0 }, // USB ZIP Bugbug since Class/SubClass code is uninitialized
{ 4, 2, 0, 0 } // USB ZIP Bugbug since Class/SubClass code is uninitialized { 4, 2, 0, 0 } // USB ZIP Bugbug since Class/SubClass code is uninitialized
}; };
// //
@ -29,23 +29,23 @@ EFI_SETUP_BBS_MAP mSetupBbsMap[] = {
#define NULL_ROM_FILE_GUID \ #define NULL_ROM_FILE_GUID \
{ 0x00000000, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } { 0x00000000, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }
SYSTEM_ROM_TABLE mSystemRomTable[] = { SYSTEM_ROM_TABLE mSystemRomTable[] = {
{ SYSTEM_ROM_FILE_GUID, 1 }, { SYSTEM_ROM_FILE_GUID, 1 },
{ NULL_ROM_FILE_GUID, 0 } { NULL_ROM_FILE_GUID, 0 }
}; };
EFI_HANDLE mVgaHandles[0x20]; EFI_HANDLE mVgaHandles[0x20];
EFI_HANDLE mDiskHandles[0x20]; EFI_HANDLE mDiskHandles[0x20];
EFI_HANDLE mIsaHandles[0x20]; EFI_HANDLE mIsaHandles[0x20];
EFI_LEGACY_IRQ_PRIORITY_TABLE_ENTRY IrqPriorityTable[MAX_IRQ_PRIORITY_ENTRIES] = { EFI_LEGACY_IRQ_PRIORITY_TABLE_ENTRY IrqPriorityTable[MAX_IRQ_PRIORITY_ENTRIES] = {
{0x0B,0}, { 0x0B, 0 },
{0x09,0}, { 0x09, 0 },
{0x0A,0}, { 0x0A, 0 },
{0x05,0}, { 0x05, 0 },
{0x07,0}, { 0x07, 0 },
{0x00,0}, { 0x00, 0 },
{0x00,0} { 0x00, 0 }
}; };
// //
@ -54,18 +54,18 @@ EFI_LEGACY_IRQ_PRIORITY_TABLE_ENTRY IrqPriorityTable[MAX_IRQ_PRIORITY_ENTRIES] =
// to check to get bus number. The Slot number - 1 is an index into a decode // to check to get bus number. The Slot number - 1 is an index into a decode
// table to get the bridge information. // table to get the bridge information.
// //
EFI_LEGACY_PIRQ_TABLE PirqTableHead = { EFI_LEGACY_PIRQ_TABLE PirqTableHead = {
{ {
EFI_LEGACY_PIRQ_TABLE_SIGNATURE, // UINT32 Signature EFI_LEGACY_PIRQ_TABLE_SIGNATURE, // UINT32 Signature
0x00, // UINT8 MinorVersion 0x00, // UINT8 MinorVersion
0x01, // UINT8 MajorVersion 0x01, // UINT8 MajorVersion
0x0000, // UINT16 TableSize 0x0000, // UINT16 TableSize
0x00, // UINT8 Bus 0x00, // UINT8 Bus
0x08, // UINT8 DevFun 0x08, // UINT8 DevFun
0x0000, // UINT16 PciOnlyIrq 0x0000, // UINT16 PciOnlyIrq
0x8086, // UINT16 CompatibleVid 0x8086, // UINT16 CompatibleVid
0x122e, // UINT16 CompatibleDid 0x122e, // UINT16 CompatibleDid
0x00000000, // UINT32 Miniport 0x00000000, // UINT32 Miniport
{ // UINT8 Reserved[11] { // UINT8 Reserved[11]
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00 0x00, 0x00, 0x00
@ -76,17 +76,29 @@ EFI_LEGACY_PIRQ_TABLE PirqTableHead = {
// -- Pin 1 -- -- Pin 2 -- -- Pin 3 -- -- Pin 4 -- // -- Pin 1 -- -- Pin 2 -- -- Pin 3 -- -- Pin 4 --
// Bus Dev Reg Map Reg Map Reg Map Reg Map // Bus Dev Reg Map Reg Map Reg Map Reg Map
// //
{0x00,0x08,{{0x60,0xDEB8},{0x61,0xDEB8},{0x62,0xDEB8},{0x63,0xDEB8}},0x00,0x00}, { 0x00, 0x08, {
{0x00,0x10,{{0x61,0xDEB8},{0x62,0xDEB8},{0x63,0xDEB8},{0x60,0xDEB8}},0x01,0x00}, { 0x60, 0xDEB8 }, { 0x61, 0xDEB8 }, { 0x62, 0xDEB8 }, { 0x63, 0xDEB8 }
{0x00,0x18,{{0x62,0xDEB8},{0x63,0xDEB8},{0x60,0xDEB8},{0x61,0xDEB8}},0x02,0x00}, }, 0x00, 0x00 },
{0x00,0x20,{{0x63,0xDEB8},{0x60,0xDEB8},{0x61,0xDEB8},{0x62,0xDEB8}},0x03,0x00}, { 0x00, 0x10, {
{0x00,0x28,{{0x60,0xDEB8},{0x61,0xDEB8},{0x62,0xDEB8},{0x63,0xDEB8}},0x04,0x00}, { 0x61, 0xDEB8 }, { 0x62, 0xDEB8 }, { 0x63, 0xDEB8 }, { 0x60, 0xDEB8 }
{0x00,0x30,{{0x61,0xDEB8},{0x62,0xDEB8},{0x63,0xDEB8},{0x60,0xDEB8}},0x05,0x00}, }, 0x01, 0x00 },
{ 0x00, 0x18, {
{ 0x62, 0xDEB8 }, { 0x63, 0xDEB8 }, { 0x60, 0xDEB8 }, { 0x61, 0xDEB8 }
}, 0x02, 0x00 },
{ 0x00, 0x20, {
{ 0x63, 0xDEB8 }, { 0x60, 0xDEB8 }, { 0x61, 0xDEB8 }, { 0x62, 0xDEB8 }
}, 0x03, 0x00 },
{ 0x00, 0x28, {
{ 0x60, 0xDEB8 }, { 0x61, 0xDEB8 }, { 0x62, 0xDEB8 }, { 0x63, 0xDEB8 }
}, 0x04, 0x00 },
{ 0x00, 0x30, {
{ 0x61, 0xDEB8 }, { 0x62, 0xDEB8 }, { 0x63, 0xDEB8 }, { 0x60, 0xDEB8 }
}, 0x05, 0x00 },
} }
}; };
LEGACY_BIOS_PLATFORM_INSTANCE mPrivateData; LEGACY_BIOS_PLATFORM_INSTANCE mPrivateData;
EFI_HANDLE mImageHandle = NULL; EFI_HANDLE mImageHandle = NULL;
/** /**
Return the handles and assorted information for the specified PCI Class code Return the handles and assorted information for the specified PCI Class code
@ -102,32 +114,32 @@ EFI_HANDLE mImageHandle = NULL;
**/ **/
EFI_STATUS EFI_STATUS
FindAllDeviceTypes ( FindAllDeviceTypes (
IN PCI_CLASS_RECORD *PciClasses, IN PCI_CLASS_RECORD *PciClasses,
IN OUT DEVICE_STRUCTURE *DeviceTable, IN OUT DEVICE_STRUCTURE *DeviceTable,
IN OUT UINT16 *DeviceIndex, IN OUT UINT16 *DeviceIndex,
IN BOOLEAN DeviceFlags IN BOOLEAN DeviceFlags
) )
{ {
UINTN HandleCount; UINTN HandleCount;
EFI_HANDLE *HandleBuffer; EFI_HANDLE *HandleBuffer;
UINTN Index; UINTN Index;
UINTN StartIndex; UINTN StartIndex;
PCI_TYPE00 PciConfigHeader; PCI_TYPE00 PciConfigHeader;
EFI_PCI_IO_PROTOCOL *PciIo; EFI_PCI_IO_PROTOCOL *PciIo;
EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;
UINTN Flags; UINTN Flags;
EFI_STATUS Status; EFI_STATUS Status;
UINTN Index2; UINTN Index2;
// //
// Get legacy BIOS protocol as it is required to deal with Option ROMs. // Get legacy BIOS protocol as it is required to deal with Option ROMs.
// //
StartIndex = *DeviceIndex; StartIndex = *DeviceIndex;
Status = gBS->LocateProtocol ( Status = gBS->LocateProtocol (
&gEfiLegacyBiosProtocolGuid, &gEfiLegacyBiosProtocolGuid,
NULL, NULL,
(VOID**)&LegacyBios (VOID **)&LegacyBios
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
// //
@ -144,7 +156,7 @@ FindAllDeviceTypes (
gBS->HandleProtocol ( gBS->HandleProtocol (
HandleBuffer[Index], HandleBuffer[Index],
&gEfiPciIoProtocolGuid, &gEfiPciIoProtocolGuid,
(VOID**)&PciIo (VOID **)&PciIo
); );
PciIo->Pci.Read ( PciIo->Pci.Read (
PciIo, PciIo,
@ -154,8 +166,9 @@ FindAllDeviceTypes (
&PciConfigHeader &PciConfigHeader
); );
for (Index2 = 0; PciClasses[Index2].Class != 0xff; Index2++) { for (Index2 = 0; PciClasses[Index2].Class != 0xff; Index2++) {
if ((PciConfigHeader.Hdr.ClassCode[2] == PciClasses[Index2].Class) && if ((PciConfigHeader.Hdr.ClassCode[2] == PciClasses[Index2].Class) &&
(PciConfigHeader.Hdr.ClassCode[1] == PciClasses[Index2].SubClass)) { (PciConfigHeader.Hdr.ClassCode[1] == PciClasses[Index2].SubClass))
{
LegacyBios->CheckPciRom ( LegacyBios->CheckPciRom (
LegacyBios, LegacyBios,
HandleBuffer[Index], HandleBuffer[Index],
@ -173,13 +186,14 @@ FindAllDeviceTypes (
if ( if (
((DeviceFlags != 0) && (Flags == NO_ROM)) || ((DeviceFlags != 0) && (Flags == NO_ROM)) ||
((Flags & (ROM_FOUND | VALID_LEGACY_ROM)) == (ROM_FOUND | VALID_LEGACY_ROM)) ((Flags & (ROM_FOUND | VALID_LEGACY_ROM)) == (ROM_FOUND | VALID_LEGACY_ROM))
) { )
{
DeviceTable->Handle = HandleBuffer[Index]; DeviceTable->Handle = HandleBuffer[Index];
DeviceTable->Vid = PciConfigHeader.Hdr.VendorId; DeviceTable->Vid = PciConfigHeader.Hdr.VendorId;
DeviceTable->Did = PciConfigHeader.Hdr.DeviceId; DeviceTable->Did = PciConfigHeader.Hdr.DeviceId;
DeviceTable->SvId = PciConfigHeader.Device.SubsystemVendorID; DeviceTable->SvId = PciConfigHeader.Device.SubsystemVendorID;
DeviceTable->SysId = PciConfigHeader.Device.SubsystemID; DeviceTable->SysId = PciConfigHeader.Device.SubsystemID;
++ *DeviceIndex; ++*DeviceIndex;
DeviceTable++; DeviceTable++;
} }
} }
@ -211,8 +225,8 @@ FindAllDeviceTypes (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
SmmInit ( SmmInit (
IN EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *This, IN EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *This,
IN VOID *EfiToLegacy16BootTable IN VOID *EfiToLegacy16BootTable
) )
{ {
return EFI_SUCCESS; return EFI_SUCCESS;
@ -226,23 +240,23 @@ SmmInit (
**/ **/
VOID VOID
GetSelectedVgaDeviceInfo ( GetSelectedVgaDeviceInfo (
OUT EFI_HANDLE *VgaHandle OUT EFI_HANDLE *VgaHandle
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINTN HandleCount; UINTN HandleCount;
EFI_HANDLE *HandleBuffer; EFI_HANDLE *HandleBuffer;
UINTN Index; UINTN Index;
EFI_PCI_IO_PROTOCOL *PciIo; EFI_PCI_IO_PROTOCOL *PciIo;
PCI_TYPE00 Pci; PCI_TYPE00 Pci;
UINT8 MinBus; UINT8 MinBus;
UINT8 MaxBus; UINT8 MaxBus;
UINTN Segment; UINTN Segment;
UINTN Bus; UINTN Bus;
UINTN Device; UINTN Device;
UINTN Function; UINTN Function;
UINTN SelectedAddress; UINTN SelectedAddress;
UINTN CurrentAddress; UINTN CurrentAddress;
// //
// Initialize return to 'not found' state // Initialize return to 'not found' state
@ -253,9 +267,9 @@ GetSelectedVgaDeviceInfo (
// Initialize variable states. This is important for selecting the VGA // Initialize variable states. This is important for selecting the VGA
// device if multiple devices exist behind a single bridge. // device if multiple devices exist behind a single bridge.
// //
HandleCount = 0; HandleCount = 0;
HandleBuffer = NULL; HandleBuffer = NULL;
SelectedAddress = PCI_LIB_ADDRESS(0xff, 0x1f, 0x7, 0); SelectedAddress = PCI_LIB_ADDRESS (0xff, 0x1f, 0x7, 0);
// //
// The bus range to search for a VGA device in. // The bus range to search for a VGA device in.
@ -265,27 +279,27 @@ GetSelectedVgaDeviceInfo (
// //
// Start to check all the pci io to find all possible VGA device // Start to check all the pci io to find all possible VGA device
// //
HandleCount = 0; HandleCount = 0;
HandleBuffer = NULL; HandleBuffer = NULL;
Status = gBS->LocateHandleBuffer ( Status = gBS->LocateHandleBuffer (
ByProtocol, ByProtocol,
&gEfiPciIoProtocolGuid, &gEfiPciIoProtocolGuid,
NULL, NULL,
&HandleCount, &HandleCount,
&HandleBuffer &HandleBuffer
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return; return;
} }
for (Index = 0; Index < HandleCount; Index++) { for (Index = 0; Index < HandleCount; Index++) {
Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiPciIoProtocolGuid, (VOID**)&PciIo); Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiPciIoProtocolGuid, (VOID **)&PciIo);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
// //
// Determine if this is in the correct bus range. // Determine if this is in the correct bus range.
// //
Status = PciIo->GetLocation (PciIo, &Segment, &Bus, &Device, &Function); Status = PciIo->GetLocation (PciIo, &Segment, &Bus, &Device, &Function);
if (EFI_ERROR(Status) || (Bus < MinBus || Bus > MaxBus)) { if (EFI_ERROR (Status) || ((Bus < MinBus) || (Bus > MaxBus))) {
continue; continue;
} }
@ -293,12 +307,12 @@ GetSelectedVgaDeviceInfo (
// Read device information. // Read device information.
// //
Status = PciIo->Pci.Read ( Status = PciIo->Pci.Read (
PciIo, PciIo,
EfiPciIoWidthUint32, EfiPciIoWidthUint32,
0, 0,
sizeof (Pci) / sizeof (UINT32), sizeof (Pci) / sizeof (UINT32),
&Pci &Pci
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
continue; continue;
} }
@ -309,7 +323,9 @@ GetSelectedVgaDeviceInfo (
if (!IS_PCI_VGA (&Pci)) { if (!IS_PCI_VGA (&Pci)) {
continue; continue;
} }
DEBUG ((DEBUG_INFO,
DEBUG ((
DEBUG_INFO,
"PCI VGA: 0x%04x:0x%04x\n", "PCI VGA: 0x%04x:0x%04x\n",
Pci.Hdr.VendorId, Pci.Hdr.VendorId,
Pci.Hdr.DeviceId Pci.Hdr.DeviceId
@ -319,10 +335,10 @@ GetSelectedVgaDeviceInfo (
// Currently we use the lowest numbered bus/device/function if multiple // Currently we use the lowest numbered bus/device/function if multiple
// devices are found in the target bus range. // devices are found in the target bus range.
// //
CurrentAddress = PCI_LIB_ADDRESS(Bus, Device, Function, 0); CurrentAddress = PCI_LIB_ADDRESS (Bus, Device, Function, 0);
if (CurrentAddress < SelectedAddress) { if (CurrentAddress < SelectedAddress) {
SelectedAddress = CurrentAddress; SelectedAddress = CurrentAddress;
*VgaHandle = HandleBuffer[Index]; *VgaHandle = HandleBuffer[Index];
} }
} }
} }
@ -330,7 +346,6 @@ GetSelectedVgaDeviceInfo (
FreePool (HandleBuffer); FreePool (HandleBuffer);
} }
/** /**
Returns a buffer of handles for the requested subfunction. Returns a buffer of handles for the requested subfunction.
@ -349,42 +364,42 @@ GetSelectedVgaDeviceInfo (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
GetPlatformHandle ( GetPlatformHandle (
IN EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *This, IN EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *This,
IN EFI_GET_PLATFORM_HANDLE_MODE Mode, IN EFI_GET_PLATFORM_HANDLE_MODE Mode,
IN UINT16 Type, IN UINT16 Type,
OUT EFI_HANDLE **HandleBuffer, OUT EFI_HANDLE **HandleBuffer,
OUT UINTN *HandleCount, OUT UINTN *HandleCount,
OUT VOID **AdditionalData OPTIONAL OUT VOID **AdditionalData OPTIONAL
) )
{ {
DEVICE_STRUCTURE LocalDevice[0x40]; DEVICE_STRUCTURE LocalDevice[0x40];
UINT32 LocalIndex; UINT32 LocalIndex;
UINT32 Index; UINT32 Index;
DEVICE_STRUCTURE TempDevice; DEVICE_STRUCTURE TempDevice;
EFI_STATUS Status; EFI_STATUS Status;
EFI_PCI_IO_PROTOCOL *PciIo; EFI_PCI_IO_PROTOCOL *PciIo;
UINTN Segment; UINTN Segment;
UINTN Bus; UINTN Bus;
UINTN Device; UINTN Device;
UINTN Function; UINTN Function;
HDD_INFO *HddInfo; HDD_INFO *HddInfo;
PCI_TYPE00 PciConfigHeader; PCI_TYPE00 PciConfigHeader;
UINT32 HddIndex; UINT32 HddIndex;
EFI_HANDLE IdeHandle; EFI_HANDLE IdeHandle;
EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;
PCI_CLASS_RECORD ClassLists[10]; PCI_CLASS_RECORD ClassLists[10];
UINTN PriorityIndex; UINTN PriorityIndex;
static BOOLEAN bConnected = FALSE; static BOOLEAN bConnected = FALSE;
LocalIndex = 0x00; LocalIndex = 0x00;
HddInfo = NULL; HddInfo = NULL;
HddIndex = 0; HddIndex = 0;
Status = gBS->LocateProtocol ( Status = gBS->LocateProtocol (
&gEfiLegacyBiosProtocolGuid, &gEfiLegacyBiosProtocolGuid,
NULL, NULL,
(VOID**)&LegacyBios (VOID **)&LegacyBios
); );
// //
@ -400,9 +415,9 @@ GetPlatformHandle (
*HandleCount = (mVgaHandles[0] != NULL) ? 1 : 0; *HandleCount = (mVgaHandles[0] != NULL) ? 1 : 0;
return EFI_SUCCESS; return EFI_SUCCESS;
case EfiGetPlatformIdeHandle: case EfiGetPlatformIdeHandle:
IdeHandle = NULL; IdeHandle = NULL;
if (AdditionalData != NULL) { if (AdditionalData != NULL) {
HddInfo = (HDD_INFO *) *AdditionalData; HddInfo = (HDD_INFO *)*AdditionalData;
} }
// //
@ -417,7 +432,7 @@ GetPlatformHandle (
ClassLists[3].Class = PCI_CLASS_MASS_STORAGE; ClassLists[3].Class = PCI_CLASS_MASS_STORAGE;
ClassLists[3].SubClass = PCI_CLASS_MASS_STORAGE_SATADPA; ClassLists[3].SubClass = PCI_CLASS_MASS_STORAGE_SATADPA;
ClassLists[4].Class = 0xff; ClassLists[4].Class = 0xff;
FindAllDeviceTypes (ClassLists, LocalDevice, (UINT16 *) &LocalIndex, TRUE); FindAllDeviceTypes (ClassLists, LocalDevice, (UINT16 *)&LocalIndex, TRUE);
if (LocalIndex == 0) { if (LocalIndex == 0) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
@ -449,10 +464,10 @@ GetPlatformHandle (
// //
PriorityIndex = 0; PriorityIndex = 0;
for (Index = 0; Index < LocalIndex; Index++) { for (Index = 0; Index < LocalIndex; Index++) {
if (LocalDevice[Index].Handle == IdeHandle && PriorityIndex == 0) { if ((LocalDevice[Index].Handle == IdeHandle) && (PriorityIndex == 0)) {
TempDevice = LocalDevice[PriorityIndex]; TempDevice = LocalDevice[PriorityIndex];
LocalDevice[PriorityIndex] = LocalDevice[Index]; LocalDevice[PriorityIndex] = LocalDevice[Index];
LocalDevice[Index] = TempDevice; LocalDevice[Index] = TempDevice;
PriorityIndex++; PriorityIndex++;
break; break;
} }
@ -464,6 +479,7 @@ GetPlatformHandle (
for (Index = 0; Index < LocalIndex; Index++) { for (Index = 0; Index < LocalIndex; Index++) {
mDiskHandles[Index] = LocalDevice[Index].Handle; mDiskHandles[Index] = LocalDevice[Index].Handle;
} }
*HandleBuffer = &mDiskHandles[0]; *HandleBuffer = &mDiskHandles[0];
*HandleCount = LocalIndex; *HandleCount = LocalIndex;
@ -477,11 +493,12 @@ GetPlatformHandle (
// //
for (Index = 0; (Index < LocalIndex) && (AdditionalData != NULL); Index++) { for (Index = 0; (Index < LocalIndex) && (AdditionalData != NULL); Index++) {
if ((LocalDevice[Index].Handle != NULL) && if ((LocalDevice[Index].Handle != NULL) &&
(LocalDevice[Index].Handle == IdeHandle)) { (LocalDevice[Index].Handle == IdeHandle))
{
Status = gBS->HandleProtocol ( Status = gBS->HandleProtocol (
LocalDevice[Index].Handle, LocalDevice[Index].Handle,
&gEfiPciIoProtocolGuid, &gEfiPciIoProtocolGuid,
(VOID **) &PciIo (VOID **)&PciIo
); );
PciIo->Pci.Read ( PciIo->Pci.Read (
PciIo, PciIo,
@ -503,14 +520,14 @@ GetPlatformHandle (
// Be sure to only fill out correct information based on platform // Be sure to only fill out correct information based on platform
// configuration. // configuration.
// //
HddInfo[HddIndex].Status |= HDD_PRIMARY; HddInfo[HddIndex].Status |= HDD_PRIMARY;
HddInfo[HddIndex].Bus = (UINT32)Bus; HddInfo[HddIndex].Bus = (UINT32)Bus;
HddInfo[HddIndex].Device = (UINT32)Device; HddInfo[HddIndex].Device = (UINT32)Device;
HddInfo[HddIndex].Function = (UINT32)Function; HddInfo[HddIndex].Function = (UINT32)Function;
HddInfo[HddIndex + 1].Status |= HDD_SECONDARY; HddInfo[HddIndex + 1].Status |= HDD_SECONDARY;
HddInfo[HddIndex + 1].Bus = (UINT32)Bus; HddInfo[HddIndex + 1].Bus = (UINT32)Bus;
HddInfo[HddIndex + 1].Device = (UINT32)Device; HddInfo[HddIndex + 1].Device = (UINT32)Device;
HddInfo[HddIndex + 1].Function = (UINT32)Function; HddInfo[HddIndex + 1].Function = (UINT32)Function;
// //
// Primary controller data // Primary controller data
@ -524,11 +541,12 @@ GetPlatformHandle (
(UINT16)(PciConfigHeader.Device.Bar[4] & 0xfffc); (UINT16)(PciConfigHeader.Device.Bar[4] & 0xfffc);
HddInfo[HddIndex].HddIrq = PciConfigHeader.Device.InterruptLine; HddInfo[HddIndex].HddIrq = PciConfigHeader.Device.InterruptLine;
} else { } else {
HddInfo[HddIndex].HddIrq = 14; HddInfo[HddIndex].HddIrq = 14;
HddInfo[HddIndex].CommandBaseAddress = 0x1f0; HddInfo[HddIndex].CommandBaseAddress = 0x1f0;
HddInfo[HddIndex].ControlBaseAddress = 0x3f6; HddInfo[HddIndex].ControlBaseAddress = 0x3f6;
HddInfo[HddIndex].BusMasterAddress = 0; HddInfo[HddIndex].BusMasterAddress = 0;
} }
HddIndex++; HddIndex++;
// //
@ -543,27 +561,29 @@ GetPlatformHandle (
(UINT16)(HddInfo[HddIndex].BusMasterAddress + 8); (UINT16)(HddInfo[HddIndex].BusMasterAddress + 8);
HddInfo[HddIndex].HddIrq = PciConfigHeader.Device.InterruptLine; HddInfo[HddIndex].HddIrq = PciConfigHeader.Device.InterruptLine;
} else { } else {
HddInfo[HddIndex].HddIrq = 15; HddInfo[HddIndex].HddIrq = 15;
HddInfo[HddIndex].CommandBaseAddress = 0x170; HddInfo[HddIndex].CommandBaseAddress = 0x170;
HddInfo[HddIndex].ControlBaseAddress = 0x376; HddInfo[HddIndex].ControlBaseAddress = 0x376;
HddInfo[HddIndex].BusMasterAddress = 0; HddInfo[HddIndex].BusMasterAddress = 0;
} }
HddIndex++; HddIndex++;
} }
} }
} }
return EFI_SUCCESS; return EFI_SUCCESS;
case EfiGetPlatformIsaBusHandle: case EfiGetPlatformIsaBusHandle:
ClassLists[0].Class = (UINT8) PCI_CLASS_BRIDGE; ClassLists[0].Class = (UINT8)PCI_CLASS_BRIDGE;
ClassLists[0].SubClass = (UINT8) PCI_CLASS_BRIDGE_ISA_PDECODE; ClassLists[0].SubClass = (UINT8)PCI_CLASS_BRIDGE_ISA_PDECODE;
ClassLists[1].Class = (UINT8) PCI_CLASS_BRIDGE; ClassLists[1].Class = (UINT8)PCI_CLASS_BRIDGE;
ClassLists[1].SubClass = (UINT8) PCI_CLASS_BRIDGE_ISA; ClassLists[1].SubClass = (UINT8)PCI_CLASS_BRIDGE_ISA;
ClassLists[2].Class = 0xff; ClassLists[2].Class = 0xff;
// //
// Locate all found block io devices // Locate all found block io devices
// //
FindAllDeviceTypes (ClassLists, LocalDevice, (UINT16 *) (&LocalIndex), TRUE); FindAllDeviceTypes (ClassLists, LocalDevice, (UINT16 *)(&LocalIndex), TRUE);
if (LocalIndex == 0) { if (LocalIndex == 0) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
@ -573,9 +593,9 @@ GetPlatformHandle (
// //
for (Index = 0; Index < LocalIndex; Index++) { for (Index = 0; Index < LocalIndex; Index++) {
if (LocalDevice[Index].Vid == V_INTEL_VENDOR_ID) { if (LocalDevice[Index].Vid == V_INTEL_VENDOR_ID) {
TempDevice = LocalDevice[0]; TempDevice = LocalDevice[0];
LocalDevice[0] = LocalDevice[Index]; LocalDevice[0] = LocalDevice[Index];
LocalDevice[Index] = TempDevice; LocalDevice[Index] = TempDevice;
} }
} }
@ -585,13 +605,14 @@ GetPlatformHandle (
for (Index = 0; Index < LocalIndex; Index++) { for (Index = 0; Index < LocalIndex; Index++) {
mIsaHandles[Index] = LocalDevice[Index].Handle; mIsaHandles[Index] = LocalDevice[Index].Handle;
} }
*HandleBuffer = &mIsaHandles[0]; *HandleBuffer = &mIsaHandles[0];
*HandleCount = LocalIndex; *HandleCount = LocalIndex;
return EFI_SUCCESS; return EFI_SUCCESS;
case EfiGetPlatformUsbHandle: case EfiGetPlatformUsbHandle:
default: default:
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
}; }
} }
/** /**
@ -613,13 +634,13 @@ GetPlatformHandle (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
PlatformHooks ( PlatformHooks (
IN EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *This, IN EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *This,
IN EFI_GET_PLATFORM_HOOK_MODE Mode, IN EFI_GET_PLATFORM_HOOK_MODE Mode,
IN UINT16 Type, IN UINT16 Type,
OUT EFI_HANDLE DeviceHandle OPTIONAL, OUT EFI_HANDLE DeviceHandle OPTIONAL,
IN OUT UINTN *Shadowaddress OPTIONAL, IN OUT UINTN *Shadowaddress OPTIONAL,
IN EFI_COMPATIBILITY16_TABLE *Compatibility16Table OPTIONAL, IN EFI_COMPATIBILITY16_TABLE *Compatibility16Table OPTIONAL,
OUT VOID **AdditionalData OPTIONAL OUT VOID **AdditionalData OPTIONAL
) )
{ {
EFI_IA32_REGISTER_SET Regs; EFI_IA32_REGISTER_SET Regs;
@ -631,7 +652,7 @@ PlatformHooks (
Status = gBS->LocateProtocol ( Status = gBS->LocateProtocol (
&gEfiLegacyBiosProtocolGuid, &gEfiLegacyBiosProtocolGuid,
NULL, NULL,
(VOID**)&LegacyBios (VOID **)&LegacyBios
); );
// //
@ -639,14 +660,14 @@ PlatformHooks (
// //
Regs.H.AH = 0x00; Regs.H.AH = 0x00;
Regs.H.AL = 0x03; Regs.H.AL = 0x03;
Status = LegacyBios->Int86 (LegacyBios, 0x10, &Regs); Status = LegacyBios->Int86 (LegacyBios, 0x10, &Regs);
return Status; return Status;
case EfiPlatformHookShadowServiceRoms: case EfiPlatformHookShadowServiceRoms:
return EFI_SUCCESS; return EFI_SUCCESS;
case EfiPlatformHookAfterRomInit: case EfiPlatformHookAfterRomInit:
default: default:
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
}; }
} }
/** /**
@ -671,24 +692,24 @@ PlatformHooks (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
GetRoutingTable ( GetRoutingTable (
IN EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *This, IN EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *This,
OUT VOID **RoutingTable, OUT VOID **RoutingTable,
OUT UINTN *RoutingTableEntries, OUT UINTN *RoutingTableEntries,
OUT VOID **LocalPirqTable OPTIONAL, OUT VOID **LocalPirqTable OPTIONAL,
OUT UINTN *PirqTableSize OPTIONAL, OUT UINTN *PirqTableSize OPTIONAL,
OUT VOID **LocalIrqPriorityTable OPTIONAL, OUT VOID **LocalIrqPriorityTable OPTIONAL,
OUT UINTN *IrqPriorityTableEntries OPTIONAL OUT UINTN *IrqPriorityTableEntries OPTIONAL
) )
{ {
UINT16 PTableSize; UINT16 PTableSize;
UINT32 Index; UINT32 Index;
UINT8 Bus; UINT8 Bus;
UINT8 Device; UINT8 Device;
UINT8 Function; UINT8 Function;
UINT8 Checksum; UINT8 Checksum;
UINT8 *Ptr; UINT8 *Ptr;
EFI_STATUS Status; EFI_STATUS Status;
EFI_LEGACY_INTERRUPT_PROTOCOL *LegacyInterrupt; EFI_LEGACY_INTERRUPT_PROTOCOL *LegacyInterrupt;
Checksum = 0; Checksum = 0;
@ -699,7 +720,7 @@ GetRoutingTable (
Status = gBS->LocateProtocol ( Status = gBS->LocateProtocol (
&gEfiLegacyInterruptProtocolGuid, &gEfiLegacyInterruptProtocolGuid,
NULL, NULL,
(VOID**)&LegacyInterrupt (VOID **)&LegacyInterrupt
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
LegacyInterrupt->GetLocation ( LegacyInterrupt->GetLocation (
@ -714,34 +735,35 @@ GetRoutingTable (
// //
PirqTableHead.PirqTable.TableSize = PTableSize; PirqTableHead.PirqTable.TableSize = PTableSize;
PirqTableHead.PirqTable.Bus = Bus; PirqTableHead.PirqTable.Bus = Bus;
PirqTableHead.PirqTable.DevFun = (UINT8) ((Device << 3) + Function); PirqTableHead.PirqTable.DevFun = (UINT8)((Device << 3) + Function);
Ptr = (UINT8 *) (&PirqTableHead); Ptr = (UINT8 *)(&PirqTableHead);
// //
// Calculate checksum. // Calculate checksum.
// //
for (Index = 0; Index < PTableSize; Index++) { for (Index = 0; Index < PTableSize; Index++) {
Checksum = (UINT8) (Checksum + (UINT8) *Ptr); Checksum = (UINT8)(Checksum + (UINT8)*Ptr);
Ptr += 1; Ptr += 1;
} }
Checksum = (UINT8) (0x00 - Checksum);
PirqTableHead.PirqTable.Checksum = Checksum; Checksum = (UINT8)(0x00 - Checksum);
PirqTableHead.PirqTable.Checksum = Checksum;
// //
// Update return values. // Update return values.
// //
*LocalPirqTable = (VOID *) (&PirqTableHead); *LocalPirqTable = (VOID *)(&PirqTableHead);
*PirqTableSize = PTableSize; *PirqTableSize = PTableSize;
} }
// //
// More items to return. // More items to return.
// //
*RoutingTable = PirqTableHead.IrqRoutingEntry; *RoutingTable = PirqTableHead.IrqRoutingEntry;
*RoutingTableEntries = MAX_IRQ_ROUTING_ENTRIES; *RoutingTableEntries = MAX_IRQ_ROUTING_ENTRIES;
if (LocalIrqPriorityTable != NULL) { if (LocalIrqPriorityTable != NULL) {
*LocalIrqPriorityTable = IrqPriorityTable; *LocalIrqPriorityTable = IrqPriorityTable;
*IrqPriorityTableEntries = MAX_IRQ_PRIORITY_ENTRIES; *IrqPriorityTableEntries = MAX_IRQ_PRIORITY_ENTRIES;
} }
return EFI_SUCCESS; return EFI_SUCCESS;
@ -767,18 +789,18 @@ GetRoutingTable (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
GetPlatformInfo ( GetPlatformInfo (
IN EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *This, IN EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *This,
IN EFI_GET_PLATFORM_INFO_MODE Mode, IN EFI_GET_PLATFORM_INFO_MODE Mode,
OUT VOID **Table, OUT VOID **Table,
OUT UINTN *TableSize, OUT UINTN *TableSize,
OUT UINTN *Location, OUT UINTN *Location,
OUT UINTN *Alignment, OUT UINTN *Alignment,
IN UINT16 LegacySegment, IN UINT16 LegacySegment,
IN UINT16 LegacyOffset IN UINT16 LegacyOffset
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINTN Index; UINTN Index;
switch (Mode) { switch (Mode) {
case EfiGetPlatformBinarySystemRom: case EfiGetPlatformBinarySystemRom:
@ -791,11 +813,12 @@ GetPlatformInfo (
EFI_SECTION_RAW, EFI_SECTION_RAW,
0, 0,
Table, Table,
(UINTN *) TableSize (UINTN *)TableSize
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
continue; continue;
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -808,7 +831,7 @@ GetPlatformInfo (
case EfiGetPlatformPciExpressBase: case EfiGetPlatformPciExpressBase:
default: default:
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
}; }
} }
/** /**
@ -830,34 +853,35 @@ GetPlatformInfo (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
TranslatePirq ( TranslatePirq (
IN EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *This, IN EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *This,
IN UINTN PciBus, IN UINTN PciBus,
IN UINTN PciDevice, IN UINTN PciDevice,
IN UINTN PciFunction, IN UINTN PciFunction,
IN OUT UINT8 *Pirq, IN OUT UINT8 *Pirq,
OUT UINT8 *PciIrq OUT UINT8 *PciIrq
) )
{ {
EFI_LEGACY_INTERRUPT_PROTOCOL *LegacyInterrupt; EFI_LEGACY_INTERRUPT_PROTOCOL *LegacyInterrupt;
EFI_STATUS Status; EFI_STATUS Status;
UINTN Index; UINTN Index;
UINTN Index1; UINTN Index1;
UINT8 LocalPirq; UINT8 LocalPirq;
UINT8 PirqData; UINT8 PirqData;
UINT8 MatchData; UINT8 MatchData;
Status = gBS->LocateProtocol ( Status = gBS->LocateProtocol (
&gEfiLegacyInterruptProtocolGuid, &gEfiLegacyInterruptProtocolGuid,
NULL, NULL,
(VOID**)&LegacyInterrupt (VOID **)&LegacyInterrupt
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
LocalPirq = (UINT8) (*Pirq); LocalPirq = (UINT8)(*Pirq);
for (Index = 0; Index < MAX_IRQ_ROUTING_ENTRIES; Index++) { for (Index = 0; Index < MAX_IRQ_ROUTING_ENTRIES; Index++) {
if ((PirqTableHead.IrqRoutingEntry[Index].Bus == PciBus) && if ((PirqTableHead.IrqRoutingEntry[Index].Bus == PciBus) &&
(PirqTableHead.IrqRoutingEntry[Index].Device == PciDevice)) { (PirqTableHead.IrqRoutingEntry[Index].Device == PciDevice))
LocalPirq = (UINT8) (PirqTableHead.IrqRoutingEntry[Index].PirqEntry[LocalPirq].Pirq & 0x0f); {
LocalPirq = (UINT8)(PirqTableHead.IrqRoutingEntry[Index].PirqEntry[LocalPirq].Pirq & 0x0f);
if (LocalPirq > 4) { if (LocalPirq > 4) {
LocalPirq -= 4; LocalPirq -= 4;
} }
@ -867,8 +891,9 @@ TranslatePirq (
while (PirqData == 0) { while (PirqData == 0) {
for (Index1 = 0; Index1 < MAX_IRQ_PRIORITY_ENTRIES; Index1++) { for (Index1 = 0; Index1 < MAX_IRQ_PRIORITY_ENTRIES; Index1++) {
if ((IrqPriorityTable[Index1].Used == MatchData) && if ((IrqPriorityTable[Index1].Used == MatchData) &&
(IrqPriorityTable[Index1].Irq != 0)) { (IrqPriorityTable[Index1].Irq != 0))
PirqData = IrqPriorityTable[Index1].Irq; {
PirqData = IrqPriorityTable[Index1].Irq;
IrqPriorityTable[Index1].Used = 0xff; IrqPriorityTable[Index1].Used = 0xff;
LegacyInterrupt->WritePirq ( LegacyInterrupt->WritePirq (
LegacyInterrupt, LegacyInterrupt,
@ -880,11 +905,10 @@ TranslatePirq (
} }
if (PirqData == 0) { if (PirqData == 0) {
// //
// No unused interrupts, so start reusing them. // No unused interrupts, so start reusing them.
// //
MatchData = (UINT8) (~MatchData); MatchData = (UINT8)(~MatchData);
} }
} }
@ -896,7 +920,6 @@ TranslatePirq (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Attempt to legacy boot the BootOption. If the EFI contexted has been Attempt to legacy boot the BootOption. If the EFI contexted has been
compromised this function will not return. compromised this function will not return.
@ -914,26 +937,26 @@ TranslatePirq (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
PrepareToBoot ( PrepareToBoot (
IN EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *This, IN EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *This,
IN BBS_BBS_DEVICE_PATH *BbsDevicePath, IN BBS_BBS_DEVICE_PATH *BbsDevicePath,
IN VOID *BbsTable, IN VOID *BbsTable,
IN UINT32 LoadOptionsSize, IN UINT32 LoadOptionsSize,
IN VOID *LoadOptions, IN VOID *LoadOptions,
IN VOID *EfiToLegacy16BootTable IN VOID *EfiToLegacy16BootTable
) )
{ {
BBS_TABLE *LocalBbsTable; BBS_TABLE *LocalBbsTable;
EFI_TO_COMPATIBILITY16_BOOT_TABLE *Legacy16BootTable; EFI_TO_COMPATIBILITY16_BOOT_TABLE *Legacy16BootTable;
DEVICE_PRODUCER_DATA_HEADER *SioPtr; DEVICE_PRODUCER_DATA_HEADER *SioPtr;
UINT16 DevicePathType; UINT16 DevicePathType;
UINT16 Index; UINT16 Index;
UINT16 Priority; UINT16 Priority;
// //
// Initialize values // Initialize values
// //
Priority = 0; Priority = 0;
Legacy16BootTable = (EFI_TO_COMPATIBILITY16_BOOT_TABLE*) EfiToLegacy16BootTable; Legacy16BootTable = (EFI_TO_COMPATIBILITY16_BOOT_TABLE *)EfiToLegacy16BootTable;
// //
// Set how Gate A20 is gated by hardware // Set how Gate A20 is gated by hardware
@ -943,7 +966,7 @@ PrepareToBoot (
SioPtr->Flags.A20Port90 = 1; SioPtr->Flags.A20Port90 = 1;
SioPtr->MousePresent = 1; SioPtr->MousePresent = 1;
LocalBbsTable = BbsTable; LocalBbsTable = BbsTable;
// //
// There are 2 cases that must be covered. // There are 2 cases that must be covered.
@ -966,8 +989,9 @@ PrepareToBoot (
if ((LocalBbsTable[Index].BootPriority != BBS_UNPRIORITIZED_ENTRY) && if ((LocalBbsTable[Index].BootPriority != BBS_UNPRIORITIZED_ENTRY) &&
(LocalBbsTable[Index].BootPriority != BBS_IGNORE_ENTRY) && (LocalBbsTable[Index].BootPriority != BBS_IGNORE_ENTRY) &&
(LocalBbsTable[Index].BootPriority != BBS_LOWEST_PRIORITY) && (LocalBbsTable[Index].BootPriority != BBS_LOWEST_PRIORITY) &&
(Priority <= LocalBbsTable[Index].BootPriority)) { (Priority <= LocalBbsTable[Index].BootPriority))
Priority = (UINT16) (LocalBbsTable[Index].BootPriority + 1); {
Priority = (UINT16)(LocalBbsTable[Index].BootPriority + 1);
} }
} }
@ -978,28 +1002,32 @@ PrepareToBoot (
case BBS_EMBED_NETWORK: case BBS_EMBED_NETWORK:
for (Index = 0; Index < Legacy16BootTable->NumberBbsEntries; Index++) { for (Index = 0; Index < Legacy16BootTable->NumberBbsEntries; Index++) {
if ((LocalBbsTable[Index].BootPriority == BBS_UNPRIORITIZED_ENTRY) && if ((LocalBbsTable[Index].BootPriority == BBS_UNPRIORITIZED_ENTRY) &&
(LocalBbsTable[Index].DeviceType == DevicePathType)) { (LocalBbsTable[Index].DeviceType == DevicePathType))
{
LocalBbsTable[Index].BootPriority = Priority; LocalBbsTable[Index].BootPriority = Priority;
++Priority; ++Priority;
} }
} }
break; break;
case BBS_BEV_DEVICE: case BBS_BEV_DEVICE:
for (Index = 0; Index < Legacy16BootTable->NumberBbsEntries; Index++) { for (Index = 0; Index < Legacy16BootTable->NumberBbsEntries; Index++) {
if ((LocalBbsTable[Index].BootPriority == BBS_UNPRIORITIZED_ENTRY) && if ((LocalBbsTable[Index].BootPriority == BBS_UNPRIORITIZED_ENTRY) &&
(LocalBbsTable[Index].Class == 01) && (LocalBbsTable[Index].Class == 01) &&
(LocalBbsTable[Index].SubClass == 01)) { (LocalBbsTable[Index].SubClass == 01))
{
LocalBbsTable[Index].BootPriority = Priority; LocalBbsTable[Index].BootPriority = Priority;
++Priority; ++Priority;
} }
} }
break; break;
case BBS_USB: case BBS_USB:
case BBS_PCMCIA: case BBS_PCMCIA:
case BBS_UNKNOWN: case BBS_UNKNOWN:
default: default:
break; break;
}; }
// //
// Set priority for rest of devices // Set priority for rest of devices
@ -1014,7 +1042,6 @@ PrepareToBoot (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Initialize Legacy Platform support Initialize Legacy Platform support
@ -1026,16 +1053,16 @@ LegacyBiosPlatformInstall (
VOID VOID
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
LEGACY_BIOS_PLATFORM_INSTANCE *Private; LEGACY_BIOS_PLATFORM_INSTANCE *Private;
mImageHandle = gImageHandle; mImageHandle = gImageHandle;
Private = &mPrivateData; Private = &mPrivateData;
// //
// Grab a copy of all the protocols we depend on. // Grab a copy of all the protocols we depend on.
// //
Private->Signature = LEGACY_BIOS_PLATFORM_INSTANCE_SIGNATURE; Private->Signature = LEGACY_BIOS_PLATFORM_INSTANCE_SIGNATURE;
Private->LegacyBiosPlatform.GetPlatformInfo = GetPlatformInfo; Private->LegacyBiosPlatform.GetPlatformInfo = GetPlatformInfo;
Private->LegacyBiosPlatform.GetPlatformHandle = GetPlatformHandle; Private->LegacyBiosPlatform.GetPlatformHandle = GetPlatformHandle;
Private->LegacyBiosPlatform.SmmInit = SmmInit; Private->LegacyBiosPlatform.SmmInit = SmmInit;
@ -1043,17 +1070,17 @@ LegacyBiosPlatformInstall (
Private->LegacyBiosPlatform.GetRoutingTable = GetRoutingTable; Private->LegacyBiosPlatform.GetRoutingTable = GetRoutingTable;
Private->LegacyBiosPlatform.TranslatePirq = TranslatePirq; Private->LegacyBiosPlatform.TranslatePirq = TranslatePirq;
Private->LegacyBiosPlatform.PrepareToBoot = PrepareToBoot; Private->LegacyBiosPlatform.PrepareToBoot = PrepareToBoot;
Private->ImageHandle = gImageHandle; Private->ImageHandle = gImageHandle;
// //
// Make a new handle and install the protocol // Make a new handle and install the protocol
// //
Private->Handle = NULL; Private->Handle = NULL;
Status = gBS->InstallProtocolInterface ( Status = gBS->InstallProtocolInterface (
&Private->Handle, &Private->Handle,
&gEfiLegacyBiosPlatformProtocolGuid, &gEfiLegacyBiosPlatformProtocolGuid,
EFI_NATIVE_INTERFACE, EFI_NATIVE_INTERFACE,
&Private->LegacyBiosPlatform &Private->LegacyBiosPlatform
); );
return Status; return Status;
} }

View File

@ -38,54 +38,54 @@
// //
// PIRQ information constants. // PIRQ information constants.
// //
#define MAX_IRQ_ROUTING_ENTRIES 6 #define MAX_IRQ_ROUTING_ENTRIES 6
#define MAX_IRQ_PRIORITY_ENTRIES 7 #define MAX_IRQ_PRIORITY_ENTRIES 7
#define V_INTEL_VENDOR_ID 0x8086 #define V_INTEL_VENDOR_ID 0x8086
#define V_PIIX4_IDE_DEVICE_ID 0x7010 #define V_PIIX4_IDE_DEVICE_ID 0x7010
// //
// Type declarations // Type declarations
// //
typedef struct { typedef struct {
UINT8 SetupValue; UINT8 SetupValue;
UINT16 DeviceType; UINT16 DeviceType;
UINT8 Class; UINT8 Class;
UINT8 SubClass; UINT8 SubClass;
} EFI_SETUP_BBS_MAP; } EFI_SETUP_BBS_MAP;
typedef struct { typedef struct {
UINT8 Class; UINT8 Class;
UINT8 SubClass; UINT8 SubClass;
} PCI_CLASS_RECORD; } PCI_CLASS_RECORD;
typedef struct { typedef struct {
EFI_LEGACY_PIRQ_TABLE_HEADER PirqTable; EFI_LEGACY_PIRQ_TABLE_HEADER PirqTable;
EFI_LEGACY_IRQ_ROUTING_ENTRY IrqRoutingEntry[MAX_IRQ_ROUTING_ENTRIES]; EFI_LEGACY_IRQ_ROUTING_ENTRY IrqRoutingEntry[MAX_IRQ_ROUTING_ENTRIES];
} EFI_LEGACY_PIRQ_TABLE; } EFI_LEGACY_PIRQ_TABLE;
typedef struct { typedef struct {
EFI_HANDLE Handle; EFI_HANDLE Handle;
UINT16 Vid; UINT16 Vid;
UINT16 Did; UINT16 Did;
UINT16 SvId; UINT16 SvId;
UINT16 SysId; UINT16 SysId;
} DEVICE_STRUCTURE; } DEVICE_STRUCTURE;
typedef struct { typedef struct {
EFI_GUID FileName; EFI_GUID FileName;
UINTN Valid; UINTN Valid;
} SYSTEM_ROM_TABLE; } SYSTEM_ROM_TABLE;
typedef struct { typedef struct {
UINT32 Signature; UINT32 Signature;
EFI_HANDLE Handle; EFI_HANDLE Handle;
EFI_LEGACY_BIOS_PLATFORM_PROTOCOL LegacyBiosPlatform; EFI_LEGACY_BIOS_PLATFORM_PROTOCOL LegacyBiosPlatform;
EFI_HANDLE ImageHandle; EFI_HANDLE ImageHandle;
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo; EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
} LEGACY_BIOS_PLATFORM_INSTANCE; } LEGACY_BIOS_PLATFORM_INSTANCE;
#define LEGACY_BIOS_PLATFORM_INSTANCE_SIGNATURE SIGNATURE_32('P','B','I','O') #define LEGACY_BIOS_PLATFORM_INSTANCE_SIGNATURE SIGNATURE_32('P','B','I','O')
#define LEGACY_BIOS_PLATFORM_INSTANCE_FROM_THIS(this) \ #define LEGACY_BIOS_PLATFORM_INSTANCE_FROM_THIS(this) \
CR (this, \ CR (this, \
@ -95,4 +95,3 @@ typedef struct {
) )
#endif #endif

View File

@ -29,55 +29,55 @@
// 0xEC000-0xEFFFF 0x5f 0x96 5:4 00 = DRAM Disabled, 01= Read Only, 10 = Write Only, 11 = Normal // 0xEC000-0xEFFFF 0x5f 0x96 5:4 00 = DRAM Disabled, 01= Read Only, 10 = Write Only, 11 = Normal
// 0xF0000-0xFFFFF 0x59 0x90 5:4 00 = DRAM Disabled, 01= Read Only, 10 = Write Only, 11 = Normal // 0xF0000-0xFFFFF 0x59 0x90 5:4 00 = DRAM Disabled, 01= Read Only, 10 = Write Only, 11 = Normal
// //
STATIC LEGACY_MEMORY_SECTION_INFO mSectionArray[] = { STATIC LEGACY_MEMORY_SECTION_INFO mSectionArray[] = {
{0xC0000, SIZE_16KB, FALSE, FALSE}, { 0xC0000, SIZE_16KB, FALSE, FALSE },
{0xC4000, SIZE_16KB, FALSE, FALSE}, { 0xC4000, SIZE_16KB, FALSE, FALSE },
{0xC8000, SIZE_16KB, FALSE, FALSE}, { 0xC8000, SIZE_16KB, FALSE, FALSE },
{0xCC000, SIZE_16KB, FALSE, FALSE}, { 0xCC000, SIZE_16KB, FALSE, FALSE },
{0xD0000, SIZE_16KB, FALSE, FALSE}, { 0xD0000, SIZE_16KB, FALSE, FALSE },
{0xD4000, SIZE_16KB, FALSE, FALSE}, { 0xD4000, SIZE_16KB, FALSE, FALSE },
{0xD8000, SIZE_16KB, FALSE, FALSE}, { 0xD8000, SIZE_16KB, FALSE, FALSE },
{0xDC000, SIZE_16KB, FALSE, FALSE}, { 0xDC000, SIZE_16KB, FALSE, FALSE },
{0xE0000, SIZE_16KB, FALSE, FALSE}, { 0xE0000, SIZE_16KB, FALSE, FALSE },
{0xE4000, SIZE_16KB, FALSE, FALSE}, { 0xE4000, SIZE_16KB, FALSE, FALSE },
{0xE8000, SIZE_16KB, FALSE, FALSE}, { 0xE8000, SIZE_16KB, FALSE, FALSE },
{0xEC000, SIZE_16KB, FALSE, FALSE}, { 0xEC000, SIZE_16KB, FALSE, FALSE },
{0xF0000, SIZE_64KB, FALSE, FALSE} { 0xF0000, SIZE_64KB, FALSE, FALSE }
}; };
STATIC PAM_REGISTER_VALUE mRegisterValues440[] = { STATIC PAM_REGISTER_VALUE mRegisterValues440[] = {
{PMC_REGISTER_PIIX4 (PIIX4_PAM1), 0x01, 0x02}, { PMC_REGISTER_PIIX4 (PIIX4_PAM1), 0x01, 0x02 },
{PMC_REGISTER_PIIX4 (PIIX4_PAM1), 0x10, 0x20}, { PMC_REGISTER_PIIX4 (PIIX4_PAM1), 0x10, 0x20 },
{PMC_REGISTER_PIIX4 (PIIX4_PAM2), 0x01, 0x02}, { PMC_REGISTER_PIIX4 (PIIX4_PAM2), 0x01, 0x02 },
{PMC_REGISTER_PIIX4 (PIIX4_PAM2), 0x10, 0x20}, { PMC_REGISTER_PIIX4 (PIIX4_PAM2), 0x10, 0x20 },
{PMC_REGISTER_PIIX4 (PIIX4_PAM3), 0x01, 0x02}, { PMC_REGISTER_PIIX4 (PIIX4_PAM3), 0x01, 0x02 },
{PMC_REGISTER_PIIX4 (PIIX4_PAM3), 0x10, 0x20}, { PMC_REGISTER_PIIX4 (PIIX4_PAM3), 0x10, 0x20 },
{PMC_REGISTER_PIIX4 (PIIX4_PAM4), 0x01, 0x02}, { PMC_REGISTER_PIIX4 (PIIX4_PAM4), 0x01, 0x02 },
{PMC_REGISTER_PIIX4 (PIIX4_PAM4), 0x10, 0x20}, { PMC_REGISTER_PIIX4 (PIIX4_PAM4), 0x10, 0x20 },
{PMC_REGISTER_PIIX4 (PIIX4_PAM5), 0x01, 0x02}, { PMC_REGISTER_PIIX4 (PIIX4_PAM5), 0x01, 0x02 },
{PMC_REGISTER_PIIX4 (PIIX4_PAM5), 0x10, 0x20}, { PMC_REGISTER_PIIX4 (PIIX4_PAM5), 0x10, 0x20 },
{PMC_REGISTER_PIIX4 (PIIX4_PAM6), 0x01, 0x02}, { PMC_REGISTER_PIIX4 (PIIX4_PAM6), 0x01, 0x02 },
{PMC_REGISTER_PIIX4 (PIIX4_PAM6), 0x10, 0x20}, { PMC_REGISTER_PIIX4 (PIIX4_PAM6), 0x10, 0x20 },
{PMC_REGISTER_PIIX4 (PIIX4_PAM0), 0x10, 0x20} { PMC_REGISTER_PIIX4 (PIIX4_PAM0), 0x10, 0x20 }
}; };
STATIC PAM_REGISTER_VALUE mRegisterValuesQ35[] = { STATIC PAM_REGISTER_VALUE mRegisterValuesQ35[] = {
{DRAMC_REGISTER_Q35 (MCH_PAM1), 0x01, 0x02}, { DRAMC_REGISTER_Q35 (MCH_PAM1), 0x01, 0x02 },
{DRAMC_REGISTER_Q35 (MCH_PAM1), 0x10, 0x20}, { DRAMC_REGISTER_Q35 (MCH_PAM1), 0x10, 0x20 },
{DRAMC_REGISTER_Q35 (MCH_PAM2), 0x01, 0x02}, { DRAMC_REGISTER_Q35 (MCH_PAM2), 0x01, 0x02 },
{DRAMC_REGISTER_Q35 (MCH_PAM2), 0x10, 0x20}, { DRAMC_REGISTER_Q35 (MCH_PAM2), 0x10, 0x20 },
{DRAMC_REGISTER_Q35 (MCH_PAM3), 0x01, 0x02}, { DRAMC_REGISTER_Q35 (MCH_PAM3), 0x01, 0x02 },
{DRAMC_REGISTER_Q35 (MCH_PAM3), 0x10, 0x20}, { DRAMC_REGISTER_Q35 (MCH_PAM3), 0x10, 0x20 },
{DRAMC_REGISTER_Q35 (MCH_PAM4), 0x01, 0x02}, { DRAMC_REGISTER_Q35 (MCH_PAM4), 0x01, 0x02 },
{DRAMC_REGISTER_Q35 (MCH_PAM4), 0x10, 0x20}, { DRAMC_REGISTER_Q35 (MCH_PAM4), 0x10, 0x20 },
{DRAMC_REGISTER_Q35 (MCH_PAM5), 0x01, 0x02}, { DRAMC_REGISTER_Q35 (MCH_PAM5), 0x01, 0x02 },
{DRAMC_REGISTER_Q35 (MCH_PAM5), 0x10, 0x20}, { DRAMC_REGISTER_Q35 (MCH_PAM5), 0x10, 0x20 },
{DRAMC_REGISTER_Q35 (MCH_PAM6), 0x01, 0x02}, { DRAMC_REGISTER_Q35 (MCH_PAM6), 0x01, 0x02 },
{DRAMC_REGISTER_Q35 (MCH_PAM6), 0x10, 0x20}, { DRAMC_REGISTER_Q35 (MCH_PAM6), 0x10, 0x20 },
{DRAMC_REGISTER_Q35 (MCH_PAM0), 0x10, 0x20} { DRAMC_REGISTER_Q35 (MCH_PAM0), 0x10, 0x20 }
}; };
STATIC PAM_REGISTER_VALUE *mRegisterValues; STATIC PAM_REGISTER_VALUE *mRegisterValues;
// //
// Handle used to install the Legacy Region Protocol // Handle used to install the Legacy Region Protocol
@ -98,25 +98,26 @@ STATIC EFI_LEGACY_REGION2_PROTOCOL mLegacyRegion2 = {
STATIC STATIC
EFI_STATUS EFI_STATUS
LegacyRegionManipulationInternal ( LegacyRegionManipulationInternal (
IN UINT32 Start, IN UINT32 Start,
IN UINT32 Length, IN UINT32 Length,
IN BOOLEAN *ReadEnable, IN BOOLEAN *ReadEnable,
IN BOOLEAN *WriteEnable, IN BOOLEAN *WriteEnable,
OUT UINT32 *Granularity OUT UINT32 *Granularity
) )
{ {
UINT32 EndAddress; UINT32 EndAddress;
UINTN Index; UINTN Index;
UINTN StartIndex; UINTN StartIndex;
// //
// Validate input parameters. // Validate input parameters.
// //
if (Length == 0 || Granularity == NULL) { if ((Length == 0) || (Granularity == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
EndAddress = Start + Length - 1; EndAddress = Start + Length - 1;
if ((Start < PAM_BASE_ADDRESS) || EndAddress > PAM_LIMIT_ADDRESS) { if ((Start < PAM_BASE_ADDRESS) || (EndAddress > PAM_LIMIT_ADDRESS)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -130,6 +131,7 @@ LegacyRegionManipulationInternal (
break; break;
} }
} }
ASSERT (Index < ARRAY_SIZE (mSectionArray)); ASSERT (Index < ARRAY_SIZE (mSectionArray));
// //
@ -145,10 +147,11 @@ LegacyRegionManipulationInternal (
} else { } else {
PciAnd8 ( PciAnd8 (
mRegisterValues[Index].PAMRegPciLibAddress, mRegisterValues[Index].PAMRegPciLibAddress,
(UINT8) (~mRegisterValues[Index].ReadEnableData) (UINT8)(~mRegisterValues[Index].ReadEnableData)
); );
} }
} }
if (WriteEnable != NULL) { if (WriteEnable != NULL) {
if (*WriteEnable) { if (*WriteEnable) {
PciOr8 ( PciOr8 (
@ -158,7 +161,7 @@ LegacyRegionManipulationInternal (
} else { } else {
PciAnd8 ( PciAnd8 (
mRegisterValues[Index].PAMRegPciLibAddress, mRegisterValues[Index].PAMRegPciLibAddress,
(UINT8) (~mRegisterValues[Index].WriteEnableData) (UINT8)(~mRegisterValues[Index].WriteEnableData)
); );
} }
} }
@ -171,6 +174,7 @@ LegacyRegionManipulationInternal (
break; break;
} }
} }
ASSERT (Index < ARRAY_SIZE (mSectionArray)); ASSERT (Index < ARRAY_SIZE (mSectionArray));
return EFI_SUCCESS; return EFI_SUCCESS;
@ -179,30 +183,31 @@ LegacyRegionManipulationInternal (
STATIC STATIC
EFI_STATUS EFI_STATUS
LegacyRegionGetInfoInternal ( LegacyRegionGetInfoInternal (
OUT UINT32 *DescriptorCount, OUT UINT32 *DescriptorCount,
OUT LEGACY_MEMORY_SECTION_INFO **Descriptor OUT LEGACY_MEMORY_SECTION_INFO **Descriptor
) )
{ {
UINTN Index; UINTN Index;
UINT8 PamValue; UINT8 PamValue;
// //
// Check input parameters // Check input parameters
// //
if (DescriptorCount == NULL || Descriptor == NULL) { if ((DescriptorCount == NULL) || (Descriptor == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
// //
// Fill in current status of legacy region. // Fill in current status of legacy region.
// //
*DescriptorCount = sizeof(mSectionArray) / sizeof (mSectionArray[0]); *DescriptorCount = sizeof (mSectionArray) / sizeof (mSectionArray[0]);
for (Index = 0; Index < *DescriptorCount; Index++) { for (Index = 0; Index < *DescriptorCount; Index++) {
PamValue = PciRead8 (mRegisterValues[Index].PAMRegPciLibAddress); PamValue = PciRead8 (mRegisterValues[Index].PAMRegPciLibAddress);
mSectionArray[Index].ReadEnabled = FALSE; mSectionArray[Index].ReadEnabled = FALSE;
if ((PamValue & mRegisterValues[Index].ReadEnableData) != 0) { if ((PamValue & mRegisterValues[Index].ReadEnableData) != 0) {
mSectionArray[Index].ReadEnabled = TRUE; mSectionArray[Index].ReadEnabled = TRUE;
} }
mSectionArray[Index].WriteEnabled = FALSE; mSectionArray[Index].WriteEnabled = FALSE;
if ((PamValue & mRegisterValues[Index].WriteEnableData) != 0) { if ((PamValue & mRegisterValues[Index].WriteEnableData) != 0) {
mSectionArray[Index].WriteEnabled = TRUE; mSectionArray[Index].WriteEnabled = TRUE;
@ -250,7 +255,6 @@ LegacyRegion2Decode (
return LegacyRegionManipulationInternal (Start, Length, On, NULL, Granularity); return LegacyRegionManipulationInternal (Start, Length, On, NULL, Granularity);
} }
/** /**
Modify the hardware to disallow memory attribute changes in a region. Modify the hardware to disallow memory attribute changes in a region.
@ -279,10 +283,10 @@ LegacyRegion2Decode (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
LegacyRegion2BootLock ( LegacyRegion2BootLock (
IN EFI_LEGACY_REGION2_PROTOCOL *This, IN EFI_LEGACY_REGION2_PROTOCOL *This,
IN UINT32 Start, IN UINT32 Start,
IN UINT32 Length, IN UINT32 Length,
OUT UINT32 *Granularity OUT UINT32 *Granularity
) )
{ {
if ((Start < 0xC0000) || ((Start + Length - 1) > 0xFFFFF)) { if ((Start < 0xC0000) || ((Start + Length - 1) > 0xFFFFF)) {
@ -292,7 +296,6 @@ LegacyRegion2BootLock (
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
/** /**
Modify the hardware to disallow memory writes in a region. Modify the hardware to disallow memory writes in a region.
@ -316,10 +319,10 @@ LegacyRegion2BootLock (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
LegacyRegion2Lock ( LegacyRegion2Lock (
IN EFI_LEGACY_REGION2_PROTOCOL *This, IN EFI_LEGACY_REGION2_PROTOCOL *This,
IN UINT32 Start, IN UINT32 Start,
IN UINT32 Length, IN UINT32 Length,
OUT UINT32 *Granularity OUT UINT32 *Granularity
) )
{ {
BOOLEAN WriteEnable; BOOLEAN WriteEnable;
@ -328,7 +331,6 @@ LegacyRegion2Lock (
return LegacyRegionManipulationInternal (Start, Length, NULL, &WriteEnable, Granularity); return LegacyRegionManipulationInternal (Start, Length, NULL, &WriteEnable, Granularity);
} }
/** /**
Modify the hardware to allow memory writes in a region. Modify the hardware to allow memory writes in a region.
@ -391,11 +393,11 @@ LegacyRegionGetInfo (
OUT EFI_LEGACY_REGION_DESCRIPTOR **Descriptor OUT EFI_LEGACY_REGION_DESCRIPTOR **Descriptor
) )
{ {
LEGACY_MEMORY_SECTION_INFO *SectionInfo; LEGACY_MEMORY_SECTION_INFO *SectionInfo;
UINT32 SectionCount; UINT32 SectionCount;
EFI_LEGACY_REGION_DESCRIPTOR *DescriptorArray; EFI_LEGACY_REGION_DESCRIPTOR *DescriptorArray;
UINTN Index; UINTN Index;
UINTN DescriptorIndex; UINTN DescriptorIndex;
// //
// Get section numbers and information // Get section numbers and information
@ -416,10 +418,11 @@ LegacyRegionGetInfo (
DescriptorArray[DescriptorIndex].Length = SectionInfo[Index].Length; DescriptorArray[DescriptorIndex].Length = SectionInfo[Index].Length;
DescriptorArray[DescriptorIndex].Granularity = SectionInfo[Index].Length; DescriptorArray[DescriptorIndex].Granularity = SectionInfo[Index].Length;
if (SectionInfo[Index].ReadEnabled) { if (SectionInfo[Index].ReadEnabled) {
DescriptorArray[DescriptorIndex].Attribute = LegacyRegionDecoded; DescriptorArray[DescriptorIndex].Attribute = LegacyRegionDecoded;
} else { } else {
DescriptorArray[DescriptorIndex].Attribute = LegacyRegionNotDecoded; DescriptorArray[DescriptorIndex].Attribute = LegacyRegionNotDecoded;
} }
DescriptorIndex++; DescriptorIndex++;
// //
@ -433,6 +436,7 @@ LegacyRegionGetInfo (
} else { } else {
DescriptorArray[DescriptorIndex].Attribute = LegacyRegionWriteDisabled; DescriptorArray[DescriptorIndex].Attribute = LegacyRegionWriteDisabled;
} }
DescriptorIndex++; DescriptorIndex++;
// //
@ -445,7 +449,7 @@ LegacyRegionGetInfo (
DescriptorIndex++; DescriptorIndex++;
} }
*DescriptorCount = (UINT32) DescriptorIndex; *DescriptorCount = (UINT32)DescriptorIndex;
*Descriptor = DescriptorArray; *Descriptor = DescriptorArray;
return EFI_SUCCESS; return EFI_SUCCESS;
@ -470,17 +474,21 @@ LegacyRegionInit (
// //
HostBridgeDevId = PcdGet16 (PcdOvmfHostBridgePciDevId); HostBridgeDevId = PcdGet16 (PcdOvmfHostBridgePciDevId);
switch (HostBridgeDevId) { switch (HostBridgeDevId) {
case INTEL_82441_DEVICE_ID: case INTEL_82441_DEVICE_ID:
mRegisterValues = mRegisterValues440; mRegisterValues = mRegisterValues440;
break; break;
case INTEL_Q35_MCH_DEVICE_ID: case INTEL_Q35_MCH_DEVICE_ID:
mRegisterValues = mRegisterValuesQ35; mRegisterValues = mRegisterValuesQ35;
break; break;
default: default:
DEBUG ((DEBUG_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n", DEBUG ((
__FUNCTION__, HostBridgeDevId)); DEBUG_ERROR,
ASSERT (FALSE); "%a: Unknown Host Bridge Device ID: 0x%04x\n",
return RETURN_UNSUPPORTED; __FUNCTION__,
HostBridgeDevId
));
ASSERT (FALSE);
return RETURN_UNSUPPORTED;
} }
// //
@ -488,11 +496,11 @@ LegacyRegionInit (
// //
Status = gBS->InstallMultipleProtocolInterfaces ( Status = gBS->InstallMultipleProtocolInterfaces (
&mHandle, &mHandle,
&gEfiLegacyRegion2ProtocolGuid, &mLegacyRegion2, &gEfiLegacyRegion2ProtocolGuid,
&mLegacyRegion2,
NULL NULL
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return Status; return Status;
} }

View File

@ -31,19 +31,19 @@
// Describes Legacy Region blocks and status. // Describes Legacy Region blocks and status.
// //
typedef struct { typedef struct {
UINT32 Start; UINT32 Start;
UINT32 Length; UINT32 Length;
BOOLEAN ReadEnabled; BOOLEAN ReadEnabled;
BOOLEAN WriteEnabled; BOOLEAN WriteEnabled;
} LEGACY_MEMORY_SECTION_INFO; } LEGACY_MEMORY_SECTION_INFO;
// //
// Provides a map of the PAM registers and bits used to set Read/Write access. // Provides a map of the PAM registers and bits used to set Read/Write access.
// //
typedef struct { typedef struct {
UINTN PAMRegPciLibAddress; UINTN PAMRegPciLibAddress;
UINT8 ReadEnableData; UINT8 ReadEnableData;
UINT8 WriteEnableData; UINT8 WriteEnableData;
} PAM_REGISTER_VALUE; } PAM_REGISTER_VALUE;
/** /**
@ -103,10 +103,10 @@ LegacyRegion2Decode (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
LegacyRegion2Lock ( LegacyRegion2Lock (
IN EFI_LEGACY_REGION2_PROTOCOL *This, IN EFI_LEGACY_REGION2_PROTOCOL *This,
IN UINT32 Start, IN UINT32 Start,
IN UINT32 Length, IN UINT32 Length,
OUT UINT32 *Granularity OUT UINT32 *Granularity
); );
/** /**
@ -137,10 +137,10 @@ LegacyRegion2Lock (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
LegacyRegion2BootLock ( LegacyRegion2BootLock (
IN EFI_LEGACY_REGION2_PROTOCOL *This, IN EFI_LEGACY_REGION2_PROTOCOL *This,
IN UINT32 Start, IN UINT32 Start,
IN UINT32 Length, IN UINT32 Length,
OUT UINT32 *Granularity OUT UINT32 *Granularity
); );
/** /**
@ -200,4 +200,3 @@ LegacyRegionGetInfo (
); );
#endif #endif

View File

@ -17,25 +17,24 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
/// ///
/// S3 Boot Script Table identifier. /// S3 Boot Script Table identifier.
/// ///
#define FRAMEWORK_EFI_ACPI_S3_RESUME_SCRIPT_TABLE 0x00 #define FRAMEWORK_EFI_ACPI_S3_RESUME_SCRIPT_TABLE 0x00
/// ///
/// The opcode is used to add a record for memory reads of the memory location and continues when the /// The opcode is used to add a record for memory reads of the memory location and continues when the
/// exit criteria is satisfied, or after a defined duration. /// exit criteria is satisfied, or after a defined duration.
/// ///
#define FRAMEWORK_EFI_BOOT_SCRIPT_MEM_POLL_OPCODE 0x09 #define FRAMEWORK_EFI_BOOT_SCRIPT_MEM_POLL_OPCODE 0x09
/// ///
/// The opcode is used to add a record for dispatching specified arbitrary code into a specified /// The opcode is used to add a record for dispatching specified arbitrary code into a specified
/// boot script table. /// boot script table.
/// ///
#define FRAMEWORK_EFI_BOOT_SCRIPT_DISPATCH_2_OPCODE 0x0D #define FRAMEWORK_EFI_BOOT_SCRIPT_DISPATCH_2_OPCODE 0x0D
/// ///
/// The opcode indicates the start of the boot script table. /// The opcode indicates the start of the boot script table.
/// ///
#define FRAMEWORK_EFI_BOOT_SCRIPT_TABLE_OPCODE 0xAA #define FRAMEWORK_EFI_BOOT_SCRIPT_TABLE_OPCODE 0xAA
/// ///
/// The opcode indicates the end of the boot script table. /// The opcode indicates the end of the boot script table.
/// ///
#define FRAMEWORK_EFI_BOOT_SCRIPT_TERMINATE_OPCODE 0xFF #define FRAMEWORK_EFI_BOOT_SCRIPT_TERMINATE_OPCODE 0xFF
#endif #endif

View File

@ -33,35 +33,35 @@ typedef struct {
// //
// Table header for the Framework EFI Runtime Services Table // Table header for the Framework EFI Runtime Services Table
// //
EFI_TABLE_HEADER Hdr; EFI_TABLE_HEADER Hdr;
// //
// Time services // Time services
// //
EFI_GET_TIME GetTime; EFI_GET_TIME GetTime;
EFI_SET_TIME SetTime; EFI_SET_TIME SetTime;
EFI_GET_WAKEUP_TIME GetWakeupTime; EFI_GET_WAKEUP_TIME GetWakeupTime;
EFI_SET_WAKEUP_TIME SetWakeupTime; EFI_SET_WAKEUP_TIME SetWakeupTime;
// //
// Virtual memory services // Virtual memory services
// //
EFI_SET_VIRTUAL_ADDRESS_MAP SetVirtualAddressMap; EFI_SET_VIRTUAL_ADDRESS_MAP SetVirtualAddressMap;
EFI_CONVERT_POINTER ConvertPointer; EFI_CONVERT_POINTER ConvertPointer;
// //
// Variable services // Variable services
// //
EFI_GET_VARIABLE GetVariable; EFI_GET_VARIABLE GetVariable;
EFI_GET_NEXT_VARIABLE_NAME GetNextVariableName; EFI_GET_NEXT_VARIABLE_NAME GetNextVariableName;
EFI_SET_VARIABLE SetVariable; EFI_SET_VARIABLE SetVariable;
// //
// Misc // Misc
// //
EFI_GET_NEXT_HIGH_MONO_COUNT GetNextHighMonotonicCount; EFI_GET_NEXT_HIGH_MONO_COUNT GetNextHighMonotonicCount;
EFI_RESET_SYSTEM ResetSystem; EFI_RESET_SYSTEM ResetSystem;
/// ///
/// A Framework extension to the EFI 1.10 runtime table. /// A Framework extension to the EFI 1.10 runtime table.
/// It was moved to a protocol to avoid conflict with UEFI 2.0. /// It was moved to a protocol to avoid conflict with UEFI 2.0.
/// ///
EFI_REPORT_STATUS_CODE ReportStatusCode; EFI_REPORT_STATUS_CODE ReportStatusCode;
} FRAMEWORK_EFI_RUNTIME_SERVICES; } FRAMEWORK_EFI_RUNTIME_SERVICES;
/// ///
@ -71,94 +71,94 @@ typedef struct {
/// ///
/// The table header for the EFI Boot Services Table. /// The table header for the EFI Boot Services Table.
/// ///
EFI_TABLE_HEADER Hdr; EFI_TABLE_HEADER Hdr;
// //
// Task Priority Services // Task Priority Services
// //
EFI_RAISE_TPL RaiseTPL; EFI_RAISE_TPL RaiseTPL;
EFI_RESTORE_TPL RestoreTPL; EFI_RESTORE_TPL RestoreTPL;
// //
// Memory Services // Memory Services
// //
EFI_ALLOCATE_PAGES AllocatePages; EFI_ALLOCATE_PAGES AllocatePages;
EFI_FREE_PAGES FreePages; EFI_FREE_PAGES FreePages;
EFI_GET_MEMORY_MAP GetMemoryMap; EFI_GET_MEMORY_MAP GetMemoryMap;
EFI_ALLOCATE_POOL AllocatePool; EFI_ALLOCATE_POOL AllocatePool;
EFI_FREE_POOL FreePool; EFI_FREE_POOL FreePool;
// //
// Event & Timer Services // Event & Timer Services
// //
EFI_CREATE_EVENT CreateEvent; EFI_CREATE_EVENT CreateEvent;
EFI_SET_TIMER SetTimer; EFI_SET_TIMER SetTimer;
EFI_WAIT_FOR_EVENT WaitForEvent; EFI_WAIT_FOR_EVENT WaitForEvent;
EFI_SIGNAL_EVENT SignalEvent; EFI_SIGNAL_EVENT SignalEvent;
EFI_CLOSE_EVENT CloseEvent; EFI_CLOSE_EVENT CloseEvent;
EFI_CHECK_EVENT CheckEvent; EFI_CHECK_EVENT CheckEvent;
// //
// Protocol Handler Services // Protocol Handler Services
// //
EFI_INSTALL_PROTOCOL_INTERFACE InstallProtocolInterface; EFI_INSTALL_PROTOCOL_INTERFACE InstallProtocolInterface;
EFI_REINSTALL_PROTOCOL_INTERFACE ReinstallProtocolInterface; EFI_REINSTALL_PROTOCOL_INTERFACE ReinstallProtocolInterface;
EFI_UNINSTALL_PROTOCOL_INTERFACE UninstallProtocolInterface; EFI_UNINSTALL_PROTOCOL_INTERFACE UninstallProtocolInterface;
EFI_HANDLE_PROTOCOL HandleProtocol; EFI_HANDLE_PROTOCOL HandleProtocol;
EFI_HANDLE_PROTOCOL PcHandleProtocol; EFI_HANDLE_PROTOCOL PcHandleProtocol;
EFI_REGISTER_PROTOCOL_NOTIFY RegisterProtocolNotify; EFI_REGISTER_PROTOCOL_NOTIFY RegisterProtocolNotify;
EFI_LOCATE_HANDLE LocateHandle; EFI_LOCATE_HANDLE LocateHandle;
EFI_LOCATE_DEVICE_PATH LocateDevicePath; EFI_LOCATE_DEVICE_PATH LocateDevicePath;
EFI_INSTALL_CONFIGURATION_TABLE InstallConfigurationTable; EFI_INSTALL_CONFIGURATION_TABLE InstallConfigurationTable;
// //
// Image Services // Image Services
// //
EFI_IMAGE_LOAD LoadImage; EFI_IMAGE_LOAD LoadImage;
EFI_IMAGE_START StartImage; EFI_IMAGE_START StartImage;
EFI_EXIT Exit; EFI_EXIT Exit;
EFI_IMAGE_UNLOAD UnloadImage; EFI_IMAGE_UNLOAD UnloadImage;
EFI_EXIT_BOOT_SERVICES ExitBootServices; EFI_EXIT_BOOT_SERVICES ExitBootServices;
// //
// Miscellaneous Services // Miscellaneous Services
// //
EFI_GET_NEXT_MONOTONIC_COUNT GetNextMonotonicCount; EFI_GET_NEXT_MONOTONIC_COUNT GetNextMonotonicCount;
EFI_STALL Stall; EFI_STALL Stall;
EFI_SET_WATCHDOG_TIMER SetWatchdogTimer; EFI_SET_WATCHDOG_TIMER SetWatchdogTimer;
// //
// DriverSupport Services // DriverSupport Services
// //
EFI_CONNECT_CONTROLLER ConnectController; EFI_CONNECT_CONTROLLER ConnectController;
EFI_DISCONNECT_CONTROLLER DisconnectController; EFI_DISCONNECT_CONTROLLER DisconnectController;
// //
// Open and Close Protocol Services // Open and Close Protocol Services
// //
EFI_OPEN_PROTOCOL OpenProtocol; EFI_OPEN_PROTOCOL OpenProtocol;
EFI_CLOSE_PROTOCOL CloseProtocol; EFI_CLOSE_PROTOCOL CloseProtocol;
EFI_OPEN_PROTOCOL_INFORMATION OpenProtocolInformation; EFI_OPEN_PROTOCOL_INFORMATION OpenProtocolInformation;
// //
// Library Services // Library Services
// //
EFI_PROTOCOLS_PER_HANDLE ProtocolsPerHandle; EFI_PROTOCOLS_PER_HANDLE ProtocolsPerHandle;
EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer; EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer;
EFI_LOCATE_PROTOCOL LocateProtocol; EFI_LOCATE_PROTOCOL LocateProtocol;
EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces; EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces;
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces; EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces;
// //
// 32-bit CRC Services // 32-bit CRC Services
// //
EFI_CALCULATE_CRC32 CalculateCrc32; EFI_CALCULATE_CRC32 CalculateCrc32;
// //
// Miscellaneous Services // Miscellaneous Services
// //
EFI_COPY_MEM CopyMem; EFI_COPY_MEM CopyMem;
EFI_SET_MEM SetMem; EFI_SET_MEM SetMem;
} FRAMEWORK_EFI_BOOT_SERVICES; } FRAMEWORK_EFI_BOOT_SERVICES;
#define EFI_EVENT_RUNTIME_CONTEXT 0x20000000 #define EFI_EVENT_RUNTIME_CONTEXT 0x20000000
@ -167,4 +167,3 @@ typedef struct {
#define EFI_EVENT_SIGNAL_LEGACY_BOOT 0x00000204 #define EFI_EVENT_SIGNAL_LEGACY_BOOT 0x00000204
#endif #endif

View File

@ -17,38 +17,38 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
/// ///
/// Firmware Volume Block Attributes bit definitions. /// Firmware Volume Block Attributes bit definitions.
///@{ ///@{
#define EFI_FVB_READ_DISABLED_CAP 0x00000001 #define EFI_FVB_READ_DISABLED_CAP 0x00000001
#define EFI_FVB_READ_ENABLED_CAP 0x00000002 #define EFI_FVB_READ_ENABLED_CAP 0x00000002
#define EFI_FVB_READ_STATUS 0x00000004 #define EFI_FVB_READ_STATUS 0x00000004
#define EFI_FVB_WRITE_DISABLED_CAP 0x00000008 #define EFI_FVB_WRITE_DISABLED_CAP 0x00000008
#define EFI_FVB_WRITE_ENABLED_CAP 0x00000010 #define EFI_FVB_WRITE_ENABLED_CAP 0x00000010
#define EFI_FVB_WRITE_STATUS 0x00000020 #define EFI_FVB_WRITE_STATUS 0x00000020
#define EFI_FVB_LOCK_CAP 0x00000040 #define EFI_FVB_LOCK_CAP 0x00000040
#define EFI_FVB_LOCK_STATUS 0x00000080 #define EFI_FVB_LOCK_STATUS 0x00000080
#define EFI_FVB_STICKY_WRITE 0x00000200 #define EFI_FVB_STICKY_WRITE 0x00000200
#define EFI_FVB_MEMORY_MAPPED 0x00000400 #define EFI_FVB_MEMORY_MAPPED 0x00000400
#define EFI_FVB_ERASE_POLARITY 0x00000800 #define EFI_FVB_ERASE_POLARITY 0x00000800
#define EFI_FVB_ALIGNMENT_CAP 0x00008000 #define EFI_FVB_ALIGNMENT_CAP 0x00008000
#define EFI_FVB_ALIGNMENT_2 0x00010000 #define EFI_FVB_ALIGNMENT_2 0x00010000
#define EFI_FVB_ALIGNMENT_4 0x00020000 #define EFI_FVB_ALIGNMENT_4 0x00020000
#define EFI_FVB_ALIGNMENT_8 0x00040000 #define EFI_FVB_ALIGNMENT_8 0x00040000
#define EFI_FVB_ALIGNMENT_16 0x00080000 #define EFI_FVB_ALIGNMENT_16 0x00080000
#define EFI_FVB_ALIGNMENT_32 0x00100000 #define EFI_FVB_ALIGNMENT_32 0x00100000
#define EFI_FVB_ALIGNMENT_64 0x00200000 #define EFI_FVB_ALIGNMENT_64 0x00200000
#define EFI_FVB_ALIGNMENT_128 0x00400000 #define EFI_FVB_ALIGNMENT_128 0x00400000
#define EFI_FVB_ALIGNMENT_256 0x00800000 #define EFI_FVB_ALIGNMENT_256 0x00800000
#define EFI_FVB_ALIGNMENT_512 0x01000000 #define EFI_FVB_ALIGNMENT_512 0x01000000
#define EFI_FVB_ALIGNMENT_1K 0x02000000 #define EFI_FVB_ALIGNMENT_1K 0x02000000
#define EFI_FVB_ALIGNMENT_2K 0x04000000 #define EFI_FVB_ALIGNMENT_2K 0x04000000
#define EFI_FVB_ALIGNMENT_4K 0x08000000 #define EFI_FVB_ALIGNMENT_4K 0x08000000
#define EFI_FVB_ALIGNMENT_8K 0x10000000 #define EFI_FVB_ALIGNMENT_8K 0x10000000
#define EFI_FVB_ALIGNMENT_16K 0x20000000 #define EFI_FVB_ALIGNMENT_16K 0x20000000
#define EFI_FVB_ALIGNMENT_32K 0x40000000 #define EFI_FVB_ALIGNMENT_32K 0x40000000
#define EFI_FVB_ALIGNMENT_64K 0x80000000 #define EFI_FVB_ALIGNMENT_64K 0x80000000
///@} ///@}
/// This is a simple macro defined as the set of all FV Block Attributes signifying capabilities. /// This is a simple macro defined as the set of all FV Block Attributes signifying capabilities.
@ -68,12 +68,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
* @param Bit A value indicating the bit(s) to test. * @param Bit A value indicating the bit(s) to test.
* If multiple bits are set, the logical OR of their tests is the expression's value. * If multiple bits are set, the logical OR of their tests is the expression's value.
**/ **/
#define EFI_TEST_FFS_ATTRIBUTES_BIT( FvbAttributes, TestAttributes, Bit) \ #define EFI_TEST_FFS_ATTRIBUTES_BIT(FvbAttributes, TestAttributes, Bit) \
((BOOLEAN) \ ((BOOLEAN) \
((FvbAttributes & EFI_FVB_ERASE_POLARITY) ? (((~TestAttributes) & Bit) == Bit) : ((TestAttributes & Bit) == Bit)) \ ((FvbAttributes & EFI_FVB_ERASE_POLARITY) ? (((~TestAttributes) & Bit) == Bit) : ((TestAttributes & Bit) == Bit)) \
) )
/// A simple macro defined as the set of all FV Block Attribute bits that indicate status. /// A simple macro defined as the set of all FV Block Attribute bits that indicate status.
#define EFI_FVB_STATUS (EFI_FVB_READ_STATUS | EFI_FVB_WRITE_STATUS | EFI_FVB_LOCK_STATUS) #define EFI_FVB_STATUS (EFI_FVB_READ_STATUS | EFI_FVB_WRITE_STATUS | EFI_FVB_LOCK_STATUS)
#endif /* __EFI_FIRMWARE_VOLUME_HEADER_H__ */ #endif /* __EFI_FIRMWARE_VOLUME_HEADER_H__ */

View File

@ -17,16 +17,16 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// //
// Bit values for AuthenticationStatus // Bit values for AuthenticationStatus
// //
#define EFI_AGGREGATE_AUTH_STATUS_PLATFORM_OVERRIDE 0x000001 #define EFI_AGGREGATE_AUTH_STATUS_PLATFORM_OVERRIDE 0x000001
#define EFI_AGGREGATE_AUTH_STATUS_IMAGE_SIGNED 0x000002 #define EFI_AGGREGATE_AUTH_STATUS_IMAGE_SIGNED 0x000002
#define EFI_AGGREGATE_AUTH_STATUS_NOT_TESTED 0x000004 #define EFI_AGGREGATE_AUTH_STATUS_NOT_TESTED 0x000004
#define EFI_AGGREGATE_AUTH_STATUS_TEST_FAILED 0x000008 #define EFI_AGGREGATE_AUTH_STATUS_TEST_FAILED 0x000008
#define EFI_AGGREGATE_AUTH_STATUS_ALL 0x00000f #define EFI_AGGREGATE_AUTH_STATUS_ALL 0x00000f
#define EFI_LOCAL_AUTH_STATUS_PLATFORM_OVERRIDE 0x010000 #define EFI_LOCAL_AUTH_STATUS_PLATFORM_OVERRIDE 0x010000
#define EFI_LOCAL_AUTH_STATUS_IMAGE_SIGNED 0x020000 #define EFI_LOCAL_AUTH_STATUS_IMAGE_SIGNED 0x020000
#define EFI_LOCAL_AUTH_STATUS_NOT_TESTED 0x040000 #define EFI_LOCAL_AUTH_STATUS_NOT_TESTED 0x040000
#define EFI_LOCAL_AUTH_STATUS_TEST_FAILED 0x080000 #define EFI_LOCAL_AUTH_STATUS_TEST_FAILED 0x080000
#define EFI_LOCAL_AUTH_STATUS_ALL 0x0f0000 #define EFI_LOCAL_AUTH_STATUS_ALL 0x0f0000
#endif #endif

View File

@ -14,72 +14,72 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef __FRAMEWORK_INTERNAL_FORMREPRESENTATION_H__ #ifndef __FRAMEWORK_INTERNAL_FORMREPRESENTATION_H__
#define __FRAMEWORK_INTERNAL_FORMREPRESENTATION_H__ #define __FRAMEWORK_INTERNAL_FORMREPRESENTATION_H__
typedef UINT16 STRING_REF; typedef UINT16 STRING_REF;
// //
// IFR Op codes // IFR Op codes
// //
#define FRAMEWORK_EFI_IFR_FORM_OP 0x01 #define FRAMEWORK_EFI_IFR_FORM_OP 0x01
#define FRAMEWORK_EFI_IFR_SUBTITLE_OP 0x02 #define FRAMEWORK_EFI_IFR_SUBTITLE_OP 0x02
#define FRAMEWORK_EFI_IFR_TEXT_OP 0x03 #define FRAMEWORK_EFI_IFR_TEXT_OP 0x03
#define EFI_IFR_GRAPHIC_OP 0x04 #define EFI_IFR_GRAPHIC_OP 0x04
#define FRAMEWORK_EFI_IFR_ONE_OF_OP 0x05 #define FRAMEWORK_EFI_IFR_ONE_OF_OP 0x05
#define FRAMEWORK_EFI_IFR_CHECKBOX_OP 0x06 #define FRAMEWORK_EFI_IFR_CHECKBOX_OP 0x06
#define FRAMEWORK_EFI_IFR_NUMERIC_OP 0x07 #define FRAMEWORK_EFI_IFR_NUMERIC_OP 0x07
#define FRAMEWORK_EFI_IFR_PASSWORD_OP 0x08 #define FRAMEWORK_EFI_IFR_PASSWORD_OP 0x08
#define FRAMEWORK_EFI_IFR_ONE_OF_OPTION_OP 0x09 ///< ONEOF OPTION field. #define FRAMEWORK_EFI_IFR_ONE_OF_OPTION_OP 0x09 ///< ONEOF OPTION field.
#define FRAMEWORK_EFI_IFR_SUPPRESS_IF_OP 0x0A #define FRAMEWORK_EFI_IFR_SUPPRESS_IF_OP 0x0A
#define EFI_IFR_END_FORM_OP 0x0B #define EFI_IFR_END_FORM_OP 0x0B
#define EFI_IFR_HIDDEN_OP 0x0C #define EFI_IFR_HIDDEN_OP 0x0C
#define EFI_IFR_END_FORM_SET_OP 0x0D #define EFI_IFR_END_FORM_SET_OP 0x0D
#define FRAMEWORK_EFI_IFR_FORM_SET_OP 0x0E #define FRAMEWORK_EFI_IFR_FORM_SET_OP 0x0E
#define FRAMEWORK_EFI_IFR_REF_OP 0x0F #define FRAMEWORK_EFI_IFR_REF_OP 0x0F
#define EFI_IFR_END_ONE_OF_OP 0x10 #define EFI_IFR_END_ONE_OF_OP 0x10
#define FRAMEWORK_EFI_IFR_END_OP EFI_IFR_END_ONE_OF_OP #define FRAMEWORK_EFI_IFR_END_OP EFI_IFR_END_ONE_OF_OP
#define FRAMEWORK_EFI_IFR_INCONSISTENT_IF_OP 0x11 #define FRAMEWORK_EFI_IFR_INCONSISTENT_IF_OP 0x11
#define FRAMEWORK_EFI_IFR_EQ_ID_VAL_OP 0x12 #define FRAMEWORK_EFI_IFR_EQ_ID_VAL_OP 0x12
#define FRAMEWORK_EFI_IFR_EQ_ID_ID_OP 0x13 #define FRAMEWORK_EFI_IFR_EQ_ID_ID_OP 0x13
#define FRAMEWORK_EFI_IFR_EQ_ID_LIST_OP 0x14 #define FRAMEWORK_EFI_IFR_EQ_ID_LIST_OP 0x14
#define FRAMEWORK_EFI_IFR_AND_OP 0x15 #define FRAMEWORK_EFI_IFR_AND_OP 0x15
#define FRAMEWORK_EFI_IFR_OR_OP 0x16 #define FRAMEWORK_EFI_IFR_OR_OP 0x16
#define FRAMEWORK_EFI_IFR_NOT_OP 0x17 #define FRAMEWORK_EFI_IFR_NOT_OP 0x17
#define EFI_IFR_END_IF_OP 0x18 ///< For endif of inconsistentif, suppressif, grayoutif. #define EFI_IFR_END_IF_OP 0x18 ///< For endif of inconsistentif, suppressif, grayoutif.
#define EFI_IFR_GRAYOUT_IF_OP 0x19 #define EFI_IFR_GRAYOUT_IF_OP 0x19
#define FRAMEWORK_EFI_IFR_DATE_OP 0x1A #define FRAMEWORK_EFI_IFR_DATE_OP 0x1A
#define FRAMEWORK_EFI_IFR_TIME_OP 0x1B #define FRAMEWORK_EFI_IFR_TIME_OP 0x1B
#define FRAMEWORK_EFI_IFR_STRING_OP 0x1C #define FRAMEWORK_EFI_IFR_STRING_OP 0x1C
#define EFI_IFR_LABEL_OP 0x1D #define EFI_IFR_LABEL_OP 0x1D
#define EFI_IFR_SAVE_DEFAULTS_OP 0x1E #define EFI_IFR_SAVE_DEFAULTS_OP 0x1E
#define EFI_IFR_RESTORE_DEFAULTS_OP 0x1F #define EFI_IFR_RESTORE_DEFAULTS_OP 0x1F
#define EFI_IFR_BANNER_OP 0x20 #define EFI_IFR_BANNER_OP 0x20
#define EFI_IFR_INVENTORY_OP 0x21 #define EFI_IFR_INVENTORY_OP 0x21
#define EFI_IFR_EQ_VAR_VAL_OP 0x22 #define EFI_IFR_EQ_VAR_VAL_OP 0x22
#define FRAMEWORK_EFI_IFR_ORDERED_LIST_OP 0x23 #define FRAMEWORK_EFI_IFR_ORDERED_LIST_OP 0x23
#define FRAMEWORK_EFI_IFR_VARSTORE_OP 0x24 #define FRAMEWORK_EFI_IFR_VARSTORE_OP 0x24
#define EFI_IFR_VARSTORE_SELECT_OP 0x25 #define EFI_IFR_VARSTORE_SELECT_OP 0x25
#define EFI_IFR_VARSTORE_SELECT_PAIR_OP 0x26 #define EFI_IFR_VARSTORE_SELECT_PAIR_OP 0x26
#define EFI_IFR_LAST_OPCODE EFI_IFR_VARSTORE_SELECT_PAIR_OP #define EFI_IFR_LAST_OPCODE EFI_IFR_VARSTORE_SELECT_PAIR_OP
#define EFI_IFR_OEM_OP 0xFE #define EFI_IFR_OEM_OP 0xFE
#define EFI_IFR_NV_ACCESS_COMMAND 0xFF #define EFI_IFR_NV_ACCESS_COMMAND 0xFF
// //
// Define values for the flags fields in some VFR opcodes. These are // Define values for the flags fields in some VFR opcodes. These are
// bitmasks. // bitmasks.
// //
#define EFI_IFR_FLAG_DEFAULT 0x01 #define EFI_IFR_FLAG_DEFAULT 0x01
#define EFI_IFR_FLAG_MANUFACTURING 0x02 #define EFI_IFR_FLAG_MANUFACTURING 0x02
#define EFI_IFR_FLAG_INTERACTIVE 0x04 #define EFI_IFR_FLAG_INTERACTIVE 0x04
#define EFI_IFR_FLAG_NV_ACCESS 0x08 #define EFI_IFR_FLAG_NV_ACCESS 0x08
#define EFI_IFR_FLAG_RESET_REQUIRED 0x10 #define EFI_IFR_FLAG_RESET_REQUIRED 0x10
#define EFI_IFR_FLAG_LATE_CHECK 0x20 #define EFI_IFR_FLAG_LATE_CHECK 0x20
#define EFI_NON_DEVICE_CLASS 0x00 ///< Useful when you do not want something in the Device Manager. #define EFI_NON_DEVICE_CLASS 0x00 ///< Useful when you do not want something in the Device Manager.
#define EFI_DISK_DEVICE_CLASS 0x01 #define EFI_DISK_DEVICE_CLASS 0x01
#define EFI_VIDEO_DEVICE_CLASS 0x02 #define EFI_VIDEO_DEVICE_CLASS 0x02
#define EFI_NETWORK_DEVICE_CLASS 0x04 #define EFI_NETWORK_DEVICE_CLASS 0x04
#define EFI_INPUT_DEVICE_CLASS 0x08 #define EFI_INPUT_DEVICE_CLASS 0x08
#define EFI_ON_BOARD_DEVICE_CLASS 0x10 #define EFI_ON_BOARD_DEVICE_CLASS 0x10
#define EFI_OTHER_DEVICE_CLASS 0x20 #define EFI_OTHER_DEVICE_CLASS 0x20
#define EFI_SETUP_APPLICATION_SUBCLASS 0x00 #define EFI_SETUP_APPLICATION_SUBCLASS 0x00
#define EFI_GENERAL_APPLICATION_SUBCLASS 0x01 #define EFI_GENERAL_APPLICATION_SUBCLASS 0x01
@ -96,70 +96,69 @@ typedef UINT16 STRING_REF;
/// ///
#define EFI_IFR_FLAG_CREATED 128 #define EFI_IFR_FLAG_CREATED 128
#pragma pack(1) #pragma pack(1)
// //
// IFR Structure definitions // IFR Structure definitions
// //
typedef struct { typedef struct {
UINT8 OpCode; UINT8 OpCode;
UINT8 Length; UINT8 Length;
} FRAMEWORK_EFI_IFR_OP_HEADER; } FRAMEWORK_EFI_IFR_OP_HEADER;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
EFI_GUID Guid; EFI_GUID Guid;
STRING_REF FormSetTitle; STRING_REF FormSetTitle;
STRING_REF Help; STRING_REF Help;
EFI_PHYSICAL_ADDRESS CallbackHandle; EFI_PHYSICAL_ADDRESS CallbackHandle;
UINT16 Class; UINT16 Class;
UINT16 SubClass; UINT16 SubClass;
UINT16 NvDataSize; ///< Set once; the size of the NV data as defined in the script. UINT16 NvDataSize; ///< Set once; the size of the NV data as defined in the script.
} FRAMEWORK_EFI_IFR_FORM_SET; } FRAMEWORK_EFI_IFR_FORM_SET;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
UINT16 FormId; UINT16 FormId;
STRING_REF FormTitle; STRING_REF FormTitle;
} FRAMEWORK_EFI_IFR_FORM; } FRAMEWORK_EFI_IFR_FORM;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
UINT16 LabelId; UINT16 LabelId;
} EFI_IFR_LABEL; } EFI_IFR_LABEL;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
STRING_REF SubTitle; STRING_REF SubTitle;
} FRAMEWORK_EFI_IFR_SUBTITLE; } FRAMEWORK_EFI_IFR_SUBTITLE;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
STRING_REF Help; STRING_REF Help;
STRING_REF Text; STRING_REF Text;
STRING_REF TextTwo; STRING_REF TextTwo;
UINT8 Flags; ///< This is included solely for purposes of interactive/dynamic support. UINT8 Flags; ///< This is included solely for purposes of interactive/dynamic support.
UINT16 Key; ///< The value to be passed to the caller to identify this particular op-code. UINT16 Key; ///< The value to be passed to the caller to identify this particular op-code.
} FRAMEWORK_EFI_IFR_TEXT; } FRAMEWORK_EFI_IFR_TEXT;
// //
// goto // goto
// //
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
UINT16 FormId; UINT16 FormId;
STRING_REF Prompt; STRING_REF Prompt;
STRING_REF Help; ///< The string Token for the context-help. STRING_REF Help; ///< The string Token for the context-help.
UINT8 Flags; ///< This is included solely for purposes of interactive/dynamic support. UINT8 Flags; ///< This is included solely for purposes of interactive/dynamic support.
UINT16 Key; ///< The value to be passed to the caller to identify this particular op-code. UINT16 Key; ///< The value to be passed to the caller to identify this particular op-code.
} FRAMEWORK_EFI_IFR_REF; } FRAMEWORK_EFI_IFR_REF;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
} EFI_IFR_END_FORM; } EFI_IFR_END_FORM;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
} EFI_IFR_END_FORM_SET; } EFI_IFR_END_FORM_SET;
// //
@ -167,51 +166,51 @@ typedef struct {
// code assumes this to be true, if this ever changes we need to revisit the InitializeTagStructures code // code assumes this to be true, if this ever changes we need to revisit the InitializeTagStructures code
// //
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
UINT16 QuestionId; ///< The ID designating what the question is about... UINT16 QuestionId; ///< The ID designating what the question is about...
UINT8 Width; ///< The Size of the Data being saved. UINT8 Width; ///< The Size of the Data being saved.
STRING_REF Prompt; ///< The String Token for the Prompt. STRING_REF Prompt; ///< The String Token for the Prompt.
STRING_REF Help; ///< The string Token for the context-help. STRING_REF Help; ///< The string Token for the context-help.
} FRAMEWORK_EFI_IFR_ONE_OF; } FRAMEWORK_EFI_IFR_ONE_OF;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
UINT16 QuestionId; ///< The offset in NV for storage of the data. UINT16 QuestionId; ///< The offset in NV for storage of the data.
UINT8 MaxEntries; ///< The maximum number of options in the ordered list (=size of NVStore). UINT8 MaxEntries; ///< The maximum number of options in the ordered list (=size of NVStore).
STRING_REF Prompt; ///< The string token for the prompt. STRING_REF Prompt; ///< The string token for the prompt.
STRING_REF Help; ///< The string token for the context-help. STRING_REF Help; ///< The string token for the context-help.
} FRAMEWORK_EFI_IFR_ORDERED_LIST; } FRAMEWORK_EFI_IFR_ORDERED_LIST;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
UINT16 QuestionId; ///< The ID designating what the question is about... UINT16 QuestionId; ///< The ID designating what the question is about...
UINT8 Width; ///< The Size of the Data being saved. UINT8 Width; ///< The Size of the Data being saved.
STRING_REF Prompt; ///< The String Token for the Prompt. STRING_REF Prompt; ///< The String Token for the Prompt.
STRING_REF Help; ///< The string Token for the context-help. STRING_REF Help; ///< The string Token for the context-help.
UINT8 Flags; ///< If non-zero, it means that it is the default option. UINT8 Flags; ///< If non-zero, it means that it is the default option.
UINT16 Key; ///< Value to be passed to caller to identify this particular op-code. UINT16 Key; ///< Value to be passed to caller to identify this particular op-code.
} FRAMEWORK_EFI_IFR_CHECKBOX, EFI_IFR_CHECK_BOX; } FRAMEWORK_EFI_IFR_CHECKBOX, EFI_IFR_CHECK_BOX;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
STRING_REF Option; ///< The string token describing the option. STRING_REF Option; ///< The string token describing the option.
UINT16 Value; ///< The value associated with this option that is stored in the NVRAM. UINT16 Value; ///< The value associated with this option that is stored in the NVRAM.
UINT8 Flags; ///< If non-zero, it means that it is the default option. UINT8 Flags; ///< If non-zero, it means that it is the default option.
UINT16 Key; ///< Value to be passed to caller to identify this particular op-code. UINT16 Key; ///< Value to be passed to caller to identify this particular op-code.
} FRAMEWORK_EFI_IFR_ONE_OF_OPTION; } FRAMEWORK_EFI_IFR_ONE_OF_OPTION;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
UINT16 QuestionId; ///< The ID designating what the question is about... UINT16 QuestionId; ///< The ID designating what the question is about...
UINT8 Width; ///< The Size of the Data being saved. UINT8 Width; ///< The Size of the Data being saved.
STRING_REF Prompt; ///< The String Token for the Prompt. STRING_REF Prompt; ///< The String Token for the Prompt.
STRING_REF Help; ///< The string Token for the context-help. STRING_REF Help; ///< The string Token for the context-help.
UINT8 Flags; ///< This is included solely for purposes of interactive/dynamic support. UINT8 Flags; ///< This is included solely for purposes of interactive/dynamic support.
UINT16 Key; ///< The value to be passed to caller to identify this particular op-code. UINT16 Key; ///< The value to be passed to caller to identify this particular op-code.
UINT16 Minimum; UINT16 Minimum;
UINT16 Maximum; UINT16 Maximum;
UINT16 Step; ///< Zero means manual input. Otherwise, arrow selection is called for. UINT16 Step; ///< Zero means manual input. Otherwise, arrow selection is called for.
UINT16 Default; UINT16 Default;
} FRAMEWORK_EFI_IFR_NUMERIC; } FRAMEWORK_EFI_IFR_NUMERIC;
// //
@ -223,50 +222,50 @@ typedef struct {
// gRT->GetXXXX series of calls. // gRT->GetXXXX series of calls.
// //
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_NUMERIC Hour; FRAMEWORK_EFI_IFR_NUMERIC Hour;
FRAMEWORK_EFI_IFR_NUMERIC Minute; FRAMEWORK_EFI_IFR_NUMERIC Minute;
FRAMEWORK_EFI_IFR_NUMERIC Second; FRAMEWORK_EFI_IFR_NUMERIC Second;
} FRAMEWORK_EFI_IFR_TIME; } FRAMEWORK_EFI_IFR_TIME;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_NUMERIC Year; FRAMEWORK_EFI_IFR_NUMERIC Year;
FRAMEWORK_EFI_IFR_NUMERIC Month; FRAMEWORK_EFI_IFR_NUMERIC Month;
FRAMEWORK_EFI_IFR_NUMERIC Day; FRAMEWORK_EFI_IFR_NUMERIC Day;
} FRAMEWORK_EFI_IFR_DATE; } FRAMEWORK_EFI_IFR_DATE;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
UINT16 QuestionId;///< The ID designating what the question is about... UINT16 QuestionId; ///< The ID designating what the question is about...
UINT8 Width; ///< The Size of the Data being saved. UINT8 Width; ///< The Size of the Data being saved.
STRING_REF Prompt; ///< The String Token for the Prompt. STRING_REF Prompt; ///< The String Token for the Prompt.
STRING_REF Help; ///< The string Token for the context-help. STRING_REF Help; ///< The string Token for the context-help.
UINT8 Flags; ///< This is included solely for purposes of interactive/dynamic support. UINT8 Flags; ///< This is included solely for purposes of interactive/dynamic support.
UINT16 Key; ///< The value to be passed to caller to identify this particular op-code. UINT16 Key; ///< The value to be passed to caller to identify this particular op-code.
UINT8 MinSize; ///< Minimum allowable sized password. UINT8 MinSize; ///< Minimum allowable sized password.
UINT8 MaxSize; ///< Maximum allowable sized password. UINT8 MaxSize; ///< Maximum allowable sized password.
UINT16 Encoding; UINT16 Encoding;
} FRAMEWORK_EFI_IFR_PASSWORD; } FRAMEWORK_EFI_IFR_PASSWORD;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
UINT16 QuestionId; ///< The ID designating what the question is about... UINT16 QuestionId; ///< The ID designating what the question is about...
UINT8 Width; ///< The Size of the Data being saved. UINT8 Width; ///< The Size of the Data being saved.
STRING_REF Prompt; ///< The String Token for the Prompt. STRING_REF Prompt; ///< The String Token for the Prompt.
STRING_REF Help; ///< The string Token for the context-help. STRING_REF Help; ///< The string Token for the context-help.
UINT8 Flags; ///< This is included solely for purposes of interactive/dynamic support. UINT8 Flags; ///< This is included solely for purposes of interactive/dynamic support.
UINT16 Key; ///< The value to be passed to caller to identify this particular op-code. UINT16 Key; ///< The value to be passed to caller to identify this particular op-code.
UINT8 MinSize; ///< Minimum allowable sized password. UINT8 MinSize; ///< Minimum allowable sized password.
UINT8 MaxSize; ///< Maximum allowable sized password. UINT8 MaxSize; ///< Maximum allowable sized password.
} FRAMEWORK_EFI_IFR_STRING; } FRAMEWORK_EFI_IFR_STRING;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
} EFI_IFR_END_ONE_OF; } EFI_IFR_END_ONE_OF;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
UINT16 Value; UINT16 Value;
UINT16 Key; UINT16 Key;
} EFI_IFR_HIDDEN; } EFI_IFR_HIDDEN;
/// ///
@ -275,92 +274,92 @@ typedef struct {
/// keep the inconsistant is for implementation needed. /// keep the inconsistant is for implementation needed.
///@{ ///@{
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
UINT8 Flags; UINT8 Flags;
} EFI_IFR_SUPPRESS; } EFI_IFR_SUPPRESS;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
UINT8 Flags; UINT8 Flags;
} EFI_IFR_GRAY_OUT; } EFI_IFR_GRAY_OUT;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
STRING_REF Popup; STRING_REF Popup;
UINT8 Flags; UINT8 Flags;
} EFI_IFR_INCONSISTENT; } EFI_IFR_INCONSISTENT;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
UINT16 QuestionId; ///< The offset into variable storage. UINT16 QuestionId; ///< The offset into variable storage.
UINT8 Width; ///< The size of variable storage. UINT8 Width; ///< The size of variable storage.
UINT16 Value; ///< The value to compare against. UINT16 Value; ///< The value to compare against.
} FRAMEWORK_EFI_IFR_EQ_ID_VAL; } FRAMEWORK_EFI_IFR_EQ_ID_VAL;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
UINT16 QuestionId; ///< The offset into variable storage. UINT16 QuestionId; ///< The offset into variable storage.
UINT8 Width; ///< The size of variable storage. UINT8 Width; ///< The size of variable storage.
UINT16 ListLength; UINT16 ListLength;
UINT16 ValueList[1]; UINT16 ValueList[1];
} FRAMEWORK_EFI_IFR_EQ_ID_LIST; } FRAMEWORK_EFI_IFR_EQ_ID_LIST;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
UINT16 QuestionId1; ///< The offset into variable storage for first value to compare. UINT16 QuestionId1; ///< The offset into variable storage for first value to compare.
UINT8 Width; ///< The size of variable storage (must be same for both). UINT8 Width; ///< The size of variable storage (must be same for both).
UINT16 QuestionId2; ///< The offset into variable storage for second value to compare. UINT16 QuestionId2; ///< The offset into variable storage for second value to compare.
} FRAMEWORK_EFI_IFR_EQ_ID_ID; } FRAMEWORK_EFI_IFR_EQ_ID_ID;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
UINT16 VariableId; ///< The offset into variable storage. UINT16 VariableId; ///< The offset into variable storage.
UINT16 Value; ///< The value to compare against. UINT16 Value; ///< The value to compare against.
} EFI_IFR_EQ_VAR_VAL; } EFI_IFR_EQ_VAR_VAL;
///@} ///@}
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
} FRAMEWORK_EFI_IFR_AND; } FRAMEWORK_EFI_IFR_AND;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
} FRAMEWORK_EFI_IFR_OR; } FRAMEWORK_EFI_IFR_OR;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
} FRAMEWORK_EFI_IFR_NOT; } FRAMEWORK_EFI_IFR_NOT;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
} EFI_IFR_END_EXPR, EFI_IFR_END_IF; } EFI_IFR_END_EXPR, EFI_IFR_END_IF;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
UINT16 FormId; UINT16 FormId;
STRING_REF Prompt; STRING_REF Prompt;
STRING_REF Help; STRING_REF Help;
UINT8 Flags; UINT8 Flags;
UINT16 Key; UINT16 Key;
} EFI_IFR_SAVE_DEFAULTS; } EFI_IFR_SAVE_DEFAULTS;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
STRING_REF Help; STRING_REF Help;
STRING_REF Text; STRING_REF Text;
STRING_REF TextTwo; ///< Optional text. STRING_REF TextTwo; ///< Optional text.
} EFI_IFR_INVENTORY; } EFI_IFR_INVENTORY;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
EFI_GUID Guid; ///< GUID for the variable. EFI_GUID Guid; ///< GUID for the variable.
UINT16 VarId; ///< The variable store ID, as referenced elsewhere in the form. UINT16 VarId; ///< The variable store ID, as referenced elsewhere in the form.
UINT16 Size; ///< The size of the variable storage. UINT16 Size; ///< The size of the variable storage.
} FRAMEWORK_EFI_IFR_VARSTORE; } FRAMEWORK_EFI_IFR_VARSTORE;
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
UINT16 VarId; ///< The variable store ID, as referenced elsewhere in the form. UINT16 VarId; ///< The variable store ID, as referenced elsewhere in the form.
} EFI_IFR_VARSTORE_SELECT; } EFI_IFR_VARSTORE_SELECT;
/// ///
@ -370,9 +369,9 @@ typedef struct {
/// IFR opcodes use the VarId as defined here. /// IFR opcodes use the VarId as defined here.
/// ///
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
UINT16 VarId; ///< The variable store ID, as referenced elsewhere in the form. UINT16 VarId; ///< The variable store ID, as referenced elsewhere in the form.
UINT16 SecondaryVarId; ///< The variable store ID, as referenced elsewhere in the form. UINT16 SecondaryVarId; ///< The variable store ID, as referenced elsewhere in the form.
} EFI_IFR_VARSTORE_SELECT_PAIR; } EFI_IFR_VARSTORE_SELECT_PAIR;
/// ///
@ -381,16 +380,16 @@ typedef struct {
#define EFI_IFR_RESTORE_DEFAULTS EFI_IFR_SAVE_DEFAULTS #define EFI_IFR_RESTORE_DEFAULTS EFI_IFR_SAVE_DEFAULTS
typedef struct { typedef struct {
FRAMEWORK_EFI_IFR_OP_HEADER Header; FRAMEWORK_EFI_IFR_OP_HEADER Header;
STRING_REF Title; ///< The string token for the banner title. STRING_REF Title; ///< The string token for the banner title.
UINT16 LineNumber; ///< 1-based line number. UINT16 LineNumber; ///< 1-based line number.
UINT8 Alignment; ///< Left, center, or right-aligned. UINT8 Alignment; ///< Left, center, or right-aligned.
} EFI_IFR_BANNER; } EFI_IFR_BANNER;
#define EFI_IFR_BANNER_ALIGN_LEFT 0 #define EFI_IFR_BANNER_ALIGN_LEFT 0
#define EFI_IFR_BANNER_ALIGN_CENTER 1 #define EFI_IFR_BANNER_ALIGN_CENTER 1
#define EFI_IFR_BANNER_ALIGN_RIGHT 2 #define EFI_IFR_BANNER_ALIGN_RIGHT 2
#define EFI_IFR_BANNER_TIMEOUT 0xFF #define EFI_IFR_BANNER_TIMEOUT 0xFF
#pragma pack() #pragma pack()

View File

@ -17,12 +17,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
/// This macro is defined to comply with the hob Framework Spec. And the marco was /// This macro is defined to comply with the hob Framework Spec. And the marco was
/// retired in the PI1.0 specification. /// retired in the PI1.0 specification.
/// ///
#define EFI_HOB_TYPE_CV 0x0008 #define EFI_HOB_TYPE_CV 0x0008
typedef struct { typedef struct {
EFI_HOB_GENERIC_HEADER Header; EFI_HOB_GENERIC_HEADER Header;
EFI_PHYSICAL_ADDRESS BaseAddress; EFI_PHYSICAL_ADDRESS BaseAddress;
UINT64 Length; UINT64 Length;
} EFI_HOB_CAPSULE_VOLUME; } EFI_HOB_CAPSULE_VOLUME;
#endif #endif

View File

@ -26,8 +26,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
/// The Framework Specification, StatusCodes 0.92, does not define the macros. /// The Framework Specification, StatusCodes 0.92, does not define the macros.
/// ///
///@{ ///@{
#define EFI_SW_DXE_BS_PC_BEGIN_CONNECTING_DRIVERS (EFI_SUBCLASS_SPECIFIC | 0x00000005) #define EFI_SW_DXE_BS_PC_BEGIN_CONNECTING_DRIVERS (EFI_SUBCLASS_SPECIFIC | 0x00000005)
#define EFI_SW_DXE_BS_PC_VERIFYING_PASSWORD (EFI_SUBCLASS_SPECIFIC | 0x00000006) #define EFI_SW_DXE_BS_PC_VERIFYING_PASSWORD (EFI_SUBCLASS_SPECIFIC | 0x00000006)
///@} ///@}
/// ///
@ -37,12 +37,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
/// The Framework Specification, StatusCodes 0.92, does not define the macros. /// The Framework Specification, StatusCodes 0.92, does not define the macros.
/// ///
///@{ ///@{
#define EFI_SW_DXE_RT_PC_S0 (EFI_SUBCLASS_SPECIFIC | 0x00000000) #define EFI_SW_DXE_RT_PC_S0 (EFI_SUBCLASS_SPECIFIC | 0x00000000)
#define EFI_SW_DXE_RT_PC_S1 (EFI_SUBCLASS_SPECIFIC | 0x00000001) #define EFI_SW_DXE_RT_PC_S1 (EFI_SUBCLASS_SPECIFIC | 0x00000001)
#define EFI_SW_DXE_RT_PC_S2 (EFI_SUBCLASS_SPECIFIC | 0x00000002) #define EFI_SW_DXE_RT_PC_S2 (EFI_SUBCLASS_SPECIFIC | 0x00000002)
#define EFI_SW_DXE_RT_PC_S3 (EFI_SUBCLASS_SPECIFIC | 0x00000003) #define EFI_SW_DXE_RT_PC_S3 (EFI_SUBCLASS_SPECIFIC | 0x00000003)
#define EFI_SW_DXE_RT_PC_S4 (EFI_SUBCLASS_SPECIFIC | 0x00000004) #define EFI_SW_DXE_RT_PC_S4 (EFI_SUBCLASS_SPECIFIC | 0x00000004)
#define EFI_SW_DXE_RT_PC_S5 (EFI_SUBCLASS_SPECIFIC | 0x00000005) #define EFI_SW_DXE_RT_PC_S5 (EFI_SUBCLASS_SPECIFIC | 0x00000005)
///@} ///@}
/// ///
@ -51,7 +51,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
/// Inconsistent with specification here: /// Inconsistent with specification here:
/// The Framework Specification, StatusCodes 0.92, does not define the macros. /// The Framework Specification, StatusCodes 0.92, does not define the macros.
/// ///
#define EFI_SOFTWARE_X64_EXCEPTION (EFI_SOFTWARE | 0x00130000) #define EFI_SOFTWARE_X64_EXCEPTION (EFI_SOFTWARE | 0x00130000)
/// ///
/// Software Class X64 Exception Subclass Error Code definitions. /// Software Class X64 Exception Subclass Error Code definitions.
@ -62,31 +62,31 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
/// The Framework Specification, StatusCodes 0.92, does not define the macros. /// The Framework Specification, StatusCodes 0.92, does not define the macros.
/// ///
///@{ ///@{
#define EFI_SW_EC_X64_DIVIDE_ERROR EXCEPT_X64_DIVIDE_ERROR #define EFI_SW_EC_X64_DIVIDE_ERROR EXCEPT_X64_DIVIDE_ERROR
#define EFI_SW_EC_X64_DEBUG EXCEPT_X64_DEBUG #define EFI_SW_EC_X64_DEBUG EXCEPT_X64_DEBUG
#define EFI_SW_EC_X64_NMI EXCEPT_X64_NMI #define EFI_SW_EC_X64_NMI EXCEPT_X64_NMI
#define EFI_SW_EC_X64_BREAKPOINT EXCEPT_X64_BREAKPOINT #define EFI_SW_EC_X64_BREAKPOINT EXCEPT_X64_BREAKPOINT
#define EFI_SW_EC_X64_OVERFLOW EXCEPT_X64_OVERFLOW #define EFI_SW_EC_X64_OVERFLOW EXCEPT_X64_OVERFLOW
#define EFI_SW_EC_X64_BOUND EXCEPT_X64_BOUND #define EFI_SW_EC_X64_BOUND EXCEPT_X64_BOUND
#define EFI_SW_EC_X64_INVALID_OPCODE EXCEPT_X64_INVALID_OPCODE #define EFI_SW_EC_X64_INVALID_OPCODE EXCEPT_X64_INVALID_OPCODE
#define EFI_SW_EC_X64_DOUBLE_FAULT EXCEPT_X64_DOUBLE_FAULT #define EFI_SW_EC_X64_DOUBLE_FAULT EXCEPT_X64_DOUBLE_FAULT
#define EFI_SW_EC_X64_INVALID_TSS EXCEPT_X64_INVALID_TSS #define EFI_SW_EC_X64_INVALID_TSS EXCEPT_X64_INVALID_TSS
#define EFI_SW_EC_X64_SEG_NOT_PRESENT EXCEPT_X64_SEG_NOT_PRESENT #define EFI_SW_EC_X64_SEG_NOT_PRESENT EXCEPT_X64_SEG_NOT_PRESENT
#define EFI_SW_EC_X64_STACK_FAULT EXCEPT_X64_STACK_FAULT #define EFI_SW_EC_X64_STACK_FAULT EXCEPT_X64_STACK_FAULT
#define EFI_SW_EC_X64_GP_FAULT EXCEPT_X64_GP_FAULT #define EFI_SW_EC_X64_GP_FAULT EXCEPT_X64_GP_FAULT
#define EFI_SW_EC_X64_PAGE_FAULT EXCEPT_X64_PAGE_FAULT #define EFI_SW_EC_X64_PAGE_FAULT EXCEPT_X64_PAGE_FAULT
#define EFI_SW_EC_X64_FP_ERROR EXCEPT_X64_FP_ERROR #define EFI_SW_EC_X64_FP_ERROR EXCEPT_X64_FP_ERROR
#define EFI_SW_EC_X64_ALIGNMENT_CHECK EXCEPT_X64_ALIGNMENT_CHECK #define EFI_SW_EC_X64_ALIGNMENT_CHECK EXCEPT_X64_ALIGNMENT_CHECK
#define EFI_SW_EC_X64_MACHINE_CHECK EXCEPT_X64_MACHINE_CHECK #define EFI_SW_EC_X64_MACHINE_CHECK EXCEPT_X64_MACHINE_CHECK
#define EFI_SW_EC_X64_SIMD EXCEPT_X64_SIMD #define EFI_SW_EC_X64_SIMD EXCEPT_X64_SIMD
///@} ///@}
/// ///
/// Software Class EFI After Life Subclass Progress Code definitions. /// Software Class EFI After Life Subclass Progress Code definitions.
/// ///
///@{ ///@{
#define EFI_SW_AL_PC_ENTRY_POINT (EFI_SUBCLASS_SPECIFIC | 0x00000000) #define EFI_SW_AL_PC_ENTRY_POINT (EFI_SUBCLASS_SPECIFIC | 0x00000000)
#define EFI_SW_AL_PC_RETURN_TO_LAST (EFI_SUBCLASS_SPECIFIC | 0x00000001) #define EFI_SW_AL_PC_RETURN_TO_LAST (EFI_SUBCLASS_SPECIFIC | 0x00000001)
///@} ///@}
/// ///
@ -95,7 +95,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
/// Inconsistent with specification here: /// Inconsistent with specification here:
/// The Framework Specification, StatusCodes 0.92, does not define the macros. /// The Framework Specification, StatusCodes 0.92, does not define the macros.
/// ///
#define EFI_SW_CSM_LEGACY_ROM_INIT (EFI_SUBCLASS_SPECIFIC | 0x00000000) #define EFI_SW_CSM_LEGACY_ROM_INIT (EFI_SUBCLASS_SPECIFIC | 0x00000000)
/// ///
/// IO Bus Class ATA/ATAPI Subclass Progress Code definitions. /// IO Bus Class ATA/ATAPI Subclass Progress Code definitions.
@ -130,7 +130,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
/// The Framework Specification, StatusCodes 0.92, does not define the macros. /// The Framework Specification, StatusCodes 0.92, does not define the macros.
/// ///
///@{ ///@{
#define EFI_CPU_CAUSE_NOT_DISABLED 0x0000 #define EFI_CPU_CAUSE_NOT_DISABLED 0x0000
///@} ///@}
/// ///

View File

@ -24,6 +24,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
0x2e3044ac, 0x879f, 0x490f, {0x97, 0x60, 0xbb, 0xdf, 0xaf, 0x69, 0x5f, 0x50 } \ 0x2e3044ac, 0x879f, 0x490f, {0x97, 0x60, 0xbb, 0xdf, 0xaf, 0x69, 0x5f, 0x50 } \
} }
extern EFI_GUID gEfiLegacyBiosGuid; extern EFI_GUID gEfiLegacyBiosGuid;
#endif #endif

View File

@ -23,17 +23,17 @@ typedef UINT8 BBS_TYPE;
#pragma pack(1) #pragma pack(1)
typedef struct { typedef struct {
BBS_TYPE BbsType; BBS_TYPE BbsType;
/// ///
/// Length = sizeof (UINT16) + sizeof (Data) /// Length = sizeof (UINT16) + sizeof (Data)
/// ///
UINT16 Length; UINT16 Length;
UINT16 Data[1]; UINT16 Data[1];
} LEGACY_DEV_ORDER_ENTRY; } LEGACY_DEV_ORDER_ENTRY;
#pragma pack() #pragma pack()
#define VAR_LEGACY_DEV_ORDER L"LegacyDevOrder" #define VAR_LEGACY_DEV_ORDER L"LegacyDevOrder"
extern EFI_GUID gEfiLegacyDevOrderVariableGuid; extern EFI_GUID gEfiLegacyDevOrderVariableGuid;
#endif #endif

View File

@ -19,7 +19,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef _FIRMWARE_VOLUME_H_ #ifndef _FIRMWARE_VOLUME_H_
#define _FIRMWARE_VOLUME_H_ #define _FIRMWARE_VOLUME_H_
// //
// Firmware Volume Protocol GUID definition // Firmware Volume Protocol GUID definition
// //
@ -28,49 +27,49 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
0x389F751F, 0x1838, 0x4388, {0x83, 0x90, 0xCD, 0x81, 0x54, 0xBD, 0x27, 0xF8 } \ 0x389F751F, 0x1838, 0x4388, {0x83, 0x90, 0xCD, 0x81, 0x54, 0xBD, 0x27, 0xF8 } \
} }
#define FV_DEVICE_SIGNATURE SIGNATURE_32 ('_', 'F', 'V', '_') #define FV_DEVICE_SIGNATURE SIGNATURE_32 ('_', 'F', 'V', '_')
typedef struct _EFI_FIRMWARE_VOLUME_PROTOCOL EFI_FIRMWARE_VOLUME_PROTOCOL; typedef struct _EFI_FIRMWARE_VOLUME_PROTOCOL EFI_FIRMWARE_VOLUME_PROTOCOL;
// //
// FRAMEWORK_EFI_FV_ATTRIBUTES bit definitions // FRAMEWORK_EFI_FV_ATTRIBUTES bit definitions
// //
typedef UINT64 FRAMEWORK_EFI_FV_ATTRIBUTES; typedef UINT64 FRAMEWORK_EFI_FV_ATTRIBUTES;
// //
// ************************************************************ // ************************************************************
// FRAMEWORK_EFI_FV_ATTRIBUTES bit definitions // FRAMEWORK_EFI_FV_ATTRIBUTES bit definitions
// ************************************************************ // ************************************************************
// //
#define EFI_FV_READ_DISABLE_CAP 0x0000000000000001ULL #define EFI_FV_READ_DISABLE_CAP 0x0000000000000001ULL
#define EFI_FV_READ_ENABLE_CAP 0x0000000000000002ULL #define EFI_FV_READ_ENABLE_CAP 0x0000000000000002ULL
#define EFI_FV_READ_STATUS 0x0000000000000004ULL #define EFI_FV_READ_STATUS 0x0000000000000004ULL
#define EFI_FV_WRITE_DISABLE_CAP 0x0000000000000008ULL #define EFI_FV_WRITE_DISABLE_CAP 0x0000000000000008ULL
#define EFI_FV_WRITE_ENABLE_CAP 0x0000000000000010ULL #define EFI_FV_WRITE_ENABLE_CAP 0x0000000000000010ULL
#define EFI_FV_WRITE_STATUS 0x0000000000000020ULL #define EFI_FV_WRITE_STATUS 0x0000000000000020ULL
#define EFI_FV_LOCK_CAP 0x0000000000000040ULL #define EFI_FV_LOCK_CAP 0x0000000000000040ULL
#define EFI_FV_LOCK_STATUS 0x0000000000000080ULL #define EFI_FV_LOCK_STATUS 0x0000000000000080ULL
#define EFI_FV_WRITE_POLICY_RELIABLE 0x0000000000000100ULL #define EFI_FV_WRITE_POLICY_RELIABLE 0x0000000000000100ULL
#define EFI_FV_ALIGNMENT_CAP 0x0000000000008000ULL #define EFI_FV_ALIGNMENT_CAP 0x0000000000008000ULL
#define EFI_FV_ALIGNMENT_2 0x0000000000010000ULL #define EFI_FV_ALIGNMENT_2 0x0000000000010000ULL
#define EFI_FV_ALIGNMENT_4 0x0000000000020000ULL #define EFI_FV_ALIGNMENT_4 0x0000000000020000ULL
#define EFI_FV_ALIGNMENT_8 0x0000000000040000ULL #define EFI_FV_ALIGNMENT_8 0x0000000000040000ULL
#define EFI_FV_ALIGNMENT_16 0x0000000000080000ULL #define EFI_FV_ALIGNMENT_16 0x0000000000080000ULL
#define EFI_FV_ALIGNMENT_32 0x0000000000100000ULL #define EFI_FV_ALIGNMENT_32 0x0000000000100000ULL
#define EFI_FV_ALIGNMENT_64 0x0000000000200000ULL #define EFI_FV_ALIGNMENT_64 0x0000000000200000ULL
#define EFI_FV_ALIGNMENT_128 0x0000000000400000ULL #define EFI_FV_ALIGNMENT_128 0x0000000000400000ULL
#define EFI_FV_ALIGNMENT_256 0x0000000000800000ULL #define EFI_FV_ALIGNMENT_256 0x0000000000800000ULL
#define EFI_FV_ALIGNMENT_512 0x0000000001000000ULL #define EFI_FV_ALIGNMENT_512 0x0000000001000000ULL
#define EFI_FV_ALIGNMENT_1K 0x0000000002000000ULL #define EFI_FV_ALIGNMENT_1K 0x0000000002000000ULL
#define EFI_FV_ALIGNMENT_2K 0x0000000004000000ULL #define EFI_FV_ALIGNMENT_2K 0x0000000004000000ULL
#define EFI_FV_ALIGNMENT_4K 0x0000000008000000ULL #define EFI_FV_ALIGNMENT_4K 0x0000000008000000ULL
#define EFI_FV_ALIGNMENT_8K 0x0000000010000000ULL #define EFI_FV_ALIGNMENT_8K 0x0000000010000000ULL
#define EFI_FV_ALIGNMENT_16K 0x0000000020000000ULL #define EFI_FV_ALIGNMENT_16K 0x0000000020000000ULL
#define EFI_FV_ALIGNMENT_32K 0x0000000040000000ULL #define EFI_FV_ALIGNMENT_32K 0x0000000040000000ULL
#define EFI_FV_ALIGNMENT_64K 0x0000000080000000ULL #define EFI_FV_ALIGNMENT_64K 0x0000000080000000ULL
// //
// Protocol API definitions // Protocol API definitions
@ -210,17 +209,17 @@ EFI_STATUS
OUT UINT32 *AuthenticationStatus OUT UINT32 *AuthenticationStatus
); );
typedef UINT32 FRAMEWORK_EFI_FV_WRITE_POLICY; typedef UINT32 FRAMEWORK_EFI_FV_WRITE_POLICY;
#define FRAMEWORK_EFI_FV_UNRELIABLE_WRITE 0x00000000 #define FRAMEWORK_EFI_FV_UNRELIABLE_WRITE 0x00000000
#define FRAMEWORK_EFI_FV_RELIABLE_WRITE 0x00000001 #define FRAMEWORK_EFI_FV_RELIABLE_WRITE 0x00000001
typedef struct { typedef struct {
EFI_GUID *NameGuid; EFI_GUID *NameGuid;
EFI_FV_FILETYPE Type; EFI_FV_FILETYPE Type;
EFI_FV_FILE_ATTRIBUTES FileAttributes; EFI_FV_FILE_ATTRIBUTES FileAttributes;
VOID *Buffer; VOID *Buffer;
UINT32 BufferSize; UINT32 BufferSize;
} FRAMEWORK_EFI_FV_WRITE_FILE_DATA; } FRAMEWORK_EFI_FV_WRITE_FILE_DATA;
/** /**
@ -296,45 +295,45 @@ struct _EFI_FIRMWARE_VOLUME_PROTOCOL {
/// ///
/// Retrieves volume capabilities and current settings. /// Retrieves volume capabilities and current settings.
/// ///
FRAMEWORK_EFI_FV_GET_ATTRIBUTES GetVolumeAttributes; FRAMEWORK_EFI_FV_GET_ATTRIBUTES GetVolumeAttributes;
/// ///
/// Modifies the current settings of the firmware volume. /// Modifies the current settings of the firmware volume.
/// ///
FRAMEWORK_EFI_FV_SET_ATTRIBUTES SetVolumeAttributes; FRAMEWORK_EFI_FV_SET_ATTRIBUTES SetVolumeAttributes;
/// ///
/// Reads an entire file from the firmware volume. /// Reads an entire file from the firmware volume.
/// ///
FRAMEWORK_EFI_FV_READ_FILE ReadFile; FRAMEWORK_EFI_FV_READ_FILE ReadFile;
/// ///
/// Reads a single section from a file into a buffer. /// Reads a single section from a file into a buffer.
/// ///
FRAMEWORK_EFI_FV_READ_SECTION ReadSection; FRAMEWORK_EFI_FV_READ_SECTION ReadSection;
/// ///
/// Writes an entire file into the firmware volume. /// Writes an entire file into the firmware volume.
/// ///
FRAMEWORK_EFI_FV_WRITE_FILE WriteFile; FRAMEWORK_EFI_FV_WRITE_FILE WriteFile;
/// ///
/// Provides service to allow searching the firmware volume. /// Provides service to allow searching the firmware volume.
/// ///
FRAMEWORK_EFI_FV_GET_NEXT_FILE GetNextFile; FRAMEWORK_EFI_FV_GET_NEXT_FILE GetNextFile;
/// ///
/// Data field that indicates the size in bytes of the Key input buffer for /// Data field that indicates the size in bytes of the Key input buffer for
/// the GetNextFile() API. /// the GetNextFile() API.
/// ///
UINT32 KeySize; UINT32 KeySize;
/// ///
/// Handle of the parent firmware volume. /// Handle of the parent firmware volume.
/// ///
EFI_HANDLE ParentHandle; EFI_HANDLE ParentHandle;
}; };
extern EFI_GUID gEfiFirmwareVolumeProtocolGuid; extern EFI_GUID gEfiFirmwareVolumeProtocolGuid;
#endif #endif

View File

@ -49,20 +49,20 @@ typedef struct _EFI_ISA_ACPI_PROTOCOL EFI_ISA_ACPI_PROTOCOL;
/// ///
/// ISA ACPI Protocol MMIO resource attributes /// ISA ACPI Protocol MMIO resource attributes
/// ///
#define EFI_ISA_ACPI_MEMORY_WIDTH_MASK 0x03 ///< Bit mask of supported ISA memory width attributes. #define EFI_ISA_ACPI_MEMORY_WIDTH_MASK 0x03 ///< Bit mask of supported ISA memory width attributes.
#define EFI_ISA_ACPI_MEMORY_WIDTH_8_BIT 0x00 ///< ISA MMIO region only supports 8-bit access. #define EFI_ISA_ACPI_MEMORY_WIDTH_8_BIT 0x00 ///< ISA MMIO region only supports 8-bit access.
#define EFI_ISA_ACPI_MEMORY_WIDTH_16_BIT 0x01 ///< ISA MMIO region only supports 16-bit access. #define EFI_ISA_ACPI_MEMORY_WIDTH_16_BIT 0x01 ///< ISA MMIO region only supports 16-bit access.
#define EFI_ISA_ACPI_MEMORY_WIDTH_8_BIT_AND_16_BIT 0x02 ///< ISA MMIO region supports both 8-bit and 16-bit access. #define EFI_ISA_ACPI_MEMORY_WIDTH_8_BIT_AND_16_BIT 0x02 ///< ISA MMIO region supports both 8-bit and 16-bit access.
#define EFI_ISA_ACPI_MEMORY_WRITEABLE 0x04 ///< ISA MMIO region supports write transactions. #define EFI_ISA_ACPI_MEMORY_WRITEABLE 0x04 ///< ISA MMIO region supports write transactions.
#define EFI_ISA_ACPI_MEMORY_CACHEABLE 0x08 ///< ISA MMIO region supports being cached. #define EFI_ISA_ACPI_MEMORY_CACHEABLE 0x08 ///< ISA MMIO region supports being cached.
#define EFI_ISA_ACPI_MEMORY_SHADOWABLE 0x10 ///< ISA MMIO region may be shadowed. #define EFI_ISA_ACPI_MEMORY_SHADOWABLE 0x10 ///< ISA MMIO region may be shadowed.
#define EFI_ISA_ACPI_MEMORY_EXPANSION_ROM 0x20 ///< ISA MMIO region is an expansion ROM. #define EFI_ISA_ACPI_MEMORY_EXPANSION_ROM 0x20 ///< ISA MMIO region is an expansion ROM.
/// ///
/// ISA ACPI Protocol I/O resource attributes /// ISA ACPI Protocol I/O resource attributes
/// ///
#define EFI_ISA_ACPI_IO_DECODE_10_BITS 0x01 ///< ISA controllers uses a 10-bit address decoder for I/O cycles. #define EFI_ISA_ACPI_IO_DECODE_10_BITS 0x01 ///< ISA controllers uses a 10-bit address decoder for I/O cycles.
#define EFI_ISA_ACPI_IO_DECODE_16_BITS 0x02 ///< ISA controllers uses a 16-bit address decoder for I/O cycles. #define EFI_ISA_ACPI_IO_DECODE_16_BITS 0x02 ///< ISA controllers uses a 16-bit address decoder for I/O cycles.
/// ///
/// EFI ISA ACPI resource type /// EFI ISA ACPI resource type
@ -79,26 +79,26 @@ typedef enum {
/// EFI ISA ACPI generic resource structure /// EFI ISA ACPI generic resource structure
/// ///
typedef struct { typedef struct {
EFI_ISA_ACPI_RESOURCE_TYPE Type; ///< The type of resource (I/O, MMIO, DMA, Interrupt). EFI_ISA_ACPI_RESOURCE_TYPE Type; ///< The type of resource (I/O, MMIO, DMA, Interrupt).
UINT32 Attribute; ///< Bit mask of attributes associated with this resource. See EFI_ISA_ACPI_xxx macros for valid combinations. UINT32 Attribute; ///< Bit mask of attributes associated with this resource. See EFI_ISA_ACPI_xxx macros for valid combinations.
UINT32 StartRange; ///< The start of the resource range. UINT32 StartRange; ///< The start of the resource range.
UINT32 EndRange; ///< The end of the resource range. UINT32 EndRange; ///< The end of the resource range.
} EFI_ISA_ACPI_RESOURCE; } EFI_ISA_ACPI_RESOURCE;
/// ///
/// EFI ISA ACPI resource device identifier /// EFI ISA ACPI resource device identifier
/// ///
typedef struct { typedef struct {
UINT32 HID; ///< The ACPI Hardware Identifier value associated with an ISA controller. Matchs ACPI DSDT contents. UINT32 HID; ///< The ACPI Hardware Identifier value associated with an ISA controller. Matchs ACPI DSDT contents.
UINT32 UID; ///< The ACPI Unique Identifier value associated with an ISA controller. Matches ACPI DSDT contents. UINT32 UID; ///< The ACPI Unique Identifier value associated with an ISA controller. Matches ACPI DSDT contents.
} EFI_ISA_ACPI_DEVICE_ID; } EFI_ISA_ACPI_DEVICE_ID;
/// ///
/// EFI ISA ACPI resource list /// EFI ISA ACPI resource list
/// ///
typedef struct { typedef struct {
EFI_ISA_ACPI_DEVICE_ID Device; ///< The ACPI HID/UID associated with an ISA controller. EFI_ISA_ACPI_DEVICE_ID Device; ///< The ACPI HID/UID associated with an ISA controller.
EFI_ISA_ACPI_RESOURCE *ResourceItem; ///< A pointer to the list of resources associated with an ISA controller. EFI_ISA_ACPI_RESOURCE *ResourceItem; ///< A pointer to the list of resources associated with an ISA controller.
} EFI_ISA_ACPI_RESOURCE_LIST; } EFI_ISA_ACPI_RESOURCE_LIST;
/** /**
@ -283,16 +283,16 @@ EFI_STATUS
/// and assign resources to an ISA controller. /// and assign resources to an ISA controller.
/// ///
struct _EFI_ISA_ACPI_PROTOCOL { struct _EFI_ISA_ACPI_PROTOCOL {
EFI_ISA_ACPI_DEVICE_ENUMERATE DeviceEnumerate; EFI_ISA_ACPI_DEVICE_ENUMERATE DeviceEnumerate;
EFI_ISA_ACPI_SET_DEVICE_POWER SetPower; EFI_ISA_ACPI_SET_DEVICE_POWER SetPower;
EFI_ISA_ACPI_GET_CUR_RESOURCE GetCurResource; EFI_ISA_ACPI_GET_CUR_RESOURCE GetCurResource;
EFI_ISA_ACPI_GET_POS_RESOURCE GetPosResource; EFI_ISA_ACPI_GET_POS_RESOURCE GetPosResource;
EFI_ISA_ACPI_SET_RESOURCE SetResource; EFI_ISA_ACPI_SET_RESOURCE SetResource;
EFI_ISA_ACPI_ENABLE_DEVICE EnableDevice; EFI_ISA_ACPI_ENABLE_DEVICE EnableDevice;
EFI_ISA_ACPI_INIT_DEVICE InitDevice; EFI_ISA_ACPI_INIT_DEVICE InitDevice;
EFI_ISA_ACPI_INTERFACE_INIT InterfaceInit; EFI_ISA_ACPI_INTERFACE_INIT InterfaceInit;
}; };
extern EFI_GUID gEfiIsaAcpiProtocolGuid; extern EFI_GUID gEfiIsaAcpiProtocolGuid;
#endif #endif

View File

@ -128,11 +128,11 @@ typedef struct {
/// ///
/// Read from ISA I/O or MMIO space. /// Read from ISA I/O or MMIO space.
/// ///
EFI_ISA_IO_PROTOCOL_IO_MEM Read; EFI_ISA_IO_PROTOCOL_IO_MEM Read;
/// ///
/// Write to ISA I/O or MMIO space. /// Write to ISA I/O or MMIO space.
/// ///
EFI_ISA_IO_PROTOCOL_IO_MEM Write; EFI_ISA_IO_PROTOCOL_IO_MEM Write;
} EFI_ISA_IO_PROTOCOL_ACCESS; } EFI_ISA_IO_PROTOCOL_ACCESS;
/** /**
@ -326,31 +326,31 @@ EFI_STATUS
/// ISA_PCI_IO_PROTOCOL instance associated with the ISA controller. /// ISA_PCI_IO_PROTOCOL instance associated with the ISA controller.
/// ///
struct _EFI_ISA_IO_PROTOCOL { struct _EFI_ISA_IO_PROTOCOL {
EFI_ISA_IO_PROTOCOL_ACCESS Mem; EFI_ISA_IO_PROTOCOL_ACCESS Mem;
EFI_ISA_IO_PROTOCOL_ACCESS Io; EFI_ISA_IO_PROTOCOL_ACCESS Io;
EFI_ISA_IO_PROTOCOL_COPY_MEM CopyMem; EFI_ISA_IO_PROTOCOL_COPY_MEM CopyMem;
EFI_ISA_IO_PROTOCOL_MAP Map; EFI_ISA_IO_PROTOCOL_MAP Map;
EFI_ISA_IO_PROTOCOL_UNMAP Unmap; EFI_ISA_IO_PROTOCOL_UNMAP Unmap;
EFI_ISA_IO_PROTOCOL_ALLOCATE_BUFFER AllocateBuffer; EFI_ISA_IO_PROTOCOL_ALLOCATE_BUFFER AllocateBuffer;
EFI_ISA_IO_PROTOCOL_FREE_BUFFER FreeBuffer; EFI_ISA_IO_PROTOCOL_FREE_BUFFER FreeBuffer;
EFI_ISA_IO_PROTOCOL_FLUSH Flush; EFI_ISA_IO_PROTOCOL_FLUSH Flush;
/// ///
/// The list of I/O , MMIO, DMA, and Interrupt resources associated with the /// The list of I/O , MMIO, DMA, and Interrupt resources associated with the
/// ISA controller abstracted by this instance of the EFI_ISA_IO_PROTOCOL. /// ISA controller abstracted by this instance of the EFI_ISA_IO_PROTOCOL.
/// ///
EFI_ISA_ACPI_RESOURCE_LIST *ResourceList; EFI_ISA_ACPI_RESOURCE_LIST *ResourceList;
/// ///
/// The size, in bytes, of the ROM image. /// The size, in bytes, of the ROM image.
/// ///
UINT32 RomSize; UINT32 RomSize;
/// ///
/// A pointer to the in memory copy of the ROM image. The ISA Bus Driver is responsible /// A pointer to the in memory copy of the ROM image. The ISA Bus Driver is responsible
/// for allocating memory for the ROM image, and copying the contents of the ROM to memory /// for allocating memory for the ROM image, and copying the contents of the ROM to memory
/// during ISA Bus initialization. /// during ISA Bus initialization.
/// ///
VOID *RomImage; VOID *RomImage;
}; };
extern EFI_GUID gEfiIsaIoProtocolGuid; extern EFI_GUID gEfiIsaIoProtocolGuid;
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -66,7 +66,7 @@ typedef enum {
/// ///
/// EFI_UNSUPPORTED The MP table is not supported on this platform. /// EFI_UNSUPPORTED The MP table is not supported on this platform.
/// ///
EfiGetPlatformBinaryMpTable = 0, EfiGetPlatformBinaryMpTable = 0,
/// ///
/// This mode returns a block of data. The content and usage is IBV or OEM defined. /// This mode returns a block of data. The content and usage is IBV or OEM defined.
/// OEMs or IBVs normally use this function for nonstandard Compatibility16 runtime soft /// OEMs or IBVs normally use this function for nonstandard Compatibility16 runtime soft
@ -104,7 +104,7 @@ typedef enum {
/// ///
/// EFI_UNSUPPORTED Oem INT is not supported on this platform. /// EFI_UNSUPPORTED Oem INT is not supported on this platform.
/// ///
EfiGetPlatformBinaryOemIntData = 1, EfiGetPlatformBinaryOemIntData = 1,
/// ///
/// This mode returns a block of data. The content and usage is IBV defined. OEMs or /// This mode returns a block of data. The content and usage is IBV defined. OEMs or
/// IBVs normally use this mode for nonstandard Compatibility16 runtime 16 bit routines. It /// IBVs normally use this mode for nonstandard Compatibility16 runtime 16 bit routines. It
@ -146,57 +146,57 @@ typedef enum {
/// ///
/// EFI_UNSUPPORTED Oem16 is not supported on this platform. /// EFI_UNSUPPORTED Oem16 is not supported on this platform.
/// ///
EfiGetPlatformBinaryOem16Data = 2, EfiGetPlatformBinaryOem16Data = 2,
/// ///
/// This mode returns a block of data. The content and usage are IBV defined. OEMs or /// This mode returns a block of data. The content and usage are IBV defined. OEMs or
/// IBVs normally use this mode for nonstandard Compatibility16 runtime 32 bit routines. It /// IBVs normally use this mode for nonstandard Compatibility16 runtime 32 bit routines. It
/// is the responsibility of this routine to coalesce multiple OEM 32 bit functions, if they /// is the responsibility of this routine to coalesce multiple OEM 32 bit functions, if they
/// exist, into one coherent package that is understandable by the Compatibility16 code. /// exist, into one coherent package that is understandable by the Compatibility16 code.
/// ///
/// Example usage: A legacy mobile BIOS that has a pre existing runtime /// Example usage: A legacy mobile BIOS that has a pre existing runtime
/// interface to return the battery status to calling applications. /// interface to return the battery status to calling applications.
/// ///
/// This mode is invoked twice. The first invocation has LegacySegment and /// This mode is invoked twice. The first invocation has LegacySegment and
/// LegacyOffset set to 0. The mode returns the table address in EFI memory and its size. /// LegacyOffset set to 0. The mode returns the table address in EFI memory and its size.
/// ///
/// The second invocation has LegacySegment and LegacyOffset set to the location /// The second invocation has LegacySegment and LegacyOffset set to the location
/// in the 0xF0000 or 0xE0000 block to which the table is to be copied. The second /// in the 0xF0000 or 0xE0000 block to which the table is to be copied. The second
/// invocation allows any table address fix ups to occur in the EFI memory copy of the table. /// invocation allows any table address fix ups to occur in the EFI memory copy of the table.
/// The caller, not EfiGetPlatformBinaryOem32Data, copies the modified table to /// The caller, not EfiGetPlatformBinaryOem32Data, copies the modified table to
/// the allocated region in 0xF0000 or 0xE0000 block after the second invocation.. /// the allocated region in 0xF0000 or 0xE0000 block after the second invocation..
/// ///
/// Note: There are two generic mechanisms by which this mode can be used. /// Note: There are two generic mechanisms by which this mode can be used.
/// Mechanism 1: This mode returns the data and the Legacy BIOS Protocol copies /// Mechanism 1: This mode returns the data and the Legacy BIOS Protocol copies
/// the data into the F0000 or E0000 block in the Compatibility16 code. The /// the data into the F0000 or E0000 block in the Compatibility16 code. The
/// EFI_COMPATIBILITY16_TABLE entries Oem32Segment and Oem32Offset can /// EFI_COMPATIBILITY16_TABLE entries Oem32Segment and Oem32Offset can
/// be viewed as two UINT16 entries. /// be viewed as two UINT16 entries.
/// Mechanism 2: This mode directly fills in the EFI_COMPATIBILITY16_TABLE with /// Mechanism 2: This mode directly fills in the EFI_COMPATIBILITY16_TABLE with
/// a pointer to the INT15 E820 region containing the 32 bit code. It returns /// a pointer to the INT15 E820 region containing the 32 bit code. It returns
/// EFI_UNSUPPORTED. The EFI_COMPATIBILITY16_TABLE entries, /// EFI_UNSUPPORTED. The EFI_COMPATIBILITY16_TABLE entries,
/// Oem32Segment and Oem32Offset, can be viewed as two UINT16 entries or /// Oem32Segment and Oem32Offset, can be viewed as two UINT16 entries or
/// as a single UINT32 entry as determined by the IBV. /// as a single UINT32 entry as determined by the IBV.
/// ///
/// The function parameters associated with this mode are: /// The function parameters associated with this mode are:
/// ///
/// TableSize Size of data. /// TableSize Size of data.
/// ///
/// Location Location to place the table. 0x00 or 0xE0000 or 0xF0000 64 KB blocks. /// Location Location to place the table. 0x00 or 0xE0000 or 0xF0000 64 KB blocks.
/// Bit 0 = 1 0xF0000 64 KB block. /// Bit 0 = 1 0xF0000 64 KB block.
/// Bit 1 = 1 0xE0000 64 KB block. /// Bit 1 = 1 0xE0000 64 KB block.
/// Multiple bits can be set. /// Multiple bits can be set.
/// ///
/// Alignment Bit mapped address alignment granularity. /// Alignment Bit mapped address alignment granularity.
/// The first nonzero bit from the right is the address granularity. /// The first nonzero bit from the right is the address granularity.
/// ///
/// LegacySegment Segment in which EfiCompatibility code will place the table or data. /// LegacySegment Segment in which EfiCompatibility code will place the table or data.
/// ///
/// LegacyOffset Offset in which EfiCompatibility code will place the table or data. /// LegacyOffset Offset in which EfiCompatibility code will place the table or data.
/// ///
/// The return values associated with this mode are: /// The return values associated with this mode are:
/// EFI_SUCCESS The data was returned successfully. /// EFI_SUCCESS The data was returned successfully.
/// EFI_UNSUPPORTED Oem32 is not supported on this platform. /// EFI_UNSUPPORTED Oem32 is not supported on this platform.
/// ///
EfiGetPlatformBinaryOem32Data = 3, EfiGetPlatformBinaryOem32Data = 3,
/// ///
/// This mode returns a TPM binary image for the onboard TPM device. /// This mode returns a TPM binary image for the onboard TPM device.
/// ///
@ -226,7 +226,7 @@ EfiGetPlatformBinaryOem32Data = 3,
/// ///
/// EFI_NOT_FOUND No BinaryImage was found. /// EFI_NOT_FOUND No BinaryImage was found.
/// ///
EfiGetPlatformBinaryTpmBinary = 4, EfiGetPlatformBinaryTpmBinary = 4,
/// ///
/// The mode finds the Compatibility16 Rom Image. /// The mode finds the Compatibility16 Rom Image.
/// ///
@ -250,7 +250,7 @@ EfiGetPlatformBinaryOem32Data = 3,
/// ///
/// EFI_NOT_FOUND ROM not found. /// EFI_NOT_FOUND ROM not found.
/// ///
EfiGetPlatformBinarySystemRom = 5, EfiGetPlatformBinarySystemRom = 5,
/// ///
/// This mode returns the Base address of PciExpress memory mapped configuration /// This mode returns the Base address of PciExpress memory mapped configuration
/// address space. /// address space.
@ -275,9 +275,9 @@ EfiGetPlatformBinaryOem32Data = 3,
/// ///
/// EFI_UNSUPPORTED System does not PciExpress. /// EFI_UNSUPPORTED System does not PciExpress.
/// ///
EfiGetPlatformPciExpressBase = 6, EfiGetPlatformPciExpressBase = 6,
/// ///
EfiGetPlatformPmmSize = 7, EfiGetPlatformPmmSize = 7,
/// ///
EfiGetPlatformEndOpromShadowAddr = 8, EfiGetPlatformEndOpromShadowAddr = 8,
/// ///
@ -301,7 +301,7 @@ typedef enum {
/// ///
/// AdditionalData NULL. /// AdditionalData NULL.
/// ///
EfiGetPlatformVgaHandle = 0, EfiGetPlatformVgaHandle = 0,
/// ///
/// This mode returns the Compatibility16 policy for the device that should be the IDE /// This mode returns the Compatibility16 policy for the device that should be the IDE
/// controller used during a Compatibility16 boot. /// controller used during a Compatibility16 boot.
@ -317,7 +317,7 @@ typedef enum {
/// AdditionalData Pointer to HddInfo. /// AdditionalData Pointer to HddInfo.
/// Information about all onboard IDE controllers. /// Information about all onboard IDE controllers.
/// ///
EfiGetPlatformIdeHandle = 1, EfiGetPlatformIdeHandle = 1,
/// ///
/// This mode returns the Compatibility16 policy for the device that should be the ISA bus /// This mode returns the Compatibility16 policy for the device that should be the ISA bus
/// controller used during a Compatibility16 boot. /// controller used during a Compatibility16 boot.
@ -332,7 +332,7 @@ typedef enum {
/// ///
/// AdditionalData NULL. /// AdditionalData NULL.
/// ///
EfiGetPlatformIsaBusHandle = 2, EfiGetPlatformIsaBusHandle = 2,
/// ///
/// This mode returns the Compatibility16 policy for the device that should be the USB /// This mode returns the Compatibility16 policy for the device that should be the USB
/// device used during a Compatibility16 boot. /// device used during a Compatibility16 boot.
@ -347,7 +347,7 @@ typedef enum {
/// ///
/// AdditionalData NULL. /// AdditionalData NULL.
/// ///
EfiGetPlatformUsbHandle = 3 EfiGetPlatformUsbHandle = 3
} EFI_GET_PLATFORM_HANDLE_MODE; } EFI_GET_PLATFORM_HANDLE_MODE;
/** /**
@ -387,7 +387,7 @@ typedef enum {
/// ///
/// AdditionalData NULL. /// AdditionalData NULL.
/// ///
EfiPlatformHookShadowServiceRoms= 1, EfiPlatformHookShadowServiceRoms = 1,
/// ///
/// This mode allows platform to perform any required operation after an OpROM has /// This mode allows platform to perform any required operation after an OpROM has
/// completed its initialization. /// completed its initialization.
@ -404,21 +404,21 @@ typedef enum {
/// ///
/// AdditionalData NULL. /// AdditionalData NULL.
/// ///
EfiPlatformHookAfterRomInit = 2 EfiPlatformHookAfterRomInit = 2
} EFI_GET_PLATFORM_HOOK_MODE; } EFI_GET_PLATFORM_HOOK_MODE;
/// ///
/// This IRQ has not been assigned to PCI. /// This IRQ has not been assigned to PCI.
/// ///
#define PCI_UNUSED 0x00 #define PCI_UNUSED 0x00
/// ///
/// This IRQ has been assigned to PCI. /// This IRQ has been assigned to PCI.
/// ///
#define PCI_USED 0xFF #define PCI_USED 0xFF
/// ///
/// This IRQ has been used by an SIO legacy device and cannot be used by PCI. /// This IRQ has been used by an SIO legacy device and cannot be used by PCI.
/// ///
#define LEGACY_USED 0xFE #define LEGACY_USED 0xFE
#pragma pack(1) #pragma pack(1)
@ -426,7 +426,7 @@ typedef struct {
/// ///
/// IRQ for this entry. /// IRQ for this entry.
/// ///
UINT8 Irq; UINT8 Irq;
/// ///
/// Status of this IRQ. /// Status of this IRQ.
/// ///
@ -437,103 +437,101 @@ typedef struct {
/// LEGACY_USED 0xFE. This IRQ has been used by an SIO legacy /// LEGACY_USED 0xFE. This IRQ has been used by an SIO legacy
/// device and cannot be used by PCI. /// device and cannot be used by PCI.
/// ///
UINT8 Used; UINT8 Used;
} EFI_LEGACY_IRQ_PRIORITY_TABLE_ENTRY; } EFI_LEGACY_IRQ_PRIORITY_TABLE_ENTRY;
// //
// Define PIR table structures // Define PIR table structures
// //
#define EFI_LEGACY_PIRQ_TABLE_SIGNATURE SIGNATURE_32 ('$', 'P', 'I', 'R') #define EFI_LEGACY_PIRQ_TABLE_SIGNATURE SIGNATURE_32 ('$', 'P', 'I', 'R')
typedef struct { typedef struct {
/// ///
/// $PIR. /// $PIR.
/// ///
UINT32 Signature; UINT32 Signature;
/// ///
/// 0x00. /// 0x00.
/// ///
UINT8 MinorVersion; UINT8 MinorVersion;
/// ///
/// 0x01 for table version 1.0. /// 0x01 for table version 1.0.
/// ///
UINT8 MajorVersion; UINT8 MajorVersion;
/// ///
/// 0x20 + RoutingTableEntries * 0x10. /// 0x20 + RoutingTableEntries * 0x10.
/// ///
UINT16 TableSize; UINT16 TableSize;
/// ///
/// PCI interrupt router bus. /// PCI interrupt router bus.
/// ///
UINT8 Bus; UINT8 Bus;
/// ///
/// PCI interrupt router device/function. /// PCI interrupt router device/function.
/// ///
UINT8 DevFun; UINT8 DevFun;
/// ///
/// If nonzero, bit map of IRQs reserved for PCI. /// If nonzero, bit map of IRQs reserved for PCI.
/// ///
UINT16 PciOnlyIrq; UINT16 PciOnlyIrq;
/// ///
/// Vendor ID of a compatible PCI interrupt router. /// Vendor ID of a compatible PCI interrupt router.
/// ///
UINT16 CompatibleVid; UINT16 CompatibleVid;
/// ///
/// Device ID of a compatible PCI interrupt router. /// Device ID of a compatible PCI interrupt router.
/// ///
UINT16 CompatibleDid; UINT16 CompatibleDid;
/// ///
/// If nonzero, a value passed directly to the IRQ miniport's Initialize function. /// If nonzero, a value passed directly to the IRQ miniport's Initialize function.
/// ///
UINT32 Miniport; UINT32 Miniport;
/// ///
/// Reserved for future usage. /// Reserved for future usage.
/// ///
UINT8 Reserved[11]; UINT8 Reserved[11];
/// ///
/// This byte plus the sum of all other bytes in the LocalPirqTable equal 0x00. /// This byte plus the sum of all other bytes in the LocalPirqTable equal 0x00.
/// ///
UINT8 Checksum; UINT8 Checksum;
} EFI_LEGACY_PIRQ_TABLE_HEADER; } EFI_LEGACY_PIRQ_TABLE_HEADER;
typedef struct { typedef struct {
/// ///
/// If nonzero, a value assigned by the IBV. /// If nonzero, a value assigned by the IBV.
/// ///
UINT8 Pirq; UINT8 Pirq;
/// ///
/// If nonzero, the IRQs that can be assigned to this device. /// If nonzero, the IRQs that can be assigned to this device.
/// ///
UINT16 IrqMask; UINT16 IrqMask;
} EFI_LEGACY_PIRQ_ENTRY; } EFI_LEGACY_PIRQ_ENTRY;
typedef struct { typedef struct {
/// ///
/// PCI bus of the entry. /// PCI bus of the entry.
/// ///
UINT8 Bus; UINT8 Bus;
/// ///
/// PCI device of this entry. /// PCI device of this entry.
/// ///
UINT8 Device; UINT8 Device;
/// ///
/// An IBV value and IRQ mask for PIRQ pins A through D. /// An IBV value and IRQ mask for PIRQ pins A through D.
/// ///
EFI_LEGACY_PIRQ_ENTRY PirqEntry[4]; EFI_LEGACY_PIRQ_ENTRY PirqEntry[4];
/// ///
/// If nonzero, the slot number assigned by the board manufacturer. /// If nonzero, the slot number assigned by the board manufacturer.
/// ///
UINT8 Slot; UINT8 Slot;
/// ///
/// Reserved for future use. /// Reserved for future use.
/// ///
UINT8 Reserved; UINT8 Reserved;
} EFI_LEGACY_IRQ_ROUTING_ENTRY; } EFI_LEGACY_IRQ_ROUTING_ENTRY;
#pragma pack() #pragma pack()
/** /**
Finds the binary data or other platform information. Finds the binary data or other platform information.
@ -725,31 +723,31 @@ struct _EFI_LEGACY_BIOS_PLATFORM_PROTOCOL {
/// ///
/// Gets binary data or other platform information. /// Gets binary data or other platform information.
/// ///
EFI_LEGACY_BIOS_PLATFORM_GET_PLATFORM_INFO GetPlatformInfo; EFI_LEGACY_BIOS_PLATFORM_GET_PLATFORM_INFO GetPlatformInfo;
/// ///
/// Returns a buffer of all handles matching the requested subfunction. /// Returns a buffer of all handles matching the requested subfunction.
/// ///
EFI_LEGACY_BIOS_PLATFORM_GET_PLATFORM_HANDLE GetPlatformHandle; EFI_LEGACY_BIOS_PLATFORM_GET_PLATFORM_HANDLE GetPlatformHandle;
/// ///
/// Loads and initializes the traditional BIOS SMM handler. /// Loads and initializes the traditional BIOS SMM handler.
EFI_LEGACY_BIOS_PLATFORM_SMM_INIT SmmInit; EFI_LEGACY_BIOS_PLATFORM_SMM_INIT SmmInit;
/// ///
/// Allows platform to perform any required actions after a LegacyBios operation. /// Allows platform to perform any required actions after a LegacyBios operation.
/// ///
EFI_LEGACY_BIOS_PLATFORM_HOOKS PlatformHooks; EFI_LEGACY_BIOS_PLATFORM_HOOKS PlatformHooks;
/// ///
/// Gets $PIR table. /// Gets $PIR table.
EFI_LEGACY_BIOS_PLATFORM_GET_ROUTING_TABLE GetRoutingTable; EFI_LEGACY_BIOS_PLATFORM_GET_ROUTING_TABLE GetRoutingTable;
/// ///
/// Translates the given PIRQ to the final value after traversing any PCI bridges. /// Translates the given PIRQ to the final value after traversing any PCI bridges.
/// ///
EFI_LEGACY_BIOS_PLATFORM_TRANSLATE_PIRQ TranslatePirq; EFI_LEGACY_BIOS_PLATFORM_TRANSLATE_PIRQ TranslatePirq;
/// ///
/// Final platform function before the system attempts to boot to a traditional OS. /// Final platform function before the system attempts to boot to a traditional OS.
/// ///
EFI_LEGACY_BIOS_PLATFORM_PREPARE_TO_BOOT PrepareToBoot; EFI_LEGACY_BIOS_PLATFORM_PREPARE_TO_BOOT PrepareToBoot;
}; };
extern EFI_GUID gEfiLegacyBiosPlatformProtocolGuid; extern EFI_GUID gEfiLegacyBiosPlatformProtocolGuid;
#endif #endif

View File

@ -13,7 +13,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef _EFI_LEGACY_INTERRUPT_H_ #ifndef _EFI_LEGACY_INTERRUPT_H_
#define _EFI_LEGACY_INTERRUPT_H_ #define _EFI_LEGACY_INTERRUPT_H_
#define EFI_LEGACY_INTERRUPT_PROTOCOL_GUID \ #define EFI_LEGACY_INTERRUPT_PROTOCOL_GUID \
{ \ { \
0x31ce593d, 0x108a, 0x485d, {0xad, 0xb2, 0x78, 0xf2, 0x1f, 0x29, 0x66, 0xbe } \ 0x31ce593d, 0x108a, 0x485d, {0xad, 0xb2, 0x78, 0xf2, 0x1f, 0x29, 0x66, 0xbe } \
@ -99,24 +98,24 @@ struct _EFI_LEGACY_INTERRUPT_PROTOCOL {
/// ///
/// Gets the number of PIRQs supported. /// Gets the number of PIRQs supported.
/// ///
EFI_LEGACY_INTERRUPT_GET_NUMBER_PIRQS GetNumberPirqs; EFI_LEGACY_INTERRUPT_GET_NUMBER_PIRQS GetNumberPirqs;
/// ///
/// Gets the PCI bus, device, and function that is associated with this protocol. /// Gets the PCI bus, device, and function that is associated with this protocol.
/// ///
EFI_LEGACY_INTERRUPT_GET_LOCATION GetLocation; EFI_LEGACY_INTERRUPT_GET_LOCATION GetLocation;
/// ///
/// Reads the indicated PIRQ register. /// Reads the indicated PIRQ register.
/// ///
EFI_LEGACY_INTERRUPT_READ_PIRQ ReadPirq; EFI_LEGACY_INTERRUPT_READ_PIRQ ReadPirq;
/// ///
/// Writes to the indicated PIRQ register. /// Writes to the indicated PIRQ register.
/// ///
EFI_LEGACY_INTERRUPT_WRITE_PIRQ WritePirq; EFI_LEGACY_INTERRUPT_WRITE_PIRQ WritePirq;
}; };
extern EFI_GUID gEfiLegacyInterruptProtocolGuid; extern EFI_GUID gEfiLegacyInterruptProtocolGuid;
#endif #endif

View File

@ -20,7 +20,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
/// ///
/// Forward declaration for the EFI_VGA_MINI_PORT_PROTOCOL. /// Forward declaration for the EFI_VGA_MINI_PORT_PROTOCOL.
/// ///
typedef struct _EFI_VGA_MINI_PORT_PROTOCOL EFI_VGA_MINI_PORT_PROTOCOL; typedef struct _EFI_VGA_MINI_PORT_PROTOCOL EFI_VGA_MINI_PORT_PROTOCOL;
/** /**
Sets the text display mode of a VGA controller. Sets the text display mode of a VGA controller.
@ -49,40 +49,40 @@ EFI_STATUS
); );
struct _EFI_VGA_MINI_PORT_PROTOCOL { struct _EFI_VGA_MINI_PORT_PROTOCOL {
EFI_VGA_MINI_PORT_SET_MODE SetMode; EFI_VGA_MINI_PORT_SET_MODE SetMode;
/// ///
/// MMIO base address of the VGA text mode framebuffer. Typically set to 0xB8000. /// MMIO base address of the VGA text mode framebuffer. Typically set to 0xB8000.
/// ///
UINT64 VgaMemoryOffset; UINT64 VgaMemoryOffset;
/// ///
/// I/O Port address for the VGA CRTC address register. Typically set to 0x3D4. /// I/O Port address for the VGA CRTC address register. Typically set to 0x3D4.
/// ///
UINT64 CrtcAddressRegisterOffset; UINT64 CrtcAddressRegisterOffset;
/// ///
/// I/O Port address for the VGA CRTC data register. Typically set to 0x3D5. /// I/O Port address for the VGA CRTC data register. Typically set to 0x3D5.
/// ///
UINT64 CrtcDataRegisterOffset; UINT64 CrtcDataRegisterOffset;
/// ///
/// PCI Controller MMIO BAR index of the VGA text mode frame buffer. Typically /// PCI Controller MMIO BAR index of the VGA text mode frame buffer. Typically
/// set to EFI_PCI_IO_PASS_THROUGH_BAR /// set to EFI_PCI_IO_PASS_THROUGH_BAR
/// ///
UINT8 VgaMemoryBar; UINT8 VgaMemoryBar;
/// ///
/// PCI Controller I/O BAR index of the VGA CRTC address register. Typically /// PCI Controller I/O BAR index of the VGA CRTC address register. Typically
/// set to EFI_PCI_IO_PASS_THROUGH_BAR /// set to EFI_PCI_IO_PASS_THROUGH_BAR
/// ///
UINT8 CrtcAddressRegisterBar; UINT8 CrtcAddressRegisterBar;
/// ///
/// PCI Controller I/O BAR index of the VGA CRTC data register. Typically set /// PCI Controller I/O BAR index of the VGA CRTC data register. Typically set
/// to EFI_PCI_IO_PASS_THROUGH_BAR /// to EFI_PCI_IO_PASS_THROUGH_BAR
/// ///
UINT8 CrtcDataRegisterBar; UINT8 CrtcDataRegisterBar;
/// ///
/// The maximum number of text modes that this VGA controller supports. /// The maximum number of text modes that this VGA controller supports.
/// ///
UINT8 MaxMode; UINT8 MaxMode;
}; };
extern EFI_GUID gEfiVgaMiniPortProtocolGuid; extern EFI_GUID gEfiVgaMiniPortProtocolGuid;
#endif #endif

View File

@ -14,13 +14,13 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// FLOPPY_NOT_PRESENT = No floppy controller present // FLOPPY_NOT_PRESENT = No floppy controller present
// FLOPPY_PRESENT_NO_MEDIA = Floppy controller present but no media inserted // FLOPPY_PRESENT_NO_MEDIA = Floppy controller present but no media inserted
// //
#define FLOPPY_NOT_PRESENT 0 #define FLOPPY_NOT_PRESENT 0
#define FLOPPY_PRESENT_WITH_MEDIA 1 #define FLOPPY_PRESENT_WITH_MEDIA 1
#define FLOPPY_PRESENT_NO_MEDIA 2 #define FLOPPY_PRESENT_NO_MEDIA 2
BBS_TABLE *mBbsTable; BBS_TABLE *mBbsTable;
BOOLEAN mBbsTableDoneFlag = FALSE; BOOLEAN mBbsTableDoneFlag = FALSE;
BOOLEAN IsHaveMediaInFloppy = TRUE; BOOLEAN IsHaveMediaInFloppy = TRUE;
/** /**
Checks the state of the floppy and if media is inserted. Checks the state of the floppy and if media is inserted.
@ -44,23 +44,23 @@ HasMediaInFloppy (
VOID VOID
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINTN HandleCount; UINTN HandleCount;
EFI_HANDLE *HandleBuffer; EFI_HANDLE *HandleBuffer;
UINTN Index; UINTN Index;
EFI_ISA_IO_PROTOCOL *IsaIo; EFI_ISA_IO_PROTOCOL *IsaIo;
EFI_BLOCK_IO_PROTOCOL *BlkIo; EFI_BLOCK_IO_PROTOCOL *BlkIo;
HandleBuffer = NULL; HandleBuffer = NULL;
HandleCount = 0; HandleCount = 0;
gBS->LocateHandleBuffer ( gBS->LocateHandleBuffer (
ByProtocol, ByProtocol,
&gEfiIsaIoProtocolGuid, &gEfiIsaIoProtocolGuid,
NULL, NULL,
&HandleCount, &HandleCount,
&HandleBuffer &HandleBuffer
); );
// //
// If don't find any ISA/IO protocol assume no floppy. Need for floppy // If don't find any ISA/IO protocol assume no floppy. Need for floppy
@ -76,7 +76,7 @@ HasMediaInFloppy (
Status = gBS->HandleProtocol ( Status = gBS->HandleProtocol (
HandleBuffer[Index], HandleBuffer[Index],
&gEfiIsaIoProtocolGuid, &gEfiIsaIoProtocolGuid,
(VOID **) &IsaIo (VOID **)&IsaIo
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
continue; continue;
@ -85,6 +85,7 @@ HasMediaInFloppy (
if (IsaIo->ResourceList->Device.HID != EISA_PNP_ID (0x604)) { if (IsaIo->ResourceList->Device.HID != EISA_PNP_ID (0x604)) {
continue; continue;
} }
// //
// Update blockio in case the floppy is inserted in during BdsTimeout // Update blockio in case the floppy is inserted in during BdsTimeout
// //
@ -103,7 +104,7 @@ HasMediaInFloppy (
Status = gBS->HandleProtocol ( Status = gBS->HandleProtocol (
HandleBuffer[Index], HandleBuffer[Index],
&gEfiBlockIoProtocolGuid, &gEfiBlockIoProtocolGuid,
(VOID **) &BlkIo (VOID **)&BlkIo
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
continue; continue;
@ -121,10 +122,8 @@ HasMediaInFloppy (
FreePool (HandleBuffer); FreePool (HandleBuffer);
return FLOPPY_NOT_PRESENT; return FLOPPY_NOT_PRESENT;
} }
/** /**
Complete build of BBS TABLE. Complete build of BBS TABLE.
@ -136,8 +135,8 @@ HasMediaInFloppy (
**/ **/
EFI_STATUS EFI_STATUS
LegacyBiosBuildBbs ( LegacyBiosBuildBbs (
IN LEGACY_BIOS_INSTANCE *Private, IN LEGACY_BIOS_INSTANCE *Private,
IN BBS_TABLE *BbsTable IN BBS_TABLE *BbsTable
) )
{ {
UINTN BbsIndex; UINTN BbsIndex;
@ -172,18 +171,18 @@ LegacyBiosBuildBbs (
} }
} }
BbsTable[0].Bus = 0xff; BbsTable[0].Bus = 0xff;
BbsTable[0].Device = 0xff; BbsTable[0].Device = 0xff;
BbsTable[0].Function = 0xff; BbsTable[0].Function = 0xff;
BbsTable[0].DeviceType = BBS_FLOPPY; BbsTable[0].DeviceType = BBS_FLOPPY;
BbsTable[0].Class = 01; BbsTable[0].Class = 01;
BbsTable[0].SubClass = 02; BbsTable[0].SubClass = 02;
BbsTable[0].StatusFlags.OldPosition = 0; BbsTable[0].StatusFlags.OldPosition = 0;
BbsTable[0].StatusFlags.Reserved1 = 0; BbsTable[0].StatusFlags.Reserved1 = 0;
BbsTable[0].StatusFlags.Enabled = 0; BbsTable[0].StatusFlags.Enabled = 0;
BbsTable[0].StatusFlags.Failed = 0; BbsTable[0].StatusFlags.Failed = 0;
BbsTable[0].StatusFlags.MediaPresent = 0; BbsTable[0].StatusFlags.MediaPresent = 0;
BbsTable[0].StatusFlags.Reserved2 = 0; BbsTable[0].StatusFlags.Reserved2 = 0;
// //
// Onboard HDD - Note Each HDD controller controls 2 drives // Onboard HDD - Note Each HDD controller controls 2 drives
@ -196,10 +195,8 @@ LegacyBiosBuildBbs (
LegacyBiosBuildIdeData (Private, &HddInfo, 0); LegacyBiosBuildIdeData (Private, &HddInfo, 0);
for (HddIndex = 0; HddIndex < MAX_IDE_CONTROLLER; HddIndex++) { for (HddIndex = 0; HddIndex < MAX_IDE_CONTROLLER; HddIndex++) {
BbsIndex = HddIndex * 2 + 1; BbsIndex = HddIndex * 2 + 1;
for (Index = 0; Index < 2; ++Index) { for (Index = 0; Index < 2; ++Index) {
BbsTable[BbsIndex + Index].Bus = HddInfo[HddIndex].Bus; BbsTable[BbsIndex + Index].Bus = HddInfo[HddIndex].Bus;
BbsTable[BbsIndex + Index].Device = HddInfo[HddIndex].Device; BbsTable[BbsIndex + Index].Device = HddInfo[HddIndex].Device;
BbsTable[BbsIndex + Index].Function = HddInfo[HddIndex].Function; BbsTable[BbsIndex + Index].Function = HddInfo[HddIndex].Function;
@ -286,7 +283,7 @@ LegacyBiosBuildBbs (
Status = gBS->HandleProtocol ( Status = gBS->HandleProtocol (
BlockIoHandles[BlockIndex], BlockIoHandles[BlockIndex],
&gEfiBlockIoProtocolGuid, &gEfiBlockIoProtocolGuid,
(VOID **) &BlkIo (VOID **)&BlkIo
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
@ -313,7 +310,7 @@ LegacyBiosBuildBbs (
Status = gBS->HandleProtocol ( Status = gBS->HandleProtocol (
BlockIoHandles[BlockIndex], BlockIoHandles[BlockIndex],
&gEfiDevicePathProtocolGuid, &gEfiDevicePathProtocolGuid,
(VOID **) &DevicePath (VOID **)&DevicePath
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
continue; continue;
@ -324,14 +321,17 @@ LegacyBiosBuildBbs (
// //
DevicePathNode = DevicePath; DevicePathNode = DevicePath;
while (!IsDevicePathEnd (DevicePathNode)) { while (!IsDevicePathEnd (DevicePathNode)) {
if (DevicePathType (DevicePathNode) == MESSAGING_DEVICE_PATH && if ((DevicePathType (DevicePathNode) == MESSAGING_DEVICE_PATH) &&
DevicePathSubType (DevicePathNode) == MSG_ATAPI_DP) { (DevicePathSubType (DevicePathNode) == MSG_ATAPI_DP))
{
break; break;
} }
DevicePathNode = NextDevicePathNode (DevicePathNode); DevicePathNode = NextDevicePathNode (DevicePathNode);
} }
if (!IsDevicePathEnd (DevicePathNode)) { if (!IsDevicePathEnd (DevicePathNode)) {
continue; continue;
} }
// //
@ -349,7 +349,7 @@ LegacyBiosBuildBbs (
Status = gBS->HandleProtocol ( Status = gBS->HandleProtocol (
PciHandle, PciHandle,
&gEfiPciIoProtocolGuid, &gEfiPciIoProtocolGuid,
(VOID **) &PciIo (VOID **)&PciIo
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
continue; continue;
@ -367,13 +367,21 @@ LegacyBiosBuildBbs (
} }
if (SegNum != 0) { if (SegNum != 0) {
DEBUG ((DEBUG_WARN, "CSM cannot use PCI devices in segment %Lu\n", DEBUG ((
(UINT64) SegNum)); DEBUG_WARN,
"CSM cannot use PCI devices in segment %Lu\n",
(UINT64)SegNum
));
continue; continue;
} }
DEBUG ((DEBUG_INFO, "Add Legacy Bbs entry for PCI %d/%d/%d\n", DEBUG ((
BusNum, DevNum, FuncNum)); DEBUG_INFO,
"Add Legacy Bbs entry for PCI %d/%d/%d\n",
BusNum,
DevNum,
FuncNum
));
BbsTable[BbsIndex].Bus = BusNum; BbsTable[BbsIndex].Bus = BusNum;
BbsTable[BbsIndex].Device = DevNum; BbsTable[BbsIndex].Device = DevNum;
@ -403,7 +411,6 @@ LegacyBiosBuildBbs (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Get all BBS info Get all BBS info
@ -421,30 +428,30 @@ LegacyBiosBuildBbs (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
LegacyBiosGetBbsInfo ( LegacyBiosGetBbsInfo (
IN EFI_LEGACY_BIOS_PROTOCOL *This, IN EFI_LEGACY_BIOS_PROTOCOL *This,
OUT UINT16 *HddCount, OUT UINT16 *HddCount,
OUT HDD_INFO **HddInfo, OUT HDD_INFO **HddInfo,
OUT UINT16 *BbsCount, OUT UINT16 *BbsCount,
OUT BBS_TABLE **BbsTable OUT BBS_TABLE **BbsTable
) )
{ {
LEGACY_BIOS_INSTANCE *Private; LEGACY_BIOS_INSTANCE *Private;
EFI_IA32_REGISTER_SET Regs; EFI_IA32_REGISTER_SET Regs;
EFI_TO_COMPATIBILITY16_BOOT_TABLE *EfiToLegacy16BootTable; EFI_TO_COMPATIBILITY16_BOOT_TABLE *EfiToLegacy16BootTable;
// HDD_INFO *LocalHddInfo; // HDD_INFO *LocalHddInfo;
// IN BBS_TABLE *LocalBbsTable; // IN BBS_TABLE *LocalBbsTable;
UINTN NumHandles; UINTN NumHandles;
EFI_HANDLE *HandleBuffer; EFI_HANDLE *HandleBuffer;
UINTN Index; UINTN Index;
UINTN TempData; UINTN TempData;
UINT32 Granularity; UINT32 Granularity;
HandleBuffer = NULL; HandleBuffer = NULL;
Private = LEGACY_BIOS_INSTANCE_FROM_THIS (This); Private = LEGACY_BIOS_INSTANCE_FROM_THIS (This);
EfiToLegacy16BootTable = &Private->IntThunk->EfiToLegacy16BootTable; EfiToLegacy16BootTable = &Private->IntThunk->EfiToLegacy16BootTable;
// LocalHddInfo = EfiToLegacy16BootTable->HddInfo; // LocalHddInfo = EfiToLegacy16BootTable->HddInfo;
// LocalBbsTable = (BBS_TABLE*)(UINTN)EfiToLegacy16BootTable->BbsTable; // LocalBbsTable = (BBS_TABLE*)(UINTN)EfiToLegacy16BootTable->BbsTable;
if (!mBbsTableDoneFlag) { if (!mBbsTableDoneFlag) {
mBbsTable = Private->BbsTablePtr; mBbsTable = Private->BbsTablePtr;
@ -457,12 +464,12 @@ LegacyBiosGetBbsInfo (
// Get PciRootBridgeIO protocol // Get PciRootBridgeIO protocol
// //
gBS->LocateHandleBuffer ( gBS->LocateHandleBuffer (
ByProtocol, ByProtocol,
&gEfiPciRootBridgeIoProtocolGuid, &gEfiPciRootBridgeIoProtocolGuid,
NULL, NULL,
&NumHandles, &NumHandles,
&HandleBuffer &HandleBuffer
); );
if (NumHandles == 0) { if (NumHandles == 0) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
@ -475,7 +482,6 @@ LegacyBiosGetBbsInfo (
// PCI bus driver enumerate all subsequent handles // PCI bus driver enumerate all subsequent handles
// //
gBS->ConnectController (HandleBuffer[Index], NULL, NULL, FALSE); gBS->ConnectController (HandleBuffer[Index], NULL, NULL, FALSE);
} }
LegacyBiosBuildBbs (Private, mBbsTable); LegacyBiosBuildBbs (Private, mBbsTable);
@ -491,18 +497,18 @@ LegacyBiosGetBbsInfo (
// //
// Pass in handoff data // Pass in handoff data
// //
TempData = (UINTN) EfiToLegacy16BootTable; TempData = (UINTN)EfiToLegacy16BootTable;
Regs.X.ES = NORMALIZE_EFI_SEGMENT ((UINT32) TempData); Regs.X.ES = NORMALIZE_EFI_SEGMENT ((UINT32)TempData);
Regs.X.BX = NORMALIZE_EFI_OFFSET ((UINT32) TempData); Regs.X.BX = NORMALIZE_EFI_OFFSET ((UINT32)TempData);
Private->LegacyBios.FarCall86 ( Private->LegacyBios.FarCall86 (
This, This,
Private->Legacy16CallSegment, Private->Legacy16CallSegment,
Private->Legacy16CallOffset, Private->Legacy16CallOffset,
&Regs, &Regs,
NULL, NULL,
0 0
); );
Private->Cpu->FlushDataCache (Private->Cpu, 0xE0000, 0x20000, EfiCpuFlushTypeWriteBackInvalidate); Private->Cpu->FlushDataCache (Private->Cpu, 0xE0000, 0x20000, EfiCpuFlushTypeWriteBackInvalidate);
Private->LegacyRegion->Lock (Private->LegacyRegion, 0xe0000, 0x20000, &Granularity); Private->LegacyRegion->Lock (Private->LegacyRegion, 0xe0000, 0x20000, &Granularity);
@ -518,7 +524,7 @@ LegacyBiosGetBbsInfo (
*HddCount = MAX_IDE_CONTROLLER; *HddCount = MAX_IDE_CONTROLLER;
*HddInfo = EfiToLegacy16BootTable->HddInfo; *HddInfo = EfiToLegacy16BootTable->HddInfo;
*BbsTable = (BBS_TABLE*)(UINTN)EfiToLegacy16BootTable->BbsTable; *BbsTable = (BBS_TABLE *)(UINTN)EfiToLegacy16BootTable->BbsTable;
*BbsCount = (UINT16) (sizeof (Private->IntThunk->BbsTable) / sizeof (BBS_TABLE)); *BbsCount = (UINT16)(sizeof (Private->IntThunk->BbsTable) / sizeof (BBS_TABLE));
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@ -21,25 +21,25 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
EFI_STATUS EFI_STATUS
LegacyBiosInitBda ( LegacyBiosInitBda (
IN LEGACY_BIOS_INSTANCE *Private IN LEGACY_BIOS_INSTANCE *Private
) )
{ {
BDA_STRUC *Bda; BDA_STRUC *Bda;
UINT8 *Ebda; UINT8 *Ebda;
Bda = (BDA_STRUC *) ((UINTN) 0x400); Bda = (BDA_STRUC *)((UINTN)0x400);
Ebda = (UINT8 *) ((UINTN) 0x9fc00); Ebda = (UINT8 *)((UINTN)0x9fc00);
ACCESS_PAGE0_CODE ( ACCESS_PAGE0_CODE (
ZeroMem (Bda, 0x100); ZeroMem (Bda, 0x100);
// //
// 640k-1k for EBDA // 640k-1k for EBDA
// //
Bda->MemSize = 0x27f; Bda->MemSize = 0x27f;
Bda->KeyHead = 0x1e; Bda->KeyHead = 0x1e;
Bda->KeyTail = 0x1e; Bda->KeyTail = 0x1e;
Bda->FloppyData = 0x00; Bda->FloppyData = 0x00;
Bda->FloppyTimeout = 0xff; Bda->FloppyTimeout = 0xff;
Bda->KeyStart = 0x001E; Bda->KeyStart = 0x001E;
Bda->KeyEnd = 0x003E; Bda->KeyEnd = 0x003E;
@ -50,10 +50,10 @@ LegacyBiosInitBda (
// Move LPT time out here and zero out LPT4 since some SCSI OPROMS // Move LPT time out here and zero out LPT4 since some SCSI OPROMS
// use this as scratch pad (LPT4 is Reserved) // use this as scratch pad (LPT4 is Reserved)
// //
Bda->Lpt1_2Timeout = 0x1414; Bda->Lpt1_2Timeout = 0x1414;
Bda->Lpt3_4Timeout = 0x1400; Bda->Lpt3_4Timeout = 0x1400;
); );
ZeroMem (Ebda, 0x400); ZeroMem (Ebda, 0x400);
*Ebda = 0x01; *Ebda = 0x01;

View File

@ -13,7 +13,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// //
// define maximum number of HDD system supports // define maximum number of HDD system supports
// //
#define MAX_HDD_ENTRIES 0x30 #define MAX_HDD_ENTRIES 0x30
// //
// Module Global: // Module Global:
@ -25,7 +25,7 @@ LEGACY_BIOS_INSTANCE mPrivateData;
// //
// The SMBIOS table in EfiRuntimeServicesData memory // The SMBIOS table in EfiRuntimeServicesData memory
// //
VOID *mRuntimeSmbiosEntryPoint = NULL; VOID *mRuntimeSmbiosEntryPoint = NULL;
// //
// The SMBIOS table in EfiReservedMemoryType memory // The SMBIOS table in EfiReservedMemoryType memory
@ -50,27 +50,27 @@ BOOLEAN mEndOfDxe = FALSE;
**/ **/
EFI_STATUS EFI_STATUS
AllocateLegacyMemory ( AllocateLegacyMemory (
IN EFI_ALLOCATE_TYPE AllocateType, IN EFI_ALLOCATE_TYPE AllocateType,
IN EFI_MEMORY_TYPE MemoryType, IN EFI_MEMORY_TYPE MemoryType,
IN EFI_PHYSICAL_ADDRESS StartPageAddress, IN EFI_PHYSICAL_ADDRESS StartPageAddress,
IN UINTN Pages, IN UINTN Pages,
OUT EFI_PHYSICAL_ADDRESS *Result OUT EFI_PHYSICAL_ADDRESS *Result
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS MemPage; EFI_PHYSICAL_ADDRESS MemPage;
EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemDesc; EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemDesc;
// //
// Allocate Pages of memory less <= StartPageAddress // Allocate Pages of memory less <= StartPageAddress
// //
MemPage = (EFI_PHYSICAL_ADDRESS) (UINTN) StartPageAddress; MemPage = (EFI_PHYSICAL_ADDRESS)(UINTN)StartPageAddress;
Status = gBS->AllocatePages ( Status = gBS->AllocatePages (
AllocateType, AllocateType,
MemoryType, MemoryType,
Pages, Pages,
&MemPage &MemPage
); );
// //
// Do not ASSERT on Status error but let caller decide since some cases // Do not ASSERT on Status error but let caller decide since some cases
// memory is already taken but that is ok. // memory is already taken but that is ok.
@ -81,13 +81,14 @@ AllocateLegacyMemory (
// Make sure that the buffer can be used to store code. // Make sure that the buffer can be used to store code.
// //
Status = gDS->GetMemorySpaceDescriptor (MemPage, &MemDesc); Status = gDS->GetMemorySpaceDescriptor (MemPage, &MemDesc);
if (!EFI_ERROR (Status) && (MemDesc.Attributes & EFI_MEMORY_XP) != 0) { if (!EFI_ERROR (Status) && ((MemDesc.Attributes & EFI_MEMORY_XP) != 0)) {
Status = gDS->SetMemorySpaceAttributes ( Status = gDS->SetMemorySpaceAttributes (
MemPage, MemPage,
EFI_PAGES_TO_SIZE (Pages), EFI_PAGES_TO_SIZE (Pages),
MemDesc.Attributes & (~EFI_MEMORY_XP) MemDesc.Attributes & (~EFI_MEMORY_XP)
); );
} }
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
gBS->FreePages (MemPage, Pages); gBS->FreePages (MemPage, Pages);
} }
@ -95,13 +96,12 @@ AllocateLegacyMemory (
} }
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
*Result = (EFI_PHYSICAL_ADDRESS) (UINTN) MemPage; *Result = (EFI_PHYSICAL_ADDRESS)(UINTN)MemPage;
} }
return Status; return Status;
} }
/** /**
This function is called when EFI needs to reserve an area in the 0xE0000 or 0xF0000 This function is called when EFI needs to reserve an area in the 0xE0000 or 0xF0000
64 KB blocks. 64 KB blocks.
@ -126,39 +126,38 @@ AllocateLegacyMemory (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
LegacyBiosGetLegacyRegion ( LegacyBiosGetLegacyRegion (
IN EFI_LEGACY_BIOS_PROTOCOL *This, IN EFI_LEGACY_BIOS_PROTOCOL *This,
IN UINTN LegacyMemorySize, IN UINTN LegacyMemorySize,
IN UINTN Region, IN UINTN Region,
IN UINTN Alignment, IN UINTN Alignment,
OUT VOID **LegacyMemoryAddress OUT VOID **LegacyMemoryAddress
) )
{ {
LEGACY_BIOS_INSTANCE *Private;
LEGACY_BIOS_INSTANCE *Private; EFI_IA32_REGISTER_SET Regs;
EFI_IA32_REGISTER_SET Regs; EFI_STATUS Status;
EFI_STATUS Status; UINT32 Granularity;
UINT32 Granularity;
Private = LEGACY_BIOS_INSTANCE_FROM_THIS (This); Private = LEGACY_BIOS_INSTANCE_FROM_THIS (This);
Private->LegacyRegion->UnLock (Private->LegacyRegion, 0xE0000, 0x20000, &Granularity); Private->LegacyRegion->UnLock (Private->LegacyRegion, 0xE0000, 0x20000, &Granularity);
ZeroMem (&Regs, sizeof (EFI_IA32_REGISTER_SET)); ZeroMem (&Regs, sizeof (EFI_IA32_REGISTER_SET));
Regs.X.AX = Legacy16GetTableAddress; Regs.X.AX = Legacy16GetTableAddress;
Regs.X.BX = (UINT16) Region; Regs.X.BX = (UINT16)Region;
Regs.X.CX = (UINT16) LegacyMemorySize; Regs.X.CX = (UINT16)LegacyMemorySize;
Regs.X.DX = (UINT16) Alignment; Regs.X.DX = (UINT16)Alignment;
Private->LegacyBios.FarCall86 ( Private->LegacyBios.FarCall86 (
&Private->LegacyBios, &Private->LegacyBios,
Private->Legacy16CallSegment, Private->Legacy16CallSegment,
Private->Legacy16CallOffset, Private->Legacy16CallOffset,
&Regs, &Regs,
NULL, NULL,
0 0
); );
if (Regs.X.AX == 0) { if (Regs.X.AX == 0) {
*LegacyMemoryAddress = (VOID *) (((UINTN) Regs.X.DS << 4) + Regs.X.BX); *LegacyMemoryAddress = (VOID *)(((UINTN)Regs.X.DS << 4) + Regs.X.BX);
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
} else { } else {
Status = EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
} }
@ -169,7 +168,6 @@ LegacyBiosGetLegacyRegion (
return Status; return Status;
} }
/** /**
This function is called when copying data to the region assigned by This function is called when copying data to the region assigned by
EFI_LEGACY_BIOS_PROTOCOL.GetLegacyRegion(). EFI_LEGACY_BIOS_PROTOCOL.GetLegacyRegion().
@ -187,21 +185,22 @@ LegacyBiosGetLegacyRegion (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
LegacyBiosCopyLegacyRegion ( LegacyBiosCopyLegacyRegion (
IN EFI_LEGACY_BIOS_PROTOCOL *This, IN EFI_LEGACY_BIOS_PROTOCOL *This,
IN UINTN LegacyMemorySize, IN UINTN LegacyMemorySize,
IN VOID *LegacyMemoryAddress, IN VOID *LegacyMemoryAddress,
IN VOID *LegacyMemorySourceAddress IN VOID *LegacyMemorySourceAddress
) )
{ {
LEGACY_BIOS_INSTANCE *Private; LEGACY_BIOS_INSTANCE *Private;
UINT32 Granularity; UINT32 Granularity;
if ((LegacyMemoryAddress < (VOID *)(UINTN)0xE0000 ) || if ((LegacyMemoryAddress < (VOID *)(UINTN)0xE0000) ||
((UINTN) LegacyMemoryAddress + LegacyMemorySize > (UINTN) 0x100000) ((UINTN)LegacyMemoryAddress + LegacyMemorySize > (UINTN)0x100000)
) { )
{
return EFI_ACCESS_DENIED; return EFI_ACCESS_DENIED;
} }
// //
// There is no protection from writes over lapping if this function is // There is no protection from writes over lapping if this function is
// called multiple times. // called multiple times.
@ -216,7 +215,6 @@ LegacyBiosCopyLegacyRegion (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Find Legacy16 BIOS image in the FLASH device and shadow it into memory. Find Find Legacy16 BIOS image in the FLASH device and shadow it into memory. Find
the $EFI table in the shadow area. Thunk into the Legacy16 code after it had the $EFI table in the shadow area. Thunk into the Legacy16 code after it had
@ -233,33 +231,33 @@ ShadowAndStartLegacy16 (
IN LEGACY_BIOS_INSTANCE *Private IN LEGACY_BIOS_INSTANCE *Private
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINT8 *Ptr; UINT8 *Ptr;
UINT8 *PtrEnd; UINT8 *PtrEnd;
BOOLEAN Done; BOOLEAN Done;
EFI_COMPATIBILITY16_TABLE *Table; EFI_COMPATIBILITY16_TABLE *Table;
UINT8 CheckSum; UINT8 CheckSum;
EFI_IA32_REGISTER_SET Regs; EFI_IA32_REGISTER_SET Regs;
EFI_TO_COMPATIBILITY16_INIT_TABLE *EfiToLegacy16InitTable; EFI_TO_COMPATIBILITY16_INIT_TABLE *EfiToLegacy16InitTable;
EFI_TO_COMPATIBILITY16_BOOT_TABLE *EfiToLegacy16BootTable; EFI_TO_COMPATIBILITY16_BOOT_TABLE *EfiToLegacy16BootTable;
VOID *LegacyBiosImage; VOID *LegacyBiosImage;
UINTN LegacyBiosImageSize; UINTN LegacyBiosImageSize;
UINTN E820Size; UINTN E820Size;
UINT32 *ClearPtr; UINT32 *ClearPtr;
BBS_TABLE *BbsTable; BBS_TABLE *BbsTable;
LEGACY_EFI_HDD_TABLE *LegacyEfiHddTable; LEGACY_EFI_HDD_TABLE *LegacyEfiHddTable;
UINTN Index; UINTN Index;
UINT32 TpmPointer; UINT32 TpmPointer;
VOID *TpmBinaryImage; VOID *TpmBinaryImage;
UINTN TpmBinaryImageSize; UINTN TpmBinaryImageSize;
UINTN Location; UINTN Location;
UINTN Alignment; UINTN Alignment;
UINTN TempData; UINTN TempData;
EFI_PHYSICAL_ADDRESS Address; EFI_PHYSICAL_ADDRESS Address;
UINT16 OldMask; UINT16 OldMask;
UINT16 NewMask; UINT16 NewMask;
UINT32 Granularity; UINT32 Granularity;
EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor; EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
Location = 0; Location = 0;
Alignment = 0; Alignment = 0;
@ -300,23 +298,23 @@ ShadowAndStartLegacy16 (
// end testtest // end testtest
// //
EfiToLegacy16BootTable = &Private->IntThunk->EfiToLegacy16BootTable; EfiToLegacy16BootTable = &Private->IntThunk->EfiToLegacy16BootTable;
Status = Private->LegacyBiosPlatform->GetPlatformInfo ( Status = Private->LegacyBiosPlatform->GetPlatformInfo (
Private->LegacyBiosPlatform, Private->LegacyBiosPlatform,
EfiGetPlatformBinarySystemRom, EfiGetPlatformBinarySystemRom,
&LegacyBiosImage, &LegacyBiosImage,
&LegacyBiosImageSize, &LegacyBiosImageSize,
&Location, &Location,
&Alignment, &Alignment,
0, 0,
0 0
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
Private->BiosStart = (UINT32) (0x100000 - LegacyBiosImageSize); Private->BiosStart = (UINT32)(0x100000 - LegacyBiosImageSize);
Private->OptionRom = 0xc0000; Private->OptionRom = 0xc0000;
Private->LegacyBiosImageSize = (UINT32) LegacyBiosImageSize; Private->LegacyBiosImageSize = (UINT32)LegacyBiosImageSize;
// //
// Can only shadow into memory allocated for legacy usage. // Can only shadow into memory allocated for legacy usage.
@ -328,20 +326,20 @@ ShadowAndStartLegacy16 (
// //
Private->LegacyRegion->UnLock (Private->LegacyRegion, 0xc0000, 0x40000, &Granularity); Private->LegacyRegion->UnLock (Private->LegacyRegion, 0xc0000, 0x40000, &Granularity);
ClearPtr = (VOID *) ((UINTN) 0xc0000); ClearPtr = (VOID *)((UINTN)0xc0000);
// //
// Initialize region from 0xc0000 to start of BIOS to all ffs. This allows unused // Initialize region from 0xc0000 to start of BIOS to all ffs. This allows unused
// regions to be used by EMM386 etc. // regions to be used by EMM386 etc.
// //
SetMem ((VOID *) ClearPtr, (UINTN) (0x40000 - LegacyBiosImageSize), 0xff); SetMem ((VOID *)ClearPtr, (UINTN)(0x40000 - LegacyBiosImageSize), 0xff);
TempData = Private->BiosStart; TempData = Private->BiosStart;
CopyMem ( CopyMem (
(VOID *) TempData, (VOID *)TempData,
LegacyBiosImage, LegacyBiosImage,
(UINTN) LegacyBiosImageSize (UINTN)LegacyBiosImageSize
); );
Private->Cpu->FlushDataCache (Private->Cpu, 0xc0000, 0x40000, EfiCpuFlushTypeWriteBackInvalidate); Private->Cpu->FlushDataCache (Private->Cpu, 0xc0000, 0x40000, EfiCpuFlushTypeWriteBackInvalidate);
@ -351,12 +349,12 @@ ShadowAndStartLegacy16 (
// //
Done = FALSE; Done = FALSE;
Table = NULL; Table = NULL;
for (Ptr = (UINT8 *) TempData; Ptr < (UINT8 *) ((UINTN) 0x100000) && !Done; Ptr += 0x10) { for (Ptr = (UINT8 *)TempData; Ptr < (UINT8 *)((UINTN)0x100000) && !Done; Ptr += 0x10) {
if (*(UINT32 *) Ptr == SIGNATURE_32 ('I', 'F', 'E', '$')) { if (*(UINT32 *)Ptr == SIGNATURE_32 ('I', 'F', 'E', '$')) {
Table = (EFI_COMPATIBILITY16_TABLE *) Ptr; Table = (EFI_COMPATIBILITY16_TABLE *)Ptr;
PtrEnd = Ptr + Table->TableLength; PtrEnd = Ptr + Table->TableLength;
for (CheckSum = 0; Ptr < PtrEnd; Ptr++) { for (CheckSum = 0; Ptr < PtrEnd; Ptr++) {
CheckSum = (UINT8) (CheckSum +*Ptr); CheckSum = (UINT8)(CheckSum +*Ptr);
} }
Done = TRUE; Done = TRUE;
@ -378,24 +376,24 @@ ShadowAndStartLegacy16 (
// //
// Remember location of the Legacy16 table // Remember location of the Legacy16 table
// //
Private->Legacy16Table = Table; Private->Legacy16Table = Table;
Private->Legacy16CallSegment = Table->Compatibility16CallSegment; Private->Legacy16CallSegment = Table->Compatibility16CallSegment;
Private->Legacy16CallOffset = Table->Compatibility16CallOffset; Private->Legacy16CallOffset = Table->Compatibility16CallOffset;
EfiToLegacy16InitTable = &Private->IntThunk->EfiToLegacy16InitTable; EfiToLegacy16InitTable = &Private->IntThunk->EfiToLegacy16InitTable;
Private->Legacy16InitPtr = EfiToLegacy16InitTable; Private->Legacy16InitPtr = EfiToLegacy16InitTable;
Private->Legacy16BootPtr = &Private->IntThunk->EfiToLegacy16BootTable; Private->Legacy16BootPtr = &Private->IntThunk->EfiToLegacy16BootTable;
Private->InternalIrqRoutingTable = NULL; Private->InternalIrqRoutingTable = NULL;
Private->NumberIrqRoutingEntries = 0; Private->NumberIrqRoutingEntries = 0;
Private->BbsTablePtr = NULL; Private->BbsTablePtr = NULL;
Private->LegacyEfiHddTable = NULL; Private->LegacyEfiHddTable = NULL;
Private->DiskEnd = 0; Private->DiskEnd = 0;
Private->Disk4075 = 0; Private->Disk4075 = 0;
Private->HddTablePtr = &Private->IntThunk->EfiToLegacy16BootTable.HddInfo; Private->HddTablePtr = &Private->IntThunk->EfiToLegacy16BootTable.HddInfo;
Private->NumberHddControllers = MAX_IDE_CONTROLLER; Private->NumberHddControllers = MAX_IDE_CONTROLLER;
Private->Dump[0] = 'D'; Private->Dump[0] = 'D';
Private->Dump[1] = 'U'; Private->Dump[1] = 'U';
Private->Dump[2] = 'M'; Private->Dump[2] = 'M';
Private->Dump[3] = 'P'; Private->Dump[3] = 'P';
ZeroMem ( ZeroMem (
Private->Legacy16BootPtr, Private->Legacy16BootPtr,
@ -405,7 +403,7 @@ ShadowAndStartLegacy16 (
// //
// Store away a copy of the EFI System Table // Store away a copy of the EFI System Table
// //
Table->EfiSystemTable = (UINT32) (UINTN) gST; Table->EfiSystemTable = (UINT32)(UINTN)gST;
// //
// IPF CSM integration -Bug // IPF CSM integration -Bug
@ -423,31 +421,31 @@ ShadowAndStartLegacy16 (
// //
// All legacy interrupt should be masked when do initialization work from legacy 16 code. // All legacy interrupt should be masked when do initialization work from legacy 16 code.
// //
Private->Legacy8259->GetMask(Private->Legacy8259, &OldMask, NULL, NULL, NULL); Private->Legacy8259->GetMask (Private->Legacy8259, &OldMask, NULL, NULL, NULL);
NewMask = 0xFFFF; NewMask = 0xFFFF;
Private->Legacy8259->SetMask(Private->Legacy8259, &NewMask, NULL, NULL, NULL); Private->Legacy8259->SetMask (Private->Legacy8259, &NewMask, NULL, NULL, NULL);
// //
// Call into Legacy16 code to do an INIT // Call into Legacy16 code to do an INIT
// //
ZeroMem (&Regs, sizeof (EFI_IA32_REGISTER_SET)); ZeroMem (&Regs, sizeof (EFI_IA32_REGISTER_SET));
Regs.X.AX = Legacy16InitializeYourself; Regs.X.AX = Legacy16InitializeYourself;
Regs.X.ES = EFI_SEGMENT (*((UINT32 *) &EfiToLegacy16InitTable)); Regs.X.ES = EFI_SEGMENT (*((UINT32 *)&EfiToLegacy16InitTable));
Regs.X.BX = EFI_OFFSET (*((UINT32 *) &EfiToLegacy16InitTable)); Regs.X.BX = EFI_OFFSET (*((UINT32 *)&EfiToLegacy16InitTable));
Private->LegacyBios.FarCall86 ( Private->LegacyBios.FarCall86 (
&Private->LegacyBios, &Private->LegacyBios,
Table->Compatibility16CallSegment, Table->Compatibility16CallSegment,
Table->Compatibility16CallOffset, Table->Compatibility16CallOffset,
&Regs, &Regs,
NULL, NULL,
0 0
); );
// //
// Restore original legacy interrupt mask value // Restore original legacy interrupt mask value
// //
Private->Legacy8259->SetMask(Private->Legacy8259, &OldMask, NULL, NULL, NULL); Private->Legacy8259->SetMask (Private->Legacy8259, &OldMask, NULL, NULL, NULL);
if (Regs.X.AX != 0) { if (Regs.X.AX != 0) {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
@ -469,30 +467,31 @@ ShadowAndStartLegacy16 (
// //
ZeroMem (&Regs, sizeof (EFI_IA32_REGISTER_SET)); ZeroMem (&Regs, sizeof (EFI_IA32_REGISTER_SET));
Regs.X.AX = Legacy16GetTableAddress; Regs.X.AX = Legacy16GetTableAddress;
Regs.X.CX = (UINT16) E820Size; Regs.X.CX = (UINT16)E820Size;
Regs.X.DX = 1; Regs.X.DX = 1;
Private->LegacyBios.FarCall86 ( Private->LegacyBios.FarCall86 (
&Private->LegacyBios, &Private->LegacyBios,
Table->Compatibility16CallSegment, Table->Compatibility16CallSegment,
Table->Compatibility16CallOffset, Table->Compatibility16CallOffset,
&Regs, &Regs,
NULL, NULL,
0 0
); );
Table->E820Pointer = (UINT32) (Regs.X.DS * 16 + Regs.X.BX); Table->E820Pointer = (UINT32)(Regs.X.DS * 16 + Regs.X.BX);
Table->E820Length = (UINT32) E820Size; Table->E820Length = (UINT32)E820Size;
if (Regs.X.AX != 0) { if (Regs.X.AX != 0) {
DEBUG ((DEBUG_ERROR, "Legacy16 E820 length insufficient\n")); DEBUG ((DEBUG_ERROR, "Legacy16 E820 length insufficient\n"));
} else { } else {
TempData = Table->E820Pointer; TempData = Table->E820Pointer;
CopyMem ((VOID *) TempData, Private->E820Table, E820Size); CopyMem ((VOID *)TempData, Private->E820Table, E820Size);
} }
// //
// Get PnPInstallationCheck Info. // Get PnPInstallationCheck Info.
// //
Private->PnPInstallationCheckSegment = Table->PnPInstallationCheckSegment; Private->PnPInstallationCheckSegment = Table->PnPInstallationCheckSegment;
Private->PnPInstallationCheckOffset = Table->PnPInstallationCheckOffset; Private->PnPInstallationCheckOffset = Table->PnPInstallationCheckOffset;
// //
// Check if PCI Express is supported. If yes, Save base address. // Check if PCI Express is supported. If yes, Save base address.
@ -508,9 +507,10 @@ ShadowAndStartLegacy16 (
0 0
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
Private->Legacy16Table->PciExpressBase = (UINT32)Location; Private->Legacy16Table->PciExpressBase = (UINT32)Location;
Location = 0; Location = 0;
} }
// //
// Check if TPM is supported. If yes get a region in E0000,F0000 to copy it // Check if TPM is supported. If yes get a region in E0000,F0000 to copy it
// into, copy it and update pointer to binary image. This needs to be // into, copy it and update pointer to binary image. This needs to be
@ -527,35 +527,34 @@ ShadowAndStartLegacy16 (
0 0
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
ZeroMem (&Regs, sizeof (EFI_IA32_REGISTER_SET)); ZeroMem (&Regs, sizeof (EFI_IA32_REGISTER_SET));
Regs.X.AX = Legacy16GetTableAddress; Regs.X.AX = Legacy16GetTableAddress;
Regs.X.CX = (UINT16) TpmBinaryImageSize; Regs.X.CX = (UINT16)TpmBinaryImageSize;
Regs.X.DX = 1; Regs.X.DX = 1;
Private->LegacyBios.FarCall86 ( Private->LegacyBios.FarCall86 (
&Private->LegacyBios, &Private->LegacyBios,
Table->Compatibility16CallSegment, Table->Compatibility16CallSegment,
Table->Compatibility16CallOffset, Table->Compatibility16CallOffset,
&Regs, &Regs,
NULL, NULL,
0 0
); );
TpmPointer = (UINT32) (Regs.X.DS * 16 + Regs.X.BX); TpmPointer = (UINT32)(Regs.X.DS * 16 + Regs.X.BX);
if (Regs.X.AX != 0) { if (Regs.X.AX != 0) {
DEBUG ((DEBUG_ERROR, "TPM cannot be loaded\n")); DEBUG ((DEBUG_ERROR, "TPM cannot be loaded\n"));
} else { } else {
CopyMem ((VOID *) (UINTN)TpmPointer, TpmBinaryImage, TpmBinaryImageSize); CopyMem ((VOID *)(UINTN)TpmPointer, TpmBinaryImage, TpmBinaryImageSize);
Table->TpmSegment = Regs.X.DS; Table->TpmSegment = Regs.X.DS;
Table->TpmOffset = Regs.X.BX; Table->TpmOffset = Regs.X.BX;
} }
} }
// //
// Lock the Legacy BIOS region // Lock the Legacy BIOS region
// //
Private->Cpu->FlushDataCache (Private->Cpu, Private->BiosStart, (UINT32) LegacyBiosImageSize, EfiCpuFlushTypeWriteBackInvalidate); Private->Cpu->FlushDataCache (Private->Cpu, Private->BiosStart, (UINT32)LegacyBiosImageSize, EfiCpuFlushTypeWriteBackInvalidate);
Private->LegacyRegion->Lock (Private->LegacyRegion, Private->BiosStart, (UINT32) LegacyBiosImageSize, &Granularity); Private->LegacyRegion->Lock (Private->LegacyRegion, Private->BiosStart, (UINT32)LegacyBiosImageSize, &Granularity);
// //
// Get the BbsTable from LOW_MEMORY_THUNK // Get the BbsTable from LOW_MEMORY_THUNK
@ -563,8 +562,8 @@ ShadowAndStartLegacy16 (
BbsTable = (BBS_TABLE *)(UINTN)Private->IntThunk->BbsTable; BbsTable = (BBS_TABLE *)(UINTN)Private->IntThunk->BbsTable;
ZeroMem ((VOID *)BbsTable, sizeof (Private->IntThunk->BbsTable)); ZeroMem ((VOID *)BbsTable, sizeof (Private->IntThunk->BbsTable));
EfiToLegacy16BootTable->BbsTable = (UINT32)(UINTN)BbsTable; EfiToLegacy16BootTable->BbsTable = (UINT32)(UINTN)BbsTable;
Private->BbsTablePtr = (VOID *) BbsTable; Private->BbsTablePtr = (VOID *)BbsTable;
// //
// Populate entire table with BBS_IGNORE_ENTRY // Populate entire table with BBS_IGNORE_ENTRY
@ -574,10 +573,11 @@ ShadowAndStartLegacy16 (
for (Index = 0; Index < MAX_BBS_ENTRIES; Index++) { for (Index = 0; Index < MAX_BBS_ENTRIES; Index++) {
BbsTable[Index].BootPriority = BBS_IGNORE_ENTRY; BbsTable[Index].BootPriority = BBS_IGNORE_ENTRY;
} }
// //
// Allocate space for Legacy HDD table // Allocate space for Legacy HDD table
// //
LegacyEfiHddTable = (LEGACY_EFI_HDD_TABLE *) AllocateZeroPool ((UINTN) MAX_HDD_ENTRIES * sizeof (LEGACY_EFI_HDD_TABLE)); LegacyEfiHddTable = (LEGACY_EFI_HDD_TABLE *)AllocateZeroPool ((UINTN)MAX_HDD_ENTRIES * sizeof (LEGACY_EFI_HDD_TABLE));
ASSERT (LegacyEfiHddTable); ASSERT (LegacyEfiHddTable);
Private->LegacyEfiHddTable = LegacyEfiHddTable; Private->LegacyEfiHddTable = LegacyEfiHddTable;
@ -612,7 +612,7 @@ ShadowAndStartLegacy16 (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
LegacyBiosShadowAllLegacyOproms ( LegacyBiosShadowAllLegacyOproms (
IN EFI_LEGACY_BIOS_PROTOCOL *This IN EFI_LEGACY_BIOS_PROTOCOL *This
) )
{ {
LEGACY_BIOS_INSTANCE *Private; LEGACY_BIOS_INSTANCE *Private;
@ -657,16 +657,16 @@ LegacyBiosShadowAllLegacyOproms (
**/ **/
UINT16 UINT16
GetPciInterfaceVersion ( GetPciInterfaceVersion (
IN LEGACY_BIOS_INSTANCE *Private IN LEGACY_BIOS_INSTANCE *Private
) )
{ {
EFI_IA32_REGISTER_SET Reg; EFI_IA32_REGISTER_SET Reg;
BOOLEAN ThunkFailed; BOOLEAN ThunkFailed;
UINT16 PciInterfaceVersion; UINT16 PciInterfaceVersion;
PciInterfaceVersion = 0; PciInterfaceVersion = 0;
Reg.X.AX = 0xB101; Reg.X.AX = 0xB101;
Reg.E.EDI = 0; Reg.E.EDI = 0;
ThunkFailed = Private->LegacyBios.Int86 (&Private->LegacyBios, 0x1A, &Reg); ThunkFailed = Private->LegacyBios.Int86 (&Private->LegacyBios, 0x1A, &Reg);
@ -684,6 +684,7 @@ GetPciInterfaceVersion (
PciInterfaceVersion = Reg.X.BX; PciInterfaceVersion = Reg.X.BX;
} }
} }
return PciInterfaceVersion; return PciInterfaceVersion;
} }
@ -699,25 +700,25 @@ GetPciInterfaceVersion (
VOID VOID
EFIAPI EFIAPI
InstallSmbiosEventCallback ( InstallSmbiosEventCallback (
IN EFI_EVENT Event, IN EFI_EVENT Event,
IN VOID *Context IN VOID *Context
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
SMBIOS_TABLE_ENTRY_POINT *EntryPointStructure; SMBIOS_TABLE_ENTRY_POINT *EntryPointStructure;
// //
// Get SMBIOS table from EFI configuration table // Get SMBIOS table from EFI configuration table
// //
Status = EfiGetSystemConfigurationTable ( Status = EfiGetSystemConfigurationTable (
&gEfiSmbiosTableGuid, &gEfiSmbiosTableGuid,
&mRuntimeSmbiosEntryPoint &mRuntimeSmbiosEntryPoint
); );
if ((EFI_ERROR (Status)) || (mRuntimeSmbiosEntryPoint == NULL)) { if ((EFI_ERROR (Status)) || (mRuntimeSmbiosEntryPoint == NULL)) {
return; return;
} }
EntryPointStructure = (SMBIOS_TABLE_ENTRY_POINT *) mRuntimeSmbiosEntryPoint; EntryPointStructure = (SMBIOS_TABLE_ENTRY_POINT *)mRuntimeSmbiosEntryPoint;
// //
// Allocate memory for SMBIOS Entry Point Structure. // Allocate memory for SMBIOS Entry Point Structure.
@ -728,21 +729,23 @@ InstallSmbiosEventCallback (
// Entrypoint structure with fixed size is allocated only once. // Entrypoint structure with fixed size is allocated only once.
// //
mReserveSmbiosEntryPoint = SIZE_4GB - 1; mReserveSmbiosEntryPoint = SIZE_4GB - 1;
Status = gBS->AllocatePages ( Status = gBS->AllocatePages (
AllocateMaxAddress, AllocateMaxAddress,
EfiReservedMemoryType, EfiReservedMemoryType,
EFI_SIZE_TO_PAGES ((UINTN) (EntryPointStructure->EntryPointLength)), EFI_SIZE_TO_PAGES ((UINTN)(EntryPointStructure->EntryPointLength)),
&mReserveSmbiosEntryPoint &mReserveSmbiosEntryPoint
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
mReserveSmbiosEntryPoint = 0; mReserveSmbiosEntryPoint = 0;
return; return;
} }
DEBUG ((DEBUG_INFO, "Allocate memory for Smbios Entry Point Structure\n")); DEBUG ((DEBUG_INFO, "Allocate memory for Smbios Entry Point Structure\n"));
} }
if ((mStructureTableAddress != 0) && if ((mStructureTableAddress != 0) &&
(mStructureTablePages < EFI_SIZE_TO_PAGES ((UINT32)EntryPointStructure->TableLength))) { (mStructureTablePages < EFI_SIZE_TO_PAGES ((UINT32)EntryPointStructure->TableLength)))
{
// //
// If original buffer is not enough for the new SMBIOS table, free original buffer and re-allocate // If original buffer is not enough for the new SMBIOS table, free original buffer and re-allocate
// //
@ -759,22 +762,23 @@ InstallSmbiosEventCallback (
// //
mStructureTableAddress = SIZE_4GB - 1; mStructureTableAddress = SIZE_4GB - 1;
mStructureTablePages = EFI_SIZE_TO_PAGES (EntryPointStructure->TableLength); mStructureTablePages = EFI_SIZE_TO_PAGES (EntryPointStructure->TableLength);
Status = gBS->AllocatePages ( Status = gBS->AllocatePages (
AllocateMaxAddress, AllocateMaxAddress,
EfiReservedMemoryType, EfiReservedMemoryType,
mStructureTablePages, mStructureTablePages,
&mStructureTableAddress &mStructureTableAddress
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
gBS->FreePages ( gBS->FreePages (
mReserveSmbiosEntryPoint, mReserveSmbiosEntryPoint,
EFI_SIZE_TO_PAGES ((UINTN) (EntryPointStructure->EntryPointLength)) EFI_SIZE_TO_PAGES ((UINTN)(EntryPointStructure->EntryPointLength))
); );
mReserveSmbiosEntryPoint = 0; mReserveSmbiosEntryPoint = 0;
mStructureTableAddress = 0; mStructureTableAddress = 0;
mStructureTablePages = 0; mStructureTablePages = 0;
return; return;
} }
DEBUG ((DEBUG_INFO, "Allocate memory for Smbios Structure Table\n")); DEBUG ((DEBUG_INFO, "Allocate memory for Smbios Structure Table\n"));
} }
} }
@ -791,8 +795,8 @@ InstallSmbiosEventCallback (
VOID VOID
EFIAPI EFIAPI
ToggleEndOfDxeStatus ( ToggleEndOfDxeStatus (
IN EFI_EVENT Event, IN EFI_EVENT Event,
IN VOID *Context IN VOID *Context
) )
{ {
mEndOfDxe = TRUE; mEndOfDxe = TRUE;
@ -812,8 +816,8 @@ ToggleEndOfDxeStatus (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
LegacyBiosInstall ( LegacyBiosInstall (
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -850,7 +854,7 @@ LegacyBiosInstall (
// When UEFI Secure Boot is enabled, CSM module will not start any more. // When UEFI Secure Boot is enabled, CSM module will not start any more.
// //
SecureBoot = NULL; SecureBoot = NULL;
GetEfiGlobalVariable2 (EFI_SECURE_BOOT_MODE_NAME, (VOID**)&SecureBoot, NULL); GetEfiGlobalVariable2 (EFI_SECURE_BOOT_MODE_NAME, (VOID **)&SecureBoot, NULL);
if ((SecureBoot != NULL) && (*SecureBoot == SECURE_BOOT_MODE_ENABLE)) { if ((SecureBoot != NULL) && (*SecureBoot == SECURE_BOOT_MODE_ENABLE)) {
FreePool (SecureBoot); FreePool (SecureBoot);
return EFI_SECURITY_VIOLATION; return EFI_SECURITY_VIOLATION;
@ -867,22 +871,22 @@ LegacyBiosInstall (
// Grab a copy of all the protocols we depend on. Any error would // Grab a copy of all the protocols we depend on. Any error would
// be a dispatcher bug!. // be a dispatcher bug!.
// //
Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **) &Private->Cpu); Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&Private->Cpu);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
Status = gBS->LocateProtocol (&gEfiTimerArchProtocolGuid, NULL, (VOID **) &Private->Timer); Status = gBS->LocateProtocol (&gEfiTimerArchProtocolGuid, NULL, (VOID **)&Private->Timer);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
Status = gBS->LocateProtocol (&gEfiLegacyRegion2ProtocolGuid, NULL, (VOID **) &Private->LegacyRegion); Status = gBS->LocateProtocol (&gEfiLegacyRegion2ProtocolGuid, NULL, (VOID **)&Private->LegacyRegion);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
Status = gBS->LocateProtocol (&gEfiLegacyBiosPlatformProtocolGuid, NULL, (VOID **) &Private->LegacyBiosPlatform); Status = gBS->LocateProtocol (&gEfiLegacyBiosPlatformProtocolGuid, NULL, (VOID **)&Private->LegacyBiosPlatform);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
Status = gBS->LocateProtocol (&gEfiLegacy8259ProtocolGuid, NULL, (VOID **) &Private->Legacy8259); Status = gBS->LocateProtocol (&gEfiLegacy8259ProtocolGuid, NULL, (VOID **)&Private->Legacy8259);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
Status = gBS->LocateProtocol (&gEfiLegacyInterruptProtocolGuid, NULL, (VOID **) &Private->LegacyInterrupt); Status = gBS->LocateProtocol (&gEfiLegacyInterruptProtocolGuid, NULL, (VOID **)&Private->LegacyInterrupt);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
// //
@ -891,7 +895,7 @@ LegacyBiosInstall (
Status = gBS->LocateProtocol ( Status = gBS->LocateProtocol (
&gEfiGenericMemTestProtocolGuid, &gEfiGenericMemTestProtocolGuid,
NULL, NULL,
(VOID **) &Private->GenericMemoryTest (VOID **)&Private->GenericMemoryTest
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
@ -904,6 +908,7 @@ LegacyBiosInstall (
StartAddress = Descriptor.BaseAddress + Descriptor.Length; StartAddress = Descriptor.BaseAddress + Descriptor.Length;
continue; continue;
} }
Length = MIN (Descriptor.Length, 0xa0000 - StartAddress); Length = MIN (Descriptor.Length, 0xa0000 - StartAddress);
Private->GenericMemoryTest->CompatibleRangeTest ( Private->GenericMemoryTest->CompatibleRangeTest (
Private->GenericMemoryTest, Private->GenericMemoryTest,
@ -912,6 +917,7 @@ LegacyBiosInstall (
); );
StartAddress = StartAddress + Length; StartAddress = StartAddress + Length;
} }
// //
// Make sure all memory from 1MB to 16MB is tested and added to memory map // Make sure all memory from 1MB to 16MB is tested and added to memory map
// //
@ -921,6 +927,7 @@ LegacyBiosInstall (
StartAddress = Descriptor.BaseAddress + Descriptor.Length; StartAddress = Descriptor.BaseAddress + Descriptor.Length;
continue; continue;
} }
Length = MIN (Descriptor.Length, BASE_16MB - StartAddress); Length = MIN (Descriptor.Length, BASE_16MB - StartAddress);
Private->GenericMemoryTest->CompatibleRangeTest ( Private->GenericMemoryTest->CompatibleRangeTest (
Private->GenericMemoryTest, Private->GenericMemoryTest,
@ -932,17 +939,17 @@ LegacyBiosInstall (
Private->Signature = LEGACY_BIOS_INSTANCE_SIGNATURE; Private->Signature = LEGACY_BIOS_INSTANCE_SIGNATURE;
Private->LegacyBios.Int86 = LegacyBiosInt86; Private->LegacyBios.Int86 = LegacyBiosInt86;
Private->LegacyBios.FarCall86 = LegacyBiosFarCall86; Private->LegacyBios.FarCall86 = LegacyBiosFarCall86;
Private->LegacyBios.CheckPciRom = LegacyBiosCheckPciRom; Private->LegacyBios.CheckPciRom = LegacyBiosCheckPciRom;
Private->LegacyBios.InstallPciRom = LegacyBiosInstallPciRom; Private->LegacyBios.InstallPciRom = LegacyBiosInstallPciRom;
Private->LegacyBios.LegacyBoot = LegacyBiosLegacyBoot; Private->LegacyBios.LegacyBoot = LegacyBiosLegacyBoot;
Private->LegacyBios.UpdateKeyboardLedStatus = LegacyBiosUpdateKeyboardLedStatus; Private->LegacyBios.UpdateKeyboardLedStatus = LegacyBiosUpdateKeyboardLedStatus;
Private->LegacyBios.GetBbsInfo = LegacyBiosGetBbsInfo; Private->LegacyBios.GetBbsInfo = LegacyBiosGetBbsInfo;
Private->LegacyBios.ShadowAllLegacyOproms = LegacyBiosShadowAllLegacyOproms; Private->LegacyBios.ShadowAllLegacyOproms = LegacyBiosShadowAllLegacyOproms;
Private->LegacyBios.PrepareToBootEfi = LegacyBiosPrepareToBootEfi; Private->LegacyBios.PrepareToBootEfi = LegacyBiosPrepareToBootEfi;
Private->LegacyBios.GetLegacyRegion = LegacyBiosGetLegacyRegion; Private->LegacyBios.GetLegacyRegion = LegacyBiosGetLegacyRegion;
Private->LegacyBios.CopyLegacyRegion = LegacyBiosCopyLegacyRegion; Private->LegacyBios.CopyLegacyRegion = LegacyBiosCopyLegacyRegion;
Private->LegacyBios.BootUnconventionalDevice = LegacyBiosBootUnconventionalDevice; Private->LegacyBios.BootUnconventionalDevice = LegacyBiosBootUnconventionalDevice;
Private->ImageHandle = ImageHandle; Private->ImageHandle = ImageHandle;
@ -994,16 +1001,16 @@ LegacyBiosInstall (
); );
ASSERT (MemoryAddress == 0x000000000); ASSERT (MemoryAddress == 0x000000000);
ClearPtr = (VOID *) ((UINTN) 0x0000); ClearPtr = (VOID *)((UINTN)0x0000);
// //
// Initialize region from 0x0000 to 4k. This initializes interrupt vector // Initialize region from 0x0000 to 4k. This initializes interrupt vector
// range. // range.
// //
ACCESS_PAGE0_CODE ( ACCESS_PAGE0_CODE (
gBS->SetMem ((VOID *) ClearPtr, 0x400, INITIAL_VALUE_BELOW_1K); gBS->SetMem ((VOID *)ClearPtr, 0x400, INITIAL_VALUE_BELOW_1K);
ZeroMem ((VOID *) ((UINTN)ClearPtr + 0x400), 0xC00); ZeroMem ((VOID *)((UINTN)ClearPtr + 0x400), 0xC00);
); );
// //
// Allocate pages for OPROM usage // Allocate pages for OPROM usage
@ -1020,7 +1027,7 @@ LegacyBiosInstall (
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
ZeroMem ((VOID *) ((UINTN) MemoryAddress), MemorySize); ZeroMem ((VOID *)((UINTN)MemoryAddress), MemorySize);
// //
// Allocate all 32k chunks from 0x60000 ~ 0x88000 for Legacy OPROMs that // Allocate all 32k chunks from 0x60000 ~ 0x88000 for Legacy OPROMs that
@ -1028,8 +1035,8 @@ LegacyBiosInstall (
// OpROMs expect different areas to be free // OpROMs expect different areas to be free
// //
EbdaReservedBaseAddress = MemoryAddress; EbdaReservedBaseAddress = MemoryAddress;
MemoryAddress = PcdGet32 (PcdOpromReservedMemoryBase); MemoryAddress = PcdGet32 (PcdOpromReservedMemoryBase);
MemorySize = PcdGet32 (PcdOpromReservedMemorySize); MemorySize = PcdGet32 (PcdOpromReservedMemorySize);
// //
// Check if base address and size for reserved memory are 4KB aligned. // Check if base address and size for reserved memory are 4KB aligned.
// //
@ -1048,7 +1055,7 @@ LegacyBiosInstall (
&StartAddress &StartAddress
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
MemoryPtr = (VOID *) ((UINTN) StartAddress); MemoryPtr = (VOID *)((UINTN)StartAddress);
ZeroMem (MemoryPtr, 0x1000); ZeroMem (MemoryPtr, 0x1000);
} else { } else {
DEBUG ((DEBUG_ERROR, "WARNING: Allocate legacy memory fail for SCSI card - %x\n", MemStart)); DEBUG ((DEBUG_ERROR, "WARNING: Allocate legacy memory fail for SCSI card - %x\n", MemStart));
@ -1069,7 +1076,7 @@ LegacyBiosInstall (
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
ZeroMem ((VOID *) ((UINTN) MemoryAddressUnder1MB), MemorySize); ZeroMem ((VOID *)((UINTN)MemoryAddressUnder1MB), MemorySize);
// //
// Allocate space for thunker and Init Thunker // Allocate space for thunker and Init Thunker
@ -1082,10 +1089,10 @@ LegacyBiosInstall (
&MemoryAddress &MemoryAddress
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
Private->IntThunk = (LOW_MEMORY_THUNK *) (UINTN) MemoryAddress; Private->IntThunk = (LOW_MEMORY_THUNK *)(UINTN)MemoryAddress;
EfiToLegacy16InitTable = &Private->IntThunk->EfiToLegacy16InitTable; EfiToLegacy16InitTable = &Private->IntThunk->EfiToLegacy16InitTable;
EfiToLegacy16InitTable->ThunkStart = (UINT32) (EFI_PHYSICAL_ADDRESS) (UINTN) MemoryAddress; EfiToLegacy16InitTable->ThunkStart = (UINT32)(EFI_PHYSICAL_ADDRESS)(UINTN)MemoryAddress;
EfiToLegacy16InitTable->ThunkSizeInBytes = (UINT32) (sizeof (LOW_MEMORY_THUNK)); EfiToLegacy16InitTable->ThunkSizeInBytes = (UINT32)(sizeof (LOW_MEMORY_THUNK));
Status = LegacyBiosInitializeThunk (Private); Status = LegacyBiosInitializeThunk (Private);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
@ -1093,8 +1100,8 @@ LegacyBiosInstall (
// //
// Init the legacy memory map in memory < 1 MB. // Init the legacy memory map in memory < 1 MB.
// //
EfiToLegacy16InitTable->BiosLessThan1MB = (UINT32) MemoryAddressUnder1MB; EfiToLegacy16InitTable->BiosLessThan1MB = (UINT32)MemoryAddressUnder1MB;
EfiToLegacy16InitTable->LowPmmMemory = (UINT32) MemoryAddressUnder1MB; EfiToLegacy16InitTable->LowPmmMemory = (UINT32)MemoryAddressUnder1MB;
EfiToLegacy16InitTable->LowPmmMemorySizeInBytes = MemorySize; EfiToLegacy16InitTable->LowPmmMemorySizeInBytes = MemorySize;
MemorySize = PcdGet32 (PcdHighPmmMemorySize); MemorySize = PcdGet32 (PcdHighPmmMemorySize);
@ -1121,8 +1128,9 @@ LegacyBiosInstall (
&MemoryAddress &MemoryAddress
); );
} }
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
EfiToLegacy16InitTable->HiPmmMemory = (UINT32) (EFI_PHYSICAL_ADDRESS) (UINTN) MemoryAddress; EfiToLegacy16InitTable->HiPmmMemory = (UINT32)(EFI_PHYSICAL_ADDRESS)(UINTN)MemoryAddress;
EfiToLegacy16InitTable->HiPmmMemorySizeInBytes = MemorySize; EfiToLegacy16InitTable->HiPmmMemorySizeInBytes = MemorySize;
} }
@ -1135,32 +1143,34 @@ LegacyBiosInstall (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// Initialize interrupt redirection code and entries; // Initialize interrupt redirection code and entries;
// IDT Vectors 0x68-0x6f must be redirected to IDT Vectors 0x08-0x0f. // IDT Vectors 0x68-0x6f must be redirected to IDT Vectors 0x08-0x0f.
// //
CopyMem ( CopyMem (
Private->IntThunk->InterruptRedirectionCode, Private->IntThunk->InterruptRedirectionCode,
(VOID *) (UINTN) InterruptRedirectionTemplate, (VOID *)(UINTN)InterruptRedirectionTemplate,
sizeof (Private->IntThunk->InterruptRedirectionCode) sizeof (Private->IntThunk->InterruptRedirectionCode)
); );
// //
// Save Unexpected interrupt vector so can restore it just prior to boot // Save Unexpected interrupt vector so can restore it just prior to boot
// //
ACCESS_PAGE0_CODE ( ACCESS_PAGE0_CODE (
BaseVectorMaster = (UINT32 *) (sizeof (UINT32) * PROTECTED_MODE_BASE_VECTOR_MASTER); BaseVectorMaster = (UINT32 *)(sizeof (UINT32) * PROTECTED_MODE_BASE_VECTOR_MASTER);
Private->BiosUnexpectedInt = BaseVectorMaster[0]; Private->BiosUnexpectedInt = BaseVectorMaster[0];
IntRedirCode = (UINT32) (UINTN) Private->IntThunk->InterruptRedirectionCode; IntRedirCode = (UINT32)(UINTN)Private->IntThunk->InterruptRedirectionCode;
for (Index = 0; Index < 8; Index++) { for (Index = 0; Index < 8; Index++) {
BaseVectorMaster[Index] = (EFI_SEGMENT (IntRedirCode + Index * 4) << 16) | EFI_OFFSET (IntRedirCode + Index * 4); BaseVectorMaster[Index] = (EFI_SEGMENT (IntRedirCode + Index * 4) << 16) | EFI_OFFSET (IntRedirCode + Index * 4);
} }
);
);
// //
// Save EFI value // Save EFI value
// //
Private->ThunkSeg = (UINT16) (EFI_SEGMENT (IntRedirCode)); Private->ThunkSeg = (UINT16)(EFI_SEGMENT (IntRedirCode));
// //
// Allocate reserved memory for SMBIOS table used in legacy boot if SMBIOS table exists // Allocate reserved memory for SMBIOS table used in legacy boot if SMBIOS table exists
@ -1198,18 +1208,20 @@ LegacyBiosInstall (
// Make a new handle and install the protocol // Make a new handle and install the protocol
// //
Private->Handle = NULL; Private->Handle = NULL;
Status = gBS->InstallProtocolInterface ( Status = gBS->InstallProtocolInterface (
&Private->Handle, &Private->Handle,
&gEfiLegacyBiosProtocolGuid, &gEfiLegacyBiosProtocolGuid,
EFI_NATIVE_INTERFACE, EFI_NATIVE_INTERFACE,
&Private->LegacyBios &Private->LegacyBios
); );
Private->Csm16PciInterfaceVersion = GetPciInterfaceVersion (Private); Private->Csm16PciInterfaceVersion = GetPciInterfaceVersion (Private);
DEBUG ((DEBUG_INFO, "CSM16 PCI BIOS Interface Version: %02x.%02x\n", DEBUG ((
(UINT8) (Private->Csm16PciInterfaceVersion >> 8), DEBUG_INFO,
(UINT8) Private->Csm16PciInterfaceVersion "CSM16 PCI BIOS Interface Version: %02x.%02x\n",
)); (UINT8)(Private->Csm16PciInterfaceVersion >> 8),
(UINT8)Private->Csm16PciInterfaceVersion
));
ASSERT (Private->Csm16PciInterfaceVersion != 0); ASSERT (Private->Csm16PciInterfaceVersion != 0);
return Status; return Status;
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -66,12 +66,12 @@ LegacyCalculateWriteStandardCmosChecksum (
for (Checksum = 0, Register = 0x10; Register < 0x2e; Register++) { for (Checksum = 0, Register = 0x10; Register < 0x2e; Register++) {
Checksum = (UINT16)(Checksum + LegacyReadStandardCmos (Register)); Checksum = (UINT16)(Checksum + LegacyReadStandardCmos (Register));
} }
LegacyWriteStandardCmos (CMOS_2E, (UINT8)(Checksum >> 8)); LegacyWriteStandardCmos (CMOS_2E, (UINT8)(Checksum >> 8));
LegacyWriteStandardCmos (CMOS_2F, (UINT8)(Checksum & 0xff)); LegacyWriteStandardCmos (CMOS_2F, (UINT8)(Checksum & 0xff));
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Fill in the standard CMOS stuff before Legacy16 load Fill in the standard CMOS stuff before Legacy16 load
@ -82,7 +82,7 @@ LegacyCalculateWriteStandardCmosChecksum (
**/ **/
EFI_STATUS EFI_STATUS
LegacyBiosInitCmos ( LegacyBiosInitCmos (
IN LEGACY_BIOS_INSTANCE *Private IN LEGACY_BIOS_INSTANCE *Private
) )
{ {
UINT32 Size; UINT32 Size;
@ -103,7 +103,7 @@ LegacyBiosInitCmos (
Size = 15 * SIZE_1MB; Size = 15 * SIZE_1MB;
if (Private->IntThunk->EfiToLegacy16InitTable.OsMemoryAbove1Mb < (15 * SIZE_1MB)) { if (Private->IntThunk->EfiToLegacy16InitTable.OsMemoryAbove1Mb < (15 * SIZE_1MB)) {
Size = Private->IntThunk->EfiToLegacy16InitTable.OsMemoryAbove1Mb >> 10; Size = Private->IntThunk->EfiToLegacy16InitTable.OsMemoryAbove1Mb >> 10;
} }
LegacyWriteStandardCmos (CMOS_17, (UINT8)(Size & 0xFF)); LegacyWriteStandardCmos (CMOS_17, (UINT8)(Size & 0xFF));

View File

@ -9,7 +9,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "LegacyBiosInterface.h" #include "LegacyBiosInterface.h"
BOOLEAN mIdeDataBuiltFlag = FALSE; BOOLEAN mIdeDataBuiltFlag = FALSE;
/** /**
Collect IDE Inquiry data from the IDE disks Collect IDE Inquiry data from the IDE disks
@ -23,9 +23,9 @@ BOOLEAN mIdeDataBuiltFlag = FALSE;
**/ **/
EFI_STATUS EFI_STATUS
LegacyBiosBuildIdeData ( LegacyBiosBuildIdeData (
IN LEGACY_BIOS_INSTANCE *Private, IN LEGACY_BIOS_INSTANCE *Private,
IN HDD_INFO **HddInfo, IN HDD_INFO **HddInfo,
IN UINT16 Flag IN UINT16 Flag
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -60,14 +60,14 @@ LegacyBiosBuildIdeData (
// //
PciDevicePath = NULL; PciDevicePath = NULL;
LocalHddInfo = *HddInfo; LocalHddInfo = *HddInfo;
Status = Private->LegacyBiosPlatform->GetPlatformHandle ( Status = Private->LegacyBiosPlatform->GetPlatformHandle (
Private->LegacyBiosPlatform, Private->LegacyBiosPlatform,
EfiGetPlatformIdeHandle, EfiGetPlatformIdeHandle,
0, 0,
&HandleBuffer, &HandleBuffer,
&HandleCount, &HandleCount,
(VOID *) &LocalHddInfo (VOID *)&LocalHddInfo
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
IdeController = HandleBuffer[0]; IdeController = HandleBuffer[0];
// //
@ -75,10 +75,10 @@ LegacyBiosBuildIdeData (
// //
if (Flag != 0) { if (Flag != 0) {
gBS->DisconnectController ( gBS->DisconnectController (
IdeController, IdeController,
NULL, NULL,
NULL NULL
); );
} }
gBS->ConnectController (IdeController, NULL, NULL, FALSE); gBS->ConnectController (IdeController, NULL, NULL, FALSE);
@ -88,13 +88,13 @@ LegacyBiosBuildIdeData (
// And GetIdeHandle will switch to Legacy mode, if required. // And GetIdeHandle will switch to Legacy mode, if required.
// //
Private->LegacyBiosPlatform->GetPlatformHandle ( Private->LegacyBiosPlatform->GetPlatformHandle (
Private->LegacyBiosPlatform, Private->LegacyBiosPlatform,
EfiGetPlatformIdeHandle, EfiGetPlatformIdeHandle,
0, 0,
&HandleBuffer, &HandleBuffer,
&HandleCount, &HandleCount,
(VOID *) &LocalHddInfo (VOID *)&LocalHddInfo
); );
} }
mIdeDataBuiltFlag = TRUE; mIdeDataBuiltFlag = TRUE;
@ -103,19 +103,19 @@ LegacyBiosBuildIdeData (
// Get Identity command from all drives // Get Identity command from all drives
// //
gBS->LocateHandleBuffer ( gBS->LocateHandleBuffer (
ByProtocol, ByProtocol,
&gEfiDiskInfoProtocolGuid, &gEfiDiskInfoProtocolGuid,
NULL, NULL,
&HandleCount, &HandleCount,
&HandleBuffer &HandleBuffer
); );
Private->IdeDriveCount = (UINT8) HandleCount; Private->IdeDriveCount = (UINT8)HandleCount;
for (Index = 0; Index < HandleCount; Index++) { for (Index = 0; Index < HandleCount; Index++) {
Status = gBS->HandleProtocol ( Status = gBS->HandleProtocol (
HandleBuffer[Index], HandleBuffer[Index],
&gEfiDiskInfoProtocolGuid, &gEfiDiskInfoProtocolGuid,
(VOID **) &DiskInfo (VOID **)&DiskInfo
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
@ -126,7 +126,7 @@ LegacyBiosBuildIdeData (
Status = gBS->HandleProtocol ( Status = gBS->HandleProtocol (
HandleBuffer[Index], HandleBuffer[Index],
&gEfiDevicePathProtocolGuid, &gEfiDevicePathProtocolGuid,
(VOID *) &DevicePath (VOID *)&DevicePath
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
@ -134,12 +134,14 @@ LegacyBiosBuildIdeData (
while (!IsDevicePathEnd (DevicePathNode)) { while (!IsDevicePathEnd (DevicePathNode)) {
TempDevicePathNode = NextDevicePathNode (DevicePathNode); TempDevicePathNode = NextDevicePathNode (DevicePathNode);
if ((DevicePathType (DevicePathNode) == HARDWARE_DEVICE_PATH) && if ((DevicePathType (DevicePathNode) == HARDWARE_DEVICE_PATH) &&
( DevicePathSubType (DevicePathNode) == HW_PCI_DP) && (DevicePathSubType (DevicePathNode) == HW_PCI_DP) &&
( DevicePathType(TempDevicePathNode) == MESSAGING_DEVICE_PATH) && (DevicePathType (TempDevicePathNode) == MESSAGING_DEVICE_PATH) &&
( DevicePathSubType(TempDevicePathNode) == MSG_ATAPI_DP) ) { (DevicePathSubType (TempDevicePathNode) == MSG_ATAPI_DP))
PciDevicePath = (PCI_DEVICE_PATH *) DevicePathNode; {
PciDevicePath = (PCI_DEVICE_PATH *)DevicePathNode;
break; break;
} }
DevicePathNode = NextDevicePathNode (DevicePathNode); DevicePathNode = NextDevicePathNode (DevicePathNode);
} }
@ -161,7 +163,8 @@ LegacyBiosBuildIdeData (
for (PciIndex = 0; PciIndex < 8; PciIndex++) { for (PciIndex = 0; PciIndex < 8; PciIndex++) {
if ((PciDevicePath->Device == LocalHddInfo[PciIndex].Device) && if ((PciDevicePath->Device == LocalHddInfo[PciIndex].Device) &&
(PciDevicePath->Function == LocalHddInfo[PciIndex].Function) (PciDevicePath->Function == LocalHddInfo[PciIndex].Function)
) { )
{
break; break;
} }
} }
@ -186,15 +189,15 @@ LegacyBiosBuildIdeData (
InquiryData = NULL; InquiryData = NULL;
InquiryDataSize = 0; InquiryDataSize = 0;
Status = DiskInfo->Inquiry ( Status = DiskInfo->Inquiry (
DiskInfo, DiskInfo,
NULL, NULL,
&InquiryDataSize &InquiryDataSize
); );
if (Status == EFI_BUFFER_TOO_SMALL) { if (Status == EFI_BUFFER_TOO_SMALL) {
InquiryData = (UINT8 *) AllocatePool ( InquiryData = (UINT8 *)AllocatePool (
InquiryDataSize InquiryDataSize
); );
if (InquiryData != NULL) { if (InquiryData != NULL) {
Status = DiskInfo->Inquiry ( Status = DiskInfo->Inquiry (
DiskInfo, DiskInfo,
@ -227,6 +230,7 @@ LegacyBiosBuildIdeData (
LocalHddInfo[PciIndex + IdeChannel].Status |= HDD_SLAVE_ATAPI_ZIPDISK; LocalHddInfo[PciIndex + IdeChannel].Status |= HDD_SLAVE_ATAPI_ZIPDISK;
} }
} }
FreePool (InquiryData); FreePool (InquiryData);
} else { } else {
if (IdeDevice == 0) { if (IdeDevice == 0) {
@ -246,7 +250,6 @@ LegacyBiosBuildIdeData (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
If the IDE channel is in compatibility (legacy) mode, remove all If the IDE channel is in compatibility (legacy) mode, remove all
PCI I/O BAR addresses from the controller. PCI I/O BAR addresses from the controller.
@ -257,13 +260,13 @@ LegacyBiosBuildIdeData (
**/ **/
VOID VOID
InitLegacyIdeController ( InitLegacyIdeController (
IN EFI_HANDLE IdeController IN EFI_HANDLE IdeController
) )
{ {
EFI_PCI_IO_PROTOCOL *PciIo; EFI_PCI_IO_PROTOCOL *PciIo;
UINT32 IOBarClear; UINT32 IOBarClear;
EFI_STATUS Status; EFI_STATUS Status;
PCI_TYPE00 PciData; PCI_TYPE00 PciData;
// //
// If the IDE channel is in compatibility (legacy) mode, remove all // If the IDE channel is in compatibility (legacy) mode, remove all
@ -277,20 +280,21 @@ InitLegacyIdeController (
(VOID **)&PciIo (VOID **)&PciIo
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return ; return;
} }
Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0, sizeof (PciData), &PciData); Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0, sizeof (PciData), &PciData);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return ; return;
} }
// //
// Check whether this is IDE // Check whether this is IDE
// //
if ((PciData.Hdr.ClassCode[2] != PCI_CLASS_MASS_STORAGE) || if ((PciData.Hdr.ClassCode[2] != PCI_CLASS_MASS_STORAGE) ||
(PciData.Hdr.ClassCode[1] != PCI_CLASS_MASS_STORAGE_IDE)) { (PciData.Hdr.ClassCode[1] != PCI_CLASS_MASS_STORAGE_IDE))
return ; {
return;
} }
// //
@ -301,10 +305,11 @@ InitLegacyIdeController (
PciIo->Pci.Write (PciIo, EfiPciIoWidthUint32, 0x10, 1, &IOBarClear); PciIo->Pci.Write (PciIo, EfiPciIoWidthUint32, 0x10, 1, &IOBarClear);
PciIo->Pci.Write (PciIo, EfiPciIoWidthUint32, 0x14, 1, &IOBarClear); PciIo->Pci.Write (PciIo, EfiPciIoWidthUint32, 0x14, 1, &IOBarClear);
} }
if ((PciData.Hdr.ClassCode[0] & IDE_PI_REGISTER_SNE) == 0) { if ((PciData.Hdr.ClassCode[0] & IDE_PI_REGISTER_SNE) == 0) {
PciIo->Pci.Write (PciIo, EfiPciIoWidthUint32, 0x18, 1, &IOBarClear); PciIo->Pci.Write (PciIo, EfiPciIoWidthUint32, 0x18, 1, &IOBarClear);
PciIo->Pci.Write (PciIo, EfiPciIoWidthUint32, 0x1C, 1, &IOBarClear); PciIo->Pci.Write (PciIo, EfiPciIoWidthUint32, 0x1C, 1, &IOBarClear);
} }
return ; return;
} }

File diff suppressed because it is too large Load Diff

View File

@ -21,32 +21,32 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
EFI_STATUS EFI_STATUS
LegacyBiosBuildSioDataFromSio ( LegacyBiosBuildSioDataFromSio (
IN DEVICE_PRODUCER_DATA_HEADER *SioPtr IN DEVICE_PRODUCER_DATA_HEADER *SioPtr
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
DEVICE_PRODUCER_SERIAL *SioSerial; DEVICE_PRODUCER_SERIAL *SioSerial;
DEVICE_PRODUCER_PARALLEL *SioParallel; DEVICE_PRODUCER_PARALLEL *SioParallel;
DEVICE_PRODUCER_FLOPPY *SioFloppy; DEVICE_PRODUCER_FLOPPY *SioFloppy;
UINTN HandleCount; UINTN HandleCount;
EFI_HANDLE *HandleBuffer; EFI_HANDLE *HandleBuffer;
UINTN Index; UINTN Index;
UINTN ChildIndex; UINTN ChildIndex;
EFI_SIO_PROTOCOL *Sio; EFI_SIO_PROTOCOL *Sio;
ACPI_RESOURCE_HEADER_PTR Resources; ACPI_RESOURCE_HEADER_PTR Resources;
EFI_ACPI_IO_PORT_DESCRIPTOR *IoResource; EFI_ACPI_IO_PORT_DESCRIPTOR *IoResource;
EFI_ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR *FixedIoResource; EFI_ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR *FixedIoResource;
EFI_ACPI_DMA_DESCRIPTOR *DmaResource; EFI_ACPI_DMA_DESCRIPTOR *DmaResource;
EFI_ACPI_IRQ_NOFLAG_DESCRIPTOR *IrqResource; EFI_ACPI_IRQ_NOFLAG_DESCRIPTOR *IrqResource;
UINT16 Address; UINT16 Address;
UINT8 Dma; UINT8 Dma;
UINT8 Irq; UINT8 Irq;
UINTN EntryCount; UINTN EntryCount;
EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer; EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;
EFI_BLOCK_IO_PROTOCOL *BlockIo; EFI_BLOCK_IO_PROTOCOL *BlockIo;
EFI_SERIAL_IO_PROTOCOL *SerialIo; EFI_SERIAL_IO_PROTOCOL *SerialIo;
EFI_DEVICE_PATH_PROTOCOL *DevicePath; EFI_DEVICE_PATH_PROTOCOL *DevicePath;
ACPI_HID_DEVICE_PATH *Acpi; ACPI_HID_DEVICE_PATH *Acpi;
// //
// Get the list of ISA controllers in the system // Get the list of ISA controllers in the system
@ -61,11 +61,12 @@ LegacyBiosBuildSioDataFromSio (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
// //
// Collect legacy information from each of the ISA controllers in the system // Collect legacy information from each of the ISA controllers in the system
// //
for (Index = 0; Index < HandleCount; Index++) { for (Index = 0; Index < HandleCount; Index++) {
Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiSioProtocolGuid, (VOID **) &Sio); Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiSioProtocolGuid, (VOID **)&Sio);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
continue; continue;
} }
@ -73,46 +74,46 @@ LegacyBiosBuildSioDataFromSio (
Address = MAX_UINT16; Address = MAX_UINT16;
Dma = MAX_UINT8; Dma = MAX_UINT8;
Irq = MAX_UINT8; Irq = MAX_UINT8;
Status = Sio->GetResources (Sio, &Resources); Status = Sio->GetResources (Sio, &Resources);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
// //
// Get the base address information from ACPI resource descriptor. // Get the base address information from ACPI resource descriptor.
// //
while (Resources.SmallHeader->Byte != ACPI_END_TAG_DESCRIPTOR) { while (Resources.SmallHeader->Byte != ACPI_END_TAG_DESCRIPTOR) {
switch (Resources.SmallHeader->Byte) { switch (Resources.SmallHeader->Byte) {
case ACPI_IO_PORT_DESCRIPTOR: case ACPI_IO_PORT_DESCRIPTOR:
IoResource = (EFI_ACPI_IO_PORT_DESCRIPTOR *) Resources.SmallHeader; IoResource = (EFI_ACPI_IO_PORT_DESCRIPTOR *)Resources.SmallHeader;
Address = IoResource->BaseAddressMin; Address = IoResource->BaseAddressMin;
break; break;
case ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR: case ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR:
FixedIoResource = (EFI_ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR *) Resources.SmallHeader; FixedIoResource = (EFI_ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR *)Resources.SmallHeader;
Address = FixedIoResource->BaseAddress; Address = FixedIoResource->BaseAddress;
break; break;
case ACPI_DMA_DESCRIPTOR: case ACPI_DMA_DESCRIPTOR:
DmaResource = (EFI_ACPI_DMA_DESCRIPTOR *) Resources.SmallHeader; DmaResource = (EFI_ACPI_DMA_DESCRIPTOR *)Resources.SmallHeader;
Dma = (UINT8) LowBitSet32 (DmaResource->ChannelMask); Dma = (UINT8)LowBitSet32 (DmaResource->ChannelMask);
break; break;
case ACPI_IRQ_DESCRIPTOR: case ACPI_IRQ_DESCRIPTOR:
case ACPI_IRQ_NOFLAG_DESCRIPTOR: case ACPI_IRQ_NOFLAG_DESCRIPTOR:
IrqResource = (EFI_ACPI_IRQ_NOFLAG_DESCRIPTOR *) Resources.SmallHeader; IrqResource = (EFI_ACPI_IRQ_NOFLAG_DESCRIPTOR *)Resources.SmallHeader;
Irq = (UINT8) LowBitSet32 (IrqResource->Mask); Irq = (UINT8)LowBitSet32 (IrqResource->Mask);
break; break;
default: default:
break; break;
} }
if (Resources.SmallHeader->Bits.Type == 0) { if (Resources.SmallHeader->Bits.Type == 0) {
Resources.SmallHeader = (ACPI_SMALL_RESOURCE_HEADER *) ((UINT8 *) Resources.SmallHeader Resources.SmallHeader = (ACPI_SMALL_RESOURCE_HEADER *)((UINT8 *)Resources.SmallHeader
+ Resources.SmallHeader->Bits.Length + Resources.SmallHeader->Bits.Length
+ sizeof (*Resources.SmallHeader)); + sizeof (*Resources.SmallHeader));
} else { } else {
Resources.LargeHeader = (ACPI_LARGE_RESOURCE_HEADER *) ((UINT8 *) Resources.LargeHeader Resources.LargeHeader = (ACPI_LARGE_RESOURCE_HEADER *)((UINT8 *)Resources.LargeHeader
+ Resources.LargeHeader->Length + Resources.LargeHeader->Length
+ sizeof (*Resources.LargeHeader)); + sizeof (*Resources.LargeHeader));
} }
} }
} }
@ -126,13 +127,14 @@ LegacyBiosBuildSioDataFromSio (
Acpi = NULL; Acpi = NULL;
while (!IsDevicePathEnd (DevicePath)) { while (!IsDevicePathEnd (DevicePath)) {
Acpi = (ACPI_HID_DEVICE_PATH *) DevicePath; Acpi = (ACPI_HID_DEVICE_PATH *)DevicePath;
DevicePath = NextDevicePathNode (DevicePath); DevicePath = NextDevicePathNode (DevicePath);
} }
if ((Acpi == NULL) || (DevicePathType (Acpi) != ACPI_DEVICE_PATH) || if ((Acpi == NULL) || (DevicePathType (Acpi) != ACPI_DEVICE_PATH) ||
((DevicePathSubType (Acpi) != ACPI_DP) && (DevicePathSubType (Acpi) != ACPI_EXTENDED_DP)) ((DevicePathSubType (Acpi) != ACPI_DP) && (DevicePathSubType (Acpi) != ACPI_EXTENDED_DP))
) { )
{
continue; continue;
} }
@ -141,9 +143,8 @@ LegacyBiosBuildSioDataFromSio (
// //
// Ignore DMA resource since it is always returned NULL // Ignore DMA resource since it is always returned NULL
// //
if (Acpi->HID == EISA_PNP_ID (0x500) || Acpi->HID == EISA_PNP_ID (0x501)) { if ((Acpi->HID == EISA_PNP_ID (0x500)) || (Acpi->HID == EISA_PNP_ID (0x501))) {
if ((Acpi->UID < 4) && (Address != MAX_UINT16) && (Irq != MAX_UINT8)) {
if (Acpi->UID < 4 && Address != MAX_UINT16 && Irq != MAX_UINT8) {
// //
// Get the handle of the child device that has opened the Super I/O Protocol // Get the handle of the child device that has opened the Super I/O Protocol
// //
@ -156,14 +157,15 @@ LegacyBiosBuildSioDataFromSio (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
continue; continue;
} }
for (ChildIndex = 0; ChildIndex < EntryCount; ChildIndex++) { for (ChildIndex = 0; ChildIndex < EntryCount; ChildIndex++) {
if ((OpenInfoBuffer[ChildIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) { if ((OpenInfoBuffer[ChildIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
Status = gBS->HandleProtocol (OpenInfoBuffer[ChildIndex].ControllerHandle, &gEfiSerialIoProtocolGuid, (VOID **) &SerialIo); Status = gBS->HandleProtocol (OpenInfoBuffer[ChildIndex].ControllerHandle, &gEfiSerialIoProtocolGuid, (VOID **)&SerialIo);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
SioSerial = &SioPtr->Serial[Acpi->UID]; SioSerial = &SioPtr->Serial[Acpi->UID];
SioSerial->Address = Address; SioSerial->Address = Address;
SioSerial->Irq = Irq; SioSerial->Irq = Irq;
SioSerial->Mode = DEVICE_SERIAL_MODE_NORMAL | DEVICE_SERIAL_MODE_DUPLEX_HALF; SioSerial->Mode = DEVICE_SERIAL_MODE_NORMAL | DEVICE_SERIAL_MODE_DUPLEX_HALF;
break; break;
} }
} }
@ -172,36 +174,39 @@ LegacyBiosBuildSioDataFromSio (
FreePool (OpenInfoBuffer); FreePool (OpenInfoBuffer);
} }
} }
// //
// See if this is an ISA parallel port // See if this is an ISA parallel port
// //
// Ignore DMA resource since it is always returned NULL, port // Ignore DMA resource since it is always returned NULL, port
// only used in output mode. // only used in output mode.
// //
if (Acpi->HID == EISA_PNP_ID (0x400) || Acpi->HID == EISA_PNP_ID (0x401)) { if ((Acpi->HID == EISA_PNP_ID (0x400)) || (Acpi->HID == EISA_PNP_ID (0x401))) {
if (Acpi->UID < 3 && Address != MAX_UINT16 && Irq != MAX_UINT8 && Dma != MAX_UINT8) { if ((Acpi->UID < 3) && (Address != MAX_UINT16) && (Irq != MAX_UINT8) && (Dma != MAX_UINT8)) {
SioParallel = &SioPtr->Parallel[Acpi->UID]; SioParallel = &SioPtr->Parallel[Acpi->UID];
SioParallel->Address = Address; SioParallel->Address = Address;
SioParallel->Irq = Irq; SioParallel->Irq = Irq;
SioParallel->Dma = Dma; SioParallel->Dma = Dma;
SioParallel->Mode = DEVICE_PARALLEL_MODE_MODE_OUTPUT_ONLY; SioParallel->Mode = DEVICE_PARALLEL_MODE_MODE_OUTPUT_ONLY;
} }
} }
// //
// See if this is an ISA floppy controller // See if this is an ISA floppy controller
// //
if (Acpi->HID == EISA_PNP_ID (0x604)) { if (Acpi->HID == EISA_PNP_ID (0x604)) {
if (Address != MAX_UINT16 && Irq != MAX_UINT8 && Dma != MAX_UINT8) { if ((Address != MAX_UINT16) && (Irq != MAX_UINT8) && (Dma != MAX_UINT8)) {
Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiBlockIoProtocolGuid, (VOID **) &BlockIo); Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiBlockIoProtocolGuid, (VOID **)&BlockIo);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
SioFloppy = &SioPtr->Floppy; SioFloppy = &SioPtr->Floppy;
SioFloppy->Address = Address; SioFloppy->Address = Address;
SioFloppy->Irq = Irq; SioFloppy->Irq = Irq;
SioFloppy->Dma = Dma; SioFloppy->Dma = Dma;
SioFloppy->NumberOfFloppy++; SioFloppy->NumberOfFloppy++;
} }
} }
} }
// //
// See if this is a mouse // See if this is a mouse
// Always set mouse found so USB hot plug will work // Always set mouse found so USB hot plug will work
@ -225,7 +230,6 @@ LegacyBiosBuildSioDataFromSio (
FreePool (HandleBuffer); FreePool (HandleBuffer);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
@ -239,27 +243,27 @@ LegacyBiosBuildSioDataFromSio (
**/ **/
EFI_STATUS EFI_STATUS
LegacyBiosBuildSioDataFromIsaIo ( LegacyBiosBuildSioDataFromIsaIo (
IN DEVICE_PRODUCER_DATA_HEADER *SioPtr IN DEVICE_PRODUCER_DATA_HEADER *SioPtr
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
DEVICE_PRODUCER_SERIAL *SioSerial; DEVICE_PRODUCER_SERIAL *SioSerial;
DEVICE_PRODUCER_PARALLEL *SioParallel; DEVICE_PRODUCER_PARALLEL *SioParallel;
DEVICE_PRODUCER_FLOPPY *SioFloppy; DEVICE_PRODUCER_FLOPPY *SioFloppy;
UINTN HandleCount; UINTN HandleCount;
EFI_HANDLE *HandleBuffer; EFI_HANDLE *HandleBuffer;
UINTN Index; UINTN Index;
UINTN ResourceIndex; UINTN ResourceIndex;
UINTN ChildIndex; UINTN ChildIndex;
EFI_ISA_IO_PROTOCOL *IsaIo; EFI_ISA_IO_PROTOCOL *IsaIo;
EFI_ISA_ACPI_RESOURCE_LIST *ResourceList; EFI_ISA_ACPI_RESOURCE_LIST *ResourceList;
EFI_ISA_ACPI_RESOURCE *IoResource; EFI_ISA_ACPI_RESOURCE *IoResource;
EFI_ISA_ACPI_RESOURCE *DmaResource; EFI_ISA_ACPI_RESOURCE *DmaResource;
EFI_ISA_ACPI_RESOURCE *InterruptResource; EFI_ISA_ACPI_RESOURCE *InterruptResource;
UINTN EntryCount; UINTN EntryCount;
EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer; EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;
EFI_BLOCK_IO_PROTOCOL *BlockIo; EFI_BLOCK_IO_PROTOCOL *BlockIo;
EFI_SERIAL_IO_PROTOCOL *SerialIo; EFI_SERIAL_IO_PROTOCOL *SerialIo;
// //
// Get the list of ISA controllers in the system // Get the list of ISA controllers in the system
@ -274,12 +278,12 @@ LegacyBiosBuildSioDataFromIsaIo (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
// //
// Collect legacy information from each of the ISA controllers in the system // Collect legacy information from each of the ISA controllers in the system
// //
for (Index = 0; Index < HandleCount; Index++) { for (Index = 0; Index < HandleCount; Index++) {
Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiIsaIoProtocolGuid, (VOID **)&IsaIo);
Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiIsaIoProtocolGuid, (VOID **) &IsaIo);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
continue; continue;
} }
@ -289,6 +293,7 @@ LegacyBiosBuildSioDataFromIsaIo (
if (ResourceList == NULL) { if (ResourceList == NULL) {
continue; continue;
} }
// //
// Collect the resource types neededto fill in the SIO data structure // Collect the resource types neededto fill in the SIO data structure
// //
@ -298,38 +303,40 @@ LegacyBiosBuildSioDataFromIsaIo (
for (ResourceIndex = 0; for (ResourceIndex = 0;
ResourceList->ResourceItem[ResourceIndex].Type != EfiIsaAcpiResourceEndOfList; ResourceList->ResourceItem[ResourceIndex].Type != EfiIsaAcpiResourceEndOfList;
ResourceIndex++ ResourceIndex++
) { )
{
switch (ResourceList->ResourceItem[ResourceIndex].Type) { switch (ResourceList->ResourceItem[ResourceIndex].Type) {
case EfiIsaAcpiResourceIo: case EfiIsaAcpiResourceIo:
IoResource = &ResourceList->ResourceItem[ResourceIndex]; IoResource = &ResourceList->ResourceItem[ResourceIndex];
break; break;
case EfiIsaAcpiResourceMemory: case EfiIsaAcpiResourceMemory:
break; break;
case EfiIsaAcpiResourceDma: case EfiIsaAcpiResourceDma:
DmaResource = &ResourceList->ResourceItem[ResourceIndex]; DmaResource = &ResourceList->ResourceItem[ResourceIndex];
break; break;
case EfiIsaAcpiResourceInterrupt: case EfiIsaAcpiResourceInterrupt:
InterruptResource = &ResourceList->ResourceItem[ResourceIndex]; InterruptResource = &ResourceList->ResourceItem[ResourceIndex];
break; break;
default: default:
break; break;
} }
} }
// //
// See if this is an ISA serial port // See if this is an ISA serial port
// //
// Ignore DMA resource since it is always returned NULL // Ignore DMA resource since it is always returned NULL
// //
if (ResourceList->Device.HID == EISA_PNP_ID (0x500) || ResourceList->Device.HID == EISA_PNP_ID (0x501)) { if ((ResourceList->Device.HID == EISA_PNP_ID (0x500)) || (ResourceList->Device.HID == EISA_PNP_ID (0x501))) {
if ((ResourceList->Device.UID <= 3) &&
if (ResourceList->Device.UID <= 3 && (IoResource != NULL) &&
IoResource != NULL && (InterruptResource != NULL)
InterruptResource != NULL )
) { {
// //
// Get the handle of the child device that has opened the ISA I/O Protocol // Get the handle of the child device that has opened the ISA I/O Protocol
// //
@ -342,17 +349,18 @@ LegacyBiosBuildSioDataFromIsaIo (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
continue; continue;
} }
// //
// We want resource for legacy even if no 32-bit driver installed // We want resource for legacy even if no 32-bit driver installed
// //
for (ChildIndex = 0; ChildIndex < EntryCount; ChildIndex++) { for (ChildIndex = 0; ChildIndex < EntryCount; ChildIndex++) {
if ((OpenInfoBuffer[ChildIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) { if ((OpenInfoBuffer[ChildIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
Status = gBS->HandleProtocol (OpenInfoBuffer[ChildIndex].ControllerHandle, &gEfiSerialIoProtocolGuid, (VOID **) &SerialIo); Status = gBS->HandleProtocol (OpenInfoBuffer[ChildIndex].ControllerHandle, &gEfiSerialIoProtocolGuid, (VOID **)&SerialIo);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
SioSerial = &SioPtr->Serial[ResourceList->Device.UID]; SioSerial = &SioPtr->Serial[ResourceList->Device.UID];
SioSerial->Address = (UINT16) IoResource->StartRange; SioSerial->Address = (UINT16)IoResource->StartRange;
SioSerial->Irq = (UINT8) InterruptResource->StartRange; SioSerial->Irq = (UINT8)InterruptResource->StartRange;
SioSerial->Mode = DEVICE_SERIAL_MODE_NORMAL | DEVICE_SERIAL_MODE_DUPLEX_HALF; SioSerial->Mode = DEVICE_SERIAL_MODE_NORMAL | DEVICE_SERIAL_MODE_DUPLEX_HALF;
break; break;
} }
} }
@ -361,40 +369,44 @@ LegacyBiosBuildSioDataFromIsaIo (
FreePool (OpenInfoBuffer); FreePool (OpenInfoBuffer);
} }
} }
// //
// See if this is an ISA parallel port // See if this is an ISA parallel port
// //
// Ignore DMA resource since it is always returned NULL, port // Ignore DMA resource since it is always returned NULL, port
// only used in output mode. // only used in output mode.
// //
if (ResourceList->Device.HID == EISA_PNP_ID (0x400) || ResourceList->Device.HID == EISA_PNP_ID (0x401)) { if ((ResourceList->Device.HID == EISA_PNP_ID (0x400)) || (ResourceList->Device.HID == EISA_PNP_ID (0x401))) {
if (ResourceList->Device.UID <= 2 && if ((ResourceList->Device.UID <= 2) &&
IoResource != NULL && (IoResource != NULL) &&
InterruptResource != NULL && (InterruptResource != NULL) &&
DmaResource != NULL (DmaResource != NULL)
) { )
SioParallel = &SioPtr->Parallel[ResourceList->Device.UID]; {
SioParallel->Address = (UINT16) IoResource->StartRange; SioParallel = &SioPtr->Parallel[ResourceList->Device.UID];
SioParallel->Irq = (UINT8) InterruptResource->StartRange; SioParallel->Address = (UINT16)IoResource->StartRange;
SioParallel->Dma = (UINT8) DmaResource->StartRange; SioParallel->Irq = (UINT8)InterruptResource->StartRange;
SioParallel->Mode = DEVICE_PARALLEL_MODE_MODE_OUTPUT_ONLY; SioParallel->Dma = (UINT8)DmaResource->StartRange;
SioParallel->Mode = DEVICE_PARALLEL_MODE_MODE_OUTPUT_ONLY;
} }
} }
// //
// See if this is an ISA floppy controller // See if this is an ISA floppy controller
// //
if (ResourceList->Device.HID == EISA_PNP_ID (0x604)) { if (ResourceList->Device.HID == EISA_PNP_ID (0x604)) {
if (IoResource != NULL && InterruptResource != NULL && DmaResource != NULL) { if ((IoResource != NULL) && (InterruptResource != NULL) && (DmaResource != NULL)) {
Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiBlockIoProtocolGuid, (VOID **) &BlockIo); Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiBlockIoProtocolGuid, (VOID **)&BlockIo);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
SioFloppy = &SioPtr->Floppy; SioFloppy = &SioPtr->Floppy;
SioFloppy->Address = (UINT16) IoResource->StartRange; SioFloppy->Address = (UINT16)IoResource->StartRange;
SioFloppy->Irq = (UINT8) InterruptResource->StartRange; SioFloppy->Irq = (UINT8)InterruptResource->StartRange;
SioFloppy->Dma = (UINT8) DmaResource->StartRange; SioFloppy->Dma = (UINT8)DmaResource->StartRange;
SioFloppy->NumberOfFloppy++; SioFloppy->NumberOfFloppy++;
} }
} }
} }
// //
// See if this is a mouse // See if this is a mouse
// Always set mouse found so USB hot plug will work // Always set mouse found so USB hot plug will work
@ -430,14 +442,14 @@ LegacyBiosBuildSioDataFromIsaIo (
**/ **/
EFI_STATUS EFI_STATUS
LegacyBiosBuildSioData ( LegacyBiosBuildSioData (
IN LEGACY_BIOS_INSTANCE *Private IN LEGACY_BIOS_INSTANCE *Private
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
DEVICE_PRODUCER_DATA_HEADER *SioPtr; DEVICE_PRODUCER_DATA_HEADER *SioPtr;
EFI_HANDLE IsaBusController; EFI_HANDLE IsaBusController;
UINTN HandleCount; UINTN HandleCount;
EFI_HANDLE *HandleBuffer; EFI_HANDLE *HandleBuffer;
// //
// Get the pointer to the SIO data structure // Get the pointer to the SIO data structure

View File

@ -9,7 +9,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "LegacyBiosInterface.h" #include "LegacyBiosInterface.h"
THUNK_CONTEXT mThunkContext; THUNK_CONTEXT mThunkContext;
/** /**
Sets the counter value for Timer #0 in a legacy 8254 timer. Sets the counter value for Timer #0 in a legacy 8254 timer.
@ -23,8 +23,8 @@ SetPitCount (
) )
{ {
IoWrite8 (TIMER_CONTROL_PORT, TIMER0_CONTROL_WORD); IoWrite8 (TIMER_CONTROL_PORT, TIMER0_CONTROL_WORD);
IoWrite8 (TIMER0_COUNT_PORT, (UINT8) (Count & 0xFF)); IoWrite8 (TIMER0_COUNT_PORT, (UINT8)(Count & 0xFF));
IoWrite8 (TIMER0_COUNT_PORT, (UINT8) ((Count>>8) & 0xFF)); IoWrite8 (TIMER0_COUNT_PORT, (UINT8)((Count>>8) & 0xFF));
} }
/** /**
@ -45,13 +45,13 @@ SetPitCount (
BOOLEAN BOOLEAN
EFIAPI EFIAPI
LegacyBiosInt86 ( LegacyBiosInt86 (
IN EFI_LEGACY_BIOS_PROTOCOL *This, IN EFI_LEGACY_BIOS_PROTOCOL *This,
IN UINT8 BiosInt, IN UINT8 BiosInt,
IN EFI_IA32_REGISTER_SET *Regs IN EFI_IA32_REGISTER_SET *Regs
) )
{ {
UINT16 Segment; UINT16 Segment;
UINT16 Offset; UINT16 Offset;
Regs->X.Flags.Reserved1 = 1; Regs->X.Flags.Reserved1 = 1;
Regs->X.Flags.Reserved2 = 0; Regs->X.Flags.Reserved2 = 0;
@ -67,9 +67,9 @@ LegacyBiosInt86 (
// We use this base address to get the legacy interrupt handler. // We use this base address to get the legacy interrupt handler.
// //
ACCESS_PAGE0_CODE ( ACCESS_PAGE0_CODE (
Segment = (UINT16)(((UINT32 *)0)[BiosInt] >> 16); Segment = (UINT16)(((UINT32 *)0)[BiosInt] >> 16);
Offset = (UINT16)((UINT32 *)0)[BiosInt]; Offset = (UINT16)((UINT32 *)0)[BiosInt];
); );
return InternalLegacyBiosFarCall ( return InternalLegacyBiosFarCall (
This, This,
@ -102,12 +102,12 @@ LegacyBiosInt86 (
BOOLEAN BOOLEAN
EFIAPI EFIAPI
LegacyBiosFarCall86 ( LegacyBiosFarCall86 (
IN EFI_LEGACY_BIOS_PROTOCOL *This, IN EFI_LEGACY_BIOS_PROTOCOL *This,
IN UINT16 Segment, IN UINT16 Segment,
IN UINT16 Offset, IN UINT16 Offset,
IN EFI_IA32_REGISTER_SET *Regs, IN EFI_IA32_REGISTER_SET *Regs,
IN VOID *Stack, IN VOID *Stack,
IN UINTN StackSize IN UINTN StackSize
) )
{ {
Regs->X.Flags.Reserved1 = 1; Regs->X.Flags.Reserved1 = 1;
@ -134,8 +134,8 @@ LegacyBiosFarCall86 (
VOID VOID
EFIAPI EFIAPI
LegacyBiosNullInterruptHandler ( LegacyBiosNullInterruptHandler (
IN EFI_EXCEPTION_TYPE InterruptType, IN EFI_EXCEPTION_TYPE InterruptType,
IN EFI_SYSTEM_CONTEXT SystemContext IN EFI_SYSTEM_CONTEXT SystemContext
) )
{ {
} }
@ -161,12 +161,12 @@ LegacyBiosNullInterruptHandler (
BOOLEAN BOOLEAN
EFIAPI EFIAPI
InternalLegacyBiosFarCall ( InternalLegacyBiosFarCall (
IN EFI_LEGACY_BIOS_PROTOCOL *This, IN EFI_LEGACY_BIOS_PROTOCOL *This,
IN UINT16 Segment, IN UINT16 Segment,
IN UINT16 Offset, IN UINT16 Offset,
IN EFI_IA32_REGISTER_SET *Regs, IN EFI_IA32_REGISTER_SET *Regs,
IN VOID *Stack, IN VOID *Stack,
IN UINTN StackSize IN UINTN StackSize
) )
{ {
UINTN Status; UINTN Status;
@ -180,19 +180,19 @@ InternalLegacyBiosFarCall (
Private = LEGACY_BIOS_INSTANCE_FROM_THIS (This); Private = LEGACY_BIOS_INSTANCE_FROM_THIS (This);
ZeroMem (&ThunkRegSet, sizeof (ThunkRegSet)); ZeroMem (&ThunkRegSet, sizeof (ThunkRegSet));
ThunkRegSet.X.DI = Regs->X.DI; ThunkRegSet.X.DI = Regs->X.DI;
ThunkRegSet.X.SI = Regs->X.SI; ThunkRegSet.X.SI = Regs->X.SI;
ThunkRegSet.X.BP = Regs->X.BP; ThunkRegSet.X.BP = Regs->X.BP;
ThunkRegSet.X.BX = Regs->X.BX; ThunkRegSet.X.BX = Regs->X.BX;
ThunkRegSet.X.DX = Regs->X.DX; ThunkRegSet.X.DX = Regs->X.DX;
// //
// Sometimes, ECX is used to pass in 32 bit data. For example, INT 1Ah, AX = B10Dh is // Sometimes, ECX is used to pass in 32 bit data. For example, INT 1Ah, AX = B10Dh is
// "PCI BIOS v2.0c + Write Configuration DWORD" and ECX has the dword to write. // "PCI BIOS v2.0c + Write Configuration DWORD" and ECX has the dword to write.
// //
ThunkRegSet.E.ECX = Regs->E.ECX; ThunkRegSet.E.ECX = Regs->E.ECX;
ThunkRegSet.X.AX = Regs->X.AX; ThunkRegSet.X.AX = Regs->X.AX;
ThunkRegSet.E.DS = Regs->X.DS; ThunkRegSet.E.DS = Regs->X.DS;
ThunkRegSet.E.ES = Regs->X.ES; ThunkRegSet.E.ES = Regs->X.ES;
CopyMem (&(ThunkRegSet.E.EFLAGS.UintN), &(Regs->X.Flags), sizeof (Regs->X.Flags)); CopyMem (&(ThunkRegSet.E.EFLAGS.UintN), &(Regs->X.Flags), sizeof (Regs->X.Flags));
@ -200,7 +200,7 @@ InternalLegacyBiosFarCall (
// Clear the error flag; thunk code may set it. Stack16 should be the high address // Clear the error flag; thunk code may set it. Stack16 should be the high address
// Make Statk16 address the low 16 bit must be not zero. // Make Statk16 address the low 16 bit must be not zero.
// //
Stack16 = (UINT16 *)((UINT8 *) mThunkContext.RealModeBuffer + mThunkContext.RealModeBufferSize - sizeof (UINT16)); Stack16 = (UINT16 *)((UINT8 *)mThunkContext.RealModeBuffer + mThunkContext.RealModeBufferSize - sizeof (UINT16));
// //
// Save current rate of DXE Timer // Save current rate of DXE Timer
@ -229,22 +229,25 @@ InternalLegacyBiosFarCall (
// handled properly from real mode. // handled properly from real mode.
// //
DEBUG_CODE_BEGIN (); DEBUG_CODE_BEGIN ();
UINTN Vector; UINTN Vector;
UINTN Count; UINTN Count;
for (Vector = 0x20, Count = 0; Vector < 0x100; Vector++) { for (Vector = 0x20, Count = 0; Vector < 0x100; Vector++) {
Status = Private->Cpu->RegisterInterruptHandler (Private->Cpu, Vector, LegacyBiosNullInterruptHandler); Status = Private->Cpu->RegisterInterruptHandler (Private->Cpu, Vector, LegacyBiosNullInterruptHandler);
if (Status == EFI_ALREADY_STARTED) { if (Status == EFI_ALREADY_STARTED) {
Count++; Count++;
}
if (Status == EFI_SUCCESS) {
Private->Cpu->RegisterInterruptHandler (Private->Cpu, Vector, NULL);
}
} }
if (Count >= 2) {
DEBUG ((DEBUG_ERROR, "ERROR: More than one HW interrupt active with CSM enabled\n")); if (Status == EFI_SUCCESS) {
Private->Cpu->RegisterInterruptHandler (Private->Cpu, Vector, NULL);
} }
ASSERT (Count < 2); }
if (Count >= 2) {
DEBUG ((DEBUG_ERROR, "ERROR: More than one HW interrupt active with CSM enabled\n"));
}
ASSERT (Count < 2);
DEBUG_CODE_END (); DEBUG_CODE_END ();
// //
@ -252,11 +255,11 @@ InternalLegacyBiosFarCall (
// period is less than the CSM required rate of 54.9254, then force the 8254 // period is less than the CSM required rate of 54.9254, then force the 8254
// PIT counter to 0, which is the CSM required rate of 54.9254 ms // PIT counter to 0, which is the CSM required rate of 54.9254 ms
// //
if (Private->TimerUses8254 && TimerPeriod < 549254) { if (Private->TimerUses8254 && (TimerPeriod < 549254)) {
SetPitCount (0); SetPitCount (0);
} }
if (Stack != NULL && StackSize != 0) { if ((Stack != NULL) && (StackSize != 0)) {
// //
// Copy Stack to low memory stack // Copy Stack to low memory stack
// //
@ -264,12 +267,12 @@ InternalLegacyBiosFarCall (
CopyMem (Stack16, Stack, StackSize); CopyMem (Stack16, Stack, StackSize);
} }
ThunkRegSet.E.SS = (UINT16) (((UINTN) Stack16 >> 16) << 12); ThunkRegSet.E.SS = (UINT16)(((UINTN)Stack16 >> 16) << 12);
ThunkRegSet.E.ESP = (UINT16) (UINTN) Stack16; ThunkRegSet.E.ESP = (UINT16)(UINTN)Stack16;
ThunkRegSet.E.CS = Segment; ThunkRegSet.E.CS = Segment;
ThunkRegSet.E.Eip = Offset; ThunkRegSet.E.Eip = Offset;
mThunkContext.RealModeState = &ThunkRegSet; mThunkContext.RealModeState = &ThunkRegSet;
// //
// Set Legacy16 state. 0x08, 0x70 is legacy 8259 vector bases. // Set Legacy16 state. 0x08, 0x70 is legacy 8259 vector bases.
@ -279,7 +282,7 @@ InternalLegacyBiosFarCall (
AsmThunk16 (&mThunkContext); AsmThunk16 (&mThunkContext);
if (Stack != NULL && StackSize != 0) { if ((Stack != NULL) && (StackSize != 0)) {
// //
// Copy low memory stack to Stack // Copy low memory stack to Stack
// //
@ -311,17 +314,17 @@ InternalLegacyBiosFarCall (
// PcdEbdaReservedMemorySize should be adjusted to larger for more OPROMs. // PcdEbdaReservedMemorySize should be adjusted to larger for more OPROMs.
// //
DEBUG_CODE_BEGIN (); DEBUG_CODE_BEGIN ();
{ {
UINTN EbdaBaseAddress; UINTN EbdaBaseAddress;
UINTN ReservedEbdaBaseAddress; UINTN ReservedEbdaBaseAddress;
ACCESS_PAGE0_CODE ( ACCESS_PAGE0_CODE (
EbdaBaseAddress = (*(UINT16 *) (UINTN) 0x40E) << 4; EbdaBaseAddress = (*(UINT16 *)(UINTN)0x40E) << 4;
ReservedEbdaBaseAddress = CONVENTIONAL_MEMORY_TOP ReservedEbdaBaseAddress = CONVENTIONAL_MEMORY_TOP
- PcdGet32 (PcdEbdaReservedMemorySize); - PcdGet32 (PcdEbdaReservedMemorySize);
ASSERT (ReservedEbdaBaseAddress <= EbdaBaseAddress); ASSERT (ReservedEbdaBaseAddress <= EbdaBaseAddress);
); );
} }
DEBUG_CODE_END (); DEBUG_CODE_END ();
// //
@ -329,21 +332,21 @@ InternalLegacyBiosFarCall (
// //
SaveAndSetDebugTimerInterrupt (InterruptState); SaveAndSetDebugTimerInterrupt (InterruptState);
Regs->E.EDI = ThunkRegSet.E.EDI; Regs->E.EDI = ThunkRegSet.E.EDI;
Regs->E.ESI = ThunkRegSet.E.ESI; Regs->E.ESI = ThunkRegSet.E.ESI;
Regs->E.EBP = ThunkRegSet.E.EBP; Regs->E.EBP = ThunkRegSet.E.EBP;
Regs->E.EBX = ThunkRegSet.E.EBX; Regs->E.EBX = ThunkRegSet.E.EBX;
Regs->E.EDX = ThunkRegSet.E.EDX; Regs->E.EDX = ThunkRegSet.E.EDX;
Regs->E.ECX = ThunkRegSet.E.ECX; Regs->E.ECX = ThunkRegSet.E.ECX;
Regs->E.EAX = ThunkRegSet.E.EAX; Regs->E.EAX = ThunkRegSet.E.EAX;
Regs->X.SS = ThunkRegSet.E.SS; Regs->X.SS = ThunkRegSet.E.SS;
Regs->X.CS = ThunkRegSet.E.CS; Regs->X.CS = ThunkRegSet.E.CS;
Regs->X.DS = ThunkRegSet.E.DS; Regs->X.DS = ThunkRegSet.E.DS;
Regs->X.ES = ThunkRegSet.E.ES; Regs->X.ES = ThunkRegSet.E.ES;
CopyMem (&(Regs->X.Flags), &(ThunkRegSet.E.EFLAGS.UintN), sizeof (Regs->X.Flags)); CopyMem (&(Regs->X.Flags), &(ThunkRegSet.E.EFLAGS.UintN), sizeof (Regs->X.Flags));
return (BOOLEAN) (Regs->X.Flags.CF == 1); return (BOOLEAN)(Regs->X.Flags.CF == 1);
} }
/** /**
@ -357,16 +360,16 @@ InternalLegacyBiosFarCall (
**/ **/
EFI_STATUS EFI_STATUS
LegacyBiosInitializeThunk ( LegacyBiosInitializeThunk (
IN LEGACY_BIOS_INSTANCE *Private IN LEGACY_BIOS_INSTANCE *Private
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS MemoryAddress; EFI_PHYSICAL_ADDRESS MemoryAddress;
UINT8 TimerVector; UINT8 TimerVector;
MemoryAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) Private->IntThunk; MemoryAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)Private->IntThunk;
mThunkContext.RealModeBuffer = (VOID *) (UINTN) (MemoryAddress + ((sizeof (LOW_MEMORY_THUNK) / EFI_PAGE_SIZE) + 1) * EFI_PAGE_SIZE); mThunkContext.RealModeBuffer = (VOID *)(UINTN)(MemoryAddress + ((sizeof (LOW_MEMORY_THUNK) / EFI_PAGE_SIZE) + 1) * EFI_PAGE_SIZE);
mThunkContext.RealModeBufferSize = EFI_PAGE_SIZE; mThunkContext.RealModeBufferSize = EFI_PAGE_SIZE;
mThunkContext.ThunkAttributes = THUNK_ATTRIBUTE_BIG_REAL_MODE | THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15; mThunkContext.ThunkAttributes = THUNK_ATTRIBUTE_BIG_REAL_MODE | THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15;
@ -376,7 +379,7 @@ LegacyBiosInitializeThunk (
// Get the interrupt vector number corresponding to IRQ0 from the 8259 driver // Get the interrupt vector number corresponding to IRQ0 from the 8259 driver
// //
TimerVector = 0; TimerVector = 0;
Status = Private->Legacy8259->GetVector (Private->Legacy8259, Efi8259Irq0, &TimerVector); Status = Private->Legacy8259->GetVector (Private->Legacy8259, Efi8259Irq0, &TimerVector);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
// //

File diff suppressed because it is too large Load Diff

View File

@ -6,13 +6,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#ifndef _EFI_LEGACY_BOOT_OPTION_H_ #ifndef _EFI_LEGACY_BOOT_OPTION_H_
#define _EFI_LEGACY_BOOT_OPTION_H_ #define _EFI_LEGACY_BOOT_OPTION_H_
#include <PiDxe.h> #include <PiDxe.h>
#include <Guid/GlobalVariable.h> #include <Guid/GlobalVariable.h>
#include <Guid/LegacyDevOrder.h> #include <Guid/LegacyDevOrder.h>
#include <Guid/MdeModuleHii.h> #include <Guid/MdeModuleHii.h>
@ -38,42 +36,40 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "LegacyBootMaintUiVfr.h" #include "LegacyBootMaintUiVfr.h"
#define CONFIG_OPTION_OFFSET 0x1200 #define CONFIG_OPTION_OFFSET 0x1200
// //
// VarOffset that will be used to create question // VarOffset that will be used to create question
// all these values are computed from the structure // all these values are computed from the structure
// defined below // defined below
// //
#define VAR_OFFSET(Field) ((UINT16) ((UINTN) &(((LEGACY_BOOT_NV_DATA *) 0)->Field))) #define VAR_OFFSET(Field) ((UINT16) ((UINTN) &(((LEGACY_BOOT_NV_DATA *) 0)->Field)))
// //
// Question Id of Zero is invalid, so add an offset to it // Question Id of Zero is invalid, so add an offset to it
// //
#define QUESTION_ID(Field) (VAR_OFFSET (Field) + CONFIG_OPTION_OFFSET) #define QUESTION_ID(Field) (VAR_OFFSET (Field) + CONFIG_OPTION_OFFSET)
#define LEGACY_FD_QUESTION_ID QUESTION_ID (LegacyFD)
#define LEGACY_HD_QUESTION_ID QUESTION_ID (LegacyHD)
#define LEGACY_CD_QUESTION_ID QUESTION_ID (LegacyCD)
#define LEGACY_NET_QUESTION_ID QUESTION_ID (LegacyNET)
#define LEGACY_BEV_QUESTION_ID QUESTION_ID (LegacyBEV)
#define LEGACY_FD_QUESTION_ID QUESTION_ID (LegacyFD)
#define LEGACY_HD_QUESTION_ID QUESTION_ID (LegacyHD)
#define LEGACY_CD_QUESTION_ID QUESTION_ID (LegacyCD)
#define LEGACY_NET_QUESTION_ID QUESTION_ID (LegacyNET)
#define LEGACY_BEV_QUESTION_ID QUESTION_ID (LegacyBEV)
// //
// String Constant // String Constant
// //
#define STR_FLOPPY L"Floppy Drive #%02x" #define STR_FLOPPY L"Floppy Drive #%02x"
#define STR_HARDDISK L"HardDisk Drive #%02x" #define STR_HARDDISK L"HardDisk Drive #%02x"
#define STR_CDROM L"ATAPI CDROM Drive #%02x" #define STR_CDROM L"ATAPI CDROM Drive #%02x"
#define STR_NET L"NET Drive #%02x" #define STR_NET L"NET Drive #%02x"
#define STR_BEV L"BEV Drive #%02x" #define STR_BEV L"BEV Drive #%02x"
#define STR_FLOPPY_HELP L"Select Floppy Drive #%02x" #define STR_FLOPPY_HELP L"Select Floppy Drive #%02x"
#define STR_HARDDISK_HELP L"Select HardDisk Drive #%02x" #define STR_HARDDISK_HELP L"Select HardDisk Drive #%02x"
#define STR_CDROM_HELP L"Select ATAPI CDROM Drive #%02x" #define STR_CDROM_HELP L"Select ATAPI CDROM Drive #%02x"
#define STR_NET_HELP L"NET Drive #%02x" #define STR_NET_HELP L"NET Drive #%02x"
#define STR_BEV_HELP L"BEV Drive #%02x" #define STR_BEV_HELP L"BEV Drive #%02x"
#define STR_FLOPPY_TITLE L"Set Legacy Floppy Drive Order" #define STR_FLOPPY_TITLE L"Set Legacy Floppy Drive Order"
#define STR_HARDDISK_TITLE L"Set Legacy HardDisk Drive Order" #define STR_HARDDISK_TITLE L"Set Legacy HardDisk Drive Order"
@ -84,7 +80,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// //
// These are the VFR compiler generated data representing our VFR data. // These are the VFR compiler generated data representing our VFR data.
// //
extern UINT8 LegacyBootMaintUiVfrBin[]; extern UINT8 LegacyBootMaintUiVfrBin[];
#pragma pack(1) #pragma pack(1)
@ -92,52 +88,49 @@ extern UINT8 LegacyBootMaintUiVfrBin[];
/// HII specific Vendor Device Path definition. /// HII specific Vendor Device Path definition.
/// ///
typedef struct { typedef struct {
VENDOR_DEVICE_PATH VendorDevicePath; VENDOR_DEVICE_PATH VendorDevicePath;
EFI_DEVICE_PATH_PROTOCOL End; EFI_DEVICE_PATH_PROTOCOL End;
} HII_VENDOR_DEVICE_PATH; } HII_VENDOR_DEVICE_PATH;
// //
// Variable created with this flag will be "Efi:...." // Variable created with this flag will be "Efi:...."
// //
#define VAR_FLAG EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE #define VAR_FLAG EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE
#define LEGACY_BOOT_OPTION_CALLBACK_DATA_SIGNATURE SIGNATURE_32 ('L', 'G', 'C', 'B') #define LEGACY_BOOT_OPTION_CALLBACK_DATA_SIGNATURE SIGNATURE_32 ('L', 'G', 'C', 'B')
typedef struct { typedef struct {
UINTN Signature; UINTN Signature;
// //
// HII relative handles // HII relative handles
// //
EFI_HII_HANDLE HiiHandle; EFI_HII_HANDLE HiiHandle;
EFI_HANDLE DriverHandle; EFI_HANDLE DriverHandle;
// //
// Produced protocols // Produced protocols
// //
EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess; EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess;
// //
// Maintain the data. // Maintain the data.
// //
LEGACY_BOOT_MAINTAIN_DATA *MaintainMapData; LEGACY_BOOT_MAINTAIN_DATA *MaintainMapData;
} LEGACY_BOOT_OPTION_CALLBACK_DATA; } LEGACY_BOOT_OPTION_CALLBACK_DATA;
// //
// All of the signatures that will be used in list structure // All of the signatures that will be used in list structure
// //
#define LEGACY_MENU_OPTION_SIGNATURE SIGNATURE_32 ('m', 'e', 'n', 'u') #define LEGACY_MENU_OPTION_SIGNATURE SIGNATURE_32 ('m', 'e', 'n', 'u')
#define LEGACY_MENU_ENTRY_SIGNATURE SIGNATURE_32 ('e', 'n', 't', 'r') #define LEGACY_MENU_ENTRY_SIGNATURE SIGNATURE_32 ('e', 'n', 't', 'r')
#define LEGACY_LEGACY_DEV_CONTEXT_SELECT 0x9 #define LEGACY_LEGACY_DEV_CONTEXT_SELECT 0x9
typedef struct { typedef struct {
UINTN Signature; UINTN Signature;
LIST_ENTRY Head; LIST_ENTRY Head;
UINTN MenuNumber; UINTN MenuNumber;
} LEGACY_MENU_OPTION; } LEGACY_MENU_OPTION;
typedef struct { typedef struct {
@ -146,18 +139,18 @@ typedef struct {
} LEGACY_DEVICE_CONTEXT; } LEGACY_DEVICE_CONTEXT;
typedef struct { typedef struct {
UINTN Signature; UINTN Signature;
LIST_ENTRY Link; LIST_ENTRY Link;
UINTN OptionNumber; UINTN OptionNumber;
UINT16 *DisplayString; UINT16 *DisplayString;
UINT16 *HelpString; UINT16 *HelpString;
EFI_STRING_ID DisplayStringToken; EFI_STRING_ID DisplayStringToken;
EFI_STRING_ID HelpStringToken; EFI_STRING_ID HelpStringToken;
VOID *VariableContext; VOID *VariableContext;
} LEGACY_MENU_ENTRY; } LEGACY_MENU_ENTRY;
typedef struct { typedef struct {
UINT16 BbsIndex; UINT16 BbsIndex;
} LEGACY_BOOT_OPTION_BBS_DATA; } LEGACY_BOOT_OPTION_BBS_DATA;
#pragma pack() #pragma pack()
@ -183,12 +176,12 @@ typedef struct {
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
LegacyBootOptionCallback ( LegacyBootOptionCallback (
IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
IN EFI_BROWSER_ACTION Action, IN EFI_BROWSER_ACTION Action,
IN EFI_QUESTION_ID QuestionId, IN EFI_QUESTION_ID QuestionId,
IN UINT8 Type, IN UINT8 Type,
IN EFI_IFR_TYPE_VALUE *Value, IN EFI_IFR_TYPE_VALUE *Value,
OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
); );
/** /**
@ -216,10 +209,10 @@ LegacyBootOptionCallback (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
LegacyBootOptionExtractConfig ( LegacyBootOptionExtractConfig (
IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
IN CONST EFI_STRING Request, IN CONST EFI_STRING Request,
OUT EFI_STRING *Progress, OUT EFI_STRING *Progress,
OUT EFI_STRING *Results OUT EFI_STRING *Results
); );
/** /**
@ -241,9 +234,9 @@ LegacyBootOptionExtractConfig (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
LegacyBootOptionRouteConfig ( LegacyBootOptionRouteConfig (
IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
IN CONST EFI_STRING Configuration, IN CONST EFI_STRING Configuration,
OUT EFI_STRING *Progress OUT EFI_STRING *Progress
); );
#endif #endif

View File

@ -6,34 +6,28 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#ifndef _EFI_LEGACY_BOOT_OPTION_VFR_H_ #ifndef _EFI_LEGACY_BOOT_OPTION_VFR_H_
#define _EFI_LEGACY_BOOT_OPTION_VFR_H_ #define _EFI_LEGACY_BOOT_OPTION_VFR_H_
#include <Guid/HiiBootMaintenanceFormset.h> #include <Guid/HiiBootMaintenanceFormset.h>
#define MAX_MENU_NUMBER 100 #define MAX_MENU_NUMBER 100
#define LEGACY_BOOT_OPTION_FORMSET_GUID { 0x6bc75598, 0x89b4, 0x483d, { 0x91, 0x60, 0x7f, 0x46, 0x9a, 0x96, 0x35, 0x31 } } #define LEGACY_BOOT_OPTION_FORMSET_GUID { 0x6bc75598, 0x89b4, 0x483d, { 0x91, 0x60, 0x7f, 0x46, 0x9a, 0x96, 0x35, 0x31 } }
#define VARSTORE_ID_LEGACY_BOOT 0x0001 #define VARSTORE_ID_LEGACY_BOOT 0x0001
#define LEGACY_BOOT_FORM_ID 0x1000 #define LEGACY_BOOT_FORM_ID 0x1000
#define LEGACY_ORDER_CHANGE_FORM_ID 0x1001 #define LEGACY_ORDER_CHANGE_FORM_ID 0x1001
#define FORM_FLOPPY_BOOT_ID 0x2000
#define FORM_HARDDISK_BOOT_ID 0x2001
#define FORM_CDROM_BOOT_ID 0x2002
#define FORM_NET_BOOT_ID 0x2003
#define FORM_BEV_BOOT_ID 0x2004
#define FORM_FLOPPY_BOOT_ID 0x2000 #define FORM_BOOT_LEGACY_DEVICE_ID 0x9000
#define FORM_HARDDISK_BOOT_ID 0x2001 #define FORM_BOOT_LEGACY_LABEL_END 0x9001
#define FORM_CDROM_BOOT_ID 0x2002
#define FORM_NET_BOOT_ID 0x2003
#define FORM_BEV_BOOT_ID 0x2004
#define FORM_BOOT_LEGACY_DEVICE_ID 0x9000
#define FORM_BOOT_LEGACY_LABEL_END 0x9001
#pragma pack(1) #pragma pack(1)
@ -49,11 +43,11 @@ typedef struct {
// //
// Legacy Device Order Selection Storage // Legacy Device Order Selection Storage
// //
UINT16 LegacyFD[MAX_MENU_NUMBER]; UINT16 LegacyFD[MAX_MENU_NUMBER];
UINT16 LegacyHD[MAX_MENU_NUMBER]; UINT16 LegacyHD[MAX_MENU_NUMBER];
UINT16 LegacyCD[MAX_MENU_NUMBER]; UINT16 LegacyCD[MAX_MENU_NUMBER];
UINT16 LegacyNET[MAX_MENU_NUMBER]; UINT16 LegacyNET[MAX_MENU_NUMBER];
UINT16 LegacyBEV[MAX_MENU_NUMBER]; UINT16 LegacyBEV[MAX_MENU_NUMBER];
} LEGACY_BOOT_NV_DATA; } LEGACY_BOOT_NV_DATA;
/// ///
@ -68,10 +62,10 @@ typedef struct {
// //
// Legacy Device Order Selection Storage // Legacy Device Order Selection Storage
// //
LEGACY_BOOT_NV_DATA InitialNvData; LEGACY_BOOT_NV_DATA InitialNvData;
LEGACY_BOOT_NV_DATA CurrentNvData; LEGACY_BOOT_NV_DATA CurrentNvData;
LEGACY_BOOT_NV_DATA LastTimeNvData; LEGACY_BOOT_NV_DATA LastTimeNvData;
UINT8 DisableMap[32]; UINT8 DisableMap[32];
} LEGACY_BOOT_MAINTAIN_DATA; } LEGACY_BOOT_MAINTAIN_DATA;
#pragma pack() #pragma pack()

View File

@ -28,7 +28,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#pragma pack(1) #pragma pack(1)
typedef struct { typedef struct {
UINT16 BbsIndex; UINT16 BbsIndex;
} LEGACY_BM_BOOT_OPTION_BBS_DATA; } LEGACY_BM_BOOT_OPTION_BBS_DATA;
#pragma pack() #pragma pack()
@ -44,7 +44,7 @@ typedef struct {
VOID VOID
EFIAPI EFIAPI
LegacyBmBoot ( LegacyBmBoot (
IN EFI_BOOT_MANAGER_LOAD_OPTION *BootOption IN EFI_BOOT_MANAGER_LOAD_OPTION *BootOption
); );
/** /**

File diff suppressed because it is too large Load Diff

View File

@ -36,13 +36,13 @@
// //
// This is needed for runtime variable access. // This is needed for runtime variable access.
// //
EFI_EVENT mEmuVarsFvbAddrChangeEvent = NULL; EFI_EVENT mEmuVarsFvbAddrChangeEvent = NULL;
// //
// This is the single instance supported by this driver. It // This is the single instance supported by this driver. It
// supports the FVB and Device Path protocols. // supports the FVB and Device Path protocols.
// //
EFI_FW_VOL_BLOCK_DEVICE mEmuVarsFvb = { EFI_FW_VOL_BLOCK_DEVICE mEmuVarsFvb = {
FVB_DEVICE_SIGNATURE, FVB_DEVICE_SIGNATURE,
{ // DevicePath { // DevicePath
{ {
@ -67,9 +67,9 @@ EFI_FW_VOL_BLOCK_DEVICE mEmuVarsFvb = {
} }
} }
}, },
NULL, // BufferPtr NULL, // BufferPtr
EMU_FVB_BLOCK_SIZE, // BlockSize EMU_FVB_BLOCK_SIZE, // BlockSize
EMU_FVB_SIZE, // Size EMU_FVB_SIZE, // Size
{ // FwVolBlockInstance { // FwVolBlockInstance
FvbProtocolGetAttributes, FvbProtocolGetAttributes,
FvbProtocolSetAttributes, FvbProtocolSetAttributes,
@ -82,7 +82,6 @@ EFI_FW_VOL_BLOCK_DEVICE mEmuVarsFvb = {
}, },
}; };
/** /**
Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE. Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
@ -96,14 +95,13 @@ EFI_FW_VOL_BLOCK_DEVICE mEmuVarsFvb = {
VOID VOID
EFIAPI EFIAPI
FvbVirtualAddressChangeEvent ( FvbVirtualAddressChangeEvent (
IN EFI_EVENT Event, IN EFI_EVENT Event,
IN VOID *Context IN VOID *Context
) )
{ {
EfiConvertPointer (0x0, &mEmuVarsFvb.BufferPtr); EfiConvertPointer (0x0, &mEmuVarsFvb.BufferPtr);
} }
// //
// FVB protocol APIs // FVB protocol APIs
// //
@ -128,20 +126,19 @@ FvbVirtualAddressChangeEvent (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
FvbProtocolGetPhysicalAddress ( FvbProtocolGetPhysicalAddress (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
OUT EFI_PHYSICAL_ADDRESS *Address OUT EFI_PHYSICAL_ADDRESS *Address
) )
{ {
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice; EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
FvbDevice = FVB_DEVICE_FROM_THIS (This); FvbDevice = FVB_DEVICE_FROM_THIS (This);
*Address = (EFI_PHYSICAL_ADDRESS)(UINTN) FvbDevice->BufferPtr; *Address = (EFI_PHYSICAL_ADDRESS)(UINTN)FvbDevice->BufferPtr;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
The GetBlockSize() function retrieves the size of the requested The GetBlockSize() function retrieves the size of the requested
block. It also returns the number of additional blocks with block. It also returns the number of additional blocks with
@ -171,13 +168,13 @@ FvbProtocolGetPhysicalAddress (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
FvbProtocolGetBlockSize ( FvbProtocolGetBlockSize (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
IN EFI_LBA Lba, IN EFI_LBA Lba,
OUT UINTN *BlockSize, OUT UINTN *BlockSize,
OUT UINTN *NumberOfBlocks OUT UINTN *NumberOfBlocks
) )
{ {
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice; EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
if (Lba >= EMU_FVB_NUM_TOTAL_BLOCKS) { if (Lba >= EMU_FVB_NUM_TOTAL_BLOCKS) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
@ -185,13 +182,12 @@ FvbProtocolGetBlockSize (
FvbDevice = FVB_DEVICE_FROM_THIS (This); FvbDevice = FVB_DEVICE_FROM_THIS (This);
*BlockSize = FvbDevice->BlockSize; *BlockSize = FvbDevice->BlockSize;
*NumberOfBlocks = (UINTN)(EMU_FVB_NUM_TOTAL_BLOCKS - Lba); *NumberOfBlocks = (UINTN)(EMU_FVB_NUM_TOTAL_BLOCKS - Lba);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
The GetAttributes() function retrieves the attributes and The GetAttributes() function retrieves the attributes and
current settings of the block. Status Codes Returned current settings of the block. Status Codes Returned
@ -210,23 +206,22 @@ FvbProtocolGetBlockSize (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
FvbProtocolGetAttributes ( FvbProtocolGetAttributes (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
OUT EFI_FVB_ATTRIBUTES_2 *Attributes OUT EFI_FVB_ATTRIBUTES_2 *Attributes
) )
{ {
*Attributes = *Attributes =
(EFI_FVB_ATTRIBUTES_2) ( (EFI_FVB_ATTRIBUTES_2)(
EFI_FVB2_READ_ENABLED_CAP | EFI_FVB2_READ_ENABLED_CAP |
EFI_FVB2_READ_STATUS | EFI_FVB2_READ_STATUS |
EFI_FVB2_WRITE_ENABLED_CAP | EFI_FVB2_WRITE_ENABLED_CAP |
EFI_FVB2_WRITE_STATUS | EFI_FVB2_WRITE_STATUS |
EFI_FVB2_ERASE_POLARITY EFI_FVB2_ERASE_POLARITY
); );
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
The SetAttributes() function sets configurable firmware volume The SetAttributes() function sets configurable firmware volume
attributes and returns the new settings of the firmware volume. attributes and returns the new settings of the firmware volume.
@ -252,14 +247,13 @@ FvbProtocolGetAttributes (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
FvbProtocolSetAttributes ( FvbProtocolSetAttributes (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes
) )
{ {
return EFI_ACCESS_DENIED; return EFI_ACCESS_DENIED;
} }
/** /**
Erases and initializes a firmware volume block. Erases and initializes a firmware volume block.
@ -311,16 +305,16 @@ FvbProtocolSetAttributes (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
FvbProtocolEraseBlocks ( FvbProtocolEraseBlocks (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
... ...
) )
{ {
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice; EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
VA_LIST Args; VA_LIST Args;
EFI_LBA StartingLba; EFI_LBA StartingLba;
UINTN NumOfLba; UINTN NumOfLba;
UINT8 *ErasePtr; UINT8 *ErasePtr;
UINTN EraseSize; UINTN EraseSize;
FvbDevice = FVB_DEVICE_FROM_THIS (This); FvbDevice = FVB_DEVICE_FROM_THIS (This);
@ -333,14 +327,17 @@ FvbProtocolEraseBlocks (
if (StartingLba == EFI_LBA_LIST_TERMINATOR) { if (StartingLba == EFI_LBA_LIST_TERMINATOR) {
break; break;
} }
NumOfLba = VA_ARG (Args, UINTN); NumOfLba = VA_ARG (Args, UINTN);
if (StartingLba > EMU_FVB_NUM_TOTAL_BLOCKS || if ((StartingLba > EMU_FVB_NUM_TOTAL_BLOCKS) ||
NumOfLba > EMU_FVB_NUM_TOTAL_BLOCKS - StartingLba) { (NumOfLba > EMU_FVB_NUM_TOTAL_BLOCKS - StartingLba))
{
VA_END (Args); VA_END (Args);
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
} while (1); } while (1);
VA_END (Args); VA_END (Args);
// //
@ -352,14 +349,16 @@ FvbProtocolEraseBlocks (
if (StartingLba == EFI_LBA_LIST_TERMINATOR) { if (StartingLba == EFI_LBA_LIST_TERMINATOR) {
break; break;
} }
NumOfLba = VA_ARG (Args, UINTN); NumOfLba = VA_ARG (Args, UINTN);
ErasePtr = FvbDevice->BufferPtr; ErasePtr = FvbDevice->BufferPtr;
ErasePtr += (UINTN)StartingLba * FvbDevice->BlockSize; ErasePtr += (UINTN)StartingLba * FvbDevice->BlockSize;
EraseSize = NumOfLba * FvbDevice->BlockSize; EraseSize = NumOfLba * FvbDevice->BlockSize;
SetMem (ErasePtr, EraseSize, ERASED_UINT8); SetMem (ErasePtr, EraseSize, ERASED_UINT8);
} while (1); } while (1);
VA_END (Args); VA_END (Args);
// //
@ -372,7 +371,6 @@ FvbProtocolEraseBlocks (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Writes the specified number of bytes from the input buffer to the block. Writes the specified number of bytes from the input buffer to the block.
@ -435,31 +433,32 @@ FvbProtocolEraseBlocks (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
FvbProtocolWrite ( FvbProtocolWrite (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
IN EFI_LBA Lba, IN EFI_LBA Lba,
IN UINTN Offset, IN UINTN Offset,
IN OUT UINTN *NumBytes, IN OUT UINTN *NumBytes,
IN UINT8 *Buffer IN UINT8 *Buffer
) )
{ {
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice; EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
UINT8 *FvbDataPtr; UINT8 *FvbDataPtr;
EFI_STATUS Status; EFI_STATUS Status;
FvbDevice = FVB_DEVICE_FROM_THIS (This); FvbDevice = FVB_DEVICE_FROM_THIS (This);
if (Lba >= EMU_FVB_NUM_TOTAL_BLOCKS || if ((Lba >= EMU_FVB_NUM_TOTAL_BLOCKS) ||
Offset > FvbDevice->BlockSize) { (Offset > FvbDevice->BlockSize))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
if (*NumBytes > FvbDevice->BlockSize - Offset) { if (*NumBytes > FvbDevice->BlockSize - Offset) {
*NumBytes = FvbDevice->BlockSize - Offset; *NumBytes = FvbDevice->BlockSize - Offset;
Status = EFI_BAD_BUFFER_SIZE; Status = EFI_BAD_BUFFER_SIZE;
} }
FvbDataPtr = FvbDevice->BufferPtr; FvbDataPtr = FvbDevice->BufferPtr;
FvbDataPtr += (UINTN)Lba * FvbDevice->BlockSize; FvbDataPtr += (UINTN)Lba * FvbDevice->BlockSize;
FvbDataPtr += Offset; FvbDataPtr += Offset;
@ -468,7 +467,6 @@ FvbProtocolWrite (
return Status; return Status;
} }
/** /**
Reads the specified number of bytes into a buffer from the specified block. Reads the specified number of bytes into a buffer from the specified block.
@ -519,31 +517,32 @@ FvbProtocolWrite (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
FvbProtocolRead ( FvbProtocolRead (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
IN EFI_LBA Lba, IN EFI_LBA Lba,
IN UINTN Offset, IN UINTN Offset,
IN OUT UINTN *NumBytes, IN OUT UINTN *NumBytes,
IN OUT UINT8 *Buffer IN OUT UINT8 *Buffer
) )
{ {
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice; EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
UINT8 *FvbDataPtr; UINT8 *FvbDataPtr;
EFI_STATUS Status; EFI_STATUS Status;
FvbDevice = FVB_DEVICE_FROM_THIS (This); FvbDevice = FVB_DEVICE_FROM_THIS (This);
if (Lba >= EMU_FVB_NUM_TOTAL_BLOCKS || if ((Lba >= EMU_FVB_NUM_TOTAL_BLOCKS) ||
Offset > FvbDevice->BlockSize) { (Offset > FvbDevice->BlockSize))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
if (*NumBytes > FvbDevice->BlockSize - Offset) { if (*NumBytes > FvbDevice->BlockSize - Offset) {
*NumBytes = FvbDevice->BlockSize - Offset; *NumBytes = FvbDevice->BlockSize - Offset;
Status = EFI_BAD_BUFFER_SIZE; Status = EFI_BAD_BUFFER_SIZE;
} }
FvbDataPtr = FvbDevice->BufferPtr; FvbDataPtr = FvbDevice->BufferPtr;
FvbDataPtr += (UINTN)Lba * FvbDevice->BlockSize; FvbDataPtr += (UINTN)Lba * FvbDevice->BlockSize;
FvbDataPtr += Offset; FvbDataPtr += Offset;
@ -552,7 +551,6 @@ FvbProtocolRead (
return Status; return Status;
} }
/** /**
Check the integrity of firmware volume header. Check the integrity of firmware volume header.
@ -564,7 +562,7 @@ FvbProtocolRead (
**/ **/
EFI_STATUS EFI_STATUS
ValidateFvHeader ( ValidateFvHeader (
IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader
) )
{ {
UINT16 Checksum; UINT16 Checksum;
@ -578,14 +576,16 @@ ValidateFvHeader (
(FwVolHeader->Signature != EFI_FVH_SIGNATURE) || (FwVolHeader->Signature != EFI_FVH_SIGNATURE) ||
(FwVolHeader->FvLength != EMU_FVB_SIZE) || (FwVolHeader->FvLength != EMU_FVB_SIZE) ||
(FwVolHeader->HeaderLength != EMU_FV_HEADER_LENGTH) (FwVolHeader->HeaderLength != EMU_FV_HEADER_LENGTH)
) { )
{
DEBUG ((DEBUG_INFO, "EMU Variable FVB: Basic FV headers were invalid\n")); DEBUG ((DEBUG_INFO, "EMU Variable FVB: Basic FV headers were invalid\n"));
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
// //
// Verify the header checksum // Verify the header checksum
// //
Checksum = CalculateSum16((VOID*) FwVolHeader, FwVolHeader->HeaderLength); Checksum = CalculateSum16 ((VOID *)FwVolHeader, FwVolHeader->HeaderLength);
if (Checksum != 0) { if (Checksum != 0) {
DEBUG ((DEBUG_INFO, "EMU Variable FVB: FV checksum was invalid\n")); DEBUG ((DEBUG_INFO, "EMU Variable FVB: FV checksum was invalid\n"));
@ -595,7 +595,6 @@ ValidateFvHeader (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Initializes the FV Header and Variable Store Header Initializes the FV Header and Variable Store Header
to support variable operations. to support variable operations.
@ -605,13 +604,13 @@ ValidateFvHeader (
**/ **/
VOID VOID
InitializeFvAndVariableStoreHeaders ( InitializeFvAndVariableStoreHeaders (
IN VOID *Ptr IN VOID *Ptr
) )
{ {
// //
// Templates for authenticated variable FV header // Templates for authenticated variable FV header
// //
STATIC FVB_FV_HDR_AND_VARS_TEMPLATE FvAndAuthenticatedVarTemplate = { STATIC FVB_FV_HDR_AND_VARS_TEMPLATE FvAndAuthenticatedVarTemplate = {
{ // EFI_FIRMWARE_VOLUME_HEADER FvHdr; { // EFI_FIRMWARE_VOLUME_HEADER FvHdr;
// UINT8 ZeroVector[16]; // UINT8 ZeroVector[16];
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
@ -638,7 +637,7 @@ InitializeFvAndVariableStoreHeaders (
0, 0,
// UINT8 Reserved[1]; // UINT8 Reserved[1];
{0}, { 0 },
// UINT8 Revision; // UINT8 Revision;
EFI_FVH_REVISION, EFI_FVH_REVISION,
@ -647,20 +646,20 @@ InitializeFvAndVariableStoreHeaders (
{ {
{ {
EMU_FVB_NUM_TOTAL_BLOCKS, // UINT32 NumBlocks; EMU_FVB_NUM_TOTAL_BLOCKS, // UINT32 NumBlocks;
EMU_FVB_BLOCK_SIZE // UINT32 Length; EMU_FVB_BLOCK_SIZE // UINT32 Length;
} }
} }
}, },
// EFI_FV_BLOCK_MAP_ENTRY EndBlockMap; // EFI_FV_BLOCK_MAP_ENTRY EndBlockMap;
{ 0, 0 }, // End of block map { 0, 0 }, // End of block map
{ // VARIABLE_STORE_HEADER VarHdr; { // VARIABLE_STORE_HEADER VarHdr;
// EFI_GUID Signature; // need authenticated variables for secure boot // EFI_GUID Signature; // need authenticated variables for secure boot
EFI_AUTHENTICATED_VARIABLE_GUID, EFI_AUTHENTICATED_VARIABLE_GUID,
// UINT32 Size; // UINT32 Size;
( (
FixedPcdGet32 (PcdFlashNvStorageVariableSize) - FixedPcdGet32 (PcdFlashNvStorageVariableSize) -
OFFSET_OF (FVB_FV_HDR_AND_VARS_TEMPLATE, VarHdr) OFFSET_OF (FVB_FV_HDR_AND_VARS_TEMPLATE, VarHdr)
), ),
// UINT8 Format; // UINT8 Format;
@ -691,7 +690,7 @@ InitializeFvAndVariableStoreHeaders (
// //
// Update the checksum for the FV header // Update the checksum for the FV header
// //
Fv = (EFI_FIRMWARE_VOLUME_HEADER*) Ptr; Fv = (EFI_FIRMWARE_VOLUME_HEADER *)Ptr;
Fv->Checksum = CalculateCheckSum16 (Ptr, Fv->HeaderLength); Fv->Checksum = CalculateCheckSum16 (Ptr, Fv->HeaderLength);
} }
@ -707,38 +706,44 @@ InitializeFvAndVariableStoreHeaders (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
FvbInitialize ( FvbInitialize (
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
VOID *Ptr; VOID *Ptr;
VOID *SubPtr; VOID *SubPtr;
BOOLEAN Initialize; BOOLEAN Initialize;
EFI_HANDLE Handle; EFI_HANDLE Handle;
EFI_PHYSICAL_ADDRESS Address; EFI_PHYSICAL_ADDRESS Address;
RETURN_STATUS PcdStatus; RETURN_STATUS PcdStatus;
DEBUG ((DEBUG_INFO, "EMU Variable FVB Started\n")); DEBUG ((DEBUG_INFO, "EMU Variable FVB Started\n"));
// //
// Verify that the PCD's are set correctly. // Verify that the PCD's are set correctly.
// //
ASSERT (FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) % ASSERT (
EMU_FVB_BLOCK_SIZE == 0); FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) %
EMU_FVB_BLOCK_SIZE == 0
);
if ( if (
(PcdGet32 (PcdFlashNvStorageVariableSize) + (PcdGet32 (PcdFlashNvStorageVariableSize) +
PcdGet32 (PcdFlashNvStorageFtwWorkingSize) PcdGet32 (PcdFlashNvStorageFtwWorkingSize)
) > ) >
EMU_FVB_NUM_SPARE_BLOCKS * EMU_FVB_BLOCK_SIZE EMU_FVB_NUM_SPARE_BLOCKS * EMU_FVB_BLOCK_SIZE
) { )
{
DEBUG ((DEBUG_ERROR, "EMU Variable invalid PCD sizes\n")); DEBUG ((DEBUG_ERROR, "EMU Variable invalid PCD sizes\n"));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (PcdGet64 (PcdFlashNvStorageVariableBase64) != 0) { if (PcdGet64 (PcdFlashNvStorageVariableBase64) != 0) {
DEBUG ((DEBUG_INFO, "Disabling EMU Variable FVB since " DEBUG ((
"flash variables appear to be supported.\n")); DEBUG_INFO,
"Disabling EMU Variable FVB since "
"flash variables appear to be supported.\n"
));
return EFI_ABORTED; return EFI_ABORTED;
} }
@ -752,7 +757,7 @@ FvbInitialize (
// //
Initialize = TRUE; Initialize = TRUE;
if (PcdGet64 (PcdEmuVariableNvStoreReserved) != 0) { if (PcdGet64 (PcdEmuVariableNvStoreReserved) != 0) {
Ptr = (VOID*)(UINTN) PcdGet64 (PcdEmuVariableNvStoreReserved); Ptr = (VOID *)(UINTN)PcdGet64 (PcdEmuVariableNvStoreReserved);
DEBUG (( DEBUG ((
DEBUG_INFO, DEBUG_INFO,
"EMU Variable FVB: Using pre-reserved block at %p\n", "EMU Variable FVB: Using pre-reserved block at %p\n",
@ -776,32 +781,37 @@ FvbInitialize (
SetMem (Ptr, EMU_FVB_SIZE, ERASED_UINT8); SetMem (Ptr, EMU_FVB_SIZE, ERASED_UINT8);
InitializeFvAndVariableStoreHeaders (Ptr); InitializeFvAndVariableStoreHeaders (Ptr);
} }
PcdStatus = PcdSet64S (PcdFlashNvStorageVariableBase64, (UINT32)(UINTN) Ptr);
PcdStatus = PcdSet64S (PcdFlashNvStorageVariableBase64, (UINT32)(UINTN)Ptr);
ASSERT_RETURN_ERROR (PcdStatus); ASSERT_RETURN_ERROR (PcdStatus);
// //
// Initialize the Fault Tolerant Write data area // Initialize the Fault Tolerant Write data area
// //
SubPtr = (VOID*) ((UINT8*) Ptr + PcdGet32 (PcdFlashNvStorageVariableSize)); SubPtr = (VOID *)((UINT8 *)Ptr + PcdGet32 (PcdFlashNvStorageVariableSize));
PcdStatus = PcdSet32S (PcdFlashNvStorageFtwWorkingBase, PcdStatus = PcdSet32S (
(UINT32)(UINTN) SubPtr); PcdFlashNvStorageFtwWorkingBase,
(UINT32)(UINTN)SubPtr
);
ASSERT_RETURN_ERROR (PcdStatus); ASSERT_RETURN_ERROR (PcdStatus);
// //
// Initialize the Fault Tolerant Write spare block // Initialize the Fault Tolerant Write spare block
// //
SubPtr = (VOID*) ((UINT8*) Ptr + SubPtr = (VOID *)((UINT8 *)Ptr +
EMU_FVB_NUM_SPARE_BLOCKS * EMU_FVB_BLOCK_SIZE); EMU_FVB_NUM_SPARE_BLOCKS * EMU_FVB_BLOCK_SIZE);
PcdStatus = PcdSet32S (PcdFlashNvStorageFtwSpareBase, PcdStatus = PcdSet32S (
(UINT32)(UINTN) SubPtr); PcdFlashNvStorageFtwSpareBase,
(UINT32)(UINTN)SubPtr
);
ASSERT_RETURN_ERROR (PcdStatus); ASSERT_RETURN_ERROR (PcdStatus);
// //
// Setup FVB device path // Setup FVB device path
// //
Address = (EFI_PHYSICAL_ADDRESS)(UINTN) Ptr; Address = (EFI_PHYSICAL_ADDRESS)(UINTN)Ptr;
mEmuVarsFvb.DevicePath.MemMapDevPath.StartingAddress = Address; mEmuVarsFvb.DevicePath.MemMapDevPath.StartingAddress = Address;
mEmuVarsFvb.DevicePath.MemMapDevPath.EndingAddress = Address + EMU_FVB_SIZE - 1; mEmuVarsFvb.DevicePath.MemMapDevPath.EndingAddress = Address + EMU_FVB_SIZE - 1;
// //
// Install the protocols // Install the protocols
@ -833,5 +843,3 @@ FvbInitialize (
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@ -19,36 +19,33 @@ Abstract:
// //
// Fvb Protocol instance data // Fvb Protocol instance data
// //
#define FVB_DEVICE_FROM_THIS(a) CR (a, EFI_FW_VOL_BLOCK_DEVICE, FwVolBlockInstance, FVB_DEVICE_SIGNATURE) #define FVB_DEVICE_FROM_THIS(a) CR (a, EFI_FW_VOL_BLOCK_DEVICE, FwVolBlockInstance, FVB_DEVICE_SIGNATURE)
#define FVB_DEVICE_SIGNATURE SIGNATURE_32 ('F', 'V', 'B', 'N') #define FVB_DEVICE_SIGNATURE SIGNATURE_32 ('F', 'V', 'B', 'N')
#pragma pack (1) #pragma pack (1)
typedef struct { typedef struct {
EFI_FIRMWARE_VOLUME_HEADER FvHdr;
EFI_FIRMWARE_VOLUME_HEADER FvHdr; EFI_FV_BLOCK_MAP_ENTRY EndBlockMap;
EFI_FV_BLOCK_MAP_ENTRY EndBlockMap; VARIABLE_STORE_HEADER VarHdr;
VARIABLE_STORE_HEADER VarHdr;
} FVB_FV_HDR_AND_VARS_TEMPLATE; } FVB_FV_HDR_AND_VARS_TEMPLATE;
typedef struct { typedef struct {
MEMMAP_DEVICE_PATH MemMapDevPath; MEMMAP_DEVICE_PATH MemMapDevPath;
EFI_DEVICE_PATH_PROTOCOL EndDevPath; EFI_DEVICE_PATH_PROTOCOL EndDevPath;
} FV_DEVICE_PATH; } FV_DEVICE_PATH;
#pragma pack () #pragma pack ()
typedef struct { typedef struct {
UINTN Signature; UINTN Signature;
FV_DEVICE_PATH DevicePath; FV_DEVICE_PATH DevicePath;
VOID *BufferPtr; VOID *BufferPtr;
UINTN BlockSize; UINTN BlockSize;
UINTN Size; UINTN Size;
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL FwVolBlockInstance; EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL FwVolBlockInstance;
} EFI_FW_VOL_BLOCK_DEVICE; } EFI_FW_VOL_BLOCK_DEVICE;
// //
// Constants // Constants
// //
@ -63,12 +60,12 @@ typedef struct {
#define FTW_WRITE_QUEUE_SIZE \ #define FTW_WRITE_QUEUE_SIZE \
(FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) - \ (FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) - \
sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER)) sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER))
#define EMU_FV_HEADER_LENGTH OFFSET_OF (FVB_FV_HDR_AND_VARS_TEMPLATE, VarHdr) #define EMU_FV_HEADER_LENGTH OFFSET_OF (FVB_FV_HDR_AND_VARS_TEMPLATE, VarHdr)
#define NOT_ERASED_BIT 0 #define NOT_ERASED_BIT 0
#define ERASED_BIT 1 #define ERASED_BIT 1
#define ERASED_UINT8 0xff #define ERASED_UINT8 0xff
#define ERASED_UINT32 0xffffffff #define ERASED_UINT32 0xffffffff
// //
// Protocol APIs // Protocol APIs

View File

@ -8,14 +8,13 @@
#include "EnrollDefaultKeys.h" #include "EnrollDefaultKeys.h"
// //
// Second KEK: "Microsoft Corporation KEK CA 2011". // Second KEK: "Microsoft Corporation KEK CA 2011".
// SHA1: 31:59:0b:fd:89:c9:d7:4e:d0:87:df:ac:66:33:4b:39:31:25:4b:30 // SHA1: 31:59:0b:fd:89:c9:d7:4e:d0:87:df:ac:66:33:4b:39:31:25:4b:30
// //
// "dbx" updates in "dbxtool" are signed with a key derived from this KEK. // "dbx" updates in "dbxtool" are signed with a key derived from this KEK.
// //
CONST UINT8 mMicrosoftKek[] = { CONST UINT8 mMicrosoftKek[] = {
0x30, 0x82, 0x05, 0xe8, 0x30, 0x82, 0x03, 0xd0, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x30, 0x82, 0x05, 0xe8, 0x30, 0x82, 0x03, 0xd0, 0xa0, 0x03, 0x02, 0x01, 0x02,
0x02, 0x0a, 0x61, 0x0a, 0xd1, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x30, 0x02, 0x0a, 0x61, 0x0a, 0xd1, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x30,
0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05,
@ -135,8 +134,7 @@ CONST UINT8 mMicrosoftKek[] = {
0x57, 0x4e, 0x36, 0xd2, 0x32, 0x84, 0xbf, 0x9e 0x57, 0x4e, 0x36, 0xd2, 0x32, 0x84, 0xbf, 0x9e
}; };
CONST UINTN mSizeOfMicrosoftKek = sizeof mMicrosoftKek; CONST UINTN mSizeOfMicrosoftKek = sizeof mMicrosoftKek;
// //
// First DB entry: "Microsoft Windows Production PCA 2011" // First DB entry: "Microsoft Windows Production PCA 2011"
@ -145,7 +143,7 @@ CONST UINTN mSizeOfMicrosoftKek = sizeof mMicrosoftKek;
// Windows 8 and Windows Server 2012 R2 boot loaders are signed with a chain // Windows 8 and Windows Server 2012 R2 boot loaders are signed with a chain
// rooted in this certificate. // rooted in this certificate.
// //
CONST UINT8 mMicrosoftPca[] = { CONST UINT8 mMicrosoftPca[] = {
0x30, 0x82, 0x05, 0xd7, 0x30, 0x82, 0x03, 0xbf, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x30, 0x82, 0x05, 0xd7, 0x30, 0x82, 0x03, 0xbf, 0xa0, 0x03, 0x02, 0x01, 0x02,
0x02, 0x0a, 0x61, 0x07, 0x76, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x30, 0x02, 0x0a, 0x61, 0x07, 0x76, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x30,
0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05,
@ -264,8 +262,7 @@ CONST UINT8 mMicrosoftPca[] = {
0x62, 0x1c, 0x59, 0x7e 0x62, 0x1c, 0x59, 0x7e
}; };
CONST UINTN mSizeOfMicrosoftPca = sizeof mMicrosoftPca; CONST UINTN mSizeOfMicrosoftPca = sizeof mMicrosoftPca;
// //
// Second DB entry: "Microsoft Corporation UEFI CA 2011" // Second DB entry: "Microsoft Corporation UEFI CA 2011"
@ -273,7 +270,7 @@ CONST UINTN mSizeOfMicrosoftPca = sizeof mMicrosoftPca;
// //
// To verify the "shim" binary and PCI expansion ROMs with. // To verify the "shim" binary and PCI expansion ROMs with.
// //
CONST UINT8 mMicrosoftUefiCa[] = { CONST UINT8 mMicrosoftUefiCa[] = {
0x30, 0x82, 0x06, 0x10, 0x30, 0x82, 0x03, 0xf8, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x30, 0x82, 0x06, 0x10, 0x30, 0x82, 0x03, 0xf8, 0xa0, 0x03, 0x02, 0x01, 0x02,
0x02, 0x0a, 0x61, 0x08, 0xd3, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x30, 0x02, 0x0a, 0x61, 0x08, 0xd3, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x30,
0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05,
@ -396,8 +393,7 @@ CONST UINT8 mMicrosoftUefiCa[] = {
0x07, 0x92, 0x9b, 0xf5, 0xa6, 0xbc, 0x59, 0x83, 0x58 0x07, 0x92, 0x9b, 0xf5, 0xa6, 0xbc, 0x59, 0x83, 0x58
}; };
CONST UINTN mSizeOfMicrosoftUefiCa = sizeof mMicrosoftUefiCa; CONST UINTN mSizeOfMicrosoftUefiCa = sizeof mMicrosoftUefiCa;
// //
// The Microsoft.UefiSecureBootLogo.Tests.OutOfBoxConfirmDBXisPresent test case // The Microsoft.UefiSecureBootLogo.Tests.OutOfBoxConfirmDBXisPresent test case
@ -431,10 +427,10 @@ CONST UINTN mSizeOfMicrosoftUefiCa = sizeof mMicrosoftUefiCa;
// practice recommended -- in natural English langauge -- in the // practice recommended -- in natural English langauge -- in the
// above-referenced TechNet article. // above-referenced TechNet article.
// //
CONST UINT8 mSha256OfDevNull[] = { CONST UINT8 mSha256OfDevNull[] = {
0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99,
0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95,
0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55
}; };
CONST UINTN mSizeOfSha256OfDevNull = sizeof mSha256OfDevNull; CONST UINTN mSizeOfSha256OfDevNull = sizeof mSha256OfDevNull;

View File

@ -24,7 +24,6 @@
#include "EnrollDefaultKeys.h" #include "EnrollDefaultKeys.h"
/** /**
Fetch the X509 certificate (to be used as Platform Key and first Key Exchange Fetch the X509 certificate (to be used as Platform Key and first Key Exchange
Key) from SMBIOS. Key) from SMBIOS.
@ -54,47 +53,55 @@
STATIC STATIC
EFI_STATUS EFI_STATUS
GetPkKek1 ( GetPkKek1 (
OUT UINT8 **PkKek1, OUT UINT8 **PkKek1,
OUT UINTN *SizeOfPkKek1 OUT UINTN *SizeOfPkKek1
) )
{ {
CONST CHAR8 *Base64Cert; CONST CHAR8 *Base64Cert;
CHAR8 OvmfPkKek1AppPrefix[GUID_STRING_LENGTH + 1 + 1]; CHAR8 OvmfPkKek1AppPrefix[GUID_STRING_LENGTH + 1 + 1];
EFI_STATUS Status; EFI_STATUS Status;
EFI_SMBIOS_PROTOCOL *Smbios; EFI_SMBIOS_PROTOCOL *Smbios;
EFI_SMBIOS_HANDLE Handle; EFI_SMBIOS_HANDLE Handle;
EFI_SMBIOS_TYPE Type; EFI_SMBIOS_TYPE Type;
EFI_SMBIOS_TABLE_HEADER *Header; EFI_SMBIOS_TABLE_HEADER *Header;
SMBIOS_TABLE_TYPE11 *OemStringsTable; SMBIOS_TABLE_TYPE11 *OemStringsTable;
UINTN Base64CertLen; UINTN Base64CertLen;
UINTN DecodedCertSize; UINTN DecodedCertSize;
UINT8 *DecodedCert; UINT8 *DecodedCert;
Base64Cert = NULL; Base64Cert = NULL;
// //
// Format the application prefix, for OEM String matching. // Format the application prefix, for OEM String matching.
// //
AsciiSPrint (OvmfPkKek1AppPrefix, sizeof OvmfPkKek1AppPrefix, "%g:", AsciiSPrint (
&gOvmfPkKek1AppPrefixGuid); OvmfPkKek1AppPrefix,
sizeof OvmfPkKek1AppPrefix,
"%g:",
&gOvmfPkKek1AppPrefixGuid
);
// //
// Scan all "OEM Strings" tables. // Scan all "OEM Strings" tables.
// //
Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, Status = gBS->LocateProtocol (
(VOID **)&Smbios); &gEfiSmbiosProtocolGuid,
NULL,
(VOID **)&Smbios
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
AsciiPrint ("error: failed to locate EFI_SMBIOS_PROTOCOL: %r\n", Status); AsciiPrint ("error: failed to locate EFI_SMBIOS_PROTOCOL: %r\n", Status);
return Status; return Status;
} }
Handle = SMBIOS_HANDLE_PI_RESERVED; Handle = SMBIOS_HANDLE_PI_RESERVED;
Type = SMBIOS_TYPE_OEM_STRINGS; Type = SMBIOS_TYPE_OEM_STRINGS;
for (Status = Smbios->GetNext (Smbios, &Handle, &Type, &Header, NULL); for (Status = Smbios->GetNext (Smbios, &Handle, &Type, &Header, NULL);
!EFI_ERROR (Status); !EFI_ERROR (Status);
Status = Smbios->GetNext (Smbios, &Handle, &Type, &Header, NULL)) { Status = Smbios->GetNext (Smbios, &Handle, &Type, &Header, NULL))
CONST CHAR8 *OemString; {
UINTN Idx; CONST CHAR8 *OemString;
UINTN Idx;
if (Header->Length < sizeof *OemStringsTable) { if (Header->Length < sizeof *OemStringsTable) {
// //
@ -102,6 +109,7 @@ GetPkKek1 (
// //
continue; continue;
} }
OemStringsTable = (SMBIOS_TABLE_TYPE11 *)Header; OemStringsTable = (SMBIOS_TABLE_TYPE11 *)Header;
// //
@ -110,13 +118,17 @@ GetPkKek1 (
// //
OemString = (CONST CHAR8 *)(OemStringsTable + 1); OemString = (CONST CHAR8 *)(OemStringsTable + 1);
for (Idx = 0; Idx < OemStringsTable->StringCount; ++Idx) { for (Idx = 0; Idx < OemStringsTable->StringCount; ++Idx) {
CHAR8 CandidatePrefix[sizeof OvmfPkKek1AppPrefix]; CHAR8 CandidatePrefix[sizeof OvmfPkKek1AppPrefix];
// //
// NUL-terminate the candidate prefix for case-insensitive comparison. // NUL-terminate the candidate prefix for case-insensitive comparison.
// //
AsciiStrnCpyS (CandidatePrefix, sizeof CandidatePrefix, OemString, AsciiStrnCpyS (
GUID_STRING_LENGTH + 1); CandidatePrefix,
sizeof CandidatePrefix,
OemString,
GUID_STRING_LENGTH + 1
);
if (AsciiStriCmp (OvmfPkKek1AppPrefix, CandidatePrefix) == 0) { if (AsciiStriCmp (OvmfPkKek1AppPrefix, CandidatePrefix) == 0) {
// //
// The current string matches the prefix. // The current string matches the prefix.
@ -124,6 +136,7 @@ GetPkKek1 (
Base64Cert = OemString + GUID_STRING_LENGTH + 1; Base64Cert = OemString + GUID_STRING_LENGTH + 1;
break; break;
} }
OemString += AsciiStrSize (OemString); OemString += AsciiStrSize (OemString);
} }
@ -139,8 +152,11 @@ GetPkKek1 (
// //
// No table with a matching string has been found. // No table with a matching string has been found.
// //
AsciiPrint ("error: OEM String with app prefix %g not found: %r\n", AsciiPrint (
&gOvmfPkKek1AppPrefixGuid, Status); "error: OEM String with app prefix %g not found: %r\n",
&gOvmfPkKek1AppPrefixGuid,
Status
);
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
@ -151,19 +167,23 @@ GetPkKek1 (
// Verify the base64 encoding, and determine the decoded size. // Verify the base64 encoding, and determine the decoded size.
// //
DecodedCertSize = 0; DecodedCertSize = 0;
Status = Base64Decode (Base64Cert, Base64CertLen, NULL, &DecodedCertSize); Status = Base64Decode (Base64Cert, Base64CertLen, NULL, &DecodedCertSize);
switch (Status) { switch (Status) {
case EFI_BUFFER_TOO_SMALL: case EFI_BUFFER_TOO_SMALL:
ASSERT (DecodedCertSize > 0); ASSERT (DecodedCertSize > 0);
break; break;
case EFI_SUCCESS: case EFI_SUCCESS:
AsciiPrint ("error: empty certificate after app prefix %g\n", AsciiPrint (
&gOvmfPkKek1AppPrefixGuid); "error: empty certificate after app prefix %g\n",
return EFI_PROTOCOL_ERROR; &gOvmfPkKek1AppPrefixGuid
default: );
AsciiPrint ("error: invalid base64 string after app prefix %g\n", return EFI_PROTOCOL_ERROR;
&gOvmfPkKek1AppPrefixGuid); default:
return EFI_PROTOCOL_ERROR; AsciiPrint (
"error: invalid base64 string after app prefix %g\n",
&gOvmfPkKek1AppPrefixGuid
);
return EFI_PROTOCOL_ERROR;
} }
// //
@ -178,16 +198,19 @@ GetPkKek1 (
// //
// Decoding will succeed at this point. // Decoding will succeed at this point.
// //
Status = Base64Decode (Base64Cert, Base64CertLen, DecodedCert, Status = Base64Decode (
&DecodedCertSize); Base64Cert,
Base64CertLen,
DecodedCert,
&DecodedCertSize
);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
*PkKek1 = DecodedCert; *PkKek1 = DecodedCert;
*SizeOfPkKek1 = DecodedCertSize; *SizeOfPkKek1 = DecodedCertSize;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Enroll a set of certificates in a global variable, overwriting it. Enroll a set of certificates in a global variable, overwriting it.
@ -235,20 +258,20 @@ STATIC
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
EnrollListOfCerts ( EnrollListOfCerts (
IN CHAR16 *VariableName, IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid, IN EFI_GUID *VendorGuid,
IN EFI_GUID *CertType, IN EFI_GUID *CertType,
... ...
) )
{ {
UINTN DataSize; UINTN DataSize;
SINGLE_HEADER *SingleHeader; SINGLE_HEADER *SingleHeader;
REPEATING_HEADER *RepeatingHeader; REPEATING_HEADER *RepeatingHeader;
VA_LIST Marker; VA_LIST Marker;
CONST UINT8 *Cert; CONST UINT8 *Cert;
EFI_STATUS Status; EFI_STATUS Status;
UINT8 *Data; UINT8 *Data;
UINT8 *Position; UINT8 *Position;
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
@ -259,25 +282,30 @@ EnrollListOfCerts (
VA_START (Marker, CertType); VA_START (Marker, CertType);
for (Cert = VA_ARG (Marker, CONST UINT8 *); for (Cert = VA_ARG (Marker, CONST UINT8 *);
Cert != NULL; Cert != NULL;
Cert = VA_ARG (Marker, CONST UINT8 *)) { Cert = VA_ARG (Marker, CONST UINT8 *))
UINTN CertSize; {
UINTN CertSize;
CertSize = VA_ARG (Marker, UINTN); CertSize = VA_ARG (Marker, UINTN);
(VOID)VA_ARG (Marker, CONST EFI_GUID *); (VOID)VA_ARG (Marker, CONST EFI_GUID *);
if (CertSize == 0 || if ((CertSize == 0) ||
CertSize > MAX_UINT32 - sizeof *RepeatingHeader || (CertSize > MAX_UINT32 - sizeof *RepeatingHeader) ||
DataSize > MAX_UINT32 - sizeof *RepeatingHeader - CertSize) { (DataSize > MAX_UINT32 - sizeof *RepeatingHeader - CertSize))
{
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
break; break;
} }
DataSize += sizeof *RepeatingHeader + CertSize; DataSize += sizeof *RepeatingHeader + CertSize;
} }
VA_END (Marker); VA_END (Marker);
if (DataSize == sizeof *SingleHeader) { if (DataSize == sizeof *SingleHeader) {
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
} }
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto Out; goto Out;
} }
@ -291,27 +319,28 @@ EnrollListOfCerts (
Position = Data; Position = Data;
SingleHeader = (SINGLE_HEADER *)Position; SingleHeader = (SINGLE_HEADER *)Position;
Status = gRT->GetTime (&SingleHeader->TimeStamp, NULL); Status = gRT->GetTime (&SingleHeader->TimeStamp, NULL);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto FreeData; goto FreeData;
} }
SingleHeader->TimeStamp.Pad1 = 0; SingleHeader->TimeStamp.Pad1 = 0;
SingleHeader->TimeStamp.Nanosecond = 0; SingleHeader->TimeStamp.Nanosecond = 0;
SingleHeader->TimeStamp.TimeZone = 0; SingleHeader->TimeStamp.TimeZone = 0;
SingleHeader->TimeStamp.Daylight = 0; SingleHeader->TimeStamp.Daylight = 0;
SingleHeader->TimeStamp.Pad2 = 0; SingleHeader->TimeStamp.Pad2 = 0;
#if 0 #if 0
SingleHeader->dwLength = DataSize - sizeof SingleHeader->TimeStamp; SingleHeader->dwLength = DataSize - sizeof SingleHeader->TimeStamp;
#else #else
// //
// This looks like a bug in edk2. According to the UEFI specification, // This looks like a bug in edk2. According to the UEFI specification,
// dwLength is "The length of the entire certificate, including the length of // dwLength is "The length of the entire certificate, including the length of
// the header, in bytes". That shouldn't stop right after CertType -- it // the header, in bytes". That shouldn't stop right after CertType -- it
// should include everything below it. // should include everything below it.
// //
SingleHeader->dwLength = sizeof *SingleHeader SingleHeader->dwLength = sizeof *SingleHeader
- sizeof SingleHeader->TimeStamp; - sizeof SingleHeader->TimeStamp;
#endif #endif
SingleHeader->wRevision = 0x0200; SingleHeader->wRevision = 0x0200;
SingleHeader->wCertificateType = WIN_CERT_TYPE_EFI_GUID; SingleHeader->wCertificateType = WIN_CERT_TYPE_EFI_GUID;
CopyGuid (&SingleHeader->CertType, &gEfiCertPkcs7Guid); CopyGuid (&SingleHeader->CertType, &gEfiCertPkcs7Guid);
@ -320,16 +349,17 @@ EnrollListOfCerts (
VA_START (Marker, CertType); VA_START (Marker, CertType);
for (Cert = VA_ARG (Marker, CONST UINT8 *); for (Cert = VA_ARG (Marker, CONST UINT8 *);
Cert != NULL; Cert != NULL;
Cert = VA_ARG (Marker, CONST UINT8 *)) { Cert = VA_ARG (Marker, CONST UINT8 *))
UINTN CertSize; {
CONST EFI_GUID *OwnerGuid; UINTN CertSize;
CONST EFI_GUID *OwnerGuid;
CertSize = VA_ARG (Marker, UINTN); CertSize = VA_ARG (Marker, UINTN);
OwnerGuid = VA_ARG (Marker, CONST EFI_GUID *); OwnerGuid = VA_ARG (Marker, CONST EFI_GUID *);
RepeatingHeader = (REPEATING_HEADER *)Position; RepeatingHeader = (REPEATING_HEADER *)Position;
CopyGuid (&RepeatingHeader->SignatureType, CertType); CopyGuid (&RepeatingHeader->SignatureType, CertType);
RepeatingHeader->SignatureListSize = RepeatingHeader->SignatureListSize =
(UINT32)(sizeof *RepeatingHeader + CertSize); (UINT32)(sizeof *RepeatingHeader + CertSize);
RepeatingHeader->SignatureHeaderSize = 0; RepeatingHeader->SignatureHeaderSize = 0;
RepeatingHeader->SignatureSize = RepeatingHeader->SignatureSize =
@ -340,29 +370,39 @@ EnrollListOfCerts (
CopyMem (Position, Cert, CertSize); CopyMem (Position, Cert, CertSize);
Position += CertSize; Position += CertSize;
} }
VA_END (Marker); VA_END (Marker);
ASSERT (Data + DataSize == Position); ASSERT (Data + DataSize == Position);
Status = gRT->SetVariable (VariableName, VendorGuid, Status = gRT->SetVariable (
VariableName,
VendorGuid,
(EFI_VARIABLE_NON_VOLATILE | (EFI_VARIABLE_NON_VOLATILE |
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS |
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS |
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS), EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS),
DataSize, Data); DataSize,
Data
);
FreeData: FreeData:
FreePool (Data); FreePool (Data);
Out: Out:
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
AsciiPrint ("error: %a(\"%s\", %g): %r\n", __FUNCTION__, VariableName, AsciiPrint (
VendorGuid, Status); "error: %a(\"%s\", %g): %r\n",
__FUNCTION__,
VariableName,
VendorGuid,
Status
);
} }
return Status; return Status;
} }
/** /**
Read a UEFI variable into a caller-allocated buffer, enforcing an exact size. Read a UEFI variable into a caller-allocated buffer, enforcing an exact size.
@ -404,39 +444,48 @@ Out:
STATIC STATIC
EFI_STATUS EFI_STATUS
GetExact ( GetExact (
IN CHAR16 *VariableName, IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid, IN EFI_GUID *VendorGuid,
OUT VOID *Data, OUT VOID *Data,
IN UINTN DataSize, IN UINTN DataSize,
IN BOOLEAN AllowMissing IN BOOLEAN AllowMissing
) )
{ {
UINTN Size; UINTN Size;
EFI_STATUS Status; EFI_STATUS Status;
Size = DataSize; Size = DataSize;
Status = gRT->GetVariable (VariableName, VendorGuid, NULL, &Size, Data); Status = gRT->GetVariable (VariableName, VendorGuid, NULL, &Size, Data);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
if (Status == EFI_NOT_FOUND && AllowMissing) { if ((Status == EFI_NOT_FOUND) && AllowMissing) {
ZeroMem (Data, DataSize); ZeroMem (Data, DataSize);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
AsciiPrint ("error: GetVariable(\"%s\", %g): %r\n", VariableName, AsciiPrint (
VendorGuid, Status); "error: GetVariable(\"%s\", %g): %r\n",
VariableName,
VendorGuid,
Status
);
return Status; return Status;
} }
if (Size != DataSize) { if (Size != DataSize) {
AsciiPrint ("error: GetVariable(\"%s\", %g): expected size 0x%Lx, " AsciiPrint (
"got 0x%Lx\n", VariableName, VendorGuid, (UINT64)DataSize, (UINT64)Size); "error: GetVariable(\"%s\", %g): expected size 0x%Lx, "
"got 0x%Lx\n",
VariableName,
VendorGuid,
(UINT64)DataSize,
(UINT64)Size
);
return EFI_PROTOCOL_ERROR; return EFI_PROTOCOL_ERROR;
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Populate a SETTINGS structure from the underlying UEFI variables. Populate a SETTINGS structure from the underlying UEFI variables.
@ -464,42 +513,65 @@ GetExact (
STATIC STATIC
EFI_STATUS EFI_STATUS
GetSettings ( GetSettings (
OUT SETTINGS *Settings OUT SETTINGS *Settings
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
Status = GetExact (EFI_SETUP_MODE_NAME, &gEfiGlobalVariableGuid, Status = GetExact (
&Settings->SetupMode, sizeof Settings->SetupMode, FALSE); EFI_SETUP_MODE_NAME,
&gEfiGlobalVariableGuid,
&Settings->SetupMode,
sizeof Settings->SetupMode,
FALSE
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
Status = GetExact (EFI_SECURE_BOOT_MODE_NAME, &gEfiGlobalVariableGuid, Status = GetExact (
&Settings->SecureBoot, sizeof Settings->SecureBoot, FALSE); EFI_SECURE_BOOT_MODE_NAME,
&gEfiGlobalVariableGuid,
&Settings->SecureBoot,
sizeof Settings->SecureBoot,
FALSE
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
Status = GetExact (EFI_SECURE_BOOT_ENABLE_NAME, Status = GetExact (
&gEfiSecureBootEnableDisableGuid, &Settings->SecureBootEnable, EFI_SECURE_BOOT_ENABLE_NAME,
sizeof Settings->SecureBootEnable, TRUE); &gEfiSecureBootEnableDisableGuid,
&Settings->SecureBootEnable,
sizeof Settings->SecureBootEnable,
TRUE
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
Status = GetExact (EFI_CUSTOM_MODE_NAME, &gEfiCustomModeEnableGuid, Status = GetExact (
&Settings->CustomMode, sizeof Settings->CustomMode, FALSE); EFI_CUSTOM_MODE_NAME,
&gEfiCustomModeEnableGuid,
&Settings->CustomMode,
sizeof Settings->CustomMode,
FALSE
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
Status = GetExact (EFI_VENDOR_KEYS_VARIABLE_NAME, &gEfiGlobalVariableGuid, Status = GetExact (
&Settings->VendorKeys, sizeof Settings->VendorKeys, FALSE); EFI_VENDOR_KEYS_VARIABLE_NAME,
&gEfiGlobalVariableGuid,
&Settings->VendorKeys,
sizeof Settings->VendorKeys,
FALSE
);
return Status; return Status;
} }
/** /**
Print the contents of a SETTINGS structure to the UEFI console. Print the contents of a SETTINGS structure to the UEFI console.
@ -508,33 +580,38 @@ GetSettings (
STATIC STATIC
VOID VOID
PrintSettings ( PrintSettings (
IN CONST SETTINGS *Settings IN CONST SETTINGS *Settings
) )
{ {
AsciiPrint ("info: SetupMode=%d SecureBoot=%d SecureBootEnable=%d " AsciiPrint (
"CustomMode=%d VendorKeys=%d\n", Settings->SetupMode, Settings->SecureBoot, "info: SetupMode=%d SecureBoot=%d SecureBootEnable=%d "
Settings->SecureBootEnable, Settings->CustomMode, Settings->VendorKeys); "CustomMode=%d VendorKeys=%d\n",
Settings->SetupMode,
Settings->SecureBoot,
Settings->SecureBootEnable,
Settings->CustomMode,
Settings->VendorKeys
);
} }
/** /**
Entry point function of this shell application. Entry point function of this shell application.
**/ **/
INTN INTN
EFIAPI EFIAPI
ShellAppMain ( ShellAppMain (
IN UINTN Argc, IN UINTN Argc,
IN CHAR16 **Argv IN CHAR16 **Argv
) )
{ {
INTN RetVal; INTN RetVal;
EFI_STATUS Status; EFI_STATUS Status;
SETTINGS Settings; SETTINGS Settings;
UINT8 *PkKek1; UINT8 *PkKek1;
UINTN SizeOfPkKek1; UINTN SizeOfPkKek1;
BOOLEAN NoDefault; BOOLEAN NoDefault;
if (Argc == 2 && StrCmp (Argv[1], L"--no-default") == 0) { if ((Argc == 2) && (StrCmp (Argv[1], L"--no-default") == 0)) {
NoDefault = TRUE; NoDefault = TRUE;
} else { } else {
NoDefault = FALSE; NoDefault = FALSE;
@ -552,6 +629,7 @@ ShellAppMain (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return RetVal; return RetVal;
} }
PrintSettings (&Settings); PrintSettings (&Settings);
if (Settings.SetupMode != 1) { if (Settings.SetupMode != 1) {
@ -563,7 +641,7 @@ ShellAppMain (
// Set PkKek1 and SizeOfPkKek1 to suppress incorrect compiler/analyzer // Set PkKek1 and SizeOfPkKek1 to suppress incorrect compiler/analyzer
// warnings. // warnings.
// //
PkKek1 = NULL; PkKek1 = NULL;
SizeOfPkKek1 = 0; SizeOfPkKek1 = 0;
// //
@ -581,13 +659,21 @@ ShellAppMain (
// //
if (Settings.CustomMode != CUSTOM_SECURE_BOOT_MODE) { if (Settings.CustomMode != CUSTOM_SECURE_BOOT_MODE) {
Settings.CustomMode = CUSTOM_SECURE_BOOT_MODE; Settings.CustomMode = CUSTOM_SECURE_BOOT_MODE;
Status = gRT->SetVariable (EFI_CUSTOM_MODE_NAME, &gEfiCustomModeEnableGuid, Status = gRT->SetVariable (
(EFI_VARIABLE_NON_VOLATILE | EFI_CUSTOM_MODE_NAME,
EFI_VARIABLE_BOOTSERVICE_ACCESS), &gEfiCustomModeEnableGuid,
sizeof Settings.CustomMode, &Settings.CustomMode); (EFI_VARIABLE_NON_VOLATILE |
EFI_VARIABLE_BOOTSERVICE_ACCESS),
sizeof Settings.CustomMode,
&Settings.CustomMode
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
AsciiPrint ("error: SetVariable(\"%s\", %g): %r\n", EFI_CUSTOM_MODE_NAME, AsciiPrint (
&gEfiCustomModeEnableGuid, Status); "error: SetVariable(\"%s\", %g): %r\n",
EFI_CUSTOM_MODE_NAME,
&gEfiCustomModeEnableGuid,
Status
);
goto FreePkKek1; goto FreePkKek1;
} }
} }
@ -600,17 +686,26 @@ ShellAppMain (
EFI_IMAGE_SECURITY_DATABASE, EFI_IMAGE_SECURITY_DATABASE,
&gEfiImageSecurityDatabaseGuid, &gEfiImageSecurityDatabaseGuid,
&gEfiCertX509Guid, &gEfiCertX509Guid,
PkKek1, SizeOfPkKek1, &gEfiCallerIdGuid, PkKek1,
NULL); SizeOfPkKek1,
&gEfiCallerIdGuid,
NULL
);
} else { } else {
Status = EnrollListOfCerts ( Status = EnrollListOfCerts (
EFI_IMAGE_SECURITY_DATABASE, EFI_IMAGE_SECURITY_DATABASE,
&gEfiImageSecurityDatabaseGuid, &gEfiImageSecurityDatabaseGuid,
&gEfiCertX509Guid, &gEfiCertX509Guid,
mMicrosoftPca, mSizeOfMicrosoftPca, &gMicrosoftVendorGuid, mMicrosoftPca,
mMicrosoftUefiCa, mSizeOfMicrosoftUefiCa, &gMicrosoftVendorGuid, mSizeOfMicrosoftPca,
NULL); &gMicrosoftVendorGuid,
mMicrosoftUefiCa,
mSizeOfMicrosoftUefiCa,
&gMicrosoftVendorGuid,
NULL
);
} }
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto FreePkKek1; goto FreePkKek1;
} }
@ -622,8 +717,11 @@ ShellAppMain (
EFI_IMAGE_SECURITY_DATABASE1, EFI_IMAGE_SECURITY_DATABASE1,
&gEfiImageSecurityDatabaseGuid, &gEfiImageSecurityDatabaseGuid,
&gEfiCertSha256Guid, &gEfiCertSha256Guid,
mSha256OfDevNull, mSizeOfSha256OfDevNull, &gEfiCallerIdGuid, mSha256OfDevNull,
NULL); mSizeOfSha256OfDevNull,
&gEfiCallerIdGuid,
NULL
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto FreePkKek1; goto FreePkKek1;
} }
@ -636,17 +734,26 @@ ShellAppMain (
EFI_KEY_EXCHANGE_KEY_NAME, EFI_KEY_EXCHANGE_KEY_NAME,
&gEfiGlobalVariableGuid, &gEfiGlobalVariableGuid,
&gEfiCertX509Guid, &gEfiCertX509Guid,
PkKek1, SizeOfPkKek1, &gEfiCallerIdGuid, PkKek1,
NULL); SizeOfPkKek1,
&gEfiCallerIdGuid,
NULL
);
} else { } else {
Status = EnrollListOfCerts ( Status = EnrollListOfCerts (
EFI_KEY_EXCHANGE_KEY_NAME, EFI_KEY_EXCHANGE_KEY_NAME,
&gEfiGlobalVariableGuid, &gEfiGlobalVariableGuid,
&gEfiCertX509Guid, &gEfiCertX509Guid,
PkKek1, SizeOfPkKek1, &gEfiCallerIdGuid, PkKek1,
mMicrosoftKek, mSizeOfMicrosoftKek, &gMicrosoftVendorGuid, SizeOfPkKek1,
NULL); &gEfiCallerIdGuid,
mMicrosoftKek,
mSizeOfMicrosoftKek,
&gMicrosoftVendorGuid,
NULL
);
} }
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto FreePkKek1; goto FreePkKek1;
} }
@ -658,8 +765,11 @@ ShellAppMain (
EFI_PLATFORM_KEY_NAME, EFI_PLATFORM_KEY_NAME,
&gEfiGlobalVariableGuid, &gEfiGlobalVariableGuid,
&gEfiCertX509Guid, &gEfiCertX509Guid,
PkKek1, SizeOfPkKek1, &gEfiGlobalVariableGuid, PkKek1,
NULL); SizeOfPkKek1,
&gEfiGlobalVariableGuid,
NULL
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto FreePkKek1; goto FreePkKek1;
} }
@ -669,12 +779,20 @@ ShellAppMain (
// signatures. // signatures.
// //
Settings.CustomMode = STANDARD_SECURE_BOOT_MODE; Settings.CustomMode = STANDARD_SECURE_BOOT_MODE;
Status = gRT->SetVariable (EFI_CUSTOM_MODE_NAME, &gEfiCustomModeEnableGuid, Status = gRT->SetVariable (
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, EFI_CUSTOM_MODE_NAME,
sizeof Settings.CustomMode, &Settings.CustomMode); &gEfiCustomModeEnableGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
sizeof Settings.CustomMode,
&Settings.CustomMode
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
AsciiPrint ("error: SetVariable(\"%s\", %g): %r\n", EFI_CUSTOM_MODE_NAME, AsciiPrint (
&gEfiCustomModeEnableGuid, Status); "error: SetVariable(\"%s\", %g): %r\n",
EFI_CUSTOM_MODE_NAME,
&gEfiCustomModeEnableGuid,
Status
);
goto FreePkKek1; goto FreePkKek1;
} }
@ -713,11 +831,13 @@ ShellAppMain (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto FreePkKek1; goto FreePkKek1;
} }
PrintSettings (&Settings); PrintSettings (&Settings);
if (Settings.SetupMode != 0 || Settings.SecureBoot != 1 || if ((Settings.SetupMode != 0) || (Settings.SecureBoot != 1) ||
Settings.SecureBootEnable != 1 || Settings.CustomMode != 0 || (Settings.SecureBootEnable != 1) || (Settings.CustomMode != 0) ||
Settings.VendorKeys != 0) { (Settings.VendorKeys != 0))
{
AsciiPrint ("error: unexpected\n"); AsciiPrint ("error: unexpected\n");
goto FreePkKek1; goto FreePkKek1;
} }

View File

@ -75,30 +75,30 @@
// //
#pragma pack (1) #pragma pack (1)
typedef struct { typedef struct {
EFI_TIME TimeStamp; EFI_TIME TimeStamp;
// //
// dwLength covers data below // dwLength covers data below
// //
UINT32 dwLength; UINT32 dwLength;
UINT16 wRevision; UINT16 wRevision;
UINT16 wCertificateType; UINT16 wCertificateType;
EFI_GUID CertType; EFI_GUID CertType;
} SINGLE_HEADER; } SINGLE_HEADER;
typedef struct { typedef struct {
// //
// SignatureListSize covers data below // SignatureListSize covers data below
// //
EFI_GUID SignatureType; EFI_GUID SignatureType;
UINT32 SignatureListSize; UINT32 SignatureListSize;
UINT32 SignatureHeaderSize; // constant 0 UINT32 SignatureHeaderSize; // constant 0
UINT32 SignatureSize; UINT32 SignatureSize;
// //
// SignatureSize covers data below // SignatureSize covers data below
// //
EFI_GUID SignatureOwner; EFI_GUID SignatureOwner;
// //
// X.509 certificate follows // X.509 certificate follows
@ -106,33 +106,31 @@ typedef struct {
} REPEATING_HEADER; } REPEATING_HEADER;
#pragma pack () #pragma pack ()
// //
// A structure that collects the values of UEFI variables related to Secure // A structure that collects the values of UEFI variables related to Secure
// Boot. // Boot.
// //
typedef struct { typedef struct {
UINT8 SetupMode; UINT8 SetupMode;
UINT8 SecureBoot; UINT8 SecureBoot;
UINT8 SecureBootEnable; UINT8 SecureBootEnable;
UINT8 CustomMode; UINT8 CustomMode;
UINT8 VendorKeys; UINT8 VendorKeys;
} SETTINGS; } SETTINGS;
// //
// Refer to "AuthData.c" for details on the following objects. // Refer to "AuthData.c" for details on the following objects.
// //
extern CONST UINT8 mMicrosoftKek[]; extern CONST UINT8 mMicrosoftKek[];
extern CONST UINTN mSizeOfMicrosoftKek; extern CONST UINTN mSizeOfMicrosoftKek;
extern CONST UINT8 mMicrosoftPca[]; extern CONST UINT8 mMicrosoftPca[];
extern CONST UINTN mSizeOfMicrosoftPca; extern CONST UINTN mSizeOfMicrosoftPca;
extern CONST UINT8 mMicrosoftUefiCa[]; extern CONST UINT8 mMicrosoftUefiCa[];
extern CONST UINTN mSizeOfMicrosoftUefiCa; extern CONST UINTN mSizeOfMicrosoftUefiCa;
extern CONST UINT8 mSha256OfDevNull[]; extern CONST UINT8 mSha256OfDevNull[];
extern CONST UINTN mSizeOfSha256OfDevNull; extern CONST UINTN mSizeOfSha256OfDevNull;
#endif /* ENROLL_DEFAULT_KEYS_H_ */ #endif /* ENROLL_DEFAULT_KEYS_H_ */

View File

@ -27,103 +27,124 @@
// //
#pragma pack (1) #pragma pack (1)
typedef struct { typedef struct {
UINT32 Type; UINT32 Type;
UINT64 ChildBase; UINT64 ChildBase;
UINT64 CpuBase; UINT64 CpuBase;
UINT64 Size; UINT64 Size;
} DTB_PCI_HOST_RANGE_RECORD; } DTB_PCI_HOST_RANGE_RECORD;
#pragma pack () #pragma pack ()
#define DTB_PCI_HOST_RANGE_RELOCATABLE BIT31 #define DTB_PCI_HOST_RANGE_RELOCATABLE BIT31
#define DTB_PCI_HOST_RANGE_PREFETCHABLE BIT30 #define DTB_PCI_HOST_RANGE_PREFETCHABLE BIT30
#define DTB_PCI_HOST_RANGE_ALIASED BIT29 #define DTB_PCI_HOST_RANGE_ALIASED BIT29
#define DTB_PCI_HOST_RANGE_MMIO32 BIT25 #define DTB_PCI_HOST_RANGE_MMIO32 BIT25
#define DTB_PCI_HOST_RANGE_MMIO64 (BIT25 | BIT24) #define DTB_PCI_HOST_RANGE_MMIO64 (BIT25 | BIT24)
#define DTB_PCI_HOST_RANGE_IO BIT24 #define DTB_PCI_HOST_RANGE_IO BIT24
#define DTB_PCI_HOST_RANGE_TYPEMASK (BIT31 | BIT30 | BIT29 | BIT25 | BIT24) #define DTB_PCI_HOST_RANGE_TYPEMASK (BIT31 | BIT30 | BIT29 | BIT25 | BIT24)
STATIC STATIC
EFI_STATUS EFI_STATUS
MapGcdMmioSpace ( MapGcdMmioSpace (
IN UINT64 Base, IN UINT64 Base,
IN UINT64 Size IN UINT64 Size
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
Status = gDS->AddMemorySpace (EfiGcdMemoryTypeMemoryMappedIo, Base, Size, Status = gDS->AddMemorySpace (
EFI_MEMORY_UC); EfiGcdMemoryTypeMemoryMappedIo,
Base,
Size,
EFI_MEMORY_UC
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, DEBUG ((
DEBUG_ERROR,
"%a: failed to add GCD memory space for region [0x%Lx+0x%Lx)\n", "%a: failed to add GCD memory space for region [0x%Lx+0x%Lx)\n",
__FUNCTION__, Base, Size)); __FUNCTION__,
Base,
Size
));
return Status; return Status;
} }
Status = gDS->SetMemorySpaceAttributes (Base, Size, EFI_MEMORY_UC); Status = gDS->SetMemorySpaceAttributes (Base, Size, EFI_MEMORY_UC);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, DEBUG ((
DEBUG_ERROR,
"%a: failed to set memory space attributes for region [0x%Lx+0x%Lx)\n", "%a: failed to set memory space attributes for region [0x%Lx+0x%Lx)\n",
__FUNCTION__, Base, Size)); __FUNCTION__,
Base,
Size
));
} }
return Status; return Status;
} }
STATIC STATIC
EFI_STATUS EFI_STATUS
ProcessPciHost ( ProcessPciHost (
OUT UINT64 *IoBase, OUT UINT64 *IoBase,
OUT UINT64 *IoSize, OUT UINT64 *IoSize,
OUT UINT64 *Mmio32Base, OUT UINT64 *Mmio32Base,
OUT UINT64 *Mmio32Size, OUT UINT64 *Mmio32Size,
OUT UINT64 *Mmio64Base, OUT UINT64 *Mmio64Base,
OUT UINT64 *Mmio64Size, OUT UINT64 *Mmio64Size,
OUT UINT32 *BusMin, OUT UINT32 *BusMin,
OUT UINT32 *BusMax OUT UINT32 *BusMax
) )
{ {
FDT_CLIENT_PROTOCOL *FdtClient; FDT_CLIENT_PROTOCOL *FdtClient;
INT32 Node; INT32 Node;
UINT64 ConfigBase, ConfigSize; UINT64 ConfigBase, ConfigSize;
CONST VOID *Prop; CONST VOID *Prop;
UINT32 Len; UINT32 Len;
UINT32 RecordIdx; UINT32 RecordIdx;
EFI_STATUS Status; EFI_STATUS Status;
UINT64 IoTranslation; UINT64 IoTranslation;
UINT64 Mmio32Translation; UINT64 Mmio32Translation;
UINT64 Mmio64Translation; UINT64 Mmio64Translation;
// //
// The following output arguments are initialized only in // The following output arguments are initialized only in
// order to suppress '-Werror=maybe-uninitialized' warnings // order to suppress '-Werror=maybe-uninitialized' warnings
// *incorrectly* emitted by some gcc versions. // *incorrectly* emitted by some gcc versions.
// //
*IoBase = 0; *IoBase = 0;
*Mmio32Base = 0; *Mmio32Base = 0;
*Mmio64Base = MAX_UINT64; *Mmio64Base = MAX_UINT64;
*BusMin = 0; *BusMin = 0;
*BusMax = 0; *BusMax = 0;
// //
// *IoSize, *Mmio##Size and IoTranslation are initialized to zero because the // *IoSize, *Mmio##Size and IoTranslation are initialized to zero because the
// logic below requires it. However, since they are also affected by the issue // logic below requires it. However, since they are also affected by the issue
// reported above, they are initialized early. // reported above, they are initialized early.
// //
*IoSize = 0; *IoSize = 0;
*Mmio32Size = 0; *Mmio32Size = 0;
*Mmio64Size = 0; *Mmio64Size = 0;
IoTranslation = 0; IoTranslation = 0;
Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL, Status = gBS->LocateProtocol (
(VOID **)&FdtClient); &gFdtClientProtocolGuid,
NULL,
(VOID **)&FdtClient
);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
Status = FdtClient->FindCompatibleNode (FdtClient, "pci-host-ecam-generic", Status = FdtClient->FindCompatibleNode (
&Node); FdtClient,
"pci-host-ecam-generic",
&Node
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, DEBUG ((
DEBUG_INFO,
"%a: No 'pci-host-ecam-generic' compatible DT node found\n", "%a: No 'pci-host-ecam-generic' compatible DT node found\n",
__FUNCTION__)); __FUNCTION__
));
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
@ -134,15 +155,22 @@ ProcessPciHost (
// A DT can legally describe multiple PCI host bridges, but we are not // A DT can legally describe multiple PCI host bridges, but we are not
// equipped to deal with that. So assert that there is only one. // equipped to deal with that. So assert that there is only one.
// //
Status = FdtClient->FindNextCompatibleNode (FdtClient, Status = FdtClient->FindNextCompatibleNode (
"pci-host-ecam-generic", Node, &Tmp); FdtClient,
"pci-host-ecam-generic",
Node,
&Tmp
);
ASSERT (Status == EFI_NOT_FOUND); ASSERT (Status == EFI_NOT_FOUND);
); );
Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg", &Prop, &Len); Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg", &Prop, &Len);
if (EFI_ERROR (Status) || Len != 2 * sizeof (UINT64)) { if (EFI_ERROR (Status) || (Len != 2 * sizeof (UINT64))) {
DEBUG ((DEBUG_ERROR, "%a: 'reg' property not found or invalid\n", DEBUG ((
__FUNCTION__)); DEBUG_ERROR,
"%a: 'reg' property not found or invalid\n",
__FUNCTION__
));
return EFI_PROTOCOL_ERROR; return EFI_PROTOCOL_ERROR;
} }
@ -155,13 +183,22 @@ ProcessPciHost (
// //
// Fetch the bus range (note: inclusive). // Fetch the bus range (note: inclusive).
// //
Status = FdtClient->GetNodeProperty (FdtClient, Node, "bus-range", &Prop, Status = FdtClient->GetNodeProperty (
&Len); FdtClient,
if (EFI_ERROR (Status) || Len != 2 * sizeof (UINT32)) { Node,
DEBUG ((DEBUG_ERROR, "%a: 'bus-range' not found or invalid\n", "bus-range",
__FUNCTION__)); &Prop,
&Len
);
if (EFI_ERROR (Status) || (Len != 2 * sizeof (UINT32))) {
DEBUG ((
DEBUG_ERROR,
"%a: 'bus-range' not found or invalid\n",
__FUNCTION__
));
return EFI_PROTOCOL_ERROR; return EFI_PROTOCOL_ERROR;
} }
*BusMin = SwapBytes32 (((CONST UINT32 *)Prop)[0]); *BusMin = SwapBytes32 (((CONST UINT32 *)Prop)[0]);
*BusMax = SwapBytes32 (((CONST UINT32 *)Prop)[1]); *BusMax = SwapBytes32 (((CONST UINT32 *)Prop)[1]);
@ -169,10 +206,14 @@ ProcessPciHost (
// Sanity check: the config space must accommodate all 4K register bytes of // Sanity check: the config space must accommodate all 4K register bytes of
// all 8 functions of all 32 devices of all buses. // all 8 functions of all 32 devices of all buses.
// //
if (*BusMax < *BusMin || *BusMax - *BusMin == MAX_UINT32 || if ((*BusMax < *BusMin) || (*BusMax - *BusMin == MAX_UINT32) ||
DivU64x32 (ConfigSize, SIZE_4KB * 8 * 32) < *BusMax - *BusMin + 1) { (DivU64x32 (ConfigSize, SIZE_4KB * 8 * 32) < *BusMax - *BusMin + 1))
DEBUG ((DEBUG_ERROR, "%a: invalid 'bus-range' and/or 'reg'\n", {
__FUNCTION__)); DEBUG ((
DEBUG_ERROR,
"%a: invalid 'bus-range' and/or 'reg'\n",
__FUNCTION__
));
return EFI_PROTOCOL_ERROR; return EFI_PROTOCOL_ERROR;
} }
@ -180,66 +221,84 @@ ProcessPciHost (
// Iterate over "ranges". // Iterate over "ranges".
// //
Status = FdtClient->GetNodeProperty (FdtClient, Node, "ranges", &Prop, &Len); Status = FdtClient->GetNodeProperty (FdtClient, Node, "ranges", &Prop, &Len);
if (EFI_ERROR (Status) || Len == 0 || if (EFI_ERROR (Status) || (Len == 0) ||
Len % sizeof (DTB_PCI_HOST_RANGE_RECORD) != 0) { (Len % sizeof (DTB_PCI_HOST_RANGE_RECORD) != 0))
{
DEBUG ((DEBUG_ERROR, "%a: 'ranges' not found or invalid\n", __FUNCTION__)); DEBUG ((DEBUG_ERROR, "%a: 'ranges' not found or invalid\n", __FUNCTION__));
return EFI_PROTOCOL_ERROR; return EFI_PROTOCOL_ERROR;
} }
for (RecordIdx = 0; RecordIdx < Len / sizeof (DTB_PCI_HOST_RANGE_RECORD); for (RecordIdx = 0; RecordIdx < Len / sizeof (DTB_PCI_HOST_RANGE_RECORD);
++RecordIdx) { ++RecordIdx)
CONST DTB_PCI_HOST_RANGE_RECORD *Record; {
CONST DTB_PCI_HOST_RANGE_RECORD *Record;
Record = (CONST DTB_PCI_HOST_RANGE_RECORD *)Prop + RecordIdx; Record = (CONST DTB_PCI_HOST_RANGE_RECORD *)Prop + RecordIdx;
switch (SwapBytes32 (Record->Type) & DTB_PCI_HOST_RANGE_TYPEMASK) { switch (SwapBytes32 (Record->Type) & DTB_PCI_HOST_RANGE_TYPEMASK) {
case DTB_PCI_HOST_RANGE_IO: case DTB_PCI_HOST_RANGE_IO:
*IoBase = SwapBytes64 (Record->ChildBase); *IoBase = SwapBytes64 (Record->ChildBase);
*IoSize = SwapBytes64 (Record->Size); *IoSize = SwapBytes64 (Record->Size);
IoTranslation = SwapBytes64 (Record->CpuBase) - *IoBase; IoTranslation = SwapBytes64 (Record->CpuBase) - *IoBase;
ASSERT (PcdGet64 (PcdPciIoTranslation) == IoTranslation); ASSERT (PcdGet64 (PcdPciIoTranslation) == IoTranslation);
break; break;
case DTB_PCI_HOST_RANGE_MMIO32: case DTB_PCI_HOST_RANGE_MMIO32:
*Mmio32Base = SwapBytes64 (Record->ChildBase); *Mmio32Base = SwapBytes64 (Record->ChildBase);
*Mmio32Size = SwapBytes64 (Record->Size); *Mmio32Size = SwapBytes64 (Record->Size);
Mmio32Translation = SwapBytes64 (Record->CpuBase) - *Mmio32Base; Mmio32Translation = SwapBytes64 (Record->CpuBase) - *Mmio32Base;
if (*Mmio32Base > MAX_UINT32 || *Mmio32Size > MAX_UINT32 || if ((*Mmio32Base > MAX_UINT32) || (*Mmio32Size > MAX_UINT32) ||
*Mmio32Base + *Mmio32Size > SIZE_4GB) { (*Mmio32Base + *Mmio32Size > SIZE_4GB))
DEBUG ((DEBUG_ERROR, "%a: MMIO32 space invalid\n", __FUNCTION__)); {
return EFI_PROTOCOL_ERROR; DEBUG ((DEBUG_ERROR, "%a: MMIO32 space invalid\n", __FUNCTION__));
} return EFI_PROTOCOL_ERROR;
}
ASSERT (PcdGet64 (PcdPciMmio32Translation) == Mmio32Translation); ASSERT (PcdGet64 (PcdPciMmio32Translation) == Mmio32Translation);
if (Mmio32Translation != 0) { if (Mmio32Translation != 0) {
DEBUG ((DEBUG_ERROR, "%a: unsupported nonzero MMIO32 translation " DEBUG ((
"0x%Lx\n", __FUNCTION__, Mmio32Translation)); DEBUG_ERROR,
return EFI_UNSUPPORTED; "%a: unsupported nonzero MMIO32 translation "
} "0x%Lx\n",
__FUNCTION__,
Mmio32Translation
));
return EFI_UNSUPPORTED;
}
break; break;
case DTB_PCI_HOST_RANGE_MMIO64: case DTB_PCI_HOST_RANGE_MMIO64:
*Mmio64Base = SwapBytes64 (Record->ChildBase); *Mmio64Base = SwapBytes64 (Record->ChildBase);
*Mmio64Size = SwapBytes64 (Record->Size); *Mmio64Size = SwapBytes64 (Record->Size);
Mmio64Translation = SwapBytes64 (Record->CpuBase) - *Mmio64Base; Mmio64Translation = SwapBytes64 (Record->CpuBase) - *Mmio64Base;
ASSERT (PcdGet64 (PcdPciMmio64Translation) == Mmio64Translation); ASSERT (PcdGet64 (PcdPciMmio64Translation) == Mmio64Translation);
if (Mmio64Translation != 0) { if (Mmio64Translation != 0) {
DEBUG ((DEBUG_ERROR, "%a: unsupported nonzero MMIO64 translation " DEBUG ((
"0x%Lx\n", __FUNCTION__, Mmio64Translation)); DEBUG_ERROR,
return EFI_UNSUPPORTED; "%a: unsupported nonzero MMIO64 translation "
} "0x%Lx\n",
__FUNCTION__,
Mmio64Translation
));
return EFI_UNSUPPORTED;
}
break; break;
} }
} }
if (*IoSize == 0 || *Mmio32Size == 0) {
DEBUG ((DEBUG_ERROR, "%a: %a space empty\n", __FUNCTION__, if ((*IoSize == 0) || (*Mmio32Size == 0)) {
(*IoSize == 0) ? "IO" : "MMIO32")); DEBUG ((
DEBUG_ERROR,
"%a: %a space empty\n",
__FUNCTION__,
(*IoSize == 0) ? "IO" : "MMIO32"
));
return EFI_PROTOCOL_ERROR; return EFI_PROTOCOL_ERROR;
} }
@ -249,10 +308,23 @@ ProcessPciHost (
// //
ASSERT (PcdGet64 (PcdPciExpressBaseAddress) == ConfigBase); ASSERT (PcdGet64 (PcdPciExpressBaseAddress) == ConfigBase);
DEBUG ((DEBUG_INFO, "%a: Config[0x%Lx+0x%Lx) Bus[0x%x..0x%x] " DEBUG ((
DEBUG_INFO,
"%a: Config[0x%Lx+0x%Lx) Bus[0x%x..0x%x] "
"Io[0x%Lx+0x%Lx)@0x%Lx Mem32[0x%Lx+0x%Lx)@0x0 Mem64[0x%Lx+0x%Lx)@0x0\n", "Io[0x%Lx+0x%Lx)@0x%Lx Mem32[0x%Lx+0x%Lx)@0x0 Mem64[0x%Lx+0x%Lx)@0x0\n",
__FUNCTION__, ConfigBase, ConfigSize, *BusMin, *BusMax, *IoBase, *IoSize, __FUNCTION__,
IoTranslation, *Mmio32Base, *Mmio32Size, *Mmio64Base, *Mmio64Size)); ConfigBase,
ConfigSize,
*BusMin,
*BusMax,
*IoBase,
*IoSize,
IoTranslation,
*Mmio32Base,
*Mmio32Size,
*Mmio64Base,
*Mmio64Size
));
// Map the ECAM space in the GCD memory map // Map the ECAM space in the GCD memory map
Status = MapGcdMmioSpace (ConfigBase, ConfigSize); Status = MapGcdMmioSpace (ConfigBase, ConfigSize);
@ -284,21 +356,21 @@ ProcessPciHost (
PCI_ROOT_BRIDGE * PCI_ROOT_BRIDGE *
EFIAPI EFIAPI
PciHostBridgeGetRootBridges ( PciHostBridgeGetRootBridges (
UINTN *Count UINTN *Count
) )
{ {
UINT64 IoBase, IoSize; UINT64 IoBase, IoSize;
UINT64 Mmio32Base, Mmio32Size; UINT64 Mmio32Base, Mmio32Size;
UINT64 Mmio64Base, Mmio64Size; UINT64 Mmio64Base, Mmio64Size;
UINT32 BusMin, BusMax; UINT32 BusMin, BusMax;
EFI_STATUS Status; EFI_STATUS Status;
UINT64 Attributes; UINT64 Attributes;
UINT64 AllocationAttributes; UINT64 AllocationAttributes;
PCI_ROOT_BRIDGE_APERTURE Io; PCI_ROOT_BRIDGE_APERTURE Io;
PCI_ROOT_BRIDGE_APERTURE Mem; PCI_ROOT_BRIDGE_APERTURE Mem;
PCI_ROOT_BRIDGE_APERTURE MemAbove4G; PCI_ROOT_BRIDGE_APERTURE MemAbove4G;
PCI_ROOT_BRIDGE_APERTURE PMem; PCI_ROOT_BRIDGE_APERTURE PMem;
PCI_ROOT_BRIDGE_APERTURE PMemAbove4G; PCI_ROOT_BRIDGE_APERTURE PMemAbove4G;
if (PcdGet64 (PcdPciExpressBaseAddress) == 0) { if (PcdGet64 (PcdPciExpressBaseAddress) == 0) {
DEBUG ((DEBUG_INFO, "%a: PCI host bridge not present\n", __FUNCTION__)); DEBUG ((DEBUG_INFO, "%a: PCI host bridge not present\n", __FUNCTION__));
@ -307,11 +379,23 @@ PciHostBridgeGetRootBridges (
return NULL; return NULL;
} }
Status = ProcessPciHost (&IoBase, &IoSize, &Mmio32Base, &Mmio32Size, Status = ProcessPciHost (
&Mmio64Base, &Mmio64Size, &BusMin, &BusMax); &IoBase,
&IoSize,
&Mmio32Base,
&Mmio32Size,
&Mmio64Base,
&Mmio64Size,
&BusMin,
&BusMax
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to discover PCI host bridge: %r\n", DEBUG ((
__FUNCTION__, Status)); DEBUG_ERROR,
"%a: failed to discover PCI host bridge: %r\n",
__FUNCTION__,
Status
));
*Count = 0; *Count = 0;
return NULL; return NULL;
} }
@ -322,21 +406,21 @@ PciHostBridgeGetRootBridges (
ZeroMem (&PMem, sizeof (PMem)); ZeroMem (&PMem, sizeof (PMem));
ZeroMem (&PMemAbove4G, sizeof (PMemAbove4G)); ZeroMem (&PMemAbove4G, sizeof (PMemAbove4G));
Attributes = EFI_PCI_ATTRIBUTE_ISA_IO_16 | Attributes = EFI_PCI_ATTRIBUTE_ISA_IO_16 |
EFI_PCI_ATTRIBUTE_ISA_MOTHERBOARD_IO | EFI_PCI_ATTRIBUTE_ISA_MOTHERBOARD_IO |
EFI_PCI_ATTRIBUTE_VGA_IO_16 | EFI_PCI_ATTRIBUTE_VGA_IO_16 |
EFI_PCI_ATTRIBUTE_VGA_PALETTE_IO_16; EFI_PCI_ATTRIBUTE_VGA_PALETTE_IO_16;
AllocationAttributes = EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM; AllocationAttributes = EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM;
Io.Base = IoBase; Io.Base = IoBase;
Io.Limit = IoBase + IoSize - 1; Io.Limit = IoBase + IoSize - 1;
Mem.Base = Mmio32Base; Mem.Base = Mmio32Base;
Mem.Limit = Mmio32Base + Mmio32Size - 1; Mem.Limit = Mmio32Base + Mmio32Size - 1;
if (sizeof (UINTN) == sizeof (UINT64)) { if (sizeof (UINTN) == sizeof (UINT64)) {
MemAbove4G.Base = Mmio64Base; MemAbove4G.Base = Mmio64Base;
MemAbove4G.Limit = Mmio64Base + Mmio64Size - 1; MemAbove4G.Limit = Mmio64Base + Mmio64Size - 1;
if (Mmio64Size > 0) { if (Mmio64Size > 0) {
AllocationAttributes |= EFI_PCI_HOST_BRIDGE_MEM64_DECODE; AllocationAttributes |= EFI_PCI_HOST_BRIDGE_MEM64_DECODE;
} }
@ -347,32 +431,32 @@ PciHostBridgeGetRootBridges (
// BARs unless they are allocated below 4 GB. So ignore the range above // BARs unless they are allocated below 4 GB. So ignore the range above
// 4 GB in this case. // 4 GB in this case.
// //
MemAbove4G.Base = MAX_UINT64; MemAbove4G.Base = MAX_UINT64;
MemAbove4G.Limit = 0; MemAbove4G.Limit = 0;
} }
// //
// No separate ranges for prefetchable and non-prefetchable BARs // No separate ranges for prefetchable and non-prefetchable BARs
// //
PMem.Base = MAX_UINT64; PMem.Base = MAX_UINT64;
PMem.Limit = 0; PMem.Limit = 0;
PMemAbove4G.Base = MAX_UINT64; PMemAbove4G.Base = MAX_UINT64;
PMemAbove4G.Limit = 0; PMemAbove4G.Limit = 0;
return PciHostBridgeUtilityGetRootBridges ( return PciHostBridgeUtilityGetRootBridges (
Count, Count,
Attributes, Attributes,
AllocationAttributes, AllocationAttributes,
TRUE, TRUE,
FALSE, FALSE,
BusMin, BusMin,
BusMax, BusMax,
&Io, &Io,
&Mem, &Mem,
&MemAbove4G, &MemAbove4G,
&PMem, &PMem,
&PMemAbove4G &PMemAbove4G
); );
} }
/** /**
@ -385,8 +469,8 @@ PciHostBridgeGetRootBridges (
VOID VOID
EFIAPI EFIAPI
PciHostBridgeFreeRootBridges ( PciHostBridgeFreeRootBridges (
PCI_ROOT_BRIDGE *Bridges, PCI_ROOT_BRIDGE *Bridges,
UINTN Count UINTN Count
) )
{ {
PciHostBridgeUtilityFreeRootBridges (Bridges, Count); PciHostBridgeUtilityFreeRootBridges (Bridges, Count);
@ -409,8 +493,8 @@ PciHostBridgeFreeRootBridges (
VOID VOID
EFIAPI EFIAPI
PciHostBridgeResourceConflict ( PciHostBridgeResourceConflict (
EFI_HANDLE HostBridgeHandle, EFI_HANDLE HostBridgeHandle,
VOID *Configuration VOID *Configuration
) )
{ {
PciHostBridgeUtilityResourceConflict (Configuration); PciHostBridgeUtilityResourceConflict (Configuration);

View File

@ -22,59 +22,62 @@
// //
#pragma pack (1) #pragma pack (1)
typedef struct { typedef struct {
UINT32 Type; UINT32 Type;
UINT64 ChildBase; UINT64 ChildBase;
UINT64 CpuBase; UINT64 CpuBase;
UINT64 Size; UINT64 Size;
} DTB_PCI_HOST_RANGE_RECORD; } DTB_PCI_HOST_RANGE_RECORD;
#pragma pack () #pragma pack ()
#define DTB_PCI_HOST_RANGE_RELOCATABLE BIT31 #define DTB_PCI_HOST_RANGE_RELOCATABLE BIT31
#define DTB_PCI_HOST_RANGE_PREFETCHABLE BIT30 #define DTB_PCI_HOST_RANGE_PREFETCHABLE BIT30
#define DTB_PCI_HOST_RANGE_ALIASED BIT29 #define DTB_PCI_HOST_RANGE_ALIASED BIT29
#define DTB_PCI_HOST_RANGE_MMIO32 BIT25 #define DTB_PCI_HOST_RANGE_MMIO32 BIT25
#define DTB_PCI_HOST_RANGE_MMIO64 (BIT25 | BIT24) #define DTB_PCI_HOST_RANGE_MMIO64 (BIT25 | BIT24)
#define DTB_PCI_HOST_RANGE_IO BIT24 #define DTB_PCI_HOST_RANGE_IO BIT24
#define DTB_PCI_HOST_RANGE_TYPEMASK (BIT31 | BIT30 | BIT29 | BIT25 | BIT24) #define DTB_PCI_HOST_RANGE_TYPEMASK (BIT31 | BIT30 | BIT29 | BIT25 | BIT24)
STATIC STATIC
RETURN_STATUS RETURN_STATUS
GetPciIoTranslation ( GetPciIoTranslation (
IN FDT_CLIENT_PROTOCOL *FdtClient, IN FDT_CLIENT_PROTOCOL *FdtClient,
IN INT32 Node, IN INT32 Node,
OUT UINT64 *IoTranslation OUT UINT64 *IoTranslation
) )
{ {
UINT32 RecordIdx; UINT32 RecordIdx;
CONST VOID *Prop; CONST VOID *Prop;
UINT32 Len; UINT32 Len;
EFI_STATUS Status; EFI_STATUS Status;
UINT64 IoBase; UINT64 IoBase;
// //
// Iterate over "ranges". // Iterate over "ranges".
// //
Status = FdtClient->GetNodeProperty (FdtClient, Node, "ranges", &Prop, &Len); Status = FdtClient->GetNodeProperty (FdtClient, Node, "ranges", &Prop, &Len);
if (EFI_ERROR (Status) || Len == 0 || if (EFI_ERROR (Status) || (Len == 0) ||
Len % sizeof (DTB_PCI_HOST_RANGE_RECORD) != 0) { (Len % sizeof (DTB_PCI_HOST_RANGE_RECORD) != 0))
{
DEBUG ((DEBUG_ERROR, "%a: 'ranges' not found or invalid\n", __FUNCTION__)); DEBUG ((DEBUG_ERROR, "%a: 'ranges' not found or invalid\n", __FUNCTION__));
return RETURN_PROTOCOL_ERROR; return RETURN_PROTOCOL_ERROR;
} }
for (RecordIdx = 0; RecordIdx < Len / sizeof (DTB_PCI_HOST_RANGE_RECORD); for (RecordIdx = 0; RecordIdx < Len / sizeof (DTB_PCI_HOST_RANGE_RECORD);
++RecordIdx) { ++RecordIdx)
CONST DTB_PCI_HOST_RANGE_RECORD *Record; {
UINT32 Type; CONST DTB_PCI_HOST_RANGE_RECORD *Record;
UINT32 Type;
Record = (CONST DTB_PCI_HOST_RANGE_RECORD *)Prop + RecordIdx; Record = (CONST DTB_PCI_HOST_RANGE_RECORD *)Prop + RecordIdx;
Type = SwapBytes32 (Record->Type) & DTB_PCI_HOST_RANGE_TYPEMASK; Type = SwapBytes32 (Record->Type) & DTB_PCI_HOST_RANGE_TYPEMASK;
if (Type == DTB_PCI_HOST_RANGE_IO) { if (Type == DTB_PCI_HOST_RANGE_IO) {
IoBase = SwapBytes64 (Record->ChildBase); IoBase = SwapBytes64 (Record->ChildBase);
*IoTranslation = SwapBytes64 (Record->CpuBase) - IoBase; *IoTranslation = SwapBytes64 (Record->CpuBase) - IoBase;
return RETURN_SUCCESS; return RETURN_SUCCESS;
} }
} }
return RETURN_NOT_FOUND; return RETURN_NOT_FOUND;
} }
@ -84,15 +87,15 @@ FdtPciPcdProducerLibConstructor (
VOID VOID
) )
{ {
UINT64 PciExpressBaseAddress; UINT64 PciExpressBaseAddress;
FDT_CLIENT_PROTOCOL *FdtClient; FDT_CLIENT_PROTOCOL *FdtClient;
CONST UINT64 *Reg; CONST UINT64 *Reg;
UINT32 RegSize; UINT32 RegSize;
EFI_STATUS Status; EFI_STATUS Status;
INT32 Node; INT32 Node;
RETURN_STATUS RetStatus; RETURN_STATUS RetStatus;
UINT64 IoTranslation; UINT64 IoTranslation;
RETURN_STATUS PcdStatus; RETURN_STATUS PcdStatus;
PciExpressBaseAddress = PcdGet64 (PcdPciExpressBaseAddress); PciExpressBaseAddress = PcdGet64 (PcdPciExpressBaseAddress);
if (PciExpressBaseAddress != MAX_UINT64) { if (PciExpressBaseAddress != MAX_UINT64) {
@ -106,38 +109,51 @@ FdtPciPcdProducerLibConstructor (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL, Status = gBS->LocateProtocol (
(VOID **)&FdtClient); &gFdtClientProtocolGuid,
NULL,
(VOID **)&FdtClient
);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
PciExpressBaseAddress = 0; PciExpressBaseAddress = 0;
Status = FdtClient->FindCompatibleNode (FdtClient, "pci-host-ecam-generic", Status = FdtClient->FindCompatibleNode (
&Node); FdtClient,
"pci-host-ecam-generic",
&Node
);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg", Status = FdtClient->GetNodeProperty (
(CONST VOID **)&Reg, &RegSize); FdtClient,
Node,
"reg",
(CONST VOID **)&Reg,
&RegSize
);
if (!EFI_ERROR (Status) && RegSize == 2 * sizeof (UINT64)) { if (!EFI_ERROR (Status) && (RegSize == 2 * sizeof (UINT64))) {
PciExpressBaseAddress = SwapBytes64 (*Reg); PciExpressBaseAddress = SwapBytes64 (*Reg);
PcdStatus = PcdSetBoolS (PcdPciDisableBusEnumeration, FALSE); PcdStatus = PcdSetBoolS (PcdPciDisableBusEnumeration, FALSE);
ASSERT_RETURN_ERROR (PcdStatus); ASSERT_RETURN_ERROR (PcdStatus);
IoTranslation = 0; IoTranslation = 0;
RetStatus = GetPciIoTranslation (FdtClient, Node, &IoTranslation); RetStatus = GetPciIoTranslation (FdtClient, Node, &IoTranslation);
if (!RETURN_ERROR (RetStatus)) { if (!RETURN_ERROR (RetStatus)) {
PcdStatus = PcdSet64S (PcdPciIoTranslation, IoTranslation); PcdStatus = PcdSet64S (PcdPciIoTranslation, IoTranslation);
ASSERT_RETURN_ERROR (PcdStatus); ASSERT_RETURN_ERROR (PcdStatus);
} else { } else {
// //
// Support for I/O BARs is not mandatory, and so it does not make sense // Support for I/O BARs is not mandatory, and so it does not make sense
// to abort in the general case. So leave it up to the actual driver to // to abort in the general case. So leave it up to the actual driver to
// complain about this if it wants to, and just issue a warning here. // complain about this if it wants to, and just issue a warning here.
// //
DEBUG ((DEBUG_WARN, DEBUG ((
DEBUG_WARN,
"%a: 'pci-host-ecam-generic' device encountered with no I/O range\n", "%a: 'pci-host-ecam-generic' device encountered with no I/O range\n",
__FUNCTION__)); __FUNCTION__
));
} }
} }
} }

View File

@ -20,40 +20,58 @@
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
InitializeHighMemDxe ( InitializeHighMemDxe (
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
FDT_CLIENT_PROTOCOL *FdtClient; FDT_CLIENT_PROTOCOL *FdtClient;
EFI_CPU_ARCH_PROTOCOL *Cpu; EFI_CPU_ARCH_PROTOCOL *Cpu;
EFI_STATUS Status, FindNodeStatus; EFI_STATUS Status, FindNodeStatus;
INT32 Node; INT32 Node;
CONST UINT32 *Reg; CONST UINT32 *Reg;
UINT32 RegSize; UINT32 RegSize;
UINTN AddressCells, SizeCells; UINTN AddressCells, SizeCells;
UINT64 CurBase; UINT64 CurBase;
UINT64 CurSize; UINT64 CurSize;
UINT64 Attributes; UINT64 Attributes;
EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor; EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;
Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL, Status = gBS->LocateProtocol (
(VOID **)&FdtClient); &gFdtClientProtocolGuid,
NULL,
(VOID **)&FdtClient
);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, Status = gBS->LocateProtocol (
(VOID **)&Cpu); &gEfiCpuArchProtocolGuid,
NULL,
(VOID **)&Cpu
);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
// //
// Check for memory node and add the memory spaces except the lowest one // Check for memory node and add the memory spaces except the lowest one
// //
for (FindNodeStatus = FdtClient->FindMemoryNodeReg (FdtClient, &Node, for (FindNodeStatus = FdtClient->FindMemoryNodeReg (
(CONST VOID **) &Reg, &AddressCells, FdtClient,
&SizeCells, &RegSize); &Node,
(CONST VOID **)&Reg,
&AddressCells,
&SizeCells,
&RegSize
);
!EFI_ERROR (FindNodeStatus); !EFI_ERROR (FindNodeStatus);
FindNodeStatus = FdtClient->FindNextMemoryNodeReg (FdtClient, Node, FindNodeStatus = FdtClient->FindNextMemoryNodeReg (
&Node, (CONST VOID **) &Reg, &AddressCells, FdtClient,
&SizeCells, &RegSize)) { Node,
&Node,
(CONST VOID **)&Reg,
&AddressCells,
&SizeCells,
&RegSize
))
{
ASSERT (AddressCells <= 2); ASSERT (AddressCells <= 2);
ASSERT (SizeCells <= 2); ASSERT (SizeCells <= 2);
@ -62,36 +80,60 @@ InitializeHighMemDxe (
if (AddressCells > 1) { if (AddressCells > 1) {
CurBase = (CurBase << 32) | SwapBytes32 (*Reg++); CurBase = (CurBase << 32) | SwapBytes32 (*Reg++);
} }
CurSize = SwapBytes32 (*Reg++); CurSize = SwapBytes32 (*Reg++);
if (SizeCells > 1) { if (SizeCells > 1) {
CurSize = (CurSize << 32) | SwapBytes32 (*Reg++); CurSize = (CurSize << 32) | SwapBytes32 (*Reg++);
} }
RegSize -= (AddressCells + SizeCells) * sizeof (UINT32); RegSize -= (AddressCells + SizeCells) * sizeof (UINT32);
Status = gDS->GetMemorySpaceDescriptor (CurBase, &GcdDescriptor); Status = gDS->GetMemorySpaceDescriptor (CurBase, &GcdDescriptor);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, DEBUG ((
DEBUG_WARN,
"%a: Region 0x%lx - 0x%lx not found in the GCD memory space map\n", "%a: Region 0x%lx - 0x%lx not found in the GCD memory space map\n",
__FUNCTION__, CurBase, CurBase + CurSize - 1)); __FUNCTION__,
continue; CurBase,
CurBase + CurSize - 1
));
continue;
} }
if (GcdDescriptor.GcdMemoryType == EfiGcdMemoryTypeNonExistent) { if (GcdDescriptor.GcdMemoryType == EfiGcdMemoryTypeNonExistent) {
Status = gDS->AddMemorySpace (EfiGcdMemoryTypeSystemMemory, CurBase, Status = gDS->AddMemorySpace (
CurSize, EFI_MEMORY_WB); EfiGcdMemoryTypeSystemMemory,
CurBase,
CurSize,
EFI_MEMORY_WB
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, DEBUG ((
DEBUG_ERROR,
"%a: Failed to add System RAM @ 0x%lx - 0x%lx (%r)\n", "%a: Failed to add System RAM @ 0x%lx - 0x%lx (%r)\n",
__FUNCTION__, CurBase, CurBase + CurSize - 1, Status)); __FUNCTION__,
CurBase,
CurBase + CurSize - 1,
Status
));
continue; continue;
} }
Status = gDS->SetMemorySpaceAttributes (CurBase, CurSize, Status = gDS->SetMemorySpaceAttributes (
EFI_MEMORY_WB); CurBase,
CurSize,
EFI_MEMORY_WB
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, DEBUG ((
DEBUG_WARN,
"%a: gDS->SetMemorySpaceAttributes() failed on region 0x%lx - 0x%lx (%r)\n", "%a: gDS->SetMemorySpaceAttributes() failed on region 0x%lx - 0x%lx (%r)\n",
__FUNCTION__, CurBase, CurBase + CurSize - 1, Status)); __FUNCTION__,
CurBase,
CurBase + CurSize - 1,
Status
));
} }
// //
@ -107,19 +149,30 @@ InitializeHighMemDxe (
// //
Attributes = EFI_MEMORY_WB; Attributes = EFI_MEMORY_WB;
if ((PcdGet64 (PcdDxeNxMemoryProtectionPolicy) & if ((PcdGet64 (PcdDxeNxMemoryProtectionPolicy) &
(1U << (UINT32)EfiConventionalMemory)) != 0) { (1U << (UINT32)EfiConventionalMemory)) != 0)
{
Attributes |= EFI_MEMORY_XP; Attributes |= EFI_MEMORY_XP;
} }
Status = Cpu->SetMemoryAttributes (Cpu, CurBase, CurSize, Attributes); Status = Cpu->SetMemoryAttributes (Cpu, CurBase, CurSize, Attributes);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, DEBUG ((
DEBUG_ERROR,
"%a: Failed to set System RAM @ 0x%lx - 0x%lx attribute (%r)\n", "%a: Failed to set System RAM @ 0x%lx - 0x%lx attribute (%r)\n",
__FUNCTION__, CurBase, CurBase + CurSize - 1, Status)); __FUNCTION__,
CurBase,
CurBase + CurSize - 1,
Status
));
} else { } else {
DEBUG ((DEBUG_INFO, "%a: Add System RAM @ 0x%lx - 0x%lx\n", DEBUG ((
__FUNCTION__, CurBase, CurBase + CurSize - 1)); DEBUG_INFO,
"%a: Add System RAM @ 0x%lx - 0x%lx\n",
__FUNCTION__,
CurBase,
CurBase + CurSize - 1
));
} }
} }
} }

View File

@ -22,43 +22,62 @@
#pragma pack (1) #pragma pack (1)
typedef struct { typedef struct {
VENDOR_DEVICE_PATH Vendor; VENDOR_DEVICE_PATH Vendor;
UINT64 PhysBase; UINT64 PhysBase;
EFI_DEVICE_PATH_PROTOCOL End; EFI_DEVICE_PATH_PROTOCOL End;
} VIRTIO_TRANSPORT_DEVICE_PATH; } VIRTIO_TRANSPORT_DEVICE_PATH;
#pragma pack () #pragma pack ()
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
InitializeVirtioFdtDxe ( InitializeVirtioFdtDxe (
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
EFI_STATUS Status, FindNodeStatus; EFI_STATUS Status, FindNodeStatus;
FDT_CLIENT_PROTOCOL *FdtClient; FDT_CLIENT_PROTOCOL *FdtClient;
INT32 Node; INT32 Node;
CONST UINT64 *Reg; CONST UINT64 *Reg;
UINT32 RegSize; UINT32 RegSize;
VIRTIO_TRANSPORT_DEVICE_PATH *DevicePath; VIRTIO_TRANSPORT_DEVICE_PATH *DevicePath;
EFI_HANDLE Handle; EFI_HANDLE Handle;
UINT64 RegBase; UINT64 RegBase;
Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL, Status = gBS->LocateProtocol (
(VOID **)&FdtClient); &gFdtClientProtocolGuid,
NULL,
(VOID **)&FdtClient
);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
for (FindNodeStatus = FdtClient->FindCompatibleNode (FdtClient, for (FindNodeStatus = FdtClient->FindCompatibleNode (
"virtio,mmio", &Node); FdtClient,
"virtio,mmio",
&Node
);
!EFI_ERROR (FindNodeStatus); !EFI_ERROR (FindNodeStatus);
FindNodeStatus = FdtClient->FindNextCompatibleNode (FdtClient, FindNodeStatus = FdtClient->FindNextCompatibleNode (
"virtio,mmio", Node, &Node)) { FdtClient,
"virtio,mmio",
Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg", Node,
(CONST VOID **)&Reg, &RegSize); &Node
))
{
Status = FdtClient->GetNodeProperty (
FdtClient,
Node,
"reg",
(CONST VOID **)&Reg,
&RegSize
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: GetNodeProperty () failed (Status == %r)\n", DEBUG ((
__FUNCTION__, Status)); DEBUG_ERROR,
"%a: GetNodeProperty () failed (Status == %r)\n",
__FUNCTION__,
Status
));
continue; continue;
} }
@ -67,11 +86,12 @@ InitializeVirtioFdtDxe (
// //
// Create a unique device path for this transport on the fly // Create a unique device path for this transport on the fly
// //
RegBase = SwapBytes64 (*Reg); RegBase = SwapBytes64 (*Reg);
DevicePath = (VIRTIO_TRANSPORT_DEVICE_PATH *)CreateDeviceNode ( DevicePath = (VIRTIO_TRANSPORT_DEVICE_PATH *)CreateDeviceNode (
HARDWARE_DEVICE_PATH, HARDWARE_DEVICE_PATH,
HW_VENDOR_DP, HW_VENDOR_DP,
sizeof (VIRTIO_TRANSPORT_DEVICE_PATH)); sizeof (VIRTIO_TRANSPORT_DEVICE_PATH)
);
if (DevicePath == NULL) { if (DevicePath == NULL) {
DEBUG ((DEBUG_ERROR, "%a: Out of memory\n", __FUNCTION__)); DEBUG ((DEBUG_ERROR, "%a: Out of memory\n", __FUNCTION__));
continue; continue;
@ -79,39 +99,62 @@ InitializeVirtioFdtDxe (
CopyGuid (&DevicePath->Vendor.Guid, &gVirtioMmioTransportGuid); CopyGuid (&DevicePath->Vendor.Guid, &gVirtioMmioTransportGuid);
DevicePath->PhysBase = RegBase; DevicePath->PhysBase = RegBase;
SetDevicePathNodeLength (&DevicePath->Vendor, SetDevicePathNodeLength (
sizeof (*DevicePath) - sizeof (DevicePath->End)); &DevicePath->Vendor,
sizeof (*DevicePath) - sizeof (DevicePath->End)
);
SetDevicePathEndNode (&DevicePath->End); SetDevicePathEndNode (&DevicePath->End);
Handle = NULL; Handle = NULL;
Status = gBS->InstallProtocolInterface (&Handle, Status = gBS->InstallProtocolInterface (
&gEfiDevicePathProtocolGuid, EFI_NATIVE_INTERFACE, &Handle,
DevicePath); &gEfiDevicePathProtocolGuid,
EFI_NATIVE_INTERFACE,
DevicePath
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Failed to install the EFI_DEVICE_PATH " DEBUG ((
DEBUG_ERROR,
"%a: Failed to install the EFI_DEVICE_PATH "
"protocol on a new handle (Status == %r)\n", "protocol on a new handle (Status == %r)\n",
__FUNCTION__, Status)); __FUNCTION__,
Status
));
FreePool (DevicePath); FreePool (DevicePath);
continue; continue;
} }
Status = VirtioMmioInstallDevice (RegBase, Handle); Status = VirtioMmioInstallDevice (RegBase, Handle);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Failed to install VirtIO transport @ 0x%Lx " DEBUG ((
"on handle %p (Status == %r)\n", __FUNCTION__, RegBase, DEBUG_ERROR,
Handle, Status)); "%a: Failed to install VirtIO transport @ 0x%Lx "
"on handle %p (Status == %r)\n",
__FUNCTION__,
RegBase,
Handle,
Status
));
Status = gBS->UninstallProtocolInterface (Handle, Status = gBS->UninstallProtocolInterface (
&gEfiDevicePathProtocolGuid, DevicePath); Handle,
&gEfiDevicePathProtocolGuid,
DevicePath
);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
FreePool (DevicePath); FreePool (DevicePath);
continue; continue;
} }
} }
if (EFI_ERROR (FindNodeStatus) && FindNodeStatus != EFI_NOT_FOUND) { if (EFI_ERROR (FindNodeStatus) && (FindNodeStatus != EFI_NOT_FOUND)) {
DEBUG ((DEBUG_ERROR, "%a: Error occurred while iterating DT nodes " DEBUG ((
"(FindNodeStatus == %r)\n", __FUNCTION__, FindNodeStatus)); DEBUG_ERROR,
"%a: Error occurred while iterating DT nodes "
"(FindNodeStatus == %r)\n",
__FUNCTION__,
FindNodeStatus
));
} }
return EFI_SUCCESS; return EFI_SUCCESS;

View File

@ -1,4 +1,4 @@
/** @file /** @file
UEFI Configuration Table for exposing the SEV Launch Secret location to UEFI UEFI Configuration Table for exposing the SEV Launch Secret location to UEFI
applications (boot loaders). applications (boot loaders).
@ -19,10 +19,10 @@
} }
typedef struct { typedef struct {
UINT64 Base; UINT64 Base;
UINT64 Size; UINT64 Size;
} CONFIDENTIAL_COMPUTING_SECRET_LOCATION; } CONFIDENTIAL_COMPUTING_SECRET_LOCATION;
extern EFI_GUID gConfidentialComputingSecretGuid; extern EFI_GUID gConfidentialComputingSecretGuid;
#endif // SEV_LAUNCH_SECRET_H_ #endif // SEV_LAUNCH_SECRET_H_

View File

@ -50,6 +50,6 @@
{ 0xbd, 0x60, 0x28, 0xf4, 0xe7, 0x8f, 0x78, 0x4b }, \ { 0xbd, 0x60, 0x28, 0xf4, 0xe7, 0x8f, 0x78, 0x4b }, \
} }
extern EFI_GUID gMicrosoftVendorGuid; extern EFI_GUID gMicrosoftVendorGuid;
#endif /* MICROSOFT_VENDOR_H_ */ #endif /* MICROSOFT_VENDOR_H_ */

View File

@ -40,6 +40,6 @@
{ 0x81, 0xd3, 0x5b, 0xb9, 0x71, 0x5f, 0x97, 0x27 }, \ { 0x81, 0xd3, 0x5b, 0xb9, 0x71, 0x5f, 0x97, 0x27 }, \
} }
extern EFI_GUID gOvmfPkKek1AppPrefixGuid; extern EFI_GUID gOvmfPkKek1AppPrefixGuid;
#endif /* OVMF_PK_KEK1_APP_PREFIX_H_ */ #endif /* OVMF_PK_KEK1_APP_PREFIX_H_ */

Some files were not shown because too many files have changed in this diff Show More