[PATCH v2 18/18] virtio: pci: Make use of dm_pci_map_bar()

Xiang W wxjstz at 126.com
Sun Aug 28 18:49:40 CEST 2022


在 2022-08-25星期四的 11:01 +0300,Felix Yan写道:
> Hi,
> 
> Today I discovered a failure which bisected to this commit.
> 
> When running QEMU with libvirt, which created some pcie devices, U-boot 
> fails on autoboot with:
> 
> Unhandled exception: Load access fault
> EPC: 00000000bff7c46e RA: 00000000bff7c46c TVAL: 0000000040200014
> EPC: 000000008002446e RA: 000000008002446c reloc adjusted
> 
> Code: 8082 1141 e022 e406 842e 40ef dc5f 611c (c783 0147)
> 
> I have tried to minimize the command line that makes the difference.
> 
> This works:
> 
> -device 
> '{"driver":"virtio-blk-pci","drive":"libvirt-2-format","id":"virtio-disk0","bootindex":1}'
> 
> This doesn't work:
> 
> -device 
> '{"driver":"virtio-blk-pci","bus":"pci.2","addr":"0x0","drive":"libvirt-2-format","id":"virtio-disk0","bootindex":1}'
> 
> I have tried this on multiple machines, different U-boot tags, mmode or 
> smode with OpenSBI, all with the same behavior. Latest U-boot master 
> with this commit reverted works fine on both cases.
> 
> I am very new to U-boot, please do let me know if more info are to be 
> provided.
> 
> Attached the full command line, for reference:
> 
> /usr/bin/qemu-system-riscv64  \
> -machine virt  \
> -bios u-boot/u-boot.bin  \
> -m 1024  \
> -device 
> '{"driver":"pcie-root-port","port":8,"chassis":1,"id":"pci.1","bus":"pcie.0","multifunction":true,"addr":"0x1"}' 
>   \
> -device 
> '{"driver":"pcie-root-port","port":9,"chassis":2,"id":"pci.2","bus":"pcie.0","addr":"0x1.0x1"}' 
>   \
> -blockdev 
> '{"driver":"file","filename":"archriscv-2022-08-24.qcow2","node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' 
>   \
> -blockdev 
> '{"node-name":"libvirt-2-format","read-only":false,"driver":"qcow2","file":"libvirt-2-storage","backing":null}' 
>   \
> -device 
> '{"driver":"virtio-blk-pci","bus":"pci.2","addr":"0x0","drive":"libvirt-2-format","id":"virtio-disk0","bootindex":1}' 
>   \
> -nographic
> 
> -- 
> Regards,
> Felix Yan

Please try my patch and let me know the test results

diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c
index 880a12cc28..cfde4007f5 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -466,7 +466,7 @@ static void __iomem *virtio_pci_map_capability(struct udevice *udev,
        unsigned long mask =
                        PCI_REGION_TYPE | PCI_REGION_SYS_MEMORY | PCI_REGION_RO;
        unsigned long flags = PCI_REGION_MEM;
-       u8 *p = dm_pci_map_bar(udev, PCI_BASE_ADDRESS_0 + cap->bar, cap->offset,
+       u8 *p = dm_pci_map_bar(udev, PCI_BASE_ADDRESS_0 + 4 * cap->bar, cap->offset,
                               cap->length, mask, flags);
 
        return (void __iomem *)p;

Regards,
Xiang W



More information about the U-Boot mailing list