mtd: rawnand: denali: deassert write protect pin
[oweals/u-boot.git] / drivers / pci / pci_auto_common.c
index 1d202ae2ef03e0f8907075a9b9983a90e506e6de..c0a53dcc929a27835ff5199e3c86045ca9a6f0de 100644 (file)
@@ -14,6 +14,7 @@
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
+#include <log.h>
 #include <pci.h>
 
 void pciauto_region_init(struct pci_region *res)
@@ -21,9 +22,10 @@ void pciauto_region_init(struct pci_region *res)
        /*
         * Avoid allocating PCI resources from address 0 -- this is illegal
         * according to PCI 2.1 and moreover, this is known to cause Linux IDE
-        * drivers to fail. Use a reasonable starting value of 0x1000 instead.
+        * drivers to fail. Use a reasonable starting value of 0x1000 instead
+        * if the bus start address is below 0x1000.
         */
-       res->bus_lower = res->bus_start ? res->bus_start : 0x1000;
+       res->bus_lower = res->bus_start < 0x1000 ? 0x1000 : res->bus_start;
 }
 
 void pciauto_region_align(struct pci_region *res, pci_size_t size)
@@ -32,25 +34,32 @@ void pciauto_region_align(struct pci_region *res, pci_size_t size)
 }
 
 int pciauto_region_allocate(struct pci_region *res, pci_size_t size,
-       pci_addr_t *bar)
+       pci_addr_t *bar, bool supports_64bit)
 {
        pci_addr_t addr;
 
        if (!res) {
-               debug("No resource");
+               debug("No resource\n");
                goto error;
        }
 
        addr = ((res->bus_lower - 1) | (size - 1)) + 1;
 
        if (addr - res->bus_start + size > res->size) {
-               debug("No room in resource");
+               debug("No room in resource, avail start=%llx / size=%llx, "
+                     "need=%llx\n", (unsigned long long)res->bus_lower,
+                     (unsigned long long)res->size, (unsigned long long)size);
+               goto error;
+       }
+
+       if (upper_32_bits(addr) && !supports_64bit) {
+               debug("Cannot assign 64-bit address to 32-bit-only resource\n");
                goto error;
        }
 
        res->bus_lower = addr + size;
 
-       debug("address=0x%llx bus_lower=0x%llx", (unsigned long long)addr,
+       debug("address=0x%llx bus_lower=0x%llx\n", (unsigned long long)addr,
              (unsigned long long)res->bus_lower);
 
        *bar = addr;