From: Thomas Huth <thuth@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>, qemu-devel@nongnu.org
Cc: "Daniel P. Berrangé" <berrange@redhat.com>,
"Ilya Leoshkevich" <iii@linux.ibm.com>,
"Halil Pasic" <pasic@linux.ibm.com>,
"Huacai Chen" <chenhuacai@kernel.org>,
"Beniamino Galvani" <b.galvani@gmail.com>,
"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
qemu-arm@nongnu.org,
"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
"Eric Farman" <farman@linux.ibm.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
qemu-s390x@nongnu.org,
"Strahinja Jankovic" <strahinja.p.jankovic@gmail.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Markus Armbruster" <armbru@redhat.com>,
"Song Gao" <gaosong@loongson.cn>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Peter Xu" <peterx@redhat.com>, "Sergio Lopez" <slp@redhat.com>,
"Christian Borntraeger" <borntraeger@linux.ibm.com>,
"David Hildenbrand" <david@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Jason Wang" <jasowang@redhat.com>
Subject: Re: [PATCH v2 05/12] hw/pci-host/bonito: Do not use SysBus API to map local MMIO region
Date: Thu, 19 Oct 2023 09:26:52 +0200 [thread overview]
Message-ID: <a00df2c8-6108-45f9-ab35-722f989f2057@redhat.com> (raw)
In-Reply-To: <20231019071611.98885-6-philmd@linaro.org>
On 19/10/2023 09.16, Philippe Mathieu-Daudé wrote:
> There is no point in exposing an internal MMIO region via
> SysBus and directly mapping it in the very same device.
>
> Just map it without using the SysBus API.
>
> Transformation done using the following coccinelle script:
>
> @@
> expression sbdev;
> expression index;
> expression addr;
> expression subregion;
> @@
> - sysbus_init_mmio(sbdev, subregion);
> ... when != sbdev
> - sysbus_mmio_map(sbdev, index, addr);
> + memory_region_add_subregion(get_system_memory(), addr, subregion);
>
> and manually adding the local 'host_mem' variable to
> avoid multiple calls to get_system_memory().
Thanks for updating it!
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> hw/pci-host/bonito.c | 32 ++++++++++++++++----------------
> 1 file changed, 16 insertions(+), 16 deletions(-)
>
> diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c
> index ee6cb85e97..96bd028671 100644
> --- a/hw/pci-host/bonito.c
> +++ b/hw/pci-host/bonito.c
> @@ -654,10 +654,10 @@ static void bonito_host_realize(DeviceState *dev, Error **errp)
> static void bonito_pci_realize(PCIDevice *dev, Error **errp)
> {
> PCIBonitoState *s = PCI_BONITO(dev);
> - SysBusDevice *sysbus = SYS_BUS_DEVICE(s->pcihost);
> PCIHostState *phb = PCI_HOST_BRIDGE(s->pcihost);
> BonitoState *bs = s->pcihost;
> MemoryRegion *pcimem_alias = g_new(MemoryRegion, 1);
> + MemoryRegion *host_mem = get_system_memory();
>
> /*
> * Bonito North Bridge, built on FPGA,
> @@ -668,48 +668,48 @@ static void bonito_pci_realize(PCIDevice *dev, Error **errp)
> /* set the north bridge register mapping */
> memory_region_init_io(&s->iomem, OBJECT(s), &bonito_ops, s,
> "north-bridge-register", BONITO_INTERNAL_REG_SIZE);
> - sysbus_init_mmio(sysbus, &s->iomem);
> - sysbus_mmio_map(sysbus, 0, BONITO_INTERNAL_REG_BASE);
> + memory_region_add_subregion(host_mem, BONITO_INTERNAL_REG_BASE,
> + &s->iomem);
>
> /* set the north bridge pci configure mapping */
> memory_region_init_io(&phb->conf_mem, OBJECT(s), &bonito_pciconf_ops, s,
> "north-bridge-pci-config", BONITO_PCICONFIG_SIZE);
> - sysbus_init_mmio(sysbus, &phb->conf_mem);
> - sysbus_mmio_map(sysbus, 1, BONITO_PCICONFIG_BASE);
> + memory_region_add_subregion(host_mem, BONITO_PCICONFIG_BASE,
> + &phb->conf_mem);
>
> /* set the south bridge pci configure mapping */
> memory_region_init_io(&phb->data_mem, OBJECT(s), &bonito_spciconf_ops, s,
> "south-bridge-pci-config", BONITO_SPCICONFIG_SIZE);
> - sysbus_init_mmio(sysbus, &phb->data_mem);
> - sysbus_mmio_map(sysbus, 2, BONITO_SPCICONFIG_BASE);
> + memory_region_add_subregion(host_mem, BONITO_SPCICONFIG_BASE,
> + &phb->data_mem);
>
> create_unimplemented_device("bonito", BONITO_REG_BASE, BONITO_REG_SIZE);
>
> memory_region_init_io(&s->iomem_ldma, OBJECT(s), &bonito_ldma_ops, s,
> "ldma", 0x100);
> - sysbus_init_mmio(sysbus, &s->iomem_ldma);
> - sysbus_mmio_map(sysbus, 3, 0x1fe00200);
> + memory_region_add_subregion(host_mem, 0x1fe00200,
> + &s->iomem_ldma);
>
> /* PCI copier */
> memory_region_init_io(&s->iomem_cop, OBJECT(s), &bonito_cop_ops, s,
> "cop", 0x100);
> - sysbus_init_mmio(sysbus, &s->iomem_cop);
> - sysbus_mmio_map(sysbus, 4, 0x1fe00300);
> + memory_region_add_subregion(host_mem, 0x1fe00300,
> + &s->iomem_cop);
At least the above two hunks look like they could now fit into one line?
Anyway:
Reviewed-by: Thomas Huth <thuth@redhat.com>
next prev parent reply other threads:[~2023-10-19 7:27 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-19 7:15 [PATCH v2 00/12] hw: Strengthen SysBus & QBus API Philippe Mathieu-Daudé
2023-10-19 7:15 ` [PATCH v2 01/12] hw/i386/amd_iommu: Do not use SysBus API to map local MMIO region Philippe Mathieu-Daudé
2023-10-20 3:33 ` Zhao Liu
2023-10-19 7:16 ` [PATCH v2 02/12] hw/i386/intel_iommu: " Philippe Mathieu-Daudé
2023-10-20 3:35 ` Zhao Liu
2023-10-19 7:16 ` [PATCH v2 03/12] hw/misc/allwinner-dramc: Move sysbus_mmio_map call from init -> realize Philippe Mathieu-Daudé
2023-10-19 7:34 ` Thomas Huth
2023-10-19 7:16 ` [PATCH v2 04/12] hw/misc/allwinner-dramc: Do not use SysBus API to map local MMIO region Philippe Mathieu-Daudé
2023-10-19 7:44 ` Thomas Huth
2023-10-19 7:16 ` [PATCH v2 05/12] hw/pci-host/bonito: " Philippe Mathieu-Daudé
2023-10-19 7:26 ` Thomas Huth [this message]
2023-10-19 7:38 ` Philippe Mathieu-Daudé
2023-10-19 7:16 ` [PATCH v2 06/12] hw/acpi: Realize ACPI_GED sysbus device before accessing it Philippe Mathieu-Daudé
2023-10-19 7:16 ` [PATCH v2 07/12] hw/arm/virt: Realize ARM_GICV2M " Philippe Mathieu-Daudé
2023-10-19 7:16 ` [PATCH v2 08/12] hw/isa: Realize ISA BUS " Philippe Mathieu-Daudé
2023-10-19 7:16 ` [PATCH v2 09/12] hw/s390x/css-bridge: Realize " Philippe Mathieu-Daudé
2023-10-19 7:46 ` Thomas Huth
2023-10-20 14:21 ` Eric Farman
2023-10-19 7:16 ` [PATCH v2 10/12] hw/qdev: Ensure parent device is not realized before adding bus Philippe Mathieu-Daudé
2023-10-19 7:16 ` [PATCH v2 11/12] hw/sysbus: Ensure device is not realized before adding MMIO region Philippe Mathieu-Daudé
2023-10-19 7:16 ` [PATCH v2 12/12] hw/sysbus: Ensure device is realized before mapping it Philippe Mathieu-Daudé
2023-10-19 7:32 ` [PATCH v2 00/12] hw: Strengthen SysBus & QBus API Thomas Huth
2023-10-19 7:35 ` Philippe Mathieu-Daudé
2023-10-19 21:40 ` 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=a00df2c8-6108-45f9-ab35-722f989f2057@redhat.com \
--to=thuth@redhat.com \
--cc=armbru@redhat.com \
--cc=b.galvani@gmail.com \
--cc=berrange@redhat.com \
--cc=borntraeger@linux.ibm.com \
--cc=chenhuacai@kernel.org \
--cc=david@redhat.com \
--cc=eduardo@habkost.net \
--cc=farman@linux.ibm.com \
--cc=gaosong@loongson.cn \
--cc=iii@linux.ibm.com \
--cc=jasowang@redhat.com \
--cc=jiaxun.yang@flygoat.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=mst@redhat.com \
--cc=pasic@linux.ibm.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=slp@redhat.com \
--cc=strahinja.p.jankovic@gmail.com \
/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).