• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2   Xen Hypercall Library implementation for Intel architecture
3 
4 Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
9 
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 
13 **/
14 
15 #include <PiDxe.h>
16 #include <Library/HobLib.h>
17 #include <Library/DebugLib.h>
18 #include <Guid/XenInfo.h>
19 
20 STATIC VOID    *HyperPage;
21 
22 /**
23   Check if the Xen Hypercall library is able to make calls to the Xen
24   hypervisor.
25 
26   Client code should call further functions in this library only if, and after,
27   this function returns TRUE.
28 
29   @retval TRUE   Hypercalls are available.
30   @retval FALSE  Hypercalls are not available.
31 **/
32 BOOLEAN
33 EFIAPI
XenHypercallIsAvailable(VOID)34 XenHypercallIsAvailable (
35   VOID
36   )
37 {
38   return HyperPage != NULL;
39 }
40 
41 //
42 // Interface exposed by the ASM implementation of the core hypercall
43 //
44 INTN
45 EFIAPI
46 __XenHypercall2 (
47   IN     VOID *HypercallAddr,
48   IN OUT INTN Arg1,
49   IN OUT INTN Arg2
50   );
51 
52 /**
53   Library constructor: retrieves the Hyperpage address
54   from the gEfiXenInfoGuid HOB
55 **/
56 
57 RETURN_STATUS
58 EFIAPI
XenHypercallLibInit(VOID)59 XenHypercallLibInit (
60   VOID
61   )
62 {
63   EFI_HOB_GUID_TYPE   *GuidHob;
64   EFI_XEN_INFO        *XenInfo;
65 
66   GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid);
67   if (GuidHob == NULL) {
68     //
69     // We don't fail library construction, since that has catastrophic
70     // consequences for client modules (whereas those modules may easily be
71     // running on a non-Xen platform). Instead, XenHypercallIsAvailable() above
72     // will return FALSE.
73     //
74     return RETURN_SUCCESS;
75   }
76   XenInfo = (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);
77   HyperPage = XenInfo->HyperPages;
78   return RETURN_SUCCESS;
79 }
80 
81 /**
82   This function will put the two arguments in the right place (registers) and
83   invoke the hypercall identified by HypercallID.
84 
85   @param HypercallID    The symbolic ID of the hypercall to be invoked
86   @param Arg1           First argument.
87   @param Arg2           Second argument.
88 
89   @return   Return 0 if success otherwise it return an errno.
90 **/
91 INTN
92 EFIAPI
XenHypercall2(IN UINTN HypercallID,IN OUT INTN Arg1,IN OUT INTN Arg2)93 XenHypercall2 (
94   IN     UINTN  HypercallID,
95   IN OUT INTN   Arg1,
96   IN OUT INTN   Arg2
97   )
98 {
99   ASSERT (HyperPage != NULL);
100 
101   return __XenHypercall2 ((UINT8*)HyperPage + HypercallID * 32, Arg1, Arg2);
102 }
103