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