From: Bernhard Beschow <shentey@gmail.com>
To: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, "Jiaxun Yang" <jiaxun.yang@flygoat.com>,
"BALATON Zoltan" <balaton@eik.bme.hu>,
"John Snow" <jsnow@redhat.com>,
"Huacai Chen" <chenhuacai@kernel.org>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
qemu-ppc@nongnu.org
Subject: Re: [PATCH 10/13] hw/ide/piix: Reuse PCIIDEState::{cmd,data}_ops
Date: Fri, 28 Apr 2023 15:58:52 +0000 [thread overview]
Message-ID: <22990C1E-D554-4FA1-AE08-DA433AD26247@gmail.com> (raw)
In-Reply-To: <6D292D6F-D82B-4425-8A03-7A51AA7791B0@gmail.com>
Am 27. April 2023 18:15:24 UTC schrieb Bernhard Beschow <shentey@gmail.com>:
>
>
>Am 27. April 2023 10:52:17 UTC schrieb Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>:
>>On 26/04/2023 21:14, Bernhard Beschow wrote:
>>
>>> Am 26. April 2023 18:18:35 UTC schrieb Bernhard Beschow <shentey@gmail.com>:
>>>>
>>>>
>>>> Am 26. April 2023 11:37:48 UTC schrieb Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>:
>>>>> On 22/04/2023 16:07, Bernhard Beschow wrote:
>>>>>
>>>>>> Now that PCIIDEState::{cmd,data}_ops are initialized in the base class
>>>>>> constructor there is an opportunity for PIIX to reuse these attributes. This
>>>>>> resolves usage of ide_init_ioport() which would fall back internally to using
>>>>>> the isabus global due to NULL being passed as ISADevice by PIIX.
>>>>>>
>>>>>> Signed-off-by: Bernhard Beschow <shentey@gmail.com>
>>>>>> ---
>>>>>> hw/ide/piix.c | 30 +++++++++++++-----------------
>>>>>> 1 file changed, 13 insertions(+), 17 deletions(-)
>>>>>>
>>>>>> diff --git a/hw/ide/piix.c b/hw/ide/piix.c
>>>>>> index a3a15dc7db..406a67fa0f 100644
>>>>>> --- a/hw/ide/piix.c
>>>>>> +++ b/hw/ide/piix.c
>>>>>> @@ -104,34 +104,32 @@ static void piix_ide_reset(DeviceState *dev)
>>>>>> pci_set_byte(pci_conf + 0x20, 0x01); /* BMIBA: 20-23h */
>>>>>> }
>>>>>> -static bool pci_piix_init_bus(PCIIDEState *d, unsigned i, ISABus *isa_bus,
>>>>>> - Error **errp)
>>>>>> +static void pci_piix_init_bus(PCIIDEState *d, unsigned i, ISABus *isa_bus)
>>>>>> {
>>>>>> static const struct {
>>>>>> int iobase;
>>>>>> int iobase2;
>>>>>> int isairq;
>>>>>> } port_info[] = {
>>>>>> - {0x1f0, 0x3f6, 14},
>>>>>> - {0x170, 0x376, 15},
>>>>>> + {0x1f0, 0x3f4, 14},
>>>>>> + {0x170, 0x374, 15},
>>>>>> };
>>>>>> - int ret;
>>>>>> + MemoryRegion *address_space_io = pci_address_space_io(PCI_DEVICE(d));
>>>>>> ide_bus_init(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2);
>>>>>> - ret = ide_init_ioport(&d->bus[i], NULL, port_info[i].iobase,
>>>>>> - port_info[i].iobase2);
>>>>>> - if (ret) {
>>>>>> - error_setg_errno(errp, -ret, "Failed to realize %s port %u",
>>>>>> - object_get_typename(OBJECT(d)), i);
>>>>>> - return false;
>>>>>> - }
>>>>>> + memory_region_add_subregion(address_space_io, port_info[i].iobase,
>>>>>> + &d->data_ops[i]);
>>>>>> + /*
>>>>>> + * PIIX forwards the last byte of cmd_ops to ISA. Model this using a low
>>>>>> + * prio so competing memory regions take precedence.
>>>>>> + */
>>>>>> + memory_region_add_subregion_overlap(address_space_io, port_info[i].iobase2,
>>>>>> + &d->cmd_ops[i], -1);
>>>>>
>>>>> Interesting. Is this behaviour documented somewhere and/or used in one of your test images at all? If I'd have seen this myself, I probably thought that the addresses were a typo...
>>>>
>>>> I first stumbled upon this and wondered why this code was working with VIA_IDE (through my pc-via branch). Then I found the correct offsets there which are confirmed in the piix datasheet, e.g.: "Secondary Control Block Offset: 0374h"
>>>
>>> In case you were wondering about the forwarding of the last byte the datasheet says: "Accesses to byte 3 of the Control Block are forwarded to ISA where the floppy disk controller responds."
>>
>>Ahhh okay okay I see what's happening here: the PIIX IDE is assuming that the legacy ioport semantics are in operation here, which as you note above is where the FDC controller is also accessed via the above byte in the IDE control block. This is also why you need to change the address above from 0x3f6/0x376 to 0x3f4/0x374 when trying to use the MemoryRegions used for the PCI BARs since the PCI IDE controller specification requires a 4 byte allocation for the Control Block - see sections 2.0 and 2.2.
>
>Yes, PIIX assuming that might be the case. Why does it contradict the PCI IDE specification? PIIX seems to apply the apprppriate "workarounds" here.
>
>>
>>And that's fine, because the portio_lists used in ide_init_ioport() set up the legacy IDE ioports so that FDC accesses done in this way can succeed, and the PIIX IDE is hard-coded to legacy mode. So in fact PIIX IDE should keep using ide_init_ioport() rather than trying to re-use the BAR MemoryRegions so I think this patch should just be dropped.
>
>I was hoping to keep that patch...
The whole paragraph reads: "PIIX4 claims all accesses to these ranges, if enabled. The byte enables do not have to be externally decoded to assert DEVSEL#. Accesses to byte 3 of the Control Block are forwarded to ISA where the floppy disk controller responds." So PIIX doesn't look at the individual io ports but rather at the whole blocks covering them.
To me, this sounds like PIIX is applying the PCI IDE controller specification without the native option. In QEMU the block part of the specification is implemented by cmd_bar and data_bar. I think that reusing the blocks here in fact models the PIIX datasheet closer than the current implementation. I'd therefore keep this patch.
Best regards,
Bernhard
>
>Best regards,
>Bernhard
>
>>
>>>>>
>>>>>> ide_bus_init_output_irq(&d->bus[i],
>>>>>> isa_bus_get_irq(isa_bus, port_info[i].isairq));
>>>>>> bmdma_init(&d->bus[i], &d->bmdma[i], d);
>>>>>> ide_bus_register_restart_cb(&d->bus[i]);
>>>>>> -
>>>>>> - return true;
>>>>>> }
>>>>>> static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
>>>>>> @@ -160,9 +158,7 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
>>>>>> }
>>>>>> for (unsigned i = 0; i < 2; i++) {
>>>>>> - if (!pci_piix_init_bus(d, i, isa_bus, errp)) {
>>>>>> - return;
>>>>>> - }
>>>>>> + pci_piix_init_bus(d, i, isa_bus);
>>>>>> }
>>>>>> }
>>
>>
>>ATB,
>>
>>Mark.
next prev parent reply other threads:[~2023-04-28 16:00 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-22 15:07 [PATCH 00/13] Clean up PCI IDE device models Bernhard Beschow
2023-04-22 15:07 ` [PATCH 01/13] hw/ide/pci: Expose legacy interrupts as GPIOs Bernhard Beschow
2023-04-26 10:41 ` Mark Cave-Ayland
2023-04-26 19:26 ` Bernhard Beschow
2023-04-22 15:07 ` [PATCH 02/13] hw/ide/via: Implement ISA IRQ routing Bernhard Beschow
2023-04-22 17:23 ` BALATON Zoltan
2023-04-22 18:47 ` Bernhard Beschow
2023-04-22 19:21 ` BALATON Zoltan
2023-04-24 7:50 ` Bernhard Beschow
2023-04-24 10:10 ` BALATON Zoltan
2023-04-26 10:55 ` Mark Cave-Ayland
2023-04-22 15:07 ` [PATCH 03/13] hw/isa/vt82c686: Remove via_isa_set_irq() Bernhard Beschow
2023-04-26 10:55 ` Mark Cave-Ayland
2023-04-22 15:07 ` [PATCH 04/13] hw/ide: Extract IDEBus assignment into bmdma_init() Bernhard Beschow
2023-04-22 17:31 ` BALATON Zoltan
2023-04-23 17:36 ` Philippe Mathieu-Daudé
2023-04-26 10:56 ` Mark Cave-Ayland
2023-04-22 15:07 ` [PATCH 05/13] hw/ide: Extract pci_ide_class_init() Bernhard Beschow
2023-04-22 17:34 ` BALATON Zoltan
2023-04-22 18:59 ` Bernhard Beschow
2023-04-23 17:41 ` Philippe Mathieu-Daudé
2023-04-23 22:11 ` Bernhard Beschow
2023-04-23 22:23 ` BALATON Zoltan
2023-04-26 11:04 ` Mark Cave-Ayland
2023-04-26 18:32 ` Bernhard Beschow
2023-04-22 15:07 ` [PATCH 06/13] hw/ide: Extract bmdma_init_ops() Bernhard Beschow
2023-04-23 17:43 ` Philippe Mathieu-Daudé
2023-04-23 22:06 ` Bernhard Beschow
2023-04-26 11:14 ` Mark Cave-Ayland
2023-04-22 15:07 ` [PATCH 07/13] hw/ide: Extract pci_ide_{cmd, data}_le_ops initialization into base class constructor Bernhard Beschow
2023-04-23 17:46 ` [PATCH 07/13] hw/ide: Extract pci_ide_{cmd,data}_le_ops " Philippe Mathieu-Daudé
2023-04-24 7:45 ` Bernhard Beschow
2023-04-26 11:16 ` [PATCH 07/13] hw/ide: Extract pci_ide_{cmd, data}_le_ops " Mark Cave-Ayland
2023-04-22 15:07 ` [PATCH 08/13] hw/ide: Rename PCIIDEState::*_bar attributes Bernhard Beschow
2023-04-22 17:53 ` BALATON Zoltan
2023-04-26 11:21 ` Mark Cave-Ayland
2023-04-26 18:29 ` Bernhard Beschow
2023-04-27 11:07 ` Mark Cave-Ayland
2023-04-22 15:07 ` [PATCH 09/13] hw/ide/piix: Disuse isa_get_irq() Bernhard Beschow
2023-04-26 11:33 ` Mark Cave-Ayland
2023-04-26 18:25 ` Bernhard Beschow
2023-04-27 12:31 ` Mark Cave-Ayland
2023-05-13 11:53 ` Bernhard Beschow
2023-05-14 12:43 ` Mark Cave-Ayland
2023-04-22 15:07 ` [PATCH 10/13] hw/ide/piix: Reuse PCIIDEState::{cmd,data}_ops Bernhard Beschow
2023-04-26 11:37 ` Mark Cave-Ayland
2023-04-26 18:18 ` Bernhard Beschow
2023-04-26 20:14 ` Bernhard Beschow
2023-04-27 10:52 ` Mark Cave-Ayland
2023-04-27 18:15 ` Bernhard Beschow
2023-04-28 15:58 ` Bernhard Beschow [this message]
2023-04-28 17:00 ` BALATON Zoltan
2023-05-03 19:52 ` Mark Cave-Ayland
2023-05-13 12:21 ` Bernhard Beschow
2023-05-18 14:53 ` Mark Cave-Ayland
2023-05-19 17:09 ` Bernhard Beschow
2023-04-22 15:07 ` [PATCH 11/13] hw/ide/sii3112: " Bernhard Beschow
2023-04-22 21:10 ` BALATON Zoltan
2023-04-23 22:19 ` Bernhard Beschow
2023-04-23 22:38 ` BALATON Zoltan
2023-04-26 11:41 ` Mark Cave-Ayland
2023-04-26 20:24 ` Bernhard Beschow
2023-04-26 23:24 ` BALATON Zoltan
2023-04-27 11:15 ` Mark Cave-Ayland
2023-04-27 12:55 ` BALATON Zoltan
2023-05-03 20:25 ` Mark Cave-Ayland
2023-04-22 15:07 ` [PATCH 12/13] hw/ide/sii3112: Reuse PCIIDEState::bmdma_ops Bernhard Beschow
2023-04-26 11:44 ` Mark Cave-Ayland
2023-04-26 20:26 ` Bernhard Beschow
2023-04-22 15:07 ` [PATCH 13/13] hw/ide: Extract bmdma_clear_status() Bernhard Beschow
2023-04-22 21:26 ` BALATON Zoltan
2023-04-23 7:48 ` Bernhard Beschow
2023-04-23 10:40 ` BALATON Zoltan
2023-04-23 21:53 ` Bernhard Beschow
2023-04-22 22:46 ` BALATON Zoltan
2023-04-23 7:35 ` Bernhard Beschow
2023-04-26 11:48 ` Mark Cave-Ayland
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=22990C1E-D554-4FA1-AE08-DA433AD26247@gmail.com \
--to=shentey@gmail.com \
--cc=balaton@eik.bme.hu \
--cc=chenhuacai@kernel.org \
--cc=jiaxun.yang@flygoat.com \
--cc=jsnow@redhat.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=philmd@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@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).