* [PULL 01/36] hw/rx/rx-gdbsim: Remove unnecessary uses of &first_cpu
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
@ 2025-01-31 21:04 ` Philippe Mathieu-Daudé
2025-01-31 21:04 ` [PULL 02/36] hw/mips/loongson3_virt: Factor generic_cpu_reset() out Philippe Mathieu-Daudé
` (35 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Richard Henderson
rx_gdbsim_init() has access to the single CPU via:
RxGdbSimMachineState {
RX62NState {
RXCPU cpu;
...
} mcu;
} s;
Directly use that instead of the &first_cpu global.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20250110180442.82687-1-philmd@linaro.org>
---
hw/rx/rx-gdbsim.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/hw/rx/rx-gdbsim.c b/hw/rx/rx-gdbsim.c
index 02fdbdf824b..88c8f12c101 100644
--- a/hw/rx/rx-gdbsim.c
+++ b/hw/rx/rx-gdbsim.c
@@ -127,7 +127,7 @@ static void rx_gdbsim_init(MachineState *machine)
* the latter half of the SDRAM space.
*/
kernel_offset = machine->ram_size / 2;
- rx_load_image(RX_CPU(first_cpu), kernel_filename,
+ rx_load_image(&s->mcu.cpu, kernel_filename,
SDRAM_BASE + kernel_offset, kernel_offset);
if (dtb_filename) {
ram_addr_t dtb_offset;
@@ -153,7 +153,7 @@ static void rx_gdbsim_init(MachineState *machine)
qemu_register_reset_nosnapshotload(qemu_fdt_randomize_seeds,
rom_ptr(SDRAM_BASE + dtb_offset, dtb_size));
/* Set dtb address to R1 */
- RX_CPU(first_cpu)->env.regs[1] = SDRAM_BASE + dtb_offset;
+ s->mcu.cpu.env.regs[1] = SDRAM_BASE + dtb_offset;
}
}
}
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 02/36] hw/mips/loongson3_virt: Factor generic_cpu_reset() out
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
2025-01-31 21:04 ` [PULL 01/36] hw/rx/rx-gdbsim: Remove unnecessary uses of &first_cpu Philippe Mathieu-Daudé
@ 2025-01-31 21:04 ` Philippe Mathieu-Daudé
2025-01-31 21:04 ` [PULL 03/36] hw/mips/loongson3_virt: Invert vCPU creation order to remove &first_cpu Philippe Mathieu-Daudé
` (34 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Richard Henderson
main_cpu_reset() is misleadingly named "main": it resets
all vCPUs, with a special case for the first vCPU.
Factor generic_cpu_reset() out of main_cpu_reset(),
allowing to remove one &first_cpu use.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20250115232952.31166-2-philmd@linaro.org>
---
hw/mips/loongson3_virt.c | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
index f3cc7a8376f..47d112981a2 100644
--- a/hw/mips/loongson3_virt.c
+++ b/hw/mips/loongson3_virt.c
@@ -399,25 +399,33 @@ static uint64_t load_kernel(CPUMIPSState *env)
return kernel_entry;
}
-static void main_cpu_reset(void *opaque)
+static void generic_cpu_reset(void *opaque)
{
MIPSCPU *cpu = opaque;
CPUMIPSState *env = &cpu->env;
cpu_reset(CPU(cpu));
- /* Loongson-3 reset stuff */
if (loaderparams.kernel_filename) {
- if (cpu == MIPS_CPU(first_cpu)) {
- env->active_tc.gpr[4] = loaderparams.a0;
- env->active_tc.gpr[5] = loaderparams.a1;
- env->active_tc.gpr[6] = loaderparams.a2;
- env->active_tc.PC = loaderparams.kernel_entry;
- }
env->CP0_Status &= ~((1 << CP0St_BEV) | (1 << CP0St_ERL));
}
}
+static void main_cpu_reset(void *opaque)
+{
+ generic_cpu_reset(opaque);
+
+ if (loaderparams.kernel_filename) {
+ MIPSCPU *cpu = opaque;
+ CPUMIPSState *env = &cpu->env;
+
+ env->active_tc.gpr[4] = loaderparams.a0;
+ env->active_tc.gpr[5] = loaderparams.a1;
+ env->active_tc.gpr[6] = loaderparams.a2;
+ env->active_tc.PC = loaderparams.kernel_entry;
+ }
+}
+
static inline void loongson3_virt_devices_init(MachineState *machine,
DeviceState *pic)
{
@@ -572,7 +580,7 @@ static void mips_loongson3_virt_init(MachineState *machine)
/* Init internal devices */
cpu_mips_irq_init_cpu(cpu);
cpu_mips_clock_init(cpu);
- qemu_register_reset(main_cpu_reset, cpu);
+ qemu_register_reset(i ? generic_cpu_reset : main_cpu_reset, cpu);
if (!kvm_enabled()) {
hwaddr base = ((hwaddr)node << 44) + virt_memmap[VIRT_IPI].base;
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 03/36] hw/mips/loongson3_virt: Invert vCPU creation order to remove &first_cpu
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
2025-01-31 21:04 ` [PULL 01/36] hw/rx/rx-gdbsim: Remove unnecessary uses of &first_cpu Philippe Mathieu-Daudé
2025-01-31 21:04 ` [PULL 02/36] hw/mips/loongson3_virt: Factor generic_cpu_reset() out Philippe Mathieu-Daudé
@ 2025-01-31 21:04 ` Philippe Mathieu-Daudé
2025-01-31 21:04 ` [PULL 04/36] hw/mips/loongson3_virt: Have fw_conf_init() access local loaderparams Philippe Mathieu-Daudé
` (33 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Richard Henderson
Create vCPUs from the last one to the first one.
No need to use the &first_cpu global since we already
have it referenced.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-Id: <20250115232952.31166-3-philmd@linaro.org>
---
hw/mips/loongson3_virt.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
index 47d112981a2..28d4eaf1e59 100644
--- a/hw/mips/loongson3_virt.c
+++ b/hw/mips/loongson3_virt.c
@@ -492,9 +492,8 @@ static void mips_loongson3_virt_init(MachineState *machine)
{
int i;
long bios_size;
- MIPSCPU *cpu;
+ MIPSCPU *cpu = NULL;
Clock *cpuclk;
- CPUMIPSState *env;
DeviceState *liointc;
DeviceState *ipi = NULL;
char *filename;
@@ -569,7 +568,7 @@ static void mips_loongson3_virt_init(MachineState *machine)
cpuclk = clock_new(OBJECT(machine), "cpu-refclk");
clock_set_hz(cpuclk, DEF_LOONGSON3_FREQ);
- for (i = 0; i < machine->smp.cpus; i++) {
+ for (i = machine->smp.cpus - 1; i >= 0; --i) {
int node = i / LOONGSON3_CORE_PER_NODE;
int core = i % LOONGSON3_CORE_PER_NODE;
int ip;
@@ -609,7 +608,7 @@ static void mips_loongson3_virt_init(MachineState *machine)
pin, cpu->env.irq[ip + 2]);
}
}
- env = &MIPS_CPU(first_cpu)->env;
+ assert(cpu); /* This variable points to the first created cpu. */
/* Allocate RAM/BIOS, 0x00000000~0x10000000 is alias of 0x80000000~0x90000000 */
memory_region_init_rom(bios, NULL, "loongson3.bios",
@@ -640,7 +639,7 @@ static void mips_loongson3_virt_init(MachineState *machine)
loaderparams.kernel_filename = kernel_filename;
loaderparams.kernel_cmdline = kernel_cmdline;
loaderparams.initrd_filename = initrd_filename;
- loaderparams.kernel_entry = load_kernel(env);
+ loaderparams.kernel_entry = load_kernel(&cpu->env);
init_boot_rom();
init_boot_param();
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 04/36] hw/mips/loongson3_virt: Have fw_conf_init() access local loaderparams
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (2 preceding siblings ...)
2025-01-31 21:04 ` [PULL 03/36] hw/mips/loongson3_virt: Invert vCPU creation order to remove &first_cpu Philippe Mathieu-Daudé
@ 2025-01-31 21:04 ` Philippe Mathieu-Daudé
2025-01-31 21:04 ` [PULL 05/36] hw/mips/loongson3_virt: Pass CPU argument to get_cpu_freq_hz() Philippe Mathieu-Daudé
` (32 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Richard Henderson
'loaderparams' is declared statically. Let fw_conf_init()
access its 'cpu_freq' and 'ram_size' fields.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20250115232952.31166-4-philmd@linaro.org>
---
hw/mips/loongson3_virt.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
index 28d4eaf1e59..45a524cca89 100644
--- a/hw/mips/loongson3_virt.c
+++ b/hw/mips/loongson3_virt.c
@@ -280,7 +280,7 @@ static void fw_cfg_boot_set(void *opaque, const char *boot_device,
fw_cfg_modify_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
}
-static void fw_conf_init(unsigned long ram_size)
+static void fw_conf_init(void)
{
static const uint8_t suspend[6] = {128, 0, 0, 129, 128, 128};
FWCfgState *fw_cfg;
@@ -289,9 +289,9 @@ static void fw_conf_init(unsigned long ram_size)
fw_cfg = fw_cfg_init_mem_wide(cfg_addr, cfg_addr + 8, 8, 0, NULL);
fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, (uint16_t)current_machine->smp.cpus);
fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)current_machine->smp.max_cpus);
- fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+ fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, loaderparams.ram_size);
fw_cfg_add_i32(fw_cfg, FW_CFG_MACHINE_VERSION, 1);
- fw_cfg_add_i64(fw_cfg, FW_CFG_CPU_FREQ, get_cpu_freq_hz());
+ fw_cfg_add_i64(fw_cfg, FW_CFG_CPU_FREQ, loaderparams.cpu_freq);
fw_cfg_add_file(fw_cfg, "etc/system-states",
g_memdup2(suspend, sizeof(suspend)), sizeof(suspend));
@@ -633,9 +633,9 @@ static void mips_loongson3_virt_init(MachineState *machine)
* Please use -L to set the BIOS path and -bios to set bios name.
*/
+ loaderparams.cpu_freq = get_cpu_freq_hz();
+ loaderparams.ram_size = ram_size;
if (kernel_filename) {
- loaderparams.cpu_freq = get_cpu_freq_hz();
- loaderparams.ram_size = ram_size;
loaderparams.kernel_filename = kernel_filename;
loaderparams.kernel_cmdline = kernel_cmdline;
loaderparams.initrd_filename = initrd_filename;
@@ -661,7 +661,7 @@ static void mips_loongson3_virt_init(MachineState *machine)
exit(1);
}
- fw_conf_init(ram_size);
+ fw_conf_init();
}
loongson3_virt_devices_init(machine, liointc);
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 05/36] hw/mips/loongson3_virt: Pass CPU argument to get_cpu_freq_hz()
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (3 preceding siblings ...)
2025-01-31 21:04 ` [PULL 04/36] hw/mips/loongson3_virt: Have fw_conf_init() access local loaderparams Philippe Mathieu-Daudé
@ 2025-01-31 21:04 ` Philippe Mathieu-Daudé
2025-01-31 21:04 ` [PULL 06/36] hw/mips/loongson3_bootp: Include missing headers Philippe Mathieu-Daudé
` (31 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Richard Henderson
Pass the first vCPU as argument, allowing to remove
another &first_cpu global use.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20250115232952.31166-5-philmd@linaro.org>
---
hw/mips/loongson3_virt.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
index 45a524cca89..9f6fdd0f287 100644
--- a/hw/mips/loongson3_virt.c
+++ b/hw/mips/loongson3_virt.c
@@ -153,7 +153,7 @@ static const MemoryRegionOps loongson3_pm_ops = {
#define DEF_LOONGSON3_FREQ (800 * 1000 * 1000)
-static uint64_t get_cpu_freq_hz(void)
+static uint64_t get_cpu_freq_hz(const MIPSCPU *cpu)
{
#ifdef CONFIG_KVM
int ret;
@@ -164,7 +164,7 @@ static uint64_t get_cpu_freq_hz(void)
};
if (kvm_enabled()) {
- ret = kvm_vcpu_ioctl(first_cpu, KVM_GET_ONE_REG, &freq_reg);
+ ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_ONE_REG, &freq_reg);
if (ret >= 0) {
return freq * 2;
}
@@ -633,7 +633,7 @@ static void mips_loongson3_virt_init(MachineState *machine)
* Please use -L to set the BIOS path and -bios to set bios name.
*/
- loaderparams.cpu_freq = get_cpu_freq_hz();
+ loaderparams.cpu_freq = get_cpu_freq_hz(cpu);
loaderparams.ram_size = ram_size;
if (kernel_filename) {
loaderparams.kernel_filename = kernel_filename;
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 06/36] hw/mips/loongson3_bootp: Include missing headers
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (4 preceding siblings ...)
2025-01-31 21:04 ` [PULL 05/36] hw/mips/loongson3_virt: Pass CPU argument to get_cpu_freq_hz() Philippe Mathieu-Daudé
@ 2025-01-31 21:04 ` Philippe Mathieu-Daudé
2025-01-31 21:04 ` [PULL 07/36] hw/mips/loongson3: Propagate cpu_count to init_loongson_params() Philippe Mathieu-Daudé
` (30 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Richard Henderson
MemMapEntry is declared in "exec/hwaddr.h", cpu_to_le32() in
"qemu/bswap.h". These headers are indirectly included via "cpu.h".
Include them explicitly in order to avoid when removing "cpu.h":
In file included from ../../hw/mips/loongson3_bootp.c:27:
hw/mips/loongson3_bootp.h:234:14: error: unknown type name 'MemMapEntry'
234 | extern const MemMapEntry virt_memmap[];
| ^
hw/mips/loongson3_bootp.c:33:18: error: call to undeclared function 'cpu_to_le32'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
33 | c->cputype = cpu_to_le32(Loongson_3A);
| ^
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20250115232952.31166-6-philmd@linaro.org>
---
hw/mips/loongson3_bootp.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/hw/mips/loongson3_bootp.c b/hw/mips/loongson3_bootp.c
index b97b81903b7..712439c2575 100644
--- a/hw/mips/loongson3_bootp.c
+++ b/hw/mips/loongson3_bootp.c
@@ -21,6 +21,8 @@
#include "qemu/osdep.h"
#include "qemu/units.h"
#include "qemu/cutils.h"
+#include "qemu/bswap.h"
+#include "exec/hwaddr.h"
#include "cpu.h"
#include "hw/boards.h"
#include "hw/mips/loongson3_bootp.h"
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 07/36] hw/mips/loongson3: Propagate cpu_count to init_loongson_params()
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (5 preceding siblings ...)
2025-01-31 21:04 ` [PULL 06/36] hw/mips/loongson3_bootp: Include missing headers Philippe Mathieu-Daudé
@ 2025-01-31 21:04 ` Philippe Mathieu-Daudé
2025-01-31 21:04 ` [PULL 08/36] hw/mips/loongson3_virt: Propagate cpu_count to init_boot_param() Philippe Mathieu-Daudé
` (29 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Richard Henderson
Propagate the %cpu_count from the machine file, allowing
to remove the "hw/boards.h" dependency (which is machine
specific) from loongson3_bootp.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20250115232952.31166-7-philmd@linaro.org>
---
hw/mips/loongson3_bootp.h | 1 +
hw/mips/loongson3_bootp.c | 11 ++++++-----
hw/mips/loongson3_virt.c | 1 +
3 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/hw/mips/loongson3_bootp.h b/hw/mips/loongson3_bootp.h
index 9091265df7f..ee6340e42c1 100644
--- a/hw/mips/loongson3_bootp.h
+++ b/hw/mips/loongson3_bootp.h
@@ -233,6 +233,7 @@ enum {
extern const MemMapEntry virt_memmap[];
void init_loongson_params(struct loongson_params *lp, void *p,
+ uint32_t cpu_count,
uint64_t cpu_freq, uint64_t ram_size);
void init_reset_system(struct efi_reset_system_t *reset);
diff --git a/hw/mips/loongson3_bootp.c b/hw/mips/loongson3_bootp.c
index 712439c2575..91b58a71a68 100644
--- a/hw/mips/loongson3_bootp.c
+++ b/hw/mips/loongson3_bootp.c
@@ -24,10 +24,10 @@
#include "qemu/bswap.h"
#include "exec/hwaddr.h"
#include "cpu.h"
-#include "hw/boards.h"
#include "hw/mips/loongson3_bootp.h"
-static void init_cpu_info(void *g_cpuinfo, uint64_t cpu_freq)
+static void init_cpu_info(void *g_cpuinfo, uint32_t cpu_count,
+ uint64_t cpu_freq)
{
struct efi_cpuinfo_loongson *c = g_cpuinfo;
@@ -40,8 +40,8 @@ static void init_cpu_info(void *g_cpuinfo, uint64_t cpu_freq)
}
c->cpu_startup_core_id = cpu_to_le16(0);
- c->nr_cpus = cpu_to_le32(current_machine->smp.cpus);
- c->total_node = cpu_to_le32(DIV_ROUND_UP(current_machine->smp.cpus,
+ c->nr_cpus = cpu_to_le32(cpu_count);
+ c->total_node = cpu_to_le32(DIV_ROUND_UP(cpu_count,
LOONGSON3_CORE_PER_NODE));
}
@@ -112,9 +112,10 @@ static void init_special_info(void *g_special)
}
void init_loongson_params(struct loongson_params *lp, void *p,
+ uint32_t cpu_count,
uint64_t cpu_freq, uint64_t ram_size)
{
- init_cpu_info(p, cpu_freq);
+ init_cpu_info(p, cpu_count, cpu_freq);
lp->cpu_offset = cpu_to_le64((uintptr_t)p - (uintptr_t)lp);
p += ROUND_UP(sizeof(struct efi_cpuinfo_loongson), 64);
diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
index 9f6fdd0f287..eb2a6a248d8 100644
--- a/hw/mips/loongson3_virt.c
+++ b/hw/mips/loongson3_virt.c
@@ -185,6 +185,7 @@ static void init_boot_param(void)
init_reset_system(&(bp->reset_system));
p += ROUND_UP(sizeof(struct boot_params), 64);
init_loongson_params(&(bp->efi.smbios.lp), p,
+ current_machine->smp.cpus,
loaderparams.cpu_freq, loaderparams.ram_size);
rom_add_blob_fixed("params_rom", bp,
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 08/36] hw/mips/loongson3_virt: Propagate cpu_count to init_boot_param()
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (6 preceding siblings ...)
2025-01-31 21:04 ` [PULL 07/36] hw/mips/loongson3: Propagate cpu_count to init_loongson_params() Philippe Mathieu-Daudé
@ 2025-01-31 21:04 ` Philippe Mathieu-Daudé
2025-01-31 21:04 ` [PULL 09/36] hw/mips/loongson3_bootp: Propagate processor_id to init_cpu_info() Philippe Mathieu-Daudé
` (28 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Richard Henderson
Remove one use of the 'current_machine' global.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20250115232952.31166-8-philmd@linaro.org>
---
hw/mips/loongson3_virt.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
index eb2a6a248d8..5fe5bc6fc03 100644
--- a/hw/mips/loongson3_virt.c
+++ b/hw/mips/loongson3_virt.c
@@ -173,7 +173,7 @@ static uint64_t get_cpu_freq_hz(const MIPSCPU *cpu)
return DEF_LOONGSON3_FREQ;
}
-static void init_boot_param(void)
+static void init_boot_param(unsigned cpu_count)
{
static void *p;
struct boot_params *bp;
@@ -184,8 +184,7 @@ static void init_boot_param(void)
bp->efi.smbios.vers = cpu_to_le16(1);
init_reset_system(&(bp->reset_system));
p += ROUND_UP(sizeof(struct boot_params), 64);
- init_loongson_params(&(bp->efi.smbios.lp), p,
- current_machine->smp.cpus,
+ init_loongson_params(&(bp->efi.smbios.lp), p, cpu_count,
loaderparams.cpu_freq, loaderparams.ram_size);
rom_add_blob_fixed("params_rom", bp,
@@ -643,7 +642,7 @@ static void mips_loongson3_virt_init(MachineState *machine)
loaderparams.kernel_entry = load_kernel(&cpu->env);
init_boot_rom();
- init_boot_param();
+ init_boot_param(machine->smp.cpus);
} else {
filename = qemu_find_file(QEMU_FILE_TYPE_BIOS,
machine->firmware ?: LOONGSON3_BIOSNAME);
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 09/36] hw/mips/loongson3_bootp: Propagate processor_id to init_cpu_info()
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (7 preceding siblings ...)
2025-01-31 21:04 ` [PULL 08/36] hw/mips/loongson3_virt: Propagate cpu_count to init_boot_param() Philippe Mathieu-Daudé
@ 2025-01-31 21:04 ` Philippe Mathieu-Daudé
2025-01-31 21:04 ` [PULL 10/36] hw/mips/loongson3_virt: Propagate processor_id to init_loongson_params() Philippe Mathieu-Daudé
` (27 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Richard Henderson
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20250115232952.31166-9-philmd@linaro.org>
---
hw/mips/loongson3_bootp.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/hw/mips/loongson3_bootp.c b/hw/mips/loongson3_bootp.c
index 91b58a71a68..1aab26df69e 100644
--- a/hw/mips/loongson3_bootp.c
+++ b/hw/mips/loongson3_bootp.c
@@ -27,12 +27,12 @@
#include "hw/mips/loongson3_bootp.h"
static void init_cpu_info(void *g_cpuinfo, uint32_t cpu_count,
- uint64_t cpu_freq)
+ uint32_t processor_id, uint64_t cpu_freq)
{
struct efi_cpuinfo_loongson *c = g_cpuinfo;
c->cputype = cpu_to_le32(Loongson_3A);
- c->processor_id = cpu_to_le32(MIPS_CPU(first_cpu)->env.CP0_PRid);
+ c->processor_id = cpu_to_le32(processor_id);
if (cpu_freq > UINT_MAX) {
c->cpu_clock_freq = cpu_to_le32(UINT_MAX);
} else {
@@ -115,7 +115,7 @@ void init_loongson_params(struct loongson_params *lp, void *p,
uint32_t cpu_count,
uint64_t cpu_freq, uint64_t ram_size)
{
- init_cpu_info(p, cpu_count, cpu_freq);
+ init_cpu_info(p, MIPS_CPU(first_cpu)->env.CP0_PRid, cpu_count, cpu_freq);
lp->cpu_offset = cpu_to_le64((uintptr_t)p - (uintptr_t)lp);
p += ROUND_UP(sizeof(struct efi_cpuinfo_loongson), 64);
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 10/36] hw/mips/loongson3_virt: Propagate processor_id to init_loongson_params()
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (8 preceding siblings ...)
2025-01-31 21:04 ` [PULL 09/36] hw/mips/loongson3_bootp: Propagate processor_id to init_cpu_info() Philippe Mathieu-Daudé
@ 2025-01-31 21:04 ` Philippe Mathieu-Daudé
2025-01-31 21:04 ` [PULL 11/36] hw/mips/loongson3_virt: Propagate %processor_id to init_boot_param() Philippe Mathieu-Daudé
` (26 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Richard Henderson
Remove one &first_cpu use in hw/mips/loongson3_bootp.c.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20250115232952.31166-10-philmd@linaro.org>
---
hw/mips/loongson3_bootp.h | 2 +-
hw/mips/loongson3_bootp.c | 5 ++---
hw/mips/loongson3_virt.c | 1 +
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/hw/mips/loongson3_bootp.h b/hw/mips/loongson3_bootp.h
index ee6340e42c1..9dc325a8557 100644
--- a/hw/mips/loongson3_bootp.h
+++ b/hw/mips/loongson3_bootp.h
@@ -233,7 +233,7 @@ enum {
extern const MemMapEntry virt_memmap[];
void init_loongson_params(struct loongson_params *lp, void *p,
- uint32_t cpu_count,
+ uint32_t cpu_count, uint32_t processor_id,
uint64_t cpu_freq, uint64_t ram_size);
void init_reset_system(struct efi_reset_system_t *reset);
diff --git a/hw/mips/loongson3_bootp.c b/hw/mips/loongson3_bootp.c
index 1aab26df69e..67812666c5b 100644
--- a/hw/mips/loongson3_bootp.c
+++ b/hw/mips/loongson3_bootp.c
@@ -23,7 +23,6 @@
#include "qemu/cutils.h"
#include "qemu/bswap.h"
#include "exec/hwaddr.h"
-#include "cpu.h"
#include "hw/mips/loongson3_bootp.h"
static void init_cpu_info(void *g_cpuinfo, uint32_t cpu_count,
@@ -112,10 +111,10 @@ static void init_special_info(void *g_special)
}
void init_loongson_params(struct loongson_params *lp, void *p,
- uint32_t cpu_count,
+ uint32_t cpu_count, uint32_t processor_id,
uint64_t cpu_freq, uint64_t ram_size)
{
- init_cpu_info(p, MIPS_CPU(first_cpu)->env.CP0_PRid, cpu_count, cpu_freq);
+ init_cpu_info(p, cpu_count, processor_id, cpu_freq);
lp->cpu_offset = cpu_to_le64((uintptr_t)p - (uintptr_t)lp);
p += ROUND_UP(sizeof(struct efi_cpuinfo_loongson), 64);
diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
index 5fe5bc6fc03..ee71fe9e9b5 100644
--- a/hw/mips/loongson3_virt.c
+++ b/hw/mips/loongson3_virt.c
@@ -185,6 +185,7 @@ static void init_boot_param(unsigned cpu_count)
init_reset_system(&(bp->reset_system));
p += ROUND_UP(sizeof(struct boot_params), 64);
init_loongson_params(&(bp->efi.smbios.lp), p, cpu_count,
+ MIPS_CPU(first_cpu)->env.CP0_PRid,
loaderparams.cpu_freq, loaderparams.ram_size);
rom_add_blob_fixed("params_rom", bp,
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 11/36] hw/mips/loongson3_virt: Propagate %processor_id to init_boot_param()
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (9 preceding siblings ...)
2025-01-31 21:04 ` [PULL 10/36] hw/mips/loongson3_virt: Propagate processor_id to init_loongson_params() Philippe Mathieu-Daudé
@ 2025-01-31 21:04 ` Philippe Mathieu-Daudé
2025-01-31 21:04 ` [PULL 12/36] hw/mips/loongson3_bootp: Move to common_ss[] Philippe Mathieu-Daudé
` (25 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Richard Henderson
Propagate %processor_id from mips_loongson3_virt_init() where
we have a reference to the first vCPU, so use it instead of
the &first_cpu global.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20250115232952.31166-11-philmd@linaro.org>
---
hw/mips/loongson3_virt.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
index ee71fe9e9b5..85cf1f707fa 100644
--- a/hw/mips/loongson3_virt.c
+++ b/hw/mips/loongson3_virt.c
@@ -173,7 +173,7 @@ static uint64_t get_cpu_freq_hz(const MIPSCPU *cpu)
return DEF_LOONGSON3_FREQ;
}
-static void init_boot_param(unsigned cpu_count)
+static void init_boot_param(unsigned cpu_count, uint32_t processor_id)
{
static void *p;
struct boot_params *bp;
@@ -184,8 +184,7 @@ static void init_boot_param(unsigned cpu_count)
bp->efi.smbios.vers = cpu_to_le16(1);
init_reset_system(&(bp->reset_system));
p += ROUND_UP(sizeof(struct boot_params), 64);
- init_loongson_params(&(bp->efi.smbios.lp), p, cpu_count,
- MIPS_CPU(first_cpu)->env.CP0_PRid,
+ init_loongson_params(&(bp->efi.smbios.lp), p, cpu_count, processor_id,
loaderparams.cpu_freq, loaderparams.ram_size);
rom_add_blob_fixed("params_rom", bp,
@@ -643,7 +642,7 @@ static void mips_loongson3_virt_init(MachineState *machine)
loaderparams.kernel_entry = load_kernel(&cpu->env);
init_boot_rom();
- init_boot_param(machine->smp.cpus);
+ init_boot_param(machine->smp.cpus, cpu->env.CP0_PRid);
} else {
filename = qemu_find_file(QEMU_FILE_TYPE_BIOS,
machine->firmware ?: LOONGSON3_BIOSNAME);
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 12/36] hw/mips/loongson3_bootp: Move to common_ss[]
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (10 preceding siblings ...)
2025-01-31 21:04 ` [PULL 11/36] hw/mips/loongson3_virt: Propagate %processor_id to init_boot_param() Philippe Mathieu-Daudé
@ 2025-01-31 21:04 ` Philippe Mathieu-Daudé
2025-01-31 21:04 ` [PULL 13/36] hw/irq: Introduce qemu_init_irqs() helper Philippe Mathieu-Daudé
` (24 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Richard Henderson
loongson3_bootp.c doesn't contain any target-specific code
and can be build generically, move it to common_ss[].
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20250115232952.31166-12-philmd@linaro.org>
---
hw/mips/meson.build | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/hw/mips/meson.build b/hw/mips/meson.build
index fcbee53bb32..31dbd2bf4d9 100644
--- a/hw/mips/meson.build
+++ b/hw/mips/meson.build
@@ -1,7 +1,8 @@
mips_ss = ss.source_set()
mips_ss.add(files('bootloader.c', 'mips_int.c'))
common_ss.add(when: 'CONFIG_FW_CFG_MIPS', if_true: files('fw_cfg.c'))
-mips_ss.add(when: 'CONFIG_LOONGSON3V', if_true: files('loongson3_bootp.c', 'loongson3_virt.c'))
+common_ss.add(when: 'CONFIG_LOONGSON3V', if_true: files('loongson3_bootp.c'))
+mips_ss.add(when: 'CONFIG_LOONGSON3V', if_true: files('loongson3_virt.c'))
mips_ss.add(when: 'CONFIG_MALTA', if_true: files('malta.c'))
mips_ss.add(when: 'CONFIG_MIPS_CPS', if_true: files('cps.c'))
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 13/36] hw/irq: Introduce qemu_init_irqs() helper
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (11 preceding siblings ...)
2025-01-31 21:04 ` [PULL 12/36] hw/mips/loongson3_bootp: Move to common_ss[] Philippe Mathieu-Daudé
@ 2025-01-31 21:04 ` Philippe Mathieu-Daudé
2025-01-31 21:04 ` [PULL 14/36] hw/ipack: Clarify KConfig symbols Philippe Mathieu-Daudé
` (23 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:04 UTC (permalink / raw)
To: qemu-devel
Cc: Philippe Mathieu-Daudé, Bernhard Beschow, Richard Henderson
While qemu_init_irq() initialize a single IRQ,
qemu_init_irqs() initialize an array of them.
Suggested-by: Bernhard Beschow <shentey@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20250121155526.29982-2-philmd@linaro.org>
---
include/hw/irq.h | 11 +++++++++++
hw/core/irq.c | 8 ++++++++
2 files changed, 19 insertions(+)
diff --git a/include/hw/irq.h b/include/hw/irq.h
index c861c1debda..b3012237acd 100644
--- a/include/hw/irq.h
+++ b/include/hw/irq.h
@@ -41,6 +41,17 @@ static inline void qemu_irq_pulse(qemu_irq irq)
void qemu_init_irq(IRQState *irq, qemu_irq_handler handler, void *opaque,
int n);
+/**
+ * qemu_init_irqs: Initialize an array of IRQs.
+ *
+ * @irq: Array of IRQs to initialize
+ * @count: number of IRQs to initialize
+ * @handler: handler to assign to each IRQ
+ * @opaque: opaque data to pass to @handler
+ */
+void qemu_init_irqs(IRQState irq[], size_t count,
+ qemu_irq_handler handler, void *opaque);
+
/* Returns an array of N IRQs. Each IRQ is assigned the argument handler and
* opaque data.
*/
diff --git a/hw/core/irq.c b/hw/core/irq.c
index 7d5b0038c12..6dd8d47bd6e 100644
--- a/hw/core/irq.c
+++ b/hw/core/irq.c
@@ -49,6 +49,14 @@ void qemu_init_irq(IRQState *irq, qemu_irq_handler handler, void *opaque,
init_irq_fields(irq, handler, opaque, n);
}
+void qemu_init_irqs(IRQState irq[], size_t count,
+ qemu_irq_handler handler, void *opaque)
+{
+ for (size_t i = 0; i < count; i++) {
+ qemu_init_irq(&irq[i], handler, opaque, i);
+ }
+}
+
qemu_irq *qemu_extend_irqs(qemu_irq *old, int n_old, qemu_irq_handler handler,
void *opaque, int n)
{
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 14/36] hw/ipack: Clarify KConfig symbols
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (12 preceding siblings ...)
2025-01-31 21:04 ` [PULL 13/36] hw/irq: Introduce qemu_init_irqs() helper Philippe Mathieu-Daudé
@ 2025-01-31 21:04 ` Philippe Mathieu-Daudé
2025-01-31 21:04 ` [PULL 15/36] hw/ipack: Remove legacy qemu_allocate_irqs() use Philippe Mathieu-Daudé
` (22 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Fabiano Rosas
Split IPACK Kconfig key as {IPACK, TPCI200, IP_OCTAL_232}
- IPack is a bus
- TPCI200 is a PCI device providing an IPack bus
- IP-Octal232 is an IPack device plugged on an IPack bus
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Acked-by: Fabiano Rosas <farosas@suse.de>
Message-Id: <20250121155526.29982-3-philmd@linaro.org>
---
hw/char/Kconfig | 5 +++++
hw/char/meson.build | 2 +-
hw/ipack/Kconfig | 4 ++++
hw/ipack/meson.build | 3 ++-
tests/qtest/libqos/meson.build | 4 +++-
tests/qtest/meson.build | 4 +++-
6 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/hw/char/Kconfig b/hw/char/Kconfig
index 4b73a803bf3..1dc20ee4c2c 100644
--- a/hw/char/Kconfig
+++ b/hw/char/Kconfig
@@ -78,3 +78,8 @@ config GOLDFISH_TTY
config SHAKTI_UART
bool
+
+config IP_OCTAL_232
+ bool
+ default y
+ depends on IPACK
diff --git a/hw/char/meson.build b/hw/char/meson.build
index 1750834385a..ed3529cbbb7 100644
--- a/hw/char/meson.build
+++ b/hw/char/meson.build
@@ -4,7 +4,7 @@ system_ss.add(when: 'CONFIG_ESCC', if_true: files('escc.c'))
system_ss.add(when: 'CONFIG_GRLIB', if_true: files('grlib_apbuart.c'))
system_ss.add(when: 'CONFIG_IBEX', if_true: files('ibex_uart.c'))
system_ss.add(when: 'CONFIG_IMX', if_true: files('imx_serial.c'))
-system_ss.add(when: 'CONFIG_IPACK', if_true: files('ipoctal232.c'))
+system_ss.add(when: 'CONFIG_IP_OCTAL_232', if_true: files('ipoctal232.c'))
system_ss.add(when: 'CONFIG_ISA_BUS', if_true: files('parallel-isa.c'))
system_ss.add(when: 'CONFIG_ISA_DEBUG', if_true: files('debugcon.c'))
system_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_uart.c'))
diff --git a/hw/ipack/Kconfig b/hw/ipack/Kconfig
index f8da24a62be..28d668727c8 100644
--- a/hw/ipack/Kconfig
+++ b/hw/ipack/Kconfig
@@ -1,4 +1,8 @@
config IPACK
bool
+
+config TPCI200
+ bool
+ select IPACK
default y if PCI_DEVICES
depends on PCI
diff --git a/hw/ipack/meson.build b/hw/ipack/meson.build
index 26567f1068e..e4805228926 100644
--- a/hw/ipack/meson.build
+++ b/hw/ipack/meson.build
@@ -1 +1,2 @@
-system_ss.add(when: 'CONFIG_IPACK', if_true: files('ipack.c', 'tpci200.c'))
+system_ss.add(when: 'CONFIG_IPACK', if_true: files('ipack.c'))
+system_ss.add(when: 'CONFIG_TPCI200', if_true: files('tpci200.c'))
diff --git a/tests/qtest/libqos/meson.build b/tests/qtest/libqos/meson.build
index 46f130ccfdb..1ddaf7b095b 100644
--- a/tests/qtest/libqos/meson.build
+++ b/tests/qtest/libqos/meson.build
@@ -32,7 +32,6 @@ libqos_srcs = files(
'i2c-omap.c',
'igb.c',
'sdhci.c',
- 'tpci200.c',
'virtio.c',
'virtio-balloon.c',
'virtio-blk.c',
@@ -70,6 +69,9 @@ endif
if config_all_devices.has_key('CONFIG_RISCV_IOMMU')
libqos_srcs += files('riscv-iommu.c')
endif
+if config_all_devices.has_key('CONFIG_TPCI200')
+ libqos_srcs += files('tpci200.c')
+endif
libqos = static_library('qos', libqos_srcs + genh,
build_by_default: false)
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index 94b28e5a534..e60e92fe9de 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -286,7 +286,6 @@ qos_test_ss.add(
'e1000-test.c',
'eepro100-test.c',
'es1370-test.c',
- 'ipoctal232-test.c',
'lsm303dlhc-mag-test.c',
'isl_pmbus_vr-test.c',
'max34451-test.c',
@@ -317,6 +316,9 @@ qos_test_ss.add(
if config_all_devices.has_key('CONFIG_VIRTIO_SERIAL')
qos_test_ss.add(files('virtio-serial-test.c'))
endif
+if config_all_devices.has_key('CONFIG_IP_OCTAL_232')
+ qos_test_ss.add(files('ipoctal232-test.c'))
+endif
if host_os != 'windows'
qos_test_ss.add(files('e1000e-test.c'))
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 15/36] hw/ipack: Remove legacy qemu_allocate_irqs() use
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (13 preceding siblings ...)
2025-01-31 21:04 ` [PULL 14/36] hw/ipack: Clarify KConfig symbols Philippe Mathieu-Daudé
@ 2025-01-31 21:04 ` Philippe Mathieu-Daudé
2025-01-31 21:04 ` [PULL 16/36] hw/sh4/r2d: Convert legacy qemu_allocate_irqs() to qemu_init_irqs() Philippe Mathieu-Daudé
` (21 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Richard Henderson
No need to dynamically allocate IRQ when we know before hands
how many we'll use. Declare the 2 of them in IPackDevice state
and initialize them in the DeviceRealize handler.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20250121155526.29982-4-philmd@linaro.org>
---
include/hw/ipack/ipack.h | 7 ++-----
hw/char/ipoctal232.c | 4 ++--
hw/ipack/ipack.c | 5 +----
hw/ipack/tpci200.c | 6 +++---
4 files changed, 8 insertions(+), 14 deletions(-)
diff --git a/include/hw/ipack/ipack.h b/include/hw/ipack/ipack.h
index cbcdda509d3..00f397fd020 100644
--- a/include/hw/ipack/ipack.h
+++ b/include/hw/ipack/ipack.h
@@ -12,6 +12,7 @@
#define QEMU_IPACK_H
#include "hw/qdev-core.h"
+#include "hw/irq.h"
#include "qom/object.h"
@@ -19,10 +20,8 @@
OBJECT_DECLARE_SIMPLE_TYPE(IPackBus, IPACK_BUS)
struct IPackBus {
- /*< private >*/
BusState parent_obj;
- /* All fields are private */
uint8_t n_slots;
uint8_t free_slot;
qemu_irq_handler set_irq;
@@ -58,13 +57,11 @@ struct IPackDeviceClass {
};
struct IPackDevice {
- /*< private >*/
DeviceState parent_obj;
- /*< public >*/
int32_t slot;
/* IRQ objects for the IndustryPack INT0# and INT1# */
- qemu_irq *irq;
+ IRQState irq[2];
};
extern const VMStateDescription vmstate_ipack_device;
diff --git a/hw/char/ipoctal232.c b/hw/char/ipoctal232.c
index d1e5f6dad2e..a2879977fb3 100644
--- a/hw/char/ipoctal232.c
+++ b/hw/char/ipoctal232.c
@@ -184,9 +184,9 @@ static void update_irq(IPOctalState *dev, unsigned block)
unsigned intno = block / 2;
if ((blk0->isr & blk0->imr) || (blk1->isr & blk1->imr)) {
- qemu_irq_raise(idev->irq[intno]);
+ qemu_irq_raise(&idev->irq[intno]);
} else {
- qemu_irq_lower(idev->irq[intno]);
+ qemu_irq_lower(&idev->irq[intno]);
}
}
diff --git a/hw/ipack/ipack.c b/hw/ipack/ipack.c
index ed75f791832..b6defae6025 100644
--- a/hw/ipack/ipack.c
+++ b/hw/ipack/ipack.c
@@ -55,22 +55,19 @@ static void ipack_device_realize(DeviceState *dev, Error **errp)
}
bus->free_slot = idev->slot + 1;
- idev->irq = qemu_allocate_irqs(bus->set_irq, idev, 2);
+ qemu_init_irqs(idev->irq, ARRAY_SIZE(idev->irq), bus->set_irq, idev);
k->realize(dev, errp);
}
static void ipack_device_unrealize(DeviceState *dev)
{
- IPackDevice *idev = IPACK_DEVICE(dev);
IPackDeviceClass *k = IPACK_DEVICE_GET_CLASS(dev);
if (k->unrealize) {
k->unrealize(dev);
return;
}
-
- qemu_free_irqs(idev->irq, 2);
}
static const Property ipack_device_props[] = {
diff --git a/hw/ipack/tpci200.c b/hw/ipack/tpci200.c
index 88eef4b8308..470a4203ae4 100644
--- a/hw/ipack/tpci200.c
+++ b/hw/ipack/tpci200.c
@@ -275,11 +275,11 @@ static void tpci200_write_las0(void *opaque, hwaddr addr, uint64_t val,
if (ip != NULL) {
if (val & STATUS_INT(i, 0)) {
DPRINTF("Clear IP %c INT0# status\n", 'A' + i);
- qemu_irq_lower(ip->irq[0]);
+ qemu_irq_lower(&ip->irq[0]);
}
if (val & STATUS_INT(i, 1)) {
DPRINTF("Clear IP %c INT1# status\n", 'A' + i);
- qemu_irq_lower(ip->irq[1]);
+ qemu_irq_lower(&ip->irq[1]);
}
}
@@ -344,7 +344,7 @@ static uint64_t tpci200_read_las1(void *opaque, hwaddr addr, unsigned size)
bool int_set = s->status & STATUS_INT(ip_n, intno);
bool int_edge_sensitive = s->ctrl[ip_n] & CTRL_INT_EDGE(intno);
if (int_set && !int_edge_sensitive) {
- qemu_irq_lower(ip->irq[intno]);
+ qemu_irq_lower(&ip->irq[intno]);
}
}
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 16/36] hw/sh4/r2d: Convert legacy qemu_allocate_irqs() to qemu_init_irqs()
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (14 preceding siblings ...)
2025-01-31 21:04 ` [PULL 15/36] hw/ipack: Remove legacy qemu_allocate_irqs() use Philippe Mathieu-Daudé
@ 2025-01-31 21:04 ` Philippe Mathieu-Daudé
2025-01-31 21:05 ` [PULL 17/36] hw/char/pci-multi: Convert legacy qemu_allocate_irqs to qemu_init_irq Philippe Mathieu-Daudé
` (20 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Richard Henderson
The FPGA exposes a fixed set of IRQs. Hold them in the FPGA
state and initialize them in place calling qemu_init_irqs().
Move r2d_fpga_irq enums earlier so we can use NR_IRQS within
the r2d_fpga_t structure. r2d_fpga_init() returns r2d_fpga_t,
and we dereference irq from it in r2d_init().
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20250121182445.35309-1-philmd@linaro.org>
---
hw/sh4/r2d.c | 38 +++++++++++++++++++++-----------------
1 file changed, 21 insertions(+), 17 deletions(-)
diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c
index 2fa439819e3..d68c94e82ef 100644
--- a/hw/sh4/r2d.c
+++ b/hw/sh4/r2d.c
@@ -63,6 +63,12 @@
#define PA_VERREG 0x32
#define PA_OUTPORT 0x36
+enum r2d_fpga_irq {
+ PCI_INTD, CF_IDE, CF_CD, PCI_INTC, SM501, KEY, RTC_A, RTC_T,
+ SDCARD, PCI_INTA, PCI_INTB, EXT, TP,
+ NR_IRQS
+};
+
typedef struct {
uint16_t bcr;
uint16_t irlmsk;
@@ -88,15 +94,10 @@ typedef struct {
/* output pin */
qemu_irq irl;
+ IRQState irq[NR_IRQS];
MemoryRegion iomem;
} r2d_fpga_t;
-enum r2d_fpga_irq {
- PCI_INTD, CF_IDE, CF_CD, PCI_INTC, SM501, KEY, RTC_A, RTC_T,
- SDCARD, PCI_INTA, PCI_INTB, EXT, TP,
- NR_IRQS
-};
-
static const struct { short irl; uint16_t msk; } irqtab[NR_IRQS] = {
[CF_IDE] = { 1, 1 << 9 },
[CF_CD] = { 2, 1 << 8 },
@@ -186,8 +187,8 @@ static const MemoryRegionOps r2d_fpga_ops = {
.endianness = DEVICE_NATIVE_ENDIAN,
};
-static qemu_irq *r2d_fpga_init(MemoryRegion *sysmem,
- hwaddr base, qemu_irq irl)
+static r2d_fpga_t *r2d_fpga_init(MemoryRegion *sysmem,
+ hwaddr base, qemu_irq irl)
{
r2d_fpga_t *s;
@@ -197,7 +198,10 @@ static qemu_irq *r2d_fpga_init(MemoryRegion *sysmem,
memory_region_init_io(&s->iomem, NULL, &r2d_fpga_ops, s, "r2d-fpga", 0x40);
memory_region_add_subregion(sysmem, base, &s->iomem);
- return qemu_allocate_irqs(r2d_fpga_irq_set, s, NR_IRQS);
+
+ qemu_init_irqs(s->irq, NR_IRQS, r2d_fpga_irq_set, s);
+
+ return s;
}
typedef struct ResetData {
@@ -239,13 +243,13 @@ static void r2d_init(MachineState *machine)
ResetData *reset_info;
struct SH7750State *s;
MemoryRegion *sdram = g_new(MemoryRegion, 1);
- qemu_irq *irq;
DriveInfo *dinfo;
DeviceState *dev;
SysBusDevice *busdev;
MemoryRegion *address_space_mem = get_system_memory();
PCIBus *pci_bus;
USBBus *usb_bus;
+ r2d_fpga_t *fpga;
cpu = SUPERH_CPU(cpu_create(machine->cpu_type));
env = &cpu->env;
@@ -260,7 +264,7 @@ static void r2d_init(MachineState *machine)
memory_region_add_subregion(address_space_mem, SDRAM_BASE, sdram);
/* Register peripherals */
s = sh7750_init(cpu, address_space_mem);
- irq = r2d_fpga_init(address_space_mem, 0x04000000, sh7750_irl(s));
+ fpga = r2d_fpga_init(address_space_mem, 0x04000000, sh7750_irl(s));
dev = qdev_new("sh_pci");
busdev = SYS_BUS_DEVICE(dev);
@@ -268,10 +272,10 @@ static void r2d_init(MachineState *machine)
pci_bus = PCI_BUS(qdev_get_child_bus(dev, "pci"));
sysbus_mmio_map(busdev, 0, P4ADDR(0x1e200000));
sysbus_mmio_map(busdev, 1, A7ADDR(0x1e200000));
- sysbus_connect_irq(busdev, 0, irq[PCI_INTA]);
- sysbus_connect_irq(busdev, 1, irq[PCI_INTB]);
- sysbus_connect_irq(busdev, 2, irq[PCI_INTC]);
- sysbus_connect_irq(busdev, 3, irq[PCI_INTD]);
+ sysbus_connect_irq(busdev, 0, &fpga->irq[PCI_INTA]);
+ sysbus_connect_irq(busdev, 1, &fpga->irq[PCI_INTB]);
+ sysbus_connect_irq(busdev, 2, &fpga->irq[PCI_INTC]);
+ sysbus_connect_irq(busdev, 3, &fpga->irq[PCI_INTD]);
dev = qdev_new("sysbus-sm501");
busdev = SYS_BUS_DEVICE(dev);
@@ -281,13 +285,13 @@ static void r2d_init(MachineState *machine)
sysbus_realize_and_unref(busdev, &error_fatal);
sysbus_mmio_map(busdev, 0, 0x10000000);
sysbus_mmio_map(busdev, 1, 0x13e00000);
- sysbus_connect_irq(busdev, 0, irq[SM501]);
+ sysbus_connect_irq(busdev, 0, &fpga->irq[SM501]);
/* onboard CF (True IDE mode, Master only). */
dinfo = drive_get(IF_IDE, 0, 0);
dev = qdev_new("mmio-ide");
busdev = SYS_BUS_DEVICE(dev);
- sysbus_connect_irq(busdev, 0, irq[CF_IDE]);
+ sysbus_connect_irq(busdev, 0, &fpga->irq[CF_IDE]);
qdev_prop_set_uint32(dev, "shift", 1);
sysbus_realize_and_unref(busdev, &error_fatal);
sysbus_mmio_map(busdev, 0, 0x14001000);
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 17/36] hw/char/pci-multi: Convert legacy qemu_allocate_irqs to qemu_init_irq
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (15 preceding siblings ...)
2025-01-31 21:04 ` [PULL 16/36] hw/sh4/r2d: Convert legacy qemu_allocate_irqs() to qemu_init_irqs() Philippe Mathieu-Daudé
@ 2025-01-31 21:05 ` Philippe Mathieu-Daudé
2025-01-31 21:05 ` [PULL 18/36] hw/misc/i2c-echo: add tracing Philippe Mathieu-Daudé
` (19 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:05 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Richard Henderson
There are a fixed number of PCI IRQs, known beforehand.
Allocate them within PCIMultiSerialState, and initialize
using qemu_init_irq(), allowing to remove the legacy
qemu_allocate_irqs() and qemu_free_irqs() calls.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20250121182828.45088-1-philmd@linaro.org>
---
hw/char/serial-pci-multi.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/hw/char/serial-pci-multi.c b/hw/char/serial-pci-multi.c
index 7578e863cfe..718ae251317 100644
--- a/hw/char/serial-pci-multi.c
+++ b/hw/char/serial-pci-multi.c
@@ -45,7 +45,7 @@ typedef struct PCIMultiSerialState {
char *name[PCI_SERIAL_MAX_PORTS];
SerialState state[PCI_SERIAL_MAX_PORTS];
uint32_t level[PCI_SERIAL_MAX_PORTS];
- qemu_irq *irqs;
+ IRQState irqs[PCI_SERIAL_MAX_PORTS];
uint8_t prog_if;
} PCIMultiSerialState;
@@ -61,7 +61,6 @@ static void multi_serial_pci_exit(PCIDevice *dev)
memory_region_del_subregion(&pci->iobar, &s->io);
g_free(pci->name[i]);
}
- qemu_free_irqs(pci->irqs, pci->ports);
}
static void multi_serial_irq_mux(void *opaque, int n, int level)
@@ -102,7 +101,6 @@ static void multi_serial_pci_realize(PCIDevice *dev, Error **errp)
pci->dev.config[PCI_INTERRUPT_PIN] = 0x01;
memory_region_init(&pci->iobar, OBJECT(pci), "multiserial", 8 * nports);
pci_register_bar(&pci->dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &pci->iobar);
- pci->irqs = qemu_allocate_irqs(multi_serial_irq_mux, pci, nports);
for (i = 0; i < nports; i++) {
s = pci->state + i;
@@ -110,7 +108,7 @@ static void multi_serial_pci_realize(PCIDevice *dev, Error **errp)
multi_serial_pci_exit(dev);
return;
}
- s->irq = pci->irqs[i];
+ s->irq = &pci->irqs[i];
pci->name[i] = g_strdup_printf("uart #%zu", i + 1);
memory_region_init_io(&s->io, OBJECT(pci), &serial_io_ops, s,
pci->name[i], 8);
@@ -183,6 +181,7 @@ static void multi_serial_init(Object *o)
size_t i, nports = multi_serial_get_port_count(PCI_DEVICE_GET_CLASS(dev));
for (i = 0; i < nports; i++) {
+ qemu_init_irq(&pms->irqs[i], multi_serial_irq_mux, pms, i);
object_initialize_child(o, "serial[*]", &pms->state[i], TYPE_SERIAL);
}
}
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 18/36] hw/misc/i2c-echo: add tracing
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (16 preceding siblings ...)
2025-01-31 21:05 ` [PULL 17/36] hw/char/pci-multi: Convert legacy qemu_allocate_irqs to qemu_init_irq Philippe Mathieu-Daudé
@ 2025-01-31 21:05 ` Philippe Mathieu-Daudé
2025-01-31 21:05 ` [PULL 19/36] hw/usb/hcd-ehci: Fix debug printf format string Philippe Mathieu-Daudé
` (18 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:05 UTC (permalink / raw)
To: qemu-devel; +Cc: Titus Rwantare, Hao Wu, Philippe Mathieu-Daudé
From: Titus Rwantare <titusr@google.com>
This has been useful when debugging and unsure if the guest is
generating i2c traffic.
Signed-off-by: Titus Rwantare <titusr@google.com>
Reviewed-by: Hao Wu <wuhaotsh@google.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20250121105935.3069035-1-titusr@google.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/misc/i2c-echo.c | 8 ++++++++
hw/misc/trace-events | 5 +++++
2 files changed, 13 insertions(+)
diff --git a/hw/misc/i2c-echo.c b/hw/misc/i2c-echo.c
index 5ae3d0817ea..65d10029dc7 100644
--- a/hw/misc/i2c-echo.c
+++ b/hw/misc/i2c-echo.c
@@ -13,6 +13,7 @@
#include "qemu/main-loop.h"
#include "block/aio.h"
#include "hw/i2c/i2c.h"
+#include "trace.h"
#define TYPE_I2C_ECHO "i2c-echo"
OBJECT_DECLARE_SIMPLE_TYPE(I2CEchoState, I2C_ECHO)
@@ -80,11 +81,13 @@ static int i2c_echo_event(I2CSlave *s, enum i2c_event event)
case I2C_START_RECV:
state->pos = 0;
+ trace_i2c_echo_event(DEVICE(s)->canonical_path, "I2C_START_RECV");
break;
case I2C_START_SEND:
state->pos = 0;
+ trace_i2c_echo_event(DEVICE(s)->canonical_path, "I2C_START_SEND");
break;
case I2C_FINISH:
@@ -92,12 +95,15 @@ static int i2c_echo_event(I2CSlave *s, enum i2c_event event)
state->state = I2C_ECHO_STATE_START_SEND;
i2c_bus_master(state->bus, state->bh);
+ trace_i2c_echo_event(DEVICE(s)->canonical_path, "I2C_FINISH");
break;
case I2C_NACK:
+ trace_i2c_echo_event(DEVICE(s)->canonical_path, "I2C_NACK");
break;
default:
+ trace_i2c_echo_event(DEVICE(s)->canonical_path, "UNHANDLED");
return -1;
}
@@ -112,6 +118,7 @@ static uint8_t i2c_echo_recv(I2CSlave *s)
return 0xff;
}
+ trace_i2c_echo_recv(DEVICE(s)->canonical_path, state->data[state->pos]);
return state->data[state->pos++];
}
@@ -119,6 +126,7 @@ static int i2c_echo_send(I2CSlave *s, uint8_t data)
{
I2CEchoState *state = I2C_ECHO(s);
+ trace_i2c_echo_send(DEVICE(s)->canonical_path, data);
if (state->pos > 2) {
return -1;
}
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
index cf1abe69285..b35b0e77f7d 100644
--- a/hw/misc/trace-events
+++ b/hw/misc/trace-events
@@ -390,3 +390,8 @@ ivshmem_flat_read_write_mmr_invalid(uint64_t addr_offset) "No ivshmem register m
ivshmem_flat_interrupt_invalid_peer(uint16_t peer_id) "Can't interrupt non-existing peer %u"
ivshmem_flat_write_mmr(uint64_t addr_offset) "Write access at offset %"PRIu64
ivshmem_flat_interrupt_peer(uint16_t peer_id, uint16_t vector_id) "Interrupting peer ID %u, vector %u..."
+
+# i2c-echo.c
+i2c_echo_event(const char *id, const char *event) "%s: %s"
+i2c_echo_recv(const char *id, uint8_t data) "%s: recv 0x%02" PRIx8
+i2c_echo_send(const char *id, uint8_t data) "%s: send 0x%02" PRIx8
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 19/36] hw/usb/hcd-ehci: Fix debug printf format string
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (17 preceding siblings ...)
2025-01-31 21:05 ` [PULL 18/36] hw/misc/i2c-echo: add tracing Philippe Mathieu-Daudé
@ 2025-01-31 21:05 ` Philippe Mathieu-Daudé
2025-01-31 21:05 ` [PULL 20/36] hw/avr/boot: Replace load_elf_ram_sym() -> load_elf_as() Philippe Mathieu-Daudé
` (17 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:05 UTC (permalink / raw)
To: qemu-devel; +Cc: BALATON Zoltan, Peter Maydell, Philippe Mathieu-Daudé
From: BALATON Zoltan <balaton@eik.bme.hu>
The variable is uint64_t so needs %PRIu64 instead of %d.
Fixes: 3ae7eb88c47 ("ehci: fix overflow in frame timer code")
Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20250124124713.64F8C4E6031@zero.eik.bme.hu>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/usb/hcd-ehci.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 6c4c14c8959..b090f253656 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -2287,7 +2287,8 @@ static void ehci_work_bh(void *opaque)
ehci_update_frindex(ehci, skipped_uframes);
ehci->last_run_ns += UFRAME_TIMER_NS * skipped_uframes;
uframes -= skipped_uframes;
- DPRINTF("WARNING - EHCI skipped %d uframes\n", skipped_uframes);
+ DPRINTF("WARNING - EHCI skipped %"PRIu64" uframes\n",
+ skipped_uframes);
}
for (i = 0; i < uframes; i++) {
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 20/36] hw/avr/boot: Replace load_elf_ram_sym() -> load_elf_as()
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (18 preceding siblings ...)
2025-01-31 21:05 ` [PULL 19/36] hw/usb/hcd-ehci: Fix debug printf format string Philippe Mathieu-Daudé
@ 2025-01-31 21:05 ` Philippe Mathieu-Daudé
2025-01-31 21:05 ` [PULL 21/36] hw/loader: Remove unused load_elf_ram() Philippe Mathieu-Daudé
` (16 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:05 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Richard Henderson
load_elf_ram_sym() with load_rom=true, sym_cb=NULL is
equivalent to load_elf_as(). Replace by the latter to
simplify.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20250127113824.50177-2-philmd@linaro.org>
---
hw/avr/boot.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/hw/avr/boot.c b/hw/avr/boot.c
index 617f3a144c8..6a91dcd12d0 100644
--- a/hw/avr/boot.c
+++ b/hw/avr/boot.c
@@ -71,11 +71,9 @@ bool avr_load_firmware(AVRCPU *cpu, MachineState *ms,
return false;
}
- bytes_loaded = load_elf_ram_sym(filename,
- NULL, NULL, NULL,
- &entry, NULL, NULL,
- &e_flags, 0, EM_AVR, 0, 0,
- NULL, true, NULL);
+ bytes_loaded = load_elf_as(filename, NULL, NULL, NULL,
+ &entry, NULL, NULL,
+ &e_flags, 0, EM_AVR, 0, 0, NULL);
if (bytes_loaded >= 0) {
/* If ELF file is provided, determine CPU type reading ELF e_flags. */
const char *elf_cpu = avr_elf_e_flags_to_cpu_type(e_flags);
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 21/36] hw/loader: Remove unused load_elf_ram()
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (19 preceding siblings ...)
2025-01-31 21:05 ` [PULL 20/36] hw/avr/boot: Replace load_elf_ram_sym() -> load_elf_as() Philippe Mathieu-Daudé
@ 2025-01-31 21:05 ` Philippe Mathieu-Daudé
2025-01-31 21:05 ` [PULL 22/36] hw/loader: Clarify local variable name in load_elf_ram_sym() Philippe Mathieu-Daudé
` (15 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:05 UTC (permalink / raw)
To: qemu-devel
Cc: Philippe Mathieu-Daudé, Richard Henderson, Alistair Francis
Last use of load_elf_ram() was removed in commit 188e255bf8e
("hw/s390x: Remove the possibility to load the s390-netboot.img
binary"), remove it.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-Id: <20250127113824.50177-3-philmd@linaro.org>
---
include/hw/loader.h | 14 +-------------
hw/core/loader.c | 16 +---------------
2 files changed, 2 insertions(+), 28 deletions(-)
diff --git a/include/hw/loader.h b/include/hw/loader.h
index 8985046be40..9bb34e6f062 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -155,20 +155,8 @@ ssize_t load_elf_ram_sym(const char *filename,
int clear_lsb, int data_swab,
AddressSpace *as, bool load_rom, symbol_fn_t sym_cb);
-/** load_elf_ram:
- * Same as load_elf_ram_sym(), but doesn't allow the caller to specify a
- * symbol callback function
- */
-ssize_t load_elf_ram(const char *filename,
- uint64_t (*elf_note_fn)(void *, void *, bool),
- uint64_t (*translate_fn)(void *, uint64_t),
- void *translate_opaque, uint64_t *pentry,
- uint64_t *lowaddr, uint64_t *highaddr, uint32_t *pflags,
- int big_endian, int elf_machine, int clear_lsb,
- int data_swab, AddressSpace *as, bool load_rom);
-
/** load_elf_as:
- * Same as load_elf_ram(), but always loads the elf as ROM
+ * Same as load_elf_ram_sym(), but always loads the elf as ROM
*/
ssize_t load_elf_as(const char *filename,
uint64_t (*elf_note_fn)(void *, void *, bool),
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 4dfdb027eee..ead10fb6cb5 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -425,26 +425,12 @@ ssize_t load_elf_as(const char *filename,
uint64_t *highaddr, uint32_t *pflags, int big_endian,
int elf_machine, int clear_lsb, int data_swab,
AddressSpace *as)
-{
- return load_elf_ram(filename, elf_note_fn, translate_fn, translate_opaque,
- pentry, lowaddr, highaddr, pflags, big_endian,
- elf_machine, clear_lsb, data_swab, as, true);
-}
-
-/* return < 0 if error, otherwise the number of bytes loaded in memory */
-ssize_t load_elf_ram(const char *filename,
- uint64_t (*elf_note_fn)(void *, void *, bool),
- uint64_t (*translate_fn)(void *, uint64_t),
- void *translate_opaque, uint64_t *pentry,
- uint64_t *lowaddr, uint64_t *highaddr, uint32_t *pflags,
- int big_endian, int elf_machine, int clear_lsb,
- int data_swab, AddressSpace *as, bool load_rom)
{
return load_elf_ram_sym(filename, elf_note_fn,
translate_fn, translate_opaque,
pentry, lowaddr, highaddr, pflags, big_endian,
elf_machine, clear_lsb, data_swab, as,
- load_rom, NULL);
+ true, NULL);
}
/* return < 0 if error, otherwise the number of bytes loaded in memory */
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 22/36] hw/loader: Clarify local variable name in load_elf_ram_sym()
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (20 preceding siblings ...)
2025-01-31 21:05 ` [PULL 21/36] hw/loader: Remove unused load_elf_ram() Philippe Mathieu-Daudé
@ 2025-01-31 21:05 ` Philippe Mathieu-Daudé
2025-01-31 21:05 ` [PULL 23/36] hw/loader: Pass ELFDATA endian order argument to load_elf_ram_sym() Philippe Mathieu-Daudé
` (14 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:05 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, BALATON Zoltan, Richard Henderson
load_elf_ram_sym() compares target_data_order versus
host data_order. Rename 'data_order' -> 'host_data_order'
to ease code review. Avoid the preprocessor by directly
checking HOST_BIG_ENDIAN.
Reviewed-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-Id: <20250127113824.50177-4-philmd@linaro.org>
---
hw/core/loader.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/hw/core/loader.c b/hw/core/loader.c
index ead10fb6cb5..de6b173f4a1 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -443,7 +443,8 @@ ssize_t load_elf_ram_sym(const char *filename,
int clear_lsb, int data_swab,
AddressSpace *as, bool load_rom, symbol_fn_t sym_cb)
{
- int fd, data_order, target_data_order, must_swab;
+ const int host_data_order = HOST_BIG_ENDIAN ? ELFDATA2MSB : ELFDATA2LSB;
+ int fd, target_data_order, must_swab;
ssize_t ret = ELF_LOAD_FAILED;
uint8_t e_ident[EI_NIDENT];
@@ -461,12 +462,7 @@ ssize_t load_elf_ram_sym(const char *filename,
ret = ELF_LOAD_NOT_ELF;
goto fail;
}
-#if HOST_BIG_ENDIAN
- data_order = ELFDATA2MSB;
-#else
- data_order = ELFDATA2LSB;
-#endif
- must_swab = data_order != e_ident[EI_DATA];
+ must_swab = host_data_order != e_ident[EI_DATA];
if (big_endian) {
target_data_order = ELFDATA2MSB;
} else {
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 23/36] hw/loader: Pass ELFDATA endian order argument to load_elf_ram_sym()
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (21 preceding siblings ...)
2025-01-31 21:05 ` [PULL 22/36] hw/loader: Clarify local variable name in load_elf_ram_sym() Philippe Mathieu-Daudé
@ 2025-01-31 21:05 ` Philippe Mathieu-Daudé
2025-01-31 21:05 ` [PULL 24/36] hw/loader: Pass ELFDATA endian order argument to load_elf_as() Philippe Mathieu-Daudé
` (13 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:05 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Richard Henderson
Rather than passing a boolean 'is_big_endian' argument,
directly pass the ELFDATA, which can be unspecified using
the ELFDATANONE value.
Update the call sites:
0 -> ELFDATA2LSB
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20250127113824.50177-5-philmd@linaro.org>
---
include/hw/loader.h | 4 ++--
hw/core/loader.c | 17 +++++++----------
hw/riscv/boot.c | 3 ++-
3 files changed, 11 insertions(+), 13 deletions(-)
diff --git a/include/hw/loader.h b/include/hw/loader.h
index 9bb34e6f062..8202c376043 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -120,7 +120,7 @@ const char *load_elf_strerror(ssize_t error);
* @lowaddr: Populated with lowest loaded address. Ignored if NULL.
* @highaddr: Populated with highest loaded address. Ignored if NULL.
* @pflags: Populated with ELF processor-specific flags. Ignore if NULL.
- * @bigendian: Expected ELF endianness. 0 for LE otherwise BE
+ * @elf_data_order: Expected ELF endianness (ELFDATA2LSB or ELFDATA2MSB).
* @elf_machine: Expected ELF machine type
* @clear_lsb: Set to mask off LSB of addresses (Some architectures use
* this for non-address data)
@@ -151,7 +151,7 @@ ssize_t load_elf_ram_sym(const char *filename,
uint64_t (*translate_fn)(void *, uint64_t),
void *translate_opaque, uint64_t *pentry,
uint64_t *lowaddr, uint64_t *highaddr,
- uint32_t *pflags, int big_endian, int elf_machine,
+ uint32_t *pflags, int elf_data_order, int elf_machine,
int clear_lsb, int data_swab,
AddressSpace *as, bool load_rom, symbol_fn_t sym_cb);
diff --git a/hw/core/loader.c b/hw/core/loader.c
index de6b173f4a1..f1fab3e91b1 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -428,7 +428,8 @@ ssize_t load_elf_as(const char *filename,
{
return load_elf_ram_sym(filename, elf_note_fn,
translate_fn, translate_opaque,
- pentry, lowaddr, highaddr, pflags, big_endian,
+ pentry, lowaddr, highaddr, pflags,
+ big_endian ? ELFDATA2MSB : ELFDATA2LSB,
elf_machine, clear_lsb, data_swab, as,
true, NULL);
}
@@ -439,12 +440,12 @@ ssize_t load_elf_ram_sym(const char *filename,
uint64_t (*translate_fn)(void *, uint64_t),
void *translate_opaque, uint64_t *pentry,
uint64_t *lowaddr, uint64_t *highaddr,
- uint32_t *pflags, int big_endian, int elf_machine,
+ uint32_t *pflags, int elf_data_order, int elf_machine,
int clear_lsb, int data_swab,
AddressSpace *as, bool load_rom, symbol_fn_t sym_cb)
{
const int host_data_order = HOST_BIG_ENDIAN ? ELFDATA2MSB : ELFDATA2LSB;
- int fd, target_data_order, must_swab;
+ int fd, must_swab;
ssize_t ret = ELF_LOAD_FAILED;
uint8_t e_ident[EI_NIDENT];
@@ -462,18 +463,14 @@ ssize_t load_elf_ram_sym(const char *filename,
ret = ELF_LOAD_NOT_ELF;
goto fail;
}
- must_swab = host_data_order != e_ident[EI_DATA];
- if (big_endian) {
- target_data_order = ELFDATA2MSB;
- } else {
- target_data_order = ELFDATA2LSB;
- }
- if (target_data_order != e_ident[EI_DATA]) {
+ if (elf_data_order != ELFDATANONE && elf_data_order != e_ident[EI_DATA]) {
ret = ELF_LOAD_WRONG_ENDIAN;
goto fail;
}
+ must_swab = host_data_order != e_ident[EI_DATA];
+
lseek(fd, 0, SEEK_SET);
if (e_ident[EI_CLASS] == ELFCLASS64) {
ret = load_elf64(filename, fd, elf_note_fn,
diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
index 90e75c69a04..c309441b7d8 100644
--- a/hw/riscv/boot.c
+++ b/hw/riscv/boot.c
@@ -246,7 +246,8 @@ void riscv_load_kernel(MachineState *machine,
*/
kernel_size = load_elf_ram_sym(kernel_filename, NULL, NULL, NULL, NULL,
&info->image_low_addr, &info->image_high_addr,
- NULL, 0, EM_RISCV, 1, 0, NULL, true, sym_cb);
+ NULL, ELFDATA2LSB, EM_RISCV,
+ 1, 0, NULL, true, sym_cb);
if (kernel_size > 0) {
info->kernel_size = kernel_size;
goto out;
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 24/36] hw/loader: Pass ELFDATA endian order argument to load_elf_as()
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (22 preceding siblings ...)
2025-01-31 21:05 ` [PULL 23/36] hw/loader: Pass ELFDATA endian order argument to load_elf_ram_sym() Philippe Mathieu-Daudé
@ 2025-01-31 21:05 ` Philippe Mathieu-Daudé
2025-01-31 21:05 ` [PULL 25/36] hw/loader: Pass ELFDATA endian order argument to load_elf() Philippe Mathieu-Daudé
` (12 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:05 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Richard Henderson
Rather than passing a boolean 'is_big_endian' argument,
directly pass the ELFDATA, which can be unspecified using
the ELFDATANONE value.
Update the call sites:
0 -> ELFDATA2LSB
1 -> ELFDATA2MSB
Note, this allow removing the target_words_bigendian() call
in the GENERIC_LOADER device, where we pass ELFDATANONE.
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20250127113824.50177-6-philmd@linaro.org>
---
include/hw/loader.h | 2 +-
hw/arm/armv7m.c | 2 +-
hw/arm/boot.c | 16 ++++++++--------
hw/avr/boot.c | 2 +-
hw/core/generic-loader.c | 6 +-----
hw/core/loader.c | 8 ++++----
6 files changed, 16 insertions(+), 20 deletions(-)
diff --git a/include/hw/loader.h b/include/hw/loader.h
index 8202c376043..84737c05b8d 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -162,7 +162,7 @@ ssize_t load_elf_as(const char *filename,
uint64_t (*elf_note_fn)(void *, void *, bool),
uint64_t (*translate_fn)(void *, uint64_t),
void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr,
- uint64_t *highaddr, uint32_t *pflags, int big_endian,
+ uint64_t *highaddr, uint32_t *pflags, int elf_data_order,
int elf_machine, int clear_lsb, int data_swab,
AddressSpace *as);
diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c
index a67a890a33e..98a69846119 100644
--- a/hw/arm/armv7m.c
+++ b/hw/arm/armv7m.c
@@ -608,7 +608,7 @@ void armv7m_load_kernel(ARMCPU *cpu, const char *kernel_filename,
if (kernel_filename) {
image_size = load_elf_as(kernel_filename, NULL, NULL, NULL,
&entry, NULL, NULL,
- NULL, 0, EM_ARM, 1, 0, as);
+ NULL, ELFDATA2LSB, EM_ARM, 1, 0, as);
if (image_size < 0) {
image_size = load_image_targphys_as(kernel_filename, mem_base,
mem_size, as);
diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index b44bea8a821..cbc24356fc1 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -798,7 +798,7 @@ static ssize_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry,
Elf64_Ehdr h64;
} elf_header;
int data_swab = 0;
- bool big_endian;
+ int elf_data_order;
ssize_t ret;
Error *err = NULL;
@@ -814,12 +814,12 @@ static ssize_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry,
}
if (elf_is64) {
- big_endian = elf_header.h64.e_ident[EI_DATA] == ELFDATA2MSB;
- info->endianness = big_endian ? ARM_ENDIANNESS_BE8
- : ARM_ENDIANNESS_LE;
+ elf_data_order = elf_header.h64.e_ident[EI_DATA];
+ info->endianness = elf_data_order == ELFDATA2MSB ? ARM_ENDIANNESS_BE8
+ : ARM_ENDIANNESS_LE;
} else {
- big_endian = elf_header.h32.e_ident[EI_DATA] == ELFDATA2MSB;
- if (big_endian) {
+ elf_data_order = elf_header.h32.e_ident[EI_DATA];
+ if (elf_data_order == ELFDATA2MSB) {
if (bswap32(elf_header.h32.e_flags) & EF_ARM_BE8) {
info->endianness = ARM_ENDIANNESS_BE8;
} else {
@@ -839,8 +839,8 @@ static ssize_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry,
}
ret = load_elf_as(info->kernel_filename, NULL, NULL, NULL,
- pentry, lowaddr, highaddr, NULL, big_endian, elf_machine,
- 1, data_swab, as);
+ pentry, lowaddr, highaddr, NULL, elf_data_order,
+ elf_machine, 1, data_swab, as);
if (ret <= 0) {
/* The header loaded but the image didn't */
error_report("Couldn't load elf '%s': %s",
diff --git a/hw/avr/boot.c b/hw/avr/boot.c
index 6a91dcd12d0..e5a29c7218e 100644
--- a/hw/avr/boot.c
+++ b/hw/avr/boot.c
@@ -73,7 +73,7 @@ bool avr_load_firmware(AVRCPU *cpu, MachineState *ms,
bytes_loaded = load_elf_as(filename, NULL, NULL, NULL,
&entry, NULL, NULL,
- &e_flags, 0, EM_AVR, 0, 0, NULL);
+ &e_flags, ELFDATA2LSB, EM_AVR, 0, 0, NULL);
if (bytes_loaded >= 0) {
/* If ELF file is provided, determine CPU type reading ELF e_flags. */
const char *elf_cpu = avr_elf_e_flags_to_cpu_type(e_flags);
diff --git a/hw/core/generic-loader.c b/hw/core/generic-loader.c
index fb354693aff..d9f5c2e8325 100644
--- a/hw/core/generic-loader.c
+++ b/hw/core/generic-loader.c
@@ -31,7 +31,6 @@
*/
#include "qemu/osdep.h"
-#include "exec/tswap.h"
#include "system/dma.h"
#include "system/reset.h"
#include "hw/boards.h"
@@ -66,7 +65,6 @@ static void generic_loader_realize(DeviceState *dev, Error **errp)
{
GenericLoaderState *s = GENERIC_LOADER(dev);
hwaddr entry;
- int big_endian;
ssize_t size = 0;
s->set_pc = false;
@@ -134,14 +132,12 @@ static void generic_loader_realize(DeviceState *dev, Error **errp)
s->cpu = first_cpu;
}
- big_endian = target_words_bigendian();
-
if (s->file) {
AddressSpace *as = s->cpu ? s->cpu->as : NULL;
if (!s->force_raw) {
size = load_elf_as(s->file, NULL, NULL, NULL, &entry, NULL, NULL,
- NULL, big_endian, 0, 0, 0, as);
+ NULL, ELFDATANONE, 0, 0, 0, as);
if (size < 0) {
size = load_uimage_as(s->file, &entry, NULL, NULL, NULL, NULL,
diff --git a/hw/core/loader.c b/hw/core/loader.c
index f1fab3e91b1..cc0631e7dd5 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -413,7 +413,8 @@ ssize_t load_elf(const char *filename,
int elf_machine, int clear_lsb, int data_swab)
{
return load_elf_as(filename, elf_note_fn, translate_fn, translate_opaque,
- pentry, lowaddr, highaddr, pflags, big_endian,
+ pentry, lowaddr, highaddr, pflags,
+ big_endian ? ELFDATA2MSB : ELFDATA2LSB,
elf_machine, clear_lsb, data_swab, NULL);
}
@@ -422,14 +423,13 @@ ssize_t load_elf_as(const char *filename,
uint64_t (*elf_note_fn)(void *, void *, bool),
uint64_t (*translate_fn)(void *, uint64_t),
void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr,
- uint64_t *highaddr, uint32_t *pflags, int big_endian,
+ uint64_t *highaddr, uint32_t *pflags, int elf_data_order,
int elf_machine, int clear_lsb, int data_swab,
AddressSpace *as)
{
return load_elf_ram_sym(filename, elf_note_fn,
translate_fn, translate_opaque,
- pentry, lowaddr, highaddr, pflags,
- big_endian ? ELFDATA2MSB : ELFDATA2LSB,
+ pentry, lowaddr, highaddr, pflags, elf_data_order,
elf_machine, clear_lsb, data_swab, as,
true, NULL);
}
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 25/36] hw/loader: Pass ELFDATA endian order argument to load_elf()
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (23 preceding siblings ...)
2025-01-31 21:05 ` [PULL 24/36] hw/loader: Pass ELFDATA endian order argument to load_elf_as() Philippe Mathieu-Daudé
@ 2025-01-31 21:05 ` Philippe Mathieu-Daudé
2025-01-31 21:05 ` [PULL 26/36] hw/sd/omap_mmc: Do a minimal conversion to QDev Philippe Mathieu-Daudé
` (11 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:05 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Richard Henderson, BALATON Zoltan
Rather than passing a boolean 'is_big_endian' argument,
directly pass the ELFDATA, which can be unspecified using
the ELFDATANONE value.
Update the call sites:
0 -> ELFDATA2LSB
1 -> ELFDATA2MSB
TARGET_BIG_ENDIAN -> TARGET_BIG_ENDIAN ? ELFDATA2MSB : ELFDATA2LSB
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20250127113824.50177-7-philmd@linaro.org>
---
include/hw/loader.h | 2 +-
hw/alpha/dp264.c | 4 ++--
hw/core/loader.c | 5 ++---
hw/hppa/machine.c | 4 ++--
hw/i386/multiboot.c | 4 ++--
hw/i386/x86-common.c | 4 ++--
hw/loongarch/boot.c | 2 +-
hw/m68k/an5206.c | 2 +-
hw/m68k/mcf5208.c | 2 +-
hw/m68k/q800.c | 2 +-
hw/m68k/virt.c | 2 +-
hw/microblaze/boot.c | 6 ++++--
hw/mips/boston.c | 2 +-
hw/mips/fuloong2e.c | 2 +-
hw/mips/loongson3_virt.c | 2 +-
hw/mips/malta.c | 5 +++--
hw/mips/mipssim.c | 3 ++-
hw/openrisc/boot.c | 2 +-
hw/pci-host/raven.c | 4 ++--
hw/ppc/e500.c | 2 +-
hw/ppc/mac_newworld.c | 5 +++--
hw/ppc/mac_oldworld.c | 4 ++--
hw/ppc/pegasos2.c | 8 ++++----
hw/ppc/ppc405_boards.c | 2 +-
hw/ppc/ppc440_bamboo.c | 3 ++-
hw/ppc/sam460ex.c | 2 +-
hw/ppc/spapr.c | 8 ++++----
hw/ppc/virtex_ml507.c | 4 ++--
hw/s390x/ipl.c | 6 +++---
hw/sparc/leon3.c | 2 +-
hw/sparc/sun4m.c | 5 +++--
hw/sparc64/sun4u.c | 6 +++---
hw/tricore/triboard.c | 2 +-
hw/tricore/tricore_testboard.c | 2 +-
hw/xtensa/sim.c | 3 ++-
hw/xtensa/xtfpga.c | 3 ++-
36 files changed, 67 insertions(+), 59 deletions(-)
diff --git a/include/hw/loader.h b/include/hw/loader.h
index 84737c05b8d..784a93d6c17 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -174,7 +174,7 @@ ssize_t load_elf(const char *filename,
uint64_t (*elf_note_fn)(void *, void *, bool),
uint64_t (*translate_fn)(void *, uint64_t),
void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr,
- uint64_t *highaddr, uint32_t *pflags, int big_endian,
+ uint64_t *highaddr, uint32_t *pflags, int elf_data_order,
int elf_machine, int clear_lsb, int data_swab);
/** load_elf_hdr:
diff --git a/hw/alpha/dp264.c b/hw/alpha/dp264.c
index 52a1fa310b9..570ea9edf24 100644
--- a/hw/alpha/dp264.c
+++ b/hw/alpha/dp264.c
@@ -144,7 +144,7 @@ static void clipper_init(MachineState *machine)
}
size = load_elf(palcode_filename, NULL, cpu_alpha_superpage_to_phys,
NULL, &palcode_entry, NULL, NULL, NULL,
- 0, EM_ALPHA, 0, 0);
+ ELFDATA2LSB, EM_ALPHA, 0, 0);
if (size < 0) {
error_report("could not load palcode '%s'", palcode_filename);
exit(1);
@@ -163,7 +163,7 @@ static void clipper_init(MachineState *machine)
size = load_elf(kernel_filename, NULL, cpu_alpha_superpage_to_phys,
NULL, &kernel_entry, &kernel_low, NULL, NULL,
- 0, EM_ALPHA, 0, 0);
+ ELFDATA2LSB, EM_ALPHA, 0, 0);
if (size < 0) {
error_report("could not load kernel '%s'", kernel_filename);
exit(1);
diff --git a/hw/core/loader.c b/hw/core/loader.c
index cc0631e7dd5..fd25c5e01bd 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -409,12 +409,11 @@ ssize_t load_elf(const char *filename,
uint64_t (*elf_note_fn)(void *, void *, bool),
uint64_t (*translate_fn)(void *, uint64_t),
void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr,
- uint64_t *highaddr, uint32_t *pflags, int big_endian,
+ uint64_t *highaddr, uint32_t *pflags, int elf_data_order,
int elf_machine, int clear_lsb, int data_swab)
{
return load_elf_as(filename, elf_note_fn, translate_fn, translate_opaque,
- pentry, lowaddr, highaddr, pflags,
- big_endian ? ELFDATA2MSB : ELFDATA2LSB,
+ pentry, lowaddr, highaddr, pflags, elf_data_order,
elf_machine, clear_lsb, data_swab, NULL);
}
diff --git a/hw/hppa/machine.c b/hw/hppa/machine.c
index 0dd19082146..b6135d95261 100644
--- a/hw/hppa/machine.c
+++ b/hw/hppa/machine.c
@@ -440,7 +440,7 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus,
size = load_elf(firmware_filename, NULL, translate, NULL,
&firmware_entry, &firmware_low, &firmware_high, NULL,
- true, EM_PARISC, 0, 0);
+ ELFDATA2MSB, EM_PARISC, 0, 0);
if (size < 0) {
error_report("could not load firmware '%s'", firmware_filename);
@@ -467,7 +467,7 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus,
if (kernel_filename) {
size = load_elf(kernel_filename, NULL, linux_kernel_virt_to_phys,
NULL, &kernel_entry, &kernel_low, &kernel_high, NULL,
- true, EM_PARISC, 0, 0);
+ ELFDATA2MSB, EM_PARISC, 0, 0);
kernel_entry = linux_kernel_virt_to_phys(NULL, kernel_entry);
diff --git a/hw/i386/multiboot.c b/hw/i386/multiboot.c
index 1d66ca3204a..cd07a058614 100644
--- a/hw/i386/multiboot.c
+++ b/hw/i386/multiboot.c
@@ -202,8 +202,8 @@ int load_multiboot(X86MachineState *x86ms,
}
kernel_size = load_elf(kernel_filename, NULL, NULL, NULL, &elf_entry,
- &elf_low, &elf_high, NULL, 0, I386_ELF_MACHINE,
- 0, 0);
+ &elf_low, &elf_high, NULL,
+ ELFDATA2LSB, I386_ELF_MACHINE, 0, 0);
if (kernel_size < 0) {
error_report("Error while loading elf kernel");
exit(1);
diff --git a/hw/i386/x86-common.c b/hw/i386/x86-common.c
index 008496b5b85..1b0671c5239 100644
--- a/hw/i386/x86-common.c
+++ b/hw/i386/x86-common.c
@@ -608,8 +608,8 @@ static bool load_elfboot(const char *kernel_filename,
uint64_t elf_note_type = XEN_ELFNOTE_PHYS32_ENTRY;
kernel_size = load_elf(kernel_filename, read_pvh_start_addr,
NULL, &elf_note_type, &elf_entry,
- &elf_low, &elf_high, NULL, 0, I386_ELF_MACHINE,
- 0, 0);
+ &elf_low, &elf_high, NULL,
+ ELFDATA2LSB, I386_ELF_MACHINE, 0, 0);
if (kernel_size < 0) {
error_report("Error while loading elf kernel");
diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
index bd8763c61c3..354cf458c81 100644
--- a/hw/loongarch/boot.c
+++ b/hw/loongarch/boot.c
@@ -243,7 +243,7 @@ static int64_t load_kernel_info(struct loongarch_boot_info *info)
kernel_size = load_elf(info->kernel_filename, NULL,
cpu_loongarch_virt_to_phys, NULL,
&kernel_entry, &kernel_low,
- &kernel_high, NULL, 0,
+ &kernel_high, NULL, ELFDATA2LSB,
EM_LOONGARCH, 1, 0);
if (kernel_size < 0) {
kernel_size = load_loongarch_linux_image(info->kernel_filename,
diff --git a/hw/m68k/an5206.c b/hw/m68k/an5206.c
index 7b8210475ec..d97399b882b 100644
--- a/hw/m68k/an5206.c
+++ b/hw/m68k/an5206.c
@@ -74,7 +74,7 @@ static void an5206_init(MachineState *machine)
}
kernel_size = load_elf(kernel_filename, NULL, NULL, NULL, &elf_entry,
- NULL, NULL, NULL, 1, EM_68K, 0, 0);
+ NULL, NULL, NULL, ELFDATA2MSB, EM_68K, 0, 0);
entry = elf_entry;
if (kernel_size < 0) {
kernel_size = load_uimage(kernel_filename, &entry, NULL, NULL,
diff --git a/hw/m68k/mcf5208.c b/hw/m68k/mcf5208.c
index 409bb72574c..75cc076f787 100644
--- a/hw/m68k/mcf5208.c
+++ b/hw/m68k/mcf5208.c
@@ -372,7 +372,7 @@ static void mcf5208evb_init(MachineState *machine)
}
kernel_size = load_elf(kernel_filename, NULL, NULL, NULL, &elf_entry,
- NULL, NULL, NULL, 1, EM_68K, 0, 0);
+ NULL, NULL, NULL, ELFDATA2MSB, EM_68K, 0, 0);
entry = elf_entry;
if (kernel_size < 0) {
kernel_size = load_uimage(kernel_filename, &entry, NULL, NULL,
diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
index ca3adb9a8ae..aeed4c8ddb8 100644
--- a/hw/m68k/q800.c
+++ b/hw/m68k/q800.c
@@ -585,7 +585,7 @@ static void q800_machine_init(MachineState *machine)
}
kernel_size = load_elf(kernel_filename, NULL, NULL, NULL,
- &elf_entry, NULL, &high, NULL, 1,
+ &elf_entry, NULL, &high, NULL, ELFDATA2MSB,
EM_68K, 0, 0);
if (kernel_size < 0) {
error_report("could not load kernel '%s'", kernel_filename);
diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c
index 87ec39eeae1..d967bdd7438 100644
--- a/hw/m68k/virt.c
+++ b/hw/m68k/virt.c
@@ -228,7 +228,7 @@ static void virt_init(MachineState *machine)
}
kernel_size = load_elf(kernel_filename, NULL, NULL, NULL,
- &elf_entry, NULL, &high, NULL, 1,
+ &elf_entry, NULL, &high, NULL, ELFDATA2MSB,
EM_68K, 0, 0);
if (kernel_size < 0) {
error_report("could not load kernel '%s'", kernel_filename);
diff --git a/hw/microblaze/boot.c b/hw/microblaze/boot.c
index 3854bc2291b..60b4ef0abe7 100644
--- a/hw/microblaze/boot.c
+++ b/hw/microblaze/boot.c
@@ -144,13 +144,15 @@ void microblaze_load_kernel(MicroBlazeCPU *cpu, bool is_little_endian,
/* Boots a kernel elf binary. */
kernel_size = load_elf(kernel_filename, NULL, NULL, NULL,
&entry, NULL, &high, NULL,
- !is_little_endian, EM_MICROBLAZE, 0, 0);
+ is_little_endian ? ELFDATA2LSB : ELFDATA2MSB,
+ EM_MICROBLAZE, 0, 0);
base32 = entry;
if (base32 == 0xc0000000) {
kernel_size = load_elf(kernel_filename, NULL,
translate_kernel_address, NULL,
&entry, NULL, NULL, NULL,
- !is_little_endian, EM_MICROBLAZE, 0, 0);
+ is_little_endian ? ELFDATA2LSB : ELFDATA2MSB,
+ EM_MICROBLAZE, 0, 0);
}
/* Always boot into physical ram. */
boot_info.bootstrap_pc = (uint32_t)entry;
diff --git a/hw/mips/boston.c b/hw/mips/boston.c
index 67044af962a..364c328032a 100644
--- a/hw/mips/boston.c
+++ b/hw/mips/boston.c
@@ -792,7 +792,7 @@ static void boston_mach_init(MachineState *machine)
kernel_size = load_elf(machine->kernel_filename, NULL,
cpu_mips_kseg0_to_phys, NULL,
&kernel_entry, NULL, &kernel_high,
- NULL, 0, EM_MIPS, 1, 0);
+ NULL, ELFDATA2LSB, EM_MIPS, 1, 0);
if (kernel_size > 0) {
int dt_size;
diff --git a/hw/mips/fuloong2e.c b/hw/mips/fuloong2e.c
index 16b6a5129e7..646044e2749 100644
--- a/hw/mips/fuloong2e.c
+++ b/hw/mips/fuloong2e.c
@@ -106,7 +106,7 @@ static uint64_t load_kernel(MIPSCPU *cpu)
cpu_mips_kseg0_to_phys, NULL,
&kernel_entry, NULL,
&kernel_high, NULL,
- 0, EM_MIPS, 1, 0);
+ ELFDATA2LSB, EM_MIPS, 1, 0);
if (kernel_size < 0) {
error_report("could not load kernel '%s': %s",
loaderparams.kernel_filename,
diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
index 85cf1f707fa..831fddb1bd7 100644
--- a/hw/mips/loongson3_virt.c
+++ b/hw/mips/loongson3_virt.c
@@ -358,7 +358,7 @@ static uint64_t load_kernel(CPUMIPSState *env)
cpu_mips_kseg0_to_phys, NULL,
&kernel_entry,
&kernel_low, &kernel_high,
- NULL, 0, EM_MIPS, 1, 0);
+ NULL, ELFDATA2LSB, EM_MIPS, 1, 0);
if (kernel_size < 0) {
error_report("could not load kernel '%s': %s",
loaderparams.kernel_filename,
diff --git a/hw/mips/malta.c b/hw/mips/malta.c
index 4e9cccaa347..8e9cea70b13 100644
--- a/hw/mips/malta.c
+++ b/hw/mips/malta.c
@@ -880,8 +880,9 @@ static uint64_t load_kernel(void)
kernel_size = load_elf(loaderparams.kernel_filename, NULL,
cpu_mips_kseg0_to_phys, NULL,
&kernel_entry, NULL,
- &kernel_high, NULL, TARGET_BIG_ENDIAN, EM_MIPS,
- 1, 0);
+ &kernel_high, NULL,
+ TARGET_BIG_ENDIAN ? ELFDATA2MSB : ELFDATA2LSB,
+ EM_MIPS, 1, 0);
if (kernel_size < 0) {
error_report("could not load kernel '%s': %s",
loaderparams.kernel_filename,
diff --git a/hw/mips/mipssim.c b/hw/mips/mipssim.c
index a294779a82b..c530688e769 100644
--- a/hw/mips/mipssim.c
+++ b/hw/mips/mipssim.c
@@ -73,7 +73,8 @@ static uint64_t load_kernel(void)
kernel_size = load_elf(loaderparams.kernel_filename, NULL,
cpu_mips_kseg0_to_phys, NULL,
&entry, NULL,
- &kernel_high, NULL, TARGET_BIG_ENDIAN,
+ &kernel_high, NULL,
+ TARGET_BIG_ENDIAN ? ELFDATA2MSB : ELFDATA2LSB,
EM_MIPS, 1, 0);
if (kernel_size < 0) {
error_report("could not load kernel '%s': %s",
diff --git a/hw/openrisc/boot.c b/hw/openrisc/boot.c
index 83c1fc6705e..0f08df812dc 100644
--- a/hw/openrisc/boot.c
+++ b/hw/openrisc/boot.c
@@ -32,7 +32,7 @@ hwaddr openrisc_load_kernel(ram_addr_t ram_size,
if (kernel_filename && !qtest_enabled()) {
kernel_size = load_elf(kernel_filename, NULL, NULL, NULL,
- &elf_entry, NULL, &high_addr, NULL, 1,
+ &elf_entry, NULL, &high_addr, NULL, ELFDATA2MSB,
EM_OPENRISC, 1, 0);
entry = elf_entry;
if (kernel_size < 0) {
diff --git a/hw/pci-host/raven.c b/hw/pci-host/raven.c
index 918a3237a9e..e3d8d206b73 100644
--- a/hw/pci-host/raven.c
+++ b/hw/pci-host/raven.c
@@ -357,8 +357,8 @@ static void raven_realize(PCIDevice *d, Error **errp)
if (filename) {
if (s->elf_machine != EM_NONE) {
bios_size = load_elf(filename, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, 1, s->elf_machine,
- 0, 0);
+ NULL, NULL, NULL,
+ ELFDATA2MSB, s->elf_machine, 0, 0);
}
if (bios_size < 0) {
bios_size = get_image_size(filename);
diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index 4551157c011..26933e0457e 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -1194,7 +1194,7 @@ void ppce500_init(MachineState *machine)
payload_size = load_elf(filename, NULL, NULL, NULL,
&bios_entry, &loadaddr, NULL, NULL,
- 1, PPC_ELF_MACHINE, 0, 0);
+ ELFDATA2MSB, PPC_ELF_MACHINE, 0, 0);
if (payload_size < 0) {
/*
* Hrm. No ELF image? Try a uImage, maybe someone is giving us an
diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c
index 6369961f78a..cb3dc3ab482 100644
--- a/hw/ppc/mac_newworld.c
+++ b/hw/ppc/mac_newworld.c
@@ -182,7 +182,8 @@ static void ppc_core99_init(MachineState *machine)
if (filename) {
/* Load OpenBIOS (ELF) */
bios_size = load_elf(filename, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0);
+ NULL, NULL, NULL,
+ ELFDATA2MSB, PPC_ELF_MACHINE, 0, 0);
if (bios_size <= 0) {
/* or load binary ROM image */
@@ -204,7 +205,7 @@ static void ppc_core99_init(MachineState *machine)
kernel_base = KERNEL_LOAD_ADDR;
kernel_size = load_elf(machine->kernel_filename, NULL,
translate_kernel_address, NULL, NULL, NULL,
- NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0);
+ NULL, NULL, ELFDATA2MSB, PPC_ELF_MACHINE, 0, 0);
if (kernel_size < 0) {
kernel_size = load_aout(machine->kernel_filename, kernel_base,
machine->ram_size - kernel_base,
diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c
index 59653e174b8..0dbcea035c3 100644
--- a/hw/ppc/mac_oldworld.c
+++ b/hw/ppc/mac_oldworld.c
@@ -136,7 +136,7 @@ static void ppc_heathrow_init(MachineState *machine)
if (filename) {
/* Load OpenBIOS (ELF) */
bios_size = load_elf(filename, NULL, NULL, NULL, NULL, &bios_addr,
- NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0);
+ NULL, NULL, ELFDATA2MSB, PPC_ELF_MACHINE, 0, 0);
/* Unfortunately, load_elf sign-extends reading elf32 */
bios_addr = (uint32_t)bios_addr;
@@ -161,7 +161,7 @@ static void ppc_heathrow_init(MachineState *machine)
kernel_base = KERNEL_LOAD_ADDR;
kernel_size = load_elf(machine->kernel_filename, NULL,
translate_kernel_address, NULL, NULL, NULL,
- NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0);
+ NULL, NULL, ELFDATA2MSB, PPC_ELF_MACHINE, 0, 0);
if (kernel_size < 0) {
kernel_size = load_aout(machine->kernel_filename, kernel_base,
machine->ram_size - kernel_base,
diff --git a/hw/ppc/pegasos2.c b/hw/ppc/pegasos2.c
index b3c21bdc57c..0364243f4fe 100644
--- a/hw/ppc/pegasos2.c
+++ b/hw/ppc/pegasos2.c
@@ -160,8 +160,8 @@ static void pegasos2_init(MachineState *machine)
}
memory_region_init_rom(rom, NULL, "pegasos2.rom", PROM_SIZE, &error_fatal);
memory_region_add_subregion(get_system_memory(), PROM_ADDR, rom);
- sz = load_elf(filename, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1,
- PPC_ELF_MACHINE, 0, 0);
+ sz = load_elf(filename, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ ELFDATA2MSB, PPC_ELF_MACHINE, 0, 0);
if (sz <= 0) {
sz = load_image_targphys(filename, pm->vof ? 0 : PROM_ADDR, PROM_SIZE);
}
@@ -239,8 +239,8 @@ static void pegasos2_init(MachineState *machine)
if (machine->kernel_filename) {
sz = load_elf(machine->kernel_filename, NULL, NULL, NULL,
- &pm->kernel_entry, &pm->kernel_addr, NULL, NULL, 1,
- PPC_ELF_MACHINE, 0, 0);
+ &pm->kernel_entry, &pm->kernel_addr, NULL, NULL,
+ ELFDATA2MSB, PPC_ELF_MACHINE, 0, 0);
if (sz <= 0) {
error_report("Could not load kernel '%s'",
machine->kernel_filename);
diff --git a/hw/ppc/ppc405_boards.c b/hw/ppc/ppc405_boards.c
index e9f65fab70d..969cac345ac 100644
--- a/hw/ppc/ppc405_boards.c
+++ b/hw/ppc/ppc405_boards.c
@@ -232,7 +232,7 @@ static void boot_from_kernel(MachineState *machine, PowerPCCPU *cpu)
kernel_size = load_elf(machine->kernel_filename, NULL, NULL, NULL,
&boot_entry, &kernel_base, NULL, NULL,
- 1, PPC_ELF_MACHINE, 0, 0);
+ ELFDATA2MSB, PPC_ELF_MACHINE, 0, 0);
if (kernel_size < 0) {
error_report("Could not load kernel '%s' : %s",
machine->kernel_filename, load_elf_strerror(kernel_size));
diff --git a/hw/ppc/ppc440_bamboo.c b/hw/ppc/ppc440_bamboo.c
index 45c5b8678d9..099fda39092 100644
--- a/hw/ppc/ppc440_bamboo.c
+++ b/hw/ppc/ppc440_bamboo.c
@@ -228,7 +228,8 @@ static void bamboo_init(MachineState *machine)
if (success < 0) {
uint64_t elf_entry;
success = load_elf(kernel_filename, NULL, NULL, NULL, &elf_entry,
- NULL, NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0);
+ NULL, NULL, NULL,
+ ELFDATA2MSB, PPC_ELF_MACHINE, 0, 0);
entry = elf_entry;
}
/* XXX try again as binary */
diff --git a/hw/ppc/sam460ex.c b/hw/ppc/sam460ex.c
index e74642a3b71..3ecae6a9504 100644
--- a/hw/ppc/sam460ex.c
+++ b/hw/ppc/sam460ex.c
@@ -479,7 +479,7 @@ static void sam460ex_init(MachineState *machine)
success = load_elf(machine->kernel_filename, NULL, NULL, NULL,
&elf_entry, NULL, NULL, NULL,
- 1, PPC_ELF_MACHINE, 0, 0);
+ ELFDATA2MSB, PPC_ELF_MACHINE, 0, 0);
entry = elf_entry;
}
/* XXX try again as binary */
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 623842f8064..f3a4b4235d4 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -3022,13 +3022,13 @@ static void spapr_machine_init(MachineState *machine)
spapr->kernel_size = load_elf(kernel_filename, NULL,
translate_kernel_address, spapr,
- NULL, &loaded_addr, NULL, NULL, 1,
- PPC_ELF_MACHINE, 0, 0);
+ NULL, &loaded_addr, NULL, NULL,
+ ELFDATA2MSB, PPC_ELF_MACHINE, 0, 0);
if (spapr->kernel_size == ELF_LOAD_WRONG_ENDIAN) {
spapr->kernel_size = load_elf(kernel_filename, NULL,
translate_kernel_address, spapr,
- NULL, &loaded_addr, NULL, NULL, 0,
- PPC_ELF_MACHINE, 0, 0);
+ NULL, &loaded_addr, NULL, NULL,
+ ELFDATA2LSB, PPC_ELF_MACHINE, 0, 0);
spapr->kernel_le = spapr->kernel_size > 0;
}
if (spapr->kernel_size < 0) {
diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c
index ea7ab8a5694..23238119273 100644
--- a/hw/ppc/virtex_ml507.c
+++ b/hw/ppc/virtex_ml507.c
@@ -242,8 +242,8 @@ static void virtex_init(MachineState *machine)
/* Boots a kernel elf binary. */
kernel_size = load_elf(kernel_filename, NULL, NULL, NULL,
- &entry, NULL, &high, NULL, 1, PPC_ELF_MACHINE,
- 0, 0);
+ &entry, NULL, &high, NULL,
+ ELFDATA2MSB, PPC_ELF_MACHINE, 0, 0);
boot_info.bootstrap_pc = entry & 0x00ffffff;
if (kernel_size < 0) {
diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c
index 4aa21c91fca..ce6f6078d74 100644
--- a/hw/s390x/ipl.c
+++ b/hw/s390x/ipl.c
@@ -162,8 +162,8 @@ static void s390_ipl_realize(DeviceState *dev, Error **errp)
bios_size = load_elf(bios_filename, NULL,
bios_translate_addr, &fwbase,
- &ipl->bios_start_addr, NULL, NULL, NULL, 1,
- EM_S390, 0, 0);
+ &ipl->bios_start_addr, NULL, NULL, NULL,
+ ELFDATA2MSB, EM_S390, 0, 0);
if (bios_size > 0) {
/* Adjust ELF start address to final location */
ipl->bios_start_addr += fwbase;
@@ -187,7 +187,7 @@ static void s390_ipl_realize(DeviceState *dev, Error **errp)
if (ipl->kernel) {
kernel_size = load_elf(ipl->kernel, NULL, NULL, NULL,
&pentry, NULL,
- NULL, NULL, 1, EM_S390, 0, 0);
+ NULL, NULL, ELFDATA2MSB, EM_S390, 0, 0);
if (kernel_size < 0) {
kernel_size = load_image_targphys(ipl->kernel, 0, ms->ram_size);
if (kernel_size < 0) {
diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
index 84381254ad0..0aeaad3becc 100644
--- a/hw/sparc/leon3.c
+++ b/hw/sparc/leon3.c
@@ -380,7 +380,7 @@ static void leon3_generic_hw_init(MachineState *machine)
kernel_size = load_elf(kernel_filename, NULL, NULL, NULL,
&entry, NULL, NULL, NULL,
- 1 /* big endian */, EM_SPARC, 0, 0);
+ ELFDATA2MSB, EM_SPARC, 0, 0);
if (kernel_size < 0) {
kernel_size = load_uimage(kernel_filename, NULL, &entry,
NULL, NULL, NULL);
diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index e070360a2c7..a48d3622c5a 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -242,7 +242,8 @@ static unsigned long sun4m_load_kernel(const char *kernel_filename,
#endif
kernel_size = load_elf(kernel_filename, NULL,
translate_kernel_address, NULL,
- NULL, NULL, NULL, NULL, 1, EM_SPARC, 0, 0);
+ NULL, NULL, NULL, NULL,
+ ELFDATA2MSB, EM_SPARC, 0, 0);
if (kernel_size < 0)
kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR,
RAM_size - KERNEL_LOAD_ADDR, bswap_needed,
@@ -703,7 +704,7 @@ static void prom_init(hwaddr addr, const char *bios_name)
if (filename) {
ret = load_elf(filename, NULL,
translate_prom_address, &addr, NULL,
- NULL, NULL, NULL, 1, EM_SPARC, 0, 0);
+ NULL, NULL, NULL, ELFDATA2MSB, EM_SPARC, 0, 0);
if (ret < 0 || ret > PROM_SIZE_MAX) {
ret = load_image_targphys(filename, addr, PROM_SIZE_MAX);
}
diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c
index 0980b446593..8ab5cf0461f 100644
--- a/hw/sparc64/sun4u.c
+++ b/hw/sparc64/sun4u.c
@@ -176,8 +176,8 @@ static uint64_t sun4u_load_kernel(const char *kernel_filename,
bswap_needed = 0;
#endif
kernel_size = load_elf(kernel_filename, NULL, NULL, NULL, kernel_entry,
- kernel_addr, &kernel_top, NULL, 1, EM_SPARCV9, 0,
- 0);
+ kernel_addr, &kernel_top, NULL,
+ ELFDATA2MSB, EM_SPARCV9, 0, 0);
if (kernel_size < 0) {
*kernel_addr = KERNEL_LOAD_ADDR;
*kernel_entry = KERNEL_LOAD_ADDR;
@@ -441,7 +441,7 @@ static void prom_init(hwaddr addr, const char *bios_name)
filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
if (filename) {
ret = load_elf(filename, NULL, translate_prom_address, &addr,
- NULL, NULL, NULL, NULL, 1, EM_SPARCV9, 0, 0);
+ NULL, NULL, NULL, NULL, ELFDATA2MSB, EM_SPARCV9, 0, 0);
if (ret < 0 || ret > PROM_SIZE_MAX) {
ret = load_image_targphys(filename, addr, PROM_SIZE_MAX);
}
diff --git a/hw/tricore/triboard.c b/hw/tricore/triboard.c
index 9cc8d282ff2..f5baa8ccbb3 100644
--- a/hw/tricore/triboard.c
+++ b/hw/tricore/triboard.c
@@ -39,7 +39,7 @@ static void tricore_load_kernel(TriCoreCPU *cpu, const char *kernel_filename)
kernel_size = load_elf(kernel_filename, NULL,
NULL, NULL, &entry, NULL,
- NULL, NULL, 0,
+ NULL, NULL, ELFDATA2LSB,
EM_TRICORE, 1, 0);
if (kernel_size <= 0) {
error_report("no kernel file '%s'", kernel_filename);
diff --git a/hw/tricore/tricore_testboard.c b/hw/tricore/tricore_testboard.c
index c29db8b451c..3facfdfd611 100644
--- a/hw/tricore/tricore_testboard.c
+++ b/hw/tricore/tricore_testboard.c
@@ -42,7 +42,7 @@ static void tricore_load_kernel(CPUTriCoreState *env)
kernel_size = load_elf(tricoretb_binfo.kernel_filename, NULL,
NULL, NULL, &entry, NULL,
- NULL, NULL, 0,
+ NULL, NULL, ELFDATA2LSB,
EM_TRICORE, 1, 0);
if (kernel_size <= 0) {
error_report("no kernel file '%s'",
diff --git a/hw/xtensa/sim.c b/hw/xtensa/sim.c
index 0a1fd900376..1cea29c66d4 100644
--- a/hw/xtensa/sim.c
+++ b/hw/xtensa/sim.c
@@ -100,7 +100,8 @@ void xtensa_sim_load_kernel(XtensaCPU *cpu, MachineState *machine)
if (kernel_filename) {
uint64_t elf_entry;
int success = load_elf(kernel_filename, NULL, translate_phys_addr, cpu,
- &elf_entry, NULL, NULL, NULL, TARGET_BIG_ENDIAN,
+ &elf_entry, NULL, NULL, NULL,
+ TARGET_BIG_ENDIAN ? ELFDATA2MSB : ELFDATA2LSB,
EM_XTENSA, 0, 0);
if (success > 0) {
diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
index 9efe91933f9..3f3677f1c9a 100644
--- a/hw/xtensa/xtfpga.c
+++ b/hw/xtensa/xtfpga.c
@@ -398,7 +398,8 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
uint64_t elf_entry;
int success = load_elf(kernel_filename, NULL, translate_phys_addr, cpu,
- &elf_entry, NULL, NULL, NULL, TARGET_BIG_ENDIAN,
+ &elf_entry, NULL, NULL, NULL,
+ TARGET_BIG_ENDIAN ? ELFDATA2MSB : ELFDATA2LSB,
EM_XTENSA, 0, 0);
if (success > 0) {
entry_point = elf_entry;
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 26/36] hw/sd/omap_mmc: Do a minimal conversion to QDev
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (24 preceding siblings ...)
2025-01-31 21:05 ` [PULL 25/36] hw/loader: Pass ELFDATA endian order argument to load_elf() Philippe Mathieu-Daudé
@ 2025-01-31 21:05 ` Philippe Mathieu-Daudé
2025-01-31 21:05 ` [PULL 27/36] hw/sd/omap_mmc: Convert remaining 'struct omap_mmc_s' uses to OMAPMMCState Philippe Mathieu-Daudé
` (10 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:05 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Richard Henderson, Philippe Mathieu-Daudé
From: Peter Maydell <peter.maydell@linaro.org>
Do a minimal conversion of the omap_mmc device model to QDev.
In this commit we do the bare minimum to produce a working device:
* add the SysBusDevice parent_obj and the usual type boilerplate
* omap_mmc_init() now returns a DeviceState*
* reset is handled by sysbus reset, so the SoC reset function
doesn't need to call omap_mmc_reset() any more
* code that should obviously be in init/realize is moved there
from omap_mmc_init()
We leave various pieces of cleanup to later commits:
* rationalizing 'struct omap_mmc_s *' to 'OMAPMMCState *'
* using gpio lines rather than having omap_mmc_init() directly
set s->irq, s->dma
* switching away from the legacy SD API and instead having
the SD card plugged into a bus
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20250128104519.3981448-2-peter.maydell@linaro.org>
[PMD: Do not add omap_mmc_realize()]
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/hw/arm/omap.h | 15 +++++----
hw/arm/omap1.c | 1 -
hw/sd/omap_mmc.c | 77 ++++++++++++++++++++++++++++++++++---------
3 files changed, 70 insertions(+), 23 deletions(-)
diff --git a/include/hw/arm/omap.h b/include/hw/arm/omap.h
index 420ed1d5735..6339c5a581e 100644
--- a/include/hw/arm/omap.h
+++ b/include/hw/arm/omap.h
@@ -529,12 +529,13 @@ struct omap_lcd_panel_s *omap_lcdc_init(MemoryRegion *sysmem,
omap_clk clk);
/* omap_mmc.c */
-struct omap_mmc_s;
-struct omap_mmc_s *omap_mmc_init(hwaddr base,
- MemoryRegion *sysmem,
- BlockBackend *blk,
- qemu_irq irq, qemu_irq dma[], omap_clk clk);
-void omap_mmc_reset(struct omap_mmc_s *s);
+#define TYPE_OMAP_MMC "omap-mmc"
+OBJECT_DECLARE_SIMPLE_TYPE(omap_mmc_s, OMAP_MMC)
+
+DeviceState *omap_mmc_init(hwaddr base,
+ MemoryRegion *sysmem,
+ BlockBackend *blk,
+ qemu_irq irq, qemu_irq dma[], omap_clk clk);
/* omap_i2c.c */
I2CBus *omap_i2c_bus(DeviceState *omap_i2c);
@@ -601,7 +602,7 @@ struct omap_mpu_state_s {
/* MPU public TIPB peripherals */
struct omap_32khz_timer_s *os_timer;
- struct omap_mmc_s *mmc;
+ DeviceState *mmc;
struct omap_mpuio_s *mpuio;
diff --git a/hw/arm/omap1.c b/hw/arm/omap1.c
index f3a0ac40e48..ea07b9aa31e 100644
--- a/hw/arm/omap1.c
+++ b/hw/arm/omap1.c
@@ -3716,7 +3716,6 @@ static void omap1_mpu_reset(void *opaque)
omap_uart_reset(mpu->uart[0]);
omap_uart_reset(mpu->uart[1]);
omap_uart_reset(mpu->uart[2]);
- omap_mmc_reset(mpu->mmc);
omap_mpuio_reset(mpu->mpuio);
omap_uwire_reset(mpu->microwire);
omap_pwl_reset(mpu->pwl);
diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c
index 1d4e30e6b7b..fec2cfd4d66 100644
--- a/hw/sd/omap_mmc.c
+++ b/hw/sd/omap_mmc.c
@@ -21,11 +21,15 @@
#include "qemu/osdep.h"
#include "qemu/log.h"
+#include "qapi/error.h"
#include "hw/irq.h"
+#include "hw/sysbus.h"
#include "hw/arm/omap.h"
#include "hw/sd/sdcard_legacy.h"
-struct omap_mmc_s {
+typedef struct omap_mmc_s {
+ SysBusDevice parent_obj;
+
qemu_irq irq;
qemu_irq *dma;
qemu_irq coverswitch;
@@ -66,7 +70,7 @@ struct omap_mmc_s {
int cdet_enable;
int cdet_state;
qemu_irq cdet;
-};
+} OMAPMMCState;
static void omap_mmc_interrupts_update(struct omap_mmc_s *s)
{
@@ -297,7 +301,7 @@ static void omap_mmc_pseudo_reset(struct omap_mmc_s *host)
host->fifo_len = 0;
}
-void omap_mmc_reset(struct omap_mmc_s *host)
+static void omap_mmc_reset(struct omap_mmc_s *host)
{
host->last_cmd = 0;
memset(host->rsp, 0, sizeof(host->rsp));
@@ -328,7 +332,9 @@ void omap_mmc_reset(struct omap_mmc_s *host)
* into any bus, and we must reset it manually. When omap_mmc is
* QOMified this must move into the QOM reset function.
*/
- device_cold_reset(DEVICE(host->card));
+ if (host->card) {
+ device_cold_reset(DEVICE(host->card));
+ }
}
static uint64_t omap_mmc_read(void *opaque, hwaddr offset, unsigned size)
@@ -583,29 +589,70 @@ static const MemoryRegionOps omap_mmc_ops = {
.endianness = DEVICE_NATIVE_ENDIAN,
};
-struct omap_mmc_s *omap_mmc_init(hwaddr base,
- MemoryRegion *sysmem,
- BlockBackend *blk,
- qemu_irq irq, qemu_irq dma[], omap_clk clk)
+DeviceState *omap_mmc_init(hwaddr base,
+ MemoryRegion *sysmem,
+ BlockBackend *blk,
+ qemu_irq irq, qemu_irq dma[], omap_clk clk)
{
- struct omap_mmc_s *s = g_new0(struct omap_mmc_s, 1);
+ DeviceState *dev;
+ OMAPMMCState *s;
+
+ dev = qdev_new(TYPE_OMAP_MMC);
+ s = OMAP_MMC(dev);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(s), &error_fatal);
s->irq = irq;
s->dma = dma;
s->clk = clk;
- s->lines = 1; /* TODO: needs to be settable per-board */
- s->rev = 1;
- memory_region_init_io(&s->iomem, NULL, &omap_mmc_ops, s, "omap.mmc", 0x800);
- memory_region_add_subregion(sysmem, base, &s->iomem);
+ memory_region_add_subregion(sysmem, base,
+ sysbus_mmio_get_region(SYS_BUS_DEVICE(s), 0));
/* Instantiate the storage */
s->card = sd_init(blk, false);
if (s->card == NULL) {
exit(1);
}
+ return dev;
+}
+
+static void omap_mmc_reset_hold(Object *obj, ResetType type)
+{
+ OMAPMMCState *s = OMAP_MMC(obj);
omap_mmc_reset(s);
-
- return s;
}
+
+static void omap_mmc_initfn(Object *obj)
+{
+ OMAPMMCState *s = OMAP_MMC(obj);
+
+ /* In theory these could be settable per-board */
+ s->lines = 1;
+ s->rev = 1;
+
+ memory_region_init_io(&s->iomem, obj, &omap_mmc_ops, s, "omap.mmc", 0x800);
+ sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem);
+}
+
+static void omap_mmc_class_init(ObjectClass *oc, void *data)
+{
+ ResettableClass *rc = RESETTABLE_CLASS(oc);
+
+ rc->phases.hold = omap_mmc_reset_hold;
+}
+
+static const TypeInfo omap_mmc_info = {
+ .name = TYPE_OMAP_MMC,
+ .parent = TYPE_SYS_BUS_DEVICE,
+ .instance_size = sizeof(OMAPMMCState),
+ .instance_init = omap_mmc_initfn,
+ .class_init = omap_mmc_class_init,
+};
+
+static void omap_mmc_register_types(void)
+{
+ type_register_static(&omap_mmc_info);
+}
+
+type_init(omap_mmc_register_types)
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 27/36] hw/sd/omap_mmc: Convert remaining 'struct omap_mmc_s' uses to OMAPMMCState
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (25 preceding siblings ...)
2025-01-31 21:05 ` [PULL 26/36] hw/sd/omap_mmc: Do a minimal conversion to QDev Philippe Mathieu-Daudé
@ 2025-01-31 21:05 ` Philippe Mathieu-Daudé
2025-01-31 21:05 ` [PULL 28/36] hw/sd/omap_mmc: Convert output qemu_irqs to gpio and sysbus IRQ APIs Philippe Mathieu-Daudé
` (9 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:05 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Richard Henderson, Philippe Mathieu-Daudé
From: Peter Maydell <peter.maydell@linaro.org>
Mechanically convert the remaining uses of 'struct omap_mmc_s' to
'OMAPMMCState'.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20250128104519.3981448-3-peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/hw/arm/omap.h | 2 +-
hw/sd/omap_mmc.c | 20 ++++++++++----------
2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/include/hw/arm/omap.h b/include/hw/arm/omap.h
index 6339c5a581e..7d1a1afc4f8 100644
--- a/include/hw/arm/omap.h
+++ b/include/hw/arm/omap.h
@@ -530,7 +530,7 @@ struct omap_lcd_panel_s *omap_lcdc_init(MemoryRegion *sysmem,
/* omap_mmc.c */
#define TYPE_OMAP_MMC "omap-mmc"
-OBJECT_DECLARE_SIMPLE_TYPE(omap_mmc_s, OMAP_MMC)
+OBJECT_DECLARE_SIMPLE_TYPE(OMAPMMCState, OMAP_MMC)
DeviceState *omap_mmc_init(hwaddr base,
MemoryRegion *sysmem,
diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c
index fec2cfd4d66..0f17479ecb8 100644
--- a/hw/sd/omap_mmc.c
+++ b/hw/sd/omap_mmc.c
@@ -27,7 +27,7 @@
#include "hw/arm/omap.h"
#include "hw/sd/sdcard_legacy.h"
-typedef struct omap_mmc_s {
+typedef struct OMAPMMCState {
SysBusDevice parent_obj;
qemu_irq irq;
@@ -72,12 +72,12 @@ typedef struct omap_mmc_s {
qemu_irq cdet;
} OMAPMMCState;
-static void omap_mmc_interrupts_update(struct omap_mmc_s *s)
+static void omap_mmc_interrupts_update(OMAPMMCState *s)
{
qemu_set_irq(s->irq, !!(s->status & s->mask));
}
-static void omap_mmc_fifolevel_update(struct omap_mmc_s *host)
+static void omap_mmc_fifolevel_update(OMAPMMCState *host)
{
if (!host->transfer && !host->fifo_len) {
host->status &= 0xf3ff;
@@ -125,7 +125,7 @@ typedef enum {
SD_TYPE_ADTC = 3, /* addressed with data transfer */
} MMCCmdType;
-static void omap_mmc_command(struct omap_mmc_s *host, int cmd, int dir,
+static void omap_mmc_command(OMAPMMCState *host, int cmd, int dir,
MMCCmdType type, int busy,
sd_rsp_type_t resptype, int init)
{
@@ -234,7 +234,7 @@ static void omap_mmc_command(struct omap_mmc_s *host, int cmd, int dir,
host->status |= 0x0001;
}
-static void omap_mmc_transfer(struct omap_mmc_s *host)
+static void omap_mmc_transfer(OMAPMMCState *host)
{
uint8_t value;
@@ -289,19 +289,19 @@ static void omap_mmc_transfer(struct omap_mmc_s *host)
static void omap_mmc_update(void *opaque)
{
- struct omap_mmc_s *s = opaque;
+ OMAPMMCState *s = opaque;
omap_mmc_transfer(s);
omap_mmc_fifolevel_update(s);
omap_mmc_interrupts_update(s);
}
-static void omap_mmc_pseudo_reset(struct omap_mmc_s *host)
+static void omap_mmc_pseudo_reset(OMAPMMCState *host)
{
host->status = 0;
host->fifo_len = 0;
}
-static void omap_mmc_reset(struct omap_mmc_s *host)
+static void omap_mmc_reset(OMAPMMCState *host)
{
host->last_cmd = 0;
memset(host->rsp, 0, sizeof(host->rsp));
@@ -340,7 +340,7 @@ static void omap_mmc_reset(struct omap_mmc_s *host)
static uint64_t omap_mmc_read(void *opaque, hwaddr offset, unsigned size)
{
uint16_t i;
- struct omap_mmc_s *s = opaque;
+ OMAPMMCState *s = opaque;
if (size != 2) {
return omap_badwidth_read16(opaque, offset);
@@ -433,7 +433,7 @@ static void omap_mmc_write(void *opaque, hwaddr offset,
uint64_t value, unsigned size)
{
int i;
- struct omap_mmc_s *s = opaque;
+ OMAPMMCState *s = opaque;
if (size != 2) {
omap_badwidth_write16(opaque, offset, value);
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 28/36] hw/sd/omap_mmc: Convert output qemu_irqs to gpio and sysbus IRQ APIs
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (26 preceding siblings ...)
2025-01-31 21:05 ` [PULL 27/36] hw/sd/omap_mmc: Convert remaining 'struct omap_mmc_s' uses to OMAPMMCState Philippe Mathieu-Daudé
@ 2025-01-31 21:05 ` Philippe Mathieu-Daudé
2025-01-31 21:05 ` [PULL 29/36] hw/sd/omap_mmc: Convert to SDBus API Philippe Mathieu-Daudé
` (8 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:05 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Richard Henderson, Philippe Mathieu-Daudé
From: Peter Maydell <peter.maydell@linaro.org>
The omap_mmc device has three outbound qemu_irq lines:
* one actual interrupt line
* two which connect to the DMA controller and are signalled for
TX and RX DMA
Convert these to a sysbus IRQ and two named GPIO outputs.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20250128104519.3981448-4-peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/sd/omap_mmc.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c
index 0f17479ecb8..43203a76c58 100644
--- a/hw/sd/omap_mmc.c
+++ b/hw/sd/omap_mmc.c
@@ -31,7 +31,8 @@ typedef struct OMAPMMCState {
SysBusDevice parent_obj;
qemu_irq irq;
- qemu_irq *dma;
+ qemu_irq dma_tx_gpio;
+ qemu_irq dma_rx_gpio;
qemu_irq coverswitch;
MemoryRegion iomem;
omap_clk clk;
@@ -87,22 +88,22 @@ static void omap_mmc_fifolevel_update(OMAPMMCState *host)
if (host->fifo_len > host->af_level && host->ddir) {
if (host->rx_dma) {
host->status &= 0xfbff;
- qemu_irq_raise(host->dma[1]);
+ qemu_irq_raise(host->dma_rx_gpio);
} else
host->status |= 0x0400;
} else {
host->status &= 0xfbff;
- qemu_irq_lower(host->dma[1]);
+ qemu_irq_lower(host->dma_rx_gpio);
}
if (host->fifo_len < host->ae_level && !host->ddir) {
if (host->tx_dma) {
host->status &= 0xf7ff;
- qemu_irq_raise(host->dma[0]);
+ qemu_irq_raise(host->dma_tx_gpio);
} else
host->status |= 0x0800;
} else {
- qemu_irq_lower(host->dma[0]);
+ qemu_irq_lower(host->dma_tx_gpio);
host->status &= 0xf7ff;
}
}
@@ -601,12 +602,13 @@ DeviceState *omap_mmc_init(hwaddr base,
s = OMAP_MMC(dev);
sysbus_realize_and_unref(SYS_BUS_DEVICE(s), &error_fatal);
- s->irq = irq;
- s->dma = dma;
s->clk = clk;
memory_region_add_subregion(sysmem, base,
sysbus_mmio_get_region(SYS_BUS_DEVICE(s), 0));
+ qdev_connect_gpio_out_named(dev, "dma-tx", 0, dma[0]);
+ qdev_connect_gpio_out_named(dev, "dma-rx", 0, dma[1]);
+ sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq);
/* Instantiate the storage */
s->card = sd_init(blk, false);
@@ -633,6 +635,10 @@ static void omap_mmc_initfn(Object *obj)
memory_region_init_io(&s->iomem, obj, &omap_mmc_ops, s, "omap.mmc", 0x800);
sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem);
+
+ sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->irq);
+ qdev_init_gpio_out_named(DEVICE(obj), &s->dma_tx_gpio, "dma-tx", 1);
+ qdev_init_gpio_out_named(DEVICE(obj), &s->dma_rx_gpio, "dma-rx", 1);
}
static void omap_mmc_class_init(ObjectClass *oc, void *data)
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 29/36] hw/sd/omap_mmc: Convert to SDBus API
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (27 preceding siblings ...)
2025-01-31 21:05 ` [PULL 28/36] hw/sd/omap_mmc: Convert output qemu_irqs to gpio and sysbus IRQ APIs Philippe Mathieu-Daudé
@ 2025-01-31 21:05 ` Philippe Mathieu-Daudé
2025-01-31 21:05 ` [PULL 30/36] hw/sd/omap_mmc: Use similar API for "wire up omap_clk" to other OMAP devices Philippe Mathieu-Daudé
` (7 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:05 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Philippe Mathieu-Daudé
From: Peter Maydell <peter.maydell@linaro.org>
Convert the OMAP MMC controller to the new SDBus API:
* the controller creates an SDBus bus
* instead of sd_foo functions on the SDState object, call
sdbus_foo functions on the SDBus
* the board code creates a proper TYPE_SD_CARD object and attaches
it to the controller's SDBus, instead of the controller creating
a card directly via sd_init() that never gets attached to any bus
* because the SD card object is on a bus, it gets reset automatically
by the "traverse the qbus tree resetting things" code, and we don't
need to manually reset the card from the controller reset function
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20250128104519.3981448-5-peter.maydell@linaro.org>
[PMD: Include "hw/sd/sd.h" instead of "hw/sd/sdcard_legacy.h",
create bus in omap_mmc_initfn() instead of omap_mmc_realize()]
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/hw/arm/omap.h | 1 -
hw/arm/omap1.c | 10 +++++++++-
hw/sd/omap_mmc.c | 31 ++++++++++---------------------
3 files changed, 19 insertions(+), 23 deletions(-)
diff --git a/include/hw/arm/omap.h b/include/hw/arm/omap.h
index 7d1a1afc4f8..d20c55a8957 100644
--- a/include/hw/arm/omap.h
+++ b/include/hw/arm/omap.h
@@ -534,7 +534,6 @@ OBJECT_DECLARE_SIMPLE_TYPE(OMAPMMCState, OMAP_MMC)
DeviceState *omap_mmc_init(hwaddr base,
MemoryRegion *sysmem,
- BlockBackend *blk,
qemu_irq irq, qemu_irq dma[], omap_clk clk);
/* omap_i2c.c */
diff --git a/hw/arm/omap1.c b/hw/arm/omap1.c
index ea07b9aa31e..15ba0a0d0c4 100644
--- a/hw/arm/omap1.c
+++ b/hw/arm/omap1.c
@@ -29,6 +29,7 @@
#include "hw/qdev-properties.h"
#include "hw/arm/boot.h"
#include "hw/arm/omap.h"
+#include "hw/sd/sd.h"
#include "system/blockdev.h"
#include "system/system.h"
#include "hw/arm/soc_dma.h"
@@ -3981,11 +3982,18 @@ struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *dram,
warn_report("missing SecureDigital device");
}
s->mmc = omap_mmc_init(0xfffb7800, system_memory,
- dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
qdev_get_gpio_in(s->ih[1], OMAP_INT_OQN),
&s->drq[OMAP_DMA_MMC_TX],
omap_findclk(s, "mmc_ck"));
+ if (dinfo) {
+ DeviceState *card = qdev_new(TYPE_SD_CARD);
+ qdev_prop_set_drive_err(card, "drive", blk_by_legacy_dinfo(dinfo),
+ &error_fatal);
+ qdev_realize_and_unref(card, qdev_get_child_bus(s->mmc, "sd-bus"),
+ &error_fatal);
+ }
+
s->mpuio = omap_mpuio_init(system_memory, 0xfffb5000,
qdev_get_gpio_in(s->ih[1], OMAP_INT_KEYBOARD),
qdev_get_gpio_in(s->ih[1], OMAP_INT_MPUIO),
diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c
index 43203a76c58..1bc8290f9d6 100644
--- a/hw/sd/omap_mmc.c
+++ b/hw/sd/omap_mmc.c
@@ -25,18 +25,19 @@
#include "hw/irq.h"
#include "hw/sysbus.h"
#include "hw/arm/omap.h"
-#include "hw/sd/sdcard_legacy.h"
+#include "hw/sd/sd.h"
typedef struct OMAPMMCState {
SysBusDevice parent_obj;
+ SDBus sdbus;
+
qemu_irq irq;
qemu_irq dma_tx_gpio;
qemu_irq dma_rx_gpio;
qemu_irq coverswitch;
MemoryRegion iomem;
omap_clk clk;
- SDState *card;
uint16_t last_cmd;
uint16_t sdio;
uint16_t rsp[8];
@@ -158,7 +159,7 @@ static void omap_mmc_command(OMAPMMCState *host, int cmd, int dir,
request.arg = host->arg;
request.crc = 0; /* FIXME */
- rsplen = sd_do_command(host->card, &request, response);
+ rsplen = sdbus_do_command(&host->sdbus, &request, response);
/* TODO: validate CRCs */
switch (resptype) {
@@ -247,10 +248,10 @@ static void omap_mmc_transfer(OMAPMMCState *host)
if (host->fifo_len > host->af_level)
break;
- value = sd_read_byte(host->card);
+ value = sdbus_read_byte(&host->sdbus);
host->fifo[(host->fifo_start + host->fifo_len) & 31] = value;
if (-- host->blen_counter) {
- value = sd_read_byte(host->card);
+ value = sdbus_read_byte(&host->sdbus);
host->fifo[(host->fifo_start + host->fifo_len) & 31] |=
value << 8;
host->blen_counter --;
@@ -262,10 +263,10 @@ static void omap_mmc_transfer(OMAPMMCState *host)
break;
value = host->fifo[host->fifo_start] & 0xff;
- sd_write_byte(host->card, value);
+ sdbus_write_byte(&host->sdbus, value);
if (-- host->blen_counter) {
value = host->fifo[host->fifo_start] >> 8;
- sd_write_byte(host->card, value);
+ sdbus_write_byte(&host->sdbus, value);
host->blen_counter --;
}
@@ -328,14 +329,6 @@ static void omap_mmc_reset(OMAPMMCState *host)
host->clkdiv = 0;
omap_mmc_pseudo_reset(host);
-
- /* Since we're still using the legacy SD API the card is not plugged
- * into any bus, and we must reset it manually. When omap_mmc is
- * QOMified this must move into the QOM reset function.
- */
- if (host->card) {
- device_cold_reset(DEVICE(host->card));
- }
}
static uint64_t omap_mmc_read(void *opaque, hwaddr offset, unsigned size)
@@ -592,7 +585,6 @@ static const MemoryRegionOps omap_mmc_ops = {
DeviceState *omap_mmc_init(hwaddr base,
MemoryRegion *sysmem,
- BlockBackend *blk,
qemu_irq irq, qemu_irq dma[], omap_clk clk)
{
DeviceState *dev;
@@ -610,11 +602,6 @@ DeviceState *omap_mmc_init(hwaddr base,
qdev_connect_gpio_out_named(dev, "dma-rx", 0, dma[1]);
sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq);
- /* Instantiate the storage */
- s->card = sd_init(blk, false);
- if (s->card == NULL) {
- exit(1);
- }
return dev;
}
@@ -639,6 +626,8 @@ static void omap_mmc_initfn(Object *obj)
sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->irq);
qdev_init_gpio_out_named(DEVICE(obj), &s->dma_tx_gpio, "dma-tx", 1);
qdev_init_gpio_out_named(DEVICE(obj), &s->dma_rx_gpio, "dma-rx", 1);
+
+ qbus_init(&s->sdbus, sizeof(s->sdbus), TYPE_SD_BUS, DEVICE(obj), "sd-bus");
}
static void omap_mmc_class_init(ObjectClass *oc, void *data)
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 30/36] hw/sd/omap_mmc: Use similar API for "wire up omap_clk" to other OMAP devices
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (28 preceding siblings ...)
2025-01-31 21:05 ` [PULL 29/36] hw/sd/omap_mmc: Convert to SDBus API Philippe Mathieu-Daudé
@ 2025-01-31 21:05 ` Philippe Mathieu-Daudé
2025-01-31 21:05 ` [PULL 31/36] hw/arm/omap1: Inline creation of MMC Philippe Mathieu-Daudé
` (6 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:05 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Philippe Mathieu-Daudé
From: Peter Maydell <peter.maydell@linaro.org>
The approach we've settled on for handling the omap_clk wiring for
OMAP devices converted to QDev is to have a function omap_foo_set_clk()
whose implementation just sets the field directly in the device's
state struct. (See the "TODO" comment near the top of omap.h.)
Make omap_mmc do the same.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20250128104519.3981448-6-peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/hw/arm/omap.h | 3 +++
hw/sd/omap_mmc.c | 9 ++++++++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/include/hw/arm/omap.h b/include/hw/arm/omap.h
index d20c55a8957..7cb87ea89cd 100644
--- a/include/hw/arm/omap.h
+++ b/include/hw/arm/omap.h
@@ -535,6 +535,9 @@ OBJECT_DECLARE_SIMPLE_TYPE(OMAPMMCState, OMAP_MMC)
DeviceState *omap_mmc_init(hwaddr base,
MemoryRegion *sysmem,
qemu_irq irq, qemu_irq dma[], omap_clk clk);
+/* TODO: clock framework (see above) */
+void omap_mmc_set_clk(DeviceState *dev, omap_clk clk);
+
/* omap_i2c.c */
I2CBus *omap_i2c_bus(DeviceState *omap_i2c);
diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c
index 1bc8290f9d6..c6b8cf65d71 100644
--- a/hw/sd/omap_mmc.c
+++ b/hw/sd/omap_mmc.c
@@ -583,6 +583,13 @@ static const MemoryRegionOps omap_mmc_ops = {
.endianness = DEVICE_NATIVE_ENDIAN,
};
+void omap_mmc_set_clk(DeviceState *dev, omap_clk clk)
+{
+ OMAPMMCState *s = OMAP_MMC(dev);
+
+ s->clk = clk;
+}
+
DeviceState *omap_mmc_init(hwaddr base,
MemoryRegion *sysmem,
qemu_irq irq, qemu_irq dma[], omap_clk clk)
@@ -594,7 +601,7 @@ DeviceState *omap_mmc_init(hwaddr base,
s = OMAP_MMC(dev);
sysbus_realize_and_unref(SYS_BUS_DEVICE(s), &error_fatal);
- s->clk = clk;
+ omap_mmc_set_clk(dev, clk);
memory_region_add_subregion(sysmem, base,
sysbus_mmio_get_region(SYS_BUS_DEVICE(s), 0));
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 31/36] hw/arm/omap1: Inline creation of MMC
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (29 preceding siblings ...)
2025-01-31 21:05 ` [PULL 30/36] hw/sd/omap_mmc: Use similar API for "wire up omap_clk" to other OMAP devices Philippe Mathieu-Daudé
@ 2025-01-31 21:05 ` Philippe Mathieu-Daudé
2025-01-31 21:05 ` [PULL 32/36] hw/sd/omap_mmc: Remove unused coverswitch qemu_irq Philippe Mathieu-Daudé
` (5 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:05 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Richard Henderson, Philippe Mathieu-Daudé
From: Peter Maydell <peter.maydell@linaro.org>
Our style for other conversions of OMAP devices to qdev has been to
inline the creation and wiring into omap310_mpu_init() -- see for
instance the handling of omap-intc, omap-gpio and omap_i2c. Do
the same for omap-mmc.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20250128104519.3981448-7-peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/arm/omap1.c | 15 +++++++++++----
hw/sd/omap_mmc.c | 22 ----------------------
2 files changed, 11 insertions(+), 26 deletions(-)
diff --git a/hw/arm/omap1.c b/hw/arm/omap1.c
index 15ba0a0d0c4..ca2eb0d1576 100644
--- a/hw/arm/omap1.c
+++ b/hw/arm/omap1.c
@@ -3981,10 +3981,17 @@ struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *dram,
if (!dinfo && !qtest_enabled()) {
warn_report("missing SecureDigital device");
}
- s->mmc = omap_mmc_init(0xfffb7800, system_memory,
- qdev_get_gpio_in(s->ih[1], OMAP_INT_OQN),
- &s->drq[OMAP_DMA_MMC_TX],
- omap_findclk(s, "mmc_ck"));
+
+ s->mmc = qdev_new(TYPE_OMAP_MMC);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(s->mmc), &error_fatal);
+ omap_mmc_set_clk(s->mmc, omap_findclk(s, "mmc_ck"));
+
+ memory_region_add_subregion(system_memory, 0xfffb7800,
+ sysbus_mmio_get_region(SYS_BUS_DEVICE(s->mmc), 0));
+ qdev_connect_gpio_out_named(s->mmc, "dma-tx", 0, s->drq[OMAP_DMA_MMC_TX]);
+ qdev_connect_gpio_out_named(s->mmc, "dma-rx", 0, s->drq[OMAP_DMA_MMC_RX]);
+ sysbus_connect_irq(SYS_BUS_DEVICE(s->mmc), 0,
+ qdev_get_gpio_in(s->ih[1], OMAP_INT_OQN));
if (dinfo) {
DeviceState *card = qdev_new(TYPE_SD_CARD);
diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c
index c6b8cf65d71..a8b541ca788 100644
--- a/hw/sd/omap_mmc.c
+++ b/hw/sd/omap_mmc.c
@@ -590,28 +590,6 @@ void omap_mmc_set_clk(DeviceState *dev, omap_clk clk)
s->clk = clk;
}
-DeviceState *omap_mmc_init(hwaddr base,
- MemoryRegion *sysmem,
- qemu_irq irq, qemu_irq dma[], omap_clk clk)
-{
- DeviceState *dev;
- OMAPMMCState *s;
-
- dev = qdev_new(TYPE_OMAP_MMC);
- s = OMAP_MMC(dev);
- sysbus_realize_and_unref(SYS_BUS_DEVICE(s), &error_fatal);
-
- omap_mmc_set_clk(dev, clk);
-
- memory_region_add_subregion(sysmem, base,
- sysbus_mmio_get_region(SYS_BUS_DEVICE(s), 0));
- qdev_connect_gpio_out_named(dev, "dma-tx", 0, dma[0]);
- qdev_connect_gpio_out_named(dev, "dma-rx", 0, dma[1]);
- sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq);
-
- return dev;
-}
-
static void omap_mmc_reset_hold(Object *obj, ResetType type)
{
OMAPMMCState *s = OMAP_MMC(obj);
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 32/36] hw/sd/omap_mmc: Remove unused coverswitch qemu_irq
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (30 preceding siblings ...)
2025-01-31 21:05 ` [PULL 31/36] hw/arm/omap1: Inline creation of MMC Philippe Mathieu-Daudé
@ 2025-01-31 21:05 ` Philippe Mathieu-Daudé
2025-01-31 21:05 ` [PULL 33/36] hw/sd/omap_mmc: Untabify Philippe Mathieu-Daudé
` (4 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:05 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Richard Henderson, Philippe Mathieu-Daudé
From: Peter Maydell <peter.maydell@linaro.org>
The coverswitch qemu_irq is never connected to anything, and the only thing
we do with it is set it in omap_mmc_reset(). Remove it.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20250128104519.3981448-8-peter.maydell@linaro.org>
[PMD: Remove unused 'coverswitch' field]
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/sd/omap_mmc.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c
index a8b541ca788..18016a2f2e2 100644
--- a/hw/sd/omap_mmc.c
+++ b/hw/sd/omap_mmc.c
@@ -35,7 +35,6 @@ typedef struct OMAPMMCState {
qemu_irq irq;
qemu_irq dma_tx_gpio;
qemu_irq dma_rx_gpio;
- qemu_irq coverswitch;
MemoryRegion iomem;
omap_clk clk;
uint16_t last_cmd;
@@ -70,7 +69,6 @@ typedef struct OMAPMMCState {
int cdet_wakeup;
int cdet_enable;
- int cdet_state;
qemu_irq cdet;
} OMAPMMCState;
@@ -325,7 +323,6 @@ static void omap_mmc_reset(OMAPMMCState *host)
host->transfer = 0;
host->cdet_wakeup = 0;
host->cdet_enable = 0;
- qemu_set_irq(host->coverswitch, host->cdet_state);
host->clkdiv = 0;
omap_mmc_pseudo_reset(host);
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 33/36] hw/sd/omap_mmc: Untabify
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (31 preceding siblings ...)
2025-01-31 21:05 ` [PULL 32/36] hw/sd/omap_mmc: Remove unused coverswitch qemu_irq Philippe Mathieu-Daudé
@ 2025-01-31 21:05 ` Philippe Mathieu-Daudé
2025-01-31 21:05 ` [PULL 34/36] hw/sd: Remove unused 'enable' method from SDCardClass Philippe Mathieu-Daudé
` (3 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:05 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Richard Henderson, Philippe Mathieu-Daudé
From: Peter Maydell <peter.maydell@linaro.org>
This is a very old source file, and still has some lingering
hard-coded tabs; untabify it.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20250128104519.3981448-9-peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/sd/omap_mmc.c | 124 +++++++++++++++++++++++------------------------
1 file changed, 62 insertions(+), 62 deletions(-)
diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c
index 18016a2f2e2..bbe7b971bbe 100644
--- a/hw/sd/omap_mmc.c
+++ b/hw/sd/omap_mmc.c
@@ -109,11 +109,11 @@ static void omap_mmc_fifolevel_update(OMAPMMCState *host)
/* These must match the encoding of the MMC_CMD Response field */
typedef enum {
- sd_nore = 0, /* no response */
- sd_r1, /* normal response command */
- sd_r2, /* CID, CSD registers */
- sd_r3, /* OCR register */
- sd_r6 = 6, /* Published RCA response */
+ sd_nore = 0, /* no response */
+ sd_r1, /* normal response command */
+ sd_r2, /* CID, CSD registers */
+ sd_r3, /* OCR register */
+ sd_r6 = 6, /* Published RCA response */
sd_r1b = -1,
} sd_rsp_type_t;
@@ -229,7 +229,7 @@ static void omap_mmc_command(OMAPMMCState *host, int cmd, int dir,
if (timeout)
host->status |= 0x0080;
else if (cmd == 12)
- host->status |= 0x0005; /* Makes it more real */
+ host->status |= 0x0005; /* Makes it more real */
else
host->status |= 0x0001;
}
@@ -338,32 +338,32 @@ static uint64_t omap_mmc_read(void *opaque, hwaddr offset, unsigned size)
}
switch (offset) {
- case 0x00: /* MMC_CMD */
+ case 0x00: /* MMC_CMD */
return s->last_cmd;
- case 0x04: /* MMC_ARGL */
+ case 0x04: /* MMC_ARGL */
return s->arg & 0x0000ffff;
- case 0x08: /* MMC_ARGH */
+ case 0x08: /* MMC_ARGH */
return s->arg >> 16;
- case 0x0c: /* MMC_CON */
+ case 0x0c: /* MMC_CON */
return (s->dw << 15) | (s->mode << 12) | (s->enable << 11) |
(s->be << 10) | s->clkdiv;
- case 0x10: /* MMC_STAT */
+ case 0x10: /* MMC_STAT */
return s->status;
- case 0x14: /* MMC_IE */
+ case 0x14: /* MMC_IE */
return s->mask;
- case 0x18: /* MMC_CTO */
+ case 0x18: /* MMC_CTO */
return s->cto;
- case 0x1c: /* MMC_DTO */
+ case 0x1c: /* MMC_DTO */
return s->dto;
- case 0x20: /* MMC_DATA */
+ case 0x20: /* MMC_DATA */
/* TODO: support 8-bit access */
i = s->fifo[s->fifo_start];
if (s->fifo_len == 0) {
@@ -378,42 +378,42 @@ static uint64_t omap_mmc_read(void *opaque, hwaddr offset, unsigned size)
omap_mmc_interrupts_update(s);
return i;
- case 0x24: /* MMC_BLEN */
+ case 0x24: /* MMC_BLEN */
return s->blen_counter;
- case 0x28: /* MMC_NBLK */
+ case 0x28: /* MMC_NBLK */
return s->nblk_counter;
- case 0x2c: /* MMC_BUF */
+ case 0x2c: /* MMC_BUF */
return (s->rx_dma << 15) | (s->af_level << 8) |
(s->tx_dma << 7) | s->ae_level;
- case 0x30: /* MMC_SPI */
+ case 0x30: /* MMC_SPI */
return 0x0000;
- case 0x34: /* MMC_SDIO */
+ case 0x34: /* MMC_SDIO */
return (s->cdet_wakeup << 2) | (s->cdet_enable) | s->sdio;
- case 0x38: /* MMC_SYST */
+ case 0x38: /* MMC_SYST */
return 0x0000;
- case 0x3c: /* MMC_REV */
+ case 0x3c: /* MMC_REV */
return s->rev;
- case 0x40: /* MMC_RSP0 */
- case 0x44: /* MMC_RSP1 */
- case 0x48: /* MMC_RSP2 */
- case 0x4c: /* MMC_RSP3 */
- case 0x50: /* MMC_RSP4 */
- case 0x54: /* MMC_RSP5 */
- case 0x58: /* MMC_RSP6 */
- case 0x5c: /* MMC_RSP7 */
+ case 0x40: /* MMC_RSP0 */
+ case 0x44: /* MMC_RSP1 */
+ case 0x48: /* MMC_RSP2 */
+ case 0x4c: /* MMC_RSP3 */
+ case 0x50: /* MMC_RSP4 */
+ case 0x54: /* MMC_RSP5 */
+ case 0x58: /* MMC_RSP6 */
+ case 0x5c: /* MMC_RSP7 */
return s->rsp[(offset - 0x40) >> 2];
/* OMAP2-specific */
- case 0x60: /* MMC_IOSR */
- case 0x64: /* MMC_SYSC */
+ case 0x60: /* MMC_IOSR */
+ case 0x64: /* MMC_SYSC */
return 0;
- case 0x68: /* MMC_SYSS */
- return 1; /* RSTD */
+ case 0x68: /* MMC_SYSS */
+ return 1; /* RSTD */
}
OMAP_BAD_REG(offset);
@@ -432,7 +432,7 @@ static void omap_mmc_write(void *opaque, hwaddr offset,
}
switch (offset) {
- case 0x00: /* MMC_CMD */
+ case 0x00: /* MMC_CMD */
if (!s->enable)
break;
@@ -447,17 +447,17 @@ static void omap_mmc_write(void *opaque, hwaddr offset,
omap_mmc_update(s);
break;
- case 0x04: /* MMC_ARGL */
+ case 0x04: /* MMC_ARGL */
s->arg &= 0xffff0000;
s->arg |= 0x0000ffff & value;
break;
- case 0x08: /* MMC_ARGH */
+ case 0x08: /* MMC_ARGH */
s->arg &= 0x0000ffff;
s->arg |= value << 16;
break;
- case 0x0c: /* MMC_CON */
+ case 0x0c: /* MMC_CON */
s->dw = (value >> 15) & 1;
s->mode = (value >> 12) & 3;
s->enable = (value >> 11) & 1;
@@ -477,27 +477,27 @@ static void omap_mmc_write(void *opaque, hwaddr offset,
omap_mmc_pseudo_reset(s);
break;
- case 0x10: /* MMC_STAT */
+ case 0x10: /* MMC_STAT */
s->status &= ~value;
omap_mmc_interrupts_update(s);
break;
- case 0x14: /* MMC_IE */
+ case 0x14: /* MMC_IE */
s->mask = value & 0x7fff;
omap_mmc_interrupts_update(s);
break;
- case 0x18: /* MMC_CTO */
+ case 0x18: /* MMC_CTO */
s->cto = value & 0xff;
if (s->cto > 0xfd && s->rev <= 1)
printf("MMC: CTO of 0xff and 0xfe cannot be used!\n");
break;
- case 0x1c: /* MMC_DTO */
+ case 0x1c: /* MMC_DTO */
s->dto = value & 0xffff;
break;
- case 0x20: /* MMC_DATA */
+ case 0x20: /* MMC_DATA */
/* TODO: support 8-bit access */
if (s->fifo_len == 32)
break;
@@ -508,18 +508,18 @@ static void omap_mmc_write(void *opaque, hwaddr offset,
omap_mmc_interrupts_update(s);
break;
- case 0x24: /* MMC_BLEN */
+ case 0x24: /* MMC_BLEN */
s->blen = (value & 0x07ff) + 1;
s->blen_counter = s->blen;
break;
- case 0x28: /* MMC_NBLK */
+ case 0x28: /* MMC_NBLK */
s->nblk = (value & 0x07ff) + 1;
s->nblk_counter = s->nblk;
s->blen_counter = s->blen;
break;
- case 0x2c: /* MMC_BUF */
+ case 0x2c: /* MMC_BUF */
s->rx_dma = (value >> 15) & 1;
s->af_level = (value >> 8) & 0x1f;
s->tx_dma = (value >> 7) & 1;
@@ -534,38 +534,38 @@ static void omap_mmc_write(void *opaque, hwaddr offset,
break;
/* SPI, SDIO and TEST modes unimplemented */
- case 0x30: /* MMC_SPI (OMAP1 only) */
+ case 0x30: /* MMC_SPI (OMAP1 only) */
break;
- case 0x34: /* MMC_SDIO */
+ case 0x34: /* MMC_SDIO */
s->sdio = value & (s->rev >= 2 ? 0xfbf3 : 0x2020);
s->cdet_wakeup = (value >> 9) & 1;
s->cdet_enable = (value >> 2) & 1;
break;
- case 0x38: /* MMC_SYST */
+ case 0x38: /* MMC_SYST */
break;
- case 0x3c: /* MMC_REV */
- case 0x40: /* MMC_RSP0 */
- case 0x44: /* MMC_RSP1 */
- case 0x48: /* MMC_RSP2 */
- case 0x4c: /* MMC_RSP3 */
- case 0x50: /* MMC_RSP4 */
- case 0x54: /* MMC_RSP5 */
- case 0x58: /* MMC_RSP6 */
- case 0x5c: /* MMC_RSP7 */
+ case 0x3c: /* MMC_REV */
+ case 0x40: /* MMC_RSP0 */
+ case 0x44: /* MMC_RSP1 */
+ case 0x48: /* MMC_RSP2 */
+ case 0x4c: /* MMC_RSP3 */
+ case 0x50: /* MMC_RSP4 */
+ case 0x54: /* MMC_RSP5 */
+ case 0x58: /* MMC_RSP6 */
+ case 0x5c: /* MMC_RSP7 */
OMAP_RO_REG(offset);
break;
/* OMAP2-specific */
- case 0x60: /* MMC_IOSR */
+ case 0x60: /* MMC_IOSR */
if (value & 0xf)
printf("MMC: SDIO bits used!\n");
break;
- case 0x64: /* MMC_SYSC */
- if (value & (1 << 2)) /* SRTS */
+ case 0x64: /* MMC_SYSC */
+ if (value & (1 << 2)) /* SRTS */
omap_mmc_reset(s);
break;
- case 0x68: /* MMC_SYSS */
+ case 0x68: /* MMC_SYSS */
OMAP_RO_REG(offset);
break;
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 34/36] hw/sd: Remove unused 'enable' method from SDCardClass
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (32 preceding siblings ...)
2025-01-31 21:05 ` [PULL 33/36] hw/sd/omap_mmc: Untabify Philippe Mathieu-Daudé
@ 2025-01-31 21:05 ` Philippe Mathieu-Daudé
2025-01-31 21:05 ` [PULL 35/36] hw/sd: Remove unused legacy functions, stop killing mammoths Philippe Mathieu-Daudé
` (2 subsequent siblings)
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:05 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Richard Henderson, Philippe Mathieu-Daudé
From: Peter Maydell <peter.maydell@linaro.org>
The SDCardClass has an 'enable' method, but nothing actually invokes it.
The underlying implementation is sd_enable(), which is documented
in sdcard_legacy.h as something that should not be used and was only
present for the benefit of the now-removed nseries boards. Unlike
all the other method pointers in SDCardClass, this one doesn't have
an sdbus_foo() function wrapper in hw/sd/core.c.
Remove the unused method.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20250128104519.3981448-10-peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/hw/sd/sd.h | 1 -
hw/sd/sd.c | 1 -
2 files changed, 2 deletions(-)
diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h
index f2458f37b3c..d6bad175131 100644
--- a/include/hw/sd/sd.h
+++ b/include/hw/sd/sd.h
@@ -119,7 +119,6 @@ struct SDCardClass {
void (*set_voltage)(SDState *sd, uint16_t millivolts);
uint8_t (*get_dat_lines)(SDState *sd);
bool (*get_cmd_line)(SDState *sd);
- void (*enable)(SDState *sd, bool enable);
bool (*get_inserted)(SDState *sd);
bool (*get_readonly)(SDState *sd);
void (*set_cid)(SDState *sd);
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 0330d432fd0..f781fd1641d 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -2831,7 +2831,6 @@ static void sdmmc_common_class_init(ObjectClass *klass, void *data)
sc->read_byte = sd_read_byte;
sc->receive_ready = sd_receive_ready;
sc->data_ready = sd_data_ready;
- sc->enable = sd_enable;
sc->get_inserted = sd_get_inserted;
sc->get_readonly = sd_get_readonly;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 35/36] hw/sd: Remove unused legacy functions, stop killing mammoths
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (33 preceding siblings ...)
2025-01-31 21:05 ` [PULL 34/36] hw/sd: Remove unused 'enable' method from SDCardClass Philippe Mathieu-Daudé
@ 2025-01-31 21:05 ` Philippe Mathieu-Daudé
2025-01-31 21:05 ` [PULL 36/36] hw/sd: Remove unused SDState::enable Philippe Mathieu-Daudé
2025-02-02 17:49 ` [PULL 00/36] Misc HW patches for 2025-01-31 Stefan Hajnoczi
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:05 UTC (permalink / raw)
To: qemu-devel
Cc: Peter Maydell, Richard Henderson, Philippe Mathieu-Daudé,
Markus Armbruster
From: Peter Maydell <peter.maydell@linaro.org>
The sdcard_legacy.h header defines function prototypes for the "legacy"
SD card API, which was used by non-qdevified SD controller models.
We've now converted the only remaining non-qdev SD controller, so
we can drop the legacy API.
Entirely unused functions:
sd_init(), sd_set_cb(), sd_enable()
Functions which now become static inside sd.c (they are the
underlying implementations of methods on SDCardClass):
sd_do_command(), sd_write_byte(), sd_read_byte()
Removal of sd_init() means that we can also remove the
me_no_qdev_me_kill_mammoth_with_rocks flag, the codepaths that were
only reachable when it was set, and the inserted_cb and readonly_cb
qemu_irq lines that went with that.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20250128104519.3981448-11-peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/hw/sd/sdcard_legacy.h | 50 -----------------------
hw/sd/sd.c | 77 ++++-------------------------------
2 files changed, 8 insertions(+), 119 deletions(-)
delete mode 100644 include/hw/sd/sdcard_legacy.h
diff --git a/include/hw/sd/sdcard_legacy.h b/include/hw/sd/sdcard_legacy.h
deleted file mode 100644
index 0dc38895551..00000000000
--- a/include/hw/sd/sdcard_legacy.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * SD Memory Card emulation (deprecated legacy API)
- *
- * Copyright (c) 2006 Andrzej Zaborowski <balrog@zabor.org>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#ifndef HW_SDCARD_LEGACY_H
-#define HW_SDCARD_LEGACY_H
-
-#include "hw/sd/sd.h"
-
-/* Legacy functions to be used only by non-qdevified callers */
-SDState *sd_init(BlockBackend *blk, bool is_spi);
-int sd_do_command(SDState *card, SDRequest *request, uint8_t *response);
-void sd_write_byte(SDState *card, uint8_t value);
-uint8_t sd_read_byte(SDState *card);
-void sd_set_cb(SDState *card, qemu_irq readonly, qemu_irq insert);
-
-/* sd_enable should not be used -- it is only used on the nseries boards,
- * where it is part of a broken implementation of the MMC card slot switch
- * (there should be two card slots which are multiplexed to a single MMC
- * controller, but instead we model it with one card and controller and
- * disable the card when the second slot is selected, so it looks like the
- * second slot is always empty).
- */
-void sd_enable(SDState *card, bool enable);
-
-#endif /* HW_SDCARD_LEGACY_H */
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index f781fd1641d..74bb7f39bbf 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -39,7 +39,6 @@
#include "hw/registerfields.h"
#include "system/block-backend.h"
#include "hw/sd/sd.h"
-#include "hw/sd/sdcard_legacy.h"
#include "migration/vmstate.h"
#include "qapi/error.h"
#include "qemu/bitmap.h"
@@ -120,10 +119,6 @@ typedef struct SDProto {
struct SDState {
DeviceState parent_obj;
- /* If true, created by sd_init() for a non-qdevified caller */
- /* TODO purge them with fire */
- bool me_no_qdev_me_kill_mammoth_with_rocks;
-
/* SD Memory Card Registers */
uint32_t ocr;
uint8_t scr[8];
@@ -177,8 +172,6 @@ struct SDState {
uint32_t data_offset;
size_t data_size;
uint8_t data[512];
- qemu_irq readonly_cb;
- qemu_irq inserted_cb;
QEMUTimer *ocr_power_timer;
bool enable;
uint8_t dat_lines;
@@ -892,17 +885,10 @@ static void sd_cardchange(void *opaque, bool load, Error **errp)
trace_sdcard_ejected();
}
- if (sd->me_no_qdev_me_kill_mammoth_with_rocks) {
- qemu_set_irq(sd->inserted_cb, inserted);
- if (inserted) {
- qemu_set_irq(sd->readonly_cb, readonly);
- }
- } else {
- sdbus = SD_BUS(qdev_get_parent_bus(dev));
- sdbus_set_inserted(sdbus, inserted);
- if (inserted) {
- sdbus_set_readonly(sdbus, readonly);
- }
+ sdbus = SD_BUS(qdev_get_parent_bus(dev));
+ sdbus_set_inserted(sdbus, inserted);
+ if (inserted) {
+ sdbus_set_readonly(sdbus, readonly);
}
}
@@ -1000,48 +986,6 @@ static const VMStateDescription sd_vmstate = {
},
};
-/* Legacy initialization function for use by non-qdevified callers */
-SDState *sd_init(BlockBackend *blk, bool is_spi)
-{
- Object *obj;
- DeviceState *dev;
- SDState *sd;
- Error *err = NULL;
-
- obj = object_new(is_spi ? TYPE_SD_CARD_SPI : TYPE_SD_CARD);
- dev = DEVICE(obj);
- if (!qdev_prop_set_drive_err(dev, "drive", blk, &err)) {
- error_reportf_err(err, "sd_init failed: ");
- return NULL;
- }
-
- /*
- * Realizing the device properly would put it into the QOM
- * composition tree even though it is not plugged into an
- * appropriate bus. That's a no-no. Hide the device from
- * QOM/qdev, and call its qdev realize callback directly.
- */
- object_ref(obj);
- object_unparent(obj);
- sd_realize(dev, &err);
- if (err) {
- error_reportf_err(err, "sd_init failed: ");
- return NULL;
- }
-
- sd = SD_CARD(dev);
- sd->me_no_qdev_me_kill_mammoth_with_rocks = true;
- return sd;
-}
-
-void sd_set_cb(SDState *sd, qemu_irq readonly, qemu_irq insert)
-{
- sd->readonly_cb = readonly;
- sd->inserted_cb = insert;
- qemu_set_irq(readonly, sd->blk ? !blk_is_writable(sd->blk) : 0);
- qemu_set_irq(insert, sd->blk ? blk_is_inserted(sd->blk) : 0);
-}
-
static void sd_blk_read(SDState *sd, uint64_t addr, uint32_t len)
{
trace_sdcard_read_block(addr, len);
@@ -2196,8 +2140,8 @@ static bool cmd_valid_while_locked(SDState *sd, unsigned cmd)
return cmd_class == 0 || cmd_class == 7;
}
-int sd_do_command(SDState *sd, SDRequest *req,
- uint8_t *response) {
+static int sd_do_command(SDState *sd, SDRequest *req,
+ uint8_t *response) {
int last_state;
sd_rsp_type_t rtype;
int rsplen;
@@ -2349,7 +2293,7 @@ static bool sd_generic_read_byte(SDState *sd, uint8_t *value)
return false;
}
-void sd_write_byte(SDState *sd, uint8_t value)
+static void sd_write_byte(SDState *sd, uint8_t value)
{
int i;
@@ -2478,7 +2422,7 @@ void sd_write_byte(SDState *sd, uint8_t value)
}
}
-uint8_t sd_read_byte(SDState *sd)
+static uint8_t sd_read_byte(SDState *sd)
{
/* TODO: Append CRCs */
const uint8_t dummy_byte = 0x00;
@@ -2561,11 +2505,6 @@ static bool sd_data_ready(SDState *sd)
return sd->state == sd_sendingdata_state;
}
-void sd_enable(SDState *sd, bool enable)
-{
- sd->enable = enable;
-}
-
static const SDProto sd_proto_spi = {
.name = "SPI",
.cmd = {
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* [PULL 36/36] hw/sd: Remove unused SDState::enable
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (34 preceding siblings ...)
2025-01-31 21:05 ` [PULL 35/36] hw/sd: Remove unused legacy functions, stop killing mammoths Philippe Mathieu-Daudé
@ 2025-01-31 21:05 ` Philippe Mathieu-Daudé
2025-02-02 17:49 ` [PULL 00/36] Misc HW patches for 2025-01-31 Stefan Hajnoczi
36 siblings, 0 replies; 38+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 21:05 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Richard Henderson, Philippe Mathieu-Daudé
From: Peter Maydell <peter.maydell@linaro.org>
Now that sd_enable() has been removed, SD::enable is set to true in
sd_instance_init() and then never changed. So we can remove it.
Note that the VMSTATE_UNUSED() size argument should be '1', not
'sizeof(bool)', as noted in the CAUTION comment in vmstate.h.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20250128104519.3981448-12-peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/sd/sd.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 74bb7f39bbf..e541c57f8c3 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -173,7 +173,6 @@ struct SDState {
size_t data_size;
uint8_t data[512];
QEMUTimer *ocr_power_timer;
- bool enable;
uint8_t dat_lines;
bool cmd_line;
};
@@ -292,12 +291,12 @@ static const char *sd_acmd_name(SDState *sd, uint8_t cmd)
static uint8_t sd_get_dat_lines(SDState *sd)
{
- return sd->enable ? sd->dat_lines : 0;
+ return sd->dat_lines;
}
static bool sd_get_cmd_line(SDState *sd)
{
- return sd->enable ? sd->cmd_line : false;
+ return sd->cmd_line;
}
static void sd_set_voltage(SDState *sd, uint16_t millivolts)
@@ -976,7 +975,7 @@ static const VMStateDescription sd_vmstate = {
VMSTATE_UINT32(data_offset, SDState),
VMSTATE_UINT8_ARRAY(data, SDState, 512),
VMSTATE_UNUSED_V(1, 512),
- VMSTATE_BOOL(enable, SDState),
+ VMSTATE_UNUSED(1),
VMSTATE_END_OF_LIST()
},
.subsections = (const VMStateDescription * const []) {
@@ -2146,7 +2145,7 @@ static int sd_do_command(SDState *sd, SDRequest *req,
sd_rsp_type_t rtype;
int rsplen;
- if (!sd->blk || !blk_is_inserted(sd->blk) || !sd->enable) {
+ if (!sd->blk || !blk_is_inserted(sd->blk)) {
return 0;
}
@@ -2297,8 +2296,9 @@ static void sd_write_byte(SDState *sd, uint8_t value)
{
int i;
- if (!sd->blk || !blk_is_inserted(sd->blk) || !sd->enable)
+ if (!sd->blk || !blk_is_inserted(sd->blk)) {
return;
+ }
if (sd->state != sd_receivingdata_state) {
qemu_log_mask(LOG_GUEST_ERROR,
@@ -2429,8 +2429,9 @@ static uint8_t sd_read_byte(SDState *sd)
uint8_t ret;
uint32_t io_len;
- if (!sd->blk || !blk_is_inserted(sd->blk) || !sd->enable)
+ if (!sd->blk || !blk_is_inserted(sd->blk)) {
return dummy_byte;
+ }
if (sd->state != sd_sendingdata_state) {
qemu_log_mask(LOG_GUEST_ERROR,
@@ -2664,7 +2665,6 @@ static void sd_instance_init(Object *obj)
sd->proto = sc->proto;
sd->last_cmd_name = "UNSET";
- sd->enable = true;
sd->ocr_power_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, sd_ocr_powerup, sd);
}
--
2.47.1
^ permalink raw reply related [flat|nested] 38+ messages in thread
* Re: [PULL 00/36] Misc HW patches for 2025-01-31
2025-01-31 21:04 [PULL 00/36] Misc HW patches for 2025-01-31 Philippe Mathieu-Daudé
` (35 preceding siblings ...)
2025-01-31 21:05 ` [PULL 36/36] hw/sd: Remove unused SDState::enable Philippe Mathieu-Daudé
@ 2025-02-02 17:49 ` Stefan Hajnoczi
36 siblings, 0 replies; 38+ messages in thread
From: Stefan Hajnoczi @ 2025-02-02 17:49 UTC (permalink / raw)
To: Philippe Mathieu-Daudé; +Cc: qemu-devel, Philippe Mathieu-Daudé
[-- Attachment #1: Type: text/plain, Size: 116 bytes --]
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/10.0 for any user-visible changes.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 38+ messages in thread