From nobody Sun Feb 8 19:56:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550495314078932.1449471122888; Mon, 18 Feb 2019 05:08:34 -0800 (PST) Received: from localhost ([127.0.0.1]:58056 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gviet-0008Vl-1l for importer@patchew.org; Mon, 18 Feb 2019 08:08:31 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44497) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gviTP-000894-SV for qemu-devel@nongnu.org; Mon, 18 Feb 2019 07:56:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gviTN-0000om-UD for qemu-devel@nongnu.org; Mon, 18 Feb 2019 07:56:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59652) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gviTI-0000WA-RH; Mon, 18 Feb 2019 07:56:33 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BB546C01DDE2; Mon, 18 Feb 2019 12:56:18 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5DA2561497; Mon, 18 Feb 2019 12:56:18 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 720201132D3C; Mon, 18 Feb 2019 13:56:15 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 18 Feb 2019 13:56:15 +0100 Message-Id: <20190218125615.18970-11-armbru@redhat.com> In-Reply-To: <20190218125615.18970-1-armbru@redhat.com> References: <20190218125615.18970-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 18 Feb 2019 12:56:18 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 10/10] hw/arm hw/xtensa: De-duplicate pflash creation code some X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, alex.bennee@linaro.org, mreitz@redhat.com, qemu-ppc@nongnu.org, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" pflash_cfi01_register() creates a TYPE_CFI_PFLASH01 device, sets properties, realizes, and wires up. We have three modified copies of it, because their users need to set additional properties, or have the wiring done differently. Factor out their common part into pflash_cfi01_create(). Signed-off-by: Markus Armbruster Reviewed-by: Laszlo Ersek --- hw/arm/vexpress.c | 22 +++++----------------- hw/arm/virt.c | 26 +++++++++----------------- hw/block/pflash_cfi01.c | 39 +++++++++++++++++++++++++++------------ hw/xtensa/xtfpga.c | 18 +++++++----------- include/hw/block/flash.h | 8 ++++++++ 5 files changed, 56 insertions(+), 57 deletions(-) diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c index 00913f2655..b23c63ed24 100644 --- a/hw/arm/vexpress.c +++ b/hw/arm/vexpress.c @@ -515,26 +515,14 @@ static void vexpress_modify_dtb(const struct arm_boot= _info *info, void *fdt) static PFlashCFI01 *ve_pflash_cfi01_register(hwaddr base, const char *name, DriveInfo *di) { - DeviceState *dev =3D qdev_create(NULL, TYPE_CFI_PFLASH01); + DeviceState *dev; =20 - if (di) { - qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(di), - &error_abort); - } - - qdev_prop_set_uint32(dev, "num-blocks", - VEXPRESS_FLASH_SIZE / VEXPRESS_FLASH_SECT_SIZE); - qdev_prop_set_uint64(dev, "sector-length", VEXPRESS_FLASH_SECT_SIZE); - qdev_prop_set_uint8(dev, "width", 4); + dev =3D DEVICE(pflash_cfi01_create(name, VEXPRESS_FLASH_SIZE, + di ? blk_by_legacy_dinfo(di) : NULL, + VEXPRESS_FLASH_SECT_SIZE, + 4, 0x89, 0x18, 0x00, 0x00, false)); qdev_prop_set_uint8(dev, "device-width", 2); - qdev_prop_set_bit(dev, "big-endian", false); - qdev_prop_set_uint16(dev, "id0", 0x89); - qdev_prop_set_uint16(dev, "id1", 0x18); - qdev_prop_set_uint16(dev, "id2", 0x00); - qdev_prop_set_uint16(dev, "id3", 0x00); - qdev_prop_set_string(dev, "name", name); qdev_init_nofail(dev); - sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base); return CFI_PFLASH01(dev); } diff --git a/hw/arm/virt.c b/hw/arm/virt.c index b7d53b2b87..7787918483 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -48,6 +48,7 @@ #include "exec/address-spaces.h" #include "qemu/bitops.h" #include "qemu/error-report.h" +#include "qemu/units.h" #include "hw/pci-host/gpex.h" #include "hw/arm/sysbus-fdt.h" #include "hw/platform-bus.h" @@ -875,29 +876,20 @@ static void create_one_flash(const char *name, hwaddr= flashbase, * parameters as the flash devices on the Versatile Express board. */ DriveInfo *dinfo =3D drive_get_next(IF_PFLASH); - DeviceState *dev =3D qdev_create(NULL, TYPE_CFI_PFLASH01); - SysBusDevice *sbd =3D SYS_BUS_DEVICE(dev); - const uint64_t sectorlength =3D 256 * 1024; + DeviceState *dev; + SysBusDevice *sbd; =20 - if (dinfo) { - qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo), - &error_abort); - } + dev =3D DEVICE(pflash_cfi01_create(name, flashsize, + dinfo ? blk_by_legacy_dinfo(dinfo) : = NULL, + 256 * KiB, + 4, 0x89, 0x18, 0x00, 0x00, false)); =20 - qdev_prop_set_uint32(dev, "num-blocks", flashsize / sectorlength); - qdev_prop_set_uint64(dev, "sector-length", sectorlength); - qdev_prop_set_uint8(dev, "width", 4); qdev_prop_set_uint8(dev, "device-width", 2); - qdev_prop_set_bit(dev, "big-endian", false); - qdev_prop_set_uint16(dev, "id0", 0x89); - qdev_prop_set_uint16(dev, "id1", 0x18); - qdev_prop_set_uint16(dev, "id2", 0x00); - qdev_prop_set_uint16(dev, "id3", 0x00); - qdev_prop_set_string(dev, "name", name); qdev_init_nofail(dev); =20 + sbd =3D SYS_BUS_DEVICE(dev); memory_region_add_subregion(sysmem, flashbase, - sysbus_mmio_get_region(SYS_BUS_DEVICE(dev)= , 0)); + sysbus_mmio_get_region(sbd, 0)); =20 if (file) { char *fn; diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index 2e161f937f..00c2efd0d7 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -920,15 +920,14 @@ static void pflash_cfi01_register_types(void) =20 type_init(pflash_cfi01_register_types) =20 -PFlashCFI01 *pflash_cfi01_register(hwaddr base, - const char *name, - hwaddr size, - BlockBackend *blk, - uint32_t sector_len, - int bank_width, - uint16_t id0, uint16_t id1, - uint16_t id2, uint16_t id3, - int be) +PFlashCFI01 *pflash_cfi01_create(const char *name, + hwaddr size, + BlockBackend *blk, + uint32_t sector_len, + int bank_width, + uint16_t id0, uint16_t id1, + uint16_t id2, uint16_t id3, + int be) { DeviceState *dev =3D qdev_create(NULL, TYPE_CFI_PFLASH01); =20 @@ -945,12 +944,28 @@ PFlashCFI01 *pflash_cfi01_register(hwaddr base, qdev_prop_set_uint16(dev, "id2", id2); qdev_prop_set_uint16(dev, "id3", id3); qdev_prop_set_string(dev, "name", name); - qdev_init_nofail(dev); - - sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base); return CFI_PFLASH01(dev); } =20 +PFlashCFI01 *pflash_cfi01_register(hwaddr base, + const char *name, + hwaddr size, + BlockBackend *blk, + uint32_t sector_len, + int bank_width, + uint16_t id0, uint16_t id1, + uint16_t id2, uint16_t id3, + int be) +{ + PFlashCFI01 *dev =3D pflash_cfi01_create(name, size, blk, + sector_len, bank_width, + id0, id1, id2, id3, be); + + qdev_init_nofail(DEVICE(dev)); + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base); + return dev; +} + MemoryRegion *pflash_cfi01_get_memory(PFlashCFI01 *fl) { return &fl->mem; diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c index a726d5632a..0e96e73ee2 100644 --- a/hw/xtensa/xtfpga.c +++ b/hw/xtensa/xtfpga.c @@ -167,21 +167,17 @@ static PFlashCFI01 *xtfpga_flash_init(MemoryRegion *a= ddress_space, DriveInfo *dinfo, int be) { SysBusDevice *s; - DeviceState *dev =3D qdev_create(NULL, TYPE_CFI_PFLASH01); + PFlashCFI01 *dev =3D pflash_cfi01_create("xtfpga.io.flash", + board->flash->size, + blk_by_legacy_dinfo(dinfo), + board->flash->sector_size, + 2, 0, 0, 0, 0, be); =20 - qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo), - &error_abort); - qdev_prop_set_uint32(dev, "num-blocks", - board->flash->size / board->flash->sector_size); - qdev_prop_set_uint64(dev, "sector-length", board->flash->sector_size); - qdev_prop_set_uint8(dev, "width", 2); - qdev_prop_set_bit(dev, "big-endian", be); - qdev_prop_set_string(dev, "name", "xtfpga.io.flash"); - qdev_init_nofail(dev); + qdev_init_nofail(DEVICE(dev)); s =3D SYS_BUS_DEVICE(dev); memory_region_add_subregion(address_space, board->flash->base, sysbus_mmio_get_region(s, 0)); - return CFI_PFLASH01(dev); + return dev; } =20 static uint64_t translate_phys_addr(void *opaque, uint64_t addr) diff --git a/include/hw/block/flash.h b/include/hw/block/flash.h index 24b13eb525..dbb25ba382 100644 --- a/include/hw/block/flash.h +++ b/include/hw/block/flash.h @@ -13,6 +13,14 @@ =20 typedef struct PFlashCFI01 PFlashCFI01; =20 +PFlashCFI01 *pflash_cfi01_create(const char *name, + hwaddr size, + BlockBackend *blk, + uint32_t sector_len, + int width, + uint16_t id0, uint16_t id1, + uint16_t id2, uint16_t id3, + int be); PFlashCFI01 *pflash_cfi01_register(hwaddr base, const char *name, hwaddr size, --=20 2.17.2