Re: [Xen-devel] [PATCH v2 17/29] Ovmf/Xen: refactor XenBusDxe hypercall implementation

2015-02-02 Thread Laszlo Ersek
On 01/27/15 14:10, Ard Biesheuvel wrote:
 On 27 January 2015 at 12:46, Ard Biesheuvel ard.biesheu...@linaro.org wrote:
 On 27 January 2015 at 12:43, Stefano Stabellini
 stefano.stabell...@eu.citrix.com wrote:
 On Mon, 26 Jan 2015, Ard Biesheuvel wrote:
 This refactors the Xen hypercall implementation that is part of the
 XenBusDxe driver, in preparation of splitting it off entirely into
 a XenHypercallLib library. This involves:
 - removing the dependency on XENBUS_DEVICE* pointers in the XenHypercall()
   prototypes
 - moving the discovered hyperpage address to a global variable
 - moving XenGetSharedInfoPage() to its only user XenBusDxe.c (the shared 
 info
   page is not strictly part of the Xen hypercall interface, and is not used
   by other expected users of XenHypercallLib such as the Xen console 
 version
   of SerialPortLib
 - reimplement XenHypercall2() in C and move the indexing of the hyperpage
   there; the existing asm implementations are renamed to __XenHypercall2() 
 and
   invoked from the new C implementation.

 Contributed-under: TianoCore Contribution Agreement 1.0
 Signed-off-by: Ard Biesheuvel ard.biesheu...@linaro.org
 ---
  OvmfPkg/XenBusDxe/EventChannel.c  | 11 +++
  OvmfPkg/XenBusDxe/GrantTable.c|  4 ++--
  OvmfPkg/XenBusDxe/Ia32/hypercall.nasm |  6 +++---
  OvmfPkg/XenBusDxe/X64/hypercall.nasm  |  6 +++---
  OvmfPkg/XenBusDxe/XenBusDxe.c | 44 
 +++-
  OvmfPkg/XenBusDxe/XenBusDxe.h |  1 -
  OvmfPkg/XenBusDxe/XenHypercall.c  | 50 
 ++
  OvmfPkg/XenBusDxe/XenHypercall.h  | 28 +++-
  OvmfPkg/XenBusDxe/XenStore.c  |  4 ++--
  9 files changed, 73 insertions(+), 81 deletions(-)

 diff --git a/OvmfPkg/XenBusDxe/EventChannel.c 
 b/OvmfPkg/XenBusDxe/EventChannel.c
 index 03efaf9cb904..a86323e6adfd 100644
 --- a/OvmfPkg/XenBusDxe/EventChannel.c
 +++ b/OvmfPkg/XenBusDxe/EventChannel.c
 @@ -28,7 +28,7 @@ XenEventChannelNotify (
evtchn_send_t Send;

Send.port = Port;
 -  ReturnCode = XenHypercallEventChannelOp (Dev, EVTCHNOP_send, Send);
 +  ReturnCode = XenHypercallEventChannelOp (EVTCHNOP_send, Send);
return (UINT32)ReturnCode;
  }

 @@ -40,15 +40,12 @@ XenBusEventChannelAllocate (
OUT evtchn_port_t   *Port
)
  {
 -  XENBUS_PRIVATE_DATA *Private;
evtchn_alloc_unbound_t Parameter;
UINT32 ReturnCode;

 -  Private = XENBUS_PRIVATE_DATA_FROM_THIS (This);
 -
Parameter.dom = DOMID_SELF;
Parameter.remote_dom = DomainId;
 -  ReturnCode = (UINT32)XenHypercallEventChannelOp (Private-Dev,
 +  ReturnCode = (UINT32)XenHypercallEventChannelOp (
 EVTCHNOP_alloc_unbound,
 Parameter);
if (ReturnCode != 0) {
 @@ -79,10 +76,8 @@ XenBusEventChannelClose (
IN evtchn_port_t   Port
)
  {
 -  XENBUS_PRIVATE_DATA *Private;
evtchn_close_t Close;

 -  Private = XENBUS_PRIVATE_DATA_FROM_THIS (This);
Close.port = Port;
 -  return (UINT32)XenHypercallEventChannelOp (Private-Dev, 
 EVTCHNOP_close, Close);
 +  return (UINT32)XenHypercallEventChannelOp (EVTCHNOP_close, Close);
  }
 diff --git a/OvmfPkg/XenBusDxe/GrantTable.c 
 b/OvmfPkg/XenBusDxe/GrantTable.c
 index 8405edc51bc4..53cb99f0e004 100644
 --- a/OvmfPkg/XenBusDxe/GrantTable.c
 +++ b/OvmfPkg/XenBusDxe/GrantTable.c
 @@ -161,7 +161,7 @@ XenGrantTableInit (
  Parameters.idx = Index;
  Parameters.space = XENMAPSPACE_grant_table;
  Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable  EFI_PAGE_SHIFT) 
 + Index;
 -ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_add_to_physmap, 
 Parameters);
 +ReturnCode = XenHypercallMemoryOp (XENMEM_add_to_physmap, 
 Parameters);
  if (ReturnCode != 0) {
DEBUG ((EFI_D_ERROR, Xen GrantTable, add_to_physmap hypercall 
 error: %d\n, ReturnCode));
  }
 @@ -184,7 +184,7 @@ XenGrantTableDeinit (
  Parameters.domid = DOMID_SELF;
  Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable  EFI_PAGE_SHIFT) 
 + Index;
  DEBUG ((EFI_D_INFO, Xen GrantTable, removing %X\n, 
 Parameters.gpfn));
 -ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_remove_from_physmap, 
 Parameters);
 +ReturnCode = XenHypercallMemoryOp (XENMEM_remove_from_physmap, 
 Parameters);
  if (ReturnCode != 0) {
DEBUG ((EFI_D_ERROR, Xen GrantTable, remove_from_physmap hypercall 
 error: %d\n, ReturnCode));
  }
 diff --git a/OvmfPkg/XenBusDxe/Ia32/hypercall.nasm 
 b/OvmfPkg/XenBusDxe/Ia32/hypercall.nasm
 index 8547c30b81ee..e0fa71bb5ba8 100644
 --- a/OvmfPkg/XenBusDxe/Ia32/hypercall.nasm
 +++ b/OvmfPkg/XenBusDxe/Ia32/hypercall.nasm
 @@ -2,13 +2,13 @@ SECTION .text

  ; INTN
  ; EFIAPI
 -; XenHypercall2 (
 +; __XenHypercall2 (
  ;   IN VOID *HypercallAddr,
  ;   IN OUT INTN Arg1,
  ;   IN OUT INTN Arg2
  ;   );
 -global ASM_PFX(XenHypercall2)
 -ASM_PFX(XenHypercall2):
 +global ASM_PFX(__XenHypercall2)
 +ASM_PFX(__XenHypercall2):
   

Re: [Xen-devel] [PATCH v2 17/29] Ovmf/Xen: refactor XenBusDxe hypercall implementation

2015-01-27 Thread Ard Biesheuvel
On 27 January 2015 at 12:43, Stefano Stabellini
stefano.stabell...@eu.citrix.com wrote:
 On Mon, 26 Jan 2015, Ard Biesheuvel wrote:
 This refactors the Xen hypercall implementation that is part of the
 XenBusDxe driver, in preparation of splitting it off entirely into
 a XenHypercallLib library. This involves:
 - removing the dependency on XENBUS_DEVICE* pointers in the XenHypercall()
   prototypes
 - moving the discovered hyperpage address to a global variable
 - moving XenGetSharedInfoPage() to its only user XenBusDxe.c (the shared info
   page is not strictly part of the Xen hypercall interface, and is not used
   by other expected users of XenHypercallLib such as the Xen console version
   of SerialPortLib
 - reimplement XenHypercall2() in C and move the indexing of the hyperpage
   there; the existing asm implementations are renamed to __XenHypercall2() 
 and
   invoked from the new C implementation.

 Contributed-under: TianoCore Contribution Agreement 1.0
 Signed-off-by: Ard Biesheuvel ard.biesheu...@linaro.org
 ---
  OvmfPkg/XenBusDxe/EventChannel.c  | 11 +++
  OvmfPkg/XenBusDxe/GrantTable.c|  4 ++--
  OvmfPkg/XenBusDxe/Ia32/hypercall.nasm |  6 +++---
  OvmfPkg/XenBusDxe/X64/hypercall.nasm  |  6 +++---
  OvmfPkg/XenBusDxe/XenBusDxe.c | 44 
 +++-
  OvmfPkg/XenBusDxe/XenBusDxe.h |  1 -
  OvmfPkg/XenBusDxe/XenHypercall.c  | 50 
 ++
  OvmfPkg/XenBusDxe/XenHypercall.h  | 28 +++-
  OvmfPkg/XenBusDxe/XenStore.c  |  4 ++--
  9 files changed, 73 insertions(+), 81 deletions(-)

 diff --git a/OvmfPkg/XenBusDxe/EventChannel.c 
 b/OvmfPkg/XenBusDxe/EventChannel.c
 index 03efaf9cb904..a86323e6adfd 100644
 --- a/OvmfPkg/XenBusDxe/EventChannel.c
 +++ b/OvmfPkg/XenBusDxe/EventChannel.c
 @@ -28,7 +28,7 @@ XenEventChannelNotify (
evtchn_send_t Send;

Send.port = Port;
 -  ReturnCode = XenHypercallEventChannelOp (Dev, EVTCHNOP_send, Send);
 +  ReturnCode = XenHypercallEventChannelOp (EVTCHNOP_send, Send);
return (UINT32)ReturnCode;
  }

 @@ -40,15 +40,12 @@ XenBusEventChannelAllocate (
OUT evtchn_port_t   *Port
)
  {
 -  XENBUS_PRIVATE_DATA *Private;
evtchn_alloc_unbound_t Parameter;
UINT32 ReturnCode;

 -  Private = XENBUS_PRIVATE_DATA_FROM_THIS (This);
 -
Parameter.dom = DOMID_SELF;
Parameter.remote_dom = DomainId;
 -  ReturnCode = (UINT32)XenHypercallEventChannelOp (Private-Dev,
 +  ReturnCode = (UINT32)XenHypercallEventChannelOp (
 EVTCHNOP_alloc_unbound,
 Parameter);
if (ReturnCode != 0) {
 @@ -79,10 +76,8 @@ XenBusEventChannelClose (
IN evtchn_port_t   Port
)
  {
 -  XENBUS_PRIVATE_DATA *Private;
evtchn_close_t Close;

 -  Private = XENBUS_PRIVATE_DATA_FROM_THIS (This);
Close.port = Port;
 -  return (UINT32)XenHypercallEventChannelOp (Private-Dev, EVTCHNOP_close, 
 Close);
 +  return (UINT32)XenHypercallEventChannelOp (EVTCHNOP_close, Close);
  }
 diff --git a/OvmfPkg/XenBusDxe/GrantTable.c b/OvmfPkg/XenBusDxe/GrantTable.c
 index 8405edc51bc4..53cb99f0e004 100644
 --- a/OvmfPkg/XenBusDxe/GrantTable.c
 +++ b/OvmfPkg/XenBusDxe/GrantTable.c
 @@ -161,7 +161,7 @@ XenGrantTableInit (
  Parameters.idx = Index;
  Parameters.space = XENMAPSPACE_grant_table;
  Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable  EFI_PAGE_SHIFT) + 
 Index;
 -ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_add_to_physmap, 
 Parameters);
 +ReturnCode = XenHypercallMemoryOp (XENMEM_add_to_physmap, Parameters);
  if (ReturnCode != 0) {
DEBUG ((EFI_D_ERROR, Xen GrantTable, add_to_physmap hypercall error: 
 %d\n, ReturnCode));
  }
 @@ -184,7 +184,7 @@ XenGrantTableDeinit (
  Parameters.domid = DOMID_SELF;
  Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable  EFI_PAGE_SHIFT) + 
 Index;
  DEBUG ((EFI_D_INFO, Xen GrantTable, removing %X\n, Parameters.gpfn));
 -ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_remove_from_physmap, 
 Parameters);
 +ReturnCode = XenHypercallMemoryOp (XENMEM_remove_from_physmap, 
 Parameters);
  if (ReturnCode != 0) {
DEBUG ((EFI_D_ERROR, Xen GrantTable, remove_from_physmap hypercall 
 error: %d\n, ReturnCode));
  }
 diff --git a/OvmfPkg/XenBusDxe/Ia32/hypercall.nasm 
 b/OvmfPkg/XenBusDxe/Ia32/hypercall.nasm
 index 8547c30b81ee..e0fa71bb5ba8 100644
 --- a/OvmfPkg/XenBusDxe/Ia32/hypercall.nasm
 +++ b/OvmfPkg/XenBusDxe/Ia32/hypercall.nasm
 @@ -2,13 +2,13 @@ SECTION .text

  ; INTN
  ; EFIAPI
 -; XenHypercall2 (
 +; __XenHypercall2 (
  ;   IN VOID *HypercallAddr,
  ;   IN OUT INTN Arg1,
  ;   IN OUT INTN Arg2
  ;   );
 -global ASM_PFX(XenHypercall2)
 -ASM_PFX(XenHypercall2):
 +global ASM_PFX(__XenHypercall2)
 +ASM_PFX(__XenHypercall2):
; Save only ebx, ecx is supposed to be a scratch register and needs to be
; saved by the caller
push ebx
 diff --git 

Re: [Xen-devel] [PATCH v2 17/29] Ovmf/Xen: refactor XenBusDxe hypercall implementation

2015-01-27 Thread Stefano Stabellini
On Mon, 26 Jan 2015, Ard Biesheuvel wrote:
 This refactors the Xen hypercall implementation that is part of the
 XenBusDxe driver, in preparation of splitting it off entirely into
 a XenHypercallLib library. This involves:
 - removing the dependency on XENBUS_DEVICE* pointers in the XenHypercall()
   prototypes
 - moving the discovered hyperpage address to a global variable
 - moving XenGetSharedInfoPage() to its only user XenBusDxe.c (the shared info
   page is not strictly part of the Xen hypercall interface, and is not used
   by other expected users of XenHypercallLib such as the Xen console version
   of SerialPortLib
 - reimplement XenHypercall2() in C and move the indexing of the hyperpage
   there; the existing asm implementations are renamed to __XenHypercall2() and
   invoked from the new C implementation.
 
 Contributed-under: TianoCore Contribution Agreement 1.0
 Signed-off-by: Ard Biesheuvel ard.biesheu...@linaro.org
 ---
  OvmfPkg/XenBusDxe/EventChannel.c  | 11 +++
  OvmfPkg/XenBusDxe/GrantTable.c|  4 ++--
  OvmfPkg/XenBusDxe/Ia32/hypercall.nasm |  6 +++---
  OvmfPkg/XenBusDxe/X64/hypercall.nasm  |  6 +++---
  OvmfPkg/XenBusDxe/XenBusDxe.c | 44 
 +++-
  OvmfPkg/XenBusDxe/XenBusDxe.h |  1 -
  OvmfPkg/XenBusDxe/XenHypercall.c  | 50 
 ++
  OvmfPkg/XenBusDxe/XenHypercall.h  | 28 +++-
  OvmfPkg/XenBusDxe/XenStore.c  |  4 ++--
  9 files changed, 73 insertions(+), 81 deletions(-)
 
 diff --git a/OvmfPkg/XenBusDxe/EventChannel.c 
 b/OvmfPkg/XenBusDxe/EventChannel.c
 index 03efaf9cb904..a86323e6adfd 100644
 --- a/OvmfPkg/XenBusDxe/EventChannel.c
 +++ b/OvmfPkg/XenBusDxe/EventChannel.c
 @@ -28,7 +28,7 @@ XenEventChannelNotify (
evtchn_send_t Send;
  
Send.port = Port;
 -  ReturnCode = XenHypercallEventChannelOp (Dev, EVTCHNOP_send, Send);
 +  ReturnCode = XenHypercallEventChannelOp (EVTCHNOP_send, Send);
return (UINT32)ReturnCode;
  }
  
 @@ -40,15 +40,12 @@ XenBusEventChannelAllocate (
OUT evtchn_port_t   *Port
)
  {
 -  XENBUS_PRIVATE_DATA *Private;
evtchn_alloc_unbound_t Parameter;
UINT32 ReturnCode;
  
 -  Private = XENBUS_PRIVATE_DATA_FROM_THIS (This);
 -
Parameter.dom = DOMID_SELF;
Parameter.remote_dom = DomainId;
 -  ReturnCode = (UINT32)XenHypercallEventChannelOp (Private-Dev,
 +  ReturnCode = (UINT32)XenHypercallEventChannelOp (
 EVTCHNOP_alloc_unbound,
 Parameter);
if (ReturnCode != 0) {
 @@ -79,10 +76,8 @@ XenBusEventChannelClose (
IN evtchn_port_t   Port
)
  {
 -  XENBUS_PRIVATE_DATA *Private;
evtchn_close_t Close;
  
 -  Private = XENBUS_PRIVATE_DATA_FROM_THIS (This);
Close.port = Port;
 -  return (UINT32)XenHypercallEventChannelOp (Private-Dev, EVTCHNOP_close, 
 Close);
 +  return (UINT32)XenHypercallEventChannelOp (EVTCHNOP_close, Close);
  }
 diff --git a/OvmfPkg/XenBusDxe/GrantTable.c b/OvmfPkg/XenBusDxe/GrantTable.c
 index 8405edc51bc4..53cb99f0e004 100644
 --- a/OvmfPkg/XenBusDxe/GrantTable.c
 +++ b/OvmfPkg/XenBusDxe/GrantTable.c
 @@ -161,7 +161,7 @@ XenGrantTableInit (
  Parameters.idx = Index;
  Parameters.space = XENMAPSPACE_grant_table;
  Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable  EFI_PAGE_SHIFT) + 
 Index;
 -ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_add_to_physmap, 
 Parameters);
 +ReturnCode = XenHypercallMemoryOp (XENMEM_add_to_physmap, Parameters);
  if (ReturnCode != 0) {
DEBUG ((EFI_D_ERROR, Xen GrantTable, add_to_physmap hypercall error: 
 %d\n, ReturnCode));
  }
 @@ -184,7 +184,7 @@ XenGrantTableDeinit (
  Parameters.domid = DOMID_SELF;
  Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable  EFI_PAGE_SHIFT) + 
 Index;
  DEBUG ((EFI_D_INFO, Xen GrantTable, removing %X\n, Parameters.gpfn));
 -ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_remove_from_physmap, 
 Parameters);
 +ReturnCode = XenHypercallMemoryOp (XENMEM_remove_from_physmap, 
 Parameters);
  if (ReturnCode != 0) {
DEBUG ((EFI_D_ERROR, Xen GrantTable, remove_from_physmap hypercall 
 error: %d\n, ReturnCode));
  }
 diff --git a/OvmfPkg/XenBusDxe/Ia32/hypercall.nasm 
 b/OvmfPkg/XenBusDxe/Ia32/hypercall.nasm
 index 8547c30b81ee..e0fa71bb5ba8 100644
 --- a/OvmfPkg/XenBusDxe/Ia32/hypercall.nasm
 +++ b/OvmfPkg/XenBusDxe/Ia32/hypercall.nasm
 @@ -2,13 +2,13 @@ SECTION .text
  
  ; INTN
  ; EFIAPI
 -; XenHypercall2 (
 +; __XenHypercall2 (
  ;   IN VOID *HypercallAddr,
  ;   IN OUT INTN Arg1,
  ;   IN OUT INTN Arg2
  ;   );
 -global ASM_PFX(XenHypercall2)
 -ASM_PFX(XenHypercall2):
 +global ASM_PFX(__XenHypercall2)
 +ASM_PFX(__XenHypercall2):
; Save only ebx, ecx is supposed to be a scratch register and needs to be
; saved by the caller
push ebx
 diff --git a/OvmfPkg/XenBusDxe/X64/hypercall.nasm 
 b/OvmfPkg/XenBusDxe/X64/hypercall.nasm
 

Re: [Xen-devel] [PATCH v2 17/29] Ovmf/Xen: refactor XenBusDxe hypercall implementation

2015-01-27 Thread Ard Biesheuvel
On 27 January 2015 at 12:46, Ard Biesheuvel ard.biesheu...@linaro.org wrote:
 On 27 January 2015 at 12:43, Stefano Stabellini
 stefano.stabell...@eu.citrix.com wrote:
 On Mon, 26 Jan 2015, Ard Biesheuvel wrote:
 This refactors the Xen hypercall implementation that is part of the
 XenBusDxe driver, in preparation of splitting it off entirely into
 a XenHypercallLib library. This involves:
 - removing the dependency on XENBUS_DEVICE* pointers in the XenHypercall()
   prototypes
 - moving the discovered hyperpage address to a global variable
 - moving XenGetSharedInfoPage() to its only user XenBusDxe.c (the shared 
 info
   page is not strictly part of the Xen hypercall interface, and is not used
   by other expected users of XenHypercallLib such as the Xen console version
   of SerialPortLib
 - reimplement XenHypercall2() in C and move the indexing of the hyperpage
   there; the existing asm implementations are renamed to __XenHypercall2() 
 and
   invoked from the new C implementation.

 Contributed-under: TianoCore Contribution Agreement 1.0
 Signed-off-by: Ard Biesheuvel ard.biesheu...@linaro.org
 ---
  OvmfPkg/XenBusDxe/EventChannel.c  | 11 +++
  OvmfPkg/XenBusDxe/GrantTable.c|  4 ++--
  OvmfPkg/XenBusDxe/Ia32/hypercall.nasm |  6 +++---
  OvmfPkg/XenBusDxe/X64/hypercall.nasm  |  6 +++---
  OvmfPkg/XenBusDxe/XenBusDxe.c | 44 
 +++-
  OvmfPkg/XenBusDxe/XenBusDxe.h |  1 -
  OvmfPkg/XenBusDxe/XenHypercall.c  | 50 
 ++
  OvmfPkg/XenBusDxe/XenHypercall.h  | 28 +++-
  OvmfPkg/XenBusDxe/XenStore.c  |  4 ++--
  9 files changed, 73 insertions(+), 81 deletions(-)

 diff --git a/OvmfPkg/XenBusDxe/EventChannel.c 
 b/OvmfPkg/XenBusDxe/EventChannel.c
 index 03efaf9cb904..a86323e6adfd 100644
 --- a/OvmfPkg/XenBusDxe/EventChannel.c
 +++ b/OvmfPkg/XenBusDxe/EventChannel.c
 @@ -28,7 +28,7 @@ XenEventChannelNotify (
evtchn_send_t Send;

Send.port = Port;
 -  ReturnCode = XenHypercallEventChannelOp (Dev, EVTCHNOP_send, Send);
 +  ReturnCode = XenHypercallEventChannelOp (EVTCHNOP_send, Send);
return (UINT32)ReturnCode;
  }

 @@ -40,15 +40,12 @@ XenBusEventChannelAllocate (
OUT evtchn_port_t   *Port
)
  {
 -  XENBUS_PRIVATE_DATA *Private;
evtchn_alloc_unbound_t Parameter;
UINT32 ReturnCode;

 -  Private = XENBUS_PRIVATE_DATA_FROM_THIS (This);
 -
Parameter.dom = DOMID_SELF;
Parameter.remote_dom = DomainId;
 -  ReturnCode = (UINT32)XenHypercallEventChannelOp (Private-Dev,
 +  ReturnCode = (UINT32)XenHypercallEventChannelOp (
 EVTCHNOP_alloc_unbound,
 Parameter);
if (ReturnCode != 0) {
 @@ -79,10 +76,8 @@ XenBusEventChannelClose (
IN evtchn_port_t   Port
)
  {
 -  XENBUS_PRIVATE_DATA *Private;
evtchn_close_t Close;

 -  Private = XENBUS_PRIVATE_DATA_FROM_THIS (This);
Close.port = Port;
 -  return (UINT32)XenHypercallEventChannelOp (Private-Dev, EVTCHNOP_close, 
 Close);
 +  return (UINT32)XenHypercallEventChannelOp (EVTCHNOP_close, Close);
  }
 diff --git a/OvmfPkg/XenBusDxe/GrantTable.c b/OvmfPkg/XenBusDxe/GrantTable.c
 index 8405edc51bc4..53cb99f0e004 100644
 --- a/OvmfPkg/XenBusDxe/GrantTable.c
 +++ b/OvmfPkg/XenBusDxe/GrantTable.c
 @@ -161,7 +161,7 @@ XenGrantTableInit (
  Parameters.idx = Index;
  Parameters.space = XENMAPSPACE_grant_table;
  Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable  EFI_PAGE_SHIFT) + 
 Index;
 -ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_add_to_physmap, 
 Parameters);
 +ReturnCode = XenHypercallMemoryOp (XENMEM_add_to_physmap, Parameters);
  if (ReturnCode != 0) {
DEBUG ((EFI_D_ERROR, Xen GrantTable, add_to_physmap hypercall 
 error: %d\n, ReturnCode));
  }
 @@ -184,7 +184,7 @@ XenGrantTableDeinit (
  Parameters.domid = DOMID_SELF;
  Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable  EFI_PAGE_SHIFT) + 
 Index;
  DEBUG ((EFI_D_INFO, Xen GrantTable, removing %X\n, Parameters.gpfn));
 -ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_remove_from_physmap, 
 Parameters);
 +ReturnCode = XenHypercallMemoryOp (XENMEM_remove_from_physmap, 
 Parameters);
  if (ReturnCode != 0) {
DEBUG ((EFI_D_ERROR, Xen GrantTable, remove_from_physmap hypercall 
 error: %d\n, ReturnCode));
  }
 diff --git a/OvmfPkg/XenBusDxe/Ia32/hypercall.nasm 
 b/OvmfPkg/XenBusDxe/Ia32/hypercall.nasm
 index 8547c30b81ee..e0fa71bb5ba8 100644
 --- a/OvmfPkg/XenBusDxe/Ia32/hypercall.nasm
 +++ b/OvmfPkg/XenBusDxe/Ia32/hypercall.nasm
 @@ -2,13 +2,13 @@ SECTION .text

  ; INTN
  ; EFIAPI
 -; XenHypercall2 (
 +; __XenHypercall2 (
  ;   IN VOID *HypercallAddr,
  ;   IN OUT INTN Arg1,
  ;   IN OUT INTN Arg2
  ;   );
 -global ASM_PFX(XenHypercall2)
 -ASM_PFX(XenHypercall2):
 +global ASM_PFX(__XenHypercall2)
 +ASM_PFX(__XenHypercall2):
; Save only ebx, ecx is supposed to be a scratch 

[Xen-devel] [PATCH v2 17/29] Ovmf/Xen: refactor XenBusDxe hypercall implementation

2015-01-26 Thread Ard Biesheuvel
This refactors the Xen hypercall implementation that is part of the
XenBusDxe driver, in preparation of splitting it off entirely into
a XenHypercallLib library. This involves:
- removing the dependency on XENBUS_DEVICE* pointers in the XenHypercall()
  prototypes
- moving the discovered hyperpage address to a global variable
- moving XenGetSharedInfoPage() to its only user XenBusDxe.c (the shared info
  page is not strictly part of the Xen hypercall interface, and is not used
  by other expected users of XenHypercallLib such as the Xen console version
  of SerialPortLib
- reimplement XenHypercall2() in C and move the indexing of the hyperpage
  there; the existing asm implementations are renamed to __XenHypercall2() and
  invoked from the new C implementation.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel ard.biesheu...@linaro.org
---
 OvmfPkg/XenBusDxe/EventChannel.c  | 11 +++
 OvmfPkg/XenBusDxe/GrantTable.c|  4 ++--
 OvmfPkg/XenBusDxe/Ia32/hypercall.nasm |  6 +++---
 OvmfPkg/XenBusDxe/X64/hypercall.nasm  |  6 +++---
 OvmfPkg/XenBusDxe/XenBusDxe.c | 44 
+++-
 OvmfPkg/XenBusDxe/XenBusDxe.h |  1 -
 OvmfPkg/XenBusDxe/XenHypercall.c  | 50 
++
 OvmfPkg/XenBusDxe/XenHypercall.h  | 28 +++-
 OvmfPkg/XenBusDxe/XenStore.c  |  4 ++--
 9 files changed, 73 insertions(+), 81 deletions(-)

diff --git a/OvmfPkg/XenBusDxe/EventChannel.c b/OvmfPkg/XenBusDxe/EventChannel.c
index 03efaf9cb904..a86323e6adfd 100644
--- a/OvmfPkg/XenBusDxe/EventChannel.c
+++ b/OvmfPkg/XenBusDxe/EventChannel.c
@@ -28,7 +28,7 @@ XenEventChannelNotify (
   evtchn_send_t Send;
 
   Send.port = Port;
-  ReturnCode = XenHypercallEventChannelOp (Dev, EVTCHNOP_send, Send);
+  ReturnCode = XenHypercallEventChannelOp (EVTCHNOP_send, Send);
   return (UINT32)ReturnCode;
 }
 
@@ -40,15 +40,12 @@ XenBusEventChannelAllocate (
   OUT evtchn_port_t   *Port
   )
 {
-  XENBUS_PRIVATE_DATA *Private;
   evtchn_alloc_unbound_t Parameter;
   UINT32 ReturnCode;
 
-  Private = XENBUS_PRIVATE_DATA_FROM_THIS (This);
-
   Parameter.dom = DOMID_SELF;
   Parameter.remote_dom = DomainId;
-  ReturnCode = (UINT32)XenHypercallEventChannelOp (Private-Dev,
+  ReturnCode = (UINT32)XenHypercallEventChannelOp (
EVTCHNOP_alloc_unbound,
Parameter);
   if (ReturnCode != 0) {
@@ -79,10 +76,8 @@ XenBusEventChannelClose (
   IN evtchn_port_t   Port
   )
 {
-  XENBUS_PRIVATE_DATA *Private;
   evtchn_close_t Close;
 
-  Private = XENBUS_PRIVATE_DATA_FROM_THIS (This);
   Close.port = Port;
-  return (UINT32)XenHypercallEventChannelOp (Private-Dev, EVTCHNOP_close, 
Close);
+  return (UINT32)XenHypercallEventChannelOp (EVTCHNOP_close, Close);
 }
diff --git a/OvmfPkg/XenBusDxe/GrantTable.c b/OvmfPkg/XenBusDxe/GrantTable.c
index 8405edc51bc4..53cb99f0e004 100644
--- a/OvmfPkg/XenBusDxe/GrantTable.c
+++ b/OvmfPkg/XenBusDxe/GrantTable.c
@@ -161,7 +161,7 @@ XenGrantTableInit (
 Parameters.idx = Index;
 Parameters.space = XENMAPSPACE_grant_table;
 Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable  EFI_PAGE_SHIFT) + 
Index;
-ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_add_to_physmap, 
Parameters);
+ReturnCode = XenHypercallMemoryOp (XENMEM_add_to_physmap, Parameters);
 if (ReturnCode != 0) {
   DEBUG ((EFI_D_ERROR, Xen GrantTable, add_to_physmap hypercall error: 
%d\n, ReturnCode));
 }
@@ -184,7 +184,7 @@ XenGrantTableDeinit (
 Parameters.domid = DOMID_SELF;
 Parameters.gpfn = (xen_pfn_t) ((UINTN) GrantTable  EFI_PAGE_SHIFT) + 
Index;
 DEBUG ((EFI_D_INFO, Xen GrantTable, removing %X\n, Parameters.gpfn));
-ReturnCode = XenHypercallMemoryOp (Dev, XENMEM_remove_from_physmap, 
Parameters);
+ReturnCode = XenHypercallMemoryOp (XENMEM_remove_from_physmap, 
Parameters);
 if (ReturnCode != 0) {
   DEBUG ((EFI_D_ERROR, Xen GrantTable, remove_from_physmap hypercall 
error: %d\n, ReturnCode));
 }
diff --git a/OvmfPkg/XenBusDxe/Ia32/hypercall.nasm 
b/OvmfPkg/XenBusDxe/Ia32/hypercall.nasm
index 8547c30b81ee..e0fa71bb5ba8 100644
--- a/OvmfPkg/XenBusDxe/Ia32/hypercall.nasm
+++ b/OvmfPkg/XenBusDxe/Ia32/hypercall.nasm
@@ -2,13 +2,13 @@ SECTION .text
 
 ; INTN
 ; EFIAPI
-; XenHypercall2 (
+; __XenHypercall2 (
 ;   IN VOID *HypercallAddr,
 ;   IN OUT INTN Arg1,
 ;   IN OUT INTN Arg2
 ;   );
-global ASM_PFX(XenHypercall2)
-ASM_PFX(XenHypercall2):
+global ASM_PFX(__XenHypercall2)
+ASM_PFX(__XenHypercall2):
   ; Save only ebx, ecx is supposed to be a scratch register and needs to be
   ; saved by the caller
   push ebx
diff --git a/OvmfPkg/XenBusDxe/X64/hypercall.nasm 
b/OvmfPkg/XenBusDxe/X64/hypercall.nasm
index 177f271ef094..5e6a0c05c5c4 100644
--- a/OvmfPkg/XenBusDxe/X64/hypercall.nasm
+++ b/OvmfPkg/XenBusDxe/X64/hypercall.nasm
@@ -3,13 +3,13 @@ SECTION .text
 
 ; INTN
 ;