diff mbox

[PULL,17/43] loader: support for unmapped ROM blobs

Message ID 1381762577-12526-18-git-send-email-mst@redhat.com
State New
Headers show

Commit Message

Michael S. Tsirkin Oct. 14, 2013, 2:58 p.m. UTC
Support ROM blobs not mapped into guest memory:
same as ROM files really but use caller's buffer.

Support invoking callback on access and
return memory pointer making it easier
for caller to update memory if necessary.

Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Tested-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/lm32/lm32_hwsetup.h |  2 +-
 include/hw/loader.h    |  7 ++++---
 hw/core/loader.c       | 23 ++++++++++++++++++++---
 3 files changed, 25 insertions(+), 7 deletions(-)

Comments

Alexander Graf Nov. 8, 2013, 12:54 a.m. UTC | #1
On 14.10.2013, at 16:58, Michael S. Tsirkin <mst@redhat.com> wrote:

> Support ROM blobs not mapped into guest memory:
> same as ROM files really but use caller's buffer.
> 
> Support invoking callback on access and
> return memory pointer making it easier
> for caller to update memory if necessary.
> 
> Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
> Tested-by: Gerd Hoffmann <kraxel@redhat.com>
> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
> Reviewed-by: Igor Mammedov <imammedo@redhat.com>
> Tested-by: Igor Mammedov <imammedo@redhat.com>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

This patch breaks -M bamboo. Let explain inline why.

> ---
> hw/lm32/lm32_hwsetup.h |  2 +-
> include/hw/loader.h    |  7 ++++---
> hw/core/loader.c       | 23 ++++++++++++++++++++---
> 3 files changed, 25 insertions(+), 7 deletions(-)
> 
> diff --git a/hw/lm32/lm32_hwsetup.h b/hw/lm32/lm32_hwsetup.h
> index 3449bd8..9fd5e69 100644
> --- a/hw/lm32/lm32_hwsetup.h
> +++ b/hw/lm32/lm32_hwsetup.h
> @@ -73,7 +73,7 @@ static inline void hwsetup_free(HWSetup *hw)
> static inline void hwsetup_create_rom(HWSetup *hw,
>         hwaddr base)
> {
> -    rom_add_blob("hwsetup", hw->data, TARGET_PAGE_SIZE, base);
> +    rom_add_blob("hwsetup", hw->data, TARGET_PAGE_SIZE, base, NULL, NULL, NULL);
> }
> 
> static inline void hwsetup_add_u8(HWSetup *hw, uint8_t u)
> diff --git a/include/hw/loader.h b/include/hw/loader.h
> index 6145736..e0c576b 100644
> --- a/include/hw/loader.h
> +++ b/include/hw/loader.h
> @@ -40,8 +40,9 @@ extern bool rom_file_in_ram;
> 
> int rom_add_file(const char *file, const char *fw_dir,
>                  hwaddr addr, int32_t bootindex);
> -int rom_add_blob(const char *name, const void *blob, size_t len,
> -                 hwaddr addr);
> +void *rom_add_blob(const char *name, const void *blob, size_t len,
> +                   hwaddr addr, const char *fw_file_name,
> +                   FWCfgReadCallback fw_callback, void *callback_opaque);
> int rom_add_elf_program(const char *name, void *data, size_t datasize,
>                         size_t romsize, hwaddr addr);
> int rom_load_all(void);
> @@ -53,7 +54,7 @@ void do_info_roms(Monitor *mon, const QDict *qdict);
> #define rom_add_file_fixed(_f, _a, _i)          \
>     rom_add_file(_f, NULL, _a, _i)
> #define rom_add_blob_fixed(_f, _b, _l, _a)      \
> -    rom_add_blob(_f, _b, _l, _a)
> +    (rom_add_blob(_f, _b, _l, _a, NULL, NULL, NULL) ? 0 : -1)

^

> 
> #define PC_ROM_MIN_VGA     0xc0000
> #define PC_ROM_MIN_OPTION  0xc8000
> diff --git a/hw/core/loader.c b/hw/core/loader.c
> index 7b3d3ee..449bd4c 100644
> --- a/hw/core/loader.c
> +++ b/hw/core/loader.c
> @@ -700,10 +700,12 @@ err:
>     return -1;
> }
> 
> -int rom_add_blob(const char *name, const void *blob, size_t len,
> -                 hwaddr addr)
> +void *rom_add_blob(const char *name, const void *blob, size_t len,
> +                   hwaddr addr, const char *fw_file_name,
> +                   FWCfgReadCallback fw_callback, void *callback_opaque)
> {
>     Rom *rom;
> +    void *data = NULL;

data = NULL

> 
>     rom           = g_malloc0(sizeof(*rom));
>     rom->name     = g_strdup(name);
> @@ -713,7 +715,22 @@ int rom_add_blob(const char *name, const void *blob, size_t len,
>     rom->data     = g_malloc0(rom->datasize);
>     memcpy(rom->data, blob, len);
>     rom_insert(rom);
> -    return 0;
> +    if (fw_file_name && fw_cfg) {

We never execute this for rom_add_blob_fixed(), so ...

> +        char devpath[100];
> +
> +        snprintf(devpath, sizeof(devpath), "/rom@%s", fw_file_name);
> +
> +        if (rom_file_in_ram) {
> +            data = rom_set_mr(rom, OBJECT(fw_cfg), devpath);
> +        } else {
> +            data = rom->data;
> +        }
> +
> +        fw_cfg_add_file_callback(fw_cfg, fw_file_name,
> +                                 fw_callback, callback_opaque,
> +                                 data, rom->romsize);
> +    }
> +    return data;

... we always return NULL here.

That means that rom_add_blob_fixed() always returns -1. If rom_add_blob_fixed() returns != 0, we abort loading the device tree as blob during bamboo machine init.


Alex
diff mbox

Patch

diff --git a/hw/lm32/lm32_hwsetup.h b/hw/lm32/lm32_hwsetup.h
index 3449bd8..9fd5e69 100644
--- a/hw/lm32/lm32_hwsetup.h
+++ b/hw/lm32/lm32_hwsetup.h
@@ -73,7 +73,7 @@  static inline void hwsetup_free(HWSetup *hw)
 static inline void hwsetup_create_rom(HWSetup *hw,
         hwaddr base)
 {
-    rom_add_blob("hwsetup", hw->data, TARGET_PAGE_SIZE, base);
+    rom_add_blob("hwsetup", hw->data, TARGET_PAGE_SIZE, base, NULL, NULL, NULL);
 }
 
 static inline void hwsetup_add_u8(HWSetup *hw, uint8_t u)
diff --git a/include/hw/loader.h b/include/hw/loader.h
index 6145736..e0c576b 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -40,8 +40,9 @@  extern bool rom_file_in_ram;
 
 int rom_add_file(const char *file, const char *fw_dir,
                  hwaddr addr, int32_t bootindex);
-int rom_add_blob(const char *name, const void *blob, size_t len,
-                 hwaddr addr);
+void *rom_add_blob(const char *name, const void *blob, size_t len,
+                   hwaddr addr, const char *fw_file_name,
+                   FWCfgReadCallback fw_callback, void *callback_opaque);
 int rom_add_elf_program(const char *name, void *data, size_t datasize,
                         size_t romsize, hwaddr addr);
 int rom_load_all(void);
@@ -53,7 +54,7 @@  void do_info_roms(Monitor *mon, const QDict *qdict);
 #define rom_add_file_fixed(_f, _a, _i)          \
     rom_add_file(_f, NULL, _a, _i)
 #define rom_add_blob_fixed(_f, _b, _l, _a)      \
-    rom_add_blob(_f, _b, _l, _a)
+    (rom_add_blob(_f, _b, _l, _a, NULL, NULL, NULL) ? 0 : -1)
 
 #define PC_ROM_MIN_VGA     0xc0000
 #define PC_ROM_MIN_OPTION  0xc8000
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 7b3d3ee..449bd4c 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -700,10 +700,12 @@  err:
     return -1;
 }
 
-int rom_add_blob(const char *name, const void *blob, size_t len,
-                 hwaddr addr)
+void *rom_add_blob(const char *name, const void *blob, size_t len,
+                   hwaddr addr, const char *fw_file_name,
+                   FWCfgReadCallback fw_callback, void *callback_opaque)
 {
     Rom *rom;
+    void *data = NULL;
 
     rom           = g_malloc0(sizeof(*rom));
     rom->name     = g_strdup(name);
@@ -713,7 +715,22 @@  int rom_add_blob(const char *name, const void *blob, size_t len,
     rom->data     = g_malloc0(rom->datasize);
     memcpy(rom->data, blob, len);
     rom_insert(rom);
-    return 0;
+    if (fw_file_name && fw_cfg) {
+        char devpath[100];
+
+        snprintf(devpath, sizeof(devpath), "/rom@%s", fw_file_name);
+
+        if (rom_file_in_ram) {
+            data = rom_set_mr(rom, OBJECT(fw_cfg), devpath);
+        } else {
+            data = rom->data;
+        }
+
+        fw_cfg_add_file_callback(fw_cfg, fw_file_name,
+                                 fw_callback, callback_opaque,
+                                 data, rom->romsize);
+    }
+    return data;
 }
 
 /* This function is specific for elf program because we don't need to allocate