0001
0002
0003
0004
0005
0006 #include <linux/bitops.h>
0007 #include <linux/efi.h>
0008 #include <linux/init.h>
0009 #include <linux/string.h>
0010
0011 #include <xen/xen.h>
0012 #include <xen/xen-ops.h>
0013 #include <xen/interface/platform.h>
0014
0015 #include <asm/page.h>
0016 #include <asm/setup.h>
0017 #include <asm/xen/hypercall.h>
0018
0019 static efi_char16_t vendor[100] __initdata;
0020
0021 static efi_system_table_t efi_systab_xen __initdata = {
0022 .hdr = {
0023 .signature = EFI_SYSTEM_TABLE_SIGNATURE,
0024 .revision = 0,
0025 .headersize = 0,
0026 .crc32 = 0,
0027 .reserved = 0
0028 },
0029 .fw_vendor = EFI_INVALID_TABLE_ADDR,
0030 .fw_revision = 0,
0031 .con_in_handle = EFI_INVALID_TABLE_ADDR,
0032 .con_in = NULL,
0033 .con_out_handle = EFI_INVALID_TABLE_ADDR,
0034 .con_out = NULL,
0035 .stderr_handle = EFI_INVALID_TABLE_ADDR,
0036 .stderr = EFI_INVALID_TABLE_ADDR,
0037 .runtime = (efi_runtime_services_t *)EFI_INVALID_TABLE_ADDR,
0038
0039 .boottime = (efi_boot_services_t *)EFI_INVALID_TABLE_ADDR,
0040
0041 .nr_tables = 0,
0042 .tables = EFI_INVALID_TABLE_ADDR
0043 };
0044
0045 static efi_system_table_t __init *xen_efi_probe(void)
0046 {
0047 struct xen_platform_op op = {
0048 .cmd = XENPF_firmware_info,
0049 .u.firmware_info = {
0050 .type = XEN_FW_EFI_INFO,
0051 .index = XEN_FW_EFI_CONFIG_TABLE
0052 }
0053 };
0054 union xenpf_efi_info *info = &op.u.firmware_info.u.efi_info;
0055
0056 if (!xen_initial_domain() || HYPERVISOR_platform_op(&op) < 0)
0057 return NULL;
0058
0059
0060 xen_efi_runtime_setup();
0061
0062 efi_systab_xen.tables = info->cfg.addr;
0063 efi_systab_xen.nr_tables = info->cfg.nent;
0064
0065 op.cmd = XENPF_firmware_info;
0066 op.u.firmware_info.type = XEN_FW_EFI_INFO;
0067 op.u.firmware_info.index = XEN_FW_EFI_VENDOR;
0068 info->vendor.bufsz = sizeof(vendor);
0069 set_xen_guest_handle(info->vendor.name, vendor);
0070
0071 if (HYPERVISOR_platform_op(&op) == 0) {
0072 efi_systab_xen.fw_vendor = __pa_symbol(vendor);
0073 efi_systab_xen.fw_revision = info->vendor.revision;
0074 } else
0075 efi_systab_xen.fw_vendor = __pa_symbol(L"UNKNOWN");
0076
0077 op.cmd = XENPF_firmware_info;
0078 op.u.firmware_info.type = XEN_FW_EFI_INFO;
0079 op.u.firmware_info.index = XEN_FW_EFI_VERSION;
0080
0081 if (HYPERVISOR_platform_op(&op) == 0)
0082 efi_systab_xen.hdr.revision = info->version;
0083
0084 op.cmd = XENPF_firmware_info;
0085 op.u.firmware_info.type = XEN_FW_EFI_INFO;
0086 op.u.firmware_info.index = XEN_FW_EFI_RT_VERSION;
0087
0088 if (HYPERVISOR_platform_op(&op) == 0)
0089 efi.runtime_version = info->version;
0090
0091 return &efi_systab_xen;
0092 }
0093
0094
0095
0096
0097 static enum efi_secureboot_mode xen_efi_get_secureboot(void)
0098 {
0099 static efi_guid_t shim_guid = EFI_SHIM_LOCK_GUID;
0100 enum efi_secureboot_mode mode;
0101 efi_status_t status;
0102 u8 moksbstate;
0103 unsigned long size;
0104
0105 mode = efi_get_secureboot_mode(efi.get_variable);
0106 if (mode == efi_secureboot_mode_unknown) {
0107 pr_err("Could not determine UEFI Secure Boot status.\n");
0108 return efi_secureboot_mode_unknown;
0109 }
0110 if (mode != efi_secureboot_mode_enabled)
0111 return mode;
0112
0113
0114 size = sizeof(moksbstate);
0115 status = efi.get_variable(L"MokSBStateRT", &shim_guid,
0116 NULL, &size, &moksbstate);
0117
0118
0119 if (status != EFI_SUCCESS)
0120 goto secure_boot_enabled;
0121
0122 if (moksbstate == 1)
0123 return efi_secureboot_mode_disabled;
0124
0125 secure_boot_enabled:
0126 pr_info("UEFI Secure Boot is enabled.\n");
0127 return efi_secureboot_mode_enabled;
0128 }
0129
0130 void __init xen_efi_init(struct boot_params *boot_params)
0131 {
0132 efi_system_table_t *efi_systab_xen;
0133
0134 efi_systab_xen = xen_efi_probe();
0135
0136 if (efi_systab_xen == NULL)
0137 return;
0138
0139 strncpy((char *)&boot_params->efi_info.efi_loader_signature, "Xen",
0140 sizeof(boot_params->efi_info.efi_loader_signature));
0141 boot_params->efi_info.efi_systab = (__u32)__pa(efi_systab_xen);
0142 boot_params->efi_info.efi_systab_hi = (__u32)(__pa(efi_systab_xen) >> 32);
0143
0144 boot_params->secure_boot = xen_efi_get_secureboot();
0145
0146 set_bit(EFI_BOOT, &efi.flags);
0147 set_bit(EFI_PARAVIRT, &efi.flags);
0148 set_bit(EFI_64BIT, &efi.flags);
0149 }