[PATCH] tests/qtest/cdrom-test: Improve the machine detection in the cdrom test

2024-09-03 Thread Thomas Huth
When configuring QEMU with the --without-default-devices switch, these
tests are currently failing since they assume that the "pc" and "q35"
machines are always available. Add some proper checks to make the test
work without these machines, too.

Signed-off-by: Thomas Huth 
---
 tests/qtest/cdrom-test.c | 77 ++--
 1 file changed, 42 insertions(+), 35 deletions(-)

diff --git a/tests/qtest/cdrom-test.c b/tests/qtest/cdrom-test.c
index 5d89e62515..9d72b24e4b 100644
--- a/tests/qtest/cdrom-test.c
+++ b/tests/qtest/cdrom-test.c
@@ -135,13 +135,35 @@ static void add_x86_tests(void)
 return;
 }
 
-qtest_add_data_func("cdrom/boot/default", "-cdrom ", test_cdboot);
-if (qtest_has_device("virtio-scsi-ccw")) {
-qtest_add_data_func("cdrom/boot/virtio-scsi",
-"-device virtio-scsi -device scsi-cd,drive=cdr "
-"-blockdev file,node-name=cdr,filename=",
-test_cdboot);
+if (qtest_has_machine("pc")) {
+qtest_add_data_func("cdrom/boot/default", "-cdrom ", test_cdboot);
+if (qtest_has_device("virtio-scsi-ccw")) {
+qtest_add_data_func("cdrom/boot/virtio-scsi",
+"-device virtio-scsi -device scsi-cd,drive=cdr 
"
+"-blockdev file,node-name=cdr,filename=",
+test_cdboot);
+}
+
+if (qtest_has_device("am53c974")) {
+qtest_add_data_func("cdrom/boot/am53c974",
+"-device am53c974 -device scsi-cd,drive=cd1 "
+"-drive if=none,id=cd1,format=raw,file=",
+test_cdboot);
+}
+if (qtest_has_device("dc390")) {
+qtest_add_data_func("cdrom/boot/dc390",
+"-device dc390 -device scsi-cd,drive=cd1 "
+"-blockdev file,node-name=cd1,filename=",
+test_cdboot);
+}
+if (qtest_has_device("lsi53c895a")) {
+qtest_add_data_func("cdrom/boot/lsi53c895a",
+"-device lsi53c895a -device scsi-cd,drive=cd1 "
+"-blockdev file,node-name=cd1,filename=",
+test_cdboot);
+}
 }
+
 /*
  * Unstable CI test under load
  * See https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg05509.html
@@ -150,35 +172,20 @@ static void add_x86_tests(void)
 qtest_add_data_func("cdrom/boot/isapc", "-M isapc "
 "-drive if=ide,media=cdrom,file=", test_cdboot);
 }
-if (qtest_has_device("am53c974")) {
-qtest_add_data_func("cdrom/boot/am53c974",
-"-device am53c974 -device scsi-cd,drive=cd1 "
-"-drive if=none,id=cd1,format=raw,file=",
-test_cdboot);
-}
-if (qtest_has_device("dc390")) {
-qtest_add_data_func("cdrom/boot/dc390",
-"-device dc390 -device scsi-cd,drive=cd1 "
-"-blockdev file,node-name=cd1,filename=",
-test_cdboot);
-}
-if (qtest_has_device("lsi53c895a")) {
-qtest_add_data_func("cdrom/boot/lsi53c895a",
-"-device lsi53c895a -device scsi-cd,drive=cd1 "
-"-blockdev file,node-name=cd1,filename=",
-test_cdboot);
-}
-if (qtest_has_device("megasas")) {
-qtest_add_data_func("cdrom/boot/megasas", "-M q35 "
-"-device megasas -device scsi-cd,drive=cd1 "
-"-blockdev file,node-name=cd1,filename=",
-test_cdboot);
-}
-if (qtest_has_device("megasas-gen2")) {
-qtest_add_data_func("cdrom/boot/megasas-gen2", "-M q35 "
-"-device megasas-gen2 -device scsi-cd,drive=cd1 "
-"-blockdev file,node-name=cd1,filename=",
-test_cdboot);
+
+if (qtest_has_machine("q35")) {
+if (qtest_has_device("megasas")) {
+qtest_add_data_func("cdrom/boot/megasas", "-M q35 "
+"-device megasas -device scsi-cd,drive=cd1 "
+"-blockdev file,node-name=cd1,filename=",
+test_cdboot);
+}
+if (qtest_has_device("megasas-gen2")) {
+qtest_add_data_func("cdrom/boot/megasas-gen2", "-M q35 "
+"-device megasas-gen2 -device 
scsi-cd,drive=cd1 "
+"-blockdev file,node-name=cd1,filename=",
+test_cdboot);
+}
 }
 }
 
-- 
2.46.0




[PATCH] tests/qtest/hd-geo-test: Check for availability of "pc" machine before using it

2024-09-03 Thread Thomas Huth
In case QEMU has been configured with "--without-default-devices", the
"pc" machine type might be missing in the binary. We should check for
its availability before using it.

Signed-off-by: Thomas Huth 
---
 tests/qtest/hd-geo-test.c | 71 +--
 1 file changed, 38 insertions(+), 33 deletions(-)

diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
index d08bffad91..85eb8d7668 100644
--- a/tests/qtest/hd-geo-test.c
+++ b/tests/qtest/hd-geo-test.c
@@ -1074,17 +1074,26 @@ int main(int argc, char **argv)
 }
 }
 
-qtest_add_func("hd-geo/ide/none", test_ide_none);
-qtest_add_func("hd-geo/ide/drive/mbr/blank", test_ide_drive_mbr_blank);
-qtest_add_func("hd-geo/ide/drive/mbr/lba", test_ide_drive_mbr_lba);
-qtest_add_func("hd-geo/ide/drive/mbr/chs", test_ide_drive_mbr_chs);
-qtest_add_func("hd-geo/ide/drive/cd_0", test_ide_drive_cd_0);
-qtest_add_func("hd-geo/ide/device/mbr/blank", test_ide_device_mbr_blank);
-qtest_add_func("hd-geo/ide/device/mbr/lba", test_ide_device_mbr_lba);
-qtest_add_func("hd-geo/ide/device/mbr/chs", test_ide_device_mbr_chs);
-qtest_add_func("hd-geo/ide/device/user/chs", test_ide_device_user_chs);
-qtest_add_func("hd-geo/ide/device/user/chst", test_ide_device_user_chst);
-if (have_qemu_img()) {
+if (qtest_has_machine("pc")) {
+qtest_add_func("hd-geo/ide/none", test_ide_none);
+qtest_add_func("hd-geo/ide/drive/mbr/blank", test_ide_drive_mbr_blank);
+qtest_add_func("hd-geo/ide/drive/mbr/lba", test_ide_drive_mbr_lba);
+qtest_add_func("hd-geo/ide/drive/mbr/chs", test_ide_drive_mbr_chs);
+qtest_add_func("hd-geo/ide/drive/cd_0", test_ide_drive_cd_0);
+qtest_add_func("hd-geo/ide/device/mbr/blank", 
test_ide_device_mbr_blank);
+qtest_add_func("hd-geo/ide/device/mbr/lba", test_ide_device_mbr_lba);
+qtest_add_func("hd-geo/ide/device/mbr/chs", test_ide_device_mbr_chs);
+qtest_add_func("hd-geo/ide/device/user/chs", test_ide_device_user_chs);
+qtest_add_func("hd-geo/ide/device/user/chst", 
test_ide_device_user_chst);
+}
+
+if (!have_qemu_img()) {
+g_test_message("QTEST_QEMU_IMG not set or qemu-img missing; "
+   "skipping hd-geo/override/* tests");
+goto test_add_done;
+}
+
+if (qtest_has_machine("pc")) {
 qtest_add_func("hd-geo/override/ide", test_override_ide);
 if (qtest_has_device("lsi53c895a")) {
 qtest_add_func("hd-geo/override/scsi", test_override_scsi);
@@ -1104,30 +1113,26 @@ int main(int argc, char **argv)
 qtest_add_func("hd-geo/override/virtio_blk",
test_override_virtio_blk);
 }
+}
 
-if (qtest_has_machine("q35")) {
-qtest_add_func("hd-geo/override/sata", test_override_sata);
-qtest_add_func("hd-geo/override/zero_chs_q35",
-   test_override_zero_chs_q35);
-if (qtest_has_device("lsi53c895a")) {
-qtest_add_func("hd-geo/override/scsi_q35",
-   test_override_scsi_q35);
-}
-if (qtest_has_device("virtio-scsi-pci")) {
-qtest_add_func("hd-geo/override/scsi_hot_unplug_q35",
-   test_override_scsi_hot_unplug_q35);
-}
-if (qtest_has_device("virtio-blk-pci")) {
-qtest_add_func("hd-geo/override/virtio_hot_unplug_q35",
-   test_override_virtio_hot_unplug_q35);
-qtest_add_func("hd-geo/override/virtio_blk_q35",
-   test_override_virtio_blk_q35);
-}
-
+if (qtest_has_machine("q35")) {
+qtest_add_func("hd-geo/override/sata", test_override_sata);
+qtest_add_func("hd-geo/override/zero_chs_q35",
+   test_override_zero_chs_q35);
+if (qtest_has_device("lsi53c895a")) {
+qtest_add_func("hd-geo/override/scsi_q35",
+   test_override_scsi_q35);
+}
+if (qtest_has_device("virtio-scsi-pci")) {
+qtest_add_func("hd-geo/override/scsi_hot_unplug_q35",
+   test_override_scsi_hot_unplug_q35);
+}
+if (qtest_has_device("virtio-blk-pci")) {
+qtest_add_func("hd-geo/override/virtio_hot_unplug_q35",
+   test_override_virtio_hot_unplug_q35);
+qtest_add_func("hd-geo/override/virtio_blk_q35",
+   test_override_virtio_blk_q35);
 }
-} else {
-g_test_message("QTEST_QEMU_IMG not set or qemu-img missing; "
-   "skipping hd-geo/override/* tests");
 }
 
 test_add_done:
-- 
2.46.0




[PATCH 1/3] hw/sh4: Remove the deprecated SHIX machine

2024-09-03 Thread Philippe Mathieu-Daudé
The SHIX machine is deprecated since v9.0 (commit
322b038c94 "target/sh4: Deprecate the shix machine").
Time to remove it.

Signed-off-by: Philippe Mathieu-Daudé 
---
 MAINTAINERS |  7 +-
 docs/about/deprecated.rst   |  6 --
 docs/about/removed-features.rst |  5 ++
 configs/devices/sh4-softmmu/default.mak |  1 -
 hw/sh4/shix.c   | 86 -
 hw/sh4/Kconfig  |  7 --
 hw/sh4/meson.build  |  1 -
 7 files changed, 6 insertions(+), 107 deletions(-)
 delete mode 100644 hw/sh4/shix.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 3584d6a6c6..c8e4e3329c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1676,16 +1676,11 @@ F: hw/timer/sh_timer.c
 F: include/hw/sh4/sh_intc.h
 F: include/hw/timer/tmu012.h
 
-Shix
+TC58128 NAND EEPROM
 R: Yoshinori Sato 
 R: Magnus Damm 
 S: Odd Fixes
 F: hw/block/tc58128.c
-F: hw/char/sh_serial.c
-F: hw/sh4/shix.c
-F: hw/intc/sh_intc.c
-F: hw/timer/sh_timer.c
-F: include/hw/sh4/sh_intc.h
 
 SPARC Machines
 --
diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst
index 88f0f03786..2020542a6b 100644
--- a/docs/about/deprecated.rst
+++ b/docs/about/deprecated.rst
@@ -232,12 +232,6 @@ These old machine types are quite neglected nowadays and 
thus might have
 various pitfalls with regards to live migration. Use a newer machine type
 instead.
 
-``shix`` (since 9.0)
-
-
-The machine is no longer in existence and has been long unmaintained
-in QEMU. This also holds for the TC51828 16MiB flash that it uses.
-
 ``pseries-2.1`` up to ``pseries-2.12`` (since 9.0)
 ''
 
diff --git a/docs/about/removed-features.rst b/docs/about/removed-features.rst
index fc7b28e637..9eaf864004 100644
--- a/docs/about/removed-features.rst
+++ b/docs/about/removed-features.rst
@@ -978,6 +978,11 @@ Nios II ``10m50-ghrd`` and ``nios2-generic-nommu`` 
machines (removed in 9.1)
 
 The Nios II architecture was orphan.
 
+``shix`` (removed in 9.2)
+'
+
+The machine was unmaintained.
+
 linux-user mode CPUs
 
 
diff --git a/configs/devices/sh4-softmmu/default.mak 
b/configs/devices/sh4-softmmu/default.mak
index c06a427053..aa821e4b60 100644
--- a/configs/devices/sh4-softmmu/default.mak
+++ b/configs/devices/sh4-softmmu/default.mak
@@ -7,4 +7,3 @@
 
 # Boards are selected by default, uncomment to keep out of the build.
 # CONFIG_R2D=n
-# CONFIG_SHIX=n
diff --git a/hw/sh4/shix.c b/hw/sh4/shix.c
deleted file mode 100644
index eb3150b5bc..00
--- a/hw/sh4/shix.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * SHIX 2.0 board description
- *
- * Copyright (c) 2005 Samuel Tardieu
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to 
deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-/*
- * Shix 2.0 board by Alexis Polti, described at
- * 
https://web.archive.org/web/20070917001736/perso.enst.fr/~polti/realisations/shix20
- *
- * More information in target/sh4/README.sh4
- */
-#include "qemu/osdep.h"
-#include "qapi/error.h"
-#include "cpu.h"
-#include "hw/sh4/sh.h"
-#include "sysemu/qtest.h"
-#include "hw/boards.h"
-#include "hw/loader.h"
-#include "qemu/error-report.h"
-
-#define BIOS_FILENAME "shix_bios.bin"
-#define BIOS_ADDRESS 0xA000
-
-static void shix_init(MachineState *machine)
-{
-int ret;
-SuperHCPU *cpu;
-struct SH7750State *s;
-MemoryRegion *sysmem = get_system_memory();
-MemoryRegion *rom = g_new(MemoryRegion, 1);
-MemoryRegion *sdram = g_new(MemoryRegion, 2);
-const char *bios_name = machine->firmware ?: BIOS_FILENAME;
-
-cpu = SUPERH_CPU(cpu_create(machine->cpu_type));
-
-/* Allocate memory space */
-memory_region_init_rom(rom, NULL, "shix.rom", 0x4000, &error_fatal);
-memory_region_add_subregion(sysmem, 0x, rom);
-memory_region_init_ram(&sdram[0], NULL, "shix.sdram1", 0x0100,
-   &error_fa

[PATCH 3/3] hw/sh4: Remove sh7750_register_io_device() helper

2024-09-03 Thread Philippe Mathieu-Daudé
sh7750_register_io_device() was only used by the TC58128
NAND EEPROM which has been removed in the previous commit.
Remove it as unused code.

Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/sh4/sh.h | 16 -
 hw/sh4/sh7750.c | 57 ++---
 2 files changed, 2 insertions(+), 71 deletions(-)

diff --git a/include/hw/sh4/sh.h b/include/hw/sh4/sh.h
index b726b987cc..c82feef8d0 100644
--- a/include/hw/sh4/sh.h
+++ b/include/hw/sh4/sh.h
@@ -38,22 +38,6 @@ struct SH7750State;
 
 struct SH7750State *sh7750_init(SuperHCPU *cpu, MemoryRegion *sysmem);
 
-typedef struct {
-/* The callback will be triggered if any of the designated lines change */
-uint16_t portamask_trigger;
-uint16_t portbmask_trigger;
-/* Return 0 if no action was taken */
-int (*port_change_cb) (uint16_t porta, uint16_t portb,
-   uint16_t *periph_pdtra,
-   uint16_t *periph_portdira,
-   uint16_t *periph_pdtrb,
-   uint16_t *periph_portdirb);
-} sh7750_io_device;
-
-int sh7750_register_io_device(struct SH7750State *s,
-  sh7750_io_device *device);
-
-/* sh_serial.c */
 #define TYPE_SH_SERIAL "sh-serial"
 #define SH_SERIAL_FEAT_SCIF (1 << 0)
 
diff --git a/hw/sh4/sh7750.c b/hw/sh4/sh7750.c
index ebe0fd96d9..8041b3b651 100644
--- a/hw/sh4/sh7750.c
+++ b/hw/sh4/sh7750.c
@@ -38,8 +38,6 @@
 #include "exec/exec-all.h"
 #include "trace.h"
 
-#define NB_DEVICES 4
-
 typedef struct SH7750State {
 MemoryRegion iomem;
 MemoryRegion iomem_1f0;
@@ -75,7 +73,6 @@ typedef struct SH7750State {
 uint16_t periph_portdira; /* Direction seen from the peripherals */
 uint16_t periph_pdtrb;/* Imposed by the peripherals */
 uint16_t periph_portdirb; /* Direction seen from the peripherals */
-sh7750_io_device *devices[NB_DEVICES]; /* External peripherals */
 
 /* Cache */
 uint32_t ccr;
@@ -92,19 +89,6 @@ static inline int has_bcr3_and_bcr4(SH7750State *s)
  * I/O ports
  */
 
-int sh7750_register_io_device(SH7750State *s, sh7750_io_device *device)
-{
-int i;
-
-for (i = 0; i < NB_DEVICES; i++) {
-if (s->devices[i] == NULL) {
-s->devices[i] = device;
-return 0;
-}
-}
-return -1;
-}
-
 static uint16_t portdir(uint32_t v)
 {
 #define EVENPORTMASK(n) ((v & (1 << ((n) << 1))) >> (n))
@@ -142,63 +126,26 @@ static uint16_t portb_lines(SH7750State *s)
 (~(s->portdirb | s->periph_portdirb) & s->portpullupb); /* Pullups */
 }
 
-static void gen_port_interrupts(SH7750State *s)
-{
-/* X interrupts not generated */
-}
-
 static void porta_changed(SH7750State *s, uint16_t prev)
 {
-uint16_t currenta, changes;
-int i, r = 0;
+uint16_t currenta;
 
 currenta = porta_lines(s);
 if (currenta == prev) {
 return;
 }
 trace_sh7750_porta(prev, currenta, s->pdtra, s->pctra);
-changes = currenta ^ prev;
-
-for (i = 0; i < NB_DEVICES; i++) {
-if (s->devices[i] && (s->devices[i]->portamask_trigger & changes)) {
-r |= s->devices[i]->port_change_cb(currenta, portb_lines(s),
-   &s->periph_pdtra,
-   &s->periph_portdira,
-   &s->periph_pdtrb,
-   &s->periph_portdirb);
-}
-}
-
-if (r) {
-gen_port_interrupts(s);
-}
 }
 
 static void portb_changed(SH7750State *s, uint16_t prev)
 {
-uint16_t currentb, changes;
-int i, r = 0;
+uint16_t currentb;
 
 currentb = portb_lines(s);
 if (currentb == prev) {
 return;
 }
 trace_sh7750_portb(prev, currentb, s->pdtrb, s->pctrb);
-changes = currentb ^ prev;
-
-for (i = 0; i < NB_DEVICES; i++) {
-if (s->devices[i] && (s->devices[i]->portbmask_trigger & changes)) {
-r |= s->devices[i]->port_change_cb(portb_lines(s), currentb,
-   &s->periph_pdtra,
-   &s->periph_portdira,
-   &s->periph_pdtrb,
-   &s->periph_portdirb);
-}
-}
-
-if (r) {
-gen_port_interrupts(s);
-}
 }
 
 /*
-- 
2.45.2




[PATCH 2/3] hw/block: Remove TC58128 NAND EEPROM

2024-09-03 Thread Philippe Mathieu-Daudé
The TC58128 NAND EEPROM is not user creatable and
needs to be instanciated in the code via tc58128_init().

Only the SHIX machine was using it, and it was removed
in the previous commit. Since the TC58128 has no more
users, remove it too.

Signed-off-by: Philippe Mathieu-Daudé 
---
 MAINTAINERS  |   6 --
 include/hw/sh4/sh.h  |   3 -
 hw/block/tc58128.c   | 211 ---
 hw/block/Kconfig |   3 -
 hw/block/meson.build |   1 -
 5 files changed, 224 deletions(-)
 delete mode 100644 hw/block/tc58128.c

diff --git a/MAINTAINERS b/MAINTAINERS
index c8e4e3329c..55f41ecbc4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1676,12 +1676,6 @@ F: hw/timer/sh_timer.c
 F: include/hw/sh4/sh_intc.h
 F: include/hw/timer/tmu012.h
 
-TC58128 NAND EEPROM
-R: Yoshinori Sato 
-R: Magnus Damm 
-S: Odd Fixes
-F: hw/block/tc58128.c
-
 SPARC Machines
 --
 Sun4m
diff --git a/include/hw/sh4/sh.h b/include/hw/sh4/sh.h
index ec716cdd45..b726b987cc 100644
--- a/include/hw/sh4/sh.h
+++ b/include/hw/sh4/sh.h
@@ -60,7 +60,4 @@ int sh7750_register_io_device(struct SH7750State *s,
 /* sh7750.c */
 qemu_irq sh7750_irl(struct SH7750State *s);
 
-/* tc58128.c */
-int tc58128_init(struct SH7750State *s, const char *zone1, const char *zone2);
-
 #endif
diff --git a/hw/block/tc58128.c b/hw/block/tc58128.c
deleted file mode 100644
index 0984e37417..00
--- a/hw/block/tc58128.c
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * TC58128 NAND EEPROM emulation
- *
- * Copyright (c) 2005 Samuel Tardieu
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to 
deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * SPDX-License-Identifier: MIT
- */
-#include "qemu/osdep.h"
-#include "qemu/units.h"
-#include "hw/sh4/sh.h"
-#include "hw/loader.h"
-#include "sysemu/qtest.h"
-#include "qemu/error-report.h"
-
-#define CE1  0x0100
-#define CE2  0x0200
-#define RE   0x0400
-#define WE   0x0800
-#define ALE  0x1000
-#define CLE  0x2000
-#define RDY1 0x4000
-#define RDY2 0x8000
-#define RDY(n) ((n) == 0 ? RDY1 : RDY2)
-
-typedef enum { WAIT, READ1, READ2, READ3 } state_t;
-
-typedef struct {
-uint8_t *flash_contents;
-state_t state;
-uint32_t address;
-uint8_t address_cycle;
-} tc58128_dev;
-
-static tc58128_dev tc58128_devs[2];
-
-#define FLASH_SIZE (16 * MiB)
-
-static void init_dev(tc58128_dev * dev, const char *filename)
-{
-int ret, blocks;
-
-dev->state = WAIT;
-dev->flash_contents = g_malloc(FLASH_SIZE);
-memset(dev->flash_contents, 0xff, FLASH_SIZE);
-if (filename) {
-/* Load flash image skipping the first block */
-ret = load_image_size(filename, dev->flash_contents + 528 * 32,
-  FLASH_SIZE - 528 * 32);
-if (ret < 0) {
-if (!qtest_enabled()) {
-error_report("Could not load flash image %s", filename);
-exit(1);
-}
-} else {
-/* Build first block with number of blocks */
-blocks = DIV_ROUND_UP(ret, 528 * 32);
-dev->flash_contents[0] = blocks & 0xff;
-dev->flash_contents[1] = (blocks >> 8) & 0xff;
-dev->flash_contents[2] = (blocks >> 16) & 0xff;
-dev->flash_contents[3] = (blocks >> 24) & 0xff;
-fprintf(stderr, "loaded %d bytes for %s into flash\n", ret,
-filename);
-}
-}
-}
-
-static void handle_command(tc58128_dev * dev, uint8_t command)
-{
-switch (command) {
-case 0xff:
-fprintf(stderr, "reset flash device\n");
-dev->state = WAIT;
-break;
-case 0x00:
-fprintf(stderr, "read mode 1\n");
-dev->state = READ1;
-dev->address_cycle = 0;
-break;
-case 0x01:
-fprintf(stderr, "read mode 2\n");
-dev->state = READ2;
-dev->address_cycle = 0;
-break;
-case 0x50:
-fprintf(stderr, "read mode 3\n");
-dev->state = READ3;
-

[PATCH 0/3] hw/sh4: Remove the deprecated SHIX machine

2024-09-03 Thread Philippe Mathieu-Daudé
Remove the deprecated SH4 SHIX machine, along
with the TC58128 NAND EEPROM.

Philippe Mathieu-Daudé (3):
  hw/sh4: Remove the deprecated SHIX machine
  hw/block: Remove TC58128 NAND EEPROM
  hw/sh4: Remove sh7750_register_io_device() helper

 MAINTAINERS |  11 --
 docs/about/deprecated.rst   |   6 -
 docs/about/removed-features.rst |   5 +
 configs/devices/sh4-softmmu/default.mak |   1 -
 include/hw/sh4/sh.h |  19 ---
 hw/block/tc58128.c  | 211 
 hw/sh4/sh7750.c |  57 +--
 hw/sh4/shix.c   |  86 --
 hw/block/Kconfig|   3 -
 hw/block/meson.build|   1 -
 hw/sh4/Kconfig  |   7 -
 hw/sh4/meson.build  |   1 -
 12 files changed, 7 insertions(+), 401 deletions(-)
 delete mode 100644 hw/block/tc58128.c
 delete mode 100644 hw/sh4/shix.c

-- 
2.45.2




Re: [PATCH 0/3] hw/sh4: Remove the deprecated SHIX machine

2024-09-03 Thread Peter Maydell
On Tue, 3 Sept 2024 at 16:40, Philippe Mathieu-Daudé  wrote:
>
> Remove the deprecated SH4 SHIX machine, along
> with the TC58128 NAND EEPROM.
>
> Philippe Mathieu-Daudé (3):
>   hw/sh4: Remove the deprecated SHIX machine
>   hw/block: Remove TC58128 NAND EEPROM
>   hw/sh4: Remove sh7750_register_io_device() helper

Whole series:
Reviewed-by: Peter Maydell 

thanks
-- PMM



[PATCH 0/2] hw/sd: Remove a pair of legacy methods

2024-09-03 Thread Philippe Mathieu-Daudé
The omap2_mmc device -- deprecated and about to be
removed -- was the last user of the legacy sd_set_cb()
and sd_enable() methods. Remove them too along with
the me_no_qdev_me_kill_mammoth_with_rocks kludge.

Based-on: <20240903160751.4100218-1-peter.mayd...@linaro.org>

Philippe Mathieu-Daudé (2):
  hw/sd: Remove legacy sd_set_cb()
  hw/sd: Remove legacy sd_enable()

 include/hw/sd/sd.h|  1 -
 include/hw/sd/sdcard_legacy.h | 10 ---
 hw/sd/sd.c| 50 +++
 3 files changed, 10 insertions(+), 51 deletions(-)

-- 
2.45.2




[PATCH 2/2] hw/sd: Remove legacy sd_enable()

2024-09-03 Thread Philippe Mathieu-Daudé
sd_enable() was only used by omap_mmc_enable() which
got recently removed. Time to remove it.

Since the SDState::enable boolean is now always %true,
we can remove it and simplify.

Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/sd/sd.h|  1 -
 include/hw/sd/sdcard_legacy.h |  9 -
 hw/sd/sd.c| 20 ++--
 3 files changed, 6 insertions(+), 24 deletions(-)

diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h
index d35a839f5e..aa0f229747 100644
--- a/include/hw/sd/sd.h
+++ b/include/hw/sd/sd.h
@@ -127,7 +127,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/include/hw/sd/sdcard_legacy.h b/include/hw/sd/sdcard_legacy.h
index a121232560..82b62e87d1 100644
--- a/include/hw/sd/sdcard_legacy.h
+++ b/include/hw/sd/sdcard_legacy.h
@@ -37,13 +37,4 @@ 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);
 
-/* 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 8a30c61ce0..0c681da432 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -166,7 +166,6 @@ struct SDState {
 size_t data_size;
 uint8_t data[512];
 QEMUTimer *ocr_power_timer;
-bool enable;
 uint8_t dat_lines;
 bool cmd_line;
 };
@@ -285,12 +284,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)
@@ -974,7 +973,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(sizeof(bool)),
 VMSTATE_END_OF_LIST()
 },
 .subsections = (const VMStateDescription * const []) {
@@ -2177,7 +2176,7 @@ 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;
 }
 
@@ -2328,7 +2327,7 @@ 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) {
@@ -2460,7 +2459,7 @@ 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) {
@@ -2536,11 +2535,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 = {
@@ -2700,7 +2694,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);
 }
 
@@ -2809,7 +2802,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.45.2




[PATCH 1/2] hw/sd: Remove legacy sd_set_cb()

2024-09-03 Thread Philippe Mathieu-Daudé
sd_set_cb() was only used by omap2_mmc_init() which
got recently removed. Time to remove it. For historical
background on the me_no_qdev_me_kill_mammoth_with_rocks
kludge, see commit 007d1dbf72 ("sd: Hide the qdev-but-not-quite
thing created by sd_init()").

Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/sd/sdcard_legacy.h |  1 -
 hw/sd/sd.c| 30 --
 2 files changed, 4 insertions(+), 27 deletions(-)

diff --git a/include/hw/sd/sdcard_legacy.h b/include/hw/sd/sdcard_legacy.h
index 0dc3889555..a121232560 100644
--- a/include/hw/sd/sdcard_legacy.h
+++ b/include/hw/sd/sdcard_legacy.h
@@ -36,7 +36,6 @@ 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
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index a140a32ccd..8a30c61ce0 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -112,10 +112,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];
@@ -169,8 +165,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;
@@ -889,17 +883,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);
 }
 }
 
@@ -1027,18 +1014,9 @@ SDState *sd_init(BlockBackend *blk, bool is_spi)
 }
 
 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);
-- 
2.45.2




Re: [PATCH 1/2] hw/sd: Remove legacy sd_set_cb()

2024-09-03 Thread Philippe Mathieu-Daudé

(Cc'ing Guenter who asked to keep the SX1 machine)

On 3/9/24 22:04, Philippe Mathieu-Daudé wrote:

sd_set_cb() was only used by omap2_mmc_init() which
got recently removed. Time to remove it. For historical
background on the me_no_qdev_me_kill_mammoth_with_rocks
kludge, see commit 007d1dbf72 ("sd: Hide the qdev-but-not-quite
thing created by sd_init()").

Signed-off-by: Philippe Mathieu-Daudé 
---
  include/hw/sd/sdcard_legacy.h |  1 -
  hw/sd/sd.c| 30 --
  2 files changed, 4 insertions(+), 27 deletions(-)

diff --git a/include/hw/sd/sdcard_legacy.h b/include/hw/sd/sdcard_legacy.h
index 0dc3889555..a121232560 100644
--- a/include/hw/sd/sdcard_legacy.h
+++ b/include/hw/sd/sdcard_legacy.h
@@ -36,7 +36,6 @@ 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
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index a140a32ccd..8a30c61ce0 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -112,10 +112,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];
@@ -169,8 +165,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;
@@ -889,17 +883,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));


Guenter, we don't have SX1 tests. I wonder if this call could
fire an assertion. Do you have test images I can use? I'd need
to eject/reinsert a card to get there.


+sdbus_set_inserted(sdbus, inserted);
+if (inserted) {
+sdbus_set_readonly(sdbus, readonly);
  }
  }
  
@@ -1027,18 +1014,9 @@ SDState *sd_init(BlockBackend *blk, bool is_spi)

  }
  
  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);





Re: [Question] [Block] Is there a way to control the read caching of a block device?

2024-09-03 Thread Philippe Mathieu-Daudé

Cc'ing the qemu-block@ list

On 3/9/24 20:13, DUO Labs wrote:
I know that the `cache` parameter for `-drive` controls the caching 
behavior when writing from the guest to the host, but is there a way to 
control the reading behavior host->guest? Currently, on HEAD, if I open 
a file on both the guest and host, and write some data to the drive on 
the (macOS) host, the time until it shows up in the (Linux) guest is 
inconsistent (more specifically, it seems that the data won't show up in 
the guest unless I close the file and reopen it --- by contrast, if I 
write to the drive on the guest, it shows up nearly instantaneously on 
the host).







Re: [PATCH 1/2] hw/sd: Remove legacy sd_set_cb()

2024-09-03 Thread Guenter Roeck

On 9/3/24 13:10, Philippe Mathieu-Daudé wrote:

(Cc'ing Guenter who asked to keep the SX1 machine)

On 3/9/24 22:04, Philippe Mathieu-Daudé wrote:

sd_set_cb() was only used by omap2_mmc_init() which
got recently removed. Time to remove it. For historical
background on the me_no_qdev_me_kill_mammoth_with_rocks
kludge, see commit 007d1dbf72 ("sd: Hide the qdev-but-not-quite
thing created by sd_init()").

Signed-off-by: Philippe Mathieu-Daudé 
---
  include/hw/sd/sdcard_legacy.h |  1 -
  hw/sd/sd.c    | 30 --
  2 files changed, 4 insertions(+), 27 deletions(-)

diff --git a/include/hw/sd/sdcard_legacy.h b/include/hw/sd/sdcard_legacy.h
index 0dc3889555..a121232560 100644
--- a/include/hw/sd/sdcard_legacy.h
+++ b/include/hw/sd/sdcard_legacy.h
@@ -36,7 +36,6 @@ 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
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index a140a32ccd..8a30c61ce0 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -112,10 +112,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];
@@ -169,8 +165,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;
@@ -889,17 +883,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));


Guenter, we don't have SX1 tests. I wonder if this call could
fire an assertion. Do you have test images I can use? I'd need
to eject/reinsert a card to get there.



Have a look into
https://github.com/groeck/linux-build-test/tree/master/rootfs/arm

rootfs-armv4*are root file systems. You'd boot those with "noreboot"
command line argument to prevent them from rebooting automatically.
Let me know if you need more detailed directions; if so, I can make
a directory with everything needed.

Guenter