]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/arm/plat-iop/pci.c
iop: unconditionally initialize the ATU on platforms known to be 'hosts'
[linux-2.6-omap-h63xx.git] / arch / arm / plat-iop / pci.c
index b5f6ec35aafb59e2b9fd1597e615e7000a157769..d9bc15a69e5ddc103337ad18f79d7b0dc0c7499f 100644 (file)
 #include <linux/ioport.h>
 #include <asm/io.h>
 #include <asm/irq.h>
+#include <asm/signal.h>
 #include <asm/system.h>
 #include <asm/hardware.h>
 #include <asm/mach/pci.h>
 #include <asm/hardware/iop3xx.h>
+#include <asm/mach-types.h>
 
 // #define DEBUG
 
@@ -55,7 +57,7 @@ static u32 iop3xx_cfg_address(struct pci_bus *bus, int devfn, int where)
  * This routine checks the status of the last configuration cycle.  If an error
  * was detected it returns a 1, else it returns a 0.  The errors being checked
  * are parity, master abort, target abort (master and target).  These types of
- * errors occure during a config cycle where there is no device, like during
+ * errors occur during a config cycle where there is no device, like during
  * the discovery stage.
  */
 static int iop3xx_pci_status(void)
@@ -85,10 +87,10 @@ static int iop3xx_pci_status(void)
 
 /*
  * Simply write the address register and read the configuration
- * data.  Note that the 4 nop's ensure that we are able to handle
+ * data.  Note that the 4 nops ensure that we are able to handle
  * a delayed abort (in theory.)
  */
-static inline u32 iop3xx_read(unsigned long addr)
+static u32 iop3xx_read(unsigned long addr)
 {
        u32 val;
 
@@ -208,8 +210,11 @@ int iop3xx_pci_setup(int nr, struct pci_sys_data *sys)
        res[1].flags = IORESOURCE_MEM;
        request_resource(&iomem_resource, &res[1]);
 
-       sys->mem_offset = IOP3XX_PCI_LOWER_MEM_PA - IOP3XX_PCI_LOWER_MEM_BA;
-       sys->io_offset  = IOP3XX_PCI_LOWER_IO_PA - IOP3XX_PCI_LOWER_IO_BA;
+       /*
+        * Use whatever translation is already setup.
+        */
+       sys->mem_offset = IOP3XX_PCI_LOWER_MEM_PA - *IOP3XX_OMWTVR0;
+       sys->io_offset  = IOP3XX_PCI_LOWER_IO_PA - *IOP3XX_OIOWTVR;
 
        sys->resource[0] = &res[0];
        sys->resource[1] = &res[1];
@@ -223,25 +228,188 @@ struct pci_bus *iop3xx_pci_scan_bus(int nr, struct pci_sys_data *sys)
        return pci_scan_bus(sys->busnr, &iop3xx_ops, sys);
 }
 
-void iop3xx_pci_preinit(void)
+void __init iop3xx_atu_setup(void)
+{
+       /* BAR 0 ( Disabled ) */
+       *IOP3XX_IAUBAR0 = 0x0;
+       *IOP3XX_IABAR0  = 0x0;
+       *IOP3XX_IATVR0  = 0x0;
+       *IOP3XX_IALR0   = 0x0;
+
+       /* BAR 1 ( Disabled ) */
+       *IOP3XX_IAUBAR1 = 0x0;
+       *IOP3XX_IABAR1  = 0x0;
+       *IOP3XX_IALR1   = 0x0;
+
+       /* BAR 2 (1:1 mapping with Physical RAM) */
+       /* Set limit and enable */
+       *IOP3XX_IALR2 = ~((u32)IOP3XX_MAX_RAM_SIZE - 1) & ~0x1;
+       *IOP3XX_IAUBAR2 = 0x0;
+
+       /* Align the inbound bar with the base of memory */
+       *IOP3XX_IABAR2 = PHYS_OFFSET |
+                              PCI_BASE_ADDRESS_MEM_TYPE_64 |
+                              PCI_BASE_ADDRESS_MEM_PREFETCH;
+
+       *IOP3XX_IATVR2 = PHYS_OFFSET;
+
+       /* Outbound window 0 */
+       *IOP3XX_OMWTVR0 = IOP3XX_PCI_LOWER_MEM_BA;
+       *IOP3XX_OUMWTVR0 = 0;
+
+       /* Outbound window 1 */
+       *IOP3XX_OMWTVR1 = IOP3XX_PCI_LOWER_MEM_BA + IOP3XX_PCI_MEM_WINDOW_SIZE;
+       *IOP3XX_OUMWTVR1 = 0;
+
+       /* BAR 3 ( Disabled ) */
+       *IOP3XX_IAUBAR3 = 0x0;
+       *IOP3XX_IABAR3  = 0x0;
+       *IOP3XX_IATVR3  = 0x0;
+       *IOP3XX_IALR3   = 0x0;
+
+       /* Setup the I/O Bar
+        */
+       *IOP3XX_OIOWTVR = IOP3XX_PCI_LOWER_IO_BA;
+
+       /* Enable inbound and outbound cycles
+        */
+       *IOP3XX_ATUCMD |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
+                              PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
+       *IOP3XX_ATUCR |= IOP3XX_ATUCR_OUT_EN;
+}
+
+void __init iop3xx_atu_disable(void)
 {
-       DBG("PCI:  Intel 803xx PCI init code.\n");
+       *IOP3XX_ATUCMD = 0;
+       *IOP3XX_ATUCR = 0;
+
+       /* wait for cycles to quiesce */
+       while (*IOP3XX_PCSR & (IOP3XX_PCSR_OUT_Q_BUSY |
+                                    IOP3XX_PCSR_IN_Q_BUSY))
+               cpu_relax();
+
+       /* BAR 0 ( Disabled ) */
+       *IOP3XX_IAUBAR0 = 0x0;
+       *IOP3XX_IABAR0  = 0x0;
+       *IOP3XX_IATVR0  = 0x0;
+       *IOP3XX_IALR0   = 0x0;
+
+       /* BAR 1 ( Disabled ) */
+       *IOP3XX_IAUBAR1 = 0x0;
+       *IOP3XX_IABAR1  = 0x0;
+       *IOP3XX_IALR1   = 0x0;
+
+       /* BAR 2 ( Disabled ) */
+       *IOP3XX_IAUBAR2 = 0x0;
+       *IOP3XX_IABAR2  = 0x0;
+       *IOP3XX_IATVR2  = 0x0;
+       *IOP3XX_IALR2   = 0x0;
+
+       /* BAR 3 ( Disabled ) */
+       *IOP3XX_IAUBAR3 = 0x0;
+       *IOP3XX_IABAR3  = 0x0;
+       *IOP3XX_IATVR3  = 0x0;
+       *IOP3XX_IALR3   = 0x0;
+
+       /* Clear the outbound windows */
+       *IOP3XX_OIOWTVR  = 0;
+
+       /* Outbound window 0 */
+       *IOP3XX_OMWTVR0 = 0;
+       *IOP3XX_OUMWTVR0 = 0;
+
+       /* Outbound window 1 */
+       *IOP3XX_OMWTVR1 = 0;
+       *IOP3XX_OUMWTVR1 = 0;
+}
+
+/* Flag to determine whether the ATU is initialized and the PCI bus scanned */
+int init_atu;
+
+int iop3xx_get_init_atu(void) {
+       /* check if default has been overridden */
+       if (init_atu != IOP3XX_INIT_ATU_DEFAULT)
+               return init_atu;
+       else
+               return IOP3XX_INIT_ATU_DISABLE;
+}
+
+static void __init iop3xx_atu_debug(void)
+{
+       DBG("PCI: Intel IOP3xx PCI init.\n");
+       DBG("PCI: Outbound memory window 0: PCI 0x%08x%08x\n",
+               *IOP3XX_OUMWTVR0, *IOP3XX_OMWTVR0);
+       DBG("PCI: Outbound memory window 1: PCI 0x%08x%08x\n",
+               *IOP3XX_OUMWTVR1, *IOP3XX_OMWTVR1);
+       DBG("PCI: Outbound IO window: PCI 0x%08x\n",
+               *IOP3XX_OIOWTVR);
+
+       DBG("PCI: Inbound memory window 0: PCI 0x%08x%08x 0x%08x -> 0x%08x\n",
+               *IOP3XX_IAUBAR0, *IOP3XX_IABAR0, *IOP3XX_IALR0, *IOP3XX_IATVR0);
+       DBG("PCI: Inbound memory window 1: PCI 0x%08x%08x 0x%08x\n",
+               *IOP3XX_IAUBAR1, *IOP3XX_IABAR1, *IOP3XX_IALR1);
+       DBG("PCI: Inbound memory window 2: PCI 0x%08x%08x 0x%08x -> 0x%08x\n",
+               *IOP3XX_IAUBAR2, *IOP3XX_IABAR2, *IOP3XX_IALR2, *IOP3XX_IATVR2);
+       DBG("PCI: Inbound memory window 3: PCI 0x%08x%08x 0x%08x -> 0x%08x\n",
+               *IOP3XX_IAUBAR3, *IOP3XX_IABAR3, *IOP3XX_IALR3, *IOP3XX_IATVR3);
+
+       DBG("PCI: Expansion ROM window: PCI 0x%08x%08x 0x%08x -> 0x%08x\n",
+               0, *IOP3XX_ERBAR, *IOP3XX_ERLR, *IOP3XX_ERTVR);
+
        DBG("ATU: IOP3XX_ATUCMD=0x%04x\n", *IOP3XX_ATUCMD);
-       DBG("ATU: IOP3XX_OMWTVR0=0x%04x, IOP3XX_OIOWTVR=0x%04x\n",
-                       *IOP3XX_OMWTVR0,
-                       *IOP3XX_OIOWTVR);
        DBG("ATU: IOP3XX_ATUCR=0x%08x\n", *IOP3XX_ATUCR);
-       DBG("ATU: IOP3XX_IABAR0=0x%08x IOP3XX_IALR0=0x%08x IOP3XX_IATVR0=%08x\n",
-                       *IOP3XX_IABAR0, *IOP3XX_IALR0, *IOP3XX_IATVR0);
-       DBG("ATU: IOP3XX_OMWTVR0=0x%08x\n", *IOP3XX_OMWTVR0);
-       DBG("ATU: IOP3XX_IABAR1=0x%08x IOP3XX_IALR1=0x%08x\n",
-                       *IOP3XX_IABAR1, *IOP3XX_IALR1);
-       DBG("ATU: IOP3XX_ERBAR=0x%08x IOP3XX_ERLR=0x%08x IOP3XX_ERTVR=%08x\n",
-                       *IOP3XX_ERBAR, *IOP3XX_ERLR, *IOP3XX_ERTVR);
-       DBG("ATU: IOP3XX_IABAR2=0x%08x IOP3XX_IALR2=0x%08x IOP3XX_IATVR2=%08x\n",
-                       *IOP3XX_IABAR2, *IOP3XX_IALR2, *IOP3XX_IATVR2);
-       DBG("ATU: IOP3XX_IABAR3=0x%08x IOP3XX_IALR3=0x%08x IOP3XX_IATVR3=%08x\n",
-                       *IOP3XX_IABAR3, *IOP3XX_IALR3, *IOP3XX_IATVR3);
 
        hook_fault_code(16+6, iop3xx_pci_abort, SIGBUS, "imprecise external abort");
 }
+
+/* for platforms that might be host-bus-adapters */
+void __init iop3xx_pci_preinit_cond(void)
+{
+       if (iop3xx_get_init_atu() == IOP3XX_INIT_ATU_ENABLE) {
+               iop3xx_atu_disable();
+               iop3xx_atu_setup();
+               iop3xx_atu_debug();
+       }
+}
+
+void __init iop3xx_pci_preinit(void)
+{
+       iop3xx_atu_disable();
+       iop3xx_atu_setup();
+       iop3xx_atu_debug();
+}
+
+/* allow init_atu to be user overridden */
+static int __init iop3xx_init_atu_setup(char *str)
+{
+       init_atu = IOP3XX_INIT_ATU_DEFAULT;
+       if (str) {
+               while (*str != '\0') {
+                       switch (*str) {
+                       case 'y':
+                       case 'Y':
+                               init_atu = IOP3XX_INIT_ATU_ENABLE;
+                               break;
+                       case 'n':
+                       case 'N':
+                               init_atu = IOP3XX_INIT_ATU_DISABLE;
+                               break;
+                       case ',':
+                       case '=':
+                               break;
+                       default:
+                               printk(KERN_DEBUG "\"%s\" malformed at "
+                                           "character: \'%c\'",
+                                           __func__,
+                                           *str);
+                               *(str + 1) = '\0';
+                       }
+                       str++;
+               }
+       }
+
+       return 1;
+}
+
+__setup("iop3xx_init_atu", iop3xx_init_atu_setup);
+