From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Richard Henderson" <richard.henderson@linaro.org>
Subject: [PULL 04/46] hw/mips/gt64xxx_pci: Endian-swap using PCI_HOST_BRIDGE MemoryRegionOps
Date: Fri, 13 Jan 2023 16:44:50 +0100 [thread overview]
Message-ID: <20230113154532.49979-5-philmd@linaro.org> (raw)
In-Reply-To: <20230113154532.49979-1-philmd@linaro.org>
GT64120's PCI endianness swapping works on little-endian hosts,
but doesn't on big-endian ones. Instead of complicating how
CFGADDR/CFGDATA registers deal with endianness, use the existing
MemoryRegionOps from hw/pci/pci_host.c. Doing so also reduce the
access to internal PCI_HOST_BRIDGE fields.
Map the PCI_HOST_BRIDGE MemoryRegionOps into the corresponding
CFGADDR/CFGDATA regions in the ISD MMIO and remove the unused
code in the current ISD read/write handlers.
Update the mapping when PCI0_CMD register is accessed (in case
the endianness is changed).
This allows using the GT64120 on a big-endian host (and boot
the MIPS Malta machine in little-endian).
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20230104133935.4639-6-philmd@linaro.org>
---
hw/mips/gt64xxx_pci.c | 70 ++++++++++++++++++++++++++++++-------------
1 file changed, 50 insertions(+), 20 deletions(-)
diff --git a/hw/mips/gt64xxx_pci.c b/hw/mips/gt64xxx_pci.c
index 65416c7b27..81232514c5 100644
--- a/hw/mips/gt64xxx_pci.c
+++ b/hw/mips/gt64xxx_pci.c
@@ -298,6 +298,50 @@ static void gt64120_isd_mapping(GT64120State *s)
memory_region_transaction_commit();
}
+static void gt64120_update_pci_cfgdata_mapping(GT64120State *s)
+{
+ /* Indexed on MByteSwap bit, see Table 158: PCI_0 Command, Offset: 0xc00 */
+ static const MemoryRegionOps *pci_host_conf_ops[] = {
+ &pci_host_conf_be_ops, &pci_host_conf_le_ops
+ };
+ static const MemoryRegionOps *pci_host_data_ops[] = {
+ &pci_host_data_be_ops, &pci_host_data_le_ops
+ };
+ PCIHostState *phb = PCI_HOST_BRIDGE(s);
+
+ memory_region_transaction_begin();
+
+ /*
+ * The setting of the MByteSwap bit and MWordSwap bit in the PCI Internal
+ * Command Register determines how data transactions from the CPU to/from
+ * PCI are handled along with the setting of the Endianess bit in the CPU
+ * Configuration Register. See:
+ * - Table 16: 32-bit PCI Transaction Endianess
+ * - Table 158: PCI_0 Command, Offset: 0xc00
+ */
+ if (memory_region_is_mapped(&phb->conf_mem)) {
+ memory_region_del_subregion(&s->ISD_mem, &phb->conf_mem);
+ object_unparent(OBJECT(&phb->conf_mem));
+ }
+ memory_region_init_io(&phb->conf_mem, OBJECT(phb),
+ pci_host_conf_ops[s->regs[GT_PCI0_CMD] & 1],
+ s, "pci-conf-idx", 4);
+ memory_region_add_subregion_overlap(&s->ISD_mem, GT_PCI0_CFGADDR << 2,
+ &phb->conf_mem, 1);
+
+ if (memory_region_is_mapped(&phb->data_mem)) {
+ memory_region_del_subregion(&s->ISD_mem, &phb->data_mem);
+ object_unparent(OBJECT(&phb->data_mem));
+ }
+ memory_region_init_io(&phb->data_mem, OBJECT(phb),
+ pci_host_data_ops[s->regs[GT_PCI0_CMD] & 1],
+ s, "pci-conf-data", 4);
+ memory_region_add_subregion_overlap(&s->ISD_mem, GT_PCI0_CFGDATA << 2,
+ &phb->data_mem, 1);
+
+ memory_region_transaction_commit();
+}
+
static void gt64120_pci_mapping(GT64120State *s)
{
memory_region_transaction_begin();
@@ -389,7 +433,6 @@ static void gt64120_writel(void *opaque, hwaddr addr,
uint64_t val, unsigned size)
{
GT64120State *s = opaque;
- PCIHostState *phb = PCI_HOST_BRIDGE(s);
uint32_t saddr = addr >> 2;
trace_gt64120_write(addr, val);
@@ -592,6 +635,7 @@ static void gt64120_writel(void *opaque, hwaddr addr,
case GT_PCI0_CMD:
case GT_PCI1_CMD:
s->regs[saddr] = val & 0x0401fc0f;
+ gt64120_update_pci_cfgdata_mapping(s);
break;
case GT_PCI0_TOR:
case GT_PCI0_BS_SCS10:
@@ -632,15 +676,9 @@ static void gt64120_writel(void *opaque, hwaddr addr,
saddr << 2, size, size << 1, val);
break;
case GT_PCI0_CFGADDR:
- phb->config_reg = val & 0x80fffffc;
- break;
case GT_PCI0_CFGDATA:
- if (!(s->regs[GT_PCI0_CMD] & 1) && (phb->config_reg & 0x00fff800)) {
- val = bswap32(val);
- }
- if (phb->config_reg & (1u << 31)) {
- pci_data_write(phb->bus, phb->config_reg, val, 4);
- }
+ /* Mapped via in gt64120_pci_mapping() */
+ g_assert_not_reached();
break;
/* Interrupts */
@@ -698,7 +736,6 @@ static uint64_t gt64120_readl(void *opaque,
hwaddr addr, unsigned size)
{
GT64120State *s = opaque;
- PCIHostState *phb = PCI_HOST_BRIDGE(s);
uint32_t val;
uint32_t saddr = addr >> 2;
@@ -883,17 +920,9 @@ static uint64_t gt64120_readl(void *opaque,
/* PCI Internal */
case GT_PCI0_CFGADDR:
- val = phb->config_reg;
- break;
case GT_PCI0_CFGDATA:
- if (!(phb->config_reg & (1 << 31))) {
- val = 0xffffffff;
- } else {
- val = pci_data_read(phb->bus, phb->config_reg, 4);
- }
- if (!(s->regs[GT_PCI0_CMD] & 1) && (phb->config_reg & 0x00fff800)) {
- val = bswap32(val);
- }
+ /* Mapped via in gt64120_pci_mapping() */
+ g_assert_not_reached();
break;
case GT_PCI0_CMD:
@@ -1153,6 +1182,7 @@ static void gt64120_reset(DeviceState *dev)
gt64120_isd_mapping(s);
gt64120_pci_mapping(s);
+ gt64120_update_pci_cfgdata_mapping(s);
}
static void gt64120_realize(DeviceState *dev, Error **errp)
--
2.38.1
next prev parent reply other threads:[~2023-01-13 16:03 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-13 15:44 [PULL 00/46] MIPS patches for 2023-01-13 Philippe Mathieu-Daudé
2023-01-13 15:44 ` [PULL 01/46] hw/mips/malta: Split FPGA LEDs/ASCII display updates Philippe Mathieu-Daudé
2023-01-13 15:44 ` [PULL 02/46] hw/mips/malta: Trace " Philippe Mathieu-Daudé
2023-01-13 15:44 ` [PULL 03/46] hw/mips/gt64xxx_pci: Accumulate address space changes Philippe Mathieu-Daudé
2023-01-13 15:44 ` Philippe Mathieu-Daudé [this message]
2023-01-13 15:44 ` [PULL 05/46] hw/mips/Kconfig: Introduce CONFIG_GT64120 to select gt64xxx_pci.c Philippe Mathieu-Daudé
2023-01-13 15:44 ` [PULL 06/46] hw/mips/gt64xxx_pci: Let the GT64120 manage the lower 512MiB hole Philippe Mathieu-Daudé
2023-01-13 15:44 ` [PULL 07/46] hw/mips/gt64xxx_pci: Manage endian bits with the RegisterFields API Philippe Mathieu-Daudé
2023-01-13 15:44 ` [PULL 08/46] hw/mips/gt64xxx_pci: Add a 'cpu-little-endian' qdev property Philippe Mathieu-Daudé
2023-01-13 15:44 ` [PULL 09/46] hw/mips/malta: Explicit GT64120 endianness upon device creation Philippe Mathieu-Daudé
2023-01-13 15:44 ` [PULL 10/46] hw/mips/meson: Make gt64xxx_pci.c endian-agnostic Philippe Mathieu-Daudé
2023-01-13 15:44 ` [PULL 11/46] hw/mips/gt64xxx_pci: Move it to hw/pci-host/ Philippe Mathieu-Daudé
2023-01-13 15:44 ` [PULL 12/46] tests/avocado: Add tests booting YAMON ROM on MIPS Malta machines Philippe Mathieu-Daudé
2023-01-13 15:44 ` [PULL 13/46] hw/mips/bootloader: Handle buffers as opaque arrays Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 14/46] hw/mips/bootloader: Implement nanoMIPS NOP opcode generator Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 15/46] hw/mips/bootloader: Implement nanoMIPS SW " Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 16/46] hw/mips/bootloader: Implement nanoMIPS LI (LUI+ORI) " Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 17/46] hw/mips/bootloader: Implement nanoMIPS JALRc " Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 18/46] hw/mips/malta: Use bootloader generator API for nanoMIPS CPUs (1/5) Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 19/46] hw/mips/malta: Use bootloader generator API for nanoMIPS CPUs (2/5) Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 20/46] hw/mips/malta: Use bootloader generator API for nanoMIPS CPUs (3/5) Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 21/46] hw/mips/malta: Use bootloader generator API for nanoMIPS CPUs (4/5) Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 22/46] hw/mips/malta: Use bootloader generator API for nanoMIPS CPUs (5/5) Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 23/46] hw/mips/malta: Merge common BL code as bl_setup_gt64120_jump_kernel() Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 24/46] hw/mips/malta: Introduce PIIX4_PCI_DEVFN definition Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 25/46] hw/mips/malta: Set PIIX4 IRQ routes in embedded bootloader Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 26/46] hw/isa/piix4: Correct IRQRC[A:D] reset values Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 27/46] mips: Remove support for trap and emulate KVM Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 28/46] mips: Always include nanomips disassembler Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 29/46] hw/pci/pci_host: Trace config accesses on unexisting functions Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 30/46] hw/pci/pci: Factor out pci_bus_map_irqs() from pci_bus_irqs() Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 31/46] hw/isa/piix3: Decouple INTx-to-LNKx routing which is board-specific Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 32/46] hw/isa/piix4: " Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 33/46] hw/mips/Kconfig: Track Malta's PIIX dependencies via Kconfig Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 34/46] hw/usb/hcd-uhci: Introduce TYPE_ defines for device models Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 35/46] hw/intc/i8259: Make using the isa_pic singleton more type-safe Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 36/46] hw/intc: Extract the IRQ counting functions into a separate file Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 37/46] hw/core/qdev-properties-system: Allow the 'slew' policy only on x86 Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 38/46] hw/rtc/mc146818rtc: Make the mc146818 RTC device target independent Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 39/46] softmmu/rtc: Emit warning when using driftfix=slew on systems without mc146818 Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 40/46] hw/pci-host/bonito: Convert to 3-phase reset Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 41/46] hw/pci-host/bonito: Use 'bonito_host' for PCI host bridge code Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 42/46] hw/pci-host/bonito: Use 'bonito_pci' for PCI function #0 code Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 43/46] hw/pci-host/bonito: Declare TYPE_BONITO_PCI_HOST_BRIDGE in header Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 44/46] hw/mips/boston: Rename MachineState 'mc' pointer to 'ms' Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 45/46] target/mips: Restrict 'qapi-commands-machine.h' to system emulation Philippe Mathieu-Daudé
2023-01-13 15:45 ` [PULL 46/46] scripts/git.orderfile: Display MAINTAINERS changes first Philippe Mathieu-Daudé
2023-01-13 17:57 ` [PULL 00/46] MIPS patches for 2023-01-13 Peter Maydell
2023-01-13 20:31 ` Philippe Mathieu-Daudé
2023-01-16 15:00 ` Peter Maydell
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=20230113154532.49979-5-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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).