[coreboot-gerrit] Patch set updated for coreboot: 7f7fd4a qemu: add fw_cfg files support

Gerd Hoffmann (kraxel@redhat.com) gerrit at coreboot.org
Thu Nov 7 16:55:45 CET 2013


Gerd Hoffmann (kraxel at redhat.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/4029

-gerrit

commit 7f7fd4a8057badc57015afef30c409e8b186b1d6
Author: Gerd Hoffmann <kraxel at redhat.com>
Date:   Wed Jun 12 10:18:58 2013 +0200

    qemu: add fw_cfg files support
    
    Qemu can provide files using the firmware config interface.
    This is used to pass config options, virtual machine config
    info and option roms into the guest.
    
    This patch adds support for reading the file index and loading
    files from qemu.
    
    Change-Id: I57d4a734527c4117239f355121cf1fb8a390ab0d
    Signed-off-by: Gerd Hoffmann <kraxel at redhat.com>
---
 src/mainboard/emulation/qemu-i440fx/fw_cfg.c | 59 ++++++++++++++++++++++++++++
 src/mainboard/emulation/qemu-i440fx/fw_cfg.h |  2 +
 2 files changed, 61 insertions(+)

diff --git a/src/mainboard/emulation/qemu-i440fx/fw_cfg.c b/src/mainboard/emulation/qemu-i440fx/fw_cfg.c
index 5166f83..b85a163 100644
--- a/src/mainboard/emulation/qemu-i440fx/fw_cfg.c
+++ b/src/mainboard/emulation/qemu-i440fx/fw_cfg.c
@@ -16,6 +16,7 @@
  */
 
 #include <string.h>
+#include <swab.h>
 #include <console/console.h>
 #include <arch/io.h>
 
@@ -26,6 +27,7 @@
 #define FW_CFG_PORT_DATA      0x0511
 
 static unsigned char fw_cfg_detected = 0xff;
+static FWCfgFiles *fw_files;
 
 static int fw_cfg_present(void)
 {
@@ -47,6 +49,63 @@ void fw_cfg_get(int entry, void *dst, int dstlen)
 	insb(FW_CFG_PORT_DATA, dst, dstlen);
 }
 
+static void fw_cfg_init_file(void)
+{
+	u32 i, size, count = 0;
+
+	if (fw_files != NULL)
+		return;
+
+	fw_cfg_get(FW_CFG_FILE_DIR, &count, sizeof(count));
+	count = swab32(count);
+	size = count * sizeof(FWCfgFile) + sizeof(count);
+	printk(BIOS_DEBUG, "QEMU: %d files in fw_cfg\n", count);
+	fw_files = malloc(size);
+	fw_cfg_get(FW_CFG_FILE_DIR, fw_files, size);
+	fw_files->count = swab32(fw_files->count);
+	for (i = 0; i < count; i++) {
+		fw_files->f[i].size   = swab32(fw_files->f[i].size);
+		fw_files->f[i].select = swab16(fw_files->f[i].select);
+		printk(BIOS_DEBUG, "QEMU:     %s [size=%d]\n",
+		       fw_files->f[i].name, fw_files->f[i].size);
+	}
+}
+
+static FWCfgFile *fw_cfg_find_file(const char *name)
+{
+	int i;
+
+	fw_cfg_init_file();
+	for (i = 0; i < fw_files->count; i++)
+		if (strcmp(fw_files->f[i].name, name) == 0)
+			return fw_files->f + i;
+	return NULL;
+}
+
+int fw_cfg_check_file(const char *name)
+{
+	FWCfgFile *file;
+
+	if (!fw_cfg_present())
+		return -1;
+	file = fw_cfg_find_file(name);
+	if (!file)
+		return -1;
+	return file->size;
+}
+
+void fw_cfg_load_file(const char *name, void *dst)
+{
+	FWCfgFile *file;
+
+	if (!fw_cfg_present())
+		return;
+	file = fw_cfg_find_file(name);
+	if (!file)
+		return;
+	fw_cfg_get(file->select, dst, file->size);
+}
+
 int fw_cfg_max_cpus(void)
 {
 	unsigned short max_cpus;
diff --git a/src/mainboard/emulation/qemu-i440fx/fw_cfg.h b/src/mainboard/emulation/qemu-i440fx/fw_cfg.h
index 063e48f..2a10d8b 100644
--- a/src/mainboard/emulation/qemu-i440fx/fw_cfg.h
+++ b/src/mainboard/emulation/qemu-i440fx/fw_cfg.h
@@ -16,4 +16,6 @@
  */
 
 void fw_cfg_get(int entry, void *dst, int dstlen);
+int fw_cfg_check_file(const char *name);
+void fw_cfg_load_file(const char *name, void *dst);
 int fw_cfg_max_cpus(void);



More information about the coreboot-gerrit mailing list