1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 1999 VA Linux Systems
7 * Copyright (C) 1999-2002 Hewlett-Packard Co.
10 * Copyright (C) 2005-2008 Intel Co.
15 * Copyright (C) 2011 Novell Co.
17 * Copyright (C) 2011-2012 Oracle Co.
19 * Copyright (c) 2014 Oracle Co., Daniel Kiper
22 #include <linux/bug.h>
23 #include <linux/efi.h>
24 #include <linux/init.h>
25 #include <linux/string.h>
27 #include <xen/interface/xen.h>
28 #include <xen/interface/platform.h>
30 #include <xen/xen-ops.h>
34 #include <asm/xen/hypercall.h>
36 #define INIT_EFI_OP(name) \
37 {.cmd = XENPF_efi_runtime_call, \
38 .u.efi_runtime_call.function = XEN_EFI_##name, \
39 .u.efi_runtime_call.misc = 0}
41 #define efi_data(op) (op.u.efi_runtime_call)
43 efi_status_t xen_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc)
45 struct xen_platform_op op = INIT_EFI_OP(get_time);
47 if (HYPERVISOR_platform_op(&op) < 0)
48 return EFI_UNSUPPORTED;
51 BUILD_BUG_ON(sizeof(*tm) != sizeof(efi_data(op).u.get_time.time));
52 memcpy(tm, &efi_data(op).u.get_time.time, sizeof(*tm));
56 tc->resolution = efi_data(op).u.get_time.resolution;
57 tc->accuracy = efi_data(op).u.get_time.accuracy;
58 tc->sets_to_zero = !!(efi_data(op).misc &
59 XEN_EFI_GET_TIME_SET_CLEARS_NS);
62 return efi_data(op).status;
64 EXPORT_SYMBOL_GPL(xen_efi_get_time);
66 efi_status_t xen_efi_set_time(efi_time_t *tm)
68 struct xen_platform_op op = INIT_EFI_OP(set_time);
70 BUILD_BUG_ON(sizeof(*tm) != sizeof(efi_data(op).u.set_time));
71 memcpy(&efi_data(op).u.set_time, tm, sizeof(*tm));
73 if (HYPERVISOR_platform_op(&op) < 0)
74 return EFI_UNSUPPORTED;
76 return efi_data(op).status;
78 EXPORT_SYMBOL_GPL(xen_efi_set_time);
80 efi_status_t xen_efi_get_wakeup_time(efi_bool_t *enabled, efi_bool_t *pending,
83 struct xen_platform_op op = INIT_EFI_OP(get_wakeup_time);
85 if (HYPERVISOR_platform_op(&op) < 0)
86 return EFI_UNSUPPORTED;
89 BUILD_BUG_ON(sizeof(*tm) != sizeof(efi_data(op).u.get_wakeup_time));
90 memcpy(tm, &efi_data(op).u.get_wakeup_time, sizeof(*tm));
94 *enabled = !!(efi_data(op).misc & XEN_EFI_GET_WAKEUP_TIME_ENABLED);
97 *pending = !!(efi_data(op).misc & XEN_EFI_GET_WAKEUP_TIME_PENDING);
99 return efi_data(op).status;
101 EXPORT_SYMBOL_GPL(xen_efi_get_wakeup_time);
103 efi_status_t xen_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
105 struct xen_platform_op op = INIT_EFI_OP(set_wakeup_time);
107 BUILD_BUG_ON(sizeof(*tm) != sizeof(efi_data(op).u.set_wakeup_time));
109 efi_data(op).misc = XEN_EFI_SET_WAKEUP_TIME_ENABLE;
111 memcpy(&efi_data(op).u.set_wakeup_time, tm, sizeof(*tm));
113 efi_data(op).misc |= XEN_EFI_SET_WAKEUP_TIME_ENABLE_ONLY;
115 if (HYPERVISOR_platform_op(&op) < 0)
116 return EFI_UNSUPPORTED;
118 return efi_data(op).status;
120 EXPORT_SYMBOL_GPL(xen_efi_set_wakeup_time);
122 efi_status_t xen_efi_get_variable(efi_char16_t *name, efi_guid_t *vendor,
123 u32 *attr, unsigned long *data_size,
126 struct xen_platform_op op = INIT_EFI_OP(get_variable);
128 set_xen_guest_handle(efi_data(op).u.get_variable.name, name);
129 BUILD_BUG_ON(sizeof(*vendor) !=
130 sizeof(efi_data(op).u.get_variable.vendor_guid));
131 memcpy(&efi_data(op).u.get_variable.vendor_guid, vendor, sizeof(*vendor));
132 efi_data(op).u.get_variable.size = *data_size;
133 set_xen_guest_handle(efi_data(op).u.get_variable.data, data);
135 if (HYPERVISOR_platform_op(&op) < 0)
136 return EFI_UNSUPPORTED;
138 *data_size = efi_data(op).u.get_variable.size;
140 *attr = efi_data(op).misc;
142 return efi_data(op).status;
144 EXPORT_SYMBOL_GPL(xen_efi_get_variable);
146 efi_status_t xen_efi_get_next_variable(unsigned long *name_size,
150 struct xen_platform_op op = INIT_EFI_OP(get_next_variable_name);
152 efi_data(op).u.get_next_variable_name.size = *name_size;
153 set_xen_guest_handle(efi_data(op).u.get_next_variable_name.name, name);
154 BUILD_BUG_ON(sizeof(*vendor) !=
155 sizeof(efi_data(op).u.get_next_variable_name.vendor_guid));
156 memcpy(&efi_data(op).u.get_next_variable_name.vendor_guid, vendor,
159 if (HYPERVISOR_platform_op(&op) < 0)
160 return EFI_UNSUPPORTED;
162 *name_size = efi_data(op).u.get_next_variable_name.size;
163 memcpy(vendor, &efi_data(op).u.get_next_variable_name.vendor_guid,
166 return efi_data(op).status;
168 EXPORT_SYMBOL_GPL(xen_efi_get_next_variable);
170 efi_status_t xen_efi_set_variable(efi_char16_t *name, efi_guid_t *vendor,
171 u32 attr, unsigned long data_size,
174 struct xen_platform_op op = INIT_EFI_OP(set_variable);
176 set_xen_guest_handle(efi_data(op).u.set_variable.name, name);
177 efi_data(op).misc = attr;
178 BUILD_BUG_ON(sizeof(*vendor) !=
179 sizeof(efi_data(op).u.set_variable.vendor_guid));
180 memcpy(&efi_data(op).u.set_variable.vendor_guid, vendor, sizeof(*vendor));
181 efi_data(op).u.set_variable.size = data_size;
182 set_xen_guest_handle(efi_data(op).u.set_variable.data, data);
184 if (HYPERVISOR_platform_op(&op) < 0)
185 return EFI_UNSUPPORTED;
187 return efi_data(op).status;
189 EXPORT_SYMBOL_GPL(xen_efi_set_variable);
191 efi_status_t xen_efi_query_variable_info(u32 attr, u64 *storage_space,
192 u64 *remaining_space,
193 u64 *max_variable_size)
195 struct xen_platform_op op = INIT_EFI_OP(query_variable_info);
197 if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
198 return EFI_UNSUPPORTED;
200 efi_data(op).u.query_variable_info.attr = attr;
202 if (HYPERVISOR_platform_op(&op) < 0)
203 return EFI_UNSUPPORTED;
205 *storage_space = efi_data(op).u.query_variable_info.max_store_size;
206 *remaining_space = efi_data(op).u.query_variable_info.remain_store_size;
207 *max_variable_size = efi_data(op).u.query_variable_info.max_size;
209 return efi_data(op).status;
211 EXPORT_SYMBOL_GPL(xen_efi_query_variable_info);
213 efi_status_t xen_efi_get_next_high_mono_count(u32 *count)
215 struct xen_platform_op op = INIT_EFI_OP(get_next_high_monotonic_count);
217 if (HYPERVISOR_platform_op(&op) < 0)
218 return EFI_UNSUPPORTED;
220 *count = efi_data(op).misc;
222 return efi_data(op).status;
224 EXPORT_SYMBOL_GPL(xen_efi_get_next_high_mono_count);
226 efi_status_t xen_efi_update_capsule(efi_capsule_header_t **capsules,
227 unsigned long count, unsigned long sg_list)
229 struct xen_platform_op op = INIT_EFI_OP(update_capsule);
231 if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
232 return EFI_UNSUPPORTED;
234 set_xen_guest_handle(efi_data(op).u.update_capsule.capsule_header_array,
236 efi_data(op).u.update_capsule.capsule_count = count;
237 efi_data(op).u.update_capsule.sg_list = sg_list;
239 if (HYPERVISOR_platform_op(&op) < 0)
240 return EFI_UNSUPPORTED;
242 return efi_data(op).status;
244 EXPORT_SYMBOL_GPL(xen_efi_update_capsule);
246 efi_status_t xen_efi_query_capsule_caps(efi_capsule_header_t **capsules,
247 unsigned long count, u64 *max_size,
250 struct xen_platform_op op = INIT_EFI_OP(query_capsule_capabilities);
252 if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
253 return EFI_UNSUPPORTED;
255 set_xen_guest_handle(efi_data(op).u.query_capsule_capabilities.capsule_header_array,
257 efi_data(op).u.query_capsule_capabilities.capsule_count = count;
259 if (HYPERVISOR_platform_op(&op) < 0)
260 return EFI_UNSUPPORTED;
262 *max_size = efi_data(op).u.query_capsule_capabilities.max_capsule_size;
263 *reset_type = efi_data(op).u.query_capsule_capabilities.reset_type;
265 return efi_data(op).status;
267 EXPORT_SYMBOL_GPL(xen_efi_query_capsule_caps);
269 void xen_efi_reset_system(int reset_type, efi_status_t status,
270 unsigned long data_size, efi_char16_t *data)
272 switch (reset_type) {
275 xen_reboot(SHUTDOWN_reboot);
277 case EFI_RESET_SHUTDOWN:
278 xen_reboot(SHUTDOWN_poweroff);
284 EXPORT_SYMBOL_GPL(xen_efi_reset_system);