* [PATCH 1/2] PCI: rework BAR size calculation
@ 2015-06-23 19:30 Lucas Stach
2015-06-23 19:30 ` [PATCH 2/2] PCI: remove bogus host bridge setup skipping Lucas Stach
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Lucas Stach @ 2015-06-23 19:30 UTC (permalink / raw)
To: barebox
The probe code now does a much better job at detecting bad BARs.
Also make sure to preserve any previous content of the BAR
registers if we don't relocate them.
Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
I hope this fixes the problems seen with new versions of QEMU on
MIPS malta.
---
drivers/pci/pci.c | 39 ++++++++++++++++++++++++++++++++++-----
1 file changed, 34 insertions(+), 5 deletions(-)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 3a0e7a5..1e45907 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -129,10 +129,24 @@ static struct pci_dev *alloc_pci_dev(void)
return dev;
}
+static u32 pci_size(u32 base, u32 maxbase, u32 mask)
+{
+ u32 size = maxbase & mask;
+ if (!size)
+ return 0;
+
+ size = (size & ~(size-1)) - 1;
+
+ if (base == maxbase && ((base | size) & mask) != mask)
+ return 0;
+
+ return size + 1;
+}
+
+
static void setup_device(struct pci_dev *dev, int max_bar)
{
- int bar, size;
- u32 mask;
+ int bar;
u8 cmd;
pci_read_config_byte(dev, PCI_COMMAND, &cmd);
@@ -141,9 +155,12 @@ static void setup_device(struct pci_dev *dev, int max_bar)
for (bar = 0; bar < max_bar; bar++) {
resource_size_t last_addr;
+ u32 orig, mask, size;
+ pci_read_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, &orig);
pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, 0xfffffffe);
pci_read_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, &mask);
+ pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, orig);
if (mask == 0 || mask == 0xffffffff) {
pr_debug("pbar%d set bad mask\n", bar);
@@ -151,7 +168,11 @@ static void setup_device(struct pci_dev *dev, int max_bar)
}
if (mask & 0x01) { /* IO */
- size = ((~(mask & 0xfffffffe)) & 0xffff) + 1;
+ size = pci_size(orig, mask, 0xfffffffe);
+ if (!size) {
+ pr_debug("pbar%d bad IO mask\n", bar);
+ continue;
+ }
pr_debug("pbar%d: mask=%08x io %d bytes\n", bar, mask, size);
if (last_io + size >
dev->bus->resource[PCI_BUS_RESOURCE_IO]->end) {
@@ -164,7 +185,11 @@ static void setup_device(struct pci_dev *dev, int max_bar)
last_io += size;
} else if ((mask & PCI_BASE_ADDRESS_MEM_PREFETCH) &&
last_mem_pref) /* prefetchable MEM */ {
- size = (~(mask & 0xfffffff0)) + 1;
+ size = pci_size(orig, mask, 0xfffffff0);
+ if (!size) {
+ pr_debug("pbar%d bad P-MEM mask\n", bar);
+ continue;
+ }
pr_debug("pbar%d: mask=%08x P memory %d bytes\n",
bar, mask, size);
if (last_mem_pref + size >
@@ -178,7 +203,11 @@ static void setup_device(struct pci_dev *dev, int max_bar)
last_addr = last_mem_pref;
last_mem_pref += size;
} else { /* non-prefetch MEM */
- size = (~(mask & 0xfffffff0)) + 1;
+ size = pci_size(orig, mask, 0xfffffff0);
+ if (!size) {
+ pr_debug("pbar%d bad NP-MEM mask\n", bar);
+ continue;
+ }
pr_debug("pbar%d: mask=%08x NP memory %d bytes\n",
bar, mask, size);
if (last_mem + size >
--
2.1.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] PCI: remove bogus host bridge setup skipping
2015-06-23 19:30 [PATCH 1/2] PCI: rework BAR size calculation Lucas Stach
@ 2015-06-23 19:30 ` Lucas Stach
2015-06-24 7:55 ` [PATCH 1/2] PCI: rework BAR size calculation Antony Pavlov
2015-06-25 6:38 ` Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Lucas Stach @ 2015-06-23 19:30 UTC (permalink / raw)
To: barebox
Apparently this was here to fix issues with some QEMU version,
but hasn't worked in the intended way for a long time. The probe
code should be mature enough by now, so this workaround isn't
needed anymore.
Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
drivers/pci/pci.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 1e45907..191561d 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -420,11 +420,6 @@ unsigned int pci_scan_bus(struct pci_bus *bus)
bus->number, dev->devfn, dev->vendor, dev->device, class, hdr_type);
continue;
}
-
- if (class == PCI_CLASS_BRIDGE_HOST) {
- pr_debug("skip pci host bridge\n");
- continue;
- }
}
/*
--
2.1.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] PCI: rework BAR size calculation
2015-06-23 19:30 [PATCH 1/2] PCI: rework BAR size calculation Lucas Stach
2015-06-23 19:30 ` [PATCH 2/2] PCI: remove bogus host bridge setup skipping Lucas Stach
@ 2015-06-24 7:55 ` Antony Pavlov
2015-06-25 6:38 ` Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Antony Pavlov @ 2015-06-24 7:55 UTC (permalink / raw)
To: Lucas Stach; +Cc: barebox
On Tue, 23 Jun 2015 21:30:38 +0200
Lucas Stach <dev@lynxeye.de> wrote:
> The probe code now does a much better job at detecting bad BARs.
> Also make sure to preserve any previous content of the BAR
> registers if we don't relocate them.
>
> Signed-off-by: Lucas Stach <dev@lynxeye.de>
> ---
> I hope this fixes the problems seen with new versions of QEMU on
> MIPS malta.
I have just tested this patchseries. The qemu problems are fixed, thanks!
> ---
> drivers/pci/pci.c | 39 ++++++++++++++++++++++++++++++++++-----
> 1 file changed, 34 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 3a0e7a5..1e45907 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -129,10 +129,24 @@ static struct pci_dev *alloc_pci_dev(void)
> return dev;
> }
>
> +static u32 pci_size(u32 base, u32 maxbase, u32 mask)
> +{
> + u32 size = maxbase & mask;
> + if (!size)
> + return 0;
> +
> + size = (size & ~(size-1)) - 1;
> +
> + if (base == maxbase && ((base | size) & mask) != mask)
> + return 0;
> +
> + return size + 1;
> +}
> +
> +
> static void setup_device(struct pci_dev *dev, int max_bar)
> {
> - int bar, size;
> - u32 mask;
> + int bar;
> u8 cmd;
>
> pci_read_config_byte(dev, PCI_COMMAND, &cmd);
> @@ -141,9 +155,12 @@ static void setup_device(struct pci_dev *dev, int max_bar)
>
> for (bar = 0; bar < max_bar; bar++) {
> resource_size_t last_addr;
> + u32 orig, mask, size;
>
> + pci_read_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, &orig);
> pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, 0xfffffffe);
> pci_read_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, &mask);
> + pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar * 4, orig);
>
> if (mask == 0 || mask == 0xffffffff) {
> pr_debug("pbar%d set bad mask\n", bar);
> @@ -151,7 +168,11 @@ static void setup_device(struct pci_dev *dev, int max_bar)
> }
>
> if (mask & 0x01) { /* IO */
> - size = ((~(mask & 0xfffffffe)) & 0xffff) + 1;
> + size = pci_size(orig, mask, 0xfffffffe);
> + if (!size) {
> + pr_debug("pbar%d bad IO mask\n", bar);
> + continue;
> + }
> pr_debug("pbar%d: mask=%08x io %d bytes\n", bar, mask, size);
> if (last_io + size >
> dev->bus->resource[PCI_BUS_RESOURCE_IO]->end) {
> @@ -164,7 +185,11 @@ static void setup_device(struct pci_dev *dev, int max_bar)
> last_io += size;
> } else if ((mask & PCI_BASE_ADDRESS_MEM_PREFETCH) &&
> last_mem_pref) /* prefetchable MEM */ {
> - size = (~(mask & 0xfffffff0)) + 1;
> + size = pci_size(orig, mask, 0xfffffff0);
> + if (!size) {
> + pr_debug("pbar%d bad P-MEM mask\n", bar);
> + continue;
> + }
> pr_debug("pbar%d: mask=%08x P memory %d bytes\n",
> bar, mask, size);
> if (last_mem_pref + size >
> @@ -178,7 +203,11 @@ static void setup_device(struct pci_dev *dev, int max_bar)
> last_addr = last_mem_pref;
> last_mem_pref += size;
> } else { /* non-prefetch MEM */
> - size = (~(mask & 0xfffffff0)) + 1;
> + size = pci_size(orig, mask, 0xfffffff0);
> + if (!size) {
> + pr_debug("pbar%d bad NP-MEM mask\n", bar);
> + continue;
> + }
> pr_debug("pbar%d: mask=%08x NP memory %d bytes\n",
> bar, mask, size);
> if (last_mem + size >
> --
> 2.1.0
>
--
--
Best regards,
Antony Pavlov
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] PCI: rework BAR size calculation
2015-06-23 19:30 [PATCH 1/2] PCI: rework BAR size calculation Lucas Stach
2015-06-23 19:30 ` [PATCH 2/2] PCI: remove bogus host bridge setup skipping Lucas Stach
2015-06-24 7:55 ` [PATCH 1/2] PCI: rework BAR size calculation Antony Pavlov
@ 2015-06-25 6:38 ` Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2015-06-25 6:38 UTC (permalink / raw)
To: Lucas Stach; +Cc: barebox
On Tue, Jun 23, 2015 at 09:30:38PM +0200, Lucas Stach wrote:
> The probe code now does a much better job at detecting bad BARs.
> Also make sure to preserve any previous content of the BAR
> registers if we don't relocate them.
>
> Signed-off-by: Lucas Stach <dev@lynxeye.de>
> ---
> I hope this fixes the problems seen with new versions of QEMU on
> MIPS malta.
Applied, thanks
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-06-25 6:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-23 19:30 [PATCH 1/2] PCI: rework BAR size calculation Lucas Stach
2015-06-23 19:30 ` [PATCH 2/2] PCI: remove bogus host bridge setup skipping Lucas Stach
2015-06-24 7:55 ` [PATCH 1/2] PCI: rework BAR size calculation Antony Pavlov
2015-06-25 6:38 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox