]> err.no Git - linux-2.6/blobdiff - arch/powerpc/platforms/pseries/iommu.c
[POWERPC] pseries/phyp dump: Reserve a variable amount of space at boot
[linux-2.6] / arch / powerpc / platforms / pseries / iommu.c
index e6653a868b91c6177c79d60a97a542bd6e79a7fe..a65c763082010c8c1ff7d6fd0a8b458974fef085 100644 (file)
@@ -242,6 +242,7 @@ static unsigned long tce_get_pSeriesLP(struct iommu_table *tbl, long tcenum)
        return tce_ret;
 }
 
+#ifdef CONFIG_PCI
 static void iommu_table_setparms(struct pci_controller *phb,
                                 struct device_node *dn,
                                 struct iommu_table *tbl)
@@ -250,10 +251,10 @@ static void iommu_table_setparms(struct pci_controller *phb,
        const unsigned long *basep;
        const u32 *sizep;
 
-       node = (struct device_node *)phb->arch_data;
+       node = phb->dn;
 
-       basep = get_property(node, "linux,tce-base", NULL);
-       sizep = get_property(node, "linux,tce-size", NULL);
+       basep = of_get_property(node, "linux,tce-base", NULL);
+       sizep = of_get_property(node, "linux,tce-size", NULL);
        if (basep == NULL || sizep == NULL) {
                printk(KERN_ERR "PCI_DMA: iommu_table_setparms: %s has "
                                "missing tce entries !\n", dn->full_name);
@@ -295,11 +296,12 @@ static void iommu_table_setparms(struct pci_controller *phb,
 static void iommu_table_setparms_lpar(struct pci_controller *phb,
                                      struct device_node *dn,
                                      struct iommu_table *tbl,
-                                     const void *dma_window)
+                                     const void *dma_window,
+                                     int bussubno)
 {
        unsigned long offset, size;
 
-       tbl->it_busno  = PCI_DN(dn)->bussubno;
+       tbl->it_busno  = bussubno;
        of_parse_dma_window(dn, dma_window, &tbl->it_index, &offset, &size);
 
        tbl->it_base   = 0;
@@ -403,7 +405,7 @@ static void pci_dma_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 = get_property(pdn, "ibm,dma-window", NULL);
+               dma_window = of_get_property(pdn, "ibm,dma-window", NULL);
                if (dma_window != NULL)
                        break;
        }
@@ -419,17 +421,10 @@ static void pci_dma_bus_setup_pSeriesLP(struct pci_bus *bus)
            pdn->full_name, ppci->iommu_table);
 
        if (!ppci->iommu_table) {
-               /* Bussubno hasn't been copied yet.
-                * Do it now because iommu_table_setparms_lpar needs it.
-                */
-
-               ppci->bussubno = bus->number;
-
                tbl = kmalloc_node(sizeof(struct iommu_table), GFP_KERNEL,
                                   ppci->phb->node);
-
-               iommu_table_setparms_lpar(ppci->phb, pdn, tbl, dma_window);
-
+               iommu_table_setparms_lpar(ppci->phb, pdn, tbl, dma_window,
+                       bus->number);
                ppci->iommu_table = iommu_init_table(tbl, ppci->phb->node);
                DBG("  created table: %p\n", ppci->iommu_table);
        }
@@ -478,29 +473,6 @@ static void pci_dma_dev_setup_pSeries(struct pci_dev *dev)
                       pci_name(dev));
 }
 
-static int iommu_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *node)
-{
-       int err = NOTIFY_OK;
-       struct device_node *np = node;
-       struct pci_dn *pci = PCI_DN(np);
-
-       switch (action) {
-       case PSERIES_RECONFIG_REMOVE:
-               if (pci && pci->iommu_table &&
-                   get_property(np, "ibm,dma-window", NULL))
-                       iommu_free_table(np);
-               break;
-       default:
-               err = NOTIFY_DONE;
-               break;
-       }
-       return err;
-}
-
-static struct notifier_block iommu_reconfig_nb = {
-       .notifier_call = iommu_reconfig_notifier,
-};
-
 static void pci_dma_dev_setup_pSeriesLP(struct pci_dev *dev)
 {
        struct device_node *pdn, *dn;
@@ -521,11 +493,17 @@ static void pci_dma_dev_setup_pSeriesLP(struct pci_dev *dev)
 
        for (pdn = dn; pdn && PCI_DN(pdn) && !PCI_DN(pdn)->iommu_table;
             pdn = pdn->parent) {
-               dma_window = get_property(pdn, "ibm,dma-window", NULL);
+               dma_window = of_get_property(pdn, "ibm,dma-window", NULL);
                if (dma_window)
                        break;
        }
 
+       if (!pdn || !PCI_DN(pdn)) {
+               printk(KERN_WARNING "pci_dma_dev_setup_pSeriesLP: "
+                      "no DMA window found for pci dev=%s dn=%s\n",
+                                pci_name(dev), dn? dn->full_name : "<null>");
+               return;
+       }
        DBG("  parent is %s\n", pdn->full_name);
 
        /* Check for parent == NULL so we don't try to setup the empty EADS
@@ -536,33 +514,59 @@ static void pci_dma_dev_setup_pSeriesLP(struct pci_dev *dev)
                dev->dev.archdata.dma_data = PCI_DN(pdn)->iommu_table;
                return;
        }
-       DBG("  found DMA window, table: %p\n", pci->iommu_table);
 
        pci = PCI_DN(pdn);
        if (!pci->iommu_table) {
-               /* iommu_table_setparms_lpar needs bussubno. */
-               pci->bussubno = pci->phb->bus->number;
-
                tbl = kmalloc_node(sizeof(struct iommu_table), GFP_KERNEL,
                                   pci->phb->node);
-
-               iommu_table_setparms_lpar(pci->phb, pdn, tbl, dma_window);
-
+               iommu_table_setparms_lpar(pci->phb, pdn, tbl, dma_window,
+                       pci->phb->bus->number);
                pci->iommu_table = iommu_init_table(tbl, pci->phb->node);
                DBG("  created table: %p\n", pci->iommu_table);
+       } else {
+               DBG("  found DMA window, table: %p\n", pci->iommu_table);
        }
 
        dev->dev.archdata.dma_data = pci->iommu_table;
 }
+#else  /* CONFIG_PCI */
+#define pci_dma_bus_setup_pSeries      NULL
+#define pci_dma_dev_setup_pSeries      NULL
+#define pci_dma_bus_setup_pSeriesLP    NULL
+#define pci_dma_dev_setup_pSeriesLP    NULL
+#endif /* !CONFIG_PCI */
+
+static int iommu_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *node)
+{
+       int err = NOTIFY_OK;
+       struct device_node *np = node;
+       struct pci_dn *pci = PCI_DN(np);
+
+       switch (action) {
+       case PSERIES_RECONFIG_REMOVE:
+               if (pci && pci->iommu_table &&
+                   of_get_property(np, "ibm,dma-window", NULL))
+                       iommu_free_table(pci->iommu_table, np->full_name);
+               break;
+       default:
+               err = NOTIFY_DONE;
+               break;
+       }
+       return err;
+}
+
+static struct notifier_block iommu_reconfig_nb = {
+       .notifier_call = iommu_reconfig_notifier,
+};
 
 /* These are called very early. */
 void iommu_init_early_pSeries(void)
 {
-       if (of_chosen && get_property(of_chosen, "linux,iommu-off", NULL)) {
+       if (of_chosen && of_get_property(of_chosen, "linux,iommu-off", NULL)) {
                /* Direct I/O, IOMMU off */
                ppc_md.pci_dma_dev_setup = NULL;
                ppc_md.pci_dma_bus_setup = NULL;
-               pci_dma_ops = &dma_direct_ops;
+               set_pci_dma_ops(&dma_direct_ops);
                return;
        }
 
@@ -588,6 +592,6 @@ void iommu_init_early_pSeries(void)
 
        pSeries_reconfig_notifier_register(&iommu_reconfig_nb);
 
-       pci_dma_ops = &dma_iommu_ops;
+       set_pci_dma_ops(&dma_iommu_ops);
 }