yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
0a122b
From 829a4521369f93923f4787cc1e45f1a0d432d71b Mon Sep 17 00:00:00 2001
0a122b
Message-Id: <829a4521369f93923f4787cc1e45f1a0d432d71b.1387298827.git.minovotn@redhat.com>
0a122b
In-Reply-To: <3ed0fb61a3dc912ef036d7ef450bed192090709e.1387298827.git.minovotn@redhat.com>
0a122b
References: <3ed0fb61a3dc912ef036d7ef450bed192090709e.1387298827.git.minovotn@redhat.com>
0a122b
From: "Michael S. Tsirkin" <mst@redhat.com>
0a122b
Date: Tue, 17 Dec 2013 15:17:59 +0100
0a122b
Subject: [PATCH 27/56] loader: support for unmapped ROM blobs
0a122b
0a122b
RH-Author: Michael S. Tsirkin <mst@redhat.com>
0a122b
Message-id: <1387293161-4085-28-git-send-email-mst@redhat.com>
0a122b
Patchwork-id: 56333
0a122b
O-Subject: [PATCH qemu-kvm RHEL7.0 v2 27/57] loader: support for unmapped ROM blobs
0a122b
Bugzilla: 1034876
0a122b
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
0a122b
RH-Acked-by: Marcel Apfelbaum <marcel.a@redhat.com>
0a122b
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
0a122b
0a122b
Support ROM blobs not mapped into guest memory:
0a122b
same as ROM files really but use caller's buffer.
0a122b
0a122b
Support invoking callback on access and
0a122b
return memory pointer making it easier
0a122b
for caller to update memory if necessary.
0a122b
0a122b
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
0a122b
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
0a122b
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
0a122b
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
0a122b
Tested-by: Igor Mammedov <imammedo@redhat.com>
0a122b
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
0a122b
(cherry picked from commit 48354cc5a3744c9a56462e5053e1f267a0ce69de)
0a122b
---
0a122b
 hw/lm32/lm32_hwsetup.h |  2 +-
0a122b
 include/hw/loader.h    |  7 ++++---
0a122b
 hw/core/loader.c       | 23 ++++++++++++++++++++---
0a122b
 3 files changed, 25 insertions(+), 7 deletions(-)
0a122b
0a122b
Signed-off-by: Michal Novotny <minovotn@redhat.com>
0a122b
---
0a122b
 hw/core/loader.c       | 23 ++++++++++++++++++++---
0a122b
 hw/lm32/lm32_hwsetup.h |  2 +-
0a122b
 include/hw/loader.h    |  7 ++++---
0a122b
 3 files changed, 25 insertions(+), 7 deletions(-)
0a122b
0a122b
diff --git a/hw/core/loader.c b/hw/core/loader.c
0a122b
index 6bdbd15..2bfff48 100644
0a122b
--- a/hw/core/loader.c
0a122b
+++ b/hw/core/loader.c
0a122b
@@ -666,10 +666,12 @@ err:
0a122b
     return -1;
0a122b
 }
0a122b
 
0a122b
-int rom_add_blob(const char *name, const void *blob, size_t len,
0a122b
-                 hwaddr addr)
0a122b
+void *rom_add_blob(const char *name, const void *blob, size_t len,
0a122b
+                   hwaddr addr, const char *fw_file_name,
0a122b
+                   FWCfgReadCallback fw_callback, void *callback_opaque)
0a122b
 {
0a122b
     Rom *rom;
0a122b
+    void *data = NULL;
0a122b
 
0a122b
     rom           = g_malloc0(sizeof(*rom));
0a122b
     rom->name     = g_strdup(name);
0a122b
@@ -679,7 +681,22 @@ int rom_add_blob(const char *name, const void *blob, size_t len,
0a122b
     rom->data     = g_malloc0(rom->datasize);
0a122b
     memcpy(rom->data, blob, len);
0a122b
     rom_insert(rom);
0a122b
-    return 0;
0a122b
+    if (fw_file_name && fw_cfg) {
0a122b
+        char devpath[100];
0a122b
+
0a122b
+        snprintf(devpath, sizeof(devpath), "/rom@%s", fw_file_name);
0a122b
+
0a122b
+        if (rom_file_in_ram) {
0a122b
+            data = rom_set_mr(rom, devpath);
0a122b
+        } else {
0a122b
+            data = rom->data;
0a122b
+        }
0a122b
+
0a122b
+        fw_cfg_add_file_callback(fw_cfg, fw_file_name,
0a122b
+                                 fw_callback, callback_opaque,
0a122b
+                                 data, rom->romsize);
0a122b
+    }
0a122b
+    return data;
0a122b
 }
0a122b
 
0a122b
 /* This function is specific for elf program because we don't need to allocate
0a122b
diff --git a/hw/lm32/lm32_hwsetup.h b/hw/lm32/lm32_hwsetup.h
0a122b
index 3449bd8..9fd5e69 100644
0a122b
--- a/hw/lm32/lm32_hwsetup.h
0a122b
+++ b/hw/lm32/lm32_hwsetup.h
0a122b
@@ -73,7 +73,7 @@ static inline void hwsetup_free(HWSetup *hw)
0a122b
 static inline void hwsetup_create_rom(HWSetup *hw,
0a122b
         hwaddr base)
0a122b
 {
0a122b
-    rom_add_blob("hwsetup", hw->data, TARGET_PAGE_SIZE, base);
0a122b
+    rom_add_blob("hwsetup", hw->data, TARGET_PAGE_SIZE, base, NULL, NULL, NULL);
0a122b
 }
0a122b
 
0a122b
 static inline void hwsetup_add_u8(HWSetup *hw, uint8_t u)
0a122b
diff --git a/include/hw/loader.h b/include/hw/loader.h
0a122b
index 19e11ea..1381a1d 100644
0a122b
--- a/include/hw/loader.h
0a122b
+++ b/include/hw/loader.h
0a122b
@@ -27,8 +27,9 @@ extern bool rom_file_in_ram;
0a122b
 
0a122b
 int rom_add_file(const char *file, const char *fw_dir,
0a122b
                  hwaddr addr, int32_t bootindex);
0a122b
-int rom_add_blob(const char *name, const void *blob, size_t len,
0a122b
-                 hwaddr addr);
0a122b
+void *rom_add_blob(const char *name, const void *blob, size_t len,
0a122b
+                   hwaddr addr, const char *fw_file_name,
0a122b
+                   FWCfgReadCallback fw_callback, void *callback_opaque);
0a122b
 int rom_add_elf_program(const char *name, void *data, size_t datasize,
0a122b
                         size_t romsize, hwaddr addr);
0a122b
 int rom_load_all(void);
0a122b
@@ -40,7 +41,7 @@ void do_info_roms(Monitor *mon, const QDict *qdict);
0a122b
 #define rom_add_file_fixed(_f, _a, _i)          \
0a122b
     rom_add_file(_f, NULL, _a, _i)
0a122b
 #define rom_add_blob_fixed(_f, _b, _l, _a)      \
0a122b
-    rom_add_blob(_f, _b, _l, _a)
0a122b
+    (rom_add_blob(_f, _b, _l, _a, NULL, NULL, NULL) ? 0 : -1)
0a122b
 
0a122b
 #define PC_ROM_MIN_VGA     0xc0000
0a122b
 #define PC_ROM_MIN_OPTION  0xc8000
0a122b
-- 
0a122b
1.7.11.7
0a122b