@@ -146,9 +146,6 @@ static void pc_system_flash_map(PCMachineState *pcms,
int64_t size;
PFlashCFI01 *system_flash;
MemoryRegion *flash_mem;
- void *flash_ptr;
- int flash_size;
- int ret;
assert(PC_MACHINE_GET_CLASS(pcms)->pci_enabled);
@@ -192,24 +189,9 @@ static void pc_system_flash_map(PCMachineState *pcms,
flash_mem = pflash_cfi01_get_memory(system_flash);
pc_isa_bios_init(rom_memory, flash_mem, size);
- /* Encrypt the pflash boot ROM */
- if (sev_enabled()) {
- flash_ptr = memory_region_get_ram_ptr(flash_mem);
- flash_size = memory_region_size(flash_mem);
- /*
- * OVMF places a GUIDed structures in the flash, so
- * search for them
- */
- pc_system_parse_ovmf_flash(flash_ptr, flash_size);
-
- ret = sev_es_save_reset_vector(flash_ptr, flash_size);
- if (ret) {
- error_report("failed to locate and/or save reset vector");
- exit(1);
- }
-
- sev_encrypt_flash(flash_ptr, flash_size, &error_fatal);
- }
+ pc_system_ovmf_initialize_sev(
+ memory_region_get_ram_ptr(flash_mem),
+ memory_region_size(flash_mem));
}
}
}
@@ -14,6 +14,7 @@
#include "qemu/osdep.h"
#include "hw/i386/pc.h"
+#include "sev.h"
bool pc_system_ovmf_table_find(const char *entry, uint8_t **data, int *data_len)
{
@@ -24,3 +25,12 @@ void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size_t flash_size)
{
g_assert_not_reached();
}
+
+void pc_system_ovmf_initialize_sev(void *ptr, size_t size)
+{
+ if (!sev_enabled()) {
+ return;
+ }
+
+ g_assert_not_reached();
+}
@@ -24,8 +24,10 @@
*/
#include "qemu/osdep.h"
+#include "qapi/error.h"
#include "hw/i386/pc.h"
#include "cpu.h"
+#include "sev.h"
#define OVMF_TABLE_FOOTER_GUID "96b582de-1fb2-45f7-baea-a366c55a082d"
@@ -149,3 +151,28 @@ bool pc_system_ovmf_table_find(const char *entry, uint8_t **data,
}
return false;
}
+
+
+void pc_system_ovmf_initialize_sev(void *ptr, size_t size)
+{
+ int ret;
+
+ /* Encrypt the boot ROM */
+ if (!sev_enabled()) {
+ return;
+ }
+
+ /*
+ * OVMF places a GUIDed structures in the flash, so
+ * search for them
+ */
+ pc_system_parse_ovmf_flash(ptr, size);
+
+ ret = sev_es_save_reset_vector(ptr, size);
+ if (ret) {
+ error_report("failed to locate and/or save reset vector");
+ exit(1);
+ }
+
+ sev_encrypt_flash(ptr, size, &error_fatal);
+}
@@ -191,6 +191,7 @@ void pc_system_firmware_init(PCMachineState *pcms, MemoryRegion *rom_memory);
bool pc_system_ovmf_table_find(const char *entry, uint8_t **data,
int *data_len);
void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size_t flash_size);
+void pc_system_ovmf_initialize_sev(void *ptr, size_t size);
/* hw/i386/acpi-common.c */
void pc_madt_cpu_entry(AcpiDeviceIf *adev, int uid,
Currently this logic is only run in the pflash codepath but we want to run it in other scenarios too. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- hw/i386/pc_sysfw.c | 24 +++--------------------- hw/i386/pc_sysfw_ovmf-stubs.c | 10 ++++++++++ hw/i386/pc_sysfw_ovmf.c | 27 +++++++++++++++++++++++++++ include/hw/i386/pc.h | 1 + 4 files changed, 41 insertions(+), 21 deletions(-)