public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: Simon Glass <sjg@chromium.org>,
	Vladimir Oltean <vladimir.oltean@nxp.com>,
	Bin Meng <bmeng.cn@gmail.com>, Stefan Roese <sr@denx.de>
Cc: u-boot@lists.denx.de
Subject: [PATCH 3/5] pci: Fix configuring BARs
Date: Thu,  7 Oct 2021 14:50:59 +0200	[thread overview]
Message-ID: <20211007125101.21811-3-pali@kernel.org> (raw)
In-Reply-To: <20211007125101.21811-1-pali@kernel.org>

Number of BARs is defined by header type, not by class code.

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 drivers/pci/pci_auto.c | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)

diff --git a/drivers/pci/pci_auto.c b/drivers/pci/pci_auto.c
index 288f7996c7c0..5af4ee6e56df 100644
--- a/drivers/pci/pci_auto.c
+++ b/drivers/pci/pci_auto.c
@@ -19,7 +19,7 @@
 #define CONFIG_SYS_PCI_CACHE_LINE_SIZE	8
 #endif
 
-static void dm_pciauto_setup_device(struct udevice *dev, int bars_num,
+static void dm_pciauto_setup_device(struct udevice *dev,
 				    struct pci_region *mem,
 				    struct pci_region *prefetch,
 				    struct pci_region *io)
@@ -28,6 +28,7 @@ static void dm_pciauto_setup_device(struct udevice *dev, int bars_num,
 	pci_size_t bar_size;
 	u16 cmdstat = 0;
 	int bar, bar_nr = 0;
+	int bars_num;
 	u8 header_type;
 	int rom_addr;
 	pci_addr_t bar_value;
@@ -39,6 +40,26 @@ static void dm_pciauto_setup_device(struct udevice *dev, int bars_num,
 	cmdstat = (cmdstat & ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) |
 			PCI_COMMAND_MASTER;
 
+	dm_pci_read_config8(dev, PCI_HEADER_TYPE, &header_type);
+	header_type &= 0x7f;
+
+	switch (header_type) {
+	case PCI_HEADER_TYPE_NORMAL:
+		bars_num = 6;
+		break;
+	case PCI_HEADER_TYPE_BRIDGE:
+		bars_num = 2;
+		break;
+	case PCI_HEADER_TYPE_CARDBUS:
+		/* CardBus header does not have any BAR */
+		bars_num = 0;
+		break;
+	default:
+		/* Skip configuring BARs for unknown header types */
+		bars_num = 0;
+		break;
+	}
+
 	for (bar = PCI_BASE_ADDRESS_0;
 	     bar < PCI_BASE_ADDRESS_0 + (bars_num * 4); bar += 4) {
 		int ret = 0;
@@ -129,8 +150,6 @@ static void dm_pciauto_setup_device(struct udevice *dev, int bars_num,
 	}
 
 	/* Configure the expansion ROM address */
-	dm_pci_read_config8(dev, PCI_HEADER_TYPE, &header_type);
-	header_type &= 0x7f;
 	if (header_type == PCI_HEADER_TYPE_NORMAL ||
 	    header_type == PCI_HEADER_TYPE_BRIDGE) {
 		rom_addr = (header_type == PCI_HEADER_TYPE_NORMAL) ?
@@ -343,7 +362,7 @@ int dm_pciauto_config_device(struct udevice *dev)
 		debug("PCI Autoconfig: Found P2P bridge, device %d\n",
 		      PCI_DEV(dm_pci_get_bdf(dev)));
 
-		dm_pciauto_setup_device(dev, 2, pci_mem, pci_prefetch, pci_io);
+		dm_pciauto_setup_device(dev, pci_mem, pci_prefetch, pci_io);
 
 		ret = dm_pci_hose_probe_bus(dev);
 		if (ret < 0)
@@ -356,7 +375,7 @@ int dm_pciauto_config_device(struct udevice *dev)
 		 * just do a minimal setup of the bridge,
 		 * let the OS take care of the rest
 		 */
-		dm_pciauto_setup_device(dev, 0, pci_mem, pci_prefetch, pci_io);
+		dm_pciauto_setup_device(dev, pci_mem, pci_prefetch, pci_io);
 
 		debug("PCI Autoconfig: Found P2CardBus bridge, device %d\n",
 		      PCI_DEV(dm_pci_get_bdf(dev)));
@@ -388,7 +407,7 @@ int dm_pciauto_config_device(struct udevice *dev)
 		/* fall through */
 
 	default:
-		dm_pciauto_setup_device(dev, 6, pci_mem, pci_prefetch, pci_io);
+		dm_pciauto_setup_device(dev, pci_mem, pci_prefetch, pci_io);
 		break;
 	}
 
-- 
2.20.1


  parent reply	other threads:[~2021-10-07 12:51 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-07 12:50 [PATCH 1/5] pci: Skip configuring PCI Rom Address for unsupported header types Pali Rohár
2021-10-07 12:50 ` [PATCH 2/5] pci: Skip configuring invalid P2P bridge devices Pali Rohár
2021-10-08  5:52   ` Stefan Roese
2021-10-15 11:52   ` Tom Rini
2021-10-07 12:50 ` Pali Rohár [this message]
2021-10-08  5:53   ` [PATCH 3/5] pci: Fix configuring BARs Stefan Roese
2021-10-15 11:52   ` Tom Rini
2021-10-07 12:51 ` [PATCH 4/5] pci: Fix showing bars Pali Rohár
2021-10-08  5:53   ` Stefan Roese
2021-10-15 11:52   ` Tom Rini
2021-10-07 12:51 ` [PATCH 5/5] pci: Fix showing registers Pali Rohár
2021-10-08  5:53   ` Stefan Roese
2021-10-15 11:52   ` Tom Rini
2021-10-08  5:52 ` [PATCH 1/5] pci: Skip configuring PCI Rom Address for unsupported header types Stefan Roese
2021-10-15 11:52 ` Tom Rini

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=20211007125101.21811-3-pali@kernel.org \
    --to=pali@kernel.org \
    --cc=bmeng.cn@gmail.com \
    --cc=sjg@chromium.org \
    --cc=sr@denx.de \
    --cc=u-boot@lists.denx.de \
    --cc=vladimir.oltean@nxp.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