aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2019-05-23 14:15:34 +0100
committerPeter Maydell <peter.maydell@linaro.org>2019-05-23 14:15:34 +0100
commit8dc7fd56dd4f56ab8ff1df3765ae6b5d3ac11c5e (patch)
tree2891a344c637e2f0d650647a3701a03fa57abfba /hw
parentd418238dca7b4e0b124135827ead3076233052b1 (diff)
parent3ae9dd1a304248e1f6ca631cdd43eb44a3e9e7b4 (diff)
Merge remote-tracking branch 'remotes/philmd-gitlab/tags/fw_cfg-20190523-pull-request' into staging
fw_cfg patches for 2019-05-23 - Add trace events - Get rid of globals in fw_cfg-test - Explicit 'reboot-timeout' is little endian - Add tests for 'reboot-timeout' and 'splash-time' # gpg: Signature made Thu 23 May 2019 13:40:32 BST # gpg: using RSA key E3E32C2CDEADC0DE # gpg: Good signature from "Philippe Mathieu-Daudé (F4BUG) <f4bug@amsat.org>" [full] # Primary key fingerprint: FAAB E75E 1291 7221 DCFD 6BB2 E3E3 2C2C DEAD C0DE * remotes/philmd-gitlab/tags/fw_cfg-20190523-pull-request: tests: fw_cfg: add 'splash-time' test case tests: fw_cfg: add 'reboot-timeout' test case hw/nvram/fw_cfg: Store 'reboot-timeout' as little endian tests: fw_cfg: add a function to get the fw_cfg file tests: refactor fw_cfg_test tests/fw_cfg: Free QFWCFG object after qtest has run tests/libqos: Add pc_fw_cfg_uninit() and use it tests/libqos: Add io_fw_cfg_uninit() and mm_fw_cfg_uninit() hw/sparc64: Implement fw_cfg_arch_key_name() hw/sparc: Implement fw_cfg_arch_key_name() hw/ppc: Implement fw_cfg_arch_key_name() hw/i386: Implement fw_cfg_arch_key_name() hw/i386: Extract fw_cfg definitions to local "fw_cfg.h" hw/nvram/fw_cfg: Add fw_cfg_arch_key_name() hw/nvram/fw_cfg: Add trace events Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw')
-rw-r--r--hw/i386/Makefile.objs2
-rw-r--r--hw/i386/fw_cfg.c38
-rw-r--r--hw/i386/fw_cfg.h20
-rw-r--r--hw/i386/pc.c7
-rw-r--r--hw/nvram/fw_cfg.c67
-rw-r--r--hw/nvram/trace-events7
-rw-r--r--hw/ppc/Makefile.objs2
-rw-r--r--hw/ppc/fw_cfg.c45
-rw-r--r--hw/sparc/sun4m.c19
-rw-r--r--hw/sparc64/sun4u.c19
10 files changed, 215 insertions, 11 deletions
diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index 27248a0777..5d9c9efd5f 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -3,7 +3,7 @@ obj-y += multiboot.o
obj-y += pc.o
obj-$(CONFIG_I440FX) += pc_piix.o
obj-$(CONFIG_Q35) += pc_q35.o
-obj-y += pc_sysfw.o
+obj-y += fw_cfg.o pc_sysfw.o
obj-y += x86-iommu.o
obj-$(CONFIG_VTD) += intel_iommu.o
obj-$(CONFIG_AMD_IOMMU) += amd_iommu.o
diff --git a/hw/i386/fw_cfg.c b/hw/i386/fw_cfg.c
new file mode 100644
index 0000000000..380a819230
--- /dev/null
+++ b/hw/i386/fw_cfg.c
@@ -0,0 +1,38 @@
+/*
+ * QEMU fw_cfg helpers (X86 specific)
+ *
+ * Copyright (c) 2019 Red Hat, Inc.
+ *
+ * Author:
+ * Philippe Mathieu-Daudé <philmd@redhat.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/i386/fw_cfg.h"
+#include "hw/nvram/fw_cfg.h"
+
+const char *fw_cfg_arch_key_name(uint16_t key)
+{
+ static const struct {
+ uint16_t key;
+ const char *name;
+ } fw_cfg_arch_wellknown_keys[] = {
+ {FW_CFG_ACPI_TABLES, "acpi_tables"},
+ {FW_CFG_SMBIOS_ENTRIES, "smbios_entries"},
+ {FW_CFG_IRQ0_OVERRIDE, "irq0_override"},
+ {FW_CFG_E820_TABLE, "e820_table"},
+ {FW_CFG_HPET, "hpet"},
+ };
+
+ for (size_t i = 0; i < ARRAY_SIZE(fw_cfg_arch_wellknown_keys); i++) {
+ if (fw_cfg_arch_wellknown_keys[i].key == key) {
+ return fw_cfg_arch_wellknown_keys[i].name;
+ }
+ }
+ return NULL;
+}
diff --git a/hw/i386/fw_cfg.h b/hw/i386/fw_cfg.h
new file mode 100644
index 0000000000..17a4bc32f2
--- /dev/null
+++ b/hw/i386/fw_cfg.h
@@ -0,0 +1,20 @@
+/*
+ * QEMU fw_cfg helpers (X86 specific)
+ *
+ * Copyright (c) 2003-2004 Fabrice Bellard
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef HW_I386_FW_CFG_H
+#define HW_I386_FW_CFG_H
+
+#include "hw/nvram/fw_cfg.h"
+
+#define FW_CFG_ACPI_TABLES (FW_CFG_ARCH_LOCAL + 0)
+#define FW_CFG_SMBIOS_ENTRIES (FW_CFG_ARCH_LOCAL + 1)
+#define FW_CFG_IRQ0_OVERRIDE (FW_CFG_ARCH_LOCAL + 2)
+#define FW_CFG_E820_TABLE (FW_CFG_ARCH_LOCAL + 3)
+#define FW_CFG_HPET (FW_CFG_ARCH_LOCAL + 4)
+
+#endif
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index d98b737b8f..2632b73f80 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -30,6 +30,7 @@
#include "hw/char/parallel.h"
#include "hw/i386/apic.h"
#include "hw/i386/topology.h"
+#include "hw/i386/fw_cfg.h"
#include "sysemu/cpus.h"
#include "hw/block/fdc.h"
#include "hw/ide.h"
@@ -88,12 +89,6 @@
#define DPRINTF(fmt, ...)
#endif
-#define FW_CFG_ACPI_TABLES (FW_CFG_ARCH_LOCAL + 0)
-#define FW_CFG_SMBIOS_ENTRIES (FW_CFG_ARCH_LOCAL + 1)
-#define FW_CFG_IRQ0_OVERRIDE (FW_CFG_ARCH_LOCAL + 2)
-#define FW_CFG_E820_TABLE (FW_CFG_ARCH_LOCAL + 3)
-#define FW_CFG_HPET (FW_CFG_ARCH_LOCAL + 4)
-
#define E820_NR_ENTRIES 16
struct e820_entry {
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index 5c3a46ce6f..9f7b7789bc 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -60,6 +60,62 @@ struct FWCfgEntry {
FWCfgWriteCallback write_cb;
};
+/**
+ * key_name:
+ *
+ * @key: The uint16 selector key.
+ *
+ * Returns: The stringified name if the selector refers to a well-known
+ * numerically defined item, or NULL on key lookup failure.
+ */
+static const char *key_name(uint16_t key)
+{
+ static const char *fw_cfg_wellknown_keys[FW_CFG_FILE_FIRST] = {
+ [FW_CFG_SIGNATURE] = "signature",
+ [FW_CFG_ID] = "id",
+ [FW_CFG_UUID] = "uuid",
+ [FW_CFG_RAM_SIZE] = "ram_size",
+ [FW_CFG_NOGRAPHIC] = "nographic",
+ [FW_CFG_NB_CPUS] = "nb_cpus",
+ [FW_CFG_MACHINE_ID] = "machine_id",
+ [FW_CFG_KERNEL_ADDR] = "kernel_addr",
+ [FW_CFG_KERNEL_SIZE] = "kernel_size",
+ [FW_CFG_KERNEL_CMDLINE] = "kernel_cmdline",
+ [FW_CFG_INITRD_ADDR] = "initrd_addr",
+ [FW_CFG_INITRD_SIZE] = "initdr_size",
+ [FW_CFG_BOOT_DEVICE] = "boot_device",
+ [FW_CFG_NUMA] = "numa",
+ [FW_CFG_BOOT_MENU] = "boot_menu",
+ [FW_CFG_MAX_CPUS] = "max_cpus",
+ [FW_CFG_KERNEL_ENTRY] = "kernel_entry",
+ [FW_CFG_KERNEL_DATA] = "kernel_data",
+ [FW_CFG_INITRD_DATA] = "initrd_data",
+ [FW_CFG_CMDLINE_ADDR] = "cmdline_addr",
+ [FW_CFG_CMDLINE_SIZE] = "cmdline_size",
+ [FW_CFG_CMDLINE_DATA] = "cmdline_data",
+ [FW_CFG_SETUP_ADDR] = "setup_addr",
+ [FW_CFG_SETUP_SIZE] = "setup_size",
+ [FW_CFG_SETUP_DATA] = "setup_data",
+ [FW_CFG_FILE_DIR] = "file_dir",
+ };
+
+ if (key & FW_CFG_ARCH_LOCAL) {
+ return fw_cfg_arch_key_name(key);
+ }
+ if (key < FW_CFG_FILE_FIRST) {
+ return fw_cfg_wellknown_keys[key];
+ }
+
+ return NULL;
+}
+
+static inline const char *trace_key_name(uint16_t key)
+{
+ const char *name = key_name(key);
+
+ return name ? name : "unknown";
+}
+
#define JPG_FILE 0
#define BMP_FILE 1
@@ -178,6 +234,7 @@ static void fw_cfg_reboot(FWCfgState *s)
{
const char *reboot_timeout = NULL;
int64_t rt_val = -1;
+ uint32_t rt_le32;
/* get user configuration */
QemuOptsList *plist = qemu_find_opts("boot-opts");
@@ -194,7 +251,8 @@ static void fw_cfg_reboot(FWCfgState *s)
}
}
- fw_cfg_add_file(s, "etc/boot-fail-wait", g_memdup(&rt_val, 4), 4);
+ rt_le32 = cpu_to_le32(rt_val);
+ fw_cfg_add_file(s, "etc/boot-fail-wait", g_memdup(&rt_le32, 4), 4);
}
static void fw_cfg_write(FWCfgState *s, uint8_t value)
@@ -233,7 +291,7 @@ static int fw_cfg_select(FWCfgState *s, uint16_t key)
}
}
- trace_fw_cfg_select(s, key, ret);
+ trace_fw_cfg_select(s, key, trace_key_name(key), ret);
return ret;
}
@@ -616,6 +674,7 @@ static void *fw_cfg_modify_bytes_read(FWCfgState *s, uint16_t key,
void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len)
{
+ trace_fw_cfg_add_bytes(key, trace_key_name(key), len);
fw_cfg_add_bytes_callback(s, key, NULL, NULL, NULL, data, len, true);
}
@@ -623,6 +682,7 @@ void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value)
{
size_t sz = strlen(value) + 1;
+ trace_fw_cfg_add_string(key, trace_key_name(key), value);
fw_cfg_add_bytes(s, key, g_memdup(value, sz), sz);
}
@@ -632,6 +692,7 @@ void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value)
copy = g_malloc(sizeof(value));
*copy = cpu_to_le16(value);
+ trace_fw_cfg_add_i16(key, trace_key_name(key), value);
fw_cfg_add_bytes(s, key, copy, sizeof(value));
}
@@ -651,6 +712,7 @@ void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value)
copy = g_malloc(sizeof(value));
*copy = cpu_to_le32(value);
+ trace_fw_cfg_add_i32(key, trace_key_name(key), value);
fw_cfg_add_bytes(s, key, copy, sizeof(value));
}
@@ -660,6 +722,7 @@ void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value)
copy = g_malloc(sizeof(value));
*copy = cpu_to_le64(value);
+ trace_fw_cfg_add_i64(key, trace_key_name(key), value);
fw_cfg_add_bytes(s, key, copy, sizeof(value));
}
diff --git a/hw/nvram/trace-events b/hw/nvram/trace-events
index e191991e2a..0dea9260ce 100644
--- a/hw/nvram/trace-events
+++ b/hw/nvram/trace-events
@@ -5,6 +5,11 @@ nvram_read(uint32_t addr, uint32_t ret) "read addr %d: 0x%02x"
nvram_write(uint32_t addr, uint32_t old, uint32_t val) "write addr %d: 0x%02x -> 0x%02x"
# fw_cfg.c
-fw_cfg_select(void *s, uint16_t key, int ret) "%p key %d = %d"
+fw_cfg_select(void *s, uint16_t key_value, const char *key_name, int ret) "%p key 0x%04" PRIx16 " '%s', ret: %d"
fw_cfg_read(void *s, uint64_t ret) "%p = 0x%"PRIx64
+fw_cfg_add_bytes(uint16_t key_value, const char *key_name, size_t len) "key 0x%04" PRIx16 " '%s', %zu bytes"
fw_cfg_add_file(void *s, int index, char *name, size_t len) "%p #%d: %s (%zd bytes)"
+fw_cfg_add_string(uint16_t key_value, const char *key_name, const char *value) "key 0x%04" PRIx16 " '%s', value '%s'"
+fw_cfg_add_i16(uint16_t key_value, const char *key_name, uint16_t value) "key 0x%04" PRIx16 " '%s', value 0x%" PRIx16
+fw_cfg_add_i32(uint16_t key_value, const char *key_name, uint32_t value) "key 0x%04" PRIx16 " '%s', value 0x%" PRIx32
+fw_cfg_add_i64(uint16_t key_value, const char *key_name, uint64_t value) "key 0x%04" PRIx16 " '%s', value 0x%" PRIx64
diff --git a/hw/ppc/Makefile.objs b/hw/ppc/Makefile.objs
index 636e717f20..9da93af905 100644
--- a/hw/ppc/Makefile.objs
+++ b/hw/ppc/Makefile.objs
@@ -1,5 +1,5 @@
# shared objects
-obj-y += ppc.o ppc_booke.o fdt.o
+obj-y += ppc.o ppc_booke.o fdt.o fw_cfg.o
# IBM pSeries (sPAPR)
obj-$(CONFIG_PSERIES) += spapr.o spapr_caps.o spapr_vio.o spapr_events.o
obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o
diff --git a/hw/ppc/fw_cfg.c b/hw/ppc/fw_cfg.c
new file mode 100644
index 0000000000..a88b5c4bde
--- /dev/null
+++ b/hw/ppc/fw_cfg.c
@@ -0,0 +1,45 @@
+/*
+ * fw_cfg helpers (PPC specific)
+ *
+ * Copyright (c) 2019 Red Hat, Inc.
+ *
+ * Author:
+ * Philippe Mathieu-Daudé <philmd@redhat.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/ppc/ppc.h"
+#include "hw/nvram/fw_cfg.h"
+
+const char *fw_cfg_arch_key_name(uint16_t key)
+{
+ static const struct {
+ uint16_t key;
+ const char *name;
+ } fw_cfg_arch_wellknown_keys[] = {
+ {FW_CFG_PPC_WIDTH, "width"},
+ {FW_CFG_PPC_HEIGHT, "height"},
+ {FW_CFG_PPC_DEPTH, "depth"},
+ {FW_CFG_PPC_TBFREQ, "tbfreq"},
+ {FW_CFG_PPC_CLOCKFREQ, "clockfreq"},
+ {FW_CFG_PPC_IS_KVM, "is_kvm"},
+ {FW_CFG_PPC_KVM_HC, "kvm_hc"},
+ {FW_CFG_PPC_KVM_PID, "pid"},
+ {FW_CFG_PPC_NVRAM_ADDR, "nvram_addr"},
+ {FW_CFG_PPC_BUSFREQ, "busfreq"},
+ {FW_CFG_PPC_NVRAM_FLAT, "nvram_flat"},
+ {FW_CFG_PPC_VIACONFIG, "viaconfig"},
+ };
+
+ for (size_t i = 0; i < ARRAY_SIZE(fw_cfg_arch_wellknown_keys); i++) {
+ if (fw_cfg_arch_wellknown_keys[i].key == key) {
+ return fw_cfg_arch_wellknown_keys[i].name;
+ }
+ }
+ return NULL;
+}
diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index 07d126aea8..5151a7202b 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -97,6 +97,25 @@ struct sun4m_hwdef {
uint8_t nvram_machine_id;
};
+const char *fw_cfg_arch_key_name(uint16_t key)
+{
+ static const struct {
+ uint16_t key;
+ const char *name;
+ } fw_cfg_arch_wellknown_keys[] = {
+ {FW_CFG_SUN4M_DEPTH, "depth"},
+ {FW_CFG_SUN4M_WIDTH, "width"},
+ {FW_CFG_SUN4M_HEIGHT, "height"},
+ };
+
+ for (size_t i = 0; i < ARRAY_SIZE(fw_cfg_arch_wellknown_keys); i++) {
+ if (fw_cfg_arch_wellknown_keys[i].key == key) {
+ return fw_cfg_arch_wellknown_keys[i].name;
+ }
+ }
+ return NULL;
+}
+
static void fw_cfg_boot_set(void *opaque, const char *boot_device,
Error **errp)
{
diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c
index 399f2d73c8..4230b17b87 100644
--- a/hw/sparc64/sun4u.c
+++ b/hw/sparc64/sun4u.c
@@ -91,6 +91,25 @@ typedef struct EbusState {
#define TYPE_EBUS "ebus"
#define EBUS(obj) OBJECT_CHECK(EbusState, (obj), TYPE_EBUS)
+const char *fw_cfg_arch_key_name(uint16_t key)
+{
+ static const struct {
+ uint16_t key;
+ const char *name;
+ } fw_cfg_arch_wellknown_keys[] = {
+ {FW_CFG_SPARC64_WIDTH, "width"},
+ {FW_CFG_SPARC64_HEIGHT, "height"},
+ {FW_CFG_SPARC64_DEPTH, "depth"},
+ };
+
+ for (size_t i = 0; i < ARRAY_SIZE(fw_cfg_arch_wellknown_keys); i++) {
+ if (fw_cfg_arch_wellknown_keys[i].key == key) {
+ return fw_cfg_arch_wellknown_keys[i].name;
+ }
+ }
+ return NULL;
+}
+
static void fw_cfg_boot_set(void *opaque, const char *boot_device,
Error **errp)
{