qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Song Gao" <gaosong@loongson.cn>,
	"Antony Pavlov" <antonynpavlov@gmail.com>,
	"Jan Kiszka" <jan.kiszka@web.de>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"Hanna Reitz" <hreitz@redhat.com>,
	"Bernhard Beschow" <shentey@gmail.com>,
	"BALATON Zoltan" <balaton@eik.bme.hu>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Alistair Francis" <alistair.francis@wdc.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	qemu-ppc@nongnu.org, "Mark Burton" <mburton@qti.qualcomm.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Magnus Damm" <magnus.damm@gmail.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Bin Meng" <bin.meng@windriver.com>,
	"Max Filippov" <jcmvbkbc@gmail.com>,
	"Aurelien Jarno" <aurelien@aurel32.net>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Radoslaw Biernacki" <rad@semihalf.com>,
	"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
	"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
	"Xiaojuan Yang" <yangxiaojuan@loongson.cn>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	qemu-block@nongnu.org, qemu-riscv@nongnu.org,
	"Yoshinori Sato" <ysato@users.sourceforge.jp>,
	"Alistair Francis" <alistair@alistair23.me>,
	qemu-arm@nongnu.org, "Leif Lindholm" <quic_llindhol@quicinc.com>,
	"Kevin Wolf" <kwolf@redhat.com>
Subject: [PATCH 03/20] hw/block: Pass DeviceState to pflash_cfi01_get_memory()
Date: Wed,  4 Jan 2023 23:04:32 +0100	[thread overview]
Message-ID: <20230104220449.41337-4-philmd@linaro.org> (raw)
In-Reply-To: <20230104220449.41337-1-philmd@linaro.org>

The point of a getter() function is to not expose the structure
internal fields. Otherwise callers could simply access the
PFlashCFI01::mem field.

Have the callers pass a DeviceState* argument. The QOM
type check is done in the callee.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/block/pflash_cfi01.c  | 4 +++-
 hw/i386/pc_sysfw.c       | 2 +-
 hw/mips/malta.c          | 3 ++-
 hw/ppc/e500.c            | 2 +-
 hw/xtensa/xtfpga.c       | 2 +-
 include/hw/block/flash.h | 2 +-
 6 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
index 8beba24989..866ea596ea 100644
--- a/hw/block/pflash_cfi01.c
+++ b/hw/block/pflash_cfi01.c
@@ -991,8 +991,10 @@ BlockBackend *pflash_cfi01_get_blk(DeviceState *dev)
     return fl->blk;
 }
 
-MemoryRegion *pflash_cfi01_get_memory(PFlashCFI01 *fl)
+MemoryRegion *pflash_cfi01_get_memory(DeviceState *dev)
 {
+    PFlashCFI01 *fl = PFLASH_CFI01(dev);
+
     return &fl->mem;
 }
 
diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c
index c08cba6628..60db0efb41 100644
--- a/hw/i386/pc_sysfw.c
+++ b/hw/i386/pc_sysfw.c
@@ -187,7 +187,7 @@ static void pc_system_flash_map(PCMachineState *pcms,
                         0x100000000ULL - total_size);
 
         if (i == 0) {
-            flash_mem = pflash_cfi01_get_memory(system_flash);
+            flash_mem = pflash_cfi01_get_memory(DEVICE(system_flash));
             pc_isa_bios_init(rom_memory, flash_mem, size);
 
             /* Encrypt the pflash boot ROM */
diff --git a/hw/mips/malta.c b/hw/mips/malta.c
index c0a2e0ab04..43fbb97799 100644
--- a/hw/mips/malta.c
+++ b/hw/mips/malta.c
@@ -1291,7 +1291,8 @@ void mips_malta_init(MachineState *machine)
                                dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                                65536,
                                4, 0x0000, 0x0000, 0x0000, 0x0000, be);
-    bios = pflash_cfi01_get_memory(fl);
+    dev = DEVICE(fl);
+    bios = pflash_cfi01_get_memory(dev);
     fl_idx++;
     if (kernel_filename) {
         ram_low_size = MIN(ram_size, 256 * MiB);
diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index 9fa1f8e6cf..b127068431 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -1144,7 +1144,7 @@ void ppce500_init(MachineState *machine)
         sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
 
         memory_region_add_subregion(&pms->pbus_dev->mmio, 0,
-                                    pflash_cfi01_get_memory(PFLASH_CFI01(dev)));
+                                    pflash_cfi01_get_memory(dev));
     }
 
     /*
diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
index 2a5556a35f..bce3a543b0 100644
--- a/hw/xtensa/xtfpga.c
+++ b/hw/xtensa/xtfpga.c
@@ -459,7 +459,7 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
         }
     } else {
         if (flash) {
-            MemoryRegion *flash_mr = pflash_cfi01_get_memory(flash);
+            MemoryRegion *flash_mr = pflash_cfi01_get_memory(DEVICE(flash));
             MemoryRegion *flash_io = g_malloc(sizeof(*flash_io));
             uint32_t size = env->config->sysrom.location[0].size;
 
diff --git a/include/hw/block/flash.h b/include/hw/block/flash.h
index 701a2c1701..25affdf7a5 100644
--- a/include/hw/block/flash.h
+++ b/include/hw/block/flash.h
@@ -22,7 +22,7 @@ PFlashCFI01 *pflash_cfi01_register(hwaddr base,
                                    uint16_t id2, uint16_t id3,
                                    int be);
 BlockBackend *pflash_cfi01_get_blk(DeviceState *dev);
-MemoryRegion *pflash_cfi01_get_memory(PFlashCFI01 *fl);
+MemoryRegion *pflash_cfi01_get_memory(DeviceState *dev);
 void pflash_cfi01_legacy_drive(DeviceState *dev, DriveInfo *dinfo);
 
 /* pflash_cfi02.c */
-- 
2.38.1



  parent reply	other threads:[~2023-01-04 22:44 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-04 22:04 [PATCH 00/20] hw: Remove implicit sysbus_mmio_map() from pflash APIs Philippe Mathieu-Daudé
2023-01-04 22:04 ` [PATCH 01/20] hw/block: Pass DeviceState to pflash_cfi01_get_blk() Philippe Mathieu-Daudé
2023-01-08  4:28   ` Bin Meng
2023-01-04 22:04 ` [PATCH 02/20] hw/block: Use pflash_cfi01_get_blk() in pflash_cfi01_legacy_drive() Philippe Mathieu-Daudé
2023-01-08  4:29   ` Bin Meng
2023-01-04 22:04 ` Philippe Mathieu-Daudé [this message]
2023-01-08  4:30   ` [PATCH 03/20] hw/block: Pass DeviceState to pflash_cfi01_get_memory() Bin Meng
2023-01-04 22:04 ` [PATCH 04/20] hw/arm: Use generic DeviceState instead of PFlashCFI01 Philippe Mathieu-Daudé
2023-01-08  5:25   ` Bin Meng
2023-01-04 22:04 ` [PATCH 05/20] hw/loongarch: " Philippe Mathieu-Daudé
2023-01-08  5:25   ` Bin Meng
2023-01-04 22:04 ` [PATCH 06/20] hw/riscv: " Philippe Mathieu-Daudé
2023-01-06 20:33   ` Daniel Henrique Barboza
2023-01-08  5:28   ` Bin Meng
2023-01-04 22:04 ` [PATCH 07/20] hw/i386: " Philippe Mathieu-Daudé
2023-01-08  5:28   ` Bin Meng
2023-01-04 22:04 ` [PATCH 08/20] hw/xtensa: " Philippe Mathieu-Daudé
2023-01-08  5:28   ` Bin Meng
2023-01-04 22:04 ` [PATCH 09/20] hw/block: Factor pflash_cfi01_create() out of pflash_cfi01_register() Philippe Mathieu-Daudé
2023-01-08  5:32   ` Bin Meng
2023-01-04 22:04 ` [PATCH 10/20] hw/arm: Open-code pflash_cfi01_register() Philippe Mathieu-Daudé
2023-01-08  5:35   ` Bin Meng
2023-01-04 22:04 ` [PATCH 11/20] hw/microblaze: " Philippe Mathieu-Daudé
2023-01-08 12:28   ` Bin Meng
2023-01-04 22:04 ` [PATCH 12/20] hw/mips: " Philippe Mathieu-Daudé
2023-01-08 12:28   ` Bin Meng
2023-01-04 22:04 ` [PATCH 13/20] hw/ppc: " Philippe Mathieu-Daudé
2023-01-08 12:28   ` Bin Meng
2023-01-04 22:04 ` [PATCH 14/20] hw/block: Remove unused pflash_cfi01_register() Philippe Mathieu-Daudé
2023-01-08 12:28   ` Bin Meng
2023-01-04 22:04 ` [PATCH 15/20] hw/block: Make PFlashCFI01 QOM declaration internal Philippe Mathieu-Daudé
2023-01-08 12:28   ` Bin Meng
2023-01-04 22:04 ` [PATCH 16/20] hw/block: Factor pflash_cfi02_create() out of pflash_cfi02_register() Philippe Mathieu-Daudé
2023-01-08 12:34   ` Bin Meng
2023-01-04 22:04 ` [PATCH 17/20] hw/arm: Open-code pflash_cfi02_register() Philippe Mathieu-Daudé
2023-01-08 12:34   ` Bin Meng
2023-01-04 22:04 ` [PATCH 18/20] hw/sh4: " Philippe Mathieu-Daudé
2023-01-08 12:34   ` Bin Meng
2023-01-04 22:04 ` [PATCH 19/20] hw/block: Remove unused pflash_cfi02_register() Philippe Mathieu-Daudé
2023-01-08 12:34   ` Bin Meng
2023-01-04 22:04 ` [PATCH 20/20] hw/block: Make PFlashCFI02 QOM declaration internal Philippe Mathieu-Daudé
2023-01-08 12:34   ` Bin Meng
2023-01-06 17:51 ` [PATCH 00/20] hw: Remove implicit sysbus_mmio_map() from pflash APIs Peter Maydell
2023-01-09 10:39   ` Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230104220449.41337-4-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=alistair.francis@wdc.com \
    --cc=alistair@alistair23.me \
    --cc=antonynpavlov@gmail.com \
    --cc=aurelien@aurel32.net \
    --cc=balaton@eik.bme.hu \
    --cc=bin.meng@windriver.com \
    --cc=edgar.iglesias@gmail.com \
    --cc=eduardo@habkost.net \
    --cc=gaosong@loongson.cn \
    --cc=hreitz@redhat.com \
    --cc=jan.kiszka@web.de \
    --cc=jcmvbkbc@gmail.com \
    --cc=jiaxun.yang@flygoat.com \
    --cc=kwolf@redhat.com \
    --cc=magnus.damm@gmail.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mburton@qti.qualcomm.com \
    --cc=mst@redhat.com \
    --cc=palmer@dabbelt.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=quic_llindhol@quicinc.com \
    --cc=rad@semihalf.com \
    --cc=richard.henderson@linaro.org \
    --cc=shentey@gmail.com \
    --cc=yangxiaojuan@loongson.cn \
    --cc=ysato@users.sourceforge.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).