Skip to content

Commit

Permalink
Ring3: Refactored I/O Map initialization using PcdUartBase and PcdDeb…
Browse files Browse the repository at this point in the history
…ugIoPort.
  • Loading branch information
Mikhail Krichanov committed Sep 5, 2024
1 parent ede4877 commit 94be39d
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 12 deletions.
5 changes: 4 additions & 1 deletion OvmfPkg/OvmfPkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,12 @@
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeNonCcFvBase|0x0|UINT32|0x6a
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeNonCcFvSize|0x0|UINT32|0x6b

## This flag is used to control the destination port for PlatformDebugLibIoPort
## Controls the destination port for PlatformDebugLibIoPort
gUefiOvmfPkgTokenSpaceGuid.PcdDebugIoPort|0x402|UINT16|4

## Controls the destination ports for SerialPortLib
gUefiOvmfPkgTokenSpaceGuid.PcdUartBase|0x3F8|UINT16|0x104

## When VirtioScsiDxe is instantiated for a HBA, the numbers of targets and
# LUNs are retrieved from the host during virtio-scsi setup.
# MdeModulePkg/Bus/Scsi/ScsiBusDxe then scans all MaxTarget * MaxLun
Expand Down
4 changes: 4 additions & 0 deletions PcAtChipsetPkg/Library/SerialIoLib/SerialIoLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@

[Packages]
MdePkg/MdePkg.dec
OvmfPkg/OvmfPkg.dec

[LibraryClasses]
BaseLib
IoLib
PcdLib

[Sources]
SerialPortLib.c

[Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdUartBase ## CONSUMES
2 changes: 1 addition & 1 deletion PcAtChipsetPkg/Library/SerialIoLib/SerialPortLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
// ---------------------------------------------
// UART Settings
// ---------------------------------------------
UINT16 gUartBase = 0x3F8;
UINT16 gUartBase = FixedPcdGet16 (PcdUartBase);
UINTN gBps = 115200;
UINT8 gData = 8;
UINT8 gStop = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard
gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList
gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize
gUefiOvmfPkgTokenSpaceGuid.PcdUartBase ## CONSUMES
gUefiOvmfPkgTokenSpaceGuid.PcdDebugIoPort ## CONSUMES

[FeaturePcd]
gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmStackGuard ## CONSUMES

[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
OvmfPkg/OvmfPkg.dec
UefiCpuPkg/UefiCpuPkg.dec

[LibraryClasses.common]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,15 @@ ArchSetupExceptionStack (
Tss->SS0 = AsmReadSs ();
Tss->IOMapBaseAddress = sizeof (IA32_TASK_STATE_SEGMENT);
//
// Allow access to gUartBase = 0x3F8 and Offsets: 0x01, 0x03, 0x04, 0x05, 0x06
// Allow access to gUartBase = 0x3F8 and Offsets: 0x01, 0x03, 0x04, 0x05, 0x06;
// and DebugIoPort = 0x402.
//
IOBitMap = (UINT8 *)((UINTN)Tss + Tss->IOMapBaseAddress);
for (Index = 0; Index < IO_BIT_MAP_SIZE; ++Index) {
if ((Index * 8) == 0x3F8) {
if ((Index * 8) == FixedPcdGet16 (PcdUartBase)) {
*IOBitMap = 0x84;
} else if ((Index * 8) == (FixedPcdGet16 (PcdDebugIoPort) - 2)) {
*IOBitMap = 0xFB;
} else {
*IOBitMap = 0xFF;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ typedef struct {
(sizeof (IA32_TSS_DESCRIPTOR) * \
(FixedPcdGetSize (PcdCpuStackSwitchExceptionList) + 1))

#define IO_BIT_MAP_SIZE (ALIGN_VALUE (0x81, 16))
#define IO_BIT_MAP_SIZE (ALIGN_VALUE (FixedPcdGet16 (PcdDebugIoPort) / 8 + 1, 16))
#define CPU_TSS_SIZE \
(sizeof (IA32_TASK_STATE_SEGMENT) * \
(FixedPcdGetSize (PcdCpuStackSwitchExceptionList) + 1) + IO_BIT_MAP_SIZE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
OvmfPkg/OvmfPkg.dec
UefiCpuPkg/UefiCpuPkg.dec

[LibraryClasses]
Expand All @@ -55,9 +56,11 @@
SynchronizationLib

[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard # CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ## CONSUMES
gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize
gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList
gUefiOvmfPkgTokenSpaceGuid.PcdUartBase ## CONSUMES
gUefiOvmfPkgTokenSpaceGuid.PcdDebugIoPort ## CONSUMES

[FeaturePcd]
gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmStackGuard ## CONSUMES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
OvmfPkg/OvmfPkg.dec
UefiCpuPkg/UefiCpuPkg.dec

[LibraryClasses.common]
Expand All @@ -69,6 +70,8 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard
gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList
gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize
gUefiOvmfPkgTokenSpaceGuid.PcdUartBase ## CONSUMES
gUefiOvmfPkgTokenSpaceGuid.PcdDebugIoPort ## CONSUMES

[FeaturePcd]
gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmStackGuard ## CONSUMES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
OvmfPkg/OvmfPkg.dec
UefiCpuPkg/UefiCpuPkg.dec

[LibraryClasses]
Expand All @@ -56,6 +57,8 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard
gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList
gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize
gUefiOvmfPkgTokenSpaceGuid.PcdUartBase ## CONSUMES
gUefiOvmfPkgTokenSpaceGuid.PcdDebugIoPort ## CONSUMES

[FeaturePcd]
gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmStackGuard ## CONSUMES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,15 @@ ArchSetupExceptionStack (
Tss->RSP0 = StackTop;
Tss->IOMapBaseAddress = sizeof (IA32_TASK_STATE_SEGMENT);
//
// Allow access to gUartBase = 0x3F8 and Offsets: 0x01, 0x03, 0x04, 0x05, 0x06
// Allow access to gUartBase = 0x3F8 and Offsets: 0x01, 0x03, 0x04, 0x05, 0x06;
// and DebugIoPort = 0x402.
//
IOBitMap = (UINT8 *)((UINTN)Tss + Tss->IOMapBaseAddress);
for (Index = 0; Index < IO_BIT_MAP_SIZE; ++Index) {
if ((Index * 8) == 0x3F8) {
if ((Index * 8) == FixedPcdGet16 (PcdUartBase)) {
*IOBitMap = 0x84;
} else if ((Index * 8) == (FixedPcdGet16 (PcdDebugIoPort) - 2)) {
*IOBitMap = 0xFB;
} else {
*IOBitMap = 0xFF;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ typedef struct {
} RESERVED_VECTORS_DATA;

#define CPU_TSS_DESC_SIZE sizeof (IA32_TSS_DESCRIPTOR)
//
// 0x81 is needed to allow Ring3 code access to Uart in I/O Permission Bit Map.
//
#define IO_BIT_MAP_SIZE (ALIGN_VALUE (0x81, 16))
#define IO_BIT_MAP_SIZE (ALIGN_VALUE (FixedPcdGet16 (PcdDebugIoPort) / 8 + 1, 16))
#define CPU_TSS_SIZE (sizeof (IA32_TASK_STATE_SEGMENT) + IO_BIT_MAP_SIZE)

#endif

0 comments on commit 94be39d

Please sign in to comment.