^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * EFI support for Xen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1999 VA Linux Systems
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 1999-2002 Hewlett-Packard Co.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * David Mosberger-Tang <davidm@hpl.hp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Stephane Eranian <eranian@hpl.hp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Copyright (C) 2005-2008 Intel Co.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Fenghua Yu <fenghua.yu@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Bibo Mao <bibo.mao@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Chandramouli Narayanan <mouli@linux.intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Huang Ying <ying.huang@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * Copyright (C) 2011 Novell Co.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Jan Beulich <JBeulich@suse.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Copyright (C) 2011-2012 Oracle Co.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * Liang Tang <liang.tang@oracle.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * Copyright (c) 2014 Oracle Co., Daniel Kiper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/bug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/efi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <xen/interface/xen.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <xen/interface/platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <xen/xen.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <xen/xen-ops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <asm/xen/hypercall.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define INIT_EFI_OP(name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {.cmd = XENPF_efi_runtime_call, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) .u.efi_runtime_call.function = XEN_EFI_##name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) .u.efi_runtime_call.misc = 0}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define efi_data(op) (op.u.efi_runtime_call)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static efi_status_t xen_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct xen_platform_op op = INIT_EFI_OP(get_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if (HYPERVISOR_platform_op(&op) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) return EFI_UNSUPPORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if (tm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) BUILD_BUG_ON(sizeof(*tm) != sizeof(efi_data(op).u.get_time.time));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) memcpy(tm, &efi_data(op).u.get_time.time, sizeof(*tm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (tc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) tc->resolution = efi_data(op).u.get_time.resolution;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) tc->accuracy = efi_data(op).u.get_time.accuracy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) tc->sets_to_zero = !!(efi_data(op).misc &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) XEN_EFI_GET_TIME_SET_CLEARS_NS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return efi_data(op).status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static efi_status_t xen_efi_set_time(efi_time_t *tm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct xen_platform_op op = INIT_EFI_OP(set_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) BUILD_BUG_ON(sizeof(*tm) != sizeof(efi_data(op).u.set_time));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) memcpy(&efi_data(op).u.set_time, tm, sizeof(*tm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (HYPERVISOR_platform_op(&op) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) return EFI_UNSUPPORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return efi_data(op).status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static efi_status_t xen_efi_get_wakeup_time(efi_bool_t *enabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) efi_bool_t *pending,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) efi_time_t *tm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct xen_platform_op op = INIT_EFI_OP(get_wakeup_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (HYPERVISOR_platform_op(&op) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return EFI_UNSUPPORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (tm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) BUILD_BUG_ON(sizeof(*tm) != sizeof(efi_data(op).u.get_wakeup_time));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) memcpy(tm, &efi_data(op).u.get_wakeup_time, sizeof(*tm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) *enabled = !!(efi_data(op).misc & XEN_EFI_GET_WAKEUP_TIME_ENABLED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (pending)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) *pending = !!(efi_data(op).misc & XEN_EFI_GET_WAKEUP_TIME_PENDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return efi_data(op).status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static efi_status_t xen_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) struct xen_platform_op op = INIT_EFI_OP(set_wakeup_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) BUILD_BUG_ON(sizeof(*tm) != sizeof(efi_data(op).u.set_wakeup_time));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) efi_data(op).misc = XEN_EFI_SET_WAKEUP_TIME_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (tm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) memcpy(&efi_data(op).u.set_wakeup_time, tm, sizeof(*tm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) efi_data(op).misc |= XEN_EFI_SET_WAKEUP_TIME_ENABLE_ONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (HYPERVISOR_platform_op(&op) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return EFI_UNSUPPORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) return efi_data(op).status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static efi_status_t xen_efi_get_variable(efi_char16_t *name, efi_guid_t *vendor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) u32 *attr, unsigned long *data_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct xen_platform_op op = INIT_EFI_OP(get_variable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) set_xen_guest_handle(efi_data(op).u.get_variable.name, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) BUILD_BUG_ON(sizeof(*vendor) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) sizeof(efi_data(op).u.get_variable.vendor_guid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) memcpy(&efi_data(op).u.get_variable.vendor_guid, vendor, sizeof(*vendor));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) efi_data(op).u.get_variable.size = *data_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) set_xen_guest_handle(efi_data(op).u.get_variable.data, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (HYPERVISOR_platform_op(&op) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return EFI_UNSUPPORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) *data_size = efi_data(op).u.get_variable.size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) *attr = efi_data(op).misc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) return efi_data(op).status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static efi_status_t xen_efi_get_next_variable(unsigned long *name_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) efi_char16_t *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) efi_guid_t *vendor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct xen_platform_op op = INIT_EFI_OP(get_next_variable_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) efi_data(op).u.get_next_variable_name.size = *name_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) set_xen_guest_handle(efi_data(op).u.get_next_variable_name.name, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) BUILD_BUG_ON(sizeof(*vendor) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) sizeof(efi_data(op).u.get_next_variable_name.vendor_guid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) memcpy(&efi_data(op).u.get_next_variable_name.vendor_guid, vendor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) sizeof(*vendor));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (HYPERVISOR_platform_op(&op) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return EFI_UNSUPPORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) *name_size = efi_data(op).u.get_next_variable_name.size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) memcpy(vendor, &efi_data(op).u.get_next_variable_name.vendor_guid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) sizeof(*vendor));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return efi_data(op).status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static efi_status_t xen_efi_set_variable(efi_char16_t *name, efi_guid_t *vendor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) u32 attr, unsigned long data_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct xen_platform_op op = INIT_EFI_OP(set_variable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) set_xen_guest_handle(efi_data(op).u.set_variable.name, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) efi_data(op).misc = attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) BUILD_BUG_ON(sizeof(*vendor) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) sizeof(efi_data(op).u.set_variable.vendor_guid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) memcpy(&efi_data(op).u.set_variable.vendor_guid, vendor, sizeof(*vendor));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) efi_data(op).u.set_variable.size = data_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) set_xen_guest_handle(efi_data(op).u.set_variable.data, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (HYPERVISOR_platform_op(&op) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) return EFI_UNSUPPORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return efi_data(op).status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static efi_status_t xen_efi_query_variable_info(u32 attr, u64 *storage_space,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) u64 *remaining_space,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) u64 *max_variable_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct xen_platform_op op = INIT_EFI_OP(query_variable_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return EFI_UNSUPPORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) efi_data(op).u.query_variable_info.attr = attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (HYPERVISOR_platform_op(&op) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) return EFI_UNSUPPORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) *storage_space = efi_data(op).u.query_variable_info.max_store_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) *remaining_space = efi_data(op).u.query_variable_info.remain_store_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) *max_variable_size = efi_data(op).u.query_variable_info.max_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return efi_data(op).status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) static efi_status_t xen_efi_get_next_high_mono_count(u32 *count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct xen_platform_op op = INIT_EFI_OP(get_next_high_monotonic_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (HYPERVISOR_platform_op(&op) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return EFI_UNSUPPORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) *count = efi_data(op).misc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return efi_data(op).status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static efi_status_t xen_efi_update_capsule(efi_capsule_header_t **capsules,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) unsigned long count, unsigned long sg_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) struct xen_platform_op op = INIT_EFI_OP(update_capsule);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return EFI_UNSUPPORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) set_xen_guest_handle(efi_data(op).u.update_capsule.capsule_header_array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) capsules);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) efi_data(op).u.update_capsule.capsule_count = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) efi_data(op).u.update_capsule.sg_list = sg_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (HYPERVISOR_platform_op(&op) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return EFI_UNSUPPORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) return efi_data(op).status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static efi_status_t xen_efi_query_capsule_caps(efi_capsule_header_t **capsules,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) unsigned long count, u64 *max_size, int *reset_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) struct xen_platform_op op = INIT_EFI_OP(query_capsule_capabilities);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return EFI_UNSUPPORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) set_xen_guest_handle(efi_data(op).u.query_capsule_capabilities.capsule_header_array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) capsules);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) efi_data(op).u.query_capsule_capabilities.capsule_count = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (HYPERVISOR_platform_op(&op) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return EFI_UNSUPPORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) *max_size = efi_data(op).u.query_capsule_capabilities.max_capsule_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) *reset_type = efi_data(op).u.query_capsule_capabilities.reset_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return efi_data(op).status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static void xen_efi_reset_system(int reset_type, efi_status_t status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) unsigned long data_size, efi_char16_t *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) switch (reset_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) case EFI_RESET_COLD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) case EFI_RESET_WARM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) xen_reboot(SHUTDOWN_reboot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) case EFI_RESET_SHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) xen_reboot(SHUTDOWN_poweroff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * Set XEN EFI runtime services function pointers. Other fields of struct efi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * e.g. efi.systab, will be set like normal EFI.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) void __init xen_efi_runtime_setup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) efi.get_time = xen_efi_get_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) efi.set_time = xen_efi_set_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) efi.get_wakeup_time = xen_efi_get_wakeup_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) efi.set_wakeup_time = xen_efi_set_wakeup_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) efi.get_variable = xen_efi_get_variable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) efi.get_next_variable = xen_efi_get_next_variable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) efi.set_variable = xen_efi_set_variable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) efi.set_variable_nonblocking = xen_efi_set_variable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) efi.query_variable_info = xen_efi_query_variable_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) efi.query_variable_info_nonblocking = xen_efi_query_variable_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) efi.update_capsule = xen_efi_update_capsule;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) efi.query_capsule_caps = xen_efi_query_capsule_caps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) efi.get_next_high_mono_count = xen_efi_get_next_high_mono_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) efi.reset_system = xen_efi_reset_system;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }