Merge tag 'dt-for-3.6' of git://sources.calxeda.com/kernel/linux
[linux-3.10.git] / arch / powerpc / platforms / pseries / iommu.c
index 019009b..bca220f 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/slab.h>
 #include <linux/mm.h>
 #include <linux/spinlock.h>
+#include <linux/sched.h>       /* for show_stack */
 #include <linux/string.h>
 #include <linux/pci.h>
 #include <linux/dma-mapping.h>
 #include "plpar_wrappers.h"
 
 
+static void tce_invalidate_pSeries_sw(struct iommu_table *tbl,
+                                     u64 *startp, u64 *endp)
+{
+       u64 __iomem *invalidate = (u64 __iomem *)tbl->it_index;
+       unsigned long start, end, inc;
+
+       start = __pa(startp);
+       end = __pa(endp);
+       inc = L1_CACHE_BYTES; /* invalidate a cacheline of TCEs at a time */
+
+       /* If this is non-zero, change the format.  We shift the
+        * address and or in the magic from the device tree. */
+       if (tbl->it_busno) {
+               start <<= 12;
+               end <<= 12;
+               inc <<= 12;
+               start |= tbl->it_busno;
+               end |= tbl->it_busno;
+       }
+
+       end |= inc - 1; /* round up end to be different than start */
+
+       mb(); /* Make sure TCEs in memory are written */
+       while (start <= end) {
+               out_be64(invalidate, start);
+               start += inc;
+       }
+}
+
 static int tce_build_pSeries(struct iommu_table *tbl, long index,
                              long npages, unsigned long uaddr,
                              enum dma_data_direction direction,
                              struct dma_attrs *attrs)
 {
        u64 proto_tce;
-       u64 *tcep;
+       u64 *tcep, *tces;
        u64 rpn;
 
        proto_tce = TCE_PCI_READ; // Read allowed
@@ -65,7 +95,7 @@ static int tce_build_pSeries(struct iommu_table *tbl, long index,
        if (direction != DMA_TO_DEVICE)
                proto_tce |= TCE_PCI_WRITE;
 
-       tcep = ((u64 *)tbl->it_base) + index;
+       tces = tcep = ((u64 *)tbl->it_base) + index;
 
        while (npages--) {
                /* can't move this out since we might cross MEMBLOCK boundary */
@@ -75,18 +105,24 @@ static int tce_build_pSeries(struct iommu_table *tbl, long index,
                uaddr += TCE_PAGE_SIZE;
                tcep++;
        }
+
+       if (tbl->it_type & TCE_PCI_SWINV_CREATE)
+               tce_invalidate_pSeries_sw(tbl, tces, tcep - 1);
        return 0;
 }
 
 
 static void tce_free_pSeries(struct iommu_table *tbl, long index, long npages)
 {
-       u64 *tcep;
+       u64 *tcep, *tces;
 
-       tcep = ((u64 *)tbl->it_base) + index;
+       tces = tcep = ((u64 *)tbl->it_base) + index;
 
        while (npages--)
                *(tcep++) = 0;
+
+       if (tbl->it_type & TCE_PCI_SWINV_FREE)
+               tce_invalidate_pSeries_sw(tbl, tces, tcep - 1);
 }
 
 static unsigned long tce_get_pseries(struct iommu_table *tbl, long index)
@@ -156,12 +192,15 @@ static int tce_buildmulti_pSeriesLP(struct iommu_table *tbl, long tcenum,
        long l, limit;
        long tcenum_start = tcenum, npages_start = npages;
        int ret = 0;
+       unsigned long flags;
 
        if (npages == 1) {
                return tce_build_pSeriesLP(tbl, tcenum, npages, uaddr,
                                           direction, attrs);
        }
 
+       local_irq_save(flags);  /* to protect tcep and the page behind it */
+
        tcep = __get_cpu_var(tce_page);
 
        /* This is safe to do since interrupts are off when we're called
@@ -171,6 +210,7 @@ static int tce_buildmulti_pSeriesLP(struct iommu_table *tbl, long tcenum,
                tcep = (u64 *)__get_free_page(GFP_ATOMIC);
                /* If allocation fails, fall back to the loop implementation */
                if (!tcep) {
+                       local_irq_restore(flags);
                        return tce_build_pSeriesLP(tbl, tcenum, npages, uaddr,
                                            direction, attrs);
                }
@@ -204,6 +244,8 @@ static int tce_buildmulti_pSeriesLP(struct iommu_table *tbl, long tcenum,
                tcenum += limit;
        } while (npages > 0 && !rc);
 
+       local_irq_restore(flags);
+
        if (unlikely(rc == H_NOT_ENOUGH_RESOURCES)) {
                ret = (int)rc;
                tce_freemulti_pSeriesLP(tbl, tcenum_start,
@@ -424,7 +466,7 @@ static void iommu_table_setparms(struct pci_controller *phb,
                                 struct iommu_table *tbl)
 {
        struct device_node *node;
-       const unsigned long *basep;
+       const unsigned long *basep, *sw_inval;
        const u32 *sizep;
 
        node = phb->dn;
@@ -461,6 +503,22 @@ static void iommu_table_setparms(struct pci_controller *phb,
        tbl->it_index = 0;
        tbl->it_blocksize = 16;
        tbl->it_type = TCE_PCI;
+
+       sw_inval = of_get_property(node, "linux,tce-sw-invalidate-info", NULL);
+       if (sw_inval) {
+               /*
+                * This property contains information on how to
+                * invalidate the TCE entry.  The first property is
+                * the base MMIO address used to invalidate entries.
+                * The second property tells us the format of the TCE
+                * invalidate (whether it needs to be shifted) and
+                * some magic routing info to add to our invalidate
+                * command.
+                */
+               tbl->it_index = (unsigned long) ioremap(sw_inval[0], 8);
+               tbl->it_busno = sw_inval[1]; /* overload this with magic */
+               tbl->it_type = TCE_PCI_SWINV_CREATE | TCE_PCI_SWINV_FREE;
+       }
 }
 
 /*
@@ -655,19 +713,37 @@ static int __init disable_ddw_setup(char *str)
 
 early_param("disable_ddw", disable_ddw_setup);
 
+static inline void __remove_ddw(struct device_node *np, const u32 *ddw_avail, u64 liobn)
+{
+       int ret;
+
+       ret = rtas_call(ddw_avail[2], 1, 1, NULL, liobn);
+       if (ret)
+               pr_warning("%s: failed to remove DMA window: rtas returned "
+                       "%d to ibm,remove-pe-dma-window(%x) %llx\n",
+                       np->full_name, ret, ddw_avail[2], liobn);
+       else
+               pr_debug("%s: successfully removed DMA window: rtas returned "
+                       "%d to ibm,remove-pe-dma-window(%x) %llx\n",
+                       np->full_name, ret, ddw_avail[2], liobn);
+}
+
 static void remove_ddw(struct device_node *np)
 {
        struct dynamic_dma_window_prop *dwp;
        struct property *win64;
-       const u32 *ddr_avail;
+       const u32 *ddw_avail;
        u64 liobn;
        int len, ret;
 
-       ddr_avail = of_get_property(np, "ibm,ddw-applicable", &len);
+       ddw_avail = of_get_property(np, "ibm,ddw-applicable", &len);
        win64 = of_find_property(np, DIRECT64_PROPNAME, NULL);
-       if (!win64 || !ddr_avail || len < 3 * sizeof(u32))
+       if (!win64)
                return;
 
+       if (!ddw_avail || len < 3 * sizeof(u32) || win64->length < sizeof(*dwp))
+               goto delprop;
+
        dwp = win64->value;
        liobn = (u64)be32_to_cpu(dwp->liobn);
 
@@ -681,28 +757,21 @@ static void remove_ddw(struct device_node *np)
                pr_debug("%s successfully cleared tces in window.\n",
                         np->full_name);
 
-       ret = rtas_call(ddr_avail[2], 1, 1, NULL, liobn);
+       __remove_ddw(np, ddw_avail, liobn);
+
+delprop:
+       ret = prom_remove_property(np, win64);
        if (ret)
-               pr_warning("%s: failed to remove direct window: rtas returned "
-                       "%d to ibm,remove-pe-dma-window(%x) %llx\n",
-                       np->full_name, ret, ddr_avail[2], liobn);
-       else
-               pr_debug("%s: successfully removed direct window: rtas returned "
-                       "%d to ibm,remove-pe-dma-window(%x) %llx\n",
-                       np->full_name, ret, ddr_avail[2], liobn);
+               pr_warning("%s: failed to remove direct window property: %d\n",
+                       np->full_name, ret);
 }
 
-
-static int dupe_ddw_if_already_created(struct pci_dev *dev, struct device_node *pdn)
+static u64 find_existing_ddw(struct device_node *pdn)
 {
-       struct device_node *dn;
-       struct pci_dn *pcidn;
        struct direct_window *window;
        const struct dynamic_dma_window_prop *direct64;
        u64 dma_addr = 0;
 
-       dn = pci_device_to_OF_node(dev);
-       pcidn = PCI_DN(dn);
        spin_lock(&direct_window_list_lock);
        /* check if we already created a window and dupe that config if so */
        list_for_each_entry(window, &direct_window_list, list) {
@@ -717,44 +786,43 @@ static int dupe_ddw_if_already_created(struct pci_dev *dev, struct device_node *
        return dma_addr;
 }
 
-static u64 dupe_ddw_if_kexec(struct pci_dev *dev, struct device_node *pdn)
+static int find_existing_ddw_windows(void)
 {
-       struct device_node *dn;
-       struct pci_dn *pcidn;
        int len;
+       struct device_node *pdn;
        struct direct_window *window;
        const struct dynamic_dma_window_prop *direct64;
-       u64 dma_addr = 0;
 
-       dn = pci_device_to_OF_node(dev);
-       pcidn = PCI_DN(dn);
-       direct64 = of_get_property(pdn, DIRECT64_PROPNAME, &len);
-       if (direct64) {
-               if (len < sizeof(struct dynamic_dma_window_prop)) {
+       if (!firmware_has_feature(FW_FEATURE_LPAR))
+               return 0;
+
+       for_each_node_with_property(pdn, DIRECT64_PROPNAME) {
+               direct64 = of_get_property(pdn, DIRECT64_PROPNAME, &len);
+               if (!direct64)
+                       continue;
+
+               window = kzalloc(sizeof(*window), GFP_KERNEL);
+               if (!window || len < sizeof(struct dynamic_dma_window_prop)) {
+                       kfree(window);
                        remove_ddw(pdn);
-               } else {
-                       window = kzalloc(sizeof(*window), GFP_KERNEL);
-                       if (!window) {
-                               remove_ddw(pdn);
-                       } else {
-                               window->device = pdn;
-                               window->prop = direct64;
-                               spin_lock(&direct_window_list_lock);
-                               list_add(&window->list, &direct_window_list);
-                               spin_unlock(&direct_window_list_lock);
-                               dma_addr = direct64->dma_base;
-                       }
+                       continue;
                }
+
+               window->device = pdn;
+               window->prop = direct64;
+               spin_lock(&direct_window_list_lock);
+               list_add(&window->list, &direct_window_list);
+               spin_unlock(&direct_window_list_lock);
        }
 
-       return dma_addr;
+       return 0;
 }
+machine_arch_initcall(pseries, find_existing_ddw_windows);
 
-static int query_ddw(struct pci_dev *dev, const u32 *ddr_avail,
+static int query_ddw(struct pci_dev *dev, const u32 *ddw_avail,
                        struct ddw_query_response *query)
 {
-       struct device_node *dn;
-       struct pci_dn *pcidn;
+       struct eeh_dev *edev;
        u32 cfg_addr;
        u64 buid;
        int ret;
@@ -765,26 +833,25 @@ static int query_ddw(struct pci_dev *dev, const u32 *ddr_avail,
         * Retrieve them from the pci device, not the node with the
         * dma-window property
         */
-       dn = pci_device_to_OF_node(dev);
-       pcidn = PCI_DN(dn);
-       cfg_addr = pcidn->eeh_config_addr;
-       if (pcidn->eeh_pe_config_addr)
-               cfg_addr = pcidn->eeh_pe_config_addr;
-       buid = pcidn->phb->buid;
-       ret = rtas_call(ddr_avail[0], 3, 5, (u32 *)query,
+       edev = pci_dev_to_eeh_dev(dev);
+       cfg_addr = edev->config_addr;
+       if (edev->pe_config_addr)
+               cfg_addr = edev->pe_config_addr;
+       buid = edev->phb->buid;
+
+       ret = rtas_call(ddw_avail[0], 3, 5, (u32 *)query,
                  cfg_addr, BUID_HI(buid), BUID_LO(buid));
        dev_info(&dev->dev, "ibm,query-pe-dma-windows(%x) %x %x %x"
-               " returned %d\n", ddr_avail[0], cfg_addr, BUID_HI(buid),
+               " returned %d\n", ddw_avail[0], cfg_addr, BUID_HI(buid),
                BUID_LO(buid), ret);
        return ret;
 }
 
-static int create_ddw(struct pci_dev *dev, const u32 *ddr_avail,
+static int create_ddw(struct pci_dev *dev, const u32 *ddw_avail,
                        struct ddw_create_response *create, int page_shift,
                        int window_shift)
 {
-       struct device_node *dn;
-       struct pci_dn *pcidn;
+       struct eeh_dev *edev;
        u32 cfg_addr;
        u64 buid;
        int ret;
@@ -795,27 +862,55 @@ static int create_ddw(struct pci_dev *dev, const u32 *ddr_avail,
         * Retrieve them from the pci device, not the node with the
         * dma-window property
         */
-       dn = pci_device_to_OF_node(dev);
-       pcidn = PCI_DN(dn);
-       cfg_addr = pcidn->eeh_config_addr;
-       if (pcidn->eeh_pe_config_addr)
-               cfg_addr = pcidn->eeh_pe_config_addr;
-       buid = pcidn->phb->buid;
+       edev = pci_dev_to_eeh_dev(dev);
+       cfg_addr = edev->config_addr;
+       if (edev->pe_config_addr)
+               cfg_addr = edev->pe_config_addr;
+       buid = edev->phb->buid;
 
        do {
                /* extra outputs are LIOBN and dma-addr (hi, lo) */
-               ret = rtas_call(ddr_avail[1], 5, 4, (u32 *)create, cfg_addr,
+               ret = rtas_call(ddw_avail[1], 5, 4, (u32 *)create, cfg_addr,
                                BUID_HI(buid), BUID_LO(buid), page_shift, window_shift);
        } while (rtas_busy_delay(ret));
        dev_info(&dev->dev,
                "ibm,create-pe-dma-window(%x) %x %x %x %x %x returned %d "
-               "(liobn = 0x%x starting addr = %x %x)\n", ddr_avail[1],
+               "(liobn = 0x%x starting addr = %x %x)\n", ddw_avail[1],
                 cfg_addr, BUID_HI(buid), BUID_LO(buid), page_shift,
                 window_shift, ret, create->liobn, create->addr_hi, create->addr_lo);
 
        return ret;
 }
 
+static void restore_default_window(struct pci_dev *dev,
+                               u32 ddw_restore_token, unsigned long liobn)
+{
+       struct eeh_dev *edev;
+       u32 cfg_addr;
+       u64 buid;
+       int ret;
+
+       /*
+        * Get the config address and phb buid of the PE window.
+        * Rely on eeh to retrieve this for us.
+        * Retrieve them from the pci device, not the node with the
+        * dma-window property
+        */
+       edev = pci_dev_to_eeh_dev(dev);
+       cfg_addr = edev->config_addr;
+       if (edev->pe_config_addr)
+               cfg_addr = edev->pe_config_addr;
+       buid = edev->phb->buid;
+
+       do {
+               ret = rtas_call(ddw_restore_token, 3, 1, NULL, cfg_addr,
+                                       BUID_HI(buid), BUID_LO(buid));
+       } while (rtas_busy_delay(ret));
+       dev_info(&dev->dev,
+               "ibm,reset-pe-dma-windows(%x) %x %x %x returned %d\n",
+                ddw_restore_token, cfg_addr, BUID_HI(buid), BUID_LO(buid), ret);
+}
+
 /*
  * If the PE supports dynamic dma windows, and there is space for a table
  * that can map all pages in a linear offset, then setup such a table,
@@ -835,18 +930,18 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn)
        int page_shift;
        u64 dma_addr, max_addr;
        struct device_node *dn;
-       const u32 *uninitialized_var(ddr_avail);
+       const u32 *uninitialized_var(ddw_avail);
+       const u32 *uninitialized_var(ddw_extensions);
+       u32 ddw_restore_token = 0;
        struct direct_window *window;
        struct property *win64;
        struct dynamic_dma_window_prop *ddwprop;
+       const void *dma_window = NULL;
+       unsigned long liobn, offset, size;
 
        mutex_lock(&direct_window_init_mutex);
 
-       dma_addr = dupe_ddw_if_already_created(dev, pdn);
-       if (dma_addr != 0)
-               goto out_unlock;
-
-       dma_addr = dupe_ddw_if_kexec(dev, pdn);
+       dma_addr = find_existing_ddw(pdn);
        if (dma_addr != 0)
                goto out_unlock;
 
@@ -858,20 +953,53 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn)
         * for the given node in that order.
         * the property is actually in the parent, not the PE
         */
-       ddr_avail = of_get_property(pdn, "ibm,ddw-applicable", &len);
-       if (!ddr_avail || len < 3 * sizeof(u32))
+       ddw_avail = of_get_property(pdn, "ibm,ddw-applicable", &len);
+       if (!ddw_avail || len < 3 * sizeof(u32))
                goto out_unlock;
 
-       /*
+       /*
+        * the extensions property is only required to exist in certain
+        * levels of firmware and later
+        * the ibm,ddw-extensions property is a list with the first
+        * element containing the number of extensions and each
+        * subsequent entry is a value corresponding to that extension
+        */
+       ddw_extensions = of_get_property(pdn, "ibm,ddw-extensions", &len);
+       if (ddw_extensions) {
+               /*
+                * each new defined extension length should be added to
+                * the top of the switch so the "earlier" entries also
+                * get picked up
+                */
+               switch (ddw_extensions[0]) {
+                       /* ibm,reset-pe-dma-windows */
+                       case 1:
+                               ddw_restore_token = ddw_extensions[1];
+                               break;
+               }
+       }
+
+       /*
+        * Only remove the existing DMA window if we can restore back to
+        * the default state. Removing the existing window maximizes the
+        * resources available to firmware for dynamic window creation.
+        */
+       if (ddw_restore_token) {
+               dma_window = of_get_property(pdn, "ibm,dma-window", NULL);
+               of_parse_dma_window(pdn, dma_window, &liobn, &offset, &size);
+               __remove_ddw(pdn, ddw_avail, liobn);
+       }
+
+       /*
         * Query if there is a second window of size to map the
         * whole partition.  Query returns number of windows, largest
         * block assigned to PE (partition endpoint), and two bitmasks
         * of page sizes: supported and supported for migrate-dma.
         */
        dn = pci_device_to_OF_node(dev);
-       ret = query_ddw(dev, ddr_avail, &query);
+       ret = query_ddw(dev, ddw_avail, &query);
        if (ret != 0)
-               goto out_unlock;
+               goto out_restore_window;
 
        if (query.windows_available == 0) {
                /*
@@ -880,7 +1008,7 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn)
                 * trading in for a larger page size.
                 */
                dev_dbg(&dev->dev, "no free dynamic windows");
-               goto out_unlock;
+               goto out_restore_window;
        }
        if (query.page_size & 4) {
                page_shift = 24; /* 16MB */
@@ -891,7 +1019,7 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn)
        } else {
                dev_dbg(&dev->dev, "no supported direct page size in mask %x",
                          query.page_size);
-               goto out_unlock;
+               goto out_restore_window;
        }
        /* verify the window * number of ptes will map the partition */
        /* check largest block * page size > max memory hotplug addr */
@@ -900,14 +1028,14 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn)
                dev_dbg(&dev->dev, "can't map partiton max 0x%llx with %u "
                          "%llu-sized pages\n", max_addr,  query.largest_available_block,
                          1ULL << page_shift);
-               goto out_unlock;
+               goto out_restore_window;
        }
        len = order_base_2(max_addr);
        win64 = kzalloc(sizeof(struct property), GFP_KERNEL);
        if (!win64) {
                dev_info(&dev->dev,
                        "couldn't allocate property for 64bit dma window\n");
-               goto out_unlock;
+               goto out_restore_window;
        }
        win64->name = kstrdup(DIRECT64_PROPNAME, GFP_KERNEL);
        win64->value = ddwprop = kmalloc(sizeof(*ddwprop), GFP_KERNEL);
@@ -918,7 +1046,7 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn)
                goto out_free_prop;
        }
 
-       ret = create_ddw(dev, ddr_avail, &create, page_shift, len);
+       ret = create_ddw(dev, ddw_avail, &create, page_shift, len);
        if (ret != 0)
                goto out_free_prop;
 
@@ -939,14 +1067,14 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn)
        if (ret) {
                dev_info(&dev->dev, "failed to map direct window for %s: %d\n",
                         dn->full_name, ret);
-               goto out_clear_window;
+               goto out_free_window;
        }
 
        ret = prom_add_property(pdn, win64);
        if (ret) {
                dev_err(&dev->dev, "unable to add dma window property for %s: %d",
                         pdn->full_name, ret);
-               goto out_clear_window;
+               goto out_free_window;
        }
 
        window->device = pdn;
@@ -958,6 +1086,9 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn)
        dma_addr = of_read_number(&create.addr_hi, 2);
        goto out_unlock;
 
+out_free_window:
+       kfree(window);
+
 out_clear_window:
        remove_ddw(pdn);
 
@@ -966,6 +1097,10 @@ out_free_prop:
        kfree(win64->value);
        kfree(win64);
 
+out_restore_window:
+       if (ddw_restore_token)
+               restore_default_window(dev, ddw_restore_token, liobn);
+
 out_unlock:
        mutex_unlock(&direct_window_init_mutex);
        return dma_addr;
@@ -999,7 +1134,7 @@ static void pci_dma_dev_setup_pSeriesLP(struct pci_dev *dev)
        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>");
+                                pci_name(dev), of_node_full_name(dn));
                return;
        }
        pr_debug("  parent is %s\n", pdn->full_name);
@@ -1026,13 +1161,16 @@ static int dma_set_mask_pSeriesLP(struct device *dev, u64 dma_mask)
        const void *dma_window = NULL;
        u64 dma_offset;
 
-       if (!dev->dma_mask || !dma_supported(dev, dma_mask))
+       if (!dev->dma_mask)
                return -EIO;
 
+       if (!dev_is_pci(dev))
+               goto check_mask;
+
+       pdev = to_pci_dev(dev);
+
        /* only attempt to use a new window if 64-bit DMA is requested */
        if (!disable_ddw && dma_mask == DMA_BIT_MASK(64)) {
-               pdev = to_pci_dev(dev);
-
                dn = pci_device_to_OF_node(pdev);
                dev_dbg(dev, "node is %s\n", dn->full_name);
 
@@ -1059,22 +1197,53 @@ static int dma_set_mask_pSeriesLP(struct device *dev, u64 dma_mask)
                }
        }
 
-       /* fall-through to iommu ops */
-       if (!ddw_enabled) {
-               dev_info(dev, "Using 32-bit DMA via iommu\n");
+       /* fall back on iommu ops, restore table pointer with ops */
+       if (!ddw_enabled && get_dma_ops(dev) != &dma_iommu_ops) {
+               dev_info(dev, "Restoring 32-bit DMA via iommu\n");
                set_dma_ops(dev, &dma_iommu_ops);
+               pci_dma_dev_setup_pSeriesLP(pdev);
        }
 
+check_mask:
+       if (!dma_supported(dev, dma_mask))
+               return -EIO;
+
        *dev->dma_mask = dma_mask;
        return 0;
 }
 
+static u64 dma_get_required_mask_pSeriesLP(struct device *dev)
+{
+       if (!dev->dma_mask)
+               return 0;
+
+       if (!disable_ddw && dev_is_pci(dev)) {
+               struct pci_dev *pdev = to_pci_dev(dev);
+               struct device_node *dn;
+
+               dn = pci_device_to_OF_node(pdev);
+
+               /* search upwards for ibm,dma-window */
+               for (; dn && PCI_DN(dn) && !PCI_DN(dn)->iommu_table;
+                               dn = dn->parent)
+                       if (of_get_property(dn, "ibm,dma-window", NULL))
+                               break;
+               /* if there is a ibm,ddw-applicable property require 64 bits */
+               if (dn && PCI_DN(dn) &&
+                               of_get_property(dn, "ibm,ddw-applicable", NULL))
+                       return DMA_BIT_MASK(64);
+       }
+
+       return dma_iommu_ops.get_required_mask(dev);
+}
+
 #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
 #define dma_set_mask_pSeriesLP         NULL
+#define dma_get_required_mask_pSeriesLP        NULL
 #endif /* !CONFIG_PCI */
 
 static int iommu_mem_notifier(struct notifier_block *nb, unsigned long action,
@@ -1178,6 +1347,7 @@ void iommu_init_early_pSeries(void)
                ppc_md.pci_dma_bus_setup = pci_dma_bus_setup_pSeriesLP;
                ppc_md.pci_dma_dev_setup = pci_dma_dev_setup_pSeriesLP;
                ppc_md.dma_set_mask = dma_set_mask_pSeriesLP;
+               ppc_md.dma_get_required_mask = dma_get_required_mask_pSeriesLP;
        } else {
                ppc_md.tce_build = tce_build_pSeries;
                ppc_md.tce_free  = tce_free_pSeries;