pci: Fix showing bars
authorPali Rohár <pali@kernel.org>
Thu, 7 Oct 2021 12:51:00 +0000 (14:51 +0200)
committerTom Rini <trini@konsulko.com>
Thu, 14 Oct 2021 23:45:07 +0000 (19:45 -0400)
Header type is 7-bit number so properly clear upper 8th bit which
indicates multifunction device.

And do not try to show bars for unsupported header types.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>
cmd/pci.c

index cfabdc0..4a82854 100644 (file)
--- a/cmd/pci.c
+++ b/cmd/pci.c
@@ -71,10 +71,15 @@ static int pci_bar_show(struct udevice *dev)
        int prefetchable;
 
        dm_pci_read_config8(dev, PCI_HEADER_TYPE, &header_type);
+       header_type &= 0x7f;
 
        if (header_type == PCI_HEADER_TYPE_CARDBUS) {
                printf("CardBus doesn't support BARs\n");
                return -ENOSYS;
+       } else if (header_type != PCI_HEADER_TYPE_NORMAL &&
+                  header_type != PCI_HEADER_TYPE_BRIDGE) {
+               printf("unknown header type\n");
+               return -ENOSYS;
        }
 
        bar_cnt = (header_type == PCI_HEADER_TYPE_NORMAL) ? 6 : 2;