aboutsummaryrefslogtreecommitdiff
path: root/hw/fw_cfg.c
diff options
context:
space:
mode:
Diffstat (limited to 'hw/fw_cfg.c')
-rw-r--r--hw/fw_cfg.c86
1 files changed, 35 insertions, 51 deletions
diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
index 7c9480c4d7..3b31d77f3f 100644
--- a/hw/fw_cfg.c
+++ b/hw/fw_cfg.c
@@ -26,19 +26,10 @@
#include "isa.h"
#include "fw_cfg.h"
#include "sysbus.h"
+#include "trace.h"
#include "qemu/error-report.h"
#include "qemu/config-file.h"
-/* debug firmware config */
-//#define DEBUG_FW_CFG
-
-#ifdef DEBUG_FW_CFG
-#define FW_CFG_DPRINTF(fmt, ...) \
- do { printf("FW_CFG: " fmt , ## __VA_ARGS__); } while (0)
-#else
-#define FW_CFG_DPRINTF(fmt, ...)
-#endif
-
#define FW_CFG_SIZE 2
#define FW_CFG_DATA_SIZE 1
@@ -213,7 +204,7 @@ static void fw_cfg_write(FWCfgState *s, uint8_t value)
int arch = !!(s->cur_entry & FW_CFG_ARCH_LOCAL);
FWCfgEntry *e = &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK];
- FW_CFG_DPRINTF("write %d\n", value);
+ trace_fw_cfg_write(s, value);
if (s->cur_entry & FW_CFG_WRITE_CHANNEL && e->callback &&
s->cur_offset < e->len) {
@@ -238,8 +229,7 @@ static int fw_cfg_select(FWCfgState *s, uint16_t key)
ret = 1;
}
- FW_CFG_DPRINTF("select key %d (%sfound)\n", key, ret ? "" : "not ");
-
+ trace_fw_cfg_select(s, key, ret);
return ret;
}
@@ -254,8 +244,7 @@ static uint8_t fw_cfg_read(FWCfgState *s)
else
ret = e->data[s->cur_offset++];
- FW_CFG_DPRINTF("read %d\n", ret);
-
+ trace_fw_cfg_read(s, ret);
return ret;
}
@@ -384,85 +373,83 @@ static const VMStateDescription vmstate_fw_cfg = {
}
};
-int fw_cfg_add_bytes(FWCfgState *s, uint16_t key, uint8_t *data, uint32_t len)
+void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len)
{
int arch = !!(key & FW_CFG_ARCH_LOCAL);
key &= FW_CFG_ENTRY_MASK;
- if (key >= FW_CFG_MAX_ENTRY)
- return 0;
+ assert(key < FW_CFG_MAX_ENTRY && len < UINT32_MAX);
s->entries[arch][key].data = data;
- s->entries[arch][key].len = len;
+ s->entries[arch][key].len = (uint32_t)len;
+}
- return 1;
+void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value)
+{
+ size_t sz = strlen(value) + 1;
+
+ return fw_cfg_add_bytes(s, key, g_memdup(value, sz), sz);
}
-int fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value)
+void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value)
{
uint16_t *copy;
copy = g_malloc(sizeof(value));
*copy = cpu_to_le16(value);
- return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value));
+ fw_cfg_add_bytes(s, key, copy, sizeof(value));
}
-int fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value)
+void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value)
{
uint32_t *copy;
copy = g_malloc(sizeof(value));
*copy = cpu_to_le32(value);
- return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value));
+ fw_cfg_add_bytes(s, key, copy, sizeof(value));
}
-int fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value)
+void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value)
{
uint64_t *copy;
copy = g_malloc(sizeof(value));
*copy = cpu_to_le64(value);
- return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value));
+ fw_cfg_add_bytes(s, key, copy, sizeof(value));
}
-int fw_cfg_add_callback(FWCfgState *s, uint16_t key, FWCfgCallback callback,
- void *callback_opaque, uint8_t *data, size_t len)
+void fw_cfg_add_callback(FWCfgState *s, uint16_t key, FWCfgCallback callback,
+ void *callback_opaque, void *data, size_t len)
{
int arch = !!(key & FW_CFG_ARCH_LOCAL);
- if (!(key & FW_CFG_WRITE_CHANNEL))
- return 0;
+ assert(key & FW_CFG_WRITE_CHANNEL);
key &= FW_CFG_ENTRY_MASK;
- if (key >= FW_CFG_MAX_ENTRY || len > 65535)
- return 0;
+ assert(key < FW_CFG_MAX_ENTRY && len <= UINT32_MAX);
s->entries[arch][key].data = data;
- s->entries[arch][key].len = len;
+ s->entries[arch][key].len = (uint32_t)len;
s->entries[arch][key].callback_opaque = callback_opaque;
s->entries[arch][key].callback = callback;
-
- return 1;
}
-int fw_cfg_add_file(FWCfgState *s, const char *filename, uint8_t *data,
- uint32_t len)
+void fw_cfg_add_file(FWCfgState *s, const char *filename,
+ void *data, size_t len)
{
int i, index;
+ size_t dsize;
if (!s->files) {
- int dsize = sizeof(uint32_t) + sizeof(FWCfgFile) * FW_CFG_FILE_SLOTS;
+ dsize = sizeof(uint32_t) + sizeof(FWCfgFile) * FW_CFG_FILE_SLOTS;
s->files = g_malloc0(dsize);
- fw_cfg_add_bytes(s, FW_CFG_FILE_DIR, (uint8_t*)s->files, dsize);
+ fw_cfg_add_bytes(s, FW_CFG_FILE_DIR, s->files, dsize);
}
index = be32_to_cpu(s->files->count);
- if (index == FW_CFG_FILE_SLOTS) {
- fprintf(stderr, "fw_cfg: out of file slots\n");
- return 0;
- }
+ assert(index < FW_CFG_FILE_SLOTS);
fw_cfg_add_bytes(s, FW_CFG_FILE_FIRST + index, data, len);
@@ -470,24 +457,21 @@ int fw_cfg_add_file(FWCfgState *s, const char *filename, uint8_t *data,
filename);
for (i = 0; i < index; i++) {
if (strcmp(s->files->f[index].name, s->files->f[i].name) == 0) {
- FW_CFG_DPRINTF("%s: skip duplicate: %s\n", __FUNCTION__,
- s->files->f[index].name);
- return 1;
+ trace_fw_cfg_add_file_dupe(s, s->files->f[index].name);
+ return;
}
}
s->files->f[index].size = cpu_to_be32(len);
s->files->f[index].select = cpu_to_be16(FW_CFG_FILE_FIRST + index);
- FW_CFG_DPRINTF("%s: #%d: %s (%d bytes)\n", __FUNCTION__,
- index, s->files->f[index].name, len);
+ trace_fw_cfg_add_file(s, index, s->files->f[index].name, len);
s->files->count = cpu_to_be32(index+1);
- return 1;
}
static void fw_cfg_machine_ready(struct Notifier *n, void *data)
{
- uint32_t len;
+ size_t len;
FWCfgState *s = container_of(n, FWCfgState, machine_ready);
char *bootindex = get_boot_devices_list(&len);
@@ -515,7 +499,7 @@ FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
if (data_addr) {
sysbus_mmio_map(d, 1, data_addr);
}
- fw_cfg_add_bytes(s, FW_CFG_SIGNATURE, (uint8_t *)"QEMU", 4);
+ fw_cfg_add_bytes(s, FW_CFG_SIGNATURE, (char *)"QEMU", 4);
fw_cfg_add_bytes(s, FW_CFG_UUID, qemu_uuid, 16);
fw_cfg_add_i16(s, FW_CFG_NOGRAPHIC, (uint16_t)(display_type == DT_NOGRAPHIC));
fw_cfg_add_i16(s, FW_CFG_NB_CPUS, (uint16_t)smp_cpus);