Re: [edk2-devel] [PATCH 0/4] Define SERIAL_DXE_FILE_GUID only once

2019-06-03 Thread Anthony PERARD
On Sat, Jun 01, 2019 at 05:00:37PM +, Kinney, Michael D wrote:
> I am curious.  I agree that a GUID can be defined in DEC file and
> in an include file that is used as a Vendor GUID in a device path.
> 
> Is there any reason that the FILE_GUID for the module needs to be
> the same GUID value?  Is there any code that looks for an FFS file
> with that GUID value as the FFS file name?

Sorry, I think you lost me here. The way I see it is that the GUID is
"produced" only by "MdeModulePkg/Universal/SerialDxe/SerialDxe.inf",
and then all the "PlatformBootManagerLib" are looking for exactly that
driver (SerialDxe), so the FILE_GUID is used.

There is probably a reason why this is already done three times in the
edk2.git repo.

Maybe you could have a closer look at
"ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c" to see how
SERIAL_DXE_FILE_GUID is used.

BTW, I've added "gSerialDxeFileGuid" as it seems there's often both a
"#define" and a variable for the GUID, but only the "#define" is used so
far. So maybe I should remove the variable?

> If not, then it would be better to not over use that GUID value.
> The FILE_GUID of the SerialDxe can be different.

Thanks for the review,

-- 
Anthony PERARD

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#41806): https://edk2.groups.io/g/devel/message/41806
Mute This Topic: https://groups.io/mt/31832613/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH 1/4] MdeModulePkg: Add SERIAL_DXE_FILE_GUID

2019-05-29 Thread Anthony PERARD
SERIAL_DXE_FILE_GUID is used in different places, create a single
define that other can use.

Suggested-by: Laszlo Ersek 
Signed-off-by: Anthony PERARD 
---

Notes:
Suggested in: Message-ID: <7d6adf5d-baca-7e9c-68ef-2f8479bbd...@redhat.com>

 MdeModulePkg/MdeModulePkg.dec |  3 +++
 MdeModulePkg/Include/Guid/SerialDxe.h | 19 +++
 2 files changed, 22 insertions(+)
 create mode 100644 MdeModulePkg/Include/Guid/SerialDxe.h

diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 6cba729982..6c5736618e 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -396,6 +396,9 @@ [Guids]
   ## Include/Guid/S3StorageDeviceInitList.h
   gS3StorageDeviceInitListGuid = { 0x310e9b8c, 0xcf90, 0x421e, { 0x8e, 0x9b, 
0x9e, 0xef, 0xb6, 0x17, 0xc8, 0xef } }
 
+  ## Include/Guid/SerialDxe.h
+  gSerialDxeFileGuid = { 0xD3987D4B, 0x971A, 0x435F, { 0x8C, 0xAF, 0x49, 0x67, 
0xEB, 0x62, 0x72, 0x41 } }
+
 [Ppis]
   ## Include/Ppi/AtaController.h
   gPeiAtaControllerPpiGuid   = { 0xa45e60d1, 0xc719, 0x44aa, { 0xb0, 0x7a, 
0xaa, 0x77, 0x7f, 0x85, 0x90, 0x6d }}
diff --git a/MdeModulePkg/Include/Guid/SerialDxe.h 
b/MdeModulePkg/Include/Guid/SerialDxe.h
new file mode 100644
index 00..4d53f4877f
--- /dev/null
+++ b/MdeModulePkg/Include/Guid/SerialDxe.h
@@ -0,0 +1,19 @@
+/** @file
+  Define the SerialDxe GUID.
+
+  Copyright (c) 2019, Citrix Systems, Inc.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef __SERIAL_DXE_H__
+#define __SERIAL_DXE_H__
+
+#define SERIAL_DXE_FILE_GUID { \
+  0xD3987D4B, 0x971A, 0x435F, \
+  { 0x8C, 0xAF, 0x49, 0x67, 0xEB, 0x62, 0x72, 0x41 } \
+  }
+
+extern EFI_GUID gSerialDxeFileGuid;
+
+#endif // __SERIAL_DXE_H__
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#41603): https://edk2.groups.io/g/devel/message/41603
Mute This Topic: https://groups.io/mt/31832610/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH 4/4] UefiPayloadPkg/PlatformBootManagerLib: Use SERIAL_DXE_FILE_GUID from MdeModulePkg

2019-05-29 Thread Anthony PERARD
SERIAL_DXE_FILE_GUID is now defined in MdeModulePkg, simply use it.

Signed-off-by: Anthony PERARD 
---
 .../Library/PlatformBootManagerLib/PlatformConsole.c   | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformConsole.c 
b/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformConsole.c
index 80a11d7451..b7c36f37d1 100644
--- a/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformConsole.c
+++ b/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformConsole.c
@@ -8,6 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 #include "PlatformBootManager.h"
 #include "PlatformConsole.h"
+#include 
 
 #define PCI_DEVICE_PATH_NODE(Func, Dev) \
   { \
@@ -53,7 +54,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) \
   } \
 }, \
-{0xD3987D4B, 0x971A, 0x435F, {0x8C, 0xAF, 0x49, 0x67, 0xEB, 0x62, 0x72, 
0x41}} \
+SERIAL_DXE_FILE_GUID \
   }
 
 #define gUart \
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#41604): https://edk2.groups.io/g/devel/message/41604
Mute This Topic: https://groups.io/mt/31832611/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH 2/4] ArmVirtPkg/PlatformBootManagerLib: Use SERIAL_DXE_FILE_GUID from MdeModulePkg

2019-05-29 Thread Anthony PERARD
SERIAL_DXE_FILE_GUID is now defined in MdeModulePkg, simply use it.

Signed-off-by: Anthony PERARD 
---
 ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c 
b/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c
index b8f50ea96b..d7697c93c3 100644
--- a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c
+++ b/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "PlatformBm.h"
 
@@ -41,11 +42,6 @@ typedef struct {
 } PLATFORM_SERIAL_CONSOLE;
 #pragma pack ()
 
-#define SERIAL_DXE_FILE_GUID { \
-  0xD3987D4B, 0x971A, 0x435F, \
-  { 0x8C, 0xAF, 0x49, 0x67, 0xEB, 0x62, 0x72, 0x41 } \
-  }
-
 STATIC PLATFORM_SERIAL_CONSOLE mSerialConsole = {
   //
   // VENDOR_DEVICE_PATH SerialDxe
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#41602): https://edk2.groups.io/g/devel/message/41602
Mute This Topic: https://groups.io/mt/31832609/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH 0/4] Define SERIAL_DXE_FILE_GUID only once

2019-05-29 Thread Anthony PERARD
The macro SERIAL_DXE_FILE_GUID is already been defined twice and the GUID is
been used once without defining the macro. This patch series define the macro
in MdeModulePkg where the SerialDxe is, and replace all other use by this new
one.

Note that I haven't build/test those changes, but I have test the first patch
by applying a similar change to a patch series I'm working on.

Patch series available in this git branch:
https://xenbits.xen.org/git-http/people/aperard/ovmf.git br.serial-dxe-guid-v1

Anthony PERARD (4):
  MdeModulePkg: Add SERIAL_DXE_FILE_GUID
  ArmVirtPkg/PlatformBootManagerLib: Use SERIAL_DXE_FILE_GUID from
MdeModulePkg
  ArmPkg/PlatformBootManagerLib: Use SERIAL_DXE_FILE_GUID from
MdeModulePkg
  UefiPayloadPkg/PlatformBootManagerLib: Use SERIAL_DXE_FILE_GUID from
MdeModulePkg

 MdeModulePkg/MdeModulePkg.dec |  3 +++
 MdeModulePkg/Include/Guid/SerialDxe.h | 19 +++
 .../PlatformBootManagerLib/PlatformBm.c   |  6 +-
 .../PlatformBootManagerLib/PlatformBm.c   |  6 +-
 .../PlatformBootManagerLib/PlatformConsole.c  |  3 ++-
 5 files changed, 26 insertions(+), 11 deletions(-)
 create mode 100644 MdeModulePkg/Include/Guid/SerialDxe.h

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#41606): https://edk2.groups.io/g/devel/message/41606
Mute This Topic: https://groups.io/mt/31832613/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH 0/4] Define SERIAL_DXE_FILE_GUID only once

2019-06-06 Thread Anthony PERARD
> > So, ultimately, we are asking Anthony to:
> > 
> > (1) please introduce the new GUID as
> > EDKII_SERIAL_VENDOR_GUID and gEdkiiSerialVendorGuid,
> 
> Yes.
> 
> > 
> > (2) please append another patch to this series,
> > replacing EFI_CALLER_ID_GUID -- and the comment! -- with
> > EDKII_SERIAL_VENDOR_GUID, in the "mSerialDevicePath"
> > initializer (in
> > "MdeModulePkg/Universal/SerialDxe/SerialIo.c").
> > 
> > Correct?
> 
> Yes.
> 
> > 
> > Can we suggest an include file name too, in place of
> > "MdeModulePkg/Include/Guid/SerialDxe.h"?
> 
> The SerialDxe module uses the services of the SeriaPortLib to
> produce the Serial I/O Protocol.  Instead of a physical register
> interface such as UART in HW, the SW APIs of the SerialPortLib are
> used.  The GUIDed Vendor HW node in the device path for the HW
> register case would be a GUID value and name(s) that represents
> the HW device used to perform the Serial I/O actions.  Applying
> this to the SerialPortLib  access would imply GUID and Include
> file names that are associated with the SerialPortLib. Perhaps:
> 
>   MdeModulePkg/Include/Guid/SerialPortLibVendor.h
> 
>   EDKII_SERIAL_PORT_LIB_VENDOR_GUID
> 
>   gEdkiiSerialPortLibVendorGuid

Thank you all, I'll update the patches.

-- 
Anthony PERARD

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#42002): https://edk2.groups.io/g/devel/message/42002
Mute This Topic: https://groups.io/mt/31832613/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v2 2/4] ArmVirtPkg/PlatformBootManagerLib: Use EDKII_SERIAL_PORT_LIB_VENDOR_GUID from MdeModulePkg

2019-06-06 Thread Anthony PERARD
SERIAL_DXE_FILE_GUID is now defined in MdeModulePkg as
EDKII_SERIAL_PORT_LIB_VENDOR_GUID, simply use it.

Signed-off-by: Anthony PERARD 
---
 ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c 
b/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c
index b8f50ea96b..30c015eec5 100644
--- a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c
+++ b/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "PlatformBm.h"
 
@@ -41,18 +42,13 @@ typedef struct {
 } PLATFORM_SERIAL_CONSOLE;
 #pragma pack ()
 
-#define SERIAL_DXE_FILE_GUID { \
-  0xD3987D4B, 0x971A, 0x435F, \
-  { 0x8C, 0xAF, 0x49, 0x67, 0xEB, 0x62, 0x72, 0x41 } \
-  }
-
 STATIC PLATFORM_SERIAL_CONSOLE mSerialConsole = {
   //
   // VENDOR_DEVICE_PATH SerialDxe
   //
   {
 { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, DP_NODE_LEN (VENDOR_DEVICE_PATH) },
-SERIAL_DXE_FILE_GUID
+EDKII_SERIAL_PORT_LIB_VENDOR_GUID
   },
 
   //
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#42005): https://edk2.groups.io/g/devel/message/42005
Mute This Topic: https://groups.io/mt/31950871/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v2 4/4] UefiPayloadPkg/PlatformBootManagerLib: Use EDKII_SERIAL_PORT_LIB_VENDOR_GUID from MdeModulePkg

2019-06-06 Thread Anthony PERARD
EDKII_SERIAL_PORT_LIB_VENDOR_GUID is now defined in MdeModulePkg,
simply use it.

Signed-off-by: Anthony PERARD 
---
 .../Library/PlatformBootManagerLib/PlatformConsole.c   | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformConsole.c 
b/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformConsole.c
index 80a11d7451..ee2d8c8d1e 100644
--- a/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformConsole.c
+++ b/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformConsole.c
@@ -8,6 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 #include "PlatformBootManager.h"
 #include "PlatformConsole.h"
+#include 
 
 #define PCI_DEVICE_PATH_NODE(Func, Dev) \
   { \
@@ -53,7 +54,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) \
   } \
 }, \
-{0xD3987D4B, 0x971A, 0x435F, {0x8C, 0xAF, 0x49, 0x67, 0xEB, 0x62, 0x72, 
0x41}} \
+EDKII_SERIAL_PORT_LIB_VENDOR_GUID \
   }
 
 #define gUart \
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#42007): https://edk2.groups.io/g/devel/message/42007
Mute This Topic: https://groups.io/mt/31950873/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v2 3/4] ArmPkg/PlatformBootManagerLib: Use EDKII_SERIAL_PORT_LIB_VENDOR_GUID from MdeModulePkg

2019-06-06 Thread Anthony PERARD
SERIAL_DXE_FILE_GUID is now defined in MdeModulePkg as
EDKII_SERIAL_PORT_LIB_VENDOR_GUID, simply use it.

Signed-off-by: Anthony PERARD 
---
 ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c 
b/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c
index 0f91692c1a..1e30f148b3 100644
--- a/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c
+++ b/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "PlatformBm.h"
 
@@ -42,18 +43,13 @@ typedef struct {
 } PLATFORM_SERIAL_CONSOLE;
 #pragma pack ()
 
-#define SERIAL_DXE_FILE_GUID { \
-  0xD3987D4B, 0x971A, 0x435F, \
-  { 0x8C, 0xAF, 0x49, 0x67, 0xEB, 0x62, 0x72, 0x41 } \
-  }
-
 STATIC PLATFORM_SERIAL_CONSOLE mSerialConsole = {
   //
   // VENDOR_DEVICE_PATH SerialDxe
   //
   {
 { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, DP_NODE_LEN (VENDOR_DEVICE_PATH) },
-SERIAL_DXE_FILE_GUID
+EDKII_SERIAL_PORT_LIB_VENDOR_GUID
   },
 
   //
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#42008): https://edk2.groups.io/g/devel/message/42008
Mute This Topic: https://groups.io/mt/31950874/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v2 00/31] Specific platform to run OVMF in Xen PVH and HVM guests

2019-04-09 Thread Anthony PERARD
On Mon, Apr 08, 2019 at 05:50:57PM +0200, Laszlo Ersek wrote:
> On 04/08/19 16:23, Anthony PERARD wrote:
> > Question:
> >
> > Should we start moving these to a different *Pkg? Like it's done for
> > ArmPkg and ArmVirtPkg?  Maybe XenPkg.
> 
> I'm pretty happy with the current package structure. ArmPkg is for both
> physical and virtual hardware. ArmVirtPkg is virt-only, and we already
> have separate platform DSCs/FDFs between Xen (ArmVirtXen) and QEMU/KVM
> (ArmVirtQemu[Kernel]). Xen- and QEMU/KVM-specific drivers and library
> instances peacefully coexist under ArmVirtPkg; the DSCs/FDFs include
> them as appropriate.
> 
> The same should map nicely to OvmfPkg. x86 stuff that targets both
> physical and virtual hardware belongs under PcAtChipsetPkg and
> UefiCpuPkg. Virt-only stuff should go under OvmfPkg; Xen-specific and
> QEMU/KVM-specific modules can coexist under OvmfPkg. It's sufficient if
> the platform DSCs cherry-pick them as appropriate.

Thanks for the feedback, that sounds good.

> > To build and boot:
> >
> > To build, simply run OvmfPkg/build.sh -p OvmfPkg/XenOvmf.dsc
> 
> (1) To stick with the ArmVirt pattern, we should initially call this
> platform OvmfXen.

I'll rename it in v3.

> (3) Please file a BZ at <https://bugzilla.tianocore.org/> about this
> feature, and assign it to yourself. The BZ should keep track of all
> versions of the patch series (from the mailing list archive).

Done: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
I'll add the links for the patch series once there is one for v2.

> (5) The BZ should be referenced in all the commit messages.

I'll do that in v3.

> (6) The new edk2 development mailing list is at:

:-(

> https://edk2.groups.io/g/devel
> 
> Please subscribe there, and resend this series to that address, i.e.
> . I'm CC'ing the new address myself, for this
> initial response, but I'd prefer the rest of my comments to go only to
> the new list (without manually updating the CC list on every response).

I'm about to do that.

Thanks,

-- 
Anthony PERARD

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#38704): https://edk2.groups.io/g/devel/message/38704
Mute This Topic: https://groups.io/mt/30964532/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v2 1/3] OvmfPkg/XenSupport: remove usage of prefetchable PCI host bridge aperture

2019-04-11 Thread Anthony PERARD
On Tue, Apr 09, 2019 at 04:12:38AM +0100, Igor Druzhinin wrote:
> This aperture doesn't exist in QEMU-XEN and hvmloader places BARs
> in arbitrary order disregarding prefetchable bit. This makes
> prefetchable and non-prefetchable BARs to follow each other that's
> quite likely with PCI passthrough devices. In that case, the existing
> code, that tries to work out aperture boundaries by reading hvmloader
> BAR placement, will report a bogus prefetchable aperture which overlaps
> with the regular one. It will eventually trigger an assertion in
> DXE PCI initialization code.
> 
> Do the same thing as OVMF on QEMU-KVM and pass a non-existing aperture
> there. It's not necessary to pass additional allocation flags as we set
> ResourceAssigned flag on the root bridge which means they will be ignored.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Igor Druzhinin 
> ---
> Changes in v2:
> * remove usage of prefetchable aperture entirely
> * explained rationale for the change in the description
> ---

Reviewed-by: Anthony PERARD 

Thanks,

-- 
Anthony PERARD

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#38887): https://edk2.groups.io/g/devel/message/38887
Mute This Topic: https://groups.io/mt/31030418/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 06/35] OvmfPkg/XenResetVector: Add new entry point for Xen PVH

2019-07-04 Thread Anthony PERARD
Add a new entry point for Xen PVH that enter directly in 32bits.

Information on the expected state of the machine when this entry point
is used can be found at:
https://xenbits.xenproject.org/docs/unstable/misc/pvh.html

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
---

Notes:
v3:
- rebased, SPDX
- remove `cli' as via PVH the interrupts are guaranteed to be off
- rewrite some comments

 .../XenResetVector/Ia16/ResetVectorVtf0.asm   | 81 +++
 OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm| 49 +++
 OvmfPkg/XenResetVector/XenResetVector.nasmb   |  1 +
 3 files changed, 131 insertions(+)
 create mode 100644 OvmfPkg/XenResetVector/Ia16/ResetVectorVtf0.asm
 create mode 100644 OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm

diff --git a/OvmfPkg/XenResetVector/Ia16/ResetVectorVtf0.asm 
b/OvmfPkg/XenResetVector/Ia16/ResetVectorVtf0.asm
new file mode 100644
index 00..958195bc5e
--- /dev/null
+++ b/OvmfPkg/XenResetVector/Ia16/ResetVectorVtf0.asm
@@ -0,0 +1,81 @@
+;--

+; @file

+; First code executed by processor after resetting.

+;

+; Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.

+; Copyright (c) 2019, Citrix Systems, Inc.

+;

+; SPDX-License-Identifier: BSD-2-Clause-Patent

+;

+;--

+

+BITS16

+

+ALIGN   16

+

+;

+; Pad the image size to 4k when page tables are in VTF0

+;

+; If the VTF0 image has page tables built in, then we need to make

+; sure the end of VTF0 is 4k above where the page tables end.

+;

+; This is required so the page tables will be 4k aligned when VTF0 is

+; located just below 0x1 (4GB) in the firmware device.

+;

+%ifdef ALIGN_TOP_TO_4K_FOR_PAGING

+TIMES (0x1000 - ($ - EndOfPageTables) - (fourGigabytes - 
xenPVHEntryPoint)) DB 0

+%endif

+

+BITS32

+xenPVHEntryPoint:

+;

+; Entry point to use when running as a Xen PVH guest. (0xffd0)

+;

+; Description of the expected state of the machine when this entry point is

+; used can be found at:

+; https://xenbits.xenproject.org/docs/unstable/misc/pvh.html

+;

+jmp xenPVHMain

+

+BITS16

+ALIGN   16

+

+applicationProcessorEntryPoint:

+;

+; Application Processors entry point

+;

+; GenFv generates code aligned on a 4k boundary which will jump to this

+; location.  (0xffe0)  This allows the Local APIC Startup IPI to be

+; used to wake up the application processors.

+;

+jmp EarlyApInitReal16

+

+ALIGN   8

+

+DD  0

+

+;

+; The VTF signature

+;

+; VTF-0 means that the VTF (Volume Top File) code does not require

+; any fixups.

+;

+vtfSignature:

+DB  'V', 'T', 'F', 0

+

+ALIGN   16

+

+resetVector:

+;

+; Reset Vector

+;

+; This is where the processor will begin execution

+;

+nop

+nop

+jmp EarlyBspInitReal16

+

+ALIGN   16

+

+fourGigabytes:

+

diff --git a/OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm 
b/OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm
new file mode 100644
index 00..2a17fed52f
--- /dev/null
+++ b/OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm
@@ -0,0 +1,49 @@
+;--

+; @file

+; An entry point use by Xen when a guest is started in PVH mode.

+;

+; Copyright (c) 2019, Citrix Systems, Inc.

+;

+; SPDX-License-Identifier: BSD-2-Clause-Patent

+;

+;--

+

+BITS32

+

+xenPVHMain:

+;

+; 'BP' to indicate boot-strap processor

+;

+mov di, 'BP'

+

+;

+; ESP will be used as initial value of the EAX register

+; in Main.asm

+;

+xor esp, esp

+

+mov ebx, ADDR_OF(gdtr)

+lgdt[ebx]

+

+mov eax, SEC_DEFAULT_CR0

+mov cr0, eax

+

+jmp LINEAR_CODE_SEL:ADDR_OF(.jmpToNewCodeSeg)

+.jmpToNewCodeSeg:

+

+mov eax, SEC_DEFAULT_CR4

+mov cr4, eax

+

+mov ax, LINEAR_SEL

+mov ds, ax

+mov es, ax

+mov fs, ax

+mov gs, ax

+mov ss, ax

+

+;

+; Jump to the main routine of the pre-SEC code

+; skiping the 16-bit part of the routine and

+; into the 32-bit flat mode part

+;

+OneTimeCallRet TransitionFromReal16To32BitFlat

diff --git a/OvmfPkg/XenResetVector/XenResetVector.nasmb 
b/OvmfPkg/XenResetVector/XenResetVector.nasmb
index 89a4b08bc3..0dbc4f2c1d 100644
--- a/OvmfPkg/XenResetVector/XenResetVector.nasmb
+++ b/OvmfPkg/XenResetVector/XenResetVector.nasmb
@@ -63,6 +63,7 @@
 %include "Ia16/Init16.asm"

 

 %include "Main.asm"

+%include "Ia32/XenPVHMain.asm"

 

 %include "Ia16/ResetVectorVtf0.asm"

 

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this g

[edk2-devel] [PATCH v3 02/35] OvmfPkg: Create platform OvmfXen

2019-07-04 Thread Anthony PERARD
OvmfXen is a copy of OvmfX64, removing VirtIO and some SMM.

This new platform will be changed to make it works on two types of Xen
guest: HVM and PVH.

Compare to OvmfX64, this patch:

- changed: PLATFORM_GUID, OUTPUT_DIRECTORY, FLASH_DEFINITION
- removed: VirtioLib class resolution
- removed: all UEFI_DRIVER modules for virtio devices
- removed: DXE_SMM_DRIVER and SMM_CORE lib class resolutions
- removed: DXE_SMM_DRIVER and SMM_CORE FDF rules
- removed: Everything related to SMM_REQUIRE==true
- removed: Everything related to SECURE_BOOT_ENABLE==true
- removed: Everything related to TPM2_ENABLE==true
- changed: PcdPciDisableBusEnumeration dynamic default flipped to TRUE
- changed: default FD_SIZE_IN_KB to 2M.
- reverted d272449d9e1e, "OvmfPkg: raise DXEFV size to 11 MB"

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
---

Notes:
v3:
- rebased, SPDX + 8259/8254 changes

 OvmfPkg/OvmfXen.dsc | 729 
 OvmfPkg/OvmfXen.fdf | 439 ++
 2 files changed, 1168 insertions(+)
 create mode 100644 OvmfPkg/OvmfXen.dsc
 create mode 100644 OvmfPkg/OvmfXen.fdf

diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
new file mode 100644
index 00..3b56815dd7
--- /dev/null
+++ b/OvmfPkg/OvmfXen.dsc
@@ -0,0 +1,729 @@
+## @file

+#  EFI/Framework Open Virtual Machine Firmware (OVMF) platform

+#

+#  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.

+#  (C) Copyright 2016 Hewlett Packard Enterprise Development LP

+#  Copyright (c) 2019, Citrix Systems, Inc.

+#

+#  SPDX-License-Identifier: BSD-2-Clause-Patent

+#

+##

+

+

+#

+# Defines Section - statements that will be processed to create a Makefile.

+#

+

+[Defines]

+  PLATFORM_NAME  = Ovmf

+  PLATFORM_GUID  = e3aa4fbe-9459-482d-bd40-d3f3b5f89d6e

+  PLATFORM_VERSION   = 0.1

+  DSC_SPECIFICATION  = 0x00010005

+  OUTPUT_DIRECTORY   = Build/OvmfXen

+  SUPPORTED_ARCHITECTURES= X64

+  BUILD_TARGETS  = NOOPT|DEBUG|RELEASE

+  SKUID_IDENTIFIER   = DEFAULT

+  FLASH_DEFINITION   = OvmfPkg/OvmfXen.fdf

+

+  #

+  # Defines for default states.  These can be changed on the command line.

+  # -D FLAG=VALUE

+  #

+

+  #

+  # Network definition

+  #

+  DEFINE NETWORK_TLS_ENABLE = FALSE

+  DEFINE NETWORK_IP6_ENABLE = FALSE

+  DEFINE NETWORK_HTTP_BOOT_ENABLE   = FALSE

+  DEFINE NETWORK_ALLOW_HTTP_CONNECTIONS = TRUE

+

+!include NetworkPkg/NetworkDefines.dsc.inc

+

+  #

+  # Flash size selection. Setting FD_SIZE_IN_KB on the command line directly to

+  # one of the supported values, in place of any of the convenience macros, is

+  # permitted.

+  #

+!ifdef $(FD_SIZE_1MB)

+  DEFINE FD_SIZE_IN_KB   = 1024

+!else

+!ifdef $(FD_SIZE_2MB)

+  DEFINE FD_SIZE_IN_KB   = 2048

+!else

+!ifdef $(FD_SIZE_4MB)

+  DEFINE FD_SIZE_IN_KB   = 4096

+!else

+  DEFINE FD_SIZE_IN_KB   = 2048

+!endif

+!endif

+!endif

+

+[BuildOptions]

+  GCC:RELEASE_*_*_CC_FLAGS = -DMDEPKG_NDEBUG

+  INTEL:RELEASE_*_*_CC_FLAGS   = /D MDEPKG_NDEBUG

+  MSFT:RELEASE_*_*_CC_FLAGS= /D MDEPKG_NDEBUG

+!if $(TOOL_CHAIN_TAG) != "XCODE5"

+  GCC:*_*_*_CC_FLAGS   = -mno-mmx -mno-sse

+!endif

+!ifdef $(SOURCE_DEBUG_ENABLE)

+  MSFT:*_*_X64_GENFW_FLAGS  = --keepexceptiontable

+  GCC:*_*_X64_GENFW_FLAGS   = --keepexceptiontable

+  INTEL:*_*_X64_GENFW_FLAGS = --keepexceptiontable

+!endif

+

+  #

+  # Disable deprecated APIs.

+  #

+  MSFT:*_*_*_CC_FLAGS = /D DISABLE_NEW_DEPRECATED_INTERFACES

+  INTEL:*_*_*_CC_FLAGS = /D DISABLE_NEW_DEPRECATED_INTERFACES

+  GCC:*_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES

+

+[BuildOptions.common.EDKII.DXE_RUNTIME_DRIVER]

+  GCC:*_*_*_DLINK_FLAGS = -z common-page-size=0x1000

+  XCODE:*_*_*_DLINK_FLAGS =

+

+# Force PE/COFF sections to be aligned at 4KB boundaries to support page level

+# protection of DXE_SMM_DRIVER/SMM_CORE modules

+[BuildOptions.common.EDKII.DXE_SMM_DRIVER, BuildOptions.common.EDKII.SMM_CORE]

+  GCC:*_*_*_DLINK_FLAGS = -z common-page-size=0x1000

+  XCODE:*_*_*_DLINK_FLAGS =

+

+

+#

+# SKU Identification section - list of all SKU IDs supported by this Platform.

+#

+

+[SkuIds]

+  0|DEFAULT

+

+

+#

+# Library Class section - list of all Library Classes nee

[edk2-devel] [PATCH v3 03/35] OvmfPkg: Introduce XenResetVector

2019-07-04 Thread Anthony PERARD
Introduce XenResetVector, a copy of OvmfPkg/ResetVector, with one
changes:
  - SEC_DEFAULT_CR0: enable cache (bit 30 or CD set to 0)

Xen copies the OVMF code to RAM, there is no need to disable cache.

This new module will later be modified to add a new entry point, more
detail in a following commit "OvmfPkg/XenResetVector: Add new entry point
for Xen PVH"

Value FILE_GUID of XenResetVector have not changed compare to ResetVector
because it is a special value (gEfiFirmwareVolumeTopFileGuid).

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Reviewed-by: Laszlo Ersek 
---

Notes:
v3:
  - Added gEfiFirmwareVolumeTopFileGuid to the commit message.
  - rebased: SPDX

 OvmfPkg/OvmfXen.dsc   |   2 +-
 OvmfPkg/OvmfXen.fdf   |   2 +-
 OvmfPkg/XenResetVector/XenResetVector.inf |  38 +
 .../XenResetVector/Ia16/Real16ToFlat32.asm| 134 
 OvmfPkg/XenResetVector/Ia32/PageTables64.asm  | 149 ++
 OvmfPkg/XenResetVector/XenResetVector.nasmb   |  68 
 6 files changed, 391 insertions(+), 2 deletions(-)
 create mode 100644 OvmfPkg/XenResetVector/XenResetVector.inf
 create mode 100644 OvmfPkg/XenResetVector/Ia16/Real16ToFlat32.asm
 create mode 100644 OvmfPkg/XenResetVector/Ia32/PageTables64.asm
 create mode 100644 OvmfPkg/XenResetVector/XenResetVector.nasmb

diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index 3b56815dd7..cab54da3e8 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -495,7 +495,7 @@ [PcdsDynamicDefault]
 #

 


 [Components]

-  OvmfPkg/ResetVector/ResetVector.inf

+  OvmfPkg/XenResetVector/XenResetVector.inf

 

   #

   # SEC Phase modules

diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf
index f59647fd14..6fc8479aae 100644
--- a/OvmfPkg/OvmfXen.fdf
+++ b/OvmfPkg/OvmfXen.fdf
@@ -118,7 +118,7 @@ [FV.SECFV]
 #

 INF  OvmfPkg/Sec/SecMain.inf

 

-INF  RuleOverride=RESET_VECTOR OvmfPkg/ResetVector/ResetVector.inf

+INF  RuleOverride=RESET_VECTOR OvmfPkg/XenResetVector/XenResetVector.inf

 

 


 [FV.PEIFV]

diff --git a/OvmfPkg/XenResetVector/XenResetVector.inf 
b/OvmfPkg/XenResetVector/XenResetVector.inf
new file mode 100644
index 00..097fc9b5b4
--- /dev/null
+++ b/OvmfPkg/XenResetVector/XenResetVector.inf
@@ -0,0 +1,38 @@
+## @file

+#  Reset Vector

+#

+#  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.

+#  Copyright (c) 2019, Citrix Systems, Inc.

+#

+#  SPDX-License-Identifier: BSD-2-Clause-Patent

+#

+##

+

+[Defines]

+  INF_VERSION= 0x00010005

+  BASE_NAME  = XenResetVector

+  FILE_GUID  = 1BA0062E-C779-4582-8566-336AE8F78F09

+  MODULE_TYPE= SEC

+  VERSION_STRING = 1.1

+

+#

+# The following information is for reference only and not required by the 
build tools.

+#

+#  VALID_ARCHITECTURES   = IA32 X64

+#

+

+[Sources]

+  XenResetVector.nasmb

+

+[Packages]

+  OvmfPkg/OvmfPkg.dec

+  MdePkg/MdePkg.dec

+  UefiCpuPkg/UefiCpuPkg.dec

+

+[BuildOptions]

+   *_*_IA32_NASMB_FLAGS = -I$(WORKSPACE)/UefiCpuPkg/ResetVector/Vtf0/

+   *_*_X64_NASMB_FLAGS = -I$(WORKSPACE)/UefiCpuPkg/ResetVector/Vtf0/

+

+[Pcd]

+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase

+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize

diff --git a/OvmfPkg/XenResetVector/Ia16/Real16ToFlat32.asm 
b/OvmfPkg/XenResetVector/Ia16/Real16ToFlat32.asm
new file mode 100644
index 00..5c329bfaea
--- /dev/null
+++ b/OvmfPkg/XenResetVector/Ia16/Real16ToFlat32.asm
@@ -0,0 +1,134 @@
+;--

+; @file

+; Transition from 16 bit real mode into 32 bit flat protected mode

+;

+; Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.

+; Copyright (c) 2019, Citrix Systems, Inc.

+; SPDX-License-Identifier: BSD-2-Clause-Patent

+;

+;--

+

+%define SEC_DEFAULT_CR0  0x0023

+%define SEC_DEFAULT_CR4  0x640

+

+BITS16

+

+;

+; Modified:  EAX, EBX

+;

+; @param[out] DS   Selector allowing flat access to all addresses

+; @param[out] ES   Selector allowing flat access to all addresses

+; @param[out] FS   Selector allowing flat access to all addresses

+; @param[out] GS   Selector allowing flat access to all addresses

+; @param[out] SS   Selector allowing flat access to all addresses

+;

+TransitionFromReal16To32BitFlat:

+

+debugShowPostCode POSTCODE_16BIT_MODE

+

+cli

+

+mov bx, 0xf000

+mov ds, bx

+

+mov bx, ADDR16_OF(gdtr)

+

+o32 lgdt[cs:bx]

+

+mov eax, SEC_DEFAULT_CR0

+mov   

[edk2-devel] [PATCH v3 05/35] OvmfPkg/OvmfXen: Creating an ELF header

2019-07-04 Thread Anthony PERARD
This patch changes the flash device image of OvmfXen to make it look
like it's an ELF. For this, we replace the empty embedded variable store
by a binary array, which is a ELF file header.

The ELF header explain to a loader to load the binary at the address
1MB, then jump to the PVH entry point which will be created in a later
patch. The header also includes a Xen ELF note that is part of the
PVH ABI.

That patch include OvmfXenElfHeaderGenerator.c which can be use to
regenerate the ELF header, but this will be a manual step.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
---

Notes:
v3:
- added license to generate_elf_header.c
  which is renamed to OvmfPkg/OvmfXenElfHeaderGenerator.c
- added an ELF NOTE into the header

 OvmfPkg/OvmfXen.fdf | 101 +++-
 OvmfPkg/OvmfXenElfHeaderGenerator.c | 140 
 2 files changed, 238 insertions(+), 3 deletions(-)
 create mode 100644 OvmfPkg/OvmfXenElfHeaderGenerator.c

diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf
index 2ceff7baa2..43c268f6cb 100644
--- a/OvmfPkg/OvmfXen.fdf
+++ b/OvmfPkg/OvmfXen.fdf
@@ -15,8 +15,8 @@ [Defines]
 !include OvmfPkg.fdf.inc

 

 #

-# Build the variable store and the firmware code as one unified flash device

-# image.

+# This will allow the flash device image to be recognize as an ELF, with first

+# an ELF headers, then the firmware code.

 #

 [FD.OVMF]

 BaseAddress   = $(FW_BASE_ADDRESS)

@@ -25,7 +25,102 @@ [FD.OVMF]
 BlockSize = $(BLOCK_SIZE)

 NumBlocks = $(FW_BLOCKS)

 

-!include VarStore.fdf.inc

+!if ($(FD_SIZE_IN_KB) == 1024) || ($(FD_SIZE_IN_KB) == 2048)

+0x|0xe000

+!endif

+!if $(FD_SIZE_IN_KB) == 4096

+0x|0x0004

+!endif

+DATA = {

+  #

+  # This hex array have been generated by OvmfPkg/OvmfXenElfHeaderGenerator.c

+  # and copied manually.

+  #

+  # ELF file header

+  0x7f, 0x45, 0x4c, 0x46, # e_ident[0..3]: Magic number

+  0x01, # File class: 32-bit objects

+  0x01, # Data encoding: 2's complement, little endian

+  0x01, # File version

+  0x03, # OS ABI identification: Object uses GNU ELF extensions

+  0x00, # ABI version

+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  # e_ident[EI_PAD...]

+  0x02, 0x00, # e_type = Executable file

+  0x03, 0x00, # e_machine = Intel 80386

+  0x01, 0x00, 0x00, 0x00, # e_version

+  0xd0, 0xff, 0x2f, 0x00, # e_entry: Entry point virtual address

+  0x34, 0x00, 0x00, 0x00, # e_phoff: Program header table file offset

+  0x00, 0x00, 0x00, 0x00, # e_shoff: Section header table file offset

+  0x00, 0x00, 0x00, 0x00, # e_flags: Processor-specific flags

+  0x34, 0x00, #e_ehsize: ELF header size

+  0x20, 0x00, # e_phentsize: Program header table entry size

+  0x02, 0x00, # e_phnum: Program header table entry count

+  0x00, 0x00, # e_shentsize: Section header table entry size

+  0x00, 0x00, # e_shnum: Section header table entry count

+  0x00, 0x00, # e_shstrndx

+

+  # ELF Program segment headers

+  # - Load segment

+  0x01, 0x00, 0x00, 0x00, # p_type = Loadable program segment

+  0x00, 0x00, 0x00, 0x00, # p_offset

+  0x00, 0x00, 0x10, 0x00, # p_vaddr: Segment virtual address

+  0x00, 0x00, 0x10, 0x00, # p_paddr: Segment physical address

+  0x00, 0x00, 0x20, 0x00, # p_filesz: Segment size in file

+  0x00, 0x00, 0x20, 0x00, # p_memsz: Segment size in memory

+  0x07, 0x00, 0x00, 0x00, # p_flags = Segment is executable | writable | 
readable

+  0x00, 0x00, 0x00, 0x00, # p_align

+  # - ELFNOTE segment

+  0x04, 0x00, 0x00, 0x00, # p_type = PT_NOTE

+  0x74, 0x00, 0x00, 0x00, # p_offset = point to XEN_ELFNOTE_PHYS32_ENTRY below

+  0x74, 0x00, 0x10, 0x00,

+  0x74, 0x00, 0x10, 0x00,

+  0x14, 0x00, 0x00, 0x00,

+  0x14, 0x00, 0x00, 0x00,

+  0x04, 0x00, 0x00, 0x00, # p_flags = Segment is readable

+  0x00, 0x00, 0x00, 0x00,

+

+  # XEN_ELFNOTE_PHYS32_ENTRY

+  0x04, 0x00, 0x00, 0x00, # name size

+  0x04, 0x00, 0x00, 0x00, # desc size

+  0x12, 0x00, 0x00, 0x00, # type = XEN_ELFNOTE_PHYS32_ENTRY

+  0x58, 0x65, 0x6e, 0x00, # name = "Xen"

+  0xd0, 0xff, 0x2f, 0x00, # desc: PVH entry point

+  0x00

+}

+

+!if ($(FD_SIZE_IN_KB) == 1024) || ($(FD_SIZE_IN_KB) == 2048)

+0xe000|0x1000

+!endif

+!if $(FD_SIZE_IN_KB) == 4096

+0x0004|0x1000

+!endif

+#NV_EVENT_LOG

+

+!if ($(FD_SIZE_IN_KB) == 1024) || ($(FD_SIZE_IN_KB) == 2048)

+0xf000|0x1000

+!endif

+!if $(FD_SIZE_IN_KB) == 4096

+0x00041000|0x1000

+!endif

+#NV_FTW_WORKING

+DATA = {

+  # EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER->Signature = 
gEdkiiWorkingBlockSignatureGuid =

+  #  { 0x9e58292b, 0x7c68, 0x497d, { 0xa0, 0xce, 0x65,  0x0, 0xfd, 0x9f, 0x1b, 
0x95 }}

+  0x2b, 0x29, 0x58, 0x9e, 0x68, 0x7c, 0x7d, 0x49,

+  0xa0, 0xce, 0x65,  0x0, 0xfd, 0x9f, 0x1b, 0x95,

+  # Crc:UINT32#WorkingBlockValid:1, WorkingBlockInvalid:1, Reserved

+  0x2c, 0xaf, 0x2c, 0x64, 0xFE, 0xF

[edk2-devel] [PATCH v3 04/35] OvmfPkg: Introduce XenPlatformPei

2019-07-04 Thread Anthony PERARD
Introduce XenPlatformPei, a copy of OvmfPkg/PlatformPei without some
of QEMU specific initialization, Xen does not support QemuFwCfg.

This new module will be adjusted to accommodate Xen PVH.

fw_cfg dependents that have been removed, which are dynamically skipped
when running PlatformPei on Xen:
- GetFirstNonAddress(): controlling the 64-bit PCI MMIO aperture via the
(experimental) "opt/ovmf/X-PciMmio64Mb" file
- GetFirstNonAddress(): honoring the hotplug DIMM area
("etc/reserved-memory-end") in the placement of the 64-bit PCI MMIO
aperture
- NoexecDxeInitialization() is removed, so PcdPropertiesTableEnable and
PcdSetNxForStack are left constant FALSE (not set dynamically from
fw_cfg "opt/ovmf/PcdXxxx")
- MaxCpuCountInitialization(), PublishPeiMemory(): the max CPU count is
not taken from the QemuFwCfgItemSmpCpuCount fw_cfg key;
PcdCpuMaxLogicalProcessorNumber is used intact and
PcdCpuApInitTimeOutInMicroSeconds is never changed or used.
- InitializeXenPlatform(), S3Verification(): S3 is assumed disabled (not
consulting "etc/system-states" via QemuFwCfgS3Enabled()).
- InstallFeatureControlCallback(): the feature control MSR is not set
from "etc/msr_feature_control"
(also removed FeatureControl.c as there is nothing been executed)

Also removed:
- SMRAM/TSEG-related low mem size adjusting (PcdSmmSmramRequire is
assumed FALSE) in PublishPeiMemory(),
- QemuInitializeRam() entirely,

Xen related changes:
- Have removed the module variable mXen, as it should be always true.
- Have the platform PEI initialization fails if Xen has not been
  detected.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Reviewed-by: Laszlo Ersek 
---

Notes:
v3:
  - fix coding style in new code
(use DEBUG_xxx, add ASSERT before CpuDeadLoop)
  - rebased, SPDX

 OvmfPkg/OvmfXen.dsc   |   2 +-
 OvmfPkg/OvmfXen.fdf   |   2 +-
 OvmfPkg/XenPlatformPei/XenPlatformPei.inf |  96 +
 OvmfPkg/XenPlatformPei/Cmos.h |  52 +++
 OvmfPkg/XenPlatformPei/Platform.h | 108 ++
 OvmfPkg/XenPlatformPei/Xen.h  |  39 ++
 OvmfPkg/XenPlatformPei/AmdSev.c   |  64 
 OvmfPkg/XenPlatformPei/ClearCache.c   | 112 ++
 OvmfPkg/XenPlatformPei/Cmos.c |  60 +++
 OvmfPkg/XenPlatformPei/Fv.c   |  76 
 OvmfPkg/XenPlatformPei/MemDetect.c| 421 
 OvmfPkg/XenPlatformPei/Platform.c | 444 ++
 OvmfPkg/XenPlatformPei/Xen.c  | 219 +++
 13 files changed, 1693 insertions(+), 2 deletions(-)
 create mode 100644 OvmfPkg/XenPlatformPei/XenPlatformPei.inf
 create mode 100644 OvmfPkg/XenPlatformPei/Cmos.h
 create mode 100644 OvmfPkg/XenPlatformPei/Platform.h
 create mode 100644 OvmfPkg/XenPlatformPei/Xen.h
 create mode 100644 OvmfPkg/XenPlatformPei/AmdSev.c
 create mode 100644 OvmfPkg/XenPlatformPei/ClearCache.c
 create mode 100644 OvmfPkg/XenPlatformPei/Cmos.c
 create mode 100644 OvmfPkg/XenPlatformPei/Fv.c
 create mode 100644 OvmfPkg/XenPlatformPei/MemDetect.c
 create mode 100644 OvmfPkg/XenPlatformPei/Platform.c
 create mode 100644 OvmfPkg/XenPlatformPei/Xen.c

diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index cab54da3e8..9f79d455fa 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -523,7 +523,7 @@ [Components]
   }

   MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf

 

-  OvmfPkg/PlatformPei/PlatformPei.inf

+  OvmfPkg/XenPlatformPei/XenPlatformPei.inf

   UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf

   UefiCpuPkg/CpuMpPei/CpuMpPei.inf

 

diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf
index 6fc8479aae..2ceff7baa2 100644
--- a/OvmfPkg/OvmfXen.fdf
+++ b/OvmfPkg/OvmfXen.fdf
@@ -152,7 +152,7 @@ [FV.PEIFV]
 INF  MdeModulePkg/Universal/PCD/Pei/Pcd.inf

 INF  
MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf

 INF  MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf

-INF  OvmfPkg/PlatformPei/PlatformPei.inf

+INF  OvmfPkg/XenPlatformPei/XenPlatformPei.inf

 INF  MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf

 INF  UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf

 INF  UefiCpuPkg/CpuMpPei/CpuMpPei.inf

diff --git a/OvmfPkg/XenPlatformPei/XenPlatformPei.inf 
b/OvmfPkg/XenPlatformPei/XenPlatformPei.inf
new file mode 100644
index 00..d1265c365a
--- /dev/null
+++ b/OvmfPkg/XenPlatformPei/XenPlatformPei.inf
@@ -0,0 +1,96 @@
+## @file

+#  Platform PEI driver

+#

+#  This module provides platform specific function to detect boot mode.

+#  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.

+#  Copyright (c) 2019, Citrix Systems, Inc.

+#

+#  SPDX-License-Identifier: BSD-2-Clause-Patent

+#

+##

+

+[Defines]

+  INF_VERSION= 0x00010005

+  BASE_NAME  = XenPlatformPei

+  FILE_GUID  = f112a6ee-993a-4f0b-8295-e520

[edk2-devel] [PATCH v3 00/35] Specific platform to run OVMF in Xen PVH and HVM guests

2019-07-04 Thread Anthony PERARD
Patch series available in this git branch:
https://xenbits.xen.org/git-http/people/aperard/ovmf.git br.platform-xen-pvh-v3

Hi,

I've started to create a Xen specific platform, in OvmfPkg/XenOvmf.dsc
with the goal to make it work on both Xen HVM and Xen PVH.

The first few patches only create the platform and duplicate some code from
OvmfPkg and the later patches makes OVMF boot in a Xen PVH guest and can boot
a Linux guest.

After this patch series, I'd like to wait a bit before removing Xen support
from the OvmfPkg*.dsc, to allow time to switch to the new Xen only platform,
maybe 1 year.

To build and boot:

To build, simply run OvmfPkg/build.sh -p OvmfPkg/OvmfXen.dsc
Then use OVMF.fd as a kernel of a pvh guest config file (with xl/libxl).

Patch series available in this git branch:
https://xenbits.xen.org/git-http/people/aperard/ovmf.git br.platform-xen-pvh-v3

Anthony PERARD (35):
  OvmfPkg/ResetSystemLib: Add missing dependency on PciLib
  OvmfPkg: Create platform OvmfXen
  OvmfPkg: Introduce XenResetVector
  OvmfPkg: Introduce XenPlatformPei
  OvmfPkg/OvmfXen: Creating an ELF header
  OvmfPkg/XenResetVector: Add new entry point for Xen PVH
  OvmfPkg/XenResetVector: Saving start of day pointer for PVH guests
  OvmfPkg/XenResetVector: Allow jumpstart from either hvmloader or PVH
  OvmfPkg/OvmfXen: use a TimerLib instance that depends only on the CPU
  OvmfPkg/XenPlatformPei: Detect OVMF_INFO from hvmloader
  OvmfPkg/XenPlatformPei: Use mXenHvmloaderInfo to get E820
  OvmfPkg/XenPlatformPei: Grab RSDP from PVH guest start of day struct
  OvmfPkg/Library/XenPlatformLib: New library
  OvmfPkg/AcpiPlatformDxe: Use XenPlatformLib
  OvmfPkg/AcpiPlatformDxe: Use Xen PVH RSDP if it exist
  OvmfPkg/XenHypercallLib: Enable it in PEIM
  OvmfPkg/XenPlatformPei: Reinit XenHypercallLib
  OvmfPkg/XenPlatformPei: Introduce XenHvmloaderDetected
  OvmfPkg/XenPlatformPei: Reserve hvmloader's memory only when it has
run
  OvmfPkg/XenPlatformPei: Setup HyperPages earlier
  OvmfPkg/XenPlatformPei: Introduce XenPvhDetected
  OvmfPkg: Import XENMEM_memory_map hypercall to Xen/memory.h
  OvmfPkg/XenPlatformPei: no hvmloader: get the E820 table via hypercall
  OvmfPkg/XenPlatformPei: Rework memory detection
  OvmfPkg/XenPlatformPei: Reserve VGA memory region, to boot Linux
  OvmfPkg/XenPlatformPei: Ignore missing PCI Host Bridge on Xen PVH
  OvmfPkg/XenPlatformLib: Cache result for XenDetected
  OvmfPkg/PlatformBootManagerLib: Use XenDetected from XenPlatformLib
  OvmfPkg/PlatformBootManagerLib: Handle the absence of PCI bus on Xen
PVH
  OvmfPkg/OvmfXen: Override PcdFSBClock to Xen vLAPIC timer frequency
  OvmfPkg/OvmfXen: Introduce XenTimerDxe
  OvmfPkg/PlatformBootManagerLib: Use a Xen console for ConOut/ConIn
  OvmfPkg: Introduce XenIoPvhDxe to initialize Grant Tables
  OvmfPkg: Move XenRealTimeClockLib from ArmVirtPkg
  OvmfPkg/OvmfXen: use RealTimeClockRuntimeDxe from EmbeddedPkg

 OvmfPkg/OvmfPkg.dec   |   7 +
 ArmVirtPkg/ArmVirtXen.dsc |   2 +-
 OvmfPkg/OvmfPkgIa32.dsc   |   1 +
 OvmfPkg/OvmfPkgIa32X64.dsc|   1 +
 OvmfPkg/OvmfPkgX64.dsc|   1 +
 OvmfPkg/{OvmfPkgX64.dsc => OvmfXen.dsc}   | 238 +---
 OvmfPkg/OvmfXen.fdf   | 539 ++
 OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf   |   2 +-
 .../PlatformBootManagerLib.inf|   5 +
 .../Library/ResetSystemLib/ResetSystemLib.inf |   1 +
 .../XenHypercallLib/XenHypercallLib.inf   |   4 +-
 .../Library/XenPlatformLib/XenPlatformLib.inf |  33 ++
 .../XenRealTimeClockLib.inf   |   0
 OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf   |  34 ++
 OvmfPkg/XenPlatformPei/XenPlatformPei.inf | 100 
 OvmfPkg/XenResetVector/XenResetVector.inf |  41 ++
 OvmfPkg/XenTimerDxe/XenTimerDxe.inf   |  42 ++
 OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h|   6 +-
 OvmfPkg/Include/Guid/XenInfo.h|   8 +-
 .../Xen/arch-x86/hvm/start_info.h | 143 +
 OvmfPkg/Include/IndustryStandard/Xen/memory.h |  23 +
 OvmfPkg/Include/Library/XenHypercallLib.h |  12 +
 OvmfPkg/Include/Library/XenPlatformLib.h  |  53 ++
 .../PlatformBootManagerLib/BdsPlatform.h  |   1 +
 OvmfPkg/XenPlatformPei/Cmos.h |  52 ++
 OvmfPkg/XenPlatformPei/Platform.h | 129 +
 OvmfPkg/XenPlatformPei/Xen.h  |  39 ++
 OvmfPkg/XenTimerDxe/XenTimerDxe.h | 177 ++
 OvmfPkg/AcpiPlatformDxe/Xen.c |  41 +-
 .../PlatformBootManagerLib/BdsPlatform.c  |  42 +-
 .../PlatformBootManagerLib/PlatformData.c |  59 +-
 .../Library/ResetSystemLib/ResetSystemLib.c   |   3 +-
 .../Library/XenHypercallLib/X86XenHypercall.c |   8 +-
 .../Library/XenHypercallLib/XenHypercall.c|  16 +
 .../Library/XenPlatformLib/XenPlatformLib.c   |  81 +++
 .../XenRealTimeClockLib/XenRealTimeClockLib.c |   0
 OvmfPkg/OvmfXenElfHeaderGenerato

[edk2-devel] [PATCH v3 07/35] OvmfPkg/XenResetVector: Saving start of day pointer for PVH guests

2019-07-04 Thread Anthony PERARD
As described in the Xen PVH documentation [1], "ebx: contains the
physical memory address where the loader has placed the boot start info
structure". To have this pointer saved to be able to use it later in the
PEI phase, we allocate some space in the MEMFD for it. We use 'XPVH' as
a signature (for "Xen PVH").

[1] https://xenbits.xenproject.org/docs/unstable/misc/pvh.html

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v3:
- rename PcdXenStartOfDay* to PcdXenPvhStartOfDay*
- Use first available token value for those (0x17 and 0x28)

 OvmfPkg/OvmfPkg.dec | 3 +++
 OvmfPkg/OvmfXen.fdf | 4 
 OvmfPkg/XenResetVector/XenResetVector.inf   | 3 +++
 OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm  | 6 ++
 OvmfPkg/XenResetVector/XenResetVector.nasmb | 2 ++
 5 files changed, 18 insertions(+)

diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index 9640360f62..c2a2ebfb95 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -218,6 +218,9 @@ [PcdsFixedAtBuild]
   #  The value should be a multiple of 4KB.

   gUefiOvmfPkgTokenSpaceGuid.PcdHighPmmMemorySize|0x40|UINT32|0x31

 

+  gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtr|0x0|UINT32|0x17

+  gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtrSize|0x0|UINT32|0x32

+

 [PcdsDynamic, PcdsDynamicEx]

   gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2

   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x10

diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf
index 43c268f6cb..49997fee9b 100644
--- a/OvmfPkg/OvmfXen.fdf
+++ b/OvmfPkg/OvmfXen.fdf
@@ -172,6 +172,10 @@ [FD.MEMFD]
 0x007000|0x001000

 
gEfiMdePkgTokenSpaceGuid.PcdGuidedExtractHandlerTableAddress|gUefiOvmfPkgTokenSpaceGuid.PcdGuidedExtractHandlerTableSize

 

+0x008000|0x001000

+# Used by XenResetVector to communicate with XenPlatformPei

+gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtr|gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtrSize

+

 0x01|0x01

 
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize

 

diff --git a/OvmfPkg/XenResetVector/XenResetVector.inf 
b/OvmfPkg/XenResetVector/XenResetVector.inf
index 097fc9b5b4..46b133a834 100644
--- a/OvmfPkg/XenResetVector/XenResetVector.inf
+++ b/OvmfPkg/XenResetVector/XenResetVector.inf
@@ -36,3 +36,6 @@ [BuildOptions]
 [Pcd]

   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase

   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize

+

+  gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtr

+  gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtrSize

diff --git a/OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm 
b/OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm
index 2a17fed52f..f42df3dba2 100644
--- a/OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm
+++ b/OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm
@@ -22,6 +22,12 @@ xenPVHMain:
 ;

 xor esp, esp

 

+;

+; Store "Start of day" struct pointer for later use

+;

+mov dword[PVH_SPACE (0)], ebx

+mov dword[PVH_SPACE (4)], 'XPVH'

+

 mov ebx, ADDR_OF(gdtr)

 lgdt[ebx]

 

diff --git a/OvmfPkg/XenResetVector/XenResetVector.nasmb 
b/OvmfPkg/XenResetVector/XenResetVector.nasmb
index 0dbc4f2c1d..b2cb405d54 100644
--- a/OvmfPkg/XenResetVector/XenResetVector.nasmb
+++ b/OvmfPkg/XenResetVector/XenResetVector.nasmb
@@ -34,6 +34,8 @@
 

 %include "CommonMacros.inc"

 

+%define PVH_SPACE(Offset) (FixedPcdGet32 (PcdXenPvhStartOfDayStructPtr) + 
(Offset))

+

 %include "PostCodes.inc"

 

 %ifdef DEBUG_PORT80

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43283): https://edk2.groups.io/g/devel/message/43283
Mute This Topic: https://groups.io/mt/32308569/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 01/35] OvmfPkg/ResetSystemLib: Add missing dependency on PciLib

2019-07-04 Thread Anthony PERARD
Add missing dependency on PciLib
and remove extra includes of OvmfPlatforms.h.

Signed-off-by: Anthony PERARD 
Reviewed-by: Laszlo Ersek 
---

Notes:
v2:
- also add PciLib.h include to the .c
- and remove extra include of OvmfPlatforms.h

 OvmfPkg/Library/ResetSystemLib/ResetSystemLib.inf | 1 +
 OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c   | 3 +--
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.inf 
b/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.inf
index 7c44f99a5c..2f24dac87f 100644
--- a/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.inf
+++ b/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.inf
@@ -30,4 +30,5 @@ [Packages]
 [LibraryClasses]

   DebugLib

   IoLib

+  PciLib

   TimerLib

diff --git a/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c 
b/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c
index 27460cd100..98dd80e33c 100644
--- a/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c
+++ b/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c
@@ -11,11 +11,10 @@
 #include 

 #include 

 #include 

+#include 

 #include 

 #include 

 

-#include 

-

 VOID

 AcpiPmControl (

   UINTN SuspendType

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43278): https://edk2.groups.io/g/devel/message/43278
Mute This Topic: https://groups.io/mt/32308563/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 09/35] OvmfPkg/OvmfXen: use a TimerLib instance that depends only on the CPU

2019-07-04 Thread Anthony PERARD
ACPI Timer does not work in a PVH guest, but local APIC works on both
PVH and HVM.

Note that the use of SecPeiDxeTimerLibCpu might be an issue with a
driver of type DXE_RUNTIME_DRIVER. I've attemptde to find out which of
the DXE_RUNTIME_DRIVER uses the TimerLib at runtime. I've done that by
replacing the TimerLib evaluation in
[LibraryClasses.common.DXE_RUNTIME_DRIVER] by a different one and
check every module that uses it (with the --report-file=report build
option).

ResetSystemRuntimeDxe is calling the TimerLib API at runtime to do the
operation "EfiResetCold", so this may never complete if the OS have
disabled the Local APIC Timer.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
---

Notes:
v3:
- cleanup .dsc, leave only one TimerLib resolution
- Added a note in the commit message regarding the use of the local apic
  by runtime drivers

 OvmfPkg/OvmfXen.dsc | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index 9f79d455fa..6288394eb8 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -104,7 +104,7 @@ [SkuIds]
 


 [LibraryClasses]

   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf

-  TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf

+  TimerLib|MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.inf

   PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf

   BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf

   BaseLib|MdePkg/Library/BaseLib/BaseLib.inf

@@ -202,7 +202,6 @@ [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf

 

 [LibraryClasses.common.SEC]

-  TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf

   QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf

 !ifdef $(DEBUG_ON_SERIAL_PORT)

   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf

@@ -281,7 +280,6 @@ [LibraryClasses.common.DXE_CORE]
 

 [LibraryClasses.common.DXE_RUNTIME_DRIVER]

   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf

-  TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf

   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf

   DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf

   
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

@@ -298,7 +296,6 @@ [LibraryClasses.common.DXE_RUNTIME_DRIVER]
 

 [LibraryClasses.common.UEFI_DRIVER]

   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf

-  TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf

   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf

   DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf

   
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

@@ -313,7 +310,6 @@ [LibraryClasses.common.UEFI_DRIVER]
 

 [LibraryClasses.common.DXE_DRIVER]

   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf

-  TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf

   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf

   
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

   
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf

@@ -337,7 +333,6 @@ [LibraryClasses.common.DXE_DRIVER]
 

 [LibraryClasses.common.UEFI_APPLICATION]

   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf

-  TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf

   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf

   
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf

   
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43287): https://edk2.groups.io/g/devel/message/43287
Mute This Topic: https://groups.io/mt/32308573/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 30/35] OvmfPkg/OvmfXen: Override PcdFSBClock to Xen vLAPIC timer frequency

2019-07-04 Thread Anthony PERARD
PcdFSBClock is used by SecPeiDxeTimerLibCpu, the TimerLib
implementation. It will also be used by XenTimerDxe. Override
PcdFSBClock to match Xen vLAPIC timer frequency.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v3:
- expand commit message body to be standalone

 OvmfPkg/OvmfXen.dsc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index 68d82da7aa..bc6b6602c6 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -439,6 +439,9 @@ [PcdsFixedAtBuild]
   # Point to the MdeModulePkg/Application/UiApp/UiApp.inf

   gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 
0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 }

 

+  ## Xen vlapic's frequence is 100 MHz

+  gEfiMdePkgTokenSpaceGuid.PcdFSBClock|1

+

 


 #

 # Pcd Dynamic Section - list of all EDK II PCD Entries defined by this Platform

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43296): https://edk2.groups.io/g/devel/message/43296
Mute This Topic: https://groups.io/mt/32308718/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 14/35] OvmfPkg/AcpiPlatformDxe: Use XenPlatformLib

2019-07-04 Thread Anthony PERARD
This patch replace the XenDetected() function by the one in
XenPlatformLib.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
---

Notes:
v3:
- new patch, splited from the next patch
  (which was OvmfPkg/AcpiPlatformDxe: Use PVH RSDP if exist)

 OvmfPkg/OvmfPkgIa32.dsc |  1 +
 OvmfPkg/OvmfPkgIa32X64.dsc  |  1 +
 OvmfPkg/OvmfPkgX64.dsc  |  1 +
 OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf |  2 +-
 OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h  |  6 +-
 OvmfPkg/AcpiPlatformDxe/Xen.c   | 24 -
 6 files changed, 5 insertions(+), 30 deletions(-)

diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index d60bcd5e54..1b116fe3b3 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -202,6 +202,7 @@ [LibraryClasses]
   SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf

   
OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf

   XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf

+  XenPlatformLib|OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf

 

 !if $(TPM2_ENABLE) == TRUE

   Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf

diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index ded3e8a464..bd8625a075 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -207,6 +207,7 @@ [LibraryClasses]
   SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf

   
OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf

   XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf

+  XenPlatformLib|OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf

 

 !if $(TPM2_ENABLE) == TRUE

   Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf

diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index 131f2b0b47..db9ba7cc15 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -207,6 +207,7 @@ [LibraryClasses]
   SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf

   
OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf

   XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf

+  XenPlatformLib|OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf

 

 !if $(TPM2_ENABLE) == TRUE

   Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf

diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf 
b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
index 24634eeae2..eadace366d 100644
--- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
+++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
@@ -44,13 +44,13 @@ [LibraryClasses]
   DebugLib

   UefiBootServicesTableLib

   UefiDriverEntryPoint

-  HobLib

   QemuFwCfgLib

   QemuFwCfgS3Lib

   MemoryAllocationLib

   BaseLib

   DxeServicesTableLib

   OrderedCollectionLib

+  XenPlatformLib

 

 [Protocols]

   gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_CONSUMED

diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h 
b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h
index 3037afcf18..9597e028e4 100644
--- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h
+++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h
@@ -19,6 +19,7 @@
 #include 

 #include 

 #include 

+#include 

 

 #include 

 

@@ -52,11 +53,6 @@ QemuInstallAcpiTable (
   OUT  UINTN *TableKey

   );

 

-BOOLEAN

-XenDetected (

-  VOID

-  );

-

 EFI_STATUS

 EFIAPI

 InstallXenTables (

diff --git a/OvmfPkg/AcpiPlatformDxe/Xen.c b/OvmfPkg/AcpiPlatformDxe/Xen.c
index e4e47bf0e8..82794b933e 100644
--- a/OvmfPkg/AcpiPlatformDxe/Xen.c
+++ b/OvmfPkg/AcpiPlatformDxe/Xen.c
@@ -9,8 +9,6 @@
 **/ 

 

 #include "AcpiPlatform.h"

-#include 

-#include 

 #include 

 

 #define XEN_ACPI_PHYSICAL_ADDRESS 0x000EA020

@@ -18,28 +16,6 @@
 

 EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER  *XenAcpiRsdpStructurePtr = NULL;

 

-/**

-  This function detects if OVMF is running on Xen.

-

-**/

-BOOLEAN

-XenDetected (

-  VOID

-  )

-{

-  EFI_HOB_GUID_TYPE *GuidHob;

-

-  //

-  // See if a XenInfo HOB is available

-  //

-  GuidHob = GetFirstGuidHob ();

-  if (GuidHob == NULL) {

-return FALSE;

-  }

-

-  return TRUE;

-}

-

 /**

   Get the address of Xen ACPI Root System Description Pointer (RSDP)

   structure.

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43288): https://edk2.groups.io/g/devel/message/43288
Mute This Topic: https://groups.io/mt/32308706/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 24/35] OvmfPkg/XenPlatformPei: Rework memory detection

2019-07-04 Thread Anthony PERARD
When running as a Xen PVH guest, there is no CMOS to read the memory
size from.  Rework GetSystemMemorySize(Below|Above)4gb() so they can
works without CMOS by reading the e820 table.

Rework XenPublishRamRegions for PVH, handle the Reserve type and explain
about the ACPI type. MTRR settings aren't modified anymore, on HVM, it's
already done by hvmloader, on PVH it is supposed to have sane default.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
Comment for Xen people:
About MTRR, should we redo the setting in OVMF? Even if in both case of
PVH and HVM, something would have setup the default type to write back
and handle a few other ranges like PCI hole, hvmloader for HVM or and
libxc I think for PVH.

(For PVH, it's in the spec as well
https://xenbits.xenproject.org/docs/unstable/misc/pvh.html#mtrr )

 OvmfPkg/XenPlatformPei/Platform.h  |  6 +++
 OvmfPkg/XenPlatformPei/MemDetect.c | 71 ++
 OvmfPkg/XenPlatformPei/Xen.c   | 47 ++--
 3 files changed, 111 insertions(+), 13 deletions(-)

diff --git a/OvmfPkg/XenPlatformPei/Platform.h 
b/OvmfPkg/XenPlatformPei/Platform.h
index db9a62572f..e8e0b835a5 100644
--- a/OvmfPkg/XenPlatformPei/Platform.h
+++ b/OvmfPkg/XenPlatformPei/Platform.h
@@ -114,6 +114,12 @@ XenPublishRamRegions (
   VOID

   );

 

+EFI_STATUS

+XenGetE820Map (

+  EFI_E820_ENTRY64 **Entries,

+  UINT32 *Count

+  );

+

 extern EFI_BOOT_MODE mBootMode;

 

 extern UINT8 mPhysMemAddressWidth;

diff --git a/OvmfPkg/XenPlatformPei/MemDetect.c 
b/OvmfPkg/XenPlatformPei/MemDetect.c
index cb7dd93ad6..3e33e7f414 100644
--- a/OvmfPkg/XenPlatformPei/MemDetect.c
+++ b/OvmfPkg/XenPlatformPei/MemDetect.c
@@ -96,6 +96,47 @@ Q35TsegMbytesInitialization (
   mQ35TsegMbytes = ExtendedTsegMbytes;

 }

 

+STATIC

+UINT64

+GetHighestSystemMemoryAddress (

+  BOOLEAN   Below4gb

+  )

+{

+  EFI_E820_ENTRY64*E820Map;

+  UINT32  E820EntriesCount;

+  EFI_E820_ENTRY64*Entry;

+  EFI_STATUS  Status;

+  UINT32  Loop;

+  UINT64  HighestAddress;

+  UINT64  EntryEnd;

+

+  HighestAddress = 0;

+

+  Status = XenGetE820Map (, );

+  ASSERT_EFI_ERROR (Status);

+

+  for (Loop = 0; Loop < E820EntriesCount; Loop++) {

+Entry = E820Map + Loop;

+EntryEnd = Entry->BaseAddr + Entry->Length;

+

+if (Entry->Type == EfiAcpiAddressRangeMemory &&

+EntryEnd > HighestAddress) {

+

+  if (Below4gb && (EntryEnd <= BASE_4GB)) {

+HighestAddress = EntryEnd;

+  } else if (!Below4gb && (EntryEnd >= BASE_4GB)) {

+HighestAddress = EntryEnd;

+  }

+}

+  }

+

+  //

+  // Round down the end address.

+  //

+  HighestAddress &= ~(UINT64)EFI_PAGE_MASK;

+

+  return HighestAddress;

+}

 

 UINT32

 GetSystemMemorySizeBelow4gb (

@@ -105,6 +146,19 @@ GetSystemMemorySizeBelow4gb (
   UINT8 Cmos0x34;

   UINT8 Cmos0x35;

 

+  //

+  // In PVH case, there is no CMOS, we have to calculate the memory size

+  // from parsing the E820

+  //

+  if (XenPvhDetected ()) {

+UINT64  HighestAddress;

+

+HighestAddress = GetHighestSystemMemoryAddress (TRUE);

+ASSERT (HighestAddress > 0 && HighestAddress <= BASE_4GB);

+

+return HighestAddress;

+  }

+

   //

   // CMOS 0x34/0x35 specifies the system memory above 16 MB.

   // * CMOS(0x35) is the high byte

@@ -129,6 +183,23 @@ GetSystemMemorySizeAbove4gb (
   UINT32 Size;

   UINTN  CmosIndex;

 

+  //

+  // In PVH case, there is no CMOS, we have to calculate the memory size

+  // from parsing the E820

+  //

+  if (XenPvhDetected ()) {

+UINT64  HighestAddress;

+

+HighestAddress = GetHighestSystemMemoryAddress (FALSE);

+ASSERT (HighestAddress == 0 || HighestAddress >= BASE_4GB);

+

+if (HighestAddress >= BASE_4GB) {

+  HighestAddress -= BASE_4GB;

+}

+

+return HighestAddress;

+  }

+

   //

   // CMOS 0x5b-0x5d specifies the system memory above 4GB MB.

   // * CMOS(0x5d) is the most significant size byte

diff --git a/OvmfPkg/XenPlatformPei/Xen.c b/OvmfPkg/XenPlatformPei/Xen.c
index cbfd8058fc..62a2c3ed93 100644
--- a/OvmfPkg/XenPlatformPei/Xen.c
+++ b/OvmfPkg/XenPlatformPei/Xen.c
@@ -279,6 +279,8 @@ XenPublishRamRegions (
   EFI_E820_ENTRY64  *E820Map;

   UINT32E820EntriesCount;

   EFI_STATUSStatus;

+  EFI_E820_ENTRY64 *Entry;

+  UINTN Index;

 

   DEBUG ((EFI_D_INFO, "Using memory map provided by Xen\n"));

 

@@ -287,26 +289,45 @@ XenPublishRamRegions (
   //

   E820EntriesCount = 0;

   Status = XenGetE820Map (, );

-

   ASSERT_EFI_ERROR (Status);

 

-  if (E820EntriesCount > 0) {

-EFI_E820_ENTRY64 *Entry;

-UINT32 Loop;

+  for (Index = 0; Index < E820EntriesCount; Index++) {

+UINT64 Base;

+UINT64 End;

 

-for (Loo

[edk2-devel] [PATCH v3 15/35] OvmfPkg/AcpiPlatformDxe: Use Xen PVH RSDP if it exist

2019-07-04 Thread Anthony PERARD
If the firmware have been started via the Xen PVH entry point, a RSDP
pointer would have been provided. Use it.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
---

Notes:
v3:
- patch splited from the previous one
- Fix DEBUG format string, use %p for pointers.
  and use gEfiCallerBaseName to print module name

 OvmfPkg/AcpiPlatformDxe/Xen.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/OvmfPkg/AcpiPlatformDxe/Xen.c b/OvmfPkg/AcpiPlatformDxe/Xen.c
index 82794b933e..376a6bd3cb 100644
--- a/OvmfPkg/AcpiPlatformDxe/Xen.c
+++ b/OvmfPkg/AcpiPlatformDxe/Xen.c
@@ -36,10 +36,27 @@ GetXenAcpiRsdp (
   EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER   *RsdpStructurePtr;

   UINT8  *XenAcpiPtr;

   UINT8  Sum;

+  EFI_XEN_INFO   *XenInfo;

 

   //

   // Detect the RSDP structure

   //

+

+  //

+  // First look for PVH one

+  //

+  XenInfo = XenGetInfoHOB ();

+  ASSERT (XenInfo != NULL);

+  if (XenInfo->RsdpPvh != NULL) {

+DEBUG ((DEBUG_INFO, "%a: Use ACPI RSDP table at 0x%p\n",

+gEfiCallerBaseName, XenInfo->RsdpPvh));

+*RsdpPtr = XenInfo->RsdpPvh;

+return EFI_SUCCESS;

+  }

+

+  //

+  // Otherwise, look for the HVM one

+  //

   for (XenAcpiPtr = (UINT8*)(UINTN) XEN_ACPI_PHYSICAL_ADDRESS;

XenAcpiPtr < (UINT8*)(UINTN) XEN_BIOS_PHYSICAL_END;

XenAcpiPtr += 0x10) {

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43293): https://edk2.groups.io/g/devel/message/43293
Mute This Topic: https://groups.io/mt/32308713/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 31/35] OvmfPkg/OvmfXen: Introduce XenTimerDxe

2019-07-04 Thread Anthony PERARD
"PcAtChipsetPkg/8254TimerDxe" is replaced with a Xen-specific
EFI_TIMER_ARCH_PROTOCOL implementation. Also remove
8259InterruptControllerDxe as it is not used anymore.

This Timer uses the local APIC timer as time source as it can work on
both a Xen PVH guest and an HVM one.

Based on the "PcAtChipsetPkg/8254TimerDxe" implementation.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
---

Notes:
v3:
- rebased, SPDX, copyright

v2:
- Use InitializeApicTimer instead of WriteLocalApicReg
- rework comments (remove many that don't apply)
- remove unused includes, and libs
- have a macro to the timervector.
- cleanup, copyright
- rework calculation of TimerCount, value to be use by the APIC timer
- check for overflow of TimerPeriod, with the apic timer, the period can
  be up to about 42s on Xen (or even higher by changing the DivideValue).

 OvmfPkg/OvmfXen.dsc |   3 +-
 OvmfPkg/OvmfXen.fdf |   3 +-
 OvmfPkg/XenTimerDxe/XenTimerDxe.inf |  42 
 OvmfPkg/XenTimerDxe/XenTimerDxe.h   | 177 ++
 OvmfPkg/XenTimerDxe/XenTimerDxe.c   | 355 
 5 files changed, 576 insertions(+), 4 deletions(-)
 create mode 100644 OvmfPkg/XenTimerDxe/XenTimerDxe.inf
 create mode 100644 OvmfPkg/XenTimerDxe/XenTimerDxe.h
 create mode 100644 OvmfPkg/XenTimerDxe/XenTimerDxe.c

diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index bc6b6602c6..1ecae3fb45 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -547,10 +547,9 @@ [Components]
   MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

 

   MdeModulePkg/Universal/EbcDxe/EbcDxe.inf

-  OvmfPkg/8259InterruptControllerDxe/8259.inf

+  OvmfPkg/XenTimerDxe/XenTimerDxe.inf

   UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf

   UefiCpuPkg/CpuDxe/CpuDxe.inf

-  OvmfPkg/8254TimerDxe/8254Timer.inf

   OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf

   OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf

   MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf {

diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf
index 49997fee9b..fa0830a324 100644
--- a/OvmfPkg/OvmfXen.fdf
+++ b/OvmfPkg/OvmfXen.fdf
@@ -298,10 +298,9 @@ [FV.DXEFV]
 INF  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf

 INF  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf

 INF  MdeModulePkg/Universal/EbcDxe/EbcDxe.inf

-INF  OvmfPkg/8259InterruptControllerDxe/8259.inf

+INF  OvmfPkg/XenTimerDxe/XenTimerDxe.inf

 INF  UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf

 INF  UefiCpuPkg/CpuDxe/CpuDxe.inf

-INF  OvmfPkg/8254TimerDxe/8254Timer.inf

 INF  OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf

 INF  OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf

 INF  MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf

diff --git a/OvmfPkg/XenTimerDxe/XenTimerDxe.inf 
b/OvmfPkg/XenTimerDxe/XenTimerDxe.inf
new file mode 100644
index 00..add1d01bbf
--- /dev/null
+++ b/OvmfPkg/XenTimerDxe/XenTimerDxe.inf
@@ -0,0 +1,42 @@
+## @file

+# Local APIC timer driver that provides Timer Arch protocol.

+#

+# Copyright (c) 2005 - 2019, Intel Corporation. All rights reserved.

+# Copyright (c) 2019, Citrix Systems, Inc.

+#

+# SPDX-License-Identifier: BSD-2-Clause-Patent

+#

+##

+

+[Defines]

+  INF_VERSION= 0x00010005

+  BASE_NAME  = XenTimerDxe

+  FILE_GUID  = 52fe8196-f9de-4d07-b22f-51f77a0e7c41

+  MODULE_TYPE= DXE_DRIVER

+  VERSION_STRING = 1.0

+

+  ENTRY_POINT= TimerDriverInitialize

+

+[Packages]

+  MdePkg/MdePkg.dec

+  UefiCpuPkg/UefiCpuPkg.dec

+  OvmfPkg/OvmfPkg.dec

+

+[LibraryClasses]

+  UefiBootServicesTableLib

+  BaseLib

+  DebugLib

+  UefiDriverEntryPoint

+  LocalApicLib

+

+[Sources]

+  XenTimerDxe.h

+  XenTimerDxe.c

+

+[Protocols]

+  gEfiCpuArchProtocolGuid   ## CONSUMES

+  gEfiTimerArchProtocolGuid ## PRODUCES

+[Pcd]

+  gEfiMdePkgTokenSpaceGuid.PcdFSBClock  ## CONSUMES

+[Depex]

+  gEfiCpuArchProtocolGuid

diff --git a/OvmfPkg/XenTimerDxe/XenTimerDxe.h 
b/OvmfPkg/XenTimerDxe/XenTimerDxe.h
new file mode 100644
index 00..e0a3d95fd0
--- /dev/null
+++ b/OvmfPkg/XenTimerDxe/XenTimerDxe.h
@@ -0,0 +1,177 @@
+/** @file

+  Private data structures

+

+Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.

+Copyright (c) 2019, Citrix Systems, Inc.

+

+SPDX-License-Identifier: BSD-2-Clause-Patent

+**/

+

+#ifndef _TIMER_H_

+#define _TIMER_H_

+

+#include 

+

+#include 

+#include 

+

+#include 

+

+#include 

+#include 

+#include 

+#include 

+#include 

+

+// The default timer tick duration is set to 10 ms = 10 100 ns units

+//

+#define DEFAULT_TIMER_TICK_DURATION 10

+

+//

+// The Timer Vector use for interrupt

+//

+#define LOCAL_APIC_TIMER_VECTOR 32

+

+//

+// Function Prototypes

+//

+/**

+  

[edk2-devel] [PATCH v3 26/35] OvmfPkg/XenPlatformPei: Ignore missing PCI Host Bridge on Xen PVH

2019-07-04 Thread Anthony PERARD
When the device ID of the host bridge is unknown, check if we are
running as a PVH guest as there is no PCI bus in that case.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
---

Notes:
v3:
- Remove use of XEN_PVH_PCI_HOST_BRIDGE_DEVICE_ID, and simply don't set
  PcdOvmfHostBridgePciDevId.

v2:
- Use new XEN_PVH_PCI_HOST_BRIDGE_DEVICE_ID macro

 OvmfPkg/XenPlatformPei/Platform.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/OvmfPkg/XenPlatformPei/Platform.c 
b/OvmfPkg/XenPlatformPei/Platform.c
index 52f6048ca4..b7fc30d2ee 100644
--- a/OvmfPkg/XenPlatformPei/Platform.c
+++ b/OvmfPkg/XenPlatformPei/Platform.c
@@ -272,6 +272,12 @@ MiscInitialization (
   AcpiEnBit  = ICH9_ACPI_CNTL_ACPI_EN;

   break;

 default:

+  if (XenPvhDetected ()) {

+//

+// There is no PCI bus in this case

+//

+return;

+  }

   DEBUG ((EFI_D_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",

 __FUNCTION__, mHostBridgeDevId));

   ASSERT (FALSE);

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43299): https://edk2.groups.io/g/devel/message/43299
Mute This Topic: https://groups.io/mt/32308723/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 13/35] OvmfPkg/Library/XenPlatformLib: New library

2019-07-04 Thread Anthony PERARD
The purpose of XenPlatformLib is to regroup the few functions that are
used in several places to detect if Xen is detected, and to get the
XenInfo HOB.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
---

Notes:
v3:
- use SPDX
- add XenPlatformLib.h to [LibraryClasses] in OvmfPkg.dec
- fix typos

 OvmfPkg/OvmfPkg.dec   |  4 ++
 OvmfPkg/OvmfXen.dsc   |  1 +
 .../Library/XenPlatformLib/XenPlatformLib.inf | 33 +
 OvmfPkg/Include/Library/XenPlatformLib.h  | 53 ++
 .../Library/XenPlatformLib/XenPlatformLib.c   | 69 +++
 5 files changed, 160 insertions(+)
 create mode 100644 OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf
 create mode 100644 OvmfPkg/Include/Library/XenPlatformLib.h
 create mode 100644 OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c

diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index c2a2ebfb95..04d5e29272 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -70,6 +70,10 @@ [LibraryClasses]
   #

   XenIoMmioLib|Include/Library/XenIoMmioLib.h

 

+  ##  @libraryclass  Get information about Xen

+  #

+  XenPlatformLib|Include/Library/XenPlatformLib.h

+

 [Guids]

   gUefiOvmfPkgTokenSpaceGuid  = {0x93bb96af, 0xb9f2, 0x4eb8, {0x94, 
0x62, 0xe0, 0xba, 0x74, 0x56, 0x42, 0x36}}

   gEfiXenInfoGuid = {0xd3b46f3b, 0xd441, 0x1244, {0x9a, 
0x12, 0x0, 0x12, 0x27, 0x3f, 0xc1, 0x4d}}

diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index 6288394eb8..68d82da7aa 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -195,6 +195,7 @@ [LibraryClasses]
   SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf

   
OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf

   XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf

+  XenPlatformLib|OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf

 

   
Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf

 

diff --git a/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf 
b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf
new file mode 100644
index 00..32adb246d6
--- /dev/null
+++ b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf
@@ -0,0 +1,33 @@
+## @file

+#  Get information about Xen

+#

+#  This library simply allow to find out if OVMF is running under Xen and

+#  allow to get more information when it is the case.

+#

+#  Copyright (c) 2019, Citrix Systems, Inc.

+#

+#  SPDX-License-Identifier: BSD-2-Clause-Patent

+#

+#

+##

+

+[Defines]

+  INF_VERSION= 0x00010005

+  BASE_NAME  = XenPlatformLib

+  FILE_GUID  = DB54DBB7-8142-4EE5-9364-78C824B582EB

+  MODULE_TYPE= BASE

+  VERSION_STRING = 1.0

+  LIBRARY_CLASS  = XenPlatformLib

+

+[Sources]

+  XenPlatformLib.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  OvmfPkg/OvmfPkg.dec

+

+[LibraryClasses]

+  HobLib

+

+[Guids]

+  gEfiXenInfoGuid

diff --git a/OvmfPkg/Include/Library/XenPlatformLib.h 
b/OvmfPkg/Include/Library/XenPlatformLib.h
new file mode 100644
index 00..a8347602b7
--- /dev/null
+++ b/OvmfPkg/Include/Library/XenPlatformLib.h
@@ -0,0 +1,53 @@
+/** @file

+*  Get information about Xen

+*

+*  This library simply allow to find out if OVMF is running under Xen and

+*  allow to get more information when it is the case.

+*

+*  Copyright (c) 2019, Citrix Systems, Inc.

+*

+*  SPDX-License-Identifier: BSD-2-Clause-Patent

+*

+**/

+

+#ifndef _XEN_PLATFORM_LIB_H_

+#define _XEN_PLATFORM_LIB_H_

+

+#include 

+

+/**

+  This function detects if OVMF is running on Xen.

+

+  @retval TRUEOVMF is running on Xen

+  @retval FALSE   Xen has not been detected

+**/

+BOOLEAN

+EFIAPI

+XenDetected (

+  VOID

+  );

+

+/**

+  This function detect if OVMF have started via the PVH entry point.

+

+  @retval TRUE  PVH entry point as been used

+  @retval FALSE OVMF have started via the HVM route

+**/

+BOOLEAN

+EFIAPI

+XenPvhDetected (

+  VOID

+  );

+

+/**

+  This function return a pointer to the XenInfo HOB.

+

+  @return  XenInfo pointer or NULL if not available

+**/

+EFI_XEN_INFO *

+EFIAPI

+XenGetInfoHOB (

+  VOID

+  );

+

+#endif

diff --git a/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c 
b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c
new file mode 100644
index 00..6f27cbffa8
--- /dev/null
+++ b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c
@@ -0,0 +1,69 @@
+/** @file

+*  Get information about Xen

+*

+*  This library simply allow to find out if OVMF is running under Xen and

+*  allow to get more information when it is the case.

+*

+*  Copyright (c) 2019, Citrix Systems, Inc.

+*

+*  SPDX-License-Identifier: BSD-2-Clause-Patent

+*

+**/

+

+#include 

+#include 

+#include

[edk2-devel] [PATCH v3 17/35] OvmfPkg/XenPlatformPei: Reinit XenHypercallLib

2019-07-04 Thread Anthony PERARD
The XenPlatformPei needs to make hypercalls, but the XenHypercallLib was
initialised before the HyperPage was ready. Now that XenPlatformPei has
initialised the HyperPage, reinitialise the XenHypercallLib.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
---

Notes:
v3:
- new patch split from XenHypercallLib: Enable it in PEIM.
- check for Lib initialisation failure.

 OvmfPkg/XenPlatformPei/XenPlatformPei.inf | 1 +
 OvmfPkg/XenPlatformPei/Xen.c  | 9 +
 2 files changed, 10 insertions(+)

diff --git a/OvmfPkg/XenPlatformPei/XenPlatformPei.inf 
b/OvmfPkg/XenPlatformPei/XenPlatformPei.inf
index 4d00206d09..0ef77db92c 100644
--- a/OvmfPkg/XenPlatformPei/XenPlatformPei.inf
+++ b/OvmfPkg/XenPlatformPei/XenPlatformPei.inf
@@ -59,6 +59,7 @@ [LibraryClasses]
   MtrrLib

   MemEncryptSevLib

   PcdLib

+  XenHypercallLib

 

 [Pcd]

   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase

diff --git a/OvmfPkg/XenPlatformPei/Xen.c b/OvmfPkg/XenPlatformPei/Xen.c
index c5293498c4..877d776de8 100644
--- a/OvmfPkg/XenPlatformPei/Xen.c
+++ b/OvmfPkg/XenPlatformPei/Xen.c
@@ -26,6 +26,7 @@
 #include 

 #include 

 #include 

+#include 

 

 #include "Platform.h"

 #include "Xen.h"

@@ -88,6 +89,7 @@ XenConnect (
   EFI_XEN_OVMF_INFO *Info;

   CHAR8 Sig[sizeof (Info->Signature) + 1];

   UINT32 *PVHResetVectorData;

+  RETURN_STATUS Status;

 

   AsmCpuid (XenLeaf + 2, , , NULL, NULL);

   mXenInfo.HyperPages = AllocatePages (TransferPages);

@@ -152,6 +154,13 @@ XenConnect (
 sizeof(mXenInfo)

 );

 

+  //

+  // Initialize the XenHypercall library, now that the XenInfo HOB is

+  // available

+  //

+  Status = XenHypercallLibInit ();

+  ASSERT_RETURN_ERROR (Status);

+

   return EFI_SUCCESS;

 }

 

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43300): https://edk2.groups.io/g/devel/message/43300
Mute This Topic: https://groups.io/mt/32308724/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 29/35] OvmfPkg/PlatformBootManagerLib: Handle the absence of PCI bus on Xen PVH

2019-07-04 Thread Anthony PERARD
When running in a Xen PVH guest, there's nothing to do in
PciAcpiInitialization() because there isn't any PCI bus. When the Host
Bridge DID isn't recognised, simply continue. (The value of
PcdOvmfHostBridgePciDevId would be 0 because it isn't set.)

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
---

Notes:
v3:
- Instead of checking for a false value,
  XEN_PVH_PCI_HOST_BRIDGE_DEVICE_ID, simply check if we are running xen
  when the HostBridge device ID isn't recognised.

 OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c 
b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
index e32969e63e..9ae590293a 100644
--- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
+++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
@@ -1209,6 +1209,12 @@ PciAcpiInitialization (
   PciWrite8 (PCI_LIB_ADDRESS (0, 0x1f, 0, 0x6b), 0x0b); // H

   break;

 default:

+  if (XenDetected ()) {

+//

+// There is no PCI bus in this case.

+//

+return;

+  }

   DEBUG ((EFI_D_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",

 __FUNCTION__, mHostBridgeDevId));

   ASSERT (FALSE);

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43311): https://edk2.groups.io/g/devel/message/43311
Mute This Topic: https://groups.io/mt/32308735/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 32/35] OvmfPkg/PlatformBootManagerLib: Use a Xen console for ConOut/ConIn

2019-07-04 Thread Anthony PERARD
On a Xen PVH guest, none of the existing serial or console interface
works, so we add a new one, based on XenConsoleSerialPortLib, and
implemented via SerialDxe.

That is a simple console implementation that can works on both PVH
guest and HVM guests, even if it rarely going to be use on HVM.

Have PlatformBootManagerLib look for the new console, when running as a
Xen guest.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
---

Notes:
v3:
- removed PciSioSerialDxe and IsaSerialDxe from OvmfXen, since they
  would not be used, maybe, to check.
- some coding style fix

- not changed: PciSioSerialDxe: even if we add SerialDxe, we still needs
  PciSioSerialDxe to have OVMF use the emulated serial port on HVM.

v2:
- Use MdeModulePkg/Universal/SerialDxe instead of something new.
- Have PlatformInitializeConsole() look for it by using the
  known-in-advance device path for the xen console in the
  PLATFORM_CONSOLE_CONNECT_ENTRY.

 OvmfPkg/OvmfXen.dsc   |  4 ++
 OvmfPkg/OvmfXen.fdf   |  1 +
 .../PlatformBootManagerLib.inf|  4 ++
 .../PlatformBootManagerLib/BdsPlatform.h  |  1 +
 .../PlatformBootManagerLib/BdsPlatform.c  |  3 +-
 .../PlatformBootManagerLib/PlatformData.c | 59 ++-
 6 files changed, 69 insertions(+), 3 deletions(-)

diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index 1ecae3fb45..487bada64d 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -586,6 +586,10 @@ [Components]
   OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf

   OvmfPkg/XenBusDxe/XenBusDxe.inf

   OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf

+  MdeModulePkg/Universal/SerialDxe/SerialDxe.inf {

+

+  
SerialPortLib|OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf

+  }

   MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf

   
MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf

   MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf

diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf
index fa0830a324..5c1a925d6a 100644
--- a/OvmfPkg/OvmfXen.fdf
+++ b/OvmfPkg/OvmfXen.fdf
@@ -312,6 +312,7 @@ [FV.DXEFV]
 INF  OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf

 INF  OvmfPkg/XenBusDxe/XenBusDxe.inf

 INF  OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf

+INF  MdeModulePkg/Universal/SerialDxe/SerialDxe.inf

 

 INF  MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf

 INF  
MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf

diff --git a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf 
b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
index b2d3b4fb4d..646a1c522c 100644
--- a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
+++ b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
@@ -61,6 +61,10 @@ [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable

   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId

   gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate ## CONSUMES

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits ## CONSUMES

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity   ## CONSUMES

+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits ## CONSUMES

 

 [Pcd.IA32, Pcd.X64]

   gEfiMdePkgTokenSpaceGuid.PcdFSBClock

diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.h 
b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.h
index 49a072b400..153e215101 100644
--- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.h
+++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.h
@@ -165,6 +165,7 @@ typedef struct {
 #define CONSOLE_IN  BIT1

 #define STD_ERROR   BIT2

 extern PLATFORM_CONSOLE_CONNECT_ENTRY  gPlatformConsole[];

+extern PLATFORM_CONSOLE_CONNECT_ENTRY  gXenPlatformConsole[];

 

 //

 // Platform BDS Functions

diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c 
b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
index 9ae590293a..ee6ee6608f 100644
--- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
+++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
@@ -399,7 +399,8 @@ PlatformBootManagerBeforeConsole (
   //

   EfiBootManagerDispatchDeferredImages ();

 

-  PlatformInitializeConsole (gPlatformConsole);

+  PlatformInitializeConsole (

+XenDetected() ? gXenPlatformConsole : gPlatformConsole);

   PcdStatus = PcdSet16S (PcdPlatformBootTimeOut,

 GetFrontPageTimeoutFromQemu ());

   ASSERT_RETURN_ERROR (PcdStatus);

diff --git a/OvmfPkg/Library/PlatformBootManagerLib/PlatformData.c 
b/OvmfPkg/Library/PlatformBootManagerLib/PlatformData.c
index 36aab784d7..a9b1fe274a 100644
--- a/OvmfPkg/Library/PlatformBootManagerLib/PlatformData.c
+++ b/OvmfPkg/Library/PlatformBootManagerLib/PlatformData.c
@@ -9,18 +9,19 @@
 

 #include "BdsPlatf

[edk2-devel] [PATCH v3 23/35] OvmfPkg/XenPlatformPei: no hvmloader: get the E820 table via hypercall

2019-07-04 Thread Anthony PERARD
When the Xen PVH entry point has been used, hvmloader hasn't run and
hasn't prepared an E820 table. The only way left to get an E820 table
is to ask Xen via an hypercall, the call can only be made once so keep
the result cached for later.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v3:
- fix commit message
- add 'm' prefix to the global variables
  and make them static

 OvmfPkg/XenPlatformPei/Xen.c | 46 +++-
 1 file changed, 45 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/XenPlatformPei/Xen.c b/OvmfPkg/XenPlatformPei/Xen.c
index 188e831c5c..cbfd8058fc 100644
--- a/OvmfPkg/XenPlatformPei/Xen.c
+++ b/OvmfPkg/XenPlatformPei/Xen.c
@@ -27,6 +27,7 @@
 #include 

 #include 

 #include 

+#include 

 

 #include "Platform.h"

 #include "Xen.h"

@@ -40,6 +41,8 @@ EFI_XEN_INFO mXenInfo;
 // Only the E820 table is used by OVMF.

 //

 EFI_XEN_OVMF_INFO *mXenHvmloaderInfo;

+STATIC EFI_E820_ENTRY64 mE820Entries[128];

+STATIC UINT32 mE820EntriesCount;

 

 /**

   Returns E820 map provided by Xen

@@ -55,6 +58,12 @@ XenGetE820Map (
   UINT32 *Count

   )

 {

+  INTN ReturnCode;

+  xen_memory_map_t Parameters;

+  UINTN LoopIndex;

+  UINTN Index;

+  EFI_E820_ENTRY64 TmpEntry;

+

   //

   // Get E820 produced by hvmloader

   //

@@ -66,7 +75,42 @@ XenGetE820Map (
 return EFI_SUCCESS;

   }

 

-  return EFI_NOT_FOUND;

+  //

+  // Otherwise, get the E820 table from the Xen hypervisor

+  //

+

+  if (mE820EntriesCount > 0) {

+*Entries = mE820Entries;

+*Count = mE820EntriesCount;

+return EFI_SUCCESS;

+  }

+

+  Parameters.nr_entries = 128;

+  set_xen_guest_handle (Parameters.buffer, mE820Entries);

+

+  // Returns a errno

+  ReturnCode = XenHypercallMemoryOp (XENMEM_memory_map, );

+  ASSERT (ReturnCode == 0);

+

+  mE820EntriesCount = Parameters.nr_entries;

+

+  //

+  // Sort E820 entries

+  //

+  for (LoopIndex = 1; LoopIndex < mE820EntriesCount; LoopIndex++) {

+for (Index = LoopIndex; Index < mE820EntriesCount; Index++) {

+  if (mE820Entries[Index - 1].BaseAddr > mE820Entries[Index].BaseAddr) {

+TmpEntry = mE820Entries[Index];

+mE820Entries[Index] = mE820Entries[Index - 1];

+mE820Entries[Index - 1] = TmpEntry;

+  }

+}

+  }

+

+  *Count = mE820EntriesCount;

+  *Entries = mE820Entries;

+

+  return EFI_SUCCESS;

 }

 

 /**

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43312): https://edk2.groups.io/g/devel/message/43312
Mute This Topic: https://groups.io/mt/32308736/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 28/35] OvmfPkg/PlatformBootManagerLib: Use XenDetected from XenPlatformLib

2019-07-04 Thread Anthony PERARD
Replace the XenDetected() implementation by the one from
XenPlatformLib.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
---

Notes:
v3:
- new patch

 .../PlatformBootManagerLib.inf|  1 +
 .../PlatformBootManagerLib/BdsPlatform.c  | 33 +--
 2 files changed, 2 insertions(+), 32 deletions(-)

diff --git a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf 
b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
index 060a3ab4c5..b2d3b4fb4d 100644
--- a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
+++ b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
@@ -54,6 +54,7 @@ [LibraryClasses]
   UefiLib

   PlatformBmPrintScLib

   Tcg2PhysicalPresenceLib

+  XenPlatformLib

 

 [Pcd]

   gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent

diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c 
b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
index 797731a41c..e32969e63e 100644
--- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
+++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
@@ -12,6 +12,7 @@
 #include 

 #include 

 #include 

+#include 

 

 

 //

@@ -1225,38 +1226,6 @@ PciAcpiInitialization (
   IoOr16 ((PciRead32 (Pmba) & ~BIT0) + 4, BIT0);

 }

 

-/**

-  This function detects if OVMF is running on Xen.

-

-**/

-STATIC

-BOOLEAN

-XenDetected (

-  VOID

-  )

-{

-  EFI_HOB_GUID_TYPE *GuidHob;

-  STATIC INTN   FoundHob = -1;

-

-  if (FoundHob == 0) {

-return FALSE;

-  } else if (FoundHob == 1) {

-return TRUE;

-  }

-

-  //

-  // See if a XenInfo HOB is available

-  //

-  GuidHob = GetFirstGuidHob ();

-  if (GuidHob == NULL) {

-FoundHob = 0;

-return FALSE;

-  }

-

-  FoundHob = 1;

-  return TRUE;

-}

-

 EFI_STATUS

 EFIAPI

 ConnectRecursivelyIfPciMassStorage (

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43302): https://edk2.groups.io/g/devel/message/43302
Mute This Topic: https://groups.io/mt/32308726/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 35/35] OvmfPkg/OvmfXen: use RealTimeClockRuntimeDxe from EmbeddedPkg

2019-07-04 Thread Anthony PERARD
A Xen PVH guest doesn't have a RTC that OVMF would expect, so
PcatRealTimeClockRuntimeDxe fails to initialize and prevent the
firmware from finish to boot. To prevent that, we will use
XenRealTimeClockLib which simply always return the same time.
This will work on both Xen PVH and HVM guests.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v3:
- moved RealTimeClockLib|*/XenRealTimeClockLib.inf to the global
  [LibraryClasses]

 OvmfPkg/OvmfXen.dsc | 3 ++-
 OvmfPkg/OvmfXen.fdf | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index af92ce3ed2..4f626fb5ef 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -199,6 +199,7 @@ [LibraryClasses]
   XenIoMmioLib|OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.inf

 

   
Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf

+  RealTimeClockLib|OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf

 

 [LibraryClasses.common]

   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf

@@ -564,7 +565,7 @@ [Components]
   }

   MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf

   MdeModulePkg/Universal/Metronome/Metronome.inf

-  PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf

+  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

   MdeModulePkg/Universal/DriverHealthManagerDxe/DriverHealthManagerDxe.inf

   MdeModulePkg/Universal/BdsDxe/BdsDxe.inf {

 

diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf
index 517a492f14..e6e9e184ef 100644
--- a/OvmfPkg/OvmfXen.fdf
+++ b/OvmfPkg/OvmfXen.fdf
@@ -307,7 +307,7 @@ [FV.DXEFV]
 INF  MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf

 INF  MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf

 INF  MdeModulePkg/Universal/Metronome/Metronome.inf

-INF  PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf

+INF  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf

 

 INF  OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf

 INF  OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43304): https://edk2.groups.io/g/devel/message/43304
Mute This Topic: https://groups.io/mt/32308728/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 25/35] OvmfPkg/XenPlatformPei: Reserve VGA memory region, to boot Linux

2019-07-04 Thread Anthony PERARD
Linux panic if the VGA region isn't reserved.

When Linux is booted on EFI system, it expects the memory at 0xa to
_not_ be conventional memory. Otherwise a variable isn't initialised
properly and Linux panic when a virtual console/terminal is asked to be
created.

See for more detail:
https://lists.xenproject.org/archives/html/xen-devel/2019-03/msg02139.html

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v3:
- fix commit message

 OvmfPkg/XenPlatformPei/Xen.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/OvmfPkg/XenPlatformPei/Xen.c b/OvmfPkg/XenPlatformPei/Xen.c
index 62a2c3ed93..9866b7c212 100644
--- a/OvmfPkg/XenPlatformPei/Xen.c
+++ b/OvmfPkg/XenPlatformPei/Xen.c
@@ -291,6 +291,12 @@ XenPublishRamRegions (
   Status = XenGetE820Map (, );

   ASSERT_EFI_ERROR (Status);

 

+  AddMemoryBaseSizeHob (0, 0xA);

+  //

+  // Video memory + Legacy BIOS region, to allow Linux to boot.

+  //

+  AddReservedMemoryBaseSizeHob (0xA, BASE_1MB - 0xA, TRUE);

+

   for (Index = 0; Index < E820EntriesCount; Index++) {

 UINT64 Base;

 UINT64 End;

@@ -304,6 +310,16 @@ XenPublishRamRegions (
 Base = ALIGN_VALUE (Entry->BaseAddr, (UINT64)EFI_PAGE_SIZE);

 End = (Entry->BaseAddr + Entry->Length) & ~(UINT64)EFI_PAGE_MASK;

 

+//

+// Ignore the first 1MB, this is handled before the loop.

+//

+if (Base < BASE_1MB) {

+  Base = BASE_1MB;

+}

+if (Base >= End) {

+  continue;

+}

+

 switch (Entry->Type) {

 case EfiAcpiAddressRangeMemory:

   AddMemoryRangeHob (Base, End);

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43309): https://edk2.groups.io/g/devel/message/43309
Mute This Topic: https://groups.io/mt/32308733/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 12/35] OvmfPkg/XenPlatformPei: Grab RSDP from PVH guest start of day struct

2019-07-04 Thread Anthony PERARD
Check if there's a start of the day struct provided to PVH guest, save
the ACPI RSDP address for later.

This patch import import arch-x86/hvm/start_info.h from xen.git.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v3:
- use SPDX
- use SIGNATURE_32
- fix coding style

 OvmfPkg/XenPlatformPei/XenPlatformPei.inf |   3 +
 OvmfPkg/Include/Guid/XenInfo.h|   4 +
 .../Xen/arch-x86/hvm/start_info.h | 143 ++
 OvmfPkg/XenPlatformPei/Xen.c  |  25 +++
 4 files changed, 175 insertions(+)
 create mode 100644 
OvmfPkg/Include/IndustryStandard/Xen/arch-x86/hvm/start_info.h

diff --git a/OvmfPkg/XenPlatformPei/XenPlatformPei.inf 
b/OvmfPkg/XenPlatformPei/XenPlatformPei.inf
index d1265c365a..4d00206d09 100644
--- a/OvmfPkg/XenPlatformPei/XenPlatformPei.inf
+++ b/OvmfPkg/XenPlatformPei/XenPlatformPei.inf
@@ -84,6 +84,9 @@ [Pcd]
   gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy

   gUefiCpuPkgTokenSpaceGuid.PcdCpuLocalApicBaseAddress

 

+  gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtr

+  gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtrSize

+

 [FixedPcd]

   gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress

 

diff --git a/OvmfPkg/Include/Guid/XenInfo.h b/OvmfPkg/Include/Guid/XenInfo.h
index b052d618fd..25743b3884 100644
--- a/OvmfPkg/Include/Guid/XenInfo.h
+++ b/OvmfPkg/Include/Guid/XenInfo.h
@@ -25,6 +25,10 @@ typedef struct {
   /// Hypervisor minor version.

   ///

   UINT16 VersionMinor;

+  ///

+  /// Pointer to the RSDP found in the hvm_start_info provided to a PVH guest

+  ///

+  VOID *RsdpPvh;

 } EFI_XEN_INFO;

 

 extern EFI_GUID gEfiXenInfoGuid;

diff --git a/OvmfPkg/Include/IndustryStandard/Xen/arch-x86/hvm/start_info.h 
b/OvmfPkg/Include/IndustryStandard/Xen/arch-x86/hvm/start_info.h
new file mode 100644
index 00..15708d6dd5
--- /dev/null
+++ b/OvmfPkg/Include/IndustryStandard/Xen/arch-x86/hvm/start_info.h
@@ -0,0 +1,143 @@
+/*

+ * SPDX-License-Identifier: MIT

+ *

+ * Copyright (c) 2016, Citrix Systems, Inc.

+ */

+

+#ifndef __XEN_PUBLIC_ARCH_X86_HVM_START_INFO_H__

+#define __XEN_PUBLIC_ARCH_X86_HVM_START_INFO_H__

+

+/*

+ * Start of day structure passed to PVH guests and to HVM guests in %ebx.

+ *

+ * NOTE: nothing will be loaded at physical address 0, so a 0 value in any

+ * of the address fields should be treated as not present.

+ *

+ *  0 ++

+ *| magic  | Contains the magic value XEN_HVM_START_MAGIC_VALUE

+ *|| ("xEn3" with the 0x80 bit of the "E" set).

+ *  4 ++

+ *| version| Version of this structure. Current version is 1. New

+ *|| versions are guaranteed to be backwards-compatible.

+ *  8 ++

+ *| flags  | SIF_xxx flags.

+ * 12 ++

+ *| nr_modules | Number of modules passed to the kernel.

+ * 16 ++

+ *| modlist_paddr  | Physical address of an array of modules

+ *|| (layout of the structure below).

+ * 24 ++

+ *| cmdline_paddr  | Physical address of the command line,

+ *|| a zero-terminated ASCII string.

+ * 32 ++

+ *| rsdp_paddr | Physical address of the RSDP ACPI data structure.

+ * 40 ++

+ *| memmap_paddr   | Physical address of the (optional) memory map. Only

+ *|| present in version 1 and newer of the structure.

+ * 48 ++

+ *| memmap_entries | Number of entries in the memory map table. Zero

+ *|| if there is no memory map being provided. Only

+ *|| present in version 1 and newer of the structure.

+ * 52 ++

+ *| reserved   | Version 1 and newer only.

+ * 56 ++

+ *

+ * The layout of each entry in the module structure is the following:

+ *

+ *  0 ++

+ *| paddr  | Physical address of the module.

+ *  8 ++

+ *| size   | Size of the module in bytes.

+ * 16 ++

+ *| cmdline_paddr  | Physical address of the command line,

+ *|| a zero-terminated ASCII string.

+ * 24 ++

+ *| reserved   |

+ * 32 ++

+ *

+ * The layout of each entry in the memory map table is as follows:

+ *

+ *  0 ++

+ *| addr   | Base address

+ *  8 ++

+ *| size   | Size of mapping in bytes

+ * 16 ++

+ *| type   | Type of mapping as defined between the hypervisor

+ *|| and guest. See XEN_HVM_MEMMAP_TYPE_* values below.

+ * 20 +|

+ *| reserved   |

+ * 24 ++

+ *

+ * The address and sizes are a

[edk2-devel] [PATCH v3 27/35] OvmfPkg/XenPlatformLib: Cache result for XenDetected

2019-07-04 Thread Anthony PERARD
We are going to replace XenDetected() implementation in
PlatformBootManagerLib by the one in XenPlatformLib.
PlatformBootManagerLib's implementation does cache the result of
GetFirstGuidHob(), so we do something similar in XenPlatformLib.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
---

Notes:
v3:
- new patch

 .../Library/XenPlatformLib/XenPlatformLib.c| 18 +++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c 
b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c
index 6f27cbffa8..b5257b0c97 100644
--- a/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c
+++ b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c
@@ -26,13 +26,25 @@ XenGetInfoHOB (
   )

 {

   EFI_HOB_GUID_TYPE  *GuidHob;

+  STATIC BOOLEAN Cached = FALSE;

+  STATIC EFI_XEN_INFO *XenInfo;

+

+  //

+  // Return the cached result for the benefit of XenDetected that can be

+  // called many times.

+  //

+  if (Cached) {

+return XenInfo;

+  }

 

   GuidHob = GetFirstGuidHob ();

   if (GuidHob == NULL) {

-return NULL;

+XenInfo = NULL;

+  } else {

+XenInfo = (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);

   }

-

-  return (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);

+  Cached = TRUE;

+  return XenInfo;

 }

 

 /**

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43303): https://edk2.groups.io/g/devel/message/43303
Mute This Topic: https://groups.io/mt/32308727/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 21/35] OvmfPkg/XenPlatformPei: Introduce XenPvhDetected

2019-07-04 Thread Anthony PERARD
XenPvhDetected() can be used to figure out if OVMF has started via the
Xen PVH entry point.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---
 OvmfPkg/XenPlatformPei/Platform.h |  5 +
 OvmfPkg/XenPlatformPei/Xen.c  | 13 +
 2 files changed, 18 insertions(+)

diff --git a/OvmfPkg/XenPlatformPei/Platform.h 
b/OvmfPkg/XenPlatformPei/Platform.h
index 4a80057bdc..db9a62572f 100644
--- a/OvmfPkg/XenPlatformPei/Platform.h
+++ b/OvmfPkg/XenPlatformPei/Platform.h
@@ -99,6 +99,11 @@ XenHvmloaderDetected (
   VOID

   );

 

+BOOLEAN

+XenPvhDetected (

+  VOID

+  );

+

 VOID

 AmdSevInitialize (

   VOID

diff --git a/OvmfPkg/XenPlatformPei/Xen.c b/OvmfPkg/XenPlatformPei/Xen.c
index 7d1696bb22..188e831c5c 100644
--- a/OvmfPkg/XenPlatformPei/Xen.c
+++ b/OvmfPkg/XenPlatformPei/Xen.c
@@ -214,6 +214,19 @@ XenHvmloaderDetected (
   return (mXenHvmloaderInfo != NULL);

 }

 

+BOOLEAN

+XenPvhDetected (

+  VOID

+  )

+{

+  //

+  // This function should only be used after XenConnect

+  //

+  ASSERT (mXenInfo.VersionMajor != 0);

+

+  return mXenHvmloaderInfo == NULL;

+}

+

 VOID

 XenPublishRamRegions (

   VOID

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43305): https://edk2.groups.io/g/devel/message/43305
Mute This Topic: https://groups.io/mt/32308729/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 16/35] OvmfPkg/XenHypercallLib: Enable it in PEIM

2019-07-04 Thread Anthony PERARD
Allow to use Xen hypercalls earlier, during the PEIM stage, but
XenHypercallLibInit() must be called once the XenInfo HOB is created
with the HyperPage setup.

Change the return value of XenHypercallLibInit so failure can be
detected when the call shouldn't fail, but still have the constructor
always succeed.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
---

Notes:
v3:
- only modify XenHypercallLib, and to the modification of XenPlatformPei
  in a separated patch.
- Allow XenHypercallLibInit to be called outside the library instead of
  creating a new function, but also return failure on failure,
  and have a new constructor that never fail.

 .../Library/XenHypercallLib/XenHypercallLib.inf  |  4 ++--
 OvmfPkg/Include/Library/XenHypercallLib.h| 12 
 .../Library/XenHypercallLib/X86XenHypercall.c|  8 +---
 OvmfPkg/Library/XenHypercallLib/XenHypercall.c   | 16 
 4 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf 
b/OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf
index 1208f0057a..21ce5b4434 100644
--- a/OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf
+++ b/OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf
@@ -12,10 +12,10 @@ [Defines]
   FILE_GUID  = B5EE9A32-CA5A-49A8-82E3-ADA4CCB77C7C

   MODULE_TYPE= BASE

   VERSION_STRING = 1.0

-  CONSTRUCTOR= XenHypercallLibInit

+  CONSTRUCTOR= XenHypercallLibConstruct

 

 [Defines.IA32, Defines.X64]

-  LIBRARY_CLASS  = XenHypercallLib|DXE_DRIVER UEFI_DRIVER

+  LIBRARY_CLASS  = XenHypercallLib|PEIM DXE_DRIVER UEFI_DRIVER

 

 [Defines.ARM, Defines.AARCH64]

   LIBRARY_CLASS  = XenHypercallLib

diff --git a/OvmfPkg/Include/Library/XenHypercallLib.h 
b/OvmfPkg/Include/Library/XenHypercallLib.h
index c43822782b..c1491dd652 100644
--- a/OvmfPkg/Include/Library/XenHypercallLib.h
+++ b/OvmfPkg/Include/Library/XenHypercallLib.h
@@ -10,6 +10,18 @@
 #ifndef __XEN_HYPERCALL_LIB_H__

 #define __XEN_HYPERCALL_LIB_H__

 

+/**

+  To call when the gEfiXenInfoGuid HOB became available after the library init

+  function has already been executed.

+

+  This allow to make hypercall in the PEIM stage.

+**/

+RETURN_STATUS

+EFIAPI

+XenHypercallLibInit (

+  VOID

+  );

+

 /**

   Check if the Xen Hypercall library is able to make calls to the Xen

   hypervisor.

diff --git a/OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c 
b/OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c
index 27083f924f..f779e46470 100644
--- a/OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c
+++ b/OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c
@@ -59,13 +59,7 @@ XenHypercallLibInit (
 

   GuidHob = GetFirstGuidHob ();

   if (GuidHob == NULL) {

-//

-// We don't fail library construction, since that has catastrophic

-// consequences for client modules (whereas those modules may easily be

-// running on a non-Xen platform). Instead, XenHypercallIsAvailable() above

-// will return FALSE.

-//

-return RETURN_SUCCESS;

+return RETURN_NOT_FOUND;

   }

   XenInfo = (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);

   HyperPage = XenInfo->HyperPages;

diff --git a/OvmfPkg/Library/XenHypercallLib/XenHypercall.c 
b/OvmfPkg/Library/XenHypercallLib/XenHypercall.c
index a2c41a2a69..d4fa802743 100644
--- a/OvmfPkg/Library/XenHypercallLib/XenHypercall.c
+++ b/OvmfPkg/Library/XenHypercallLib/XenHypercall.c
@@ -15,6 +15,22 @@
 #include 

 #include 

 

+RETURN_STATUS

+EFIAPI

+XenHypercallLibConstruct (

+  VOID

+  )

+{

+  XenHypercallLibInit ();

+  //

+  // We don't fail library construction, since that has catastrophic

+  // consequences for client modules (whereas those modules may easily be

+  // running on a non-Xen platform). Instead, XenHypercallIsAvailable()

+  // will return FALSE.

+  //

+  return RETURN_SUCCESS;

+}

+

 UINT64

 EFIAPI

 XenHypercallHvmGetParam (

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43301): https://edk2.groups.io/g/devel/message/43301
Mute This Topic: https://groups.io/mt/32308725/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 11/35] OvmfPkg/XenPlatformPei: Use mXenHvmloaderInfo to get E820

2019-07-04 Thread Anthony PERARD
Use the already checked pointer mXenHvmloaderInfo to retrieve the E820
table produced by hvmloader.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---
 OvmfPkg/XenPlatformPei/Xen.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/OvmfPkg/XenPlatformPei/Xen.c b/OvmfPkg/XenPlatformPei/Xen.c
index d6361da306..9c2ff6324d 100644
--- a/OvmfPkg/XenPlatformPei/Xen.c
+++ b/OvmfPkg/XenPlatformPei/Xen.c
@@ -53,18 +53,18 @@ XenGetE820Map (
   UINT32 *Count

   )

 {

-  EFI_XEN_OVMF_INFO *Info =

-(EFI_XEN_OVMF_INFO *)(UINTN) OVMF_INFO_PHYSICAL_ADDRESS;

+  //

+  // Get E820 produced by hvmloader

+  //

+  if (mXenHvmloaderInfo != NULL) {

+ASSERT (mXenHvmloaderInfo->E820 < MAX_ADDRESS);

+*Entries = (EFI_E820_ENTRY64 *)(UINTN) mXenHvmloaderInfo->E820;

+*Count = mXenHvmloaderInfo->E820EntriesCount;

 

-  if (AsciiStrCmp ((CHAR8 *) Info->Signature, "XenHVMOVMF")) {

-return EFI_NOT_FOUND;

+return EFI_SUCCESS;

   }

 

-  ASSERT (Info->E820 < MAX_ADDRESS);

-  *Entries = (EFI_E820_ENTRY64 *)(UINTN) Info->E820;

-  *Count = Info->E820EntriesCount;

-

-  return EFI_SUCCESS;

+  return EFI_NOT_FOUND;

 }

 

 /**

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43298): https://edk2.groups.io/g/devel/message/43298
Mute This Topic: https://groups.io/mt/32308722/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 34/35] OvmfPkg: Move XenRealTimeClockLib from ArmVirtPkg

2019-07-04 Thread Anthony PERARD
Move XenRealTimeClockLib from ArmVirtPkg to OvmfPkg so it can be used
from the OvmfPkg by the following patch, "OvmfPkg/OvmfXen: use
RealTimeClockRuntimeDxe from EmbeddedPkg"

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Reviewed-by: Laszlo Ersek 
---

Notes:
v3:
- fix the commit message body

 ArmVirtPkg/ArmVirtXen.dsc   | 2 +-
 .../Library/XenRealTimeClockLib/XenRealTimeClockLib.inf | 0
 .../Library/XenRealTimeClockLib/XenRealTimeClockLib.c   | 0
 3 files changed, 1 insertion(+), 1 deletion(-)
 rename {ArmVirtPkg => 
OvmfPkg}/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf (100%)
 rename {ArmVirtPkg => 
OvmfPkg}/Library/XenRealTimeClockLib/XenRealTimeClockLib.c (100%)

diff --git a/ArmVirtPkg/ArmVirtXen.dsc b/ArmVirtPkg/ArmVirtXen.dsc
index 79304ee61d..1b42a9a813 100644
--- a/ArmVirtPkg/ArmVirtXen.dsc
+++ b/ArmVirtPkg/ArmVirtXen.dsc
@@ -27,7 +27,7 @@ [Defines]
 

 [LibraryClasses]

   
SerialPortLib|OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf

-  
RealTimeClockLib|ArmVirtPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf

+  RealTimeClockLib|OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf

   XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf

 

   
ArmGenericTimerCounterLib|ArmVirtPkg/Library/XenArmGenericTimerVirtCounterLib/XenArmGenericTimerVirtCounterLib.inf

diff --git a/ArmVirtPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf 
b/OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf
similarity index 100%
rename from ArmVirtPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf
rename to OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf
diff --git a/ArmVirtPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.c 
b/OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.c
similarity index 100%
rename from ArmVirtPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.c
rename to OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.c
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43294): https://edk2.groups.io/g/devel/message/43294
Mute This Topic: https://groups.io/mt/32308716/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 20/35] OvmfPkg/XenPlatformPei: Setup HyperPages earlier

2019-07-04 Thread Anthony PERARD
We are going to need to make an hypercall in order to retreive the E820
table from the hypervisor before been able to setup the memory.

Calling XenConnect earlier will allow to setup the XenHypercallLib
earlier to allow to make hypercalls.

While here, add some comments in XenConnect().

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---
 OvmfPkg/XenPlatformPei/Platform.h |  5 +
 OvmfPkg/XenPlatformPei/Platform.c |  2 ++
 OvmfPkg/XenPlatformPei/Xen.c  | 23 ---
 3 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/OvmfPkg/XenPlatformPei/Platform.h 
b/OvmfPkg/XenPlatformPei/Platform.h
index 925df31f88..4a80057bdc 100644
--- a/OvmfPkg/XenPlatformPei/Platform.h
+++ b/OvmfPkg/XenPlatformPei/Platform.h
@@ -79,6 +79,11 @@ InstallClearCacheCallback (
   VOID

   );

 

+EFI_STATUS

+XenConnect (

+  VOID

+  );

+

 EFI_STATUS

 InitializeXen (

   VOID

diff --git a/OvmfPkg/XenPlatformPei/Platform.c 
b/OvmfPkg/XenPlatformPei/Platform.c
index c97a2fb6c1..52f6048ca4 100644
--- a/OvmfPkg/XenPlatformPei/Platform.c
+++ b/OvmfPkg/XenPlatformPei/Platform.c
@@ -416,6 +416,8 @@ InitializeXenPlatform (
 CpuDeadLoop ();

   }

 

+  XenConnect ();

+

   BootModeInitialization ();

   AddressWidthInitialization ();

 

diff --git a/OvmfPkg/XenPlatformPei/Xen.c b/OvmfPkg/XenPlatformPei/Xen.c
index 37e9cff4b4..7d1696bb22 100644
--- a/OvmfPkg/XenPlatformPei/Xen.c
+++ b/OvmfPkg/XenPlatformPei/Xen.c
@@ -72,14 +72,11 @@ XenGetE820Map (
 /**

   Connects to the Hypervisor.

  

-  @param  XenLeaf CPUID index used to connect.

-

   @return EFI_STATUS

 

 **/

 EFI_STATUS

 XenConnect (

-  UINT32 XenLeaf

   )

 {

   UINT32 Index;

@@ -91,7 +88,13 @@ XenConnect (
   UINT32 *PVHResetVectorData;

   RETURN_STATUS Status;

 

-  AsmCpuid (XenLeaf + 2, , , NULL, NULL);

+  ASSERT (mXenLeaf != 0);

+

+  //

+  // Prepare HyperPages to be able to make hypercalls

+  //

+

+  AsmCpuid (mXenLeaf + 2, , , NULL, NULL);

   mXenInfo.HyperPages = AllocatePages (TransferPages);

   if (!mXenInfo.HyperPages) {

 return EFI_OUT_OF_RESOURCES;

@@ -103,7 +106,11 @@ XenConnect (
(Index << EFI_PAGE_SHIFT) + Index);

   }

 

-  AsmCpuid (XenLeaf + 1, , NULL, NULL, NULL);

+  //

+  // Find out the Xen version

+  //

+

+  AsmCpuid (mXenLeaf + 1, , NULL, NULL, NULL);

   DEBUG ((EFI_D_ERROR, "Detected Xen version %d.%d\n",

   XenVersion >> 16, XenVersion & 0x));

   mXenInfo.VersionMajor = (UINT16)(XenVersion >> 16);

@@ -262,12 +269,6 @@ InitializeXen (
 {

   RETURN_STATUS PcdStatus;

 

-  if (mXenLeaf == 0) {

-return EFI_NOT_FOUND;

-  }

-

-  XenConnect (mXenLeaf);

-

   //

   // Reserve away HVMLOADER reserved memory [0xFC00,0xFD00).

   // This needs to match HVMLOADER RESERVED_MEMBASE/RESERVED_MEMSIZE.

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43291): https://edk2.groups.io/g/devel/message/43291
Mute This Topic: https://groups.io/mt/32308711/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 10/35] OvmfPkg/XenPlatformPei: Detect OVMF_INFO from hvmloader

2019-07-04 Thread Anthony PERARD
EFI_XEN_OVMF_INFO is only useful to retrieve the E820 table. The
mXenHvmloaderInfo isn't used yet, but will be use in a further patch to
retrieve the E820 table.

Also remove the unused pointer from the XenInfo HOB as that information
is only useful in the XenPlatformPei.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v3:
- fix coding style
- fix commit message

 OvmfPkg/Include/Guid/XenInfo.h |  4 
 OvmfPkg/PlatformPei/Xen.c  |  3 ---
 OvmfPkg/XenPlatformPei/Xen.c   | 25 +++--
 3 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/OvmfPkg/Include/Guid/XenInfo.h b/OvmfPkg/Include/Guid/XenInfo.h
index 25d76a7828..b052d618fd 100644
--- a/OvmfPkg/Include/Guid/XenInfo.h
+++ b/OvmfPkg/Include/Guid/XenInfo.h
@@ -18,10 +18,6 @@ typedef struct {
   ///

   VOID *HyperPages;

   ///

-  /// Location of the hvm_info page.

-  ///

-  VOID *HvmInfo;

-  ///

   /// Hypervisor major version.

   ///

   UINT16 VersionMajor;

diff --git a/OvmfPkg/PlatformPei/Xen.c b/OvmfPkg/PlatformPei/Xen.c
index 89dc4143b2..3e15b32a73 100644
--- a/OvmfPkg/PlatformPei/Xen.c
+++ b/OvmfPkg/PlatformPei/Xen.c
@@ -98,9 +98,6 @@ XenConnect (
   mXenInfo.VersionMajor = (UINT16)(XenVersion >> 16);

   mXenInfo.VersionMinor = (UINT16)(XenVersion & 0x);

 

-  /* TBD: Locate hvm_info and reserve it away. */

-  mXenInfo.HvmInfo = NULL;

-

   BuildGuidDataHob (

 ,

 ,

diff --git a/OvmfPkg/XenPlatformPei/Xen.c b/OvmfPkg/XenPlatformPei/Xen.c
index 81042ab94f..d6361da306 100644
--- a/OvmfPkg/XenPlatformPei/Xen.c
+++ b/OvmfPkg/XenPlatformPei/Xen.c
@@ -33,6 +33,12 @@ STATIC UINT32 mXenLeaf = 0;
 

 EFI_XEN_INFO mXenInfo;

 

+//

+// Location of the firmware info struct setup by hvmloader.

+// Only the E820 table is used by OVMF.

+//

+EFI_XEN_OVMF_INFO *mXenHvmloaderInfo;

+

 /**

   Returns E820 map provided by Xen

 

@@ -78,6 +84,8 @@ XenConnect (
   UINT32 TransferReg;

   UINT32 TransferPages;

   UINT32 XenVersion;

+  EFI_XEN_OVMF_INFO *Info;

+  CHAR8 Sig[sizeof (Info->Signature) + 1];

 

   AsmCpuid (XenLeaf + 2, , , NULL, NULL);

   mXenInfo.HyperPages = AllocatePages (TransferPages);

@@ -97,8 +105,21 @@ XenConnect (
   mXenInfo.VersionMajor = (UINT16)(XenVersion >> 16);

   mXenInfo.VersionMinor = (UINT16)(XenVersion & 0x);

 

-  /* TBD: Locate hvm_info and reserve it away. */

-  mXenInfo.HvmInfo = NULL;

+  //

+  // Check if there are information left by hvmloader

+  //

+

+  Info = (EFI_XEN_OVMF_INFO *)(UINTN) OVMF_INFO_PHYSICAL_ADDRESS;

+  //

+  // Copy the signature, and make it null-terminated.

+  //

+  AsciiStrnCpyS (Sig, sizeof (Sig), (CHAR8 *) >Signature,

+sizeof (Info->Signature));

+  if (AsciiStrCmp (Sig, "XenHVMOVMF") == 0) {

+mXenHvmloaderInfo = Info;

+  } else {

+mXenHvmloaderInfo = NULL;

+  }

 

   BuildGuidDataHob (

 ,

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43297): https://edk2.groups.io/g/devel/message/43297
Mute This Topic: https://groups.io/mt/32308719/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v3 22/35] OvmfPkg: Import XENMEM_memory_map hypercall to Xen/memory.h

2019-07-04 Thread Anthony PERARD
The informations to make a XENMEM_memory_map hypercall is copied over
from the public header of the Xen Project, with the type name modified
to build on OVMF.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v3:
- expanded the "This" that was starting the commit message body.

 OvmfPkg/Include/IndustryStandard/Xen/memory.h | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/OvmfPkg/Include/IndustryStandard/Xen/memory.h 
b/OvmfPkg/Include/IndustryStandard/Xen/memory.h
index 81e981331a..4a33a26d4e 100644
--- a/OvmfPkg/Include/IndustryStandard/Xen/memory.h
+++ b/OvmfPkg/Include/IndustryStandard/Xen/memory.h
@@ -65,6 +65,29 @@ struct xen_remove_from_physmap {
 typedef struct xen_remove_from_physmap xen_remove_from_physmap_t;

 DEFINE_XEN_GUEST_HANDLE(xen_remove_from_physmap_t);

 

+/*

+ * Returns the pseudo-physical memory map as it was when the domain

+ * was started (specified by XENMEM_set_memory_map).

+ * arg == addr of xen_memory_map_t.

+ */

+#define XENMEM_memory_map   9

+struct xen_memory_map {

+/*

+ * On call the number of entries which can be stored in buffer. On

+ * return the number of entries which have been stored in

+ * buffer.

+ */

+UINT32 nr_entries;

+

+/*

+ * Entries in the buffer are in the same format as returned by the

+ * BIOS INT 0x15 EAX=0xE820 call.

+ */

+XEN_GUEST_HANDLE(void) buffer;

+};

+typedef struct xen_memory_map xen_memory_map_t;

+DEFINE_XEN_GUEST_HANDLE(xen_memory_map_t);

+

 #endif /* __XEN_PUBLIC_MEMORY_H__ */

 

 /*

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43313): https://edk2.groups.io/g/devel/message/43313
Mute This Topic: https://groups.io/mt/32308738/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v2] OvmfPkg/XenBusDxe: Close XenIoProtocol openned by children

2019-07-01 Thread Anthony PERARD
In XenBusDxe, the XenBusAddDevice() opens the gXenIoProtocolGuid on
behalf of child controllers. It is never closed and prevents us from
uninstalling the protocol.

Close it where we stop all the children in XenBusDxe->Stop().

Signed-off-by: Anthony PERARD 
Reviewed-by: Laszlo Ersek 
---
 OvmfPkg/XenBusDxe/XenBusDxe.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.c b/OvmfPkg/XenBusDxe/XenBusDxe.c
index 0e63707f50..7c07a96650 100644
--- a/OvmfPkg/XenBusDxe/XenBusDxe.c
+++ b/OvmfPkg/XenBusDxe/XenBusDxe.c
@@ -453,6 +453,10 @@ XenBusDxeDriverBindingStop (
   continue;

 }

 

+Status = gBS->CloseProtocol (Dev->ControllerHandle, ,

+Dev->This->DriverBindingHandle, ChildData->Handle);

+ASSERT_EFI_ERROR (Status);

+

 Status = gBS->UninstallMultipleProtocolInterfaces (

ChildData->Handle,

, ChildData->DevicePath,

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43115): https://edk2.groups.io/g/devel/message/43115
Mute This Topic: https://groups.io/mt/32270096/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH] OvmfPkg/XenBusDxe: Close XenIoProtocol openned by childs

2019-07-01 Thread Anthony PERARD
On Sun, Jun 30, 2019 at 12:56:57PM +0200, Laszlo Ersek wrote:
> (5) Side remark (no need to do anything about it in the scope of this
> patch): I think the DisconnectController() call in
> XenBusDxeDriverBindingStop() is superfluous. That kind of disconnection
> is not the job of EFI_DRIVER_BINDING_PROTOCOL.Stop().

That sounds good and works fine without the call, I'll send a separate
patch.

-- 
Anthony PERARD

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43114): https://edk2.groups.io/g/devel/message/43114
Mute This Topic: https://groups.io/mt/32243460/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH] OvmfPkg/XenBusDxe: Don't call DisconnectController in Stop()

2019-07-01 Thread Anthony PERARD
Calling DisconnectController() on children isn't part of the job of
EFI_DRIVER_BINDING_PROTOCOL.Stop() as it only needs to deallocate
resources allocated in Start(). The disconnection will happen when
both DevicePath and XenBus protocols gets uninstalled.

Reported-by: Laszlo Ersek 
Signed-off-by: Anthony PERARD 
---

Notes:
Please apply this patch after:
"OvmfPkg/XenBusDxe: Close XenIoProtocol openned by children"

 OvmfPkg/XenBusDxe/XenBusDxe.c | 6 --
 1 file changed, 6 deletions(-)

diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.c b/OvmfPkg/XenBusDxe/XenBusDxe.c
index 7c07a96650..634c7b71eb 100644
--- a/OvmfPkg/XenBusDxe/XenBusDxe.c
+++ b/OvmfPkg/XenBusDxe/XenBusDxe.c
@@ -446,12 +446,6 @@ XenBusDxeDriverBindingStop (
   continue;

 }

 ChildData = XENBUS_PRIVATE_DATA_FROM_THIS (XenBusIo);

-Status = gBS->DisconnectController (ChildData->Handle, NULL, NULL);

-if (EFI_ERROR (Status)) {

-  DEBUG ((EFI_D_ERROR, "XenBusDxe: error disconnecting child: %r\n",

-  Status));

-  continue;

-}

 

 Status = gBS->CloseProtocol (Dev->ControllerHandle, ,

 Dev->This->DriverBindingHandle, ChildData->Handle);

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43119): https://edk2.groups.io/g/devel/message/43119
Mute This Topic: https://groups.io/mt/32270256/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v4 29/35] OvmfPkg/OvmfXen: Override PcdFSBClock to Xen vLAPIC timer frequency

2019-08-12 Thread Anthony PERARD
On Thu, Aug 08, 2019 at 05:18:15PM +0200, Roger Pau Monné wrote:
> On Thu, Aug 08, 2019 at 03:26:41PM +0100, Anthony PERARD wrote:
> > So EDKII doesn't have that capability, FSBClock is a build time value
> > and can't be changed at run time. But OVMF (on KVM or HVM) doesn't use
> > that value at all, it uses the ACPI timer instead.
> 
> But after your series both PVH and HVM will use the lapic timer
> instead of the ACPI timer, and thus rely on the value of FSBClock?

Short answer, Yes.

Longuer answer, after the series is applied, there will be a new
platform, "OvmfXen" which will be for both Xen PVH and Xen HVM, but the
OVMF that we know (OvmfPkgX64 that xen.git builds) will still be
capable of running on Xen HVM for a short while and will still use the
ACPI timer.

-- 
Anthony PERARD

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45454): https://edk2.groups.io/g/devel/message/45454
Mute This Topic: https://groups.io/mt/32644083/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v4 00/35] Specific platform to run OVMF in Xen PVH and HVM guests

2019-08-12 Thread Anthony PERARD
On Tue, Jul 30, 2019 at 03:10:13PM +0200, Laszlo Ersek wrote:
> Hi Anthony,
> 
> On 07/29/19 17:39, Anthony PERARD wrote:
> > Patch series available in this git branch:
> > https://xenbits.xen.org/git-http/people/aperard/ovmf.git 
> > br.platform-xen-pvh-v4
> > 
> > Changes in v4:
> > - patch "OvmfPkg/XenPlatformPei: Reserve hvmloader's memory only when it has
> >   run" was removed, and instead a different change is done in
> >   "OvmfPkg/XenPlatformPei: Rework memory detection"
> > - other changes detailed in the notes of each patch
> 
> I've gone through the v4 series. If reviewers on the xen-devel list
> think v4 is okay to merge, I can do that (with the small fixups I
> offered here and there). I suggest that we wait a few days -- please
> ping me when you believe the review on xen-devel has concluded.
> 
> If you prefer to post v5, that works as well of course.

There's a few more small fixup proposed by Roger, should I post a v5 for
them? (and maybe only CC you and the lists.)

Otherwise, I've pushed the branch br.platform-xen-pvh-v4.1 to my repo [1]
where I believe I've collected all the small fixups.
[1] https://xenbits.xen.org/git-http/people/aperard/ovmf.git  
br.platform-xen-pvh-v4.1

Thanks,

-- 
Anthony PERARD

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45456): https://edk2.groups.io/g/devel/message/45456
Mute This Topic: https://groups.io/mt/32643834/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v5 02/35] OvmfPkg: Create platform OvmfXen

2019-08-13 Thread Anthony PERARD
OvmfXen is a copy of OvmfX64, removing VirtIO and some SMM.

This new platform will be changed to make it works on two types of Xen
guest: HVM and PVH.

Compare to OvmfX64, this patch:

- changed: PLATFORM_GUID, OUTPUT_DIRECTORY, FLASH_DEFINITION
- removed: VirtioLib class resolution
- removed: all UEFI_DRIVER modules for virtio devices
- removed: DXE_SMM_DRIVER and SMM_CORE lib class resolutions
- removed: DXE_SMM_DRIVER and SMM_CORE FDF rules
- removed: Everything related to SMM_REQUIRE==true
- removed: Everything related to SECURE_BOOT_ENABLE==true
- removed: Everything related to TPM2_ENABLE==true
- changed: PcdPciDisableBusEnumeration dynamic default flipped to TRUE
- changed: default FD_SIZE_IN_KB to 2M.
- reverted d272449d9e1e, "OvmfPkg: raise DXEFV size to 11 MB"

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Reviewed-by: Laszlo Ersek 
---

Notes:
v4:
- rebased
- Update Maintainers.txt

v3:
- rebased, SPDX + 8259/8254 changes

 OvmfPkg/OvmfXen.dsc | 729 
 OvmfPkg/OvmfXen.fdf | 439 ++
 Maintainers.txt |   1 +
 3 files changed, 1169 insertions(+)
 create mode 100644 OvmfPkg/OvmfXen.dsc
 create mode 100644 OvmfPkg/OvmfXen.fdf

diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
new file mode 100644
index 00..f224ac32b4
--- /dev/null
+++ b/OvmfPkg/OvmfXen.dsc
@@ -0,0 +1,729 @@
+## @file
+#  EFI/Framework Open Virtual Machine Firmware (OVMF) platform
+#
+#  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
+#  (C) Copyright 2016 Hewlett Packard Enterprise Development LP
+#  Copyright (c) 2019, Citrix Systems, Inc.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+
+#
+# Defines Section - statements that will be processed to create a Makefile.
+#
+
+[Defines]
+  PLATFORM_NAME  = Ovmf
+  PLATFORM_GUID  = e3aa4fbe-9459-482d-bd40-d3f3b5f89d6e
+  PLATFORM_VERSION   = 0.1
+  DSC_SPECIFICATION  = 0x00010005
+  OUTPUT_DIRECTORY   = Build/OvmfXen
+  SUPPORTED_ARCHITECTURES= X64
+  BUILD_TARGETS  = NOOPT|DEBUG|RELEASE
+  SKUID_IDENTIFIER   = DEFAULT
+  FLASH_DEFINITION   = OvmfPkg/OvmfXen.fdf
+
+  #
+  # Defines for default states.  These can be changed on the command line.
+  # -D FLAG=VALUE
+  #
+
+  #
+  # Network definition
+  #
+  DEFINE NETWORK_TLS_ENABLE = FALSE
+  DEFINE NETWORK_IP6_ENABLE = FALSE
+  DEFINE NETWORK_HTTP_BOOT_ENABLE   = FALSE
+  DEFINE NETWORK_ALLOW_HTTP_CONNECTIONS = TRUE
+
+!include NetworkPkg/NetworkDefines.dsc.inc
+
+  #
+  # Flash size selection. Setting FD_SIZE_IN_KB on the command line directly to
+  # one of the supported values, in place of any of the convenience macros, is
+  # permitted.
+  #
+!ifdef $(FD_SIZE_1MB)
+  DEFINE FD_SIZE_IN_KB   = 1024
+!else
+!ifdef $(FD_SIZE_2MB)
+  DEFINE FD_SIZE_IN_KB   = 2048
+!else
+!ifdef $(FD_SIZE_4MB)
+  DEFINE FD_SIZE_IN_KB   = 4096
+!else
+  DEFINE FD_SIZE_IN_KB   = 2048
+!endif
+!endif
+!endif
+
+[BuildOptions]
+  GCC:RELEASE_*_*_CC_FLAGS = -DMDEPKG_NDEBUG
+  INTEL:RELEASE_*_*_CC_FLAGS   = /D MDEPKG_NDEBUG
+  MSFT:RELEASE_*_*_CC_FLAGS= /D MDEPKG_NDEBUG
+!if $(TOOL_CHAIN_TAG) != "XCODE5"
+  GCC:*_*_*_CC_FLAGS   = -mno-mmx -mno-sse
+!endif
+!ifdef $(SOURCE_DEBUG_ENABLE)
+  MSFT:*_*_X64_GENFW_FLAGS  = --keepexceptiontable
+  GCC:*_*_X64_GENFW_FLAGS   = --keepexceptiontable
+  INTEL:*_*_X64_GENFW_FLAGS = --keepexceptiontable
+!endif
+
+  #
+  # Disable deprecated APIs.
+  #
+  MSFT:*_*_*_CC_FLAGS = /D DISABLE_NEW_DEPRECATED_INTERFACES
+  INTEL:*_*_*_CC_FLAGS = /D DISABLE_NEW_DEPRECATED_INTERFACES
+  GCC:*_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES
+
+[BuildOptions.common.EDKII.DXE_RUNTIME_DRIVER]
+  GCC:*_*_*_DLINK_FLAGS = -z common-page-size=0x1000
+  XCODE:*_*_*_DLINK_FLAGS =
+
+# Force PE/COFF sections to be aligned at 4KB boundaries to support page level
+# protection of DXE_SMM_DRIVER/SMM_CORE modules
+[BuildOptions.common.EDKII.DXE_SMM_DRIVER, BuildOptions.common.EDKII.SMM_CORE]
+  GCC:*_*_*_DLINK_FLAGS = -z common-page-size=0x1000
+  XCODE:*_*_*_DLINK_FLAGS =
+
+
+#
+# SKU Identification section - list of all SKU IDs supported by this Platform.
+#
+
+[SkuIds]
+  0|DEFAULT
+
+
+#
+# Library Class section - list of all Library Classes nee

[edk2-devel] [PATCH v5 04/35] OvmfPkg: Introduce XenPlatformPei

2019-08-13 Thread Anthony PERARD
Introduce XenPlatformPei, a copy of OvmfPkg/PlatformPei without some
of QEMU specific initialization, Xen does not support QemuFwCfg.

This new module will be adjusted to accommodate Xen PVH.

fw_cfg dependents that have been removed, which are dynamically skipped
when running PlatformPei on Xen:
- GetFirstNonAddress(): controlling the 64-bit PCI MMIO aperture via the
(experimental) "opt/ovmf/X-PciMmio64Mb" file
- GetFirstNonAddress(): honoring the hotplug DIMM area
("etc/reserved-memory-end") in the placement of the 64-bit PCI MMIO
aperture
- NoexecDxeInitialization() is removed, so PcdPropertiesTableEnable and
PcdSetNxForStack are left constant FALSE (not set dynamically from
fw_cfg "opt/ovmf/PcdXxxx")
- MaxCpuCountInitialization(), PublishPeiMemory(): the max CPU count is
not taken from the QemuFwCfgItemSmpCpuCount fw_cfg key;
PcdCpuMaxLogicalProcessorNumber is used intact and
PcdCpuApInitTimeOutInMicroSeconds is never changed or used.
- InitializeXenPlatform(), S3Verification(): S3 is assumed disabled (not
consulting "etc/system-states" via QemuFwCfgS3Enabled()).
- InstallFeatureControlCallback(): the feature control MSR is not set
from "etc/msr_feature_control"
(also removed FeatureControl.c as there is nothing been executed)

Also removed:
- SMRAM/TSEG-related low mem size adjusting (PcdSmmSmramRequire is
assumed FALSE) in PublishPeiMemory(),
- QemuInitializeRam() entirely,

Xen related changes:
- Have removed the module variable mXen, as it should be always true.
- Have the platform PEI initialization fails if Xen has not been
  detected.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Reviewed-by: Laszlo Ersek 
---

Notes:
v4:
  - replace the other EFI_D_ by DEBUG_.
  - Update Maintainers.txt
  - fix one trailing whitespace

v3:
  - fix coding style in new code
(use DEBUG_xxx, add ASSERT before CpuDeadLoop)
  - rebased, SPDX

 OvmfPkg/OvmfXen.dsc   |   2 +-
 OvmfPkg/OvmfXen.fdf   |   2 +-
 OvmfPkg/XenPlatformPei/XenPlatformPei.inf |  96 +
 OvmfPkg/XenPlatformPei/Cmos.h |  52 +++
 OvmfPkg/XenPlatformPei/Platform.h | 108 ++
 OvmfPkg/XenPlatformPei/Xen.h  |  39 ++
 OvmfPkg/XenPlatformPei/AmdSev.c   |  64 
 OvmfPkg/XenPlatformPei/ClearCache.c   | 112 ++
 OvmfPkg/XenPlatformPei/Cmos.c |  60 +++
 OvmfPkg/XenPlatformPei/Fv.c   |  76 
 OvmfPkg/XenPlatformPei/MemDetect.c| 421 
 OvmfPkg/XenPlatformPei/Platform.c | 444 ++
 OvmfPkg/XenPlatformPei/Xen.c  | 219 +++
 Maintainers.txt   |   1 +
 14 files changed, 1694 insertions(+), 2 deletions(-)
 create mode 100644 OvmfPkg/XenPlatformPei/XenPlatformPei.inf
 create mode 100644 OvmfPkg/XenPlatformPei/Cmos.h
 create mode 100644 OvmfPkg/XenPlatformPei/Platform.h
 create mode 100644 OvmfPkg/XenPlatformPei/Xen.h
 create mode 100644 OvmfPkg/XenPlatformPei/AmdSev.c
 create mode 100644 OvmfPkg/XenPlatformPei/ClearCache.c
 create mode 100644 OvmfPkg/XenPlatformPei/Cmos.c
 create mode 100644 OvmfPkg/XenPlatformPei/Fv.c
 create mode 100644 OvmfPkg/XenPlatformPei/MemDetect.c
 create mode 100644 OvmfPkg/XenPlatformPei/Platform.c
 create mode 100644 OvmfPkg/XenPlatformPei/Xen.c

diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index 1a0e59f0cc..7619a89382 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -523,7 +523,7 @@ [Components]
   }
   MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
 
-  OvmfPkg/PlatformPei/PlatformPei.inf
+  OvmfPkg/XenPlatformPei/XenPlatformPei.inf
   UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf
   UefiCpuPkg/CpuMpPei/CpuMpPei.inf
 
diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf
index 6fc8479aae..2ceff7baa2 100644
--- a/OvmfPkg/OvmfXen.fdf
+++ b/OvmfPkg/OvmfXen.fdf
@@ -152,7 +152,7 @@ [FV.PEIFV]
 INF  MdeModulePkg/Universal/PCD/Pei/Pcd.inf
 INF  
MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf
 INF  MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf
-INF  OvmfPkg/PlatformPei/PlatformPei.inf
+INF  OvmfPkg/XenPlatformPei/XenPlatformPei.inf
 INF  MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
 INF  UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf
 INF  UefiCpuPkg/CpuMpPei/CpuMpPei.inf
diff --git a/OvmfPkg/XenPlatformPei/XenPlatformPei.inf 
b/OvmfPkg/XenPlatformPei/XenPlatformPei.inf
new file mode 100644
index 00..d1265c365a
--- /dev/null
+++ b/OvmfPkg/XenPlatformPei/XenPlatformPei.inf
@@ -0,0 +1,96 @@
+## @file
+#  Platform PEI driver
+#
+#  This module provides platform specific function to detect boot mode.
+#  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
+#  Copyright (c) 2019, Citrix Systems, Inc.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VE

[edk2-devel] [PATCH v5 08/35] OvmfPkg/XenResetVector: Allow jumpstart from either hvmloader or PVH

2019-08-13 Thread Anthony PERARD
This patch allows the ResetVector to be run indenpendently from build
time addresses.

The goal of the patch is to avoid having to create RAM just below 4G
when creating a Xen PVH guest while being compatible with the way
hvmloader currently load OVMF, just below 4G.

Only the new PVH entry point will do the calculation.

The ResetVector will figure out its current running address by creating
a temporary stack, make a call and calculate the difference between the
build time address and the address at run time.

This patch copies and make the necessary modification to some other asm
files:
- copy of UefiCpuPkg/.../Flat32ToFlat64.asm:
  Allow Transition32FlatTo64Flat to be run from anywhere in memory
- copy of UefiCpuPkg/../SearchForBfvBase.asm:
  Add a extra parameter to indicate where to start the search for the
  boot firmware volume.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v3:
- rebased, SPDX
- fix commit message

 .../XenResetVector/Ia16/Real16ToFlat32.asm|  3 +
 .../XenResetVector/Ia32/Flat32ToFlat64.asm| 68 +++
 .../XenResetVector/Ia32/SearchForBfvBase.asm  | 87 +++
 OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm| 43 +++--
 4 files changed, 194 insertions(+), 7 deletions(-)
 create mode 100644 OvmfPkg/XenResetVector/Ia32/Flat32ToFlat64.asm
 create mode 100644 OvmfPkg/XenResetVector/Ia32/SearchForBfvBase.asm

diff --git a/OvmfPkg/XenResetVector/Ia16/Real16ToFlat32.asm 
b/OvmfPkg/XenResetVector/Ia16/Real16ToFlat32.asm
index 5c329bfaea..36ea74f7fe 100644
--- a/OvmfPkg/XenResetVector/Ia16/Real16ToFlat32.asm
+++ b/OvmfPkg/XenResetVector/Ia16/Real16ToFlat32.asm
@@ -54,6 +54,9 @@ jumpTo32BitAndLandHere:
 mov gs, ax
 mov ss, ax
 
+; parameter for Flat32SearchForBfvBase
+xor eax, eax ; Start searching from top of 4GB for BfvBase
+
 OneTimeCallRet TransitionFromReal16To32BitFlat
 
 ALIGN   2
diff --git a/OvmfPkg/XenResetVector/Ia32/Flat32ToFlat64.asm 
b/OvmfPkg/XenResetVector/Ia32/Flat32ToFlat64.asm
new file mode 100644
index 00..661a8e7028
--- /dev/null
+++ b/OvmfPkg/XenResetVector/Ia32/Flat32ToFlat64.asm
@@ -0,0 +1,68 @@
+;--
+; @file
+; Transition from 32 bit flat protected mode into 64 bit flat protected mode
+;
+; Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.
+; Copyright (c) 2019, Citrix Systems, Inc.
+;
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;
+;--
+
+BITS32
+
+;
+; Modified:  EAX, EBX, ECX, EDX, ESP
+;
+Transition32FlatTo64Flat:
+
+OneTimeCall SetCr3ForPageTables64
+
+mov eax, cr4
+bts eax, 5  ; enable PAE
+mov cr4, eax
+
+mov ecx, 0xc080
+rdmsr
+bts eax, 8  ; set LME
+wrmsr
+
+mov eax, cr0
+bts eax, 31 ; set PG
+mov cr0, eax; enable paging
+
+;
+; backup ESP
+;
+mov ebx, esp
+
+;
+; recalculate delta
+;
+mov esp, PVH_SPACE(16)
+call.delta
+.delta:
+pop edx
+sub edx, ADDR_OF(.delta)
+
+;
+; push return addr and seg to the stack, then return far
+;
+pushdword LINEAR_CODE64_SEL
+mov eax, ADDR_OF(jumpTo64BitAndLandHere)
+add eax, edx ; add delta
+pusheax
+retf
+
+BITS64
+jumpTo64BitAndLandHere:
+
+;
+; restore ESP
+;
+mov esp, ebx
+
+debugShowPostCode POSTCODE_64BIT_MODE
+
+OneTimeCallRet Transition32FlatTo64Flat
+
diff --git a/OvmfPkg/XenResetVector/Ia32/SearchForBfvBase.asm 
b/OvmfPkg/XenResetVector/Ia32/SearchForBfvBase.asm
new file mode 100644
index 00..190389c46f
--- /dev/null
+++ b/OvmfPkg/XenResetVector/Ia32/SearchForBfvBase.asm
@@ -0,0 +1,87 @@
+;--
+; @file
+; Search for the Boot Firmware Volume (BFV) base address
+;
+; Copyright (c) 2008 - 2009, Intel Corporation. All rights reserved.
+; Copyright (c) 2019, Citrix Systems, Inc.
+;
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;
+;--
+
+;#define EFI_FIRMWARE_FILE_SYSTEM2_GUID \
+;  { 0x8c8ce578, 0x8a3d, 0x4f1c, { 0x99, 0x35, 0x89, 0x61, 0x85, 0xc3, 0x2d, 
0xd3 } }
+%define FFS_GUID_DWORD0 0x8c8ce578
+%define FFS_GUID_DWORD1 0x4f1c8a3d
+%define FFS_GUID_DWORD2 0x61893599
+%define FFS_GUID_DWORD3 0xd32dc385
+
+BITS32
+
+;
+; Modified:  EAX, EBX, ECX
+; Preserved: EDI, ESP
+;
+; @param[in]   EAX  Start search from here
+; @param[out]  EBP  Address of Boot Firmware Volume (BFV)
+;
+Flat32SearchForBfvBase:
+
+mov ecx, eax
+searchingForBfvHeaderLoop:
+;
+; We check for a firmware volume

[edk2-devel] [PATCH v5 09/35] OvmfPkg/OvmfXen: use a TimerLib instance that depends only on the CPU

2019-08-13 Thread Anthony PERARD
The ACPI Timer isn't present in a PVH guest, but local APIC works on
both PVH and HVM.

Note that the use of SecPeiDxeTimerLibCpu might be an issue with a
driver of type DXE_RUNTIME_DRIVER. I've attempted to find out which of
the DXE_RUNTIME_DRIVER uses the TimerLib at runtime. I've done that by
replacing the TimerLib evaluation in
[LibraryClasses.common.DXE_RUNTIME_DRIVER] by a different one and
checking every module that uses it (with the --report-file=report
build option).

ResetSystemRuntimeDxe is calling the TimerLib API at runtime to do the
operation "EfiResetCold", so this may never complete if the OS have
disabled the Local APIC Timer.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v4:
- reworded the first sentence, use "not present" instead of "don't work".

v3:
- cleanup .dsc, leave only one TimerLib resolution
- Added a note in the commit message regarding the use of the local apic
  by runtime drivers

 OvmfPkg/OvmfXen.dsc | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index 7619a89382..b40d39e003 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -104,7 +104,7 @@ [SkuIds]
 

 [LibraryClasses]
   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
-  TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf
+  TimerLib|MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.inf
   PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
   BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf
   BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
@@ -202,7 +202,6 @@ [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
 
 [LibraryClasses.common.SEC]
-  TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf
   QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf
 !ifdef $(DEBUG_ON_SERIAL_PORT)
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
@@ -281,7 +280,6 @@ [LibraryClasses.common.DXE_CORE]
 
 [LibraryClasses.common.DXE_RUNTIME_DRIVER]
   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
-  TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
   DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf
   
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
@@ -298,7 +296,6 @@ [LibraryClasses.common.DXE_RUNTIME_DRIVER]
 
 [LibraryClasses.common.UEFI_DRIVER]
   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
-  TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
   DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf
   
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
@@ -313,7 +310,6 @@ [LibraryClasses.common.UEFI_DRIVER]
 
 [LibraryClasses.common.DXE_DRIVER]
   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
-  TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
   
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
   
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
@@ -337,7 +333,6 @@ [LibraryClasses.common.DXE_DRIVER]
 
 [LibraryClasses.common.UEFI_APPLICATION]
   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
-  TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
   
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
   
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45530): https://edk2.groups.io/g/devel/message/45530
Mute This Topic: https://groups.io/mt/32851501/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v5 03/35] OvmfPkg: Introduce XenResetVector

2019-08-13 Thread Anthony PERARD
Introduce XenResetVector, a copy of OvmfPkg/ResetVector, with one
changes:
  - SEC_DEFAULT_CR0: enable cache (bit 30 or CD set to 0)

Xen copies the OVMF code to RAM, there is no need to disable cache.

This new module will later be modified to add a new entry point, more
detail in a following commit "OvmfPkg/XenResetVector: Add new entry point
for Xen PVH"

Value FILE_GUID of XenResetVector have not changed compare to ResetVector
because it is a special value (gEfiFirmwareVolumeTopFileGuid).

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Reviewed-by: Laszlo Ersek 
---

Notes:
v4:
- Update Maintainers.txt

v3:
  - Added gEfiFirmwareVolumeTopFileGuid to the commit message.
  - rebased: SPDX

 OvmfPkg/OvmfXen.dsc   |   2 +-
 OvmfPkg/OvmfXen.fdf   |   2 +-
 OvmfPkg/XenResetVector/XenResetVector.inf |  38 +
 Maintainers.txt   |   1 +
 .../XenResetVector/Ia16/Real16ToFlat32.asm| 134 
 OvmfPkg/XenResetVector/Ia32/PageTables64.asm  | 149 ++
 OvmfPkg/XenResetVector/XenResetVector.nasmb   |  68 
 7 files changed, 392 insertions(+), 2 deletions(-)
 create mode 100644 OvmfPkg/XenResetVector/XenResetVector.inf
 create mode 100644 OvmfPkg/XenResetVector/Ia16/Real16ToFlat32.asm
 create mode 100644 OvmfPkg/XenResetVector/Ia32/PageTables64.asm
 create mode 100644 OvmfPkg/XenResetVector/XenResetVector.nasmb

diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index f224ac32b4..1a0e59f0cc 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -495,7 +495,7 @@ [PcdsDynamicDefault]
 #
 

 [Components]
-  OvmfPkg/ResetVector/ResetVector.inf
+  OvmfPkg/XenResetVector/XenResetVector.inf
 
   #
   # SEC Phase modules
diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf
index f59647fd14..6fc8479aae 100644
--- a/OvmfPkg/OvmfXen.fdf
+++ b/OvmfPkg/OvmfXen.fdf
@@ -118,7 +118,7 @@ [FV.SECFV]
 #
 INF  OvmfPkg/Sec/SecMain.inf
 
-INF  RuleOverride=RESET_VECTOR OvmfPkg/ResetVector/ResetVector.inf
+INF  RuleOverride=RESET_VECTOR OvmfPkg/XenResetVector/XenResetVector.inf
 
 

 [FV.PEIFV]
diff --git a/OvmfPkg/XenResetVector/XenResetVector.inf 
b/OvmfPkg/XenResetVector/XenResetVector.inf
new file mode 100644
index 00..097fc9b5b4
--- /dev/null
+++ b/OvmfPkg/XenResetVector/XenResetVector.inf
@@ -0,0 +1,38 @@
+## @file
+#  Reset Vector
+#
+#  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+#  Copyright (c) 2019, Citrix Systems, Inc.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION= 0x00010005
+  BASE_NAME  = XenResetVector
+  FILE_GUID  = 1BA0062E-C779-4582-8566-336AE8F78F09
+  MODULE_TYPE= SEC
+  VERSION_STRING = 1.1
+
+#
+# The following information is for reference only and not required by the 
build tools.
+#
+#  VALID_ARCHITECTURES   = IA32 X64
+#
+
+[Sources]
+  XenResetVector.nasmb
+
+[Packages]
+  OvmfPkg/OvmfPkg.dec
+  MdePkg/MdePkg.dec
+  UefiCpuPkg/UefiCpuPkg.dec
+
+[BuildOptions]
+   *_*_IA32_NASMB_FLAGS = -I$(WORKSPACE)/UefiCpuPkg/ResetVector/Vtf0/
+   *_*_X64_NASMB_FLAGS = -I$(WORKSPACE)/UefiCpuPkg/ResetVector/Vtf0/
+
+[Pcd]
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize
diff --git a/Maintainers.txt b/Maintainers.txt
index 98f6d828eb..34bdb275b4 100644
--- a/Maintainers.txt
+++ b/Maintainers.txt
@@ -380,6 +380,7 @@ F: OvmfPkg/SmbiosPlatformDxe/*Xen.c
 F: OvmfPkg/XenBusDxe/
 F: OvmfPkg/XenIoPciDxe/
 F: OvmfPkg/XenPvBlkDxe/
+F: OvmfPkg/XenResetVector/
 R: Anthony Perard 
 R: Julien Grall 
 
diff --git a/OvmfPkg/XenResetVector/Ia16/Real16ToFlat32.asm 
b/OvmfPkg/XenResetVector/Ia16/Real16ToFlat32.asm
new file mode 100644
index 00..5c329bfaea
--- /dev/null
+++ b/OvmfPkg/XenResetVector/Ia16/Real16ToFlat32.asm
@@ -0,0 +1,134 @@
+;--
+; @file
+; Transition from 16 bit real mode into 32 bit flat protected mode
+;
+; Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.
+; Copyright (c) 2019, Citrix Systems, Inc.
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;
+;--
+
+%define SEC_DEFAULT_CR0  0x0023
+%define SEC_DEFAULT_CR4  0x640
+
+BITS16
+
+;
+; Modified:  EAX, EBX
+;
+; @param[out] DS   Selector allowing flat access to all addresses
+; @param[out] ES   Selector allowing flat access to all addresses
+; @param[out] FS   Selector allowing flat access to all addresses
+; @param[out] GS   Selector allowing flat access to all

[edk2-devel] [PATCH v5 05/35] OvmfPkg/OvmfXen: Creating an ELF header

2019-08-13 Thread Anthony PERARD
This patch changes the flash device image of OvmfXen to make it look
like it's an ELF. For this, we replace the empty embedded variable store
by a binary array, which is a ELF file header.

The ELF header explain to a loader to load the binary at the address
1MB, then jump to the PVH entry point which will be created in a later
patch. The header also includes a Xen ELF note that is part of the
PVH ABI.

That patch include OvmfXenElfHeaderGenerator.c which can be use to
regenerate the ELF header, but this will be a manual step.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v4:
- fix top-level comment style
- Update Maintainers.txt

v3:
- added license to generate_elf_header.c
  which is renamed to OvmfPkg/OvmfXenElfHeaderGenerator.c
- added an ELF NOTE into the header

 OvmfPkg/OvmfXen.fdf | 101 +++-
 OvmfPkg/OvmfXenElfHeaderGenerator.c | 140 
 Maintainers.txt |   1 +
 3 files changed, 239 insertions(+), 3 deletions(-)
 create mode 100644 OvmfPkg/OvmfXenElfHeaderGenerator.c

diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf
index 2ceff7baa2..43c268f6cb 100644
--- a/OvmfPkg/OvmfXen.fdf
+++ b/OvmfPkg/OvmfXen.fdf
@@ -15,8 +15,8 @@ [Defines]
 !include OvmfPkg.fdf.inc
 
 #
-# Build the variable store and the firmware code as one unified flash device
-# image.
+# This will allow the flash device image to be recognize as an ELF, with first
+# an ELF headers, then the firmware code.
 #
 [FD.OVMF]
 BaseAddress   = $(FW_BASE_ADDRESS)
@@ -25,7 +25,102 @@ [FD.OVMF]
 BlockSize = $(BLOCK_SIZE)
 NumBlocks = $(FW_BLOCKS)
 
-!include VarStore.fdf.inc
+!if ($(FD_SIZE_IN_KB) == 1024) || ($(FD_SIZE_IN_KB) == 2048)
+0x|0xe000
+!endif
+!if $(FD_SIZE_IN_KB) == 4096
+0x|0x0004
+!endif
+DATA = {
+  #
+  # This hex array have been generated by OvmfPkg/OvmfXenElfHeaderGenerator.c
+  # and copied manually.
+  #
+  # ELF file header
+  0x7f, 0x45, 0x4c, 0x46, # e_ident[0..3]: Magic number
+  0x01, # File class: 32-bit objects
+  0x01, # Data encoding: 2's complement, little endian
+  0x01, # File version
+  0x03, # OS ABI identification: Object uses GNU ELF extensions
+  0x00, # ABI version
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  # e_ident[EI_PAD...]
+  0x02, 0x00, # e_type = Executable file
+  0x03, 0x00, # e_machine = Intel 80386
+  0x01, 0x00, 0x00, 0x00, # e_version
+  0xd0, 0xff, 0x2f, 0x00, # e_entry: Entry point virtual address
+  0x34, 0x00, 0x00, 0x00, # e_phoff: Program header table file offset
+  0x00, 0x00, 0x00, 0x00, # e_shoff: Section header table file offset
+  0x00, 0x00, 0x00, 0x00, # e_flags: Processor-specific flags
+  0x34, 0x00, #e_ehsize: ELF header size
+  0x20, 0x00, # e_phentsize: Program header table entry size
+  0x02, 0x00, # e_phnum: Program header table entry count
+  0x00, 0x00, # e_shentsize: Section header table entry size
+  0x00, 0x00, # e_shnum: Section header table entry count
+  0x00, 0x00, # e_shstrndx
+
+  # ELF Program segment headers
+  # - Load segment
+  0x01, 0x00, 0x00, 0x00, # p_type = Loadable program segment
+  0x00, 0x00, 0x00, 0x00, # p_offset
+  0x00, 0x00, 0x10, 0x00, # p_vaddr: Segment virtual address
+  0x00, 0x00, 0x10, 0x00, # p_paddr: Segment physical address
+  0x00, 0x00, 0x20, 0x00, # p_filesz: Segment size in file
+  0x00, 0x00, 0x20, 0x00, # p_memsz: Segment size in memory
+  0x07, 0x00, 0x00, 0x00, # p_flags = Segment is executable | writable | 
readable
+  0x00, 0x00, 0x00, 0x00, # p_align
+  # - ELFNOTE segment
+  0x04, 0x00, 0x00, 0x00, # p_type = PT_NOTE
+  0x74, 0x00, 0x00, 0x00, # p_offset = point to XEN_ELFNOTE_PHYS32_ENTRY below
+  0x74, 0x00, 0x10, 0x00,
+  0x74, 0x00, 0x10, 0x00,
+  0x14, 0x00, 0x00, 0x00,
+  0x14, 0x00, 0x00, 0x00,
+  0x04, 0x00, 0x00, 0x00, # p_flags = Segment is readable
+  0x00, 0x00, 0x00, 0x00,
+
+  # XEN_ELFNOTE_PHYS32_ENTRY
+  0x04, 0x00, 0x00, 0x00, # name size
+  0x04, 0x00, 0x00, 0x00, # desc size
+  0x12, 0x00, 0x00, 0x00, # type = XEN_ELFNOTE_PHYS32_ENTRY
+  0x58, 0x65, 0x6e, 0x00, # name = "Xen"
+  0xd0, 0xff, 0x2f, 0x00, # desc: PVH entry point
+  0x00
+}
+
+!if ($(FD_SIZE_IN_KB) == 1024) || ($(FD_SIZE_IN_KB) == 2048)
+0xe000|0x1000
+!endif
+!if $(FD_SIZE_IN_KB) == 4096
+0x0004|0x1000
+!endif
+#NV_EVENT_LOG
+
+!if ($(FD_SIZE_IN_KB) == 1024) || ($(FD_SIZE_IN_KB) == 2048)
+0xf000|0x1000
+!endif
+!if $(FD_SIZE_IN_KB) == 4096
+0x00041000|0x1000
+!endif
+#NV_FTW_WORKING
+DATA = {
+  # EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER->Signature = 
gEdkiiWorkingBlockSignatureGuid =
+  #  { 0x9e58292b, 0x7c68, 0x497d, { 0xa0, 0xce, 0x65,  0x0, 0xfd, 0x9f, 0x1b, 
0x95 }}
+  0x2b, 0x29, 0x58, 0x9e, 0x68, 0x7c, 0x7d, 0x49,
+  0xa0, 0xce, 0x65,  0x0, 0xfd, 0x9f, 0x1b, 0x95,
+  # Crc:UINT32#WorkingBlockValid:1, WorkingBlockInvalid:1, Reserved
+  0x2

[edk2-devel] [PATCH v5 06/35] OvmfPkg/XenResetVector: Add new entry point for Xen PVH

2019-08-13 Thread Anthony PERARD
Add a new entry point for Xen PVH that enter directly in 32bits.

Information on the expected state of the machine when this entry point
is used can be found at:
https://xenbits.xenproject.org/docs/unstable/misc/pvh.html

Also, compare to the original file [1], the two `nop' of the "resetVector"
entry point are removed. There were introduced by 8332983e2e33
("UefiCpuPkg: Replace the un-necessary WBINVD instruction at the reset
vector with two NOPs in VTF0.", 2011-08-04), but don't seems to be
useful. This is the entry point used by HVM guest (hvmloader).

[1] UefiCpuPkg/ResetVector/Vtf0/Ia16/ResetVectorVtf0.asm

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v4:
- remove the two nop in the HVM entry point

v3:
- rebased, SPDX
- remove `cli' as via PVH the interrupts are guaranteed to be off
- rewrite some comments

 .../XenResetVector/Ia16/ResetVectorVtf0.asm   | 79 +++
 OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm| 49 
 OvmfPkg/XenResetVector/XenResetVector.nasmb   |  1 +
 3 files changed, 129 insertions(+)
 create mode 100644 OvmfPkg/XenResetVector/Ia16/ResetVectorVtf0.asm
 create mode 100644 OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm

diff --git a/OvmfPkg/XenResetVector/Ia16/ResetVectorVtf0.asm 
b/OvmfPkg/XenResetVector/Ia16/ResetVectorVtf0.asm
new file mode 100644
index 00..56749bdbc9
--- /dev/null
+++ b/OvmfPkg/XenResetVector/Ia16/ResetVectorVtf0.asm
@@ -0,0 +1,79 @@
+;--
+; @file
+; First code executed by processor after resetting.
+;
+; Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.
+; Copyright (c) 2019, Citrix Systems, Inc.
+;
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;
+;--
+
+BITS16
+
+ALIGN   16
+
+;
+; Pad the image size to 4k when page tables are in VTF0
+;
+; If the VTF0 image has page tables built in, then we need to make
+; sure the end of VTF0 is 4k above where the page tables end.
+;
+; This is required so the page tables will be 4k aligned when VTF0 is
+; located just below 0x1 (4GB) in the firmware device.
+;
+%ifdef ALIGN_TOP_TO_4K_FOR_PAGING
+TIMES (0x1000 - ($ - EndOfPageTables) - (fourGigabytes - 
xenPVHEntryPoint)) DB 0
+%endif
+
+BITS32
+xenPVHEntryPoint:
+;
+; Entry point to use when running as a Xen PVH guest. (0xffd0)
+;
+; Description of the expected state of the machine when this entry point is
+; used can be found at:
+; https://xenbits.xenproject.org/docs/unstable/misc/pvh.html
+;
+jmp xenPVHMain
+
+BITS16
+ALIGN   16
+
+applicationProcessorEntryPoint:
+;
+; Application Processors entry point
+;
+; GenFv generates code aligned on a 4k boundary which will jump to this
+; location.  (0xffe0)  This allows the Local APIC Startup IPI to be
+; used to wake up the application processors.
+;
+jmp EarlyApInitReal16
+
+ALIGN   8
+
+DD  0
+
+;
+; The VTF signature
+;
+; VTF-0 means that the VTF (Volume Top File) code does not require
+; any fixups.
+;
+vtfSignature:
+DB  'V', 'T', 'F', 0
+
+ALIGN   16
+
+resetVector:
+;
+; Reset Vector
+;
+; This is where the processor will begin execution
+;
+jmp EarlyBspInitReal16
+
+ALIGN   16
+
+fourGigabytes:
+
diff --git a/OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm 
b/OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm
new file mode 100644
index 00..2a17fed52f
--- /dev/null
+++ b/OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm
@@ -0,0 +1,49 @@
+;--
+; @file
+; An entry point use by Xen when a guest is started in PVH mode.
+;
+; Copyright (c) 2019, Citrix Systems, Inc.
+;
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;
+;--
+
+BITS32
+
+xenPVHMain:
+;
+; 'BP' to indicate boot-strap processor
+;
+mov di, 'BP'
+
+;
+; ESP will be used as initial value of the EAX register
+; in Main.asm
+;
+xor esp, esp
+
+mov ebx, ADDR_OF(gdtr)
+lgdt[ebx]
+
+mov eax, SEC_DEFAULT_CR0
+mov cr0, eax
+
+jmp LINEAR_CODE_SEL:ADDR_OF(.jmpToNewCodeSeg)
+.jmpToNewCodeSeg:
+
+mov eax, SEC_DEFAULT_CR4
+mov cr4, eax
+
+mov ax, LINEAR_SEL
+mov ds, ax
+mov es, ax
+mov fs, ax
+mov gs, ax
+mov ss, ax
+
+;
+; Jump to the main routine of the pre-SEC code
+; skiping the 16-bit part of the routine and
+; into the 32-bit flat mode part
+;
+OneTimeCallRet TransitionFromReal16To32BitFlat
diff --git a/OvmfPkg/XenResetVector/XenResetVector.nasmb 
b/OvmfPkg/XenResetVector/XenResetVector.nasmb
index 89a4b08bc3..0dbc4f2c1d 100644
--- a/OvmfPkg/XenResetVector/XenRes

[edk2-devel] [PATCH v5 07/35] OvmfPkg/XenResetVector: Saving start of day pointer for PVH guests

2019-08-13 Thread Anthony PERARD
As described in the Xen PVH documentation [1], "ebx: contains the
physical memory address where the loader has placed the boot start info
structure". To have this pointer saved to be able to use it later in the
PEI phase, we allocate some space in the MEMFD for it. We use 'XPVH' as
a signature (for "Xen PVH").

[1] https://xenbits.xenproject.org/docs/unstable/misc/pvh.html

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v3:
- rename PcdXenStartOfDay* to PcdXenPvhStartOfDay*
- Use first available token value for those (0x17 and 0x28)

 OvmfPkg/OvmfPkg.dec | 3 +++
 OvmfPkg/OvmfXen.fdf | 4 
 OvmfPkg/XenResetVector/XenResetVector.inf   | 3 +++
 OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm  | 6 ++
 OvmfPkg/XenResetVector/XenResetVector.nasmb | 2 ++
 5 files changed, 18 insertions(+)

diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index 9640360f62..c2a2ebfb95 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -218,6 +218,9 @@ [PcdsFixedAtBuild]
   #  The value should be a multiple of 4KB.
   gUefiOvmfPkgTokenSpaceGuid.PcdHighPmmMemorySize|0x40|UINT32|0x31
 
+  gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtr|0x0|UINT32|0x17
+  gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtrSize|0x0|UINT32|0x32
+
 [PcdsDynamic, PcdsDynamicEx]
   gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x10
diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf
index 43c268f6cb..49997fee9b 100644
--- a/OvmfPkg/OvmfXen.fdf
+++ b/OvmfPkg/OvmfXen.fdf
@@ -172,6 +172,10 @@ [FD.MEMFD]
 0x007000|0x001000
 
gEfiMdePkgTokenSpaceGuid.PcdGuidedExtractHandlerTableAddress|gUefiOvmfPkgTokenSpaceGuid.PcdGuidedExtractHandlerTableSize
 
+0x008000|0x001000
+# Used by XenResetVector to communicate with XenPlatformPei
+gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtr|gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtrSize
+
 0x01|0x01
 
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize
 
diff --git a/OvmfPkg/XenResetVector/XenResetVector.inf 
b/OvmfPkg/XenResetVector/XenResetVector.inf
index 097fc9b5b4..46b133a834 100644
--- a/OvmfPkg/XenResetVector/XenResetVector.inf
+++ b/OvmfPkg/XenResetVector/XenResetVector.inf
@@ -36,3 +36,6 @@ [BuildOptions]
 [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize
+
+  gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtr
+  gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtrSize
diff --git a/OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm 
b/OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm
index 2a17fed52f..f42df3dba2 100644
--- a/OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm
+++ b/OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm
@@ -22,6 +22,12 @@ xenPVHMain:
 ;
 xor esp, esp
 
+;
+; Store "Start of day" struct pointer for later use
+;
+mov dword[PVH_SPACE (0)], ebx
+mov dword[PVH_SPACE (4)], 'XPVH'
+
 mov ebx, ADDR_OF(gdtr)
 lgdt[ebx]
 
diff --git a/OvmfPkg/XenResetVector/XenResetVector.nasmb 
b/OvmfPkg/XenResetVector/XenResetVector.nasmb
index 0dbc4f2c1d..b2cb405d54 100644
--- a/OvmfPkg/XenResetVector/XenResetVector.nasmb
+++ b/OvmfPkg/XenResetVector/XenResetVector.nasmb
@@ -34,6 +34,8 @@
 
 %include "CommonMacros.inc"
 
+%define PVH_SPACE(Offset) (FixedPcdGet32 (PcdXenPvhStartOfDayStructPtr) + 
(Offset))
+
 %include "PostCodes.inc"
 
 %ifdef DEBUG_PORT80
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45535): https://edk2.groups.io/g/devel/message/45535
Mute This Topic: https://groups.io/mt/32851507/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v5 01/35] OvmfPkg/ResetSystemLib: Add missing dependency on PciLib

2019-08-13 Thread Anthony PERARD
Add missing dependency on PciLib
and remove extra includes of OvmfPlatforms.h.

Signed-off-by: Anthony PERARD 
Reviewed-by: Laszlo Ersek 
---

Notes:
v2:
- also add PciLib.h include to the .c
- and remove extra include of OvmfPlatforms.h

 OvmfPkg/Library/ResetSystemLib/ResetSystemLib.inf | 1 +
 OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c   | 3 +--
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.inf 
b/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.inf
index 7c44f99a5c..2f24dac87f 100644
--- a/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.inf
+++ b/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.inf
@@ -30,4 +30,5 @@ [Packages]
 [LibraryClasses]
   DebugLib
   IoLib
+  PciLib
   TimerLib
diff --git a/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c 
b/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c
index 27460cd100..98dd80e33c 100644
--- a/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c
+++ b/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c
@@ -11,11 +11,10 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
-#include 
-
 VOID
 AcpiPmControl (
   UINTN SuspendType
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45533): https://edk2.groups.io/g/devel/message/45533
Mute This Topic: https://groups.io/mt/32851505/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v5 00/35] Specific platform to run OVMF in Xen PVH and HVM guests

2019-08-13 Thread Anthony PERARD
Patch series available in this git branch:
https://xenbits.xen.org/git-http/people/aperard/ovmf.git br.platform-xen-pvh-v5

Changes in v5:
- patch 23 got a rework of the lapic range skipping
- small fixups in patch 20, 22, 23, 31, 32, 33.
  see notes for detail.

Hi,

I've started to create a Xen specific platform, in OvmfPkg/XenOvmf.dsc
with the goal to make it work on both Xen HVM and Xen PVH.

The first few patches only create the platform and duplicate some code from
OvmfPkg and the later patches makes OVMF boot in a Xen PVH guest and can boot
a Linux guest.

After this patch series, I'd like to wait a bit before removing Xen support
from the OvmfPkg*.dsc, to allow time to switch to the new Xen only platform,
maybe 1 year.

To build and boot:

To build, simply run OvmfPkg/build.sh -p OvmfPkg/OvmfXen.dsc
Then use OVMF.fd as a kernel of a pvh guest config file (with xl/libxl).

Patch series available in this git branch:
https://xenbits.xen.org/git-http/people/aperard/ovmf.git br.platform-xen-pvh-v5

Anthony PERARD (35):
  OvmfPkg/ResetSystemLib: Add missing dependency on PciLib
  OvmfPkg: Create platform OvmfXen
  OvmfPkg: Introduce XenResetVector
  OvmfPkg: Introduce XenPlatformPei
  OvmfPkg/OvmfXen: Creating an ELF header
  OvmfPkg/XenResetVector: Add new entry point for Xen PVH
  OvmfPkg/XenResetVector: Saving start of day pointer for PVH guests
  OvmfPkg/XenResetVector: Allow jumpstart from either hvmloader or PVH
  OvmfPkg/OvmfXen: use a TimerLib instance that depends only on the CPU
  OvmfPkg/XenPlatformPei: Detect OVMF_INFO from hvmloader
  OvmfPkg/XenPlatformPei: Use mXenHvmloaderInfo to get E820
  OvmfPkg/XenPlatformPei: Grab RSDP from PVH guest start of day struct
  OvmfPkg/Library/XenPlatformLib: New library
  OvmfPkg/AcpiPlatformDxe: Use XenPlatformLib
  OvmfPkg/AcpiPlatformDxe: Use Xen PVH RSDP if it exist
  OvmfPkg/XenHypercallLib: Enable it in PEIM
  OvmfPkg/XenPlatformPei: Reinit XenHypercallLib
  OvmfPkg/XenPlatformPei: Introduce XenHvmloaderDetected
  OvmfPkg/XenPlatformPei: Setup HyperPages earlier
  OvmfPkg/XenPlatformPei: Introduce XenPvhDetected
  OvmfPkg: Import XENMEM_memory_map hypercall to Xen/memory.h
  OvmfPkg/XenPlatformPei: no hvmloader: get the E820 table via hypercall
  OvmfPkg/XenPlatformPei: Rework memory detection
  OvmfPkg/XenPlatformPei: Reserve VGA memory region, to boot Linux
  OvmfPkg/XenPlatformPei: Ignore missing PCI Host Bridge on Xen PVH
  OvmfPkg/XenPlatformLib: Cache result for XenDetected
  OvmfPkg/PlatformBootManagerLib: Use XenDetected from XenPlatformLib
  OvmfPkg/PlatformBootManagerLib: Handle the absence of PCI bus on Xen
PVH
  OvmfPkg/OvmfXen: Override PcdFSBClock to Xen vLAPIC timer frequency
  OvmfPkg/OvmfXen: Introduce XenTimerDxe
  OvmfPkg/PlatformBootManagerLib: Use a Xen console for ConOut/ConIn
  OvmfPkg: Introduce PcdXenGrantFrames
  OvmfPkg: Introduce XenIoPvhDxe to initialize Grant Tables
  OvmfPkg: Move XenRealTimeClockLib from ArmVirtPkg
  OvmfPkg/OvmfXen: use RealTimeClockRuntimeDxe from EmbeddedPkg

 OvmfPkg/OvmfPkg.dec   |  10 +
 ArmVirtPkg/ArmVirtXen.dsc |   2 +-
 OvmfPkg/OvmfPkgIa32.dsc   |   1 +
 OvmfPkg/OvmfPkgIa32X64.dsc|   1 +
 OvmfPkg/OvmfPkgX64.dsc|   1 +
 OvmfPkg/{OvmfPkgX64.dsc => OvmfXen.dsc}   | 238 +---
 OvmfPkg/OvmfXen.fdf   | 539 ++
 OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf   |   3 +-
 .../PlatformBootManagerLib.inf|   6 +-
 .../Library/ResetSystemLib/ResetSystemLib.inf |   1 +
 .../XenHypercallLib/XenHypercallLib.inf   |   4 +-
 .../Library/XenPlatformLib/XenPlatformLib.inf |  33 ++
 .../XenRealTimeClockLib.inf   |   0
 OvmfPkg/XenBusDxe/XenBusDxe.inf   |   3 +
 OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf   |  36 ++
 OvmfPkg/XenPlatformPei/XenPlatformPei.inf | 100 
 OvmfPkg/XenResetVector/XenResetVector.inf |  41 ++
 OvmfPkg/XenTimerDxe/XenTimerDxe.inf   |  42 ++
 OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h|   6 +-
 OvmfPkg/Include/Guid/XenInfo.h|   8 +-
 .../Xen/arch-x86/hvm/start_info.h | 143 +
 OvmfPkg/Include/IndustryStandard/Xen/memory.h |  23 +
 OvmfPkg/Include/Library/XenHypercallLib.h |  12 +
 OvmfPkg/Include/Library/XenPlatformLib.h  |  53 ++
 .../PlatformBootManagerLib/BdsPlatform.h  |   1 +
 OvmfPkg/XenBusDxe/XenBusDxe.h |   1 +
 OvmfPkg/XenPlatformPei/Cmos.h |  52 ++
 OvmfPkg/XenPlatformPei/Platform.h | 136 +
 OvmfPkg/XenPlatformPei/Xen.h  |  39 ++
 OvmfPkg/XenTimerDxe/XenTimerDxe.h | 177 ++
 OvmfPkg/AcpiPlatformDxe/Xen.c |  41 +-
 .../PlatformBootManagerLib/BdsPlatform.c  |  43 +-
 .../PlatformBootManagerLib/PlatformData.c |  49 +-
 .../Library/ResetSystemLib/ResetSystemLib.c   |   3 +-
 .../Library/XenHypercallLib/X86XenHypercal

[edk2-devel] [PATCH v5 29/35] OvmfPkg/OvmfXen: Override PcdFSBClock to Xen vLAPIC timer frequency

2019-08-13 Thread Anthony PERARD
PcdFSBClock is used by SecPeiDxeTimerLibCpu, the TimerLib
implementation. It will also be used by XenTimerDxe. Override
PcdFSBClock to match Xen vLAPIC timer frequency.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v3:
- expand commit message body to be standalone

 OvmfPkg/OvmfXen.dsc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index 22970eda5d..477d8c76a1 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -439,6 +439,9 @@ [PcdsFixedAtBuild]
   # Point to the MdeModulePkg/Application/UiApp/UiApp.inf
   gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 
0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 }
 
+  ## Xen vlapic's frequence is 100 MHz
+  gEfiMdePkgTokenSpaceGuid.PcdFSBClock|1
+
 

 #
 # Pcd Dynamic Section - list of all EDK II PCD Entries defined by this Platform
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45556): https://edk2.groups.io/g/devel/message/45556
Mute This Topic: https://groups.io/mt/32851704/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v5 31/35] OvmfPkg/PlatformBootManagerLib: Use a Xen console for ConOut/ConIn

2019-08-13 Thread Anthony PERARD
On a Xen PVH guest, none of the existing serial or console interface
works, so we add a new one, based on XenConsoleSerialPortLib, and
implemented via SerialDxe.

That is a simple console implementation that can work on both PVH
guest and HVM guests, even if it is rarely going to be used on HVM.

Have PlatformBootManagerLib look for the new console, when running as a
Xen guest.

Since we use VENDOR_UART_DEVICE_PATH, fix its description and coding
style.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Reviewed-by: Laszlo Ersek 
---

Notes:
v5:
- fix typos in commit message.

v4:
- instead of creating a new XEN_CONSOLE_DEVICE_PATH, use the existing
  VENDOR_UART_DEVICE_PATH. And explain why VENDOR_UART_DEVICE_PATH
  changed in the commit message.

v3:
- removed PciSioSerialDxe and IsaSerialDxe from OvmfXen, since they
  would not be used, maybe, to check.
- some coding style fix

- not changed: PciSioSerialDxe: even if we add SerialDxe, we still needs
  PciSioSerialDxe to have OVMF use the emulated serial port on HVM.

v2:
- Use MdeModulePkg/Universal/SerialDxe instead of something new.
- Have PlatformInitializeConsole() look for it by using the
  known-in-advance device path for the xen console in the
  PLATFORM_CONSOLE_CONNECT_ENTRY.

 OvmfPkg/OvmfXen.dsc   |  4 ++
 OvmfPkg/OvmfXen.fdf   |  1 +
 .../PlatformBootManagerLib.inf|  4 ++
 .../PlatformBootManagerLib/BdsPlatform.h  |  1 +
 .../PlatformBootManagerLib/BdsPlatform.c  |  3 +-
 .../PlatformBootManagerLib/PlatformData.c | 49 +--
 6 files changed, 58 insertions(+), 4 deletions(-)

diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index 54ac910d8e..e719a168f8 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -586,6 +586,10 @@ [Components]
   OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
   OvmfPkg/XenBusDxe/XenBusDxe.inf
   OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
+  MdeModulePkg/Universal/SerialDxe/SerialDxe.inf {
+
+  
SerialPortLib|OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf
+  }
   MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
   
MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
   MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf
index fa0830a324..5c1a925d6a 100644
--- a/OvmfPkg/OvmfXen.fdf
+++ b/OvmfPkg/OvmfXen.fdf
@@ -312,6 +312,7 @@ [FV.DXEFV]
 INF  OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
 INF  OvmfPkg/XenBusDxe/XenBusDxe.inf
 INF  OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
+INF  MdeModulePkg/Universal/SerialDxe/SerialDxe.inf
 
 INF  MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
 INF  
MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
diff --git a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf 
b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
index 04d614cd49..f89cce1879 100644
--- a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
+++ b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
@@ -61,6 +61,10 @@ [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
   gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut
+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate ## CONSUMES
+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits ## CONSUMES
+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity   ## CONSUMES
+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits ## CONSUMES
 
 [Pcd.IA32, Pcd.X64]
   gEfiMdePkgTokenSpaceGuid.PcdFSBClock
diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.h 
b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.h
index 49a072b400..153e215101 100644
--- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.h
+++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.h
@@ -165,6 +165,7 @@ typedef struct {
 #define CONSOLE_IN  BIT1
 #define STD_ERROR   BIT2
 extern PLATFORM_CONSOLE_CONNECT_ENTRY  gPlatformConsole[];
+extern PLATFORM_CONSOLE_CONNECT_ENTRY  gXenPlatformConsole[];
 
 //
 // Platform BDS Functions
diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c 
b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
index 1eba304f09..70df6b841a 100644
--- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
+++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
@@ -398,7 +398,8 @@ PlatformBootManagerBeforeConsole (
   //
   EfiBootManagerDispatchDeferredImages ();
 
-  PlatformInitializeConsole (gPlatformConsole);
+  PlatformInitializeConsole (
+XenDetected() ? gXenPlatformConsole : gPlatformConsole);
   PcdStatus = PcdSet16S (PcdPlatformBootTimeOut,
 GetFrontPageTimeoutFromQemu ());
   ASSERT_RETURN_ERROR (PcdStatus);
diff --git

[edk2-devel] [PATCH v5 17/35] OvmfPkg/XenPlatformPei: Reinit XenHypercallLib

2019-08-13 Thread Anthony PERARD
The XenPlatformPei needs to make hypercalls, but the XenHypercallLib was
initialised before the HyperPage was ready. Now that XenPlatformPei has
initialised the HyperPage, reinitialise the XenHypercallLib.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Reviewed-by: Laszlo Ersek 
---

Notes:
v3:
- new patch split from XenHypercallLib: Enable it in PEIM.
- check for Lib initialisation failure.

 OvmfPkg/XenPlatformPei/XenPlatformPei.inf | 1 +
 OvmfPkg/XenPlatformPei/Xen.c  | 9 +
 2 files changed, 10 insertions(+)

diff --git a/OvmfPkg/XenPlatformPei/XenPlatformPei.inf 
b/OvmfPkg/XenPlatformPei/XenPlatformPei.inf
index 4d00206d09..0ef77db92c 100644
--- a/OvmfPkg/XenPlatformPei/XenPlatformPei.inf
+++ b/OvmfPkg/XenPlatformPei/XenPlatformPei.inf
@@ -59,6 +59,7 @@ [LibraryClasses]
   MtrrLib
   MemEncryptSevLib
   PcdLib
+  XenHypercallLib
 
 [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase
diff --git a/OvmfPkg/XenPlatformPei/Xen.c b/OvmfPkg/XenPlatformPei/Xen.c
index b366139a0a..c67f4c9697 100644
--- a/OvmfPkg/XenPlatformPei/Xen.c
+++ b/OvmfPkg/XenPlatformPei/Xen.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "Platform.h"
 #include "Xen.h"
@@ -88,6 +89,7 @@ XenConnect (
   EFI_XEN_OVMF_INFO *Info;
   CHAR8 Sig[sizeof (Info->Signature) + 1];
   UINT32 *PVHResetVectorData;
+  RETURN_STATUS Status;
 
   AsmCpuid (XenLeaf + 2, , , NULL, NULL);
   mXenInfo.HyperPages = AllocatePages (TransferPages);
@@ -152,6 +154,13 @@ XenConnect (
 sizeof(mXenInfo)
 );
 
+  //
+  // Initialize the XenHypercall library, now that the XenInfo HOB is
+  // available
+  //
+  Status = XenHypercallLibInit ();
+  ASSERT_RETURN_ERROR (Status);
+
   return EFI_SUCCESS;
 }
 
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45558): https://edk2.groups.io/g/devel/message/45558
Mute This Topic: https://groups.io/mt/32851706/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v5 23/35] OvmfPkg/XenPlatformPei: Rework memory detection

2019-08-13 Thread Anthony PERARD
When running as a Xen PVH guest, there is no CMOS to read the memory
size from.  Rework GetSystemMemorySize(Below|Above)4gb() so they can
work without CMOS by reading the e820 table.

Rework XenPublishRamRegions to also care for the reserved and ACPI
entry in the e820 table. The region that was added by InitializeXen()
isn't needed as that same entry is in the e820 table provided by
hvmloader.

MTRR settings aren't modified anymore, on HVM it's already done by
hvmloader, on PVH it is supposed to have sane default. MTRR will need
to be done properly but keeping what's already been done by programs
that have run before OVMF will do for now.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v5:
- fix coding style
- fix typo in commit message
- Handle all possible cases of a E820 reserved range overlapping with the
  LAPIC range.

v4:
- some coding style
- Added AddReservedMemoryRangeHob, and using it.
- this patch now replace "OvmfPkg/XenPlatformPei: Reserve hvmloader's 
memory only when it has run"
  from v3.  hvmloader have added an entry in the e820 table, there is no
  need for a special case.
- now, everything that is in the e820 table is added to OVMF's memory
  map, no more skipping ACPI entries or hvmloader's reserved entries.
  Instead, we look for the local APIC region and avoid it if it is
  present in the e820.
- rework commit message

 OvmfPkg/XenPlatformPei/Platform.h  | 13 ++
 OvmfPkg/XenPlatformPei/MemDetect.c | 69 +++
 OvmfPkg/XenPlatformPei/Platform.c  | 11 +
 OvmfPkg/XenPlatformPei/Xen.c   | 75 +-
 4 files changed, 147 insertions(+), 21 deletions(-)

diff --git a/OvmfPkg/XenPlatformPei/Platform.h 
b/OvmfPkg/XenPlatformPei/Platform.h
index db9a62572f..7661f4a8de 100644
--- a/OvmfPkg/XenPlatformPei/Platform.h
+++ b/OvmfPkg/XenPlatformPei/Platform.h
@@ -44,6 +44,13 @@ AddReservedMemoryBaseSizeHob (
   BOOLEAN Cacheable
   );
 
+VOID
+AddReservedMemoryRangeHob (
+  EFI_PHYSICAL_ADDRESSMemoryBase,
+  EFI_PHYSICAL_ADDRESSMemoryLimit,
+  BOOLEAN Cacheable
+  );
+
 VOID
 AddressWidthInitialization (
   VOID
@@ -114,6 +121,12 @@ XenPublishRamRegions (
   VOID
   );
 
+EFI_STATUS
+XenGetE820Map (
+  EFI_E820_ENTRY64 **Entries,
+  UINT32 *Count
+  );
+
 extern EFI_BOOT_MODE mBootMode;
 
 extern UINT8 mPhysMemAddressWidth;
diff --git a/OvmfPkg/XenPlatformPei/MemDetect.c 
b/OvmfPkg/XenPlatformPei/MemDetect.c
index cf95f9c474..1f81eee407 100644
--- a/OvmfPkg/XenPlatformPei/MemDetect.c
+++ b/OvmfPkg/XenPlatformPei/MemDetect.c
@@ -96,6 +96,45 @@ Q35TsegMbytesInitialization (
   mQ35TsegMbytes = ExtendedTsegMbytes;
 }
 
+STATIC
+UINT64
+GetHighestSystemMemoryAddress (
+  BOOLEAN   Below4gb
+  )
+{
+  EFI_E820_ENTRY64*E820Map;
+  UINT32  E820EntriesCount;
+  EFI_E820_ENTRY64*Entry;
+  EFI_STATUS  Status;
+  UINT32  Loop;
+  UINT64  HighestAddress;
+  UINT64  EntryEnd;
+
+  HighestAddress = 0;
+
+  Status = XenGetE820Map (, );
+  ASSERT_EFI_ERROR (Status);
+
+  for (Loop = 0; Loop < E820EntriesCount; Loop++) {
+Entry = E820Map + Loop;
+EntryEnd = Entry->BaseAddr + Entry->Length;
+
+if (Entry->Type == EfiAcpiAddressRangeMemory &&
+EntryEnd > HighestAddress) {
+
+  if (Below4gb && (EntryEnd <= BASE_4GB)) {
+HighestAddress = EntryEnd;
+  } else if (!Below4gb && (EntryEnd >= BASE_4GB)) {
+HighestAddress = EntryEnd;
+  }
+}
+  }
+
+  //
+  // Round down the end address.
+  //
+  return HighestAddress & ~(UINT64)EFI_PAGE_MASK;
+}
 
 UINT32
 GetSystemMemorySizeBelow4gb (
@@ -105,6 +144,19 @@ GetSystemMemorySizeBelow4gb (
   UINT8 Cmos0x34;
   UINT8 Cmos0x35;
 
+  //
+  // In PVH case, there is no CMOS, we have to calculate the memory size
+  // from parsing the E820
+  //
+  if (XenPvhDetected ()) {
+UINT64  HighestAddress;
+
+HighestAddress = GetHighestSystemMemoryAddress (TRUE);
+ASSERT (HighestAddress > 0 && HighestAddress <= BASE_4GB);
+
+return HighestAddress;
+  }
+
   //
   // CMOS 0x34/0x35 specifies the system memory above 16 MB.
   // * CMOS(0x35) is the high byte
@@ -129,6 +181,23 @@ GetSystemMemorySizeAbove4gb (
   UINT32 Size;
   UINTN  CmosIndex;
 
+  //
+  // In PVH case, there is no CMOS, we have to calculate the memory size
+  // from parsing the E820
+  //
+  if (XenPvhDetected ()) {
+UINT64  HighestAddress;
+
+HighestAddress = GetHighestSystemMemoryAddress (FALSE);
+ASSERT (HighestAddress == 0 || HighestAddress >= BASE_4GB);
+
+if (HighestAddress >= BASE_4GB) {
+  HighestAddress -= BASE_4GB;
+}
+
+return HighestAddress;
+  }
+
   //
   // CMOS 0x5b-0x5d specifies the system memory above 4G

[edk2-devel] [PATCH v5 20/35] OvmfPkg/XenPlatformPei: Introduce XenPvhDetected

2019-08-13 Thread Anthony PERARD
XenPvhDetected() can be used to figure out if OVMF has started via the
Xen PVH entry point.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v5:
- in XenPvhDetected, check mXenInfo.HyperPages instead of .VersionMajor

 OvmfPkg/XenPlatformPei/Platform.h |  5 +
 OvmfPkg/XenPlatformPei/Xen.c  | 13 +
 2 files changed, 18 insertions(+)

diff --git a/OvmfPkg/XenPlatformPei/Platform.h 
b/OvmfPkg/XenPlatformPei/Platform.h
index 4a80057bdc..db9a62572f 100644
--- a/OvmfPkg/XenPlatformPei/Platform.h
+++ b/OvmfPkg/XenPlatformPei/Platform.h
@@ -99,6 +99,11 @@ XenHvmloaderDetected (
   VOID
   );
 
+BOOLEAN
+XenPvhDetected (
+  VOID
+  );
+
 VOID
 AmdSevInitialize (
   VOID
diff --git a/OvmfPkg/XenPlatformPei/Xen.c b/OvmfPkg/XenPlatformPei/Xen.c
index 29b42b746c..f26f0e56dd 100644
--- a/OvmfPkg/XenPlatformPei/Xen.c
+++ b/OvmfPkg/XenPlatformPei/Xen.c
@@ -214,6 +214,19 @@ XenHvmloaderDetected (
   return (mXenHvmloaderInfo != NULL);
 }
 
+BOOLEAN
+XenPvhDetected (
+  VOID
+  )
+{
+  //
+  // This function should only be used after XenConnect
+  //
+  ASSERT (mXenInfo.HyperPages != NULL);
+
+  return mXenHvmloaderInfo == NULL;
+}
+
 VOID
 XenPublishRamRegions (
   VOID
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45560): https://edk2.groups.io/g/devel/message/45560
Mute This Topic: https://groups.io/mt/32851708/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v5 21/35] OvmfPkg: Import XENMEM_memory_map hypercall to Xen/memory.h

2019-08-13 Thread Anthony PERARD
The informations to make a XENMEM_memory_map hypercall is copied over
from the public header of the Xen Project, with the type name modified
to build on OVMF.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v3:
- expanded the "This" that was starting the commit message body.

 OvmfPkg/Include/IndustryStandard/Xen/memory.h | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/OvmfPkg/Include/IndustryStandard/Xen/memory.h 
b/OvmfPkg/Include/IndustryStandard/Xen/memory.h
index 81e981331a..4a33a26d4e 100644
--- a/OvmfPkg/Include/IndustryStandard/Xen/memory.h
+++ b/OvmfPkg/Include/IndustryStandard/Xen/memory.h
@@ -65,6 +65,29 @@ struct xen_remove_from_physmap {
 typedef struct xen_remove_from_physmap xen_remove_from_physmap_t;
 DEFINE_XEN_GUEST_HANDLE(xen_remove_from_physmap_t);
 
+/*
+ * Returns the pseudo-physical memory map as it was when the domain
+ * was started (specified by XENMEM_set_memory_map).
+ * arg == addr of xen_memory_map_t.
+ */
+#define XENMEM_memory_map   9
+struct xen_memory_map {
+/*
+ * On call the number of entries which can be stored in buffer. On
+ * return the number of entries which have been stored in
+ * buffer.
+ */
+UINT32 nr_entries;
+
+/*
+ * Entries in the buffer are in the same format as returned by the
+ * BIOS INT 0x15 EAX=0xE820 call.
+ */
+XEN_GUEST_HANDLE(void) buffer;
+};
+typedef struct xen_memory_map xen_memory_map_t;
+DEFINE_XEN_GUEST_HANDLE(xen_memory_map_t);
+
 #endif /* __XEN_PUBLIC_MEMORY_H__ */
 
 /*
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45554): https://edk2.groups.io/g/devel/message/45554
Mute This Topic: https://groups.io/mt/32851702/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v5 24/35] OvmfPkg/XenPlatformPei: Reserve VGA memory region, to boot Linux

2019-08-13 Thread Anthony PERARD
Linux panic if the VGA region isn't reserved.

When Linux is booted on EFI system, it expects the memory at 0xa to
_not_ be conventional memory. Otherwise a variable isn't initialised
properly and Linux panic when a virtual console/terminal is asked to be
created.

See for more detail:
https://lists.xenproject.org/archives/html/xen-devel/2019-03/msg02139.html

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v3:
- fix commit message

 OvmfPkg/XenPlatformPei/Xen.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/OvmfPkg/XenPlatformPei/Xen.c b/OvmfPkg/XenPlatformPei/Xen.c
index c4506def9a..c41fecdc48 100644
--- a/OvmfPkg/XenPlatformPei/Xen.c
+++ b/OvmfPkg/XenPlatformPei/Xen.c
@@ -294,6 +294,12 @@ XenPublishRamRegions (
   Status = XenGetE820Map (, );
   ASSERT_EFI_ERROR (Status);
 
+  AddMemoryBaseSizeHob (0, 0xA);
+  //
+  // Video memory + Legacy BIOS region, to allow Linux to boot.
+  //
+  AddReservedMemoryBaseSizeHob (0xA, BASE_1MB - 0xA, TRUE);
+
   LapicBase = PcdGet32 (PcdCpuLocalApicBaseAddress);
   LapicEnd = LapicBase + SIZE_1MB;
   AddIoMemoryRangeHob (LapicBase, LapicEnd);
@@ -312,6 +318,16 @@ XenPublishRamRegions (
 Base = ALIGN_VALUE (Entry->BaseAddr, (UINT64)EFI_PAGE_SIZE);
 End = (Entry->BaseAddr + Entry->Length) & ~(UINT64)EFI_PAGE_MASK;
 
+//
+// Ignore the first 1MB, this is handled before the loop.
+//
+if (Base < BASE_1MB) {
+  Base = BASE_1MB;
+}
+if (Base >= End) {
+  continue;
+}
+
 switch (Entry->Type) {
 case EfiAcpiAddressRangeMemory:
   AddMemoryRangeHob (Base, End);
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45540): https://edk2.groups.io/g/devel/message/45540
Mute This Topic: https://groups.io/mt/32851684/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v5 32/35] OvmfPkg: Introduce PcdXenGrantFrames

2019-08-13 Thread Anthony PERARD
Introduce PcdXenGrantFrames to replace a define in XenBusDxe and allow
the same value to be used in a different module.

The reason for the number of page to be 4 doesn't exist anymore, so
simply remove the comment.

Signed-off-by: Anthony PERARD 
Reviewed-by: Laszlo Ersek 
---

Notes:
v5:
- add missing PcdLib to [LibraryClasses]

v4:
- new patch

 OvmfPkg/OvmfPkg.dec | 3 +++
 OvmfPkg/XenBusDxe/XenBusDxe.inf | 3 +++
 OvmfPkg/XenBusDxe/XenBusDxe.h   | 1 +
 OvmfPkg/XenBusDxe/GrantTable.c  | 3 +--
 4 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index 04d5e29272..d5fee805ef 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -225,6 +225,9 @@ [PcdsFixedAtBuild]
   gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtr|0x0|UINT32|0x17
   gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtrSize|0x0|UINT32|0x32
 
+  ## Number of page frames to use for storing grant table entries.
+  gUefiOvmfPkgTokenSpaceGuid.PcdXenGrantFrames|4|UINT32|0x33
+
 [PcdsDynamic, PcdsDynamicEx]
   gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x10
diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.inf b/OvmfPkg/XenBusDxe/XenBusDxe.inf
index 86e0fb8224..536b49fa8c 100644
--- a/OvmfPkg/XenBusDxe/XenBusDxe.inf
+++ b/OvmfPkg/XenBusDxe/XenBusDxe.inf
@@ -51,6 +51,7 @@ [LibraryClasses]
   XenHypercallLib
   SynchronizationLib
   PrintLib
+  PcdLib
 
 [Protocols]
   gEfiDriverBindingProtocolGuid
@@ -59,3 +60,5 @@ [Protocols]
   gXenBusProtocolGuid
   gXenIoProtocolGuid
 
+[FixedPcd]
+  gUefiOvmfPkgTokenSpaceGuid.PcdXenGrantFrames
diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.h b/OvmfPkg/XenBusDxe/XenBusDxe.h
index 8510361bca..b1dcc3549c 100644
--- a/OvmfPkg/XenBusDxe/XenBusDxe.h
+++ b/OvmfPkg/XenBusDxe/XenBusDxe.h
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 
 
 //
diff --git a/OvmfPkg/XenBusDxe/GrantTable.c b/OvmfPkg/XenBusDxe/GrantTable.c
index 6575e9b88c..1130404cd1 100644
--- a/OvmfPkg/XenBusDxe/GrantTable.c
+++ b/OvmfPkg/XenBusDxe/GrantTable.c
@@ -22,8 +22,7 @@
 
 #define NR_RESERVED_ENTRIES 8
 
-/* NR_GRANT_FRAMES must be less than or equal to that configured in Xen */
-#define NR_GRANT_FRAMES 4
+#define NR_GRANT_FRAMES (FixedPcdGet32 (PcdXenGrantFrames))
 #define NR_GRANT_ENTRIES (NR_GRANT_FRAMES * EFI_PAGE_SIZE / 
sizeof(grant_entry_v1_t))
 
 STATIC grant_entry_v1_t *GrantTable = NULL;
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45544): https://edk2.groups.io/g/devel/message/45544
Mute This Topic: https://groups.io/mt/32851690/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v5 11/35] OvmfPkg/XenPlatformPei: Use mXenHvmloaderInfo to get E820

2019-08-13 Thread Anthony PERARD
Use the already checked pointer mXenHvmloaderInfo to retrieve the E820
table produced by hvmloader.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---
 OvmfPkg/XenPlatformPei/Xen.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/OvmfPkg/XenPlatformPei/Xen.c b/OvmfPkg/XenPlatformPei/Xen.c
index 9962fe9fc7..5c7d7ddc1c 100644
--- a/OvmfPkg/XenPlatformPei/Xen.c
+++ b/OvmfPkg/XenPlatformPei/Xen.c
@@ -53,18 +53,18 @@ XenGetE820Map (
   UINT32 *Count
   )
 {
-  EFI_XEN_OVMF_INFO *Info =
-(EFI_XEN_OVMF_INFO *)(UINTN) OVMF_INFO_PHYSICAL_ADDRESS;
+  //
+  // Get E820 produced by hvmloader
+  //
+  if (mXenHvmloaderInfo != NULL) {
+ASSERT (mXenHvmloaderInfo->E820 < MAX_ADDRESS);
+*Entries = (EFI_E820_ENTRY64 *)(UINTN) mXenHvmloaderInfo->E820;
+*Count = mXenHvmloaderInfo->E820EntriesCount;
 
-  if (AsciiStrCmp ((CHAR8 *) Info->Signature, "XenHVMOVMF")) {
-return EFI_NOT_FOUND;
+return EFI_SUCCESS;
   }
 
-  ASSERT (Info->E820 < MAX_ADDRESS);
-  *Entries = (EFI_E820_ENTRY64 *)(UINTN) Info->E820;
-  *Count = Info->E820EntriesCount;
-
-  return EFI_SUCCESS;
+  return EFI_NOT_FOUND;
 }
 
 /**
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45536): https://edk2.groups.io/g/devel/message/45536
Mute This Topic: https://groups.io/mt/32851680/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v5 13/35] OvmfPkg/Library/XenPlatformLib: New library

2019-08-13 Thread Anthony PERARD
The purpose of XenPlatformLib is to regroup the few functions that are
used in several places to detect if Xen is detected, and to get the
XenInfo HOB.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Reviewed-by: Laszlo Ersek 
---

Notes:
v4:
- fix top-level comment style
- Update Maintainers.txt

v3:
- use SPDX
- add XenPlatformLib.h to [LibraryClasses] in OvmfPkg.dec
- fix typos

 OvmfPkg/OvmfPkg.dec   |  4 ++
 OvmfPkg/OvmfXen.dsc   |  1 +
 .../Library/XenPlatformLib/XenPlatformLib.inf | 33 +
 OvmfPkg/Include/Library/XenPlatformLib.h  | 53 ++
 .../Library/XenPlatformLib/XenPlatformLib.c   | 69 +++
 Maintainers.txt   |  2 +
 6 files changed, 162 insertions(+)
 create mode 100644 OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf
 create mode 100644 OvmfPkg/Include/Library/XenPlatformLib.h
 create mode 100644 OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c

diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index c2a2ebfb95..04d5e29272 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -70,6 +70,10 @@ [LibraryClasses]
   #
   XenIoMmioLib|Include/Library/XenIoMmioLib.h
 
+  ##  @libraryclass  Get information about Xen
+  #
+  XenPlatformLib|Include/Library/XenPlatformLib.h
+
 [Guids]
   gUefiOvmfPkgTokenSpaceGuid  = {0x93bb96af, 0xb9f2, 0x4eb8, {0x94, 
0x62, 0xe0, 0xba, 0x74, 0x56, 0x42, 0x36}}
   gEfiXenInfoGuid = {0xd3b46f3b, 0xd441, 0x1244, {0x9a, 
0x12, 0x0, 0x12, 0x27, 0x3f, 0xc1, 0x4d}}
diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index b40d39e003..22970eda5d 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -194,6 +194,7 @@ [LibraryClasses]
   SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf
   
OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf
   XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf
+  XenPlatformLib|OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf
 
   
Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf
   
TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf
diff --git a/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf 
b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf
new file mode 100644
index 00..32adb246d6
--- /dev/null
+++ b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf
@@ -0,0 +1,33 @@
+## @file
+#  Get information about Xen
+#
+#  This library simply allow to find out if OVMF is running under Xen and
+#  allow to get more information when it is the case.
+#
+#  Copyright (c) 2019, Citrix Systems, Inc.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#
+##
+
+[Defines]
+  INF_VERSION= 0x00010005
+  BASE_NAME  = XenPlatformLib
+  FILE_GUID  = DB54DBB7-8142-4EE5-9364-78C824B582EB
+  MODULE_TYPE= BASE
+  VERSION_STRING = 1.0
+  LIBRARY_CLASS  = XenPlatformLib
+
+[Sources]
+  XenPlatformLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  OvmfPkg/OvmfPkg.dec
+
+[LibraryClasses]
+  HobLib
+
+[Guids]
+  gEfiXenInfoGuid
diff --git a/OvmfPkg/Include/Library/XenPlatformLib.h 
b/OvmfPkg/Include/Library/XenPlatformLib.h
new file mode 100644
index 00..8b8c0d057f
--- /dev/null
+++ b/OvmfPkg/Include/Library/XenPlatformLib.h
@@ -0,0 +1,53 @@
+/** @file
+  Get information about Xen
+
+  This library simply allow to find out if OVMF is running under Xen and
+  allow to get more information when it is the case.
+
+  Copyright (c) 2019, Citrix Systems, Inc.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _XEN_PLATFORM_LIB_H_
+#define _XEN_PLATFORM_LIB_H_
+
+#include 
+
+/**
+  This function detects if OVMF is running on Xen.
+
+  @retval TRUEOVMF is running on Xen
+  @retval FALSE   Xen has not been detected
+**/
+BOOLEAN
+EFIAPI
+XenDetected (
+  VOID
+  );
+
+/**
+  This function detect if OVMF have started via the PVH entry point.
+
+  @retval TRUE  PVH entry point as been used
+  @retval FALSE OVMF have started via the HVM route
+**/
+BOOLEAN
+EFIAPI
+XenPvhDetected (
+  VOID
+  );
+
+/**
+  This function return a pointer to the XenInfo HOB.
+
+  @return  XenInfo pointer or NULL if not available
+**/
+EFI_XEN_INFO *
+EFIAPI
+XenGetInfoHOB (
+  VOID
+  );
+
+#endif
diff --git a/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c 
b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c
new file mode 100644
index 00..974a0e73f1
--- /dev/null
+++ b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c
@@ -0,0 +1,69 @@
+/** @file
+  Get information about Xen
+
+  This library simply allow to find out if OVMF is running under Xen and
+  allow to get more information when it is the case.
+
+  Copyright (c) 2019, Citrix Systems

[edk2-devel] [PATCH v5 12/35] OvmfPkg/XenPlatformPei: Grab RSDP from PVH guest start of day struct

2019-08-13 Thread Anthony PERARD
Check if there's a start of the day struct provided to PVH guest, save
the ACPI RSDP address for later.

This patch import import arch-x86/hvm/start_info.h from xen.git.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v3:
- use SPDX
- use SIGNATURE_32
- fix coding style

 OvmfPkg/XenPlatformPei/XenPlatformPei.inf |   3 +
 OvmfPkg/Include/Guid/XenInfo.h|   4 +
 .../Xen/arch-x86/hvm/start_info.h | 143 ++
 OvmfPkg/XenPlatformPei/Xen.c  |  25 +++
 4 files changed, 175 insertions(+)
 create mode 100644 
OvmfPkg/Include/IndustryStandard/Xen/arch-x86/hvm/start_info.h

diff --git a/OvmfPkg/XenPlatformPei/XenPlatformPei.inf 
b/OvmfPkg/XenPlatformPei/XenPlatformPei.inf
index d1265c365a..4d00206d09 100644
--- a/OvmfPkg/XenPlatformPei/XenPlatformPei.inf
+++ b/OvmfPkg/XenPlatformPei/XenPlatformPei.inf
@@ -84,6 +84,9 @@ [Pcd]
   gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy
   gUefiCpuPkgTokenSpaceGuid.PcdCpuLocalApicBaseAddress
 
+  gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtr
+  gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtrSize
+
 [FixedPcd]
   gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress
 
diff --git a/OvmfPkg/Include/Guid/XenInfo.h b/OvmfPkg/Include/Guid/XenInfo.h
index b052d618fd..25743b3884 100644
--- a/OvmfPkg/Include/Guid/XenInfo.h
+++ b/OvmfPkg/Include/Guid/XenInfo.h
@@ -25,6 +25,10 @@ typedef struct {
   /// Hypervisor minor version.
   ///
   UINT16 VersionMinor;
+  ///
+  /// Pointer to the RSDP found in the hvm_start_info provided to a PVH guest
+  ///
+  VOID *RsdpPvh;
 } EFI_XEN_INFO;
 
 extern EFI_GUID gEfiXenInfoGuid;
diff --git a/OvmfPkg/Include/IndustryStandard/Xen/arch-x86/hvm/start_info.h 
b/OvmfPkg/Include/IndustryStandard/Xen/arch-x86/hvm/start_info.h
new file mode 100644
index 00..15708d6dd5
--- /dev/null
+++ b/OvmfPkg/Include/IndustryStandard/Xen/arch-x86/hvm/start_info.h
@@ -0,0 +1,143 @@
+/*
+ * SPDX-License-Identifier: MIT
+ *
+ * Copyright (c) 2016, Citrix Systems, Inc.
+ */
+
+#ifndef __XEN_PUBLIC_ARCH_X86_HVM_START_INFO_H__
+#define __XEN_PUBLIC_ARCH_X86_HVM_START_INFO_H__
+
+/*
+ * Start of day structure passed to PVH guests and to HVM guests in %ebx.
+ *
+ * NOTE: nothing will be loaded at physical address 0, so a 0 value in any
+ * of the address fields should be treated as not present.
+ *
+ *  0 ++
+ *| magic  | Contains the magic value XEN_HVM_START_MAGIC_VALUE
+ *|| ("xEn3" with the 0x80 bit of the "E" set).
+ *  4 ++
+ *| version| Version of this structure. Current version is 1. New
+ *|| versions are guaranteed to be backwards-compatible.
+ *  8 ++
+ *| flags  | SIF_xxx flags.
+ * 12 ++
+ *| nr_modules | Number of modules passed to the kernel.
+ * 16 ++
+ *| modlist_paddr  | Physical address of an array of modules
+ *|| (layout of the structure below).
+ * 24 ++
+ *| cmdline_paddr  | Physical address of the command line,
+ *|| a zero-terminated ASCII string.
+ * 32 ++
+ *| rsdp_paddr | Physical address of the RSDP ACPI data structure.
+ * 40 ++
+ *| memmap_paddr   | Physical address of the (optional) memory map. Only
+ *|| present in version 1 and newer of the structure.
+ * 48 ++
+ *| memmap_entries | Number of entries in the memory map table. Zero
+ *|| if there is no memory map being provided. Only
+ *|| present in version 1 and newer of the structure.
+ * 52 ++
+ *| reserved   | Version 1 and newer only.
+ * 56 ++
+ *
+ * The layout of each entry in the module structure is the following:
+ *
+ *  0 ++
+ *| paddr  | Physical address of the module.
+ *  8 ++
+ *| size   | Size of the module in bytes.
+ * 16 ++
+ *| cmdline_paddr  | Physical address of the command line,
+ *|| a zero-terminated ASCII string.
+ * 24 ++
+ *| reserved   |
+ * 32 ++
+ *
+ * The layout of each entry in the memory map table is as follows:
+ *
+ *  0 ++
+ *| addr   | Base address
+ *  8 ++
+ *| size   | Size of mapping in bytes
+ * 16 ++
+ *| type   | Type of mapping as defined between the hypervisor
+ *|| and guest. See XEN_HVM_MEMMAP_TYPE_* values below.
+ * 20 +|
+ *| reserved   |
+ * 24 ++
+ *
+ * The address and sizes are always a 64bit little endian unsigned integer.
+ *
+ * NB: Xen on x86 will always try t

[edk2-devel] [PATCH v5 27/35] OvmfPkg/PlatformBootManagerLib: Use XenDetected from XenPlatformLib

2019-08-13 Thread Anthony PERARD
Replace the XenDetected() implementation by the one from
XenPlatformLib.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Reviewed-by: Laszlo Ersek 
---

Notes:
v4:
- removed gEfiXenInfoGuid from Guids list and the associated include of
  Guid/XenInfo.h

v3:
- new patch

 .../PlatformBootManagerLib.inf|  2 +-
 .../PlatformBootManagerLib/BdsPlatform.c  | 34 +--
 2 files changed, 2 insertions(+), 34 deletions(-)

diff --git a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf 
b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
index 060a3ab4c5..04d614cd49 100644
--- a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
+++ b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
@@ -54,6 +54,7 @@ [LibraryClasses]
   UefiLib
   PlatformBmPrintScLib
   Tcg2PhysicalPresenceLib
+  XenPlatformLib
 
 [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent
@@ -73,7 +74,6 @@ [Protocols]
   gEfiFirmwareVolume2ProtocolGuid   # PROTOCOL SOMETIMES_CONSUMED
 
 [Guids]
-  gEfiXenInfoGuid
   gEfiEndOfDxeEventGroupGuid
   gRootBridgesConnectedEventGroupGuid
   gUefiShellFileGuid
diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c 
b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
index 797731a41c..d5d5d20fd8 100644
--- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
+++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
@@ -7,11 +7,11 @@
 **/
 
 #include "BdsPlatform.h"
-#include 
 #include 
 #include 
 #include 
 #include 
+#include 
 
 
 //
@@ -1225,38 +1225,6 @@ PciAcpiInitialization (
   IoOr16 ((PciRead32 (Pmba) & ~BIT0) + 4, BIT0);
 }
 
-/**
-  This function detects if OVMF is running on Xen.
-
-**/
-STATIC
-BOOLEAN
-XenDetected (
-  VOID
-  )
-{
-  EFI_HOB_GUID_TYPE *GuidHob;
-  STATIC INTN   FoundHob = -1;
-
-  if (FoundHob == 0) {
-return FALSE;
-  } else if (FoundHob == 1) {
-return TRUE;
-  }
-
-  //
-  // See if a XenInfo HOB is available
-  //
-  GuidHob = GetFirstGuidHob ();
-  if (GuidHob == NULL) {
-FoundHob = 0;
-return FALSE;
-  }
-
-  FoundHob = 1;
-  return TRUE;
-}
-
 EFI_STATUS
 EFIAPI
 ConnectRecursivelyIfPciMassStorage (
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45538): https://edk2.groups.io/g/devel/message/45538
Mute This Topic: https://groups.io/mt/32851682/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v5 25/35] OvmfPkg/XenPlatformPei: Ignore missing PCI Host Bridge on Xen PVH

2019-08-13 Thread Anthony PERARD
When the device ID of the host bridge is unknown, check if we are
running as a PVH guest as there is no PCI bus in that case.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v3:
- Remove use of XEN_PVH_PCI_HOST_BRIDGE_DEVICE_ID, and simply don't set
  PcdOvmfHostBridgePciDevId.

v2:
- Use new XEN_PVH_PCI_HOST_BRIDGE_DEVICE_ID macro

 OvmfPkg/XenPlatformPei/Platform.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/OvmfPkg/XenPlatformPei/Platform.c 
b/OvmfPkg/XenPlatformPei/Platform.c
index 2f42ca6ccd..717fd0ab1a 100644
--- a/OvmfPkg/XenPlatformPei/Platform.c
+++ b/OvmfPkg/XenPlatformPei/Platform.c
@@ -283,6 +283,12 @@ MiscInitialization (
   AcpiEnBit  = ICH9_ACPI_CNTL_ACPI_EN;
   break;
 default:
+  if (XenPvhDetected ()) {
+//
+// There is no PCI bus in this case
+//
+return;
+  }
   DEBUG ((DEBUG_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",
 __FUNCTION__, mHostBridgeDevId));
   ASSERT (FALSE);
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45550): https://edk2.groups.io/g/devel/message/45550
Mute This Topic: https://groups.io/mt/32851698/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v5 30/35] OvmfPkg/OvmfXen: Introduce XenTimerDxe

2019-08-13 Thread Anthony PERARD
"OvmfPkg/8254TimerDxe" is replaced with a Xen-specific
EFI_TIMER_ARCH_PROTOCOL implementation. Also remove
8259InterruptControllerDxe as it is not used anymore.

This Timer uses the local APIC timer as time source as it can work on
both a Xen PVH guest and an HVM one.

Based on the "OvmfPkg/8254TimerDxe" implementation.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v4:
- fix the commit message to reflect the fact that the original code as
  moved.
- Update Maintainers.txt

v3:
- rebased, SPDX, copyright

v2:
- Use InitializeApicTimer instead of WriteLocalApicReg
- rework comments (remove many that don't apply)
- remove unused includes, and libs
- have a macro to the timervector.
- cleanup, copyright
- rework calculation of TimerCount, value to be use by the APIC timer
- check for overflow of TimerPeriod, with the apic timer, the period can
  be up to about 42s on Xen (or even higher by changing the DivideValue).

 OvmfPkg/OvmfXen.dsc |   3 +-
 OvmfPkg/OvmfXen.fdf |   3 +-
 OvmfPkg/XenTimerDxe/XenTimerDxe.inf |  42 
 OvmfPkg/XenTimerDxe/XenTimerDxe.h   | 177 ++
 OvmfPkg/XenTimerDxe/XenTimerDxe.c   | 355 
 Maintainers.txt |   1 +
 6 files changed, 577 insertions(+), 4 deletions(-)
 create mode 100644 OvmfPkg/XenTimerDxe/XenTimerDxe.inf
 create mode 100644 OvmfPkg/XenTimerDxe/XenTimerDxe.h
 create mode 100644 OvmfPkg/XenTimerDxe/XenTimerDxe.c

diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index 477d8c76a1..54ac910d8e 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -547,10 +547,9 @@ [Components]
   MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
 
   MdeModulePkg/Universal/EbcDxe/EbcDxe.inf
-  OvmfPkg/8259InterruptControllerDxe/8259.inf
+  OvmfPkg/XenTimerDxe/XenTimerDxe.inf
   UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf
   UefiCpuPkg/CpuDxe/CpuDxe.inf
-  OvmfPkg/8254TimerDxe/8254Timer.inf
   OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf
   OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf
   MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf {
diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf
index 49997fee9b..fa0830a324 100644
--- a/OvmfPkg/OvmfXen.fdf
+++ b/OvmfPkg/OvmfXen.fdf
@@ -298,10 +298,9 @@ [FV.DXEFV]
 INF  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
 INF  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
 INF  MdeModulePkg/Universal/EbcDxe/EbcDxe.inf
-INF  OvmfPkg/8259InterruptControllerDxe/8259.inf
+INF  OvmfPkg/XenTimerDxe/XenTimerDxe.inf
 INF  UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf
 INF  UefiCpuPkg/CpuDxe/CpuDxe.inf
-INF  OvmfPkg/8254TimerDxe/8254Timer.inf
 INF  OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf
 INF  OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf
 INF  MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf
diff --git a/OvmfPkg/XenTimerDxe/XenTimerDxe.inf 
b/OvmfPkg/XenTimerDxe/XenTimerDxe.inf
new file mode 100644
index 00..add1d01bbf
--- /dev/null
+++ b/OvmfPkg/XenTimerDxe/XenTimerDxe.inf
@@ -0,0 +1,42 @@
+## @file
+# Local APIC timer driver that provides Timer Arch protocol.
+#
+# Copyright (c) 2005 - 2019, Intel Corporation. All rights reserved.
+# Copyright (c) 2019, Citrix Systems, Inc.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION= 0x00010005
+  BASE_NAME  = XenTimerDxe
+  FILE_GUID  = 52fe8196-f9de-4d07-b22f-51f77a0e7c41
+  MODULE_TYPE= DXE_DRIVER
+  VERSION_STRING = 1.0
+
+  ENTRY_POINT= TimerDriverInitialize
+
+[Packages]
+  MdePkg/MdePkg.dec
+  UefiCpuPkg/UefiCpuPkg.dec
+  OvmfPkg/OvmfPkg.dec
+
+[LibraryClasses]
+  UefiBootServicesTableLib
+  BaseLib
+  DebugLib
+  UefiDriverEntryPoint
+  LocalApicLib
+
+[Sources]
+  XenTimerDxe.h
+  XenTimerDxe.c
+
+[Protocols]
+  gEfiCpuArchProtocolGuid   ## CONSUMES
+  gEfiTimerArchProtocolGuid ## PRODUCES
+[Pcd]
+  gEfiMdePkgTokenSpaceGuid.PcdFSBClock  ## CONSUMES
+[Depex]
+  gEfiCpuArchProtocolGuid
diff --git a/OvmfPkg/XenTimerDxe/XenTimerDxe.h 
b/OvmfPkg/XenTimerDxe/XenTimerDxe.h
new file mode 100644
index 00..e0a3d95fd0
--- /dev/null
+++ b/OvmfPkg/XenTimerDxe/XenTimerDxe.h
@@ -0,0 +1,177 @@
+/** @file
+  Private data structures
+
+Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2019, Citrix Systems, Inc.
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef _TIMER_H_
+#define _TIMER_H_
+
+#include 
+
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+// The default timer tick duration is set to 10 ms = 10 100 ns units
+//
+#define DEFAULT_TIMER_TICK_DURATION 10
+
+//
+// The Timer Vector use for in

[edk2-devel] [PATCH v5 34/35] OvmfPkg: Move XenRealTimeClockLib from ArmVirtPkg

2019-08-13 Thread Anthony PERARD
Move XenRealTimeClockLib from ArmVirtPkg to OvmfPkg so it can be used
from the OvmfPkg by the following patch, "OvmfPkg/OvmfXen: use
RealTimeClockRuntimeDxe from EmbeddedPkg"

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Reviewed-by: Laszlo Ersek 
---

Notes:
v4:
- Update Maintainers.txt

v3:
- fix the commit message body

 ArmVirtPkg/ArmVirtXen.dsc   | 2 +-
 .../Library/XenRealTimeClockLib/XenRealTimeClockLib.inf | 0
 .../Library/XenRealTimeClockLib/XenRealTimeClockLib.c   | 0
 Maintainers.txt | 2 +-
 4 files changed, 2 insertions(+), 2 deletions(-)
 rename {ArmVirtPkg => 
OvmfPkg}/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf (100%)
 rename {ArmVirtPkg => 
OvmfPkg}/Library/XenRealTimeClockLib/XenRealTimeClockLib.c (100%)

diff --git a/ArmVirtPkg/ArmVirtXen.dsc b/ArmVirtPkg/ArmVirtXen.dsc
index 79304ee61d..1b42a9a813 100644
--- a/ArmVirtPkg/ArmVirtXen.dsc
+++ b/ArmVirtPkg/ArmVirtXen.dsc
@@ -27,7 +27,7 @@ [Defines]
 
 [LibraryClasses]
   
SerialPortLib|OvmfPkg/Library/XenConsoleSerialPortLib/XenConsoleSerialPortLib.inf
-  
RealTimeClockLib|ArmVirtPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf
+  RealTimeClockLib|OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf
   XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf
 
   
ArmGenericTimerCounterLib|ArmVirtPkg/Library/XenArmGenericTimerVirtCounterLib/XenArmGenericTimerVirtCounterLib.inf
diff --git a/ArmVirtPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf 
b/OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf
similarity index 100%
rename from ArmVirtPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf
rename to OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf
diff --git a/ArmVirtPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.c 
b/OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.c
similarity index 100%
rename from ArmVirtPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.c
rename to OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.c
diff --git a/Maintainers.txt b/Maintainers.txt
index 79defd13bf..919baccc56 100644
--- a/Maintainers.txt
+++ b/Maintainers.txt
@@ -114,7 +114,6 @@ R: Leif Lindholm 
 ArmVirtPkg: modules used on Xen
 F: ArmVirtPkg/ArmVirtXen.*
 F: ArmVirtPkg/Library/XenArmGenericTimerVirtCounterLib/
-F: ArmVirtPkg/Library/XenRealTimeClockLib/
 F: ArmVirtPkg/Library/XenVirtMemInfoLib/
 F: ArmVirtPkg/PrePi/
 F: ArmVirtPkg/XenAcpiPlatformDxe/
@@ -374,6 +373,7 @@ F: OvmfPkg/Library/XenConsoleSerialPortLib/
 F: OvmfPkg/Library/XenHypercallLib/
 F: OvmfPkg/Library/XenIoMmioLib/
 F: OvmfPkg/Library/XenPlatformLib/
+F: OvmfPkg/Library/XenRealTimeClockLib/
 F: OvmfPkg/OvmfXen.*
 F: OvmfPkg/OvmfXenElfHeaderGenerator.c
 F: OvmfPkg/PlatformPei/MemDetect.c
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45539): https://edk2.groups.io/g/devel/message/45539
Mute This Topic: https://groups.io/mt/32851683/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v5 22/35] OvmfPkg/XenPlatformPei: no hvmloader: get the E820 table via hypercall

2019-08-13 Thread Anthony PERARD
When the Xen PVH entry point has been used, hvmloader hasn't run and
hasn't prepared an E820 table. The only way left to get an E820 table
is to ask Xen via an hypercall.  We keep the result cached to avoid
making a second hypercall which would give the same result.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v5:
- fix commit message, the hypercall *can* be made several time, but we
  still cache the result.

v3:
- fix commit message
- add 'm' prefix to the global variables
  and make them static

 OvmfPkg/XenPlatformPei/Xen.c | 46 +++-
 1 file changed, 45 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/XenPlatformPei/Xen.c b/OvmfPkg/XenPlatformPei/Xen.c
index f26f0e56dd..72f6f37b46 100644
--- a/OvmfPkg/XenPlatformPei/Xen.c
+++ b/OvmfPkg/XenPlatformPei/Xen.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "Platform.h"
 #include "Xen.h"
@@ -40,6 +41,8 @@ EFI_XEN_INFO mXenInfo;
 // Only the E820 table is used by OVMF.
 //
 EFI_XEN_OVMF_INFO *mXenHvmloaderInfo;
+STATIC EFI_E820_ENTRY64 mE820Entries[128];
+STATIC UINT32 mE820EntriesCount;
 
 /**
   Returns E820 map provided by Xen
@@ -55,6 +58,12 @@ XenGetE820Map (
   UINT32 *Count
   )
 {
+  INTN ReturnCode;
+  xen_memory_map_t Parameters;
+  UINTN LoopIndex;
+  UINTN Index;
+  EFI_E820_ENTRY64 TmpEntry;
+
   //
   // Get E820 produced by hvmloader
   //
@@ -66,7 +75,42 @@ XenGetE820Map (
 return EFI_SUCCESS;
   }
 
-  return EFI_NOT_FOUND;
+  //
+  // Otherwise, get the E820 table from the Xen hypervisor
+  //
+
+  if (mE820EntriesCount > 0) {
+*Entries = mE820Entries;
+*Count = mE820EntriesCount;
+return EFI_SUCCESS;
+  }
+
+  Parameters.nr_entries = 128;
+  set_xen_guest_handle (Parameters.buffer, mE820Entries);
+
+  // Returns a errno
+  ReturnCode = XenHypercallMemoryOp (XENMEM_memory_map, );
+  ASSERT (ReturnCode == 0);
+
+  mE820EntriesCount = Parameters.nr_entries;
+
+  //
+  // Sort E820 entries
+  //
+  for (LoopIndex = 1; LoopIndex < mE820EntriesCount; LoopIndex++) {
+for (Index = LoopIndex; Index < mE820EntriesCount; Index++) {
+  if (mE820Entries[Index - 1].BaseAddr > mE820Entries[Index].BaseAddr) {
+TmpEntry = mE820Entries[Index];
+mE820Entries[Index] = mE820Entries[Index - 1];
+mE820Entries[Index - 1] = TmpEntry;
+  }
+}
+  }
+
+  *Count = mE820EntriesCount;
+  *Entries = mE820Entries;
+
+  return EFI_SUCCESS;
 }
 
 /**
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45547): https://edk2.groups.io/g/devel/message/45547
Mute This Topic: https://groups.io/mt/32851694/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v5 10/35] OvmfPkg/XenPlatformPei: Detect OVMF_INFO from hvmloader

2019-08-13 Thread Anthony PERARD
EFI_XEN_OVMF_INFO is only useful to retrieve the E820 table. The
mXenHvmloaderInfo isn't used yet, but will be use in a further patch to
retrieve the E820 table.

Also remove the unused pointer from the XenInfo HOB as that information
is only useful in the XenPlatformPei.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v3:
- fix coding style
- fix commit message

 OvmfPkg/Include/Guid/XenInfo.h |  4 
 OvmfPkg/PlatformPei/Xen.c  |  3 ---
 OvmfPkg/XenPlatformPei/Xen.c   | 25 +++--
 3 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/OvmfPkg/Include/Guid/XenInfo.h b/OvmfPkg/Include/Guid/XenInfo.h
index 25d76a7828..b052d618fd 100644
--- a/OvmfPkg/Include/Guid/XenInfo.h
+++ b/OvmfPkg/Include/Guid/XenInfo.h
@@ -18,10 +18,6 @@ typedef struct {
   ///
   VOID *HyperPages;
   ///
-  /// Location of the hvm_info page.
-  ///
-  VOID *HvmInfo;
-  ///
   /// Hypervisor major version.
   ///
   UINT16 VersionMajor;
diff --git a/OvmfPkg/PlatformPei/Xen.c b/OvmfPkg/PlatformPei/Xen.c
index 89dc4143b2..3e15b32a73 100644
--- a/OvmfPkg/PlatformPei/Xen.c
+++ b/OvmfPkg/PlatformPei/Xen.c
@@ -98,9 +98,6 @@ XenConnect (
   mXenInfo.VersionMajor = (UINT16)(XenVersion >> 16);
   mXenInfo.VersionMinor = (UINT16)(XenVersion & 0x);
 
-  /* TBD: Locate hvm_info and reserve it away. */
-  mXenInfo.HvmInfo = NULL;
-
   BuildGuidDataHob (
 ,
 ,
diff --git a/OvmfPkg/XenPlatformPei/Xen.c b/OvmfPkg/XenPlatformPei/Xen.c
index f4d0d1c73b..9962fe9fc7 100644
--- a/OvmfPkg/XenPlatformPei/Xen.c
+++ b/OvmfPkg/XenPlatformPei/Xen.c
@@ -33,6 +33,12 @@ STATIC UINT32 mXenLeaf = 0;
 
 EFI_XEN_INFO mXenInfo;
 
+//
+// Location of the firmware info struct setup by hvmloader.
+// Only the E820 table is used by OVMF.
+//
+EFI_XEN_OVMF_INFO *mXenHvmloaderInfo;
+
 /**
   Returns E820 map provided by Xen
 
@@ -78,6 +84,8 @@ XenConnect (
   UINT32 TransferReg;
   UINT32 TransferPages;
   UINT32 XenVersion;
+  EFI_XEN_OVMF_INFO *Info;
+  CHAR8 Sig[sizeof (Info->Signature) + 1];
 
   AsmCpuid (XenLeaf + 2, , , NULL, NULL);
   mXenInfo.HyperPages = AllocatePages (TransferPages);
@@ -97,8 +105,21 @@ XenConnect (
   mXenInfo.VersionMajor = (UINT16)(XenVersion >> 16);
   mXenInfo.VersionMinor = (UINT16)(XenVersion & 0x);
 
-  /* TBD: Locate hvm_info and reserve it away. */
-  mXenInfo.HvmInfo = NULL;
+  //
+  // Check if there are information left by hvmloader
+  //
+
+  Info = (EFI_XEN_OVMF_INFO *)(UINTN) OVMF_INFO_PHYSICAL_ADDRESS;
+  //
+  // Copy the signature, and make it null-terminated.
+  //
+  AsciiStrnCpyS (Sig, sizeof (Sig), (CHAR8 *) >Signature,
+sizeof (Info->Signature));
+  if (AsciiStrCmp (Sig, "XenHVMOVMF") == 0) {
+mXenHvmloaderInfo = Info;
+  } else {
+mXenHvmloaderInfo = NULL;
+  }
 
   BuildGuidDataHob (
 ,
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45543): https://edk2.groups.io/g/devel/message/45543
Mute This Topic: https://groups.io/mt/32851687/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v5 14/35] OvmfPkg/AcpiPlatformDxe: Use XenPlatformLib

2019-08-13 Thread Anthony PERARD
This patch replace the XenDetected() function by the one in
XenPlatformLib.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Reviewed-by: Laszlo Ersek 
---

Notes:
v4:
- removed gEfiXenInfoGuid from Guids list.

v3:
- new patch, splited from the next patch
  (which was OvmfPkg/AcpiPlatformDxe: Use PVH RSDP if exist)

 OvmfPkg/OvmfPkgIa32.dsc |  1 +
 OvmfPkg/OvmfPkgIa32X64.dsc  |  1 +
 OvmfPkg/OvmfPkgX64.dsc  |  1 +
 OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf |  3 +--
 OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h  |  6 +-
 OvmfPkg/AcpiPlatformDxe/Xen.c   | 24 -
 6 files changed, 5 insertions(+), 31 deletions(-)

diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index 6ab7300186..66e944436a 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -200,6 +200,7 @@ [LibraryClasses]
   SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf
   
OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf
   XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf
+  XenPlatformLib|OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf
 
 !if $(TPM2_ENABLE) == TRUE
   Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index f163aa2671..51c2bfb44f 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -205,6 +205,7 @@ [LibraryClasses]
   SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf
   
OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf
   XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf
+  XenPlatformLib|OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf
 
 !if $(TPM2_ENABLE) == TRUE
   Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index fa98f16a3f..ba7a758844 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -205,6 +205,7 @@ [LibraryClasses]
   SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf
   
OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf
   XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf
+  XenPlatformLib|OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf
 
 !if $(TPM2_ENABLE) == TRUE
   Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf
diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf 
b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
index 24634eeae2..e486b8afa5 100644
--- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
+++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
@@ -44,13 +44,13 @@ [LibraryClasses]
   DebugLib
   UefiBootServicesTableLib
   UefiDriverEntryPoint
-  HobLib
   QemuFwCfgLib
   QemuFwCfgS3Lib
   MemoryAllocationLib
   BaseLib
   DxeServicesTableLib
   OrderedCollectionLib
+  XenPlatformLib
 
 [Protocols]
   gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_CONSUMED
@@ -58,7 +58,6 @@ [Protocols]
   gEfiPciIoProtocolGuid # PROTOCOL SOMETIMES_CONSUMED
 
 [Guids]
-  gEfiXenInfoGuid
   gRootBridgesConnectedEventGroupGuid
 
 [Pcd]
diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h 
b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h
index 3037afcf18..9597e028e4 100644
--- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h
+++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -52,11 +53,6 @@ QemuInstallAcpiTable (
   OUT  UINTN *TableKey
   );
 
-BOOLEAN
-XenDetected (
-  VOID
-  );
-
 EFI_STATUS
 EFIAPI
 InstallXenTables (
diff --git a/OvmfPkg/AcpiPlatformDxe/Xen.c b/OvmfPkg/AcpiPlatformDxe/Xen.c
index e4e47bf0e8..82794b933e 100644
--- a/OvmfPkg/AcpiPlatformDxe/Xen.c
+++ b/OvmfPkg/AcpiPlatformDxe/Xen.c
@@ -9,8 +9,6 @@
 **/ 
 
 #include "AcpiPlatform.h"
-#include 
-#include 
 #include 
 
 #define XEN_ACPI_PHYSICAL_ADDRESS 0x000EA020
@@ -18,28 +16,6 @@
 
 EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER  *XenAcpiRsdpStructurePtr = NULL;
 
-/**
-  This function detects if OVMF is running on Xen.
-
-**/
-BOOLEAN
-XenDetected (
-  VOID
-  )
-{
-  EFI_HOB_GUID_TYPE *GuidHob;
-
-  //
-  // See if a XenInfo HOB is available
-  //
-  GuidHob = GetFirstGuidHob ();
-  if (GuidHob == NULL) {
-return FALSE;
-  }
-
-  return TRUE;
-}
-
 /**
   Get the address of Xen ACPI Root System Description Pointer (RSDP)
   structure.
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45549): https://edk2.groups.io/g/devel/message/45549
Mute This Topic: https://groups.io/mt/32851697/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: ht

[edk2-devel] [PATCH v5 35/35] OvmfPkg/OvmfXen: use RealTimeClockRuntimeDxe from EmbeddedPkg

2019-08-13 Thread Anthony PERARD
A Xen PVH guest doesn't have a RTC that OVMF would expect, so
PcatRealTimeClockRuntimeDxe fails to initialize and prevent the
firmware from finish to boot. To prevent that, we will use
XenRealTimeClockLib which simply always return the same time.
This will work on both Xen PVH and HVM guests.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v3:
- moved RealTimeClockLib|*/XenRealTimeClockLib.inf to the global
  [LibraryClasses]

 OvmfPkg/OvmfXen.dsc | 3 ++-
 OvmfPkg/OvmfXen.fdf | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index 5e07b37279..5a31f75f05 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -199,6 +199,7 @@ [LibraryClasses]
 
   
Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf
   
TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf
+  RealTimeClockLib|OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf
 
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
@@ -564,7 +565,7 @@ [Components]
   }
   MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf
   MdeModulePkg/Universal/Metronome/Metronome.inf
-  PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf
+  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
   MdeModulePkg/Universal/DriverHealthManagerDxe/DriverHealthManagerDxe.inf
   MdeModulePkg/Universal/BdsDxe/BdsDxe.inf {
 
diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf
index 517a492f14..e6e9e184ef 100644
--- a/OvmfPkg/OvmfXen.fdf
+++ b/OvmfPkg/OvmfXen.fdf
@@ -307,7 +307,7 @@ [FV.DXEFV]
 INF  MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf
 INF  MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf
 INF  MdeModulePkg/Universal/Metronome/Metronome.inf
-INF  PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf
+INF  EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
 
 INF  OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf
 INF  OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45551): https://edk2.groups.io/g/devel/message/45551
Mute This Topic: https://groups.io/mt/32851699/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v5 33/35] OvmfPkg: Introduce XenIoPvhDxe to initialize Grant Tables

2019-08-13 Thread Anthony PERARD
XenIoPvhDxe use XenIoMmioLib to reserve some space to be use by the
Grant Tables.

The call is only done if it is necessary, we simply detect if the
guest is PVH, as in this case there is currently no PCI bus, and no
PCI Xen platform device which would start the XenIoPciDxe and allocate
the space for the Grant Tables.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Reviewed-by: Laszlo Ersek 
---

Notes:
v5:
- add missing PcdLib as #include and in [LibraryClasses]

v4:
- Removed XenIoPvhDxeNotifyExitBoot() which was doing action that should
  not be done in an ExitBootServices notification.
  (InitializeXenIoPvhDxe() has been cleaned up following this.)
- Use new PcdXenGrantFrames.
- Some coding style fix
- Update Maintainers.txt

v3:
- downgrade type to DXE_DRIVER
- use SPDX
- rework InitializeXenIoPvhDxe, and handle errors properly.
- Free the reserved allocation in ExitBootServices even if the XenIo
  protocol could successfully been uninstalled.

v2:
- do allocation in EntryPoint like the other user of XenIoMmioLib.
- allocate memory instead of hardcoded addr.
- cleanup, add copyright
- detect if we are running in PVH mode

 OvmfPkg/OvmfXen.dsc |  2 ++
 OvmfPkg/OvmfXen.fdf |  1 +
 OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf | 36 +++
 OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.c   | 54 +
 Maintainers.txt |  1 +
 5 files changed, 94 insertions(+)
 create mode 100644 OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf
 create mode 100644 OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.c

diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index e719a168f8..5e07b37279 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -195,6 +195,7 @@ [LibraryClasses]
   
OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf
   XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf
   XenPlatformLib|OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf
+  XenIoMmioLib|OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.inf
 
   
Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf
   
TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf
@@ -583,6 +584,7 @@ [Components]
   NULL|OvmfPkg/Csm/LegacyBootMaintUiLib/LegacyBootMaintUiLib.inf
 !endif
   }
+  OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf
   OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
   OvmfPkg/XenBusDxe/XenBusDxe.inf
   OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf
index 5c1a925d6a..517a492f14 100644
--- a/OvmfPkg/OvmfXen.fdf
+++ b/OvmfPkg/OvmfXen.fdf
@@ -309,6 +309,7 @@ [FV.DXEFV]
 INF  MdeModulePkg/Universal/Metronome/Metronome.inf
 INF  PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf
 
+INF  OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf
 INF  OvmfPkg/XenIoPciDxe/XenIoPciDxe.inf
 INF  OvmfPkg/XenBusDxe/XenBusDxe.inf
 INF  OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.inf
diff --git a/OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf 
b/OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf
new file mode 100644
index 00..1c27f8aae0
--- /dev/null
+++ b/OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.inf
@@ -0,0 +1,36 @@
+## @file
+#  Driver for the XenIo protocol
+#
+#  Copyright (c) 2019, Citrix Systems, Inc.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION   = 0x00010005
+  BASE_NAME = XenIoPvhDxe
+  FILE_GUID = 7a567cc4-0e75-4d7a-a305-c3db109b53ad
+  MODULE_TYPE   = DXE_DRIVER
+  VERSION_STRING= 1.0
+  ENTRY_POINT   = InitializeXenIoPvhDxe
+
+[Packages]
+  MdePkg/MdePkg.dec
+  OvmfPkg/OvmfPkg.dec
+
+[Sources]
+  XenIoPvhDxe.c
+
+[LibraryClasses]
+  MemoryAllocationLib
+  PcdLib
+  UefiDriverEntryPoint
+  XenIoMmioLib
+  XenPlatformLib
+
+[FixedPcd]
+  gUefiOvmfPkgTokenSpaceGuid.PcdXenGrantFrames
+
+[Depex]
+  TRUE
diff --git a/OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.c 
b/OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.c
new file mode 100644
index 00..9264a85df1
--- /dev/null
+++ b/OvmfPkg/XenIoPvhDxe/XenIoPvhDxe.c
@@ -0,0 +1,54 @@
+/** @file
+
+  Driver for the XenIo protocol
+
+  This driver simply allocate space for the grant tables.
+
+  Copyright (c) 2019, Citrix Systems, Inc.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include 
+#include 
+#include 
+#include 
+
+EFI_STATUS
+EFIAPI
+InitializeXenIoPvhDxe (
+  IN EFI_HANDLE   ImageHandle,
+  IN EFI_SYSTEM_TABLE *SystemTable
+  )
+{
+  VOID  *Allocation;
+  EFI_STATUSStatus;
+  EFI_HANDLEXenIoHandle;
+
+  Allocation = NULL;
+  XenIoHandle = NULL;
+
+  if (!XenPvhDetected ()) {
+return EFI_UNSUPPORTED;
+  }
+
+  Allocation = AllocateReservedPages (FixedPcdGet32 (PcdXenGrantFrames));
+  if (Allocation == NULL) {
+Status = EFI_OUT_OF_RESOURCES

[edk2-devel] [PATCH v5 19/35] OvmfPkg/XenPlatformPei: Setup HyperPages earlier

2019-08-13 Thread Anthony PERARD
We are going to need to make an hypercall in order to retreive the E820
table from the hypervisor before been able to setup the memory.

Calling XenConnect earlier will allow to setup the XenHypercallLib
earlier to allow to make hypercalls.

While here, add some comments in XenConnect().

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---
 OvmfPkg/XenPlatformPei/Platform.h |  5 +
 OvmfPkg/XenPlatformPei/Platform.c |  2 ++
 OvmfPkg/XenPlatformPei/Xen.c  | 23 ---
 3 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/OvmfPkg/XenPlatformPei/Platform.h 
b/OvmfPkg/XenPlatformPei/Platform.h
index 925df31f88..4a80057bdc 100644
--- a/OvmfPkg/XenPlatformPei/Platform.h
+++ b/OvmfPkg/XenPlatformPei/Platform.h
@@ -79,6 +79,11 @@ InstallClearCacheCallback (
   VOID
   );
 
+EFI_STATUS
+XenConnect (
+  VOID
+  );
+
 EFI_STATUS
 InitializeXen (
   VOID
diff --git a/OvmfPkg/XenPlatformPei/Platform.c 
b/OvmfPkg/XenPlatformPei/Platform.c
index 5809eadb0b..6aaafc3ee9 100644
--- a/OvmfPkg/XenPlatformPei/Platform.c
+++ b/OvmfPkg/XenPlatformPei/Platform.c
@@ -416,6 +416,8 @@ InitializeXenPlatform (
 CpuDeadLoop ();
   }
 
+  XenConnect ();
+
   BootModeInitialization ();
   AddressWidthInitialization ();
 
diff --git a/OvmfPkg/XenPlatformPei/Xen.c b/OvmfPkg/XenPlatformPei/Xen.c
index 2105304c41..29b42b746c 100644
--- a/OvmfPkg/XenPlatformPei/Xen.c
+++ b/OvmfPkg/XenPlatformPei/Xen.c
@@ -72,14 +72,11 @@ XenGetE820Map (
 /**
   Connects to the Hypervisor.
 
-  @param  XenLeaf CPUID index used to connect.
-
   @return EFI_STATUS
 
 **/
 EFI_STATUS
 XenConnect (
-  UINT32 XenLeaf
   )
 {
   UINT32 Index;
@@ -91,7 +88,13 @@ XenConnect (
   UINT32 *PVHResetVectorData;
   RETURN_STATUS Status;
 
-  AsmCpuid (XenLeaf + 2, , , NULL, NULL);
+  ASSERT (mXenLeaf != 0);
+
+  //
+  // Prepare HyperPages to be able to make hypercalls
+  //
+
+  AsmCpuid (mXenLeaf + 2, , , NULL, NULL);
   mXenInfo.HyperPages = AllocatePages (TransferPages);
   if (!mXenInfo.HyperPages) {
 return EFI_OUT_OF_RESOURCES;
@@ -103,7 +106,11 @@ XenConnect (
(Index << EFI_PAGE_SHIFT) + Index);
   }
 
-  AsmCpuid (XenLeaf + 1, , NULL, NULL, NULL);
+  //
+  // Find out the Xen version
+  //
+
+  AsmCpuid (mXenLeaf + 1, , NULL, NULL, NULL);
   DEBUG ((DEBUG_ERROR, "Detected Xen version %d.%d\n",
   XenVersion >> 16, XenVersion & 0x));
   mXenInfo.VersionMajor = (UINT16)(XenVersion >> 16);
@@ -262,12 +269,6 @@ InitializeXen (
 {
   RETURN_STATUS PcdStatus;
 
-  if (mXenLeaf == 0) {
-return EFI_NOT_FOUND;
-  }
-
-  XenConnect (mXenLeaf);
-
   //
   // Reserve away HVMLOADER reserved memory [0xFC00,0xFD00).
   // This needs to match HVMLOADER RESERVED_MEMBASE/RESERVED_MEMSIZE.
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#4): https://edk2.groups.io/g/devel/message/4
Mute This Topic: https://groups.io/mt/32851703/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v5 15/35] OvmfPkg/AcpiPlatformDxe: Use Xen PVH RSDP if it exist

2019-08-13 Thread Anthony PERARD
If the firmware have been started via the Xen PVH entry point, a RSDP
pointer would have been provided. Use it.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Reviewed-by: Laszlo Ersek 
---

Notes:
v4:
- fix coding style

v3:
- patch splited from the previous one
- Fix DEBUG format string, use %p for pointers.
  and use gEfiCallerBaseName to print module name

 OvmfPkg/AcpiPlatformDxe/Xen.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/OvmfPkg/AcpiPlatformDxe/Xen.c b/OvmfPkg/AcpiPlatformDxe/Xen.c
index 82794b933e..f80dfe1a57 100644
--- a/OvmfPkg/AcpiPlatformDxe/Xen.c
+++ b/OvmfPkg/AcpiPlatformDxe/Xen.c
@@ -36,10 +36,27 @@ GetXenAcpiRsdp (
   EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER   *RsdpStructurePtr;
   UINT8  *XenAcpiPtr;
   UINT8  Sum;
+  EFI_XEN_INFO   *XenInfo;
 
   //
   // Detect the RSDP structure
   //
+
+  //
+  // First look for PVH one
+  //
+  XenInfo = XenGetInfoHOB ();
+  ASSERT (XenInfo != NULL);
+  if (XenInfo->RsdpPvh != NULL) {
+DEBUG ((DEBUG_INFO, "%a: Use ACPI RSDP table at 0x%p\n",
+  gEfiCallerBaseName, XenInfo->RsdpPvh));
+*RsdpPtr = XenInfo->RsdpPvh;
+return EFI_SUCCESS;
+  }
+
+  //
+  // Otherwise, look for the HVM one
+  //
   for (XenAcpiPtr = (UINT8*)(UINTN) XEN_ACPI_PHYSICAL_ADDRESS;
XenAcpiPtr < (UINT8*)(UINTN) XEN_BIOS_PHYSICAL_END;
XenAcpiPtr += 0x10) {
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45537): https://edk2.groups.io/g/devel/message/45537
Mute This Topic: https://groups.io/mt/32851681/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v5 18/35] OvmfPkg/XenPlatformPei: Introduce XenHvmloaderDetected

2019-08-13 Thread Anthony PERARD
This new XenHvmloaderDetected() return true if the hvmloader firmware
has runned before OVMF.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v3:
- Added one sentence in the commit message.

 OvmfPkg/XenPlatformPei/Platform.h | 5 +
 OvmfPkg/XenPlatformPei/Xen.c  | 7 +++
 2 files changed, 12 insertions(+)

diff --git a/OvmfPkg/XenPlatformPei/Platform.h 
b/OvmfPkg/XenPlatformPei/Platform.h
index 77427496c0..925df31f88 100644
--- a/OvmfPkg/XenPlatformPei/Platform.h
+++ b/OvmfPkg/XenPlatformPei/Platform.h
@@ -89,6 +89,11 @@ XenDetect (
   VOID
   );
 
+BOOLEAN
+XenHvmloaderDetected (
+  VOID
+  );
+
 VOID
 AmdSevInitialize (
   VOID
diff --git a/OvmfPkg/XenPlatformPei/Xen.c b/OvmfPkg/XenPlatformPei/Xen.c
index c67f4c9697..2105304c41 100644
--- a/OvmfPkg/XenPlatformPei/Xen.c
+++ b/OvmfPkg/XenPlatformPei/Xen.c
@@ -199,6 +199,13 @@ XenDetect (
   return FALSE;
 }
 
+BOOLEAN
+XenHvmloaderDetected (
+  VOID
+  )
+{
+  return (mXenHvmloaderInfo != NULL);
+}
 
 VOID
 XenPublishRamRegions (
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45541): https://edk2.groups.io/g/devel/message/45541
Mute This Topic: https://groups.io/mt/32851685/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v5 26/35] OvmfPkg/XenPlatformLib: Cache result for XenDetected

2019-08-13 Thread Anthony PERARD
We are going to replace XenDetected() implementation in
PlatformBootManagerLib by the one in XenPlatformLib.
PlatformBootManagerLib's implementation does cache the result of
GetFirstGuidHob(), so we do something similar in XenPlatformLib.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Reviewed-by: Laszlo Ersek 
---

Notes:
v4:
- fix coding style

v3:
- new patch

 .../Library/XenPlatformLib/XenPlatformLib.c   | 20 +++
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c 
b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c
index 974a0e73f1..8f20ae2d45 100644
--- a/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c
+++ b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c
@@ -25,14 +25,26 @@ XenGetInfoHOB (
   VOID
   )
 {
-  EFI_HOB_GUID_TYPE  *GuidHob;
+  EFI_HOB_GUID_TYPE   *GuidHob;
+  STATIC BOOLEAN  Cached = FALSE;
+  STATIC EFI_XEN_INFO *XenInfo;
+
+  //
+  // Return the cached result for the benefit of XenDetected that can be
+  // called many times.
+  //
+  if (Cached) {
+return XenInfo;
+  }
 
   GuidHob = GetFirstGuidHob ();
   if (GuidHob == NULL) {
-return NULL;
+XenInfo = NULL;
+  } else {
+XenInfo = (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);
   }
-
-  return (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);
+  Cached = TRUE;
+  return XenInfo;
 }
 
 /**
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45553): https://edk2.groups.io/g/devel/message/45553
Mute This Topic: https://groups.io/mt/32851701/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v5 16/35] OvmfPkg/XenHypercallLib: Enable it in PEIM

2019-08-13 Thread Anthony PERARD
Allow to use Xen hypercalls earlier, during the PEIM stage, but
XenHypercallLibInit() must be called once the XenInfo HOB is created
with the HyperPage setup.

Change the return value of XenHypercallLibInit so failure can be
detected when the call shouldn't fail, but still have the constructor
always succeed.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Reviewed-by: Laszlo Ersek 
---

Notes:
v3:
- only modify XenHypercallLib, and to the modification of XenPlatformPei
  in a separated patch.
- Allow XenHypercallLibInit to be called outside the library instead of
  creating a new function, but also return failure on failure,
  and have a new constructor that never fail.

 .../Library/XenHypercallLib/XenHypercallLib.inf  |  4 ++--
 OvmfPkg/Include/Library/XenHypercallLib.h| 12 
 .../Library/XenHypercallLib/X86XenHypercall.c|  8 +---
 OvmfPkg/Library/XenHypercallLib/XenHypercall.c   | 16 
 4 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf 
b/OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf
index 1208f0057a..21ce5b4434 100644
--- a/OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf
+++ b/OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf
@@ -12,10 +12,10 @@ [Defines]
   FILE_GUID  = B5EE9A32-CA5A-49A8-82E3-ADA4CCB77C7C
   MODULE_TYPE= BASE
   VERSION_STRING = 1.0
-  CONSTRUCTOR= XenHypercallLibInit
+  CONSTRUCTOR= XenHypercallLibConstruct
 
 [Defines.IA32, Defines.X64]
-  LIBRARY_CLASS  = XenHypercallLib|DXE_DRIVER UEFI_DRIVER
+  LIBRARY_CLASS  = XenHypercallLib|PEIM DXE_DRIVER UEFI_DRIVER
 
 [Defines.ARM, Defines.AARCH64]
   LIBRARY_CLASS  = XenHypercallLib
diff --git a/OvmfPkg/Include/Library/XenHypercallLib.h 
b/OvmfPkg/Include/Library/XenHypercallLib.h
index c43822782b..c1491dd652 100644
--- a/OvmfPkg/Include/Library/XenHypercallLib.h
+++ b/OvmfPkg/Include/Library/XenHypercallLib.h
@@ -10,6 +10,18 @@
 #ifndef __XEN_HYPERCALL_LIB_H__
 #define __XEN_HYPERCALL_LIB_H__
 
+/**
+  To call when the gEfiXenInfoGuid HOB became available after the library init
+  function has already been executed.
+
+  This allow to make hypercall in the PEIM stage.
+**/
+RETURN_STATUS
+EFIAPI
+XenHypercallLibInit (
+  VOID
+  );
+
 /**
   Check if the Xen Hypercall library is able to make calls to the Xen
   hypervisor.
diff --git a/OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c 
b/OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c
index 27083f924f..f779e46470 100644
--- a/OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c
+++ b/OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c
@@ -59,13 +59,7 @@ XenHypercallLibInit (
 
   GuidHob = GetFirstGuidHob ();
   if (GuidHob == NULL) {
-//
-// We don't fail library construction, since that has catastrophic
-// consequences for client modules (whereas those modules may easily be
-// running on a non-Xen platform). Instead, XenHypercallIsAvailable() above
-// will return FALSE.
-//
-return RETURN_SUCCESS;
+return RETURN_NOT_FOUND;
   }
   XenInfo = (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);
   HyperPage = XenInfo->HyperPages;
diff --git a/OvmfPkg/Library/XenHypercallLib/XenHypercall.c 
b/OvmfPkg/Library/XenHypercallLib/XenHypercall.c
index a2c41a2a69..d4fa802743 100644
--- a/OvmfPkg/Library/XenHypercallLib/XenHypercall.c
+++ b/OvmfPkg/Library/XenHypercallLib/XenHypercall.c
@@ -15,6 +15,22 @@
 #include 
 #include 
 
+RETURN_STATUS
+EFIAPI
+XenHypercallLibConstruct (
+  VOID
+  )
+{
+  XenHypercallLibInit ();
+  //
+  // We don't fail library construction, since that has catastrophic
+  // consequences for client modules (whereas those modules may easily be
+  // running on a non-Xen platform). Instead, XenHypercallIsAvailable()
+  // will return FALSE.
+  //
+  return RETURN_SUCCESS;
+}
+
 UINT64
 EFIAPI
 XenHypercallHvmGetParam (
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45545): https://edk2.groups.io/g/devel/message/45545
Mute This Topic: https://groups.io/mt/32851691/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v5 28/35] OvmfPkg/PlatformBootManagerLib: Handle the absence of PCI bus on Xen PVH

2019-08-13 Thread Anthony PERARD
When running in a Xen PVH guest, there's nothing to do in
PciAcpiInitialization() because there isn't any PCI bus. When the Host
Bridge DID isn't recognised, simply continue. (The value of
PcdOvmfHostBridgePciDevId would be 0 because it isn't set.)

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Reviewed-by: Laszlo Ersek 
---

Notes:
v3:
- Instead of checking for a false value,
  XEN_PVH_PCI_HOST_BRIDGE_DEVICE_ID, simply check if we are running xen
  when the HostBridge device ID isn't recognised.

 OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c 
b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
index d5d5d20fd8..1eba304f09 100644
--- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
+++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
@@ -1208,6 +1208,12 @@ PciAcpiInitialization (
   PciWrite8 (PCI_LIB_ADDRESS (0, 0x1f, 0, 0x6b), 0x0b); // H
   break;
 default:
+  if (XenDetected ()) {
+//
+// There is no PCI bus in this case.
+//
+return;
+  }
   DEBUG ((EFI_D_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",
 __FUNCTION__, mHostBridgeDevId));
   ASSERT (FALSE);
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#45559): https://edk2.groups.io/g/devel/message/45559
Mute This Topic: https://groups.io/mt/32851707/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH 11/11] OvmfPkg/XenBusDxe: Fix XenStoreWaitForEvent use during EBS

2019-09-13 Thread Anthony PERARD
XenStoreWaitForEvent is going to be called when the ExitBootServices
is signaled, but both CreateEvent and WaitForEvent can't be used.
CreateEvent allocate some memory and WaitForEvent can only be used
when TPL is TPL_APPLICATION.

When ExitBootServices has been called, simply return immediately and
let caller of XenStoreWaitForEvent do a busy loop.

Also cleanup error handling in XenStoreWaitForEvent, WaitForEvent
shouldn't return EFI_UNSUPPORTED anymore.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2190
Signed-off-by: Anthony PERARD 
---
 OvmfPkg/XenBusDxe/XenBusDxe.c |  2 ++
 OvmfPkg/XenBusDxe/XenBusDxe.h |  1 +
 OvmfPkg/XenBusDxe/XenStore.c  | 13 +
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.c b/OvmfPkg/XenBusDxe/XenBusDxe.c
index c71966a666..eb1503ad2b 100644
--- a/OvmfPkg/XenBusDxe/XenBusDxe.c
+++ b/OvmfPkg/XenBusDxe/XenBusDxe.c
@@ -264,6 +264,8 @@ NotifyExitBoot (
 
   Dev = Context;
 
+  Dev->ExitBootNotified = TRUE;
+
   //
   // First, ask every driver using xenbus to disconnect without
   // deallocating memory.
diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.h b/OvmfPkg/XenBusDxe/XenBusDxe.h
index 0e91c24338..80162fc3ff 100644
--- a/OvmfPkg/XenBusDxe/XenBusDxe.h
+++ b/OvmfPkg/XenBusDxe/XenBusDxe.h
@@ -79,6 +79,7 @@ struct _XENBUS_DEVICE {
   EFI_HANDLEControllerHandle;
   XENIO_PROTOCOL*XenIo;
   EFI_EVENT ExitBootEvent;
+  BOOLEAN   ExitBootNotified;
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
   LIST_ENTRYChildList;
 
diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c
index 4026c8a829..4f126109d4 100644
--- a/OvmfPkg/XenBusDxe/XenStore.c
+++ b/OvmfPkg/XenBusDxe/XenStore.c
@@ -401,17 +401,22 @@ XenStoreWaitForEvent (
   EFI_EVENT TimerEvent;
   EFI_EVENT WaitList[2];
 
+  //
+  // If the ExitBootServices event have been signaled, simply allow to have
+  // busy loop in the caller.
+  //
+  if (xs.Dev->ExitBootNotified) {
+return EFI_SUCCESS;
+  }
+
   gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, );
   gBS->SetTimer (TimerEvent, TimerRelative, Timeout);
 
   WaitList[0] = xs.EventChannelEvent;
   WaitList[1] = TimerEvent;
   Status = gBS->WaitForEvent (2, WaitList, );
-  ASSERT (Status != EFI_INVALID_PARAMETER);
+  ASSERT_EFI_ERROR (Status);
   gBS->CloseEvent (TimerEvent);
-  if (Status == EFI_UNSUPPORTED) {
-return EFI_SUCCESS;
-  }
   if (Index == 1) {
 return EFI_TIMEOUT;
   } else {
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#47218): https://edk2.groups.io/g/devel/message/47218
Mute This Topic: https://groups.io/mt/34128216/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH 01/11] OvmfPkg/XenBusDxe: Fix missing \n in DEBUG messages

2019-09-13 Thread Anthony PERARD
Fix missing \n in DEBUG messages in XenBusDxe and use DEBUG_*.

Signed-off-by: Anthony PERARD 
---
 OvmfPkg/XenBusDxe/EventChannel.c | 3 ++-
 OvmfPkg/XenBusDxe/XenStore.c | 6 +++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/OvmfPkg/XenBusDxe/EventChannel.c b/OvmfPkg/XenBusDxe/EventChannel.c
index 6900071782..c6b3871781 100644
--- a/OvmfPkg/XenBusDxe/EventChannel.c
+++ b/OvmfPkg/XenBusDxe/EventChannel.c
@@ -44,7 +44,8 @@ XenBusEventChannelAllocate (
EVTCHNOP_alloc_unbound,
);
   if (ReturnCode != 0) {
-DEBUG ((EFI_D_ERROR, "ERROR: alloc_unbound failed with rc=%d", 
ReturnCode));
+DEBUG ((DEBUG_ERROR, "ERROR: alloc_unbound failed with rc=%d\n",
+ReturnCode));
 return ReturnCode;
   }
   *Port = Parameter.port;
diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c
index 34890ae40b..7253d8ae37 100644
--- a/OvmfPkg/XenBusDxe/XenStore.c
+++ b/OvmfPkg/XenBusDxe/XenStore.c
@@ -738,7 +738,7 @@ XenStoreReadReply (
 XENSTORE_STATUS Status;
 Status = XenStoreProcessMessage ();
 if (Status != XENSTORE_STATUS_SUCCESS && Status != XENSTORE_STATUS_EAGAIN) 
{
-  DEBUG ((EFI_D_ERROR, "XenStore, error while reading the ring (%d).",
+  DEBUG ((DEBUG_ERROR, "XenStore, error while reading the ring (%d).\n",
   Status));
   return Status;
 }
@@ -1076,7 +1076,7 @@ XenStoreDeinit (
   if (!IsListEmpty ()) {
 XENSTORE_WATCH *Watch;
 LIST_ENTRY *Entry;
-DEBUG ((EFI_D_WARN, "XenStore: RegisteredWatches is not empty, cleaning 
up..."));
+DEBUG ((DEBUG_WARN, "XenStore: RegisteredWatches is not empty, cleaning 
up...\n"));
 Entry = GetFirstNode ();
 while (!IsNull (, Entry)) {
   Watch = XENSTORE_WATCH_FROM_LINK (Entry);
@@ -1092,7 +1092,7 @@ XenStoreDeinit (
   //
   if (!IsListEmpty ()) {
 LIST_ENTRY *Entry;
-DEBUG ((EFI_D_WARN, "XenStore: WatchEvents is not empty, cleaning up..."));
+DEBUG ((DEBUG_WARN, "XenStore: WatchEvents is not empty, cleaning 
up...\n"));
 Entry = GetFirstNode ();
 while (!IsNull (, Entry)) {
   XENSTORE_MESSAGE *Message = XENSTORE_MESSAGE_FROM_LINK (Entry);
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#47209): https://edk2.groups.io/g/devel/message/47209
Mute This Topic: https://groups.io/mt/34128010/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH 09/11] OvmfPkg/XenBusDxe: Fix NotifyExitBoot to avoid Memory Allocation Services

2019-09-13 Thread Anthony PERARD
This patch fix the EVT_SIGNAL_EXIT_BOOT_SERVICES handler to avoid
using the Memory Allocation Services.

This comes with a new interface named RegisterExitCallback so that PV
drivers can disconnect from the backend before XenBusDxe is teared
down.

Instead of using Disconnect() to tear down the XenBus driver and the
children drivers, we are going to ask every driver using
XENBUS_PROTOCOL to disconnect from the hardware via the callback set
with RegisterExitCallback, then reset the xenstore shared ring and
the grant table.

Since there are no driver using RegisterExitCallback yet, no driver are
going to be disconnected. Linux can deal with that. And that will be
fixed by the next patch with a change for XenPvBlkDxe.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2190
Signed-off-by: Anthony PERARD 
---
 OvmfPkg/Include/Protocol/XenBus.h | 35 +++
 OvmfPkg/XenBusDxe/XenBus.c| 18 
 OvmfPkg/XenBusDxe/XenBusDxe.c | 27 +---
 OvmfPkg/XenBusDxe/XenBusDxe.h |  2 ++
 OvmfPkg/XenBusDxe/XenStore.c  | 22 ++-
 OvmfPkg/XenBusDxe/XenStore.h  | 21 +++
 6 files changed, 121 insertions(+), 4 deletions(-)

diff --git a/OvmfPkg/Include/Protocol/XenBus.h 
b/OvmfPkg/Include/Protocol/XenBus.h
index c22bdfb368..04986747c8 100644
--- a/OvmfPkg/Include/Protocol/XenBus.h
+++ b/OvmfPkg/Include/Protocol/XenBus.h
@@ -373,6 +373,38 @@ XENSTORE_STATUS
   IN VOID *Token
   );
 
+typedef
+VOID
+(EFIAPI *XENBUS_EXIT_CALLBACK)(
+  IN  VOID *Context
+  );
+
+/**
+  Register a function to be called during the ExitBootServices event.
+
+  NotifyFunction will be called when XenBusDxe is notified of
+  EVT_SIGNAL_EXIT_BOOT_SERVICES. The function should follow the same
+  requirements as if it as registered an event on
+  EVT_SIGNAL_EXIT_BOOT_SERVICES, i.e. no use of the Memory Allocation
+  Services.
+
+  To unregister the function, call RegisterExitCallback with
+  NotifyFunction=NULL.
+
+  @note There can only be one callback per driver.
+
+  @param This A pointer to the XENBUS_PROTOCOL.
+  @param NotifyFunction   The function to be called.
+  @param NotifyContextA context.
+**/
+typedef
+VOID
+(EFIAPI *XENBUS_SET_EXIT_CALLBACK) (
+  IN XENBUS_PROTOCOL   *This,
+  IN XENBUS_EXIT_CALLBACK  NotifyFunction,
+  IN VOID  *NotifyContext
+  );
+
 
 ///
 /// Protocol structure
@@ -400,6 +432,9 @@ struct _XENBUS_PROTOCOL {
   XENBUS_REGISTER_WATCH_BACKEND RegisterWatchBackend;
   XENBUS_UNREGISTER_WATCH   UnregisterWatch;
   XENBUS_WAIT_FOR_WATCH WaitForWatch;
+
+  XENBUS_SET_EXIT_CALLBACK  RegisterExitCallback;
+
   //
   // Protocol data fields
   //
diff --git a/OvmfPkg/XenBusDxe/XenBus.c b/OvmfPkg/XenBusDxe/XenBus.c
index 78835ec7b3..54166505d2 100644
--- a/OvmfPkg/XenBusDxe/XenBus.c
+++ b/OvmfPkg/XenBusDxe/XenBus.c
@@ -343,6 +343,23 @@ XenBusSetState (
   return Status;
 }
 
+STATIC
+VOID
+EFIAPI
+XenBusRegisterExitCallback (
+  IN XENBUS_PROTOCOL   *This,
+  IN XENBUS_EXIT_CALLBACK  NotifyFunction,
+  IN VOID  *NotifyContext
+  )
+{
+  XENBUS_PRIVATE_DATA *Dev;
+
+  Dev = XENBUS_PRIVATE_DATA_FROM_THIS (This);
+
+  Dev->ExitCallback = NotifyFunction;
+  Dev->ExitCallbackContext = NotifyContext;
+}
+
 STATIC XENBUS_PRIVATE_DATA gXenBusPrivateData = {
   XENBUS_PRIVATE_DATA_SIGNATURE,// Signature
   { NULL, NULL },   // Link
@@ -364,6 +381,7 @@ STATIC XENBUS_PRIVATE_DATA gXenBusPrivateData = {
 XenBusRegisterWatchBackend, // XenBusIo.RegisterWatchBackend
 XenBusUnregisterWatch,  // XenBusIo.UnregisterWatch
 XenBusWaitForWatch, // XenBusIo.WaitForWatch
+XenBusRegisterExitCallback, // XenBusIo.RegisterExitCallback
 
 NULL,   // XenBusIo.Type
 0,  // XenBusIo.DeviceId
diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.c b/OvmfPkg/XenBusDxe/XenBusDxe.c
index 634c7b71eb..c71966a666 100644
--- a/OvmfPkg/XenBusDxe/XenBusDxe.c
+++ b/OvmfPkg/XenBusDxe/XenBusDxe.c
@@ -258,10 +258,31 @@ NotifyExitBoot (
   IN VOID *Context
   )
 {
-  XENBUS_DEVICE *Dev = Context;
+  XENBUS_DEVICE   *Dev;
+  LIST_ENTRY  *Entry;
+  XENBUS_PRIVATE_DATA *Child;
 
-  gBS->DisconnectController(Dev->ControllerHandle,
-Dev->This->DriverBindingHandle, NULL);
+  Dev = Context;
+
+  //
+  // First, ask every driver using xenbus to disconnect without
+  // deallocating memory.
+  //
+  for (Entry = GetFirstNode (>ChildList);
+   !IsNodeAtEnd (>ChildList, Entry);
+   Entry = GetNextNode (>ChildList, Entry)) {
+Child = XENBUS_PRIVATE_DATA_FROM_LINK (Entry);
+if (Child->ExitCallback != NULL) {
+  Child->ExitCallback (Child->ExitCallbackContext);
+}
+  }
+
+  //
+  // Now, we can reset the devices used by XenBusDxe.
+  //
+  XenStoreResetW

[edk2-devel] [PATCH 10/11] OvmfPkg/XenPvBlkDxe: Use XenBusIo->RegisterExitCallback

2019-09-13 Thread Anthony PERARD
In order to be able to reset the backend before handing it to the next
operating system, it should be reset properly. This patch register a
callback function to be called by XenBusDxe during the
ExitBootServices event.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2190
Signed-off-by: Anthony PERARD 
---
 OvmfPkg/XenPvBlkDxe/BlockFront.c  | 37 ---
 OvmfPkg/XenPvBlkDxe/BlockFront.h  | 12 +-
 OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c |  4 ++--
 3 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/OvmfPkg/XenPvBlkDxe/BlockFront.c b/OvmfPkg/XenPvBlkDxe/BlockFront.c
index 25a398ccc4..7c166888bd 100644
--- a/OvmfPkg/XenPvBlkDxe/BlockFront.c
+++ b/OvmfPkg/XenPvBlkDxe/BlockFront.c
@@ -309,6 +309,8 @@ XenPvBlockFrontInitialization (
   Dev->MediaInfo.Sectors, Dev->MediaInfo.SectorSize));
 
   *DevPtr = Dev;
+
+  XenBusIo->RegisterExitCallback (XenBusIo, XenPvBlockFrontReset, Dev);
   return EFI_SUCCESS;
 
 Error2:
@@ -326,13 +328,16 @@ XenPvBlockFrontInitialization (
 
 VOID
 XenPvBlockFrontShutdown (
-  IN XEN_BLOCK_FRONT_DEVICE *Dev
+  IN XEN_BLOCK_FRONT_DEVICE *Dev,
+  IN BOOLEANResetOnly
   )
 {
   XENBUS_PROTOCOL *XenBusIo = Dev->XenBusIo;
   XENSTORE_STATUS Status;
   UINT64 Value;
 
+  XenBusIo->RegisterExitCallback (XenBusIo, NULL, NULL);
+
   XenPvBlockSync (Dev);
 
   Status = XenBusIo->SetState (XenBusIo, XST_NIL, XenbusStateClosing);
@@ -393,12 +398,38 @@ XenPvBlockFrontShutdown (
   }
 
 Close:
-  XenBusIo->UnregisterWatch (XenBusIo, Dev->StateWatchToken);
+  if (!ResetOnly) {
+XenBusIo->UnregisterWatch (XenBusIo, Dev->StateWatchToken);
+  }
   XenBusIo->XsRemove (XenBusIo, XST_NIL, "ring-ref");
   XenBusIo->XsRemove (XenBusIo, XST_NIL, "event-channel");
   XenBusIo->XsRemove (XenBusIo, XST_NIL, "protocol");
 
-  XenPvBlockFree (Dev);
+  if (ResetOnly) {
+XenBusIo->GrantEndAccess (XenBusIo, Dev->RingRef);
+XenBusIo->EventChannelClose (XenBusIo, Dev->EventChannel);
+  } else {
+XenPvBlockFree (Dev);
+  }
+}
+
+/**
+  To be called when ExitBootServices has been called.
+
+  This should reset the PV backend without using memory allocation
+  services.
+**/
+VOID
+EFIAPI
+XenPvBlockFrontReset (
+  IN VOID *Context
+  )
+{
+  XEN_BLOCK_FRONT_DEVICE *Dev;
+
+  Dev = Context;
+
+  XenPvBlockFrontShutdown (Dev, TRUE);
 }
 
 STATIC
diff --git a/OvmfPkg/XenPvBlkDxe/BlockFront.h b/OvmfPkg/XenPvBlkDxe/BlockFront.h
index 7c2d7f2c9e..ebce4fe434 100644
--- a/OvmfPkg/XenPvBlkDxe/BlockFront.h
+++ b/OvmfPkg/XenPvBlkDxe/BlockFront.h
@@ -67,9 +67,19 @@ XenPvBlockFrontInitialization (
   OUT XEN_BLOCK_FRONT_DEVICE **DevPtr
   );
 
+/**
+  @param ResetOnly  Set to TRUE when called during the ExitBootServices.
+**/
 VOID
 XenPvBlockFrontShutdown (
-  IN XEN_BLOCK_FRONT_DEVICE *Dev
+  IN XEN_BLOCK_FRONT_DEVICE *Dev,
+  IN BOOLEANResetOnly
+  );
+
+VOID
+EFIAPI
+XenPvBlockFrontReset (
+  IN VOID *Context
   );
 
 VOID
diff --git a/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c 
b/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c
index bfe7b1a754..3031406980 100644
--- a/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c
+++ b/OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c
@@ -312,7 +312,7 @@ XenPvBlkDxeDriverBindingStart (
 
 UninitBlockFront:
   FreePool (Media);
-  XenPvBlockFrontShutdown (Dev);
+  XenPvBlockFrontShutdown (Dev, FALSE);
 CloseProtocol:
   gBS->CloseProtocol (ControllerHandle, ,
   This->DriverBindingHandle, ControllerHandle);
@@ -377,7 +377,7 @@ XenPvBlkDxeDriverBindingStop (
 
   Media = BlockIo->Media;
   Dev = XEN_BLOCK_FRONT_FROM_BLOCK_IO (BlockIo);
-  XenPvBlockFrontShutdown (Dev);
+  XenPvBlockFrontShutdown (Dev, FALSE);
 
   FreePool (Media);
 
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#47219): https://edk2.groups.io/g/devel/message/47219
Mute This Topic: https://groups.io/mt/34128218/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH 03/11] OvmfPkg/XenBusDxe: Rework watch events reception

2019-09-13 Thread Anthony PERARD
This patch rework the reception of xenstore watch event to avoid
allocation.

Instead of queuing watch events, we simply mark a XENSTORE_WATCH as
"triggered". We don't need to know how many time we received the
event, only that it happened. That avoid to allocate a
XENSTORE_MESSAGE for every watch events.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2190
Signed-off-by: Anthony PERARD 
---
 OvmfPkg/XenBusDxe/XenStore.c | 125 ++-
 1 file changed, 35 insertions(+), 90 deletions(-)

diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c
index 727641a0fe..5cc900190a 100644
--- a/OvmfPkg/XenBusDxe/XenStore.c
+++ b/OvmfPkg/XenBusDxe/XenStore.c
@@ -65,6 +65,8 @@ struct _XENSTORE_WATCH
 
   /* Path being watched. */
   CHAR8   *Node;
+
+  BOOLEAN Triggered;
 };
 
 #define XENSTORE_WATCH_FROM_LINK(l) \
@@ -86,13 +88,6 @@ typedef struct {
 struct {
   CHAR8 *Body;
 } Reply;
-
-/* Queued watch events. */
-struct {
-  XENSTORE_WATCH *Handle;
-  CONST CHAR8 **Vector;
-  UINT32 VectorSize;
-} Watch;
   } u;
 } XENSTORE_MESSAGE;
 #define XENSTORE_MESSAGE_FROM_LINK(r) \
@@ -133,14 +128,6 @@ typedef struct {
   /** Lock protecting the registered watches list. */
   EFI_LOCK RegisteredWatchesLock;
 
-  /**
-   * List of pending watch callback events.
-   */
-  LIST_ENTRY WatchEvents;
-
-  /** Lock protecting the watch calback list. */
-  EFI_LOCK WatchEventsLock;
-
   /**
* The event channel for communicating with the
* XenStore service.
@@ -630,29 +617,32 @@ XenStoreProcessMessage (
   Body[Message->Header.len] = '\0';
 
   if (Message->Header.type == XS_WATCH_EVENT) {
-VOID *ConvertedToken;
+CONST CHAR8*WatchEventPath;
+CONST CHAR8*WatchEventToken;
+VOID   *ConvertedToken;
+XENSTORE_WATCH *Watch;
 
-Message->u.Watch.Vector = Split(Body, Message->Header.len,
->u.Watch.VectorSize);
+//
+// Parse WATCH_EVENT messages
+//   \0\0
+//
+WatchEventPath = Body;
+WatchEventToken = WatchEventPath + AsciiStrSize (WatchEventPath);
 
-ConvertedToken =
-  (VOID *) AsciiStrHexToUintn (Message->u.Watch.Vector[XS_WATCH_TOKEN]);
+ConvertedToken = (VOID *) AsciiStrHexToUintn (WatchEventToken);
 
 EfiAcquireLock ();
-Message->u.Watch.Handle = XenStoreFindWatch (ConvertedToken);
-DEBUG ((EFI_D_INFO, "XenStore: Watch event %a\n",
-Message->u.Watch.Vector[XS_WATCH_TOKEN]));
-if (Message->u.Watch.Handle != NULL) {
-  EfiAcquireLock ();
-  InsertHeadList (, >Link);
-  EfiReleaseLock ();
+Watch = XenStoreFindWatch (ConvertedToken);
+DEBUG ((DEBUG_INFO, "XenStore: Watch event %a\n", WatchEventToken));
+if (Watch != NULL) {
+  Watch->Triggered = TRUE;
 } else {
   DEBUG ((EFI_D_WARN, "XenStore: Watch handle %a not found\n",
-  Message->u.Watch.Vector[XS_WATCH_TOKEN]));
-  FreePool((VOID*)Message->u.Watch.Vector);
-  FreePool(Message);
+  WatchEventToken));
 }
 EfiReleaseLock ();
+FreePool (Message);
+FreePool (Body);
   } else {
 Message->u.Reply.Body = Body;
 EfiAcquireLock ();
@@ -936,40 +926,29 @@ XenStoreUnwatch (
 STATIC
 XENSTORE_STATUS
 XenStoreWaitWatch (
-  VOID *Token
+  IN VOID *Token
   )
 {
-  XENSTORE_MESSAGE *Message;
-  LIST_ENTRY *Entry = NULL;
-  LIST_ENTRY *Last = NULL;
+  XENSTORE_WATCH  *Watch;
   XENSTORE_STATUS Status;
 
+  EfiAcquireLock ();
+  Watch = XenStoreFindWatch (Token);
+  EfiReleaseLock ();
+  if (Watch == NULL) {
+return XENSTORE_STATUS_EINVAL;
+  }
+
   while (TRUE) {
-EfiAcquireLock ();
-if (IsListEmpty () ||
-Last == GetFirstNode ()) {
-  EfiReleaseLock ();
-  Status = XenStoreProcessMessage ();
-  if (Status != XENSTORE_STATUS_SUCCESS && Status != 
XENSTORE_STATUS_EAGAIN) {
-return Status;
-  }
-  continue;
+if (Watch->Triggered) {
+  Watch->Triggered = FALSE;
+  return XENSTORE_STATUS_SUCCESS;
 }
 
-for (Entry = GetFirstNode ();
- Entry != Last && !IsNull (, Entry);
- Entry = GetNextNode (, Entry)) {
-  Message = XENSTORE_MESSAGE_FROM_LINK (Entry);
-  if (Message->u.Watch.Handle == Token) {
-RemoveEntryList (Entry);
-EfiReleaseLock ();
-FreePool((VOID*)Message->u.Watch.Vector);
-FreePool(Message);
-return XENSTORE_STATUS_SUCCESS;
-  }
+Status = XenStoreProcessMessage ();
+if (Status != XENSTORE_STATUS_SUCCESS && Status != XENSTORE_STATUS_EAGAIN) 
{
+  return Status;
 }
-Last = GetFirstNode ();
-EfiReleaseLock ();
   }
 }
 
@@ -1052,12 +1031,10 @@ XenStoreInit (
   xs.XenStore, xs.EventChannel));
 
   InitializeListHead ();
-  InitializeListHead ();
   InitializeListHead ();
 
   EfiIniti

[edk2-devel] [PATCH 06/11] OvmfPkg/XenBusDxe: Rework XenStoreProcessMessage to avoid allocating memory

2019-09-13 Thread Anthony PERARD
This patch rework XenStoreProcessMessage in order to avoid memory
allocation when a reply is expected. Instead of allocating a buffer
for this reply, we are going to copy to a buffer passed by the caller.
For messages that aren't fully received, they will be stored in a
buffer that have been allocated at the initialisation of the driver.

A temporary memory allocation is made in XenStoreTalkv but that will
be removed in a further patch.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2190
Signed-off-by: Anthony PERARD 
---
 OvmfPkg/XenBusDxe/XenStore.c | 297 +++
 1 file changed, 130 insertions(+), 167 deletions(-)

diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c
index ca7be12d68..004d3b6022 100644
--- a/OvmfPkg/XenBusDxe/XenStore.c
+++ b/OvmfPkg/XenBusDxe/XenStore.c
@@ -72,27 +72,6 @@ struct _XENSTORE_WATCH
 #define XENSTORE_WATCH_FROM_LINK(l) \
   CR (l, XENSTORE_WATCH, Link, XENSTORE_WATCH_SIGNATURE)
 
-
-/**
- * Structure capturing messages received from the XenStore service.
- */
-#define XENSTORE_MESSAGE_SIGNATURE SIGNATURE_32 ('X', 'S', 's', 'm')
-typedef struct {
-  UINT32 Signature;
-  LIST_ENTRY Link;
-
-  struct xsd_sockmsg Header;
-
-  union {
-/* Queued replies. */
-struct {
-  CHAR8 *Body;
-} Reply;
-  } u;
-} XENSTORE_MESSAGE;
-#define XENSTORE_MESSAGE_FROM_LINK(r) \
-  CR (r, XENSTORE_MESSAGE, Link, XENSTORE_MESSAGE_SIGNATURE)
-
 /**
  * Container for all XenStore related state.
  */
@@ -105,21 +84,6 @@ typedef struct {
 
   XENBUS_DEVICE *Dev;
 
-  /**
-   * A list of replies to our requests.
-   *
-   * The reply list is filled by xs_rcv_thread().  It
-   * is consumed by the context that issued the request
-   * to which a reply is made.  The requester blocks in
-   * XenStoreReadReply ().
-   *
-   * /note Only one requesting context can be active at a time.
-   */
-  LIST_ENTRY ReplyList;
-
-  /** Lock protecting the reply list. */
-  EFI_LOCK ReplyLock;
-
   /**
* List of registered watches.
*/
@@ -136,6 +100,13 @@ typedef struct {
 
   /** Handle for XenStore events. */
   EFI_EVENT EventChannelEvent;
+
+  /** Buffer used to copy payloads from the xenstore ring */
+  // The + 1 is to allow to have a \0.
+  CHAR8 Buffer[XENSTORE_PAYLOAD_MAX + 1];
+
+  /** ID used when sending messages to xenstored */
+  UINTN NextRequestId;
 } XENSTORE_PRIVATE;
 
 //
@@ -148,6 +119,12 @@ static XENSTORE_PRIVATE xs;
 // Private Utility Functions
 //
 
+STATIC
+XENSTORE_STATUS
+XenStoreGetError (
+  CONST CHAR8 *ErrorStr
+  );
+
 /**
   Count and optionally record pointers to a number of NUL terminated
   strings in a buffer.
@@ -613,70 +590,106 @@ XenStoreReadStore (
   Block reading the next message from the XenStore service and
   process the result.
 
+  @param ExpectedRequestId  Block until a reply to with this ID is seen.
+  @param ExpectedTransactionId  Idem, but should also match this ID.
+  @param BufferSize IN: size of the buffer
+OUT: The returned length of the reply.
+  @param Buffer The returned body of the reply.
+
   @return  XENSTORE_STATUS_SUCCESS on success.  Otherwise an errno value
indicating the type of failure encountered.
 **/
 STATIC
 XENSTORE_STATUS
 XenStoreProcessMessage (
-  VOID
+  IN UINT32ExpectedRequestId,
+  IN UINT32ExpectedTransactionId,
+  IN OUT UINTN *BufferSize OPTIONAL,
+  IN OUT CHAR8 *Buffer OPTIONAL
   )
 {
-  XENSTORE_MESSAGE *Message;
-  CHAR8 *Body;
-  XENSTORE_STATUS Status;
-
-  Message = AllocateZeroPool (sizeof (XENSTORE_MESSAGE));
-  Message->Signature = XENSTORE_MESSAGE_SIGNATURE;
-  Status = XenStoreReadStore (>Header, sizeof (Message->Header));
-  if (Status != XENSTORE_STATUS_SUCCESS) {
-FreePool (Message);
-DEBUG ((EFI_D_ERROR, "XenStore: Error read store (%d)\n", Status));
-return Status;
-  }
-
-  Body = AllocatePool (Message->Header.len + 1);
-  Status = XenStoreReadStore (Body, Message->Header.len);
-  if (Status != XENSTORE_STATUS_SUCCESS) {
-FreePool (Body);
-FreePool (Message);
-DEBUG ((EFI_D_ERROR, "XenStore: Error read store (%d)\n", Status));
-return Status;
-  }
-  Body[Message->Header.len] = '\0';
+  struct xsd_sockmsg Header;
+  CHAR8  *Payload;
+  XENSTORE_STATUSStatus;
 
-  if (Message->Header.type == XS_WATCH_EVENT) {
-CONST CHAR8*WatchEventPath;
-CONST CHAR8*WatchEventToken;
-VOID   *ConvertedToken;
-XENSTORE_WATCH *Watch;
+  while (TRUE) {
 
-//
-// Parse WATCH_EVENT messages
-//   \0\0
-//
-WatchEventPath = Body;
-WatchEventToken = WatchEventPath + AsciiStrSize (WatchEventPath);
+Status = XenStoreReadStore (, sizeof (Header));
+if (Status != XENSTORE_STATUS_SUCCESS) {
+  DEBUG ((DEBUG_ERROR, "XenStore: Error read store (%d)\n", Status));
+  return Status;
+}
 
-ConvertedT

[edk2-devel] [PATCH 08/11] OvmfPkg/XenBus: Change XENBUS_PROTOCOL to not return allocated memory

2019-09-13 Thread Anthony PERARD
XsRead and XsBackendRead of the XENBUS_PROTOCOL return allocated
memory but this isn't allowed during the ExitBootServices call. We
need XsRead and XsBackendRead to disconnect from the device so
XENBUS_PROTOCOL is changed to use a buffer supplied by a child driver.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2190
Signed-off-by: Anthony PERARD 
---
 OvmfPkg/Include/Protocol/XenBus.h | 32 --
 OvmfPkg/XenBusDxe/XenStore.c  | 44 +-
 OvmfPkg/XenBusDxe/XenStore.h  |  6 +++--
 OvmfPkg/XenPvBlkDxe/BlockFront.c  | 45 ++-
 4 files changed, 54 insertions(+), 73 deletions(-)

diff --git a/OvmfPkg/Include/Protocol/XenBus.h 
b/OvmfPkg/Include/Protocol/XenBus.h
index 8ff5ca3575..c22bdfb368 100644
--- a/OvmfPkg/Include/Protocol/XenBus.h
+++ b/OvmfPkg/Include/Protocol/XenBus.h
@@ -35,6 +35,12 @@ typedef struct
 
 #define XST_NIL ((XENSTORE_TRANSACTION *) NULL)
 
+//
+// When reading a node from xenstore, if the size of the data to be read is
+// unknown, this value can be use for the size of the buffer.
+//
+#define XENSTORE_PAYLOAD_MAX 4096
+
 typedef enum {
   XENSTORE_STATUS_SUCCESS = 0,
   XENSTORE_STATUS_FAIL,
@@ -64,19 +70,17 @@ typedef enum {
 ///
 
 /**
-  Get the contents of the node Node of the PV device. Returns the contents in
-  *Result which should be freed after use.
+  Get the contents of the node Node of the PV device.
 
   @param This   A pointer to XENBUS_PROTOCOL instance.
   @param TransactionThe XenStore transaction covering this request.
   @param Node   The basename of the file to read.
-  @param Result The returned contents from this file.
+  @param BufferSize On input, a pointer to the size of the buffer at 
Buffer.
+On output, the size of the data written to Buffer.
+  @param Buffer A pointer to a buffer into which the data read will be 
saved.
 
   @return  On success, XENSTORE_STATUS_SUCCESS. Otherwise an errno value
indicating the type of failure.
-
-  @note The results buffer is malloced and should be free'd by the
-caller.
 **/
 typedef
 XENSTORE_STATUS
@@ -84,23 +88,22 @@ XENSTORE_STATUS
   IN  XENBUS_PROTOCOL   *This,
   IN  CONST XENSTORE_TRANSACTION *Transaction,
   IN  CONST CHAR8   *Node,
-  OUT VOID  **Result
+  IN OUT UINTN  *BufferSize,
+  OUT VOID  *Buffer
   );
 
 /**
-  Get the contents of the node Node of the PV device's backend. Returns the
-  contents in *Result which should be freed after use.
+  Get the contents of the node Node of the PV device's backend.
 
   @param This   A pointer to XENBUS_PROTOCOL instance.
   @param TransactionThe XenStore transaction covering this request.
   @param Node   The basename of the file to read.
-  @param Result The returned contents from this file.
+  @param BufferSize On input, a pointer to the size of the buffer at 
Buffer.
+On output, the size of the data written to Buffer.
+  @param Buffer A pointer to a buffer into which the data read will be 
saved.
 
   @return  On success, XENSTORE_STATUS_SUCCESS. Otherwise an errno value
indicating the type of failure.
-
-  @note The results buffer is malloced and should be free'd by the
-caller.
 **/
 typedef
 XENSTORE_STATUS
@@ -108,7 +111,8 @@ XENSTORE_STATUS
   IN  XENBUS_PROTOCOL   *This,
   IN  CONST XENSTORE_TRANSACTION *Transaction,
   IN  CONST CHAR8   *Node,
-  OUT VOID  **Result
+  IN OUT UINTN  *BufferSize,
+  OUT VOID  *Buffer
   );
 
 /**
diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c
index b9588bb8c6..cb2d9e1215 100644
--- a/OvmfPkg/XenBusDxe/XenStore.c
+++ b/OvmfPkg/XenBusDxe/XenStore.c
@@ -1336,27 +1336,11 @@ XenBusXenStoreRead (
   IN  XENBUS_PROTOCOL   *This,
   IN  CONST XENSTORE_TRANSACTION *Transaction,
   IN  CONST CHAR8   *Node,
-  OUT VOID  **Value
+  IN OUT UINTN  *BufferSize,
+  OUT VOID  *Buffer
   )
 {
-  XENSTORE_STATUS Status;
-  UINTN   BufferSize;
-  VOID*Buffer;
-
-  BufferSize = XENSTORE_PAYLOAD_MAX + 1;
-  Buffer = AllocatePool (BufferSize);
-  if (Buffer == NULL) {
-return XENSTORE_STATUS_ENOMEM;
-  }
-
-  Status = XenStoreRead (Transaction, This->Node, Node, , Buffer);
-
-  if (Status == XENSTORE_STATUS_SUCCESS) {
-*Value = Buffer;
-  } else {
-FreePool (Buffer);
-  }
-  return Status;
+  return XenStoreRead (Transaction, This->Node, Node, BufferSize, Buffer);
 }
 
 XENSTORE_STATUS
@@ -1365,27 +1349,11 @@ XenBusXenStoreBackendRead (
   IN  XENBUS_PROTOCOL   *This,
   IN  CONST XENSTORE_TRANSACTION *Transaction,
   IN  CONST CHAR8   *Node,
-  OUT VOID  **Value
+  IN OUT UINTN  *BufferSize,
+  OUT VOID  *

[edk2-devel] [PATCH 00/11] OvmfPkg/XenBusDxe: Fix ExitBootServices handler to avoid allocation

2019-09-13 Thread Anthony PERARD
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2190

Patch series available in this git branch:
https://xenbits.xen.org/git-http/people/aperard/ovmf.git 
br.xenbusdxe-fix-exitbootservices-v1

Hi,

This patch series works toward removing usage of Memory Allocation Services in
XenBusDxe when ExitBootServices() is called by the next operating system.

Since that in order to reset a backend, communication needs to happened via
xenstore, this series focus mostly on getting rid of allocation in the xenstore
driver. There are still some left but that's in function that aren't needed 
after
EBS is called.

In some places (like XenStoreVSPrint), instead of allocating a buffer, the
buffer (4k) is on the stack.

Thanks,

Anthony PERARD (11):
  OvmfPkg/XenBusDxe: Fix missing \n in DEBUG messages
  OvmfPkg/XenBusDxe: Have XenStoreFindWatch take a pointer
  OvmfPkg/XenBusDxe: Rework watch events reception
  OvmfPkg/XenBusDxe: Avoid Allocate in XenStoreVSPrint
  OvmfPkg/XenBusDxe: Construct paths without allocation
  OvmfPkg/XenBusDxe: Rework XenStoreProcessMessage to avoid allocating
memory
  OvmfPkg/XenBusDxe: Use on stack buffer in internal functions
  OvmfPkg/XenBus: Change XENBUS_PROTOCOL to not return allocated memory
  OvmfPkg/XenBusDxe: Fix NotifyExitBoot to avoid Memory Allocation
Services
  OvmfPkg/XenPvBlkDxe: Use XenBusIo->RegisterExitCallback
  OvmfPkg/XenBusDxe: Fix XenStoreWaitForEvent use during EBS

 OvmfPkg/Include/Protocol/XenBus.h |  67 +++-
 OvmfPkg/XenBusDxe/EventChannel.c  |   3 +-
 OvmfPkg/XenBusDxe/XenBus.c|  58 ++-
 OvmfPkg/XenBusDxe/XenBusDxe.c |  29 +-
 OvmfPkg/XenBusDxe/XenBusDxe.h |   3 +
 OvmfPkg/XenBusDxe/XenStore.c  | 577 +-
 OvmfPkg/XenBusDxe/XenStore.h  |  44 ++-
 OvmfPkg/XenPvBlkDxe/BlockFront.c  |  82 +++--
 OvmfPkg/XenPvBlkDxe/BlockFront.h  |  12 +-
 OvmfPkg/XenPvBlkDxe/XenPvBlkDxe.c |   4 +-
 10 files changed, 483 insertions(+), 396 deletions(-)

-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#47208): https://edk2.groups.io/g/devel/message/47208
Mute This Topic: https://groups.io/mt/34128009/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH 07/11] OvmfPkg/XenBusDxe: Use on stack buffer in internal functions

2019-09-13 Thread Anthony PERARD
We will use a buffer on the stack instead of allocating memory for
internal functions that are expecting a reply from xenstore.

The external interface XENBUS_PROTOCOL isn't changed yet, so
allocation are made for XsRead and XsBackendRead.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2190
Signed-off-by: Anthony PERARD 
---
 OvmfPkg/XenBusDxe/XenBus.c   |  40 ++--
 OvmfPkg/XenBusDxe/XenStore.c | 115 ---
 OvmfPkg/XenBusDxe/XenStore.h |  17 +++---
 3 files changed, 95 insertions(+), 77 deletions(-)

diff --git a/OvmfPkg/XenBusDxe/XenBus.c b/OvmfPkg/XenBusDxe/XenBus.c
index bb8ddbc4d4..78835ec7b3 100644
--- a/OvmfPkg/XenBusDxe/XenBus.c
+++ b/OvmfPkg/XenBusDxe/XenBus.c
@@ -89,19 +89,18 @@ XenBusReadDriverState (
   IN CONST CHAR8 *Path
   )
 {
-  XenbusState State;
-  CHAR8 *Ptr = NULL;
+  XenbusState State;
+  CHAR8   Buffer[4];
+  UINTN   BufferSize;
   XENSTORE_STATUS Status;
 
-  Status = XenStoreRead (XST_NIL, Path, "state", NULL, (VOID **));
+  BufferSize = sizeof (Buffer) - 1;
+  Status = XenStoreRead (XST_NIL, Path, "state", , Buffer);
   if (Status != XENSTORE_STATUS_SUCCESS) {
 State = XenbusStateClosed;
   } else {
-State = AsciiStrDecimalToUintn (Ptr);
-  }
-
-  if (Ptr != NULL) {
-FreePool (Ptr);
+Buffer[BufferSize] = '\0';
+State = AsciiStrDecimalToUintn (Buffer);
   }
 
   return State;
@@ -129,8 +128,11 @@ XenBusAddDevice (
 
   if (XenStorePathExists (XST_NIL, DevicePath, "")) {
 XENBUS_PRIVATE_DATA *Child;
-enum xenbus_state State;
-CHAR8 *BackendPath;
+enum xenbus_state   State;
+CHAR8   BackendPath[XENSTORE_ABS_PATH_MAX + 1];
+UINTN   BackendPathSize;
+
+BackendPathSize = sizeof (BackendPath);
 
 Child = XenBusDeviceInitialized (Dev, DevicePath);
 if (Child != NULL) {
@@ -155,17 +157,18 @@ XenBusAddDevice (
 }
 
 StatusXenStore = XenStoreRead (XST_NIL, DevicePath, "backend",
-   NULL, (VOID **) );
+  , BackendPath);
 if (StatusXenStore != XENSTORE_STATUS_SUCCESS) {
   DEBUG ((EFI_D_ERROR, "xenbus: %a no backend path.\n", DevicePath));
   Status = EFI_NOT_FOUND;
   goto out;
 }
+BackendPath[BackendPathSize] = '\0';
 
 Private = AllocateCopyPool (sizeof (*Private), );
 Private->XenBusIo.Type = AsciiStrDup (Type);
 Private->XenBusIo.Node = AsciiStrDup (DevicePath);
-Private->XenBusIo.Backend = BackendPath;
+Private->XenBusIo.Backend = AsciiStrDup (BackendPath);
 Private->XenBusIo.DeviceId = (UINT16)AsciiStrDecimalToUintn (Id);
 Private->Dev = Dev;
 
@@ -309,17 +312,20 @@ XenBusSetState (
   )
 {
   enum xenbus_state CurrentState;
-  XENSTORE_STATUS Status;
-  CHAR8 *Temp;
+  XENSTORE_STATUS   Status;
+  CHAR8 Buffer[4];
+  UINTN BufferSize;
+
+  BufferSize = sizeof (Buffer) - 1;
 
   DEBUG ((EFI_D_INFO, "XenBus: Set state to %d\n", NewState));
 
-  Status = XenStoreRead (Transaction, This->Node, "state", NULL, (VOID 
**));
+  Status = XenStoreRead (Transaction, This->Node, "state", , 
Buffer);
   if (Status != XENSTORE_STATUS_SUCCESS) {
 goto Out;
   }
-  CurrentState = AsciiStrDecimalToUintn (Temp);
-  FreePool (Temp);
+  Buffer[BufferSize] = '\0';
+  CurrentState = AsciiStrDecimalToUintn (Buffer);
   if (CurrentState == NewState) {
 goto Out;
   }
diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c
index 004d3b6022..b9588bb8c6 100644
--- a/OvmfPkg/XenBusDxe/XenStore.c
+++ b/OvmfPkg/XenBusDxe/XenStore.c
@@ -756,8 +756,9 @@ XenStoreGetError (
   @param RequestTypeThe type of message to send.
   @param WriteRequest   Pointers to the body sections of the request.
   @param NumRequestsThe number of body sections in the request.
-  @param LenPtr The returned length of the reply.
-  @param ResultPtr  The returned body of the reply.
+  @param BufferSize IN: size of the buffer
+OUT: The returned length of the reply.
+  @param Buffer The returned body of the reply.
 
   @return  XENSTORE_STATUS_SUCCESS on success.  Otherwise an errno indicating
the cause of failure.
@@ -769,15 +770,13 @@ XenStoreTalkv (
   IN  enum xsd_sockmsg_type   RequestType,
   IN  CONST WRITE_REQUEST *WriteRequest,
   IN  UINT32  NumRequests,
-  OUT UINT32  *LenPtr OPTIONAL,
-  OUT VOID**ResultPtr OPTIONAL
+  IN OUT UINTN*BufferSize OPTIONAL,
+  OUT VOID*Buffer OPTIONAL
   )
 {
   struct xsd_sockmsg Message;
   UINTN  Index;
   XENSTORE_STATUSStatus;
-  VOID   *Buffer;
-  UINTN  BufferSize;
 
   if (Transaction == XST_NIL) {
 Message.tx_id = 0;
@@ -805,32 +804,15 @@ XenStoreTalkv (
 }
   }
 
-  if (ResultPtr) {
-Buffer = 

[edk2-devel] [PATCH 02/11] OvmfPkg/XenBusDxe: Have XenStoreFindWatch take a pointer

2019-09-13 Thread Anthony PERARD
Rework XenStoreFindWatch() to be able to search for a registered watch
with a pointer instead of a string.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2190
Signed-off-by: Anthony PERARD 
---
 OvmfPkg/XenBusDxe/XenStore.c | 20 +++-
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c
index 7253d8ae37..727641a0fe 100644
--- a/OvmfPkg/XenBusDxe/XenStore.c
+++ b/OvmfPkg/XenBusDxe/XenStore.c
@@ -253,14 +253,12 @@ Split (
 STATIC
 XENSTORE_WATCH *
 XenStoreFindWatch (
-  IN CONST CHAR8 *Token
+  IN VOID *Token
   )
 {
-  XENSTORE_WATCH *Watch, *WantedWatch;
+  XENSTORE_WATCH *Watch;
   LIST_ENTRY *Entry;
 
-  WantedWatch = (VOID *) AsciiStrHexToUintn (Token);
-
   if (IsListEmpty ()) {
 return NULL;
   }
@@ -268,7 +266,7 @@ XenStoreFindWatch (
!IsNull (, Entry);
Entry = GetNextNode (, Entry)) {
 Watch = XENSTORE_WATCH_FROM_LINK (Entry);
-if (Watch == WantedWatch)
+if ((VOID *) Watch == Token)
   return Watch;
   }
 
@@ -632,12 +630,16 @@ XenStoreProcessMessage (
   Body[Message->Header.len] = '\0';
 
   if (Message->Header.type == XS_WATCH_EVENT) {
+VOID *ConvertedToken;
+
 Message->u.Watch.Vector = Split(Body, Message->Header.len,
 >u.Watch.VectorSize);
 
+ConvertedToken =
+  (VOID *) AsciiStrHexToUintn (Message->u.Watch.Vector[XS_WATCH_TOKEN]);
+
 EfiAcquireLock ();
-Message->u.Watch.Handle =
-  XenStoreFindWatch (Message->u.Watch.Vector[XS_WATCH_TOKEN]);
+Message->u.Watch.Handle = XenStoreFindWatch (ConvertedToken);
 DEBUG ((EFI_D_INFO, "XenStore: Watch event %a\n",
 Message->u.Watch.Vector[XS_WATCH_TOKEN]));
 if (Message->u.Watch.Handle != NULL) {
@@ -1384,8 +1386,7 @@ XenStoreUnregisterWatch (
 
   ASSERT (Watch->Signature == XENSTORE_WATCH_SIGNATURE);
 
-  AsciiSPrint (Token, sizeof (Token), "%p", (VOID *) Watch);
-  if (XenStoreFindWatch (Token) == NULL) {
+  if (XenStoreFindWatch (Watch) == NULL) {
 return;
   }
 
@@ -1393,6 +1394,7 @@ XenStoreUnregisterWatch (
   RemoveEntryList (>Link);
   EfiReleaseLock ();
 
+  AsciiSPrint (Token, sizeof (Token), "%p", (VOID *) Watch);
   XenStoreUnwatch (Watch->Node, Token);
 
   /* Cancel pending watch events. */
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#47211): https://edk2.groups.io/g/devel/message/47211
Mute This Topic: https://groups.io/mt/34128012/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH 22/35] OvmfPkg/XenBusDxe: fix UninstallMultipleProtocolInterfaces() call

2019-09-18 Thread Anthony PERARD
On Tue, Sep 17, 2019 at 09:49:22PM +0200, Laszlo Ersek wrote:
> Unlike the InstallMultipleProtocolInterfaces() boot service, which takes
> an (EFI_HANDLE*) as first parameter, the
> UninstallMultipleProtocolInterfaces() boot service takes an EFI_HANDLE as
> first parameter.
> 
> This is an actual bug. It must have remained hidden until now because it's
> on an error path. Fix the UninstallMultipleProtocolInterfaces() call.
> 
> Cc: Anthony Perard 
> Cc: Ard Biesheuvel 
> Cc: Jordan Justen 
> Cc: Julien Grall 
> Signed-off-by: Laszlo Ersek 

Reviewed-by: Anthony PERARD 

Thanks,

-- 
Anthony PERARD

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#47473): https://edk2.groups.io/g/devel/message/47473
Mute This Topic: https://groups.io/mt/34180223/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v4 03/35] OvmfPkg: Introduce XenResetVector

2019-07-29 Thread Anthony PERARD
Introduce XenResetVector, a copy of OvmfPkg/ResetVector, with one
changes:
  - SEC_DEFAULT_CR0: enable cache (bit 30 or CD set to 0)

Xen copies the OVMF code to RAM, there is no need to disable cache.

This new module will later be modified to add a new entry point, more
detail in a following commit "OvmfPkg/XenResetVector: Add new entry point
for Xen PVH"

Value FILE_GUID of XenResetVector have not changed compare to ResetVector
because it is a special value (gEfiFirmwareVolumeTopFileGuid).

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Reviewed-by: Laszlo Ersek 
---

Notes:
v4:
- Update Maintainers.txt

v3:
  - Added gEfiFirmwareVolumeTopFileGuid to the commit message.
  - rebased: SPDX

 OvmfPkg/OvmfXen.dsc   |   2 +-
 OvmfPkg/OvmfXen.fdf   |   2 +-
 OvmfPkg/XenResetVector/XenResetVector.inf |  38 +
 Maintainers.txt   |   1 +
 .../XenResetVector/Ia16/Real16ToFlat32.asm| 134 
 OvmfPkg/XenResetVector/Ia32/PageTables64.asm  | 149 ++
 OvmfPkg/XenResetVector/XenResetVector.nasmb   |  68 
 7 files changed, 392 insertions(+), 2 deletions(-)
 create mode 100644 OvmfPkg/XenResetVector/XenResetVector.inf
 create mode 100644 OvmfPkg/XenResetVector/Ia16/Real16ToFlat32.asm
 create mode 100644 OvmfPkg/XenResetVector/Ia32/PageTables64.asm
 create mode 100644 OvmfPkg/XenResetVector/XenResetVector.nasmb

diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index f224ac32b4..1a0e59f0cc 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -495,7 +495,7 @@ [PcdsDynamicDefault]
 #
 

 [Components]
-  OvmfPkg/ResetVector/ResetVector.inf
+  OvmfPkg/XenResetVector/XenResetVector.inf
 
   #
   # SEC Phase modules
diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf
index f59647fd14..6fc8479aae 100644
--- a/OvmfPkg/OvmfXen.fdf
+++ b/OvmfPkg/OvmfXen.fdf
@@ -118,7 +118,7 @@ [FV.SECFV]
 #
 INF  OvmfPkg/Sec/SecMain.inf
 
-INF  RuleOverride=RESET_VECTOR OvmfPkg/ResetVector/ResetVector.inf
+INF  RuleOverride=RESET_VECTOR OvmfPkg/XenResetVector/XenResetVector.inf
 
 

 [FV.PEIFV]
diff --git a/OvmfPkg/XenResetVector/XenResetVector.inf 
b/OvmfPkg/XenResetVector/XenResetVector.inf
new file mode 100644
index 00..097fc9b5b4
--- /dev/null
+++ b/OvmfPkg/XenResetVector/XenResetVector.inf
@@ -0,0 +1,38 @@
+## @file
+#  Reset Vector
+#
+#  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+#  Copyright (c) 2019, Citrix Systems, Inc.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION= 0x00010005
+  BASE_NAME  = XenResetVector
+  FILE_GUID  = 1BA0062E-C779-4582-8566-336AE8F78F09
+  MODULE_TYPE= SEC
+  VERSION_STRING = 1.1
+
+#
+# The following information is for reference only and not required by the 
build tools.
+#
+#  VALID_ARCHITECTURES   = IA32 X64
+#
+
+[Sources]
+  XenResetVector.nasmb
+
+[Packages]
+  OvmfPkg/OvmfPkg.dec
+  MdePkg/MdePkg.dec
+  UefiCpuPkg/UefiCpuPkg.dec
+
+[BuildOptions]
+   *_*_IA32_NASMB_FLAGS = -I$(WORKSPACE)/UefiCpuPkg/ResetVector/Vtf0/
+   *_*_X64_NASMB_FLAGS = -I$(WORKSPACE)/UefiCpuPkg/ResetVector/Vtf0/
+
+[Pcd]
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize
diff --git a/Maintainers.txt b/Maintainers.txt
index 98f6d828eb..34bdb275b4 100644
--- a/Maintainers.txt
+++ b/Maintainers.txt
@@ -380,6 +380,7 @@ F: OvmfPkg/SmbiosPlatformDxe/*Xen.c
 F: OvmfPkg/XenBusDxe/
 F: OvmfPkg/XenIoPciDxe/
 F: OvmfPkg/XenPvBlkDxe/
+F: OvmfPkg/XenResetVector/
 R: Anthony Perard 
 R: Julien Grall 
 
diff --git a/OvmfPkg/XenResetVector/Ia16/Real16ToFlat32.asm 
b/OvmfPkg/XenResetVector/Ia16/Real16ToFlat32.asm
new file mode 100644
index 00..5c329bfaea
--- /dev/null
+++ b/OvmfPkg/XenResetVector/Ia16/Real16ToFlat32.asm
@@ -0,0 +1,134 @@
+;--
+; @file
+; Transition from 16 bit real mode into 32 bit flat protected mode
+;
+; Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.
+; Copyright (c) 2019, Citrix Systems, Inc.
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;
+;--
+
+%define SEC_DEFAULT_CR0  0x0023
+%define SEC_DEFAULT_CR4  0x640
+
+BITS16
+
+;
+; Modified:  EAX, EBX
+;
+; @param[out] DS   Selector allowing flat access to all addresses
+; @param[out] ES   Selector allowing flat access to all addresses
+; @param[out] FS   Selector allowing flat access to all addresses
+; @param[out] GS   Selector allowing flat access to all

[edk2-devel] [PATCH v4 07/35] OvmfPkg/XenResetVector: Saving start of day pointer for PVH guests

2019-07-29 Thread Anthony PERARD
As described in the Xen PVH documentation [1], "ebx: contains the
physical memory address where the loader has placed the boot start info
structure". To have this pointer saved to be able to use it later in the
PEI phase, we allocate some space in the MEMFD for it. We use 'XPVH' as
a signature (for "Xen PVH").

[1] https://xenbits.xenproject.org/docs/unstable/misc/pvh.html

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v3:
- rename PcdXenStartOfDay* to PcdXenPvhStartOfDay*
- Use first available token value for those (0x17 and 0x28)

 OvmfPkg/OvmfPkg.dec | 3 +++
 OvmfPkg/OvmfXen.fdf | 4 
 OvmfPkg/XenResetVector/XenResetVector.inf   | 3 +++
 OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm  | 6 ++
 OvmfPkg/XenResetVector/XenResetVector.nasmb | 2 ++
 5 files changed, 18 insertions(+)

diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index 9640360f62..c2a2ebfb95 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -218,6 +218,9 @@ [PcdsFixedAtBuild]
   #  The value should be a multiple of 4KB.
   gUefiOvmfPkgTokenSpaceGuid.PcdHighPmmMemorySize|0x40|UINT32|0x31
 
+  gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtr|0x0|UINT32|0x17
+  gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtrSize|0x0|UINT32|0x32
+
 [PcdsDynamic, PcdsDynamicEx]
   gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x10
diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf
index 43c268f6cb..49997fee9b 100644
--- a/OvmfPkg/OvmfXen.fdf
+++ b/OvmfPkg/OvmfXen.fdf
@@ -172,6 +172,10 @@ [FD.MEMFD]
 0x007000|0x001000
 
gEfiMdePkgTokenSpaceGuid.PcdGuidedExtractHandlerTableAddress|gUefiOvmfPkgTokenSpaceGuid.PcdGuidedExtractHandlerTableSize
 
+0x008000|0x001000
+# Used by XenResetVector to communicate with XenPlatformPei
+gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtr|gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtrSize
+
 0x01|0x01
 
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize
 
diff --git a/OvmfPkg/XenResetVector/XenResetVector.inf 
b/OvmfPkg/XenResetVector/XenResetVector.inf
index 097fc9b5b4..46b133a834 100644
--- a/OvmfPkg/XenResetVector/XenResetVector.inf
+++ b/OvmfPkg/XenResetVector/XenResetVector.inf
@@ -36,3 +36,6 @@ [BuildOptions]
 [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize
+
+  gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtr
+  gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtrSize
diff --git a/OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm 
b/OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm
index 2a17fed52f..f42df3dba2 100644
--- a/OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm
+++ b/OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm
@@ -22,6 +22,12 @@ xenPVHMain:
 ;
 xor esp, esp
 
+;
+; Store "Start of day" struct pointer for later use
+;
+mov dword[PVH_SPACE (0)], ebx
+mov dword[PVH_SPACE (4)], 'XPVH'
+
 mov ebx, ADDR_OF(gdtr)
 lgdt[ebx]
 
diff --git a/OvmfPkg/XenResetVector/XenResetVector.nasmb 
b/OvmfPkg/XenResetVector/XenResetVector.nasmb
index 0dbc4f2c1d..b2cb405d54 100644
--- a/OvmfPkg/XenResetVector/XenResetVector.nasmb
+++ b/OvmfPkg/XenResetVector/XenResetVector.nasmb
@@ -34,6 +34,8 @@
 
 %include "CommonMacros.inc"
 
+%define PVH_SPACE(Offset) (FixedPcdGet32 (PcdXenPvhStartOfDayStructPtr) + 
(Offset))
+
 %include "PostCodes.inc"
 
 %ifdef DEBUG_PORT80
-- 
Anthony PERARD


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#44527): https://edk2.groups.io/g/devel/message/44527
Mute This Topic: https://groups.io/mt/32643832/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v4 05/35] OvmfPkg/OvmfXen: Creating an ELF header

2019-07-29 Thread Anthony PERARD
This patch changes the flash device image of OvmfXen to make it look
like it's an ELF. For this, we replace the empty embedded variable store
by a binary array, which is a ELF file header.

The ELF header explain to a loader to load the binary at the address
1MB, then jump to the PVH entry point which will be created in a later
patch. The header also includes a Xen ELF note that is part of the
PVH ABI.

That patch include OvmfXenElfHeaderGenerator.c which can be use to
regenerate the ELF header, but this will be a manual step.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v4:
- fix top-level comment style
- Update Maintainers.txt

v3:
- added license to generate_elf_header.c
  which is renamed to OvmfPkg/OvmfXenElfHeaderGenerator.c
- added an ELF NOTE into the header

 OvmfPkg/OvmfXen.fdf | 101 +++-
 OvmfPkg/OvmfXenElfHeaderGenerator.c | 140 
 Maintainers.txt |   1 +
 3 files changed, 239 insertions(+), 3 deletions(-)
 create mode 100644 OvmfPkg/OvmfXenElfHeaderGenerator.c

diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf
index 2ceff7baa2..43c268f6cb 100644
--- a/OvmfPkg/OvmfXen.fdf
+++ b/OvmfPkg/OvmfXen.fdf
@@ -15,8 +15,8 @@ [Defines]
 !include OvmfPkg.fdf.inc
 
 #
-# Build the variable store and the firmware code as one unified flash device
-# image.
+# This will allow the flash device image to be recognize as an ELF, with first
+# an ELF headers, then the firmware code.
 #
 [FD.OVMF]
 BaseAddress   = $(FW_BASE_ADDRESS)
@@ -25,7 +25,102 @@ [FD.OVMF]
 BlockSize = $(BLOCK_SIZE)
 NumBlocks = $(FW_BLOCKS)
 
-!include VarStore.fdf.inc
+!if ($(FD_SIZE_IN_KB) == 1024) || ($(FD_SIZE_IN_KB) == 2048)
+0x|0xe000
+!endif
+!if $(FD_SIZE_IN_KB) == 4096
+0x|0x0004
+!endif
+DATA = {
+  #
+  # This hex array have been generated by OvmfPkg/OvmfXenElfHeaderGenerator.c
+  # and copied manually.
+  #
+  # ELF file header
+  0x7f, 0x45, 0x4c, 0x46, # e_ident[0..3]: Magic number
+  0x01, # File class: 32-bit objects
+  0x01, # Data encoding: 2's complement, little endian
+  0x01, # File version
+  0x03, # OS ABI identification: Object uses GNU ELF extensions
+  0x00, # ABI version
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  # e_ident[EI_PAD...]
+  0x02, 0x00, # e_type = Executable file
+  0x03, 0x00, # e_machine = Intel 80386
+  0x01, 0x00, 0x00, 0x00, # e_version
+  0xd0, 0xff, 0x2f, 0x00, # e_entry: Entry point virtual address
+  0x34, 0x00, 0x00, 0x00, # e_phoff: Program header table file offset
+  0x00, 0x00, 0x00, 0x00, # e_shoff: Section header table file offset
+  0x00, 0x00, 0x00, 0x00, # e_flags: Processor-specific flags
+  0x34, 0x00, #e_ehsize: ELF header size
+  0x20, 0x00, # e_phentsize: Program header table entry size
+  0x02, 0x00, # e_phnum: Program header table entry count
+  0x00, 0x00, # e_shentsize: Section header table entry size
+  0x00, 0x00, # e_shnum: Section header table entry count
+  0x00, 0x00, # e_shstrndx
+
+  # ELF Program segment headers
+  # - Load segment
+  0x01, 0x00, 0x00, 0x00, # p_type = Loadable program segment
+  0x00, 0x00, 0x00, 0x00, # p_offset
+  0x00, 0x00, 0x10, 0x00, # p_vaddr: Segment virtual address
+  0x00, 0x00, 0x10, 0x00, # p_paddr: Segment physical address
+  0x00, 0x00, 0x20, 0x00, # p_filesz: Segment size in file
+  0x00, 0x00, 0x20, 0x00, # p_memsz: Segment size in memory
+  0x07, 0x00, 0x00, 0x00, # p_flags = Segment is executable | writable | 
readable
+  0x00, 0x00, 0x00, 0x00, # p_align
+  # - ELFNOTE segment
+  0x04, 0x00, 0x00, 0x00, # p_type = PT_NOTE
+  0x74, 0x00, 0x00, 0x00, # p_offset = point to XEN_ELFNOTE_PHYS32_ENTRY below
+  0x74, 0x00, 0x10, 0x00,
+  0x74, 0x00, 0x10, 0x00,
+  0x14, 0x00, 0x00, 0x00,
+  0x14, 0x00, 0x00, 0x00,
+  0x04, 0x00, 0x00, 0x00, # p_flags = Segment is readable
+  0x00, 0x00, 0x00, 0x00,
+
+  # XEN_ELFNOTE_PHYS32_ENTRY
+  0x04, 0x00, 0x00, 0x00, # name size
+  0x04, 0x00, 0x00, 0x00, # desc size
+  0x12, 0x00, 0x00, 0x00, # type = XEN_ELFNOTE_PHYS32_ENTRY
+  0x58, 0x65, 0x6e, 0x00, # name = "Xen"
+  0xd0, 0xff, 0x2f, 0x00, # desc: PVH entry point
+  0x00
+}
+
+!if ($(FD_SIZE_IN_KB) == 1024) || ($(FD_SIZE_IN_KB) == 2048)
+0xe000|0x1000
+!endif
+!if $(FD_SIZE_IN_KB) == 4096
+0x0004|0x1000
+!endif
+#NV_EVENT_LOG
+
+!if ($(FD_SIZE_IN_KB) == 1024) || ($(FD_SIZE_IN_KB) == 2048)
+0xf000|0x1000
+!endif
+!if $(FD_SIZE_IN_KB) == 4096
+0x00041000|0x1000
+!endif
+#NV_FTW_WORKING
+DATA = {
+  # EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER->Signature = 
gEdkiiWorkingBlockSignatureGuid =
+  #  { 0x9e58292b, 0x7c68, 0x497d, { 0xa0, 0xce, 0x65,  0x0, 0xfd, 0x9f, 0x1b, 
0x95 }}
+  0x2b, 0x29, 0x58, 0x9e, 0x68, 0x7c, 0x7d, 0x49,
+  0xa0, 0xce, 0x65,  0x0, 0xfd, 0x9f, 0x1b, 0x95,
+  # Crc:UINT32#WorkingBlockValid:1, WorkingBlockInvalid:1, Reserved
+  0x2

[edk2-devel] [PATCH v4 04/35] OvmfPkg: Introduce XenPlatformPei

2019-07-29 Thread Anthony PERARD
Introduce XenPlatformPei, a copy of OvmfPkg/PlatformPei without some
of QEMU specific initialization, Xen does not support QemuFwCfg.

This new module will be adjusted to accommodate Xen PVH.

fw_cfg dependents that have been removed, which are dynamically skipped
when running PlatformPei on Xen:
- GetFirstNonAddress(): controlling the 64-bit PCI MMIO aperture via the
(experimental) "opt/ovmf/X-PciMmio64Mb" file
- GetFirstNonAddress(): honoring the hotplug DIMM area
("etc/reserved-memory-end") in the placement of the 64-bit PCI MMIO
aperture
- NoexecDxeInitialization() is removed, so PcdPropertiesTableEnable and
PcdSetNxForStack are left constant FALSE (not set dynamically from
fw_cfg "opt/ovmf/PcdXxxx")
- MaxCpuCountInitialization(), PublishPeiMemory(): the max CPU count is
not taken from the QemuFwCfgItemSmpCpuCount fw_cfg key;
PcdCpuMaxLogicalProcessorNumber is used intact and
PcdCpuApInitTimeOutInMicroSeconds is never changed or used.
- InitializeXenPlatform(), S3Verification(): S3 is assumed disabled (not
consulting "etc/system-states" via QemuFwCfgS3Enabled()).
- InstallFeatureControlCallback(): the feature control MSR is not set
from "etc/msr_feature_control"
(also removed FeatureControl.c as there is nothing been executed)

Also removed:
- SMRAM/TSEG-related low mem size adjusting (PcdSmmSmramRequire is
assumed FALSE) in PublishPeiMemory(),
- QemuInitializeRam() entirely,

Xen related changes:
- Have removed the module variable mXen, as it should be always true.
- Have the platform PEI initialization fails if Xen has not been
  detected.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Reviewed-by: Laszlo Ersek 
---

Notes:
v4:
  - replace the other EFI_D_ by DEBUG_.
  - Update Maintainers.txt
  - fix one trailing whitespace

v3:
  - fix coding style in new code
(use DEBUG_xxx, add ASSERT before CpuDeadLoop)
  - rebased, SPDX

 OvmfPkg/OvmfXen.dsc   |   2 +-
 OvmfPkg/OvmfXen.fdf   |   2 +-
 OvmfPkg/XenPlatformPei/XenPlatformPei.inf |  96 +
 OvmfPkg/XenPlatformPei/Cmos.h |  52 +++
 OvmfPkg/XenPlatformPei/Platform.h | 108 ++
 OvmfPkg/XenPlatformPei/Xen.h  |  39 ++
 OvmfPkg/XenPlatformPei/AmdSev.c   |  64 
 OvmfPkg/XenPlatformPei/ClearCache.c   | 112 ++
 OvmfPkg/XenPlatformPei/Cmos.c |  60 +++
 OvmfPkg/XenPlatformPei/Fv.c   |  76 
 OvmfPkg/XenPlatformPei/MemDetect.c| 421 
 OvmfPkg/XenPlatformPei/Platform.c | 444 ++
 OvmfPkg/XenPlatformPei/Xen.c  | 219 +++
 Maintainers.txt   |   1 +
 14 files changed, 1694 insertions(+), 2 deletions(-)
 create mode 100644 OvmfPkg/XenPlatformPei/XenPlatformPei.inf
 create mode 100644 OvmfPkg/XenPlatformPei/Cmos.h
 create mode 100644 OvmfPkg/XenPlatformPei/Platform.h
 create mode 100644 OvmfPkg/XenPlatformPei/Xen.h
 create mode 100644 OvmfPkg/XenPlatformPei/AmdSev.c
 create mode 100644 OvmfPkg/XenPlatformPei/ClearCache.c
 create mode 100644 OvmfPkg/XenPlatformPei/Cmos.c
 create mode 100644 OvmfPkg/XenPlatformPei/Fv.c
 create mode 100644 OvmfPkg/XenPlatformPei/MemDetect.c
 create mode 100644 OvmfPkg/XenPlatformPei/Platform.c
 create mode 100644 OvmfPkg/XenPlatformPei/Xen.c

diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index 1a0e59f0cc..7619a89382 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -523,7 +523,7 @@ [Components]
   }
   MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
 
-  OvmfPkg/PlatformPei/PlatformPei.inf
+  OvmfPkg/XenPlatformPei/XenPlatformPei.inf
   UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf
   UefiCpuPkg/CpuMpPei/CpuMpPei.inf
 
diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf
index 6fc8479aae..2ceff7baa2 100644
--- a/OvmfPkg/OvmfXen.fdf
+++ b/OvmfPkg/OvmfXen.fdf
@@ -152,7 +152,7 @@ [FV.PEIFV]
 INF  MdeModulePkg/Universal/PCD/Pei/Pcd.inf
 INF  
MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf
 INF  MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf
-INF  OvmfPkg/PlatformPei/PlatformPei.inf
+INF  OvmfPkg/XenPlatformPei/XenPlatformPei.inf
 INF  MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
 INF  UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf
 INF  UefiCpuPkg/CpuMpPei/CpuMpPei.inf
diff --git a/OvmfPkg/XenPlatformPei/XenPlatformPei.inf 
b/OvmfPkg/XenPlatformPei/XenPlatformPei.inf
new file mode 100644
index 00..d1265c365a
--- /dev/null
+++ b/OvmfPkg/XenPlatformPei/XenPlatformPei.inf
@@ -0,0 +1,96 @@
+## @file
+#  Platform PEI driver
+#
+#  This module provides platform specific function to detect boot mode.
+#  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
+#  Copyright (c) 2019, Citrix Systems, Inc.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VE

[edk2-devel] [PATCH v4 08/35] OvmfPkg/XenResetVector: Allow jumpstart from either hvmloader or PVH

2019-07-29 Thread Anthony PERARD
This patch allows the ResetVector to be run indenpendently from build
time addresses.

The goal of the patch is to avoid having to create RAM just below 4G
when creating a Xen PVH guest while being compatible with the way
hvmloader currently load OVMF, just below 4G.

Only the new PVH entry point will do the calculation.

The ResetVector will figure out its current running address by creating
a temporary stack, make a call and calculate the difference between the
build time address and the address at run time.

This patch copies and make the necessary modification to some other asm
files:
- copy of UefiCpuPkg/.../Flat32ToFlat64.asm:
  Allow Transition32FlatTo64Flat to be run from anywhere in memory
- copy of UefiCpuPkg/../SearchForBfvBase.asm:
  Add a extra parameter to indicate where to start the search for the
  boot firmware volume.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD 
Acked-by: Laszlo Ersek 
---

Notes:
v3:
- rebased, SPDX
- fix commit message

 .../XenResetVector/Ia16/Real16ToFlat32.asm|  3 +
 .../XenResetVector/Ia32/Flat32ToFlat64.asm| 68 +++
 .../XenResetVector/Ia32/SearchForBfvBase.asm  | 87 +++
 OvmfPkg/XenResetVector/Ia32/XenPVHMain.asm| 43 +++--
 4 files changed, 194 insertions(+), 7 deletions(-)
 create mode 100644 OvmfPkg/XenResetVector/Ia32/Flat32ToFlat64.asm
 create mode 100644 OvmfPkg/XenResetVector/Ia32/SearchForBfvBase.asm

diff --git a/OvmfPkg/XenResetVector/Ia16/Real16ToFlat32.asm 
b/OvmfPkg/XenResetVector/Ia16/Real16ToFlat32.asm
index 5c329bfaea..36ea74f7fe 100644
--- a/OvmfPkg/XenResetVector/Ia16/Real16ToFlat32.asm
+++ b/OvmfPkg/XenResetVector/Ia16/Real16ToFlat32.asm
@@ -54,6 +54,9 @@ jumpTo32BitAndLandHere:
 mov gs, ax
 mov ss, ax
 
+; parameter for Flat32SearchForBfvBase
+xor eax, eax ; Start searching from top of 4GB for BfvBase
+
 OneTimeCallRet TransitionFromReal16To32BitFlat
 
 ALIGN   2
diff --git a/OvmfPkg/XenResetVector/Ia32/Flat32ToFlat64.asm 
b/OvmfPkg/XenResetVector/Ia32/Flat32ToFlat64.asm
new file mode 100644
index 00..661a8e7028
--- /dev/null
+++ b/OvmfPkg/XenResetVector/Ia32/Flat32ToFlat64.asm
@@ -0,0 +1,68 @@
+;--
+; @file
+; Transition from 32 bit flat protected mode into 64 bit flat protected mode
+;
+; Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.
+; Copyright (c) 2019, Citrix Systems, Inc.
+;
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;
+;--
+
+BITS32
+
+;
+; Modified:  EAX, EBX, ECX, EDX, ESP
+;
+Transition32FlatTo64Flat:
+
+OneTimeCall SetCr3ForPageTables64
+
+mov eax, cr4
+bts eax, 5  ; enable PAE
+mov cr4, eax
+
+mov ecx, 0xc080
+rdmsr
+bts eax, 8  ; set LME
+wrmsr
+
+mov eax, cr0
+bts eax, 31 ; set PG
+mov cr0, eax; enable paging
+
+;
+; backup ESP
+;
+mov ebx, esp
+
+;
+; recalculate delta
+;
+mov esp, PVH_SPACE(16)
+call.delta
+.delta:
+pop edx
+sub edx, ADDR_OF(.delta)
+
+;
+; push return addr and seg to the stack, then return far
+;
+pushdword LINEAR_CODE64_SEL
+mov eax, ADDR_OF(jumpTo64BitAndLandHere)
+add eax, edx ; add delta
+pusheax
+retf
+
+BITS64
+jumpTo64BitAndLandHere:
+
+;
+; restore ESP
+;
+mov esp, ebx
+
+debugShowPostCode POSTCODE_64BIT_MODE
+
+OneTimeCallRet Transition32FlatTo64Flat
+
diff --git a/OvmfPkg/XenResetVector/Ia32/SearchForBfvBase.asm 
b/OvmfPkg/XenResetVector/Ia32/SearchForBfvBase.asm
new file mode 100644
index 00..190389c46f
--- /dev/null
+++ b/OvmfPkg/XenResetVector/Ia32/SearchForBfvBase.asm
@@ -0,0 +1,87 @@
+;--
+; @file
+; Search for the Boot Firmware Volume (BFV) base address
+;
+; Copyright (c) 2008 - 2009, Intel Corporation. All rights reserved.
+; Copyright (c) 2019, Citrix Systems, Inc.
+;
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;
+;--
+
+;#define EFI_FIRMWARE_FILE_SYSTEM2_GUID \
+;  { 0x8c8ce578, 0x8a3d, 0x4f1c, { 0x99, 0x35, 0x89, 0x61, 0x85, 0xc3, 0x2d, 
0xd3 } }
+%define FFS_GUID_DWORD0 0x8c8ce578
+%define FFS_GUID_DWORD1 0x4f1c8a3d
+%define FFS_GUID_DWORD2 0x61893599
+%define FFS_GUID_DWORD3 0xd32dc385
+
+BITS32
+
+;
+; Modified:  EAX, EBX, ECX
+; Preserved: EDI, ESP
+;
+; @param[in]   EAX  Start search from here
+; @param[out]  EBP  Address of Boot Firmware Volume (BFV)
+;
+Flat32SearchForBfvBase:
+
+mov ecx, eax
+searchingForBfvHeaderLoop:
+;
+; We check for a firmware volume

  1   2   3   >