Re: [edk2-devel] [PATCH v1 2/7] MdeModulePkg: Invoke GetPhysicalAddressBits() and remove the duplicated code

2022-03-10 Thread Pu, Yu
Hi, Mike, Liming,

This patch makes MdeModulePkg depend on UefiCpuPkg.
Ray and me would like to move the UefiCpuLib from UefiCpuPkg to MdePkg, do you 
agree with it ?

Thanks,
Yu

-Original Message-
From: Ni, Ray 
Sent: Monday, March 7, 2022 11:55 AM
To: Kinney, Michael D ; Gao, Liming 

Cc: Wang, Jian J ; Gao, Liming 
; devel@edk2.groups.io; Pu, Yu 
Subject: RE: [edk2-devel] [PATCH v1 2/7] MdeModulePkg: Invoke 
GetPhysicalAddressBits() and remove the duplicated code

Mike, Liming,
This patch makes MdeModulePkg depend on UefiCpuPkg.
But according to 
https://github.com/tianocore/edk2/blob/master/MdeModulePkg/MdeModulePkg.ci.yaml#L49,
 such dependency is not allowed.

Do you agree to move the UefiCpuLib from UefiCpuPkg to MdePkg? The library 
header and instance are in following paths:

https://github.com/tianocore/edk2/blob/master/UefiCpuPkg/Include/Library/UefiCpuLib.h

https://github.com/tianocore/edk2/tree/master/UefiCpuPkg/Library/BaseUefiCpuLib

Thanks,
Ray


-Original Message-
From: devel@edk2.groups.io  On Behalf Of Yu Pu
Sent: Wednesday, March 2, 2022 5:19 PM
To: devel@edk2.groups.io
Cc: Pu, Yu ; Wang, Jian J ; Gao, Liming 

Subject: [edk2-devel] [PATCH v1 2/7] MdeModulePkg: Invoke 
GetPhysicalAddressBits() and remove the duplicated code

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

Invoke GetPhysicalAddressBits() defined in UefiCpuPkg for CPU physical address 
mask calculation and remove the duplicated code in MdeModulePkg.

Cc: Jian J Wang 
Cc: Liming Gao 

Signed-off-by: Yu Pu 
---
 MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c|  
9 ++---
 MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEntry.c | 
14 ++
 MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c| 
14 ++
 MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf |  
2 ++
 MdeModulePkg/MdeModulePkg.dsc   |  
1 +
 MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf |  
2 ++
 MdeModulePkg/Universal/CapsulePei/CapsuleX64.inf|  
2 ++
 7 files changed, 13 insertions(+), 31 deletions(-)

diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c 
b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c
index 0700f310b203..78e91e6e9024 100644
--- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c
+++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c
@@ -22,6 +22,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent


 **/



+#include 

 #include 

 #include "DxeIpl.h"

 #include "VirtualMemory.h"

@@ -733,13 +734,7 @@ CreateIdentityMappingPageTables (
   if (Hob != NULL) {

 PhysicalAddressBits = ((EFI_HOB_CPU *)Hob)->SizeOfMemorySpace;

   } else {

-AsmCpuid (0x8000, &RegEax, NULL, NULL, NULL);

-if (RegEax >= 0x8008) {

-  AsmCpuid (0x8008, &RegEax, NULL, NULL, NULL);

-  PhysicalAddressBits = (UINT8)RegEax;

-} else {

-  PhysicalAddressBits = 36;

-}

+PhysicalAddressBits = GetPhysicalAddressBits(NULL, NULL);

   }



   Page5LevelSupport = FALSE;

diff --git 
a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEntry.c 
b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEntry.c
index 6b44f50bac70..367bf8cdd1e6 100644
--- a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEntry.c
+++ b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEntry.
+++ c
@@ -10,6 +10,7 @@ Copyright (c) 2017, AMD Incorporated. All rights reserved.
 SPDX-License-Identifier: BSD-2-Clause-Patent



 **/

+#include 

 #include "ScriptExecute.h"



 //

@@ -51,20 +52,9 @@ HookPageFaultHandler (
   IN IA32_IDT_GATE_DESCRIPTOR  *IdtEntry

   )

 {

-  UINT32  RegEax;

-  UINT8   PhysicalAddressBits;

   UINTN   PageFaultHandlerHookAddress;



-  AsmCpuid (0x8000, &RegEax, NULL, NULL, NULL);

-  if (RegEax >= 0x8008) {

-AsmCpuid (0x8008, &RegEax, NULL, NULL, NULL);

-PhysicalAddressBits = (UINT8)RegEax;

-  } else {

-PhysicalAddressBits = 36;

-  }

-

-  mPhyMask  = LShiftU64 (1, PhysicalAddressBits) - 1;

-  mPhyMask &= (1ull << 48) - SIZE_4KB;

+  GetPhysicalAddressBits(NULL, &mPhyMask);



   //

   // Set Page Fault entry to catch >4G access

diff --git a/MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c 
b/MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c
index 05941f9f8d56..06d6129c5e6d 100644
--- a/MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c
+++ b/MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c
@@ -12,6 +12,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent  #include 


 #include 

 #include 

+#include 

 #include "CommonHeader.h"



 #define EXCEPTION_VECTOR_NUMBER  0x22

@@ -61,20 +62,9 @@ HookPageFaultHandler (
   IN OUT PAGE_FAULT_CONTEXT*PageFaultContext

   )

 {

-  UINT32  RegEax;

-  UI

Re: [edk2-devel] [PATCH v1 2/7] MdeModulePkg: Invoke GetPhysicalAddressBits() and remove the duplicated code

2022-03-06 Thread Ni, Ray
Mike, Liming,
This patch makes MdeModulePkg depend on UefiCpuPkg.
But according to 
https://github.com/tianocore/edk2/blob/master/MdeModulePkg/MdeModulePkg.ci.yaml#L49,
 such dependency is not allowed.

Do you agree to move the UefiCpuLib from UefiCpuPkg to MdePkg? The library 
header and instance are in following paths:

https://github.com/tianocore/edk2/blob/master/UefiCpuPkg/Include/Library/UefiCpuLib.h

https://github.com/tianocore/edk2/tree/master/UefiCpuPkg/Library/BaseUefiCpuLib

Thanks,
Ray


-Original Message-
From: devel@edk2.groups.io  On Behalf Of Yu Pu
Sent: Wednesday, March 2, 2022 5:19 PM
To: devel@edk2.groups.io
Cc: Pu, Yu ; Wang, Jian J ; Gao, Liming 

Subject: [edk2-devel] [PATCH v1 2/7] MdeModulePkg: Invoke 
GetPhysicalAddressBits() and remove the duplicated code

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

Invoke GetPhysicalAddressBits() defined in UefiCpuPkg for CPU physical address
mask calculation and remove the duplicated code in MdeModulePkg.

Cc: Jian J Wang 
Cc: Liming Gao 

Signed-off-by: Yu Pu 
---
 MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c|  
9 ++---
 MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEntry.c | 
14 ++
 MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c| 
14 ++
 MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf |  
2 ++
 MdeModulePkg/MdeModulePkg.dsc   |  
1 +
 MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf |  
2 ++
 MdeModulePkg/Universal/CapsulePei/CapsuleX64.inf|  
2 ++
 7 files changed, 13 insertions(+), 31 deletions(-)

diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c 
b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c
index 0700f310b203..78e91e6e9024 100644
--- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c
+++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c
@@ -22,6 +22,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent


 **/



+#include 

 #include 

 #include "DxeIpl.h"

 #include "VirtualMemory.h"

@@ -733,13 +734,7 @@ CreateIdentityMappingPageTables (
   if (Hob != NULL) {

 PhysicalAddressBits = ((EFI_HOB_CPU *)Hob)->SizeOfMemorySpace;

   } else {

-AsmCpuid (0x8000, &RegEax, NULL, NULL, NULL);

-if (RegEax >= 0x8008) {

-  AsmCpuid (0x8008, &RegEax, NULL, NULL, NULL);

-  PhysicalAddressBits = (UINT8)RegEax;

-} else {

-  PhysicalAddressBits = 36;

-}

+PhysicalAddressBits = GetPhysicalAddressBits(NULL, NULL);

   }



   Page5LevelSupport = FALSE;

diff --git 
a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEntry.c 
b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEntry.c
index 6b44f50bac70..367bf8cdd1e6 100644
--- a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEntry.c
+++ b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEntry.c
@@ -10,6 +10,7 @@ Copyright (c) 2017, AMD Incorporated. All rights reserved.
 SPDX-License-Identifier: BSD-2-Clause-Patent



 **/

+#include 

 #include "ScriptExecute.h"



 //

@@ -51,20 +52,9 @@ HookPageFaultHandler (
   IN IA32_IDT_GATE_DESCRIPTOR  *IdtEntry

   )

 {

-  UINT32  RegEax;

-  UINT8   PhysicalAddressBits;

   UINTN   PageFaultHandlerHookAddress;



-  AsmCpuid (0x8000, &RegEax, NULL, NULL, NULL);

-  if (RegEax >= 0x8008) {

-AsmCpuid (0x8008, &RegEax, NULL, NULL, NULL);

-PhysicalAddressBits = (UINT8)RegEax;

-  } else {

-PhysicalAddressBits = 36;

-  }

-

-  mPhyMask  = LShiftU64 (1, PhysicalAddressBits) - 1;

-  mPhyMask &= (1ull << 48) - SIZE_4KB;

+  GetPhysicalAddressBits(NULL, &mPhyMask);



   //

   // Set Page Fault entry to catch >4G access

diff --git a/MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c 
b/MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c
index 05941f9f8d56..06d6129c5e6d 100644
--- a/MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c
+++ b/MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c
@@ -12,6 +12,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include 

 #include 

 #include 

+#include 

 #include "CommonHeader.h"



 #define EXCEPTION_VECTOR_NUMBER  0x22

@@ -61,20 +62,9 @@ HookPageFaultHandler (
   IN OUT PAGE_FAULT_CONTEXT*PageFaultContext

   )

 {

-  UINT32  RegEax;

-  UINT8   PhysicalAddressBits;

   UINTN   PageFaultHandlerHookAddress;



-  AsmCpuid (0x8000, &RegEax, NULL, NULL, NULL);

-  if (RegEax >= 0x8008) {

-AsmCpuid (0x8008, &RegEax, NULL, NULL, NULL);

-PhysicalAddressBits = (UINT8)RegEax;

-  } else {

-PhysicalAddressBits = 36;

-  }

-

-  PageFaultContext->PhyMask  = LShiftU64 (1, PhysicalAddressBits) - 1;

-  PageFaultContext->PhyMask &= (1ull << 48) - SIZE_4KB;

+  GetPhysicalAddressBits(NULL, &(PageFaultContext->PhyMask));



   //

   // Set Page Fault entry to catch >4G access

diff --git a/MdeMod