--- /dev/null
+# INTN\r
+# EFIAPI\r
+# XenHypercall2 (\r
+# IN VOID *HypercallAddr,\r
+# IN OUT INTN Arg1,\r
+# IN OUT INTN Arg2\r
+# );\r
+ASM_GLOBAL ASM_PFX(XenHypercall2)\r
+ASM_PFX(XenHypercall2):\r
+ # Save only ebx, ecx is supposed to be a scratch register and needs to be\r
+ # saved by the caller\r
+ push %ebx\r
+ # Copy HypercallAddr to eax\r
+ mov 8(%esp), %eax\r
+ # Copy Arg1 to the register expected by Xen\r
+ mov 12(%esp), %ebx\r
+ # Copy Arg2 to the register expected by Xen\r
+ mov 16(%esp), %ecx\r
+ # Call HypercallAddr\r
+ call *%eax\r
+ pop %ebx\r
+ ret\r
--- /dev/null
+.code\r
+\r
+; INTN\r
+; EFIAPI\r
+; XenHypercall2 (\r
+; IN VOID *HypercallAddr,\r
+; IN OUT INTN Arg1,\r
+; IN OUT INTN Arg2\r
+; );\r
+XenHypercall2 PROC\r
+ ; Save only ebx, ecx is supposed to be a scratch register and needs to be\r
+ ; saved by the caller\r
+ push ebx\r
+ ; Copy HypercallAddr to eax\r
+ mov eax, [esp + 8]\r
+ ; Copy Arg1 to the register expected by Xen\r
+ mov ebx, [esp + 12]\r
+ ; Copy Arg2 to the register expected by Xen\r
+ mov ecx, [esp + 16]\r
+ ; Call HypercallAddr\r
+ call eax\r
+ pop ebx\r
+ ret\r
+XenHypercall2 ENDP\r
+\r
+END\r
--- /dev/null
+# INTN\r
+# EFIAPI\r
+# XenHypercall2 (\r
+# IN VOID *HypercallAddr,\r
+# IN OUT INTN Arg1,\r
+# IN OUT INTN Arg2\r
+# );\r
+ASM_GLOBAL ASM_PFX(XenHypercall2)\r
+ASM_PFX(XenHypercall2):\r
+ push %rdi\r
+ push %rsi\r
+ # Copy HypercallAddr to rax\r
+ movq %rcx, %rax\r
+ # Copy Arg1 to the register expected by Xen\r
+ movq %rdx, %rdi\r
+ # Copy Arg2 to the register expected by Xen\r
+ movq %r8, %rsi\r
+ # Call HypercallAddr\r
+ call *%rax\r
+ pop %rsi\r
+ pop %rdi\r
+ ret\r
--- /dev/null
+.code\r
+\r
+; INTN\r
+; EFIAPI\r
+; XenHypercall2 (\r
+; IN VOID *HypercallAddr,\r
+; IN OUT INTN Arg1,\r
+; IN OUT INTN Arg2\r
+; );\r
+XenHypercall2 PROC\r
+ push rdi\r
+ push rsi\r
+ ; Copy HypercallAddr to rax\r
+ mov rax, rcx\r
+ ; Copy Arg1 to the register expected by Xen\r
+ mov rdi, rdx\r
+ ; Copy Arg2 to the register expected by Xen\r
+ mov rsi, r8\r
+ ; Call HypercallAddr\r
+ call rax\r
+ pop rsi\r
+ pop rdi\r
+ ret\r
+XenHypercall2 ENDP\r
+\r
+END\r
\r
#include "XenBusDxe.h"\r
\r
+#include "XenHypercall.h"\r
+\r
\r
///\r
/// Driver Binding Protocol instance\r
@retval EFI_SUCCESS The device was started.\r
@retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
+ @retval EFI_UNSUPPORTED Something is missing on the system that\r
+ prevent to start the edvice.\r
@retval Others The driver failded to start the device.\r
\r
**/\r
mMyDevice = Dev;\r
EfiReleaseLock (&mMyDeviceLock);\r
\r
+ Status = XenHyperpageInit (Dev);\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((EFI_D_ERROR, "XenBus: Unable to retrieve the hyperpage.\n"));\r
+ Status = EFI_UNSUPPORTED;\r
+ goto ErrorAllocated;\r
+ }\r
+\r
+ Status = XenGetSharedInfoPage (Dev);\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((EFI_D_ERROR, "XenBus: Unable to get the shared info page.\n"));\r
+ Status = EFI_UNSUPPORTED;\r
+ goto ErrorAllocated;\r
+ }\r
+\r
Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_CALLBACK,\r
NotifyExitBoot,\r
(VOID*) Dev,\r
//\r
// Other stuff\r
//\r
+#include <IndustryStandard/Xen/xen.h>\r
+\r
#define PCI_VENDOR_ID_XEN 0x5853\r
#define PCI_DEVICE_ID_XEN_PLATFORM 0x0001\r
\r
EFI_DRIVER_BINDING_PROTOCOL *This;\r
EFI_HANDLE ControllerHandle;\r
EFI_EVENT ExitBootEvent;\r
+\r
+ VOID *Hyperpage;\r
+ shared_info_t *SharedInfo;\r
};\r
\r
#endif\r
DriverBinding.h\r
ComponentName.c\r
ComponentName.h\r
+ XenHypercall.c\r
+ XenHypercall.h\r
+\r
+[Sources.IA32]\r
+ Ia32/hypercall.S\r
+ Ia32/hypercall.asm\r
+\r
+[Sources.X64]\r
+ X64/hypercall.S\r
+ X64/hypercall.asm\r
\r
[LibraryClasses]\r
UefiDriverEntryPoint\r
--- /dev/null
+/** @file\r
+ Functions to make Xen hypercalls.\r
+\r
+ Copyright (C) 2014, Citrix Ltd.\r
+\r
+ This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <PiDxe.h>\r
+#include <Library/HobLib.h>\r
+#include <Guid/XenInfo.h>\r
+\r
+#include "XenBusDxe.h"\r
+#include "XenHypercall.h"\r
+\r
+#include <IndustryStandard/Xen/hvm/params.h>\r
+#include <IndustryStandard/Xen/memory.h>\r
+\r
+EFI_STATUS\r
+XenHyperpageInit (\r
+ IN OUT XENBUS_DEVICE *Dev\r
+ )\r
+{\r
+ EFI_HOB_GUID_TYPE *GuidHob;\r
+ EFI_XEN_INFO *XenInfo;\r
+\r
+ GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid);\r
+ if (GuidHob == NULL) {\r
+ return EFI_NOT_FOUND;\r
+ }\r
+ XenInfo = (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);\r
+ Dev->Hyperpage = XenInfo->HyperPages;\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+UINT64\r
+XenHypercallHvmGetParam (\r
+ IN XENBUS_DEVICE *Dev,\r
+ IN INTN Index\r
+ )\r
+{\r
+ xen_hvm_param_t Parameter;\r
+ INTN Error;\r
+\r
+ ASSERT (Dev->Hyperpage != NULL);\r
+\r
+ Parameter.domid = DOMID_SELF;\r
+ Parameter.index = Index;\r
+ Error = XenHypercall2 (Dev->Hyperpage + __HYPERVISOR_hvm_op * 32,\r
+ HVMOP_get_param, (INTN) &Parameter);\r
+ if (Error != 0) {\r
+ DEBUG ((EFI_D_ERROR,\r
+ "XenHypercall: Error %d trying to get HVM parameter %d\n",\r
+ Error, Index));\r
+ return 0;\r
+ }\r
+ return Parameter.value;\r
+}\r
+\r
+INTN\r
+XenHypercallMemoryOp (\r
+ IN XENBUS_DEVICE *Dev,\r
+ IN UINTN Operation,\r
+ IN OUT VOID *Arguments\r
+ )\r
+{\r
+ ASSERT (Dev->Hyperpage != NULL);\r
+ return XenHypercall2 (Dev->Hyperpage + __HYPERVISOR_memory_op * 32,\r
+ Operation, (INTN) Arguments);\r
+}\r
+\r
+INTN\r
+XenHypercallEventChannelOp (\r
+ IN XENBUS_DEVICE *Dev,\r
+ IN INTN Operation,\r
+ IN OUT VOID *Arguments\r
+ )\r
+{\r
+ ASSERT (Dev->Hyperpage != NULL);\r
+ return XenHypercall2 (Dev->Hyperpage + __HYPERVISOR_event_channel_op * 32,\r
+ Operation, (INTN) Arguments);\r
+}\r
+\r
+EFI_STATUS\r
+XenGetSharedInfoPage (\r
+ IN OUT XENBUS_DEVICE *Dev\r
+ )\r
+{\r
+ xen_add_to_physmap_t Parameter;\r
+\r
+ ASSERT (Dev->SharedInfo == NULL);\r
+\r
+ Parameter.domid = DOMID_SELF;\r
+ Parameter.space = XENMAPSPACE_shared_info;\r
+ Parameter.idx = 0;\r
+\r
+ //\r
+ // using reserved page because the page is not released when Linux is\r
+ // starting because of the add_to_physmap. QEMU might try to access the\r
+ // page, and fail because it have no right to do so (segv).\r
+ //\r
+ Dev->SharedInfo = AllocateReservedPages (1);\r
+ Parameter.gpfn = (UINTN) Dev->SharedInfo >> EFI_PAGE_SHIFT;\r
+ if (XenHypercallMemoryOp (Dev, XENMEM_add_to_physmap, &Parameter) != 0) {\r
+ FreePages (Dev->SharedInfo, 1);\r
+ Dev->SharedInfo = NULL;\r
+ return EFI_LOAD_ERROR;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
--- /dev/null
+/** @file\r
+ Functions declarations to make Xen hypercalls.\r
+\r
+ Copyright (C) 2014, Citrix Ltd.\r
+\r
+ This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __XENBUS_DXE_HYPERCALL_H__\r
+#define __XENBUS_DXE_HYPERCALL_H__\r
+\r
+typedef struct _XENBUS_DEVICE XENBUS_DEVICE;\r
+\r
+/**\r
+ This function will put the two arguments in the right place (registers) and\r
+ call HypercallAddr, which correspond to an entry in the hypercall pages.\r
+\r
+ @param HypercallAddr A memory address where the hypercall to call is.\r
+ @param Arg1 First argument.\r
+ @param Arg2 Second argument.\r
+\r
+ @return Return 0 if success otherwise it return an errno.\r
+**/\r
+INTN\r
+EFIAPI\r
+XenHypercall2 (\r
+ IN VOID *HypercallAddr,\r
+ IN OUT INTN Arg1,\r
+ IN OUT INTN Arg2\r
+ );\r
+\r
+/**\r
+ Get the page where all hypercall are from the XenInfo hob.\r
+\r
+ @param Dev A XENBUS_DEVICE instance.\r
+\r
+ @retval EFI_NOT_FOUND hyperpage could not be found.\r
+ @retval EFI_SUCCESS Successfully retrieve the hyperpage pointer.\r
+**/\r
+EFI_STATUS\r
+XenHyperpageInit (\r
+ XENBUS_DEVICE *Dev\r
+ );\r
+\r
+/**\r
+ Return the value of the HVM parameter Index.\r
+\r
+ @param Dev A XENBUS_DEVICE instance.\r
+ @param Index The parameter to get, e.g. HVM_PARAM_STORE_EVTCHN.\r
+\r
+ @return The value of the asked parameter or 0 in case of error.\r
+**/\r
+UINT64\r
+XenHypercallHvmGetParam (\r
+ XENBUS_DEVICE *Dev,\r
+ INTN Index\r
+ );\r
+\r
+/**\r
+ Hypercall to do different operation on the memory.\r
+\r
+ @param Dev A XENBUS_DEVICE instance.\r
+ @param Operation The operation number, e.g. XENMEM_add_to_physmap.\r
+ @param Arguments The arguments associated to the operation.\r
+\r
+ @return Return the return value from the hypercall, 0 in case of success\r
+ otherwise, an error code.\r
+**/\r
+INTN\r
+XenHypercallMemoryOp (\r
+ IN XENBUS_DEVICE *Dev,\r
+ IN UINTN Operation,\r
+ IN OUT VOID *Arguments\r
+ );\r
+\r
+/**\r
+ Do an operation on the event channels.\r
+\r
+ @param Dev A XENBUS_DEVICE instance.\r
+ @param Operation The operation number, e.g. EVTCHNOP_send.\r
+ @param Arguments The argument associated to the operation.\r
+\r
+ @return Return the return value from the hypercall, 0 in case of success\r
+ otherwise, an error code.\r
+**/\r
+INTN\r
+XenHypercallEventChannelOp (\r
+ IN XENBUS_DEVICE *Dev,\r
+ IN INTN Operation,\r
+ IN OUT VOID *Arguments\r
+ );\r
+\r
+/**\r
+ Map the shared_info_t page into memory.\r
+\r
+ @param Dev A XENBUS_DEVICE instance.\r
+\r
+ @retval EFI_SUCCESS Dev->SharedInfo whill contain a pointer to\r
+ the shared info page\r
+ @retval EFI_LOAD_ERROR The shared info page could not be mapped. The\r
+ hypercall returned an error.\r
+**/\r
+EFI_STATUS\r
+XenGetSharedInfoPage (\r
+ IN OUT XENBUS_DEVICE *Dev\r
+ );\r
+\r
+#endif\r