Remove obsolete #include <linux/config.h>
[pandora-kernel.git] / arch / powerpc / platforms / pseries / iommu.c
index ed102f3..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;
 
@@ -281,30 +311,22 @@ static void iommu_table_setparms(struct pci_controller *phb,
  * iommu_table_setparms_lpar
  *
  * Function: On pSeries LPAR systems, return TCE table info, given a pci bus.
- *
- * ToDo: properly interpret the ibm,dma-window property.  The definition is:
- *     logical-bus-number      (1 word)
- *     phys-address            (#address-cells words)
- *     size                    (#cell-size words)
- *
- * Currently we hard code these sizes (more or less).
  */
 static void iommu_table_setparms_lpar(struct pci_controller *phb,
                                      struct device_node *dn,
                                      struct iommu_table *tbl,
-                                     unsigned int *dma_window)
+                                     unsigned char *dma_window)
 {
+       unsigned long offset, size;
+
        tbl->it_busno  = PCI_DN(dn)->bussubno;
+       of_parse_dma_window(dn, dma_window, &tbl->it_index, &offset, &size);
 
-       /* TODO: Parse field size properties properly. */
-       tbl->it_size   = (((unsigned long)dma_window[4] << 32) |
-                          (unsigned long)dma_window[5]) >> PAGE_SHIFT;
-       tbl->it_offset = (((unsigned long)dma_window[2] << 32) |
-                          (unsigned long)dma_window[3]) >> PAGE_SHIFT;
        tbl->it_base   = 0;
-       tbl->it_index  = dma_window[0];
        tbl->it_blocksize  = 16;
        tbl->it_type = TCE_PCI;
+       tbl->it_offset = offset >> PAGE_SHIFT;
+       tbl->it_size = size >> PAGE_SHIFT;
 }
 
 static void iommu_bus_setup_pSeries(struct pci_bus *bus)
@@ -339,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);
 
@@ -376,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;
@@ -396,7 +415,7 @@ static void iommu_bus_setup_pSeriesLP(struct pci_bus *bus)
        struct iommu_table *tbl;
        struct device_node *dn, *pdn;
        struct pci_dn *ppci;
-       unsigned int *dma_window = NULL;
+       unsigned char *dma_window = NULL;
 
        DBG("iommu_bus_setup_pSeriesLP, bus %p, bus->self %p\n", bus, bus->self);
 
@@ -404,7 +423,7 @@ static void iommu_bus_setup_pSeriesLP(struct pci_bus *bus)
 
        /* Find nearest ibm,dma-window, walking up the device tree */
        for (pdn = dn; pdn != NULL; pdn = pdn->parent) {
-               dma_window = (unsigned int *)get_property(pdn, "ibm,dma-window", NULL);
+               dma_window = get_property(pdn, "ibm,dma-window", NULL);
                if (dma_window != NULL)
                        break;
        }
@@ -422,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)
@@ -450,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;
        }
@@ -498,7 +519,7 @@ static void iommu_dev_setup_pSeriesLP(struct pci_dev *dev)
 {
        struct device_node *pdn, *dn;
        struct iommu_table *tbl;
-       int *dma_window = NULL;
+       unsigned char *dma_window = NULL;
        struct pci_dn *pci;
 
        DBG("iommu_dev_setup_pSeriesLP, dev %p (%s)\n", dev, pci_name(dev));
@@ -513,8 +534,7 @@ static void iommu_dev_setup_pSeriesLP(struct pci_dev *dev)
 
        for (pdn = dn; pdn && PCI_DN(pdn) && !PCI_DN(pdn)->iommu_table;
             pdn = pdn->parent) {
-               dma_window = (unsigned int *)
-                       get_property(pdn, "ibm,dma-window", NULL);
+               dma_window = get_property(pdn, "ibm,dma-window", NULL);
                if (dma_window)
                        break;
        }
@@ -535,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)
@@ -570,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;
        }