ddr: fsl: Impl. Erratum A008109
[oweals/u-boot.git] / drivers / ata / ahci.c
index e3135bb75fddb303cd3e826f02926df0c25e2cfe..47cdea1f586a438da39d7bf66b5698d43ef7b910 100644 (file)
@@ -9,6 +9,11 @@
  * This driver provides a SCSI interface to SATA.
  */
 #include <common.h>
+#include <blk.h>
+#include <cpu_func.h>
+#include <log.h>
+#include <linux/bitops.h>
+#include <linux/delay.h>
 
 #include <command.h>
 #include <dm.h>
@@ -50,6 +55,8 @@ struct ahci_uc_priv *probe_ent = NULL;
 #define WAIT_MS_FLUSH  5000
 #define WAIT_MS_LINKUP 200
 
+#define AHCI_CAP_S64A BIT(31)
+
 __weak void __iomem *ahci_port_base(void __iomem *base, u32 port)
 {
        return base + 0x100 + (port * 0x80);
@@ -503,9 +510,15 @@ static int ahci_fill_sg(struct ahci_uc_priv *uc_priv, u8 port,
        }
 
        for (i = 0; i < sg_count; i++) {
-               ahci_sg->addr =
-                   cpu_to_le32((unsigned long) buf + i * MAX_DATA_BYTE_COUNT);
-               ahci_sg->addr_hi = 0;
+               /* We assume virt=phys */
+               phys_addr_t pa = (unsigned long)buf + i * MAX_DATA_BYTE_COUNT;
+
+               ahci_sg->addr = cpu_to_le32(lower_32_bits(pa));
+               ahci_sg->addr_hi = cpu_to_le32(upper_32_bits(pa));
+               if (ahci_sg->addr_hi && !(uc_priv->cap & AHCI_CAP_S64A)) {
+                       printf("Error: DMA address too high\n");
+                       return -1;
+               }
                ahci_sg->flags_size = cpu_to_le32(0x3fffff &
                                          (buf_len < MAX_DATA_BYTE_COUNT
                                           ? (buf_len - 1)
@@ -548,6 +561,7 @@ static int ahci_port_start(struct ahci_uc_priv *uc_priv, u8 port)
 {
        struct ahci_ioports *pp = &(uc_priv->port[port]);
        void __iomem *port_mmio = pp->port_mmio;
+       u64 dma_addr;
        u32 port_status;
        void __iomem *mem;
 
@@ -593,10 +607,12 @@ static int ahci_port_start(struct ahci_uc_priv *uc_priv, u8 port)
        pp->cmd_tbl_sg =
                        (struct ahci_sg *)(uintptr_t)virt_to_phys((void *)mem);
 
-       writel_with_flush((unsigned long)pp->cmd_slot,
-                         port_mmio + PORT_LST_ADDR);
-
-       writel_with_flush(pp->rx_fis, port_mmio + PORT_FIS_ADDR);
+       dma_addr = (ulong)pp->cmd_slot;
+       writel_with_flush(dma_addr, port_mmio + PORT_LST_ADDR);
+       writel_with_flush(dma_addr >> 32, port_mmio + PORT_LST_ADDR_HI);
+       dma_addr = (ulong)pp->rx_fis;
+       writel_with_flush(dma_addr, port_mmio + PORT_FIS_ADDR);
+       writel_with_flush(dma_addr >> 32, port_mmio + PORT_FIS_ADDR_HI);
 
 #ifdef CONFIG_SUNXI_AHCI
        sunxi_dma_init(port_mmio);
@@ -1167,6 +1183,14 @@ int ahci_probe_scsi(struct udevice *ahci_dev, ulong base)
        if (ret)
                return ret;
 
+       /*
+        * scsi_scan_dev() scans devices up-to the number of max_id.
+        * Update max_id if the number of detected ports exceeds max_id.
+        * This allows SCSI to scan all detected ports.
+        */
+       uc_plat->max_id = max_t(unsigned long, uc_priv->n_ports,
+                               uc_plat->max_id);
+
        return 0;
 }