qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Bin Meng" <bmeng.cn@gmail.com>
Subject: [PATCH v2 02/21] hw/block: Pass DeviceState to pflash_cfi01_get_blk()
Date: Mon,  9 Jan 2023 13:08:14 +0100	[thread overview]
Message-ID: <20230109120833.3330-3-philmd@linaro.org> (raw)
In-Reply-To: <20230109120833.3330-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::blk 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>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---
 hw/arm/sbsa-ref.c        | 2 +-
 hw/arm/virt.c            | 2 +-
 hw/block/pflash_cfi01.c  | 4 +++-
 hw/i386/pc_sysfw.c       | 4 ++--
 include/hw/block/flash.h | 2 +-
 5 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
index 4bb444684f..65b9acba04 100644
--- a/hw/arm/sbsa-ref.c
+++ b/hw/arm/sbsa-ref.c
@@ -346,7 +346,7 @@ static bool sbsa_firmware_init(SBSAMachineState *sms,
 
     sbsa_flash_map(sms, sysmem, secure_sysmem);
 
-    pflash_blk0 = pflash_cfi01_get_blk(sms->flash[0]);
+    pflash_blk0 = pflash_cfi01_get_blk(DEVICE(sms->flash[0]));
 
     bios_name = MACHINE(sms)->firmware;
     if (bios_name) {
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index ea2413a0ba..954e3ca5ce 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -1233,7 +1233,7 @@ static bool virt_firmware_init(VirtMachineState *vms,
 
     virt_flash_map(vms, sysmem, secure_sysmem);
 
-    pflash_blk0 = pflash_cfi01_get_blk(vms->flash[0]);
+    pflash_blk0 = pflash_cfi01_get_blk(DEVICE(vms->flash[0]));
 
     bios_name = MACHINE(vms)->firmware;
     if (bios_name) {
diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
index 0cbc2fb4cb..458c50ec45 100644
--- a/hw/block/pflash_cfi01.c
+++ b/hw/block/pflash_cfi01.c
@@ -984,8 +984,10 @@ PFlashCFI01 *pflash_cfi01_register(hwaddr base,
     return PFLASH_CFI01(dev);
 }
 
-BlockBackend *pflash_cfi01_get_blk(PFlashCFI01 *fl)
+BlockBackend *pflash_cfi01_get_blk(DeviceState *dev)
 {
+    PFlashCFI01 *fl = PFLASH_CFI01(dev);
+
     return fl->blk;
 }
 
diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c
index c8d9e71b88..4b85c48ec8 100644
--- a/hw/i386/pc_sysfw.c
+++ b/hw/i386/pc_sysfw.c
@@ -152,7 +152,7 @@ static void pc_system_flash_map(PCMachineState *pcms,
 
     for (i = 0; i < ARRAY_SIZE(pcms->flash); i++) {
         system_flash = pcms->flash[i];
-        blk = pflash_cfi01_get_blk(system_flash);
+        blk = pflash_cfi01_get_blk(DEVICE(system_flash));
         if (!blk) {
             break;
         }
@@ -216,7 +216,7 @@ void pc_system_firmware_init(PCMachineState *pcms,
     for (i = 0; i < ARRAY_SIZE(pcms->flash); i++) {
         pflash_cfi01_legacy_drive(pcms->flash[i],
                                   drive_get(IF_PFLASH, 0, i));
-        pflash_blk[i] = pflash_cfi01_get_blk(pcms->flash[i]);
+        pflash_blk[i] = pflash_cfi01_get_blk(DEVICE(pcms->flash[i]));
     }
 
     /* Reject gaps */
diff --git a/include/hw/block/flash.h b/include/hw/block/flash.h
index 86d8363bb0..961b6e9f74 100644
--- a/include/hw/block/flash.h
+++ b/include/hw/block/flash.h
@@ -21,7 +21,7 @@ PFlashCFI01 *pflash_cfi01_register(hwaddr base,
                                    uint16_t id0, uint16_t id1,
                                    uint16_t id2, uint16_t id3,
                                    int be);
-BlockBackend *pflash_cfi01_get_blk(PFlashCFI01 *fl);
+BlockBackend *pflash_cfi01_get_blk(DeviceState *dev);
 MemoryRegion *pflash_cfi01_get_memory(PFlashCFI01 *fl);
 void pflash_cfi01_legacy_drive(PFlashCFI01 *dev, DriveInfo *dinfo);
 
-- 
2.38.1



  parent reply	other threads:[~2023-01-09 12:37 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-09 12:08 [PATCH v2 00/21] hw: Remove implicit sysbus_mmio_map() from pflash APIs Philippe Mathieu-Daudé
2023-01-09 12:08 ` [PATCH v2 01/21] hw/block: Rename TYPE_PFLASH_CFI02 'width' property as 'device-width' Philippe Mathieu-Daudé
2023-01-09 13:33   ` BALATON Zoltan
2023-01-09 13:56     ` Philippe Mathieu-Daudé
2023-01-09 14:18       ` BALATON Zoltan
2023-01-09 15:14         ` Philippe Mathieu-Daudé
2023-01-09 14:33       ` Daniel P. Berrangé
2023-01-09 15:17         ` Philippe Mathieu-Daudé
2023-01-13 13:37       ` Peter Maydell
2023-01-16  6:40         ` Markus Armbruster
2023-01-16  8:41           ` Philippe Mathieu-Daudé
2023-01-17  8:11             ` Markus Armbruster
2023-01-09 12:08 ` Philippe Mathieu-Daudé [this message]
2023-01-09 12:08 ` [PATCH v2 03/21] hw/block: Use pflash_cfi01_get_blk() in pflash_cfi01_legacy_drive() Philippe Mathieu-Daudé
2023-01-09 12:08 ` [PATCH v2 04/21] hw/block: Pass DeviceState to pflash_cfi01_get_memory() Philippe Mathieu-Daudé
2023-01-09 23:42   ` Bernhard Beschow
2023-01-13 13:40     ` Peter Maydell
2023-01-09 12:08 ` [PATCH v2 05/21] hw/arm: Use generic DeviceState instead of PFlashCFI01 Philippe Mathieu-Daudé
2023-01-09 12:08 ` [PATCH v2 06/21] hw/loongarch: " Philippe Mathieu-Daudé
2023-01-09 12:08 ` [PATCH v2 07/21] hw/riscv: " Philippe Mathieu-Daudé
2023-01-09 22:57   ` Alistair Francis
2023-01-09 12:08 ` [PATCH v2 08/21] hw/i386: " Philippe Mathieu-Daudé
2023-01-09 12:08 ` [PATCH v2 09/21] hw/xtensa: " Philippe Mathieu-Daudé
2023-01-09 12:08 ` [PATCH v2 10/21] hw/sh4: Open-code pflash_cfi02_register() Philippe Mathieu-Daudé
2023-01-09 13:40   ` BALATON Zoltan
2023-01-09 13:51     ` Philippe Mathieu-Daudé
2023-01-09 14:06       ` BALATON Zoltan
2023-01-09 12:08 ` [PATCH v2 11/21] hw/arm/digic: " Philippe Mathieu-Daudé
2023-01-13 13:47   ` Peter Maydell
2023-01-09 12:08 ` [PATCH v2 12/21] hw/arm/musicpal: " Philippe Mathieu-Daudé
2023-01-13 13:48   ` Peter Maydell
2023-01-09 12:08 ` [PATCH v2 13/21] hw/arm/xilinx_zynq: " Philippe Mathieu-Daudé
2023-01-13 13:55   ` Peter Maydell
2023-01-09 12:08 ` [PATCH v2 14/21] hw/block: Remove unused pflash_cfi02_register() Philippe Mathieu-Daudé
2023-01-09 12:08 ` [PATCH v2 15/21] hw/block: Make PFlashCFI02 QOM declaration internal Philippe Mathieu-Daudé
2023-01-09 12:08 ` [PATCH v2 16/21] hw/arm: Open-code pflash_cfi01_register() Philippe Mathieu-Daudé
2023-01-13 14:03   ` Peter Maydell
2023-01-09 12:08 ` [PATCH v2 17/21] hw/microblaze: " Philippe Mathieu-Daudé
2023-01-09 12:08 ` [PATCH v2 18/21] hw/mips: " Philippe Mathieu-Daudé
2023-01-09 12:08 ` [PATCH v2 19/21] hw/ppc: " Philippe Mathieu-Daudé
2023-01-09 13:52   ` BALATON Zoltan
2023-01-09 12:08 ` [PATCH v2 20/21] hw/block: Remove unused pflash_cfi01_register() Philippe Mathieu-Daudé
2023-01-09 12:08 ` [PATCH v2 21/21] hw/block: Make PFlashCFI01 QOM declaration internal Philippe Mathieu-Daudé
2023-01-09 12:13 ` [PATCH v2 00/21] hw: Remove implicit sysbus_mmio_map() from pflash APIs 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=20230109120833.3330-3-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=bmeng.cn@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /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).