Remove obsolete #include <linux/config.h>
[pandora-kernel.git] / arch / powerpc / platforms / pseries / iommu.c
index 44a507e..d67af2c 100644 (file)
@@ -24,7 +24,6 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  */
 
-#include <linux/config.h>
 #include <linux/init.h>
 #include <linux/types.h>
 #include <linux/slab.h>
@@ -92,6 +91,15 @@ static void tce_free_pSeries(struct iommu_table *tbl, long index, long npages)
                *(tcep++) = 0;
 }
 
+static unsigned long tce_get_pseries(struct iommu_table *tbl, long index)
+{
+       u64 *tcep;
+
+       index <<= TCE_PAGE_FACTOR;
+       tcep = ((u64 *)tbl->it_base) + index;
+
+       return *tcep;
+}
 
 static void tce_build_pSeriesLP(struct iommu_table *tbl, long tcenum,
                                long npages, unsigned long uaddr,
@@ -235,6 +243,25 @@ static void tce_freemulti_pSeriesLP(struct iommu_table *tbl, long tcenum, long n
        }
 }
 
+static unsigned long tce_get_pSeriesLP(struct iommu_table *tbl, long tcenum)
+{
+       u64 rc;
+       unsigned long tce_ret;
+
+       tcenum <<= TCE_PAGE_FACTOR;
+       rc = plpar_tce_get((u64)tbl->it_index, (u64)tcenum << 12, &tce_ret);
+
+       if (rc && printk_ratelimit()) {
+               printk("tce_get_pSeriesLP: plpar_tce_get failed. rc=%ld\n",
+                       rc);
+               printk("\tindex   = 0x%lx\n", (u64)tbl->it_index);
+               printk("\ttcenum  = 0x%lx\n", (u64)tcenum);
+               show_stack(current, (unsigned long *)__get_SP());
+       }
+
+       return tce_ret;
+}
+
 static void iommu_table_setparms(struct pci_controller *phb,
                                 struct device_node *dn,
                                 struct iommu_table *tbl)
@@ -254,7 +281,10 @@ static void iommu_table_setparms(struct pci_controller *phb,
        }
 
        tbl->it_base = (unsigned long)__va(*basep);
+
+#ifndef CONFIG_CRASH_DUMP
        memset((void *)tbl->it_base, 0, *sizep);
+#endif
 
        tbl->it_busno = phb->bus->number;
 
@@ -331,13 +361,9 @@ static void iommu_bus_setup_pSeries(struct pci_bus *bus)
        if (isa_dn_orig)
                of_node_put(isa_dn_orig);
 
-       /* Count number of direct PCI children of the PHB.
-        * All PCI device nodes have class-code property, so it's
-        * an easy way to find them.
-        */
+       /* Count number of direct PCI children of the PHB. */
        for (children = 0, tmp = dn->child; tmp; tmp = tmp->sibling)
-               if (get_property(tmp, "class-code", NULL))
-                       children++;
+               children++;
 
        DBG("Children: %d\n", children);
 
@@ -368,10 +394,11 @@ static void iommu_bus_setup_pSeries(struct pci_bus *bus)
        pci->phb->dma_window_size = 0x8000000ul;
        pci->phb->dma_window_base_cur = 0x8000000ul;
 
-       tbl = kmalloc(sizeof(struct iommu_table), GFP_KERNEL);
+       tbl = kmalloc_node(sizeof(struct iommu_table), GFP_KERNEL,
+                          pci->phb->node);
 
        iommu_table_setparms(pci->phb, dn, tbl);
-       pci->iommu_table = iommu_init_table(tbl);
+       pci->iommu_table = iommu_init_table(tbl, pci->phb->node);
 
        /* Divide the rest (1.75GB) among the children */
        pci->phb->dma_window_size = 0x80000000ul;
@@ -414,12 +441,12 @@ static void iommu_bus_setup_pSeriesLP(struct pci_bus *bus)
 
                ppci->bussubno = bus->number;
 
-               tbl = (struct iommu_table *)kmalloc(sizeof(struct iommu_table),
-                                                   GFP_KERNEL);
+               tbl = kmalloc_node(sizeof(struct iommu_table), GFP_KERNEL,
+                                  ppci->phb->node);
 
                iommu_table_setparms_lpar(ppci->phb, pdn, tbl, dma_window);
 
-               ppci->iommu_table = iommu_init_table(tbl);
+               ppci->iommu_table = iommu_init_table(tbl, ppci->phb->node);
        }
 
        if (pdn != dn)
@@ -442,9 +469,11 @@ static void iommu_dev_setup_pSeries(struct pci_dev *dev)
         */
        if (!dev->bus->self) {
                DBG(" --> first child, no bridge. Allocating iommu table.\n");
-               tbl = kmalloc(sizeof(struct iommu_table), GFP_KERNEL);
+               tbl = kmalloc_node(sizeof(struct iommu_table), GFP_KERNEL,
+                                  PCI_DN(dn)->phb->node);
                iommu_table_setparms(PCI_DN(dn)->phb, dn, tbl);
-               PCI_DN(mydn)->iommu_table = iommu_init_table(tbl);
+               PCI_DN(dn)->iommu_table = iommu_init_table(tbl,
+                                               PCI_DN(dn)->phb->node);
 
                return;
        }
@@ -526,12 +555,12 @@ static void iommu_dev_setup_pSeriesLP(struct pci_dev *dev)
                /* iommu_table_setparms_lpar needs bussubno. */
                pci->bussubno = pci->phb->bus->number;
 
-               tbl = (struct iommu_table *)kmalloc(sizeof(struct iommu_table),
-                                                   GFP_KERNEL);
+               tbl = kmalloc_node(sizeof(struct iommu_table), GFP_KERNEL,
+                                  pci->phb->node);
 
                iommu_table_setparms_lpar(pci->phb, pdn, tbl, dma_window);
 
-               pci->iommu_table = iommu_init_table(tbl);
+               pci->iommu_table = iommu_init_table(tbl, pci->phb->node);
        }
 
        if (pdn != dn)
@@ -561,11 +590,13 @@ void iommu_init_early_pSeries(void)
                        ppc_md.tce_build = tce_build_pSeriesLP;
                        ppc_md.tce_free  = tce_free_pSeriesLP;
                }
+               ppc_md.tce_get   = tce_get_pSeriesLP;
                ppc_md.iommu_bus_setup = iommu_bus_setup_pSeriesLP;
                ppc_md.iommu_dev_setup = iommu_dev_setup_pSeriesLP;
        } else {
                ppc_md.tce_build = tce_build_pSeries;
                ppc_md.tce_free  = tce_free_pSeries;
+               ppc_md.tce_get   = tce_get_pseries;
                ppc_md.iommu_bus_setup = iommu_bus_setup_pSeries;
                ppc_md.iommu_dev_setup = iommu_dev_setup_pSeries;
        }