1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2001 Mike Corrigan & Dave Engebretsen, IBM Corporation
7 * Copyright (C) 2004 Olof Johansson <olof@lixom.net>, IBM Corporation
8 * Copyright (C) 2006 Olof Johansson <olof@lixom.net>
10 * Dynamic DMA mapping support, pSeries-specific parts, both SMP and LPAR.
13 #include <linux/init.h>
14 #include <linux/types.h>
15 #include <linux/slab.h>
17 #include <linux/memblock.h>
18 #include <linux/spinlock.h>
19 #include <linux/string.h>
20 #include <linux/pci.h>
21 #include <linux/dma-mapping.h>
22 #include <linux/crash_dump.h>
23 #include <linux/memory.h>
25 #include <linux/iommu.h>
26 #include <linux/rculist.h>
30 #include <asm/iommu.h>
31 #include <asm/pci-bridge.h>
32 #include <asm/machdep.h>
33 #include <asm/firmware.h>
35 #include <asm/ppc-pci.h>
37 #include <asm/mmzone.h>
38 #include <asm/plpar_wrappers.h>
43 DDW_QUERY_PE_DMA_WIN = 0,
44 DDW_CREATE_PE_DMA_WIN = 1,
45 DDW_REMOVE_PE_DMA_WIN = 2,
52 DDW_EXT_RESET_DMA_WIN = 1,
53 DDW_EXT_QUERY_OUT_SIZE = 2
56 static struct iommu_table *iommu_pseries_alloc_table(int node)
58 struct iommu_table *tbl;
60 tbl = kzalloc_node(sizeof(struct iommu_table), GFP_KERNEL, node);
64 INIT_LIST_HEAD_RCU(&tbl->it_group_list);
65 kref_init(&tbl->it_kref);
69 static struct iommu_table_group *iommu_pseries_alloc_group(int node)
71 struct iommu_table_group *table_group;
73 table_group = kzalloc_node(sizeof(*table_group), GFP_KERNEL, node);
77 table_group->tables[0] = iommu_pseries_alloc_table(node);
78 if (table_group->tables[0])
85 static void iommu_pseries_free_group(struct iommu_table_group *table_group,
86 const char *node_name)
88 struct iommu_table *tbl;
93 tbl = table_group->tables[0];
94 #ifdef CONFIG_IOMMU_API
95 if (table_group->group) {
96 iommu_group_put(table_group->group);
97 BUG_ON(table_group->group);
100 iommu_tce_table_put(tbl);
105 static int tce_build_pSeries(struct iommu_table *tbl, long index,
106 long npages, unsigned long uaddr,
107 enum dma_data_direction direction,
113 const unsigned long tceshift = tbl->it_page_shift;
114 const unsigned long pagesize = IOMMU_PAGE_SIZE(tbl);
116 proto_tce = TCE_PCI_READ; // Read allowed
118 if (direction != DMA_TO_DEVICE)
119 proto_tce |= TCE_PCI_WRITE;
121 tcep = ((__be64 *)tbl->it_base) + index;
124 /* can't move this out since we might cross MEMBLOCK boundary */
125 rpn = __pa(uaddr) >> tceshift;
126 *tcep = cpu_to_be64(proto_tce | rpn << tceshift);
135 static void tce_free_pSeries(struct iommu_table *tbl, long index, long npages)
139 tcep = ((__be64 *)tbl->it_base) + index;
145 static unsigned long tce_get_pseries(struct iommu_table *tbl, long index)
149 tcep = ((__be64 *)tbl->it_base) + index;
151 return be64_to_cpu(*tcep);
154 static void tce_free_pSeriesLP(unsigned long liobn, long, long, long);
155 static void tce_freemulti_pSeriesLP(struct iommu_table*, long, long);
157 static int tce_build_pSeriesLP(unsigned long liobn, long tcenum, long tceshift,
158 long npages, unsigned long uaddr,
159 enum dma_data_direction direction,
166 long tcenum_start = tcenum, npages_start = npages;
168 rpn = __pa(uaddr) >> tceshift;
169 proto_tce = TCE_PCI_READ;
170 if (direction != DMA_TO_DEVICE)
171 proto_tce |= TCE_PCI_WRITE;
174 tce = proto_tce | rpn << tceshift;
175 rc = plpar_tce_put((u64)liobn, (u64)tcenum << tceshift, tce);
177 if (unlikely(rc == H_NOT_ENOUGH_RESOURCES)) {
179 tce_free_pSeriesLP(liobn, tcenum_start, tceshift,
180 (npages_start - (npages + 1)));
184 if (rc && printk_ratelimit()) {
185 printk("tce_build_pSeriesLP: plpar_tce_put failed. rc=%lld\n", rc);
186 printk("\tindex = 0x%llx\n", (u64)liobn);
187 printk("\ttcenum = 0x%llx\n", (u64)tcenum);
188 printk("\ttce val = 0x%llx\n", tce );
198 static DEFINE_PER_CPU(__be64 *, tce_page);
200 static int tce_buildmulti_pSeriesLP(struct iommu_table *tbl, long tcenum,
201 long npages, unsigned long uaddr,
202 enum dma_data_direction direction,
210 long tcenum_start = tcenum, npages_start = npages;
213 const unsigned long tceshift = tbl->it_page_shift;
215 if ((npages == 1) || !firmware_has_feature(FW_FEATURE_PUT_TCE_IND)) {
216 return tce_build_pSeriesLP(tbl->it_index, tcenum,
217 tceshift, npages, uaddr,
221 local_irq_save(flags); /* to protect tcep and the page behind it */
223 tcep = __this_cpu_read(tce_page);
225 /* This is safe to do since interrupts are off when we're called
226 * from iommu_alloc{,_sg}()
229 tcep = (__be64 *)__get_free_page(GFP_ATOMIC);
230 /* If allocation fails, fall back to the loop implementation */
232 local_irq_restore(flags);
233 return tce_build_pSeriesLP(tbl->it_index, tcenum,
235 npages, uaddr, direction, attrs);
237 __this_cpu_write(tce_page, tcep);
240 rpn = __pa(uaddr) >> tceshift;
241 proto_tce = TCE_PCI_READ;
242 if (direction != DMA_TO_DEVICE)
243 proto_tce |= TCE_PCI_WRITE;
245 /* We can map max one pageful of TCEs at a time */
248 * Set up the page with TCE data, looping through and setting
251 limit = min_t(long, npages, 4096/TCE_ENTRY_SIZE);
253 for (l = 0; l < limit; l++) {
254 tcep[l] = cpu_to_be64(proto_tce | rpn << tceshift);
258 rc = plpar_tce_put_indirect((u64)tbl->it_index,
259 (u64)tcenum << tceshift,
265 } while (npages > 0 && !rc);
267 local_irq_restore(flags);
269 if (unlikely(rc == H_NOT_ENOUGH_RESOURCES)) {
271 tce_freemulti_pSeriesLP(tbl, tcenum_start,
272 (npages_start - (npages + limit)));
276 if (rc && printk_ratelimit()) {
277 printk("tce_buildmulti_pSeriesLP: plpar_tce_put failed. rc=%lld\n", rc);
278 printk("\tindex = 0x%llx\n", (u64)tbl->it_index);
279 printk("\tnpages = 0x%llx\n", (u64)npages);
280 printk("\ttce[0] val = 0x%llx\n", tcep[0]);
286 static void tce_free_pSeriesLP(unsigned long liobn, long tcenum, long tceshift,
292 rc = plpar_tce_put((u64)liobn, (u64)tcenum << tceshift, 0);
294 if (rc && printk_ratelimit()) {
295 printk("tce_free_pSeriesLP: plpar_tce_put failed. rc=%lld\n", rc);
296 printk("\tindex = 0x%llx\n", (u64)liobn);
297 printk("\ttcenum = 0x%llx\n", (u64)tcenum);
306 static void tce_freemulti_pSeriesLP(struct iommu_table *tbl, long tcenum, long npages)
310 if (!firmware_has_feature(FW_FEATURE_STUFF_TCE))
311 return tce_free_pSeriesLP(tbl->it_index, tcenum,
312 tbl->it_page_shift, npages);
314 rc = plpar_tce_stuff((u64)tbl->it_index,
315 (u64)tcenum << tbl->it_page_shift, 0, npages);
317 if (rc && printk_ratelimit()) {
318 printk("tce_freemulti_pSeriesLP: plpar_tce_stuff failed\n");
319 printk("\trc = %lld\n", rc);
320 printk("\tindex = 0x%llx\n", (u64)tbl->it_index);
321 printk("\tnpages = 0x%llx\n", (u64)npages);
326 static unsigned long tce_get_pSeriesLP(struct iommu_table *tbl, long tcenum)
329 unsigned long tce_ret;
331 rc = plpar_tce_get((u64)tbl->it_index,
332 (u64)tcenum << tbl->it_page_shift, &tce_ret);
334 if (rc && printk_ratelimit()) {
335 printk("tce_get_pSeriesLP: plpar_tce_get failed. rc=%lld\n", rc);
336 printk("\tindex = 0x%llx\n", (u64)tbl->it_index);
337 printk("\ttcenum = 0x%llx\n", (u64)tcenum);
344 /* this is compatible with cells for the device tree property */
345 struct dynamic_dma_window_prop {
346 __be32 liobn; /* tce table number */
347 __be64 dma_base; /* address hi,lo */
348 __be32 tce_shift; /* ilog2(tce_page_size) */
349 __be32 window_shift; /* ilog2(tce_window_size) */
353 struct device_node *device;
354 const struct dynamic_dma_window_prop *prop;
355 struct list_head list;
358 /* Dynamic DMA Window support */
359 struct ddw_query_response {
360 u32 windows_available;
361 u64 largest_available_block;
363 u32 migration_capable;
366 struct ddw_create_response {
372 static LIST_HEAD(dma_win_list);
373 /* prevents races between memory on/offline and window creation */
374 static DEFINE_SPINLOCK(dma_win_list_lock);
375 /* protects initializing window twice for same device */
376 static DEFINE_MUTEX(dma_win_init_mutex);
377 #define DIRECT64_PROPNAME "linux,direct64-ddr-window-info"
378 #define DMA64_PROPNAME "linux,dma64-ddr-window-info"
380 static int tce_clearrange_multi_pSeriesLP(unsigned long start_pfn,
381 unsigned long num_pfn, const void *arg)
383 const struct dynamic_dma_window_prop *maprange = arg;
385 u64 tce_size, num_tce, dma_offset, next;
389 tce_shift = be32_to_cpu(maprange->tce_shift);
390 tce_size = 1ULL << tce_shift;
391 next = start_pfn << PAGE_SHIFT;
392 num_tce = num_pfn << PAGE_SHIFT;
394 /* round back to the beginning of the tce page size */
395 num_tce += next & (tce_size - 1);
396 next &= ~(tce_size - 1);
398 /* covert to number of tces */
399 num_tce |= tce_size - 1;
400 num_tce >>= tce_shift;
404 * Set up the page with TCE data, looping through and setting
407 limit = min_t(long, num_tce, 512);
408 dma_offset = next + be64_to_cpu(maprange->dma_base);
410 rc = plpar_tce_stuff((u64)be32_to_cpu(maprange->liobn),
413 next += limit * tce_size;
415 } while (num_tce > 0 && !rc);
420 static int tce_setrange_multi_pSeriesLP(unsigned long start_pfn,
421 unsigned long num_pfn, const void *arg)
423 const struct dynamic_dma_window_prop *maprange = arg;
424 u64 tce_size, num_tce, dma_offset, next, proto_tce, liobn;
430 if (!firmware_has_feature(FW_FEATURE_PUT_TCE_IND)) {
431 unsigned long tceshift = be32_to_cpu(maprange->tce_shift);
432 unsigned long dmastart = (start_pfn << PAGE_SHIFT) +
433 be64_to_cpu(maprange->dma_base);
434 unsigned long tcenum = dmastart >> tceshift;
435 unsigned long npages = num_pfn << PAGE_SHIFT >> tceshift;
436 void *uaddr = __va(start_pfn << PAGE_SHIFT);
438 return tce_build_pSeriesLP(be32_to_cpu(maprange->liobn),
439 tcenum, tceshift, npages, (unsigned long) uaddr,
440 DMA_BIDIRECTIONAL, 0);
443 local_irq_disable(); /* to protect tcep and the page behind it */
444 tcep = __this_cpu_read(tce_page);
447 tcep = (__be64 *)__get_free_page(GFP_ATOMIC);
452 __this_cpu_write(tce_page, tcep);
455 proto_tce = TCE_PCI_READ | TCE_PCI_WRITE;
457 liobn = (u64)be32_to_cpu(maprange->liobn);
458 tce_shift = be32_to_cpu(maprange->tce_shift);
459 tce_size = 1ULL << tce_shift;
460 next = start_pfn << PAGE_SHIFT;
461 num_tce = num_pfn << PAGE_SHIFT;
463 /* round back to the beginning of the tce page size */
464 num_tce += next & (tce_size - 1);
465 next &= ~(tce_size - 1);
467 /* covert to number of tces */
468 num_tce |= tce_size - 1;
469 num_tce >>= tce_shift;
471 /* We can map max one pageful of TCEs at a time */
474 * Set up the page with TCE data, looping through and setting
477 limit = min_t(long, num_tce, 4096/TCE_ENTRY_SIZE);
478 dma_offset = next + be64_to_cpu(maprange->dma_base);
480 for (l = 0; l < limit; l++) {
481 tcep[l] = cpu_to_be64(proto_tce | next);
485 rc = plpar_tce_put_indirect(liobn,
491 } while (num_tce > 0 && !rc);
493 /* error cleanup: caller will clear whole range */
499 static int tce_setrange_multi_pSeriesLP_walk(unsigned long start_pfn,
500 unsigned long num_pfn, void *arg)
502 return tce_setrange_multi_pSeriesLP(start_pfn, num_pfn, arg);
505 static void iommu_table_setparms_common(struct iommu_table *tbl, unsigned long busno,
506 unsigned long liobn, unsigned long win_addr,
507 unsigned long window_size, unsigned long page_shift,
508 void *base, struct iommu_table_ops *table_ops)
510 tbl->it_busno = busno;
511 tbl->it_index = liobn;
512 tbl->it_offset = win_addr >> page_shift;
513 tbl->it_size = window_size >> page_shift;
514 tbl->it_page_shift = page_shift;
515 tbl->it_base = (unsigned long)base;
516 tbl->it_blocksize = 16;
517 tbl->it_type = TCE_PCI;
518 tbl->it_ops = table_ops;
521 struct iommu_table_ops iommu_table_pseries_ops;
523 static void iommu_table_setparms(struct pci_controller *phb,
524 struct device_node *dn,
525 struct iommu_table *tbl)
527 struct device_node *node;
528 const unsigned long *basep;
531 /* Test if we are going over 2GB of DMA space */
532 if (phb->dma_window_base_cur + phb->dma_window_size > SZ_2G) {
533 udbg_printf("PCI_DMA: Unexpected number of IOAs under this PHB.\n");
534 panic("PCI_DMA: Unexpected number of IOAs under this PHB.\n");
538 basep = of_get_property(node, "linux,tce-base", NULL);
539 sizep = of_get_property(node, "linux,tce-size", NULL);
540 if (basep == NULL || sizep == NULL) {
541 printk(KERN_ERR "PCI_DMA: iommu_table_setparms: %pOF has "
542 "missing tce entries !\n", dn);
546 iommu_table_setparms_common(tbl, phb->bus->number, 0, phb->dma_window_base_cur,
547 phb->dma_window_size, IOMMU_PAGE_SHIFT_4K,
548 __va(*basep), &iommu_table_pseries_ops);
550 if (!is_kdump_kernel())
551 memset((void *)tbl->it_base, 0, *sizep);
553 phb->dma_window_base_cur += phb->dma_window_size;
556 struct iommu_table_ops iommu_table_lpar_multi_ops;
559 * iommu_table_setparms_lpar
561 * Function: On pSeries LPAR systems, return TCE table info, given a pci bus.
563 static void iommu_table_setparms_lpar(struct pci_controller *phb,
564 struct device_node *dn,
565 struct iommu_table *tbl,
566 struct iommu_table_group *table_group,
567 const __be32 *dma_window)
569 unsigned long offset, size, liobn;
571 of_parse_dma_window(dn, dma_window, &liobn, &offset, &size);
573 iommu_table_setparms_common(tbl, phb->bus->number, liobn, offset, size, IOMMU_PAGE_SHIFT_4K, NULL,
574 &iommu_table_lpar_multi_ops);
577 table_group->tce32_start = offset;
578 table_group->tce32_size = size;
581 struct iommu_table_ops iommu_table_pseries_ops = {
582 .set = tce_build_pSeries,
583 .clear = tce_free_pSeries,
584 .get = tce_get_pseries
587 static void pci_dma_bus_setup_pSeries(struct pci_bus *bus)
589 struct device_node *dn;
590 struct iommu_table *tbl;
591 struct device_node *isa_dn, *isa_dn_orig;
592 struct device_node *tmp;
596 dn = pci_bus_to_OF_node(bus);
598 pr_debug("pci_dma_bus_setup_pSeries: setting up bus %pOF\n", dn);
601 /* This is not a root bus, any setup will be done for the
602 * device-side of the bridge in iommu_dev_setup_pSeries().
608 /* Check if the ISA bus on the system is under
611 isa_dn = isa_dn_orig = of_find_node_by_type(NULL, "isa");
613 while (isa_dn && isa_dn != dn)
614 isa_dn = isa_dn->parent;
616 of_node_put(isa_dn_orig);
618 /* Count number of direct PCI children of the PHB. */
619 for (children = 0, tmp = dn->child; tmp; tmp = tmp->sibling)
622 pr_debug("Children: %d\n", children);
624 /* Calculate amount of DMA window per slot. Each window must be
625 * a power of two (due to pci_alloc_consistent requirements).
627 * Keep 256MB aside for PHBs with ISA.
631 /* No ISA/IDE - just set window size and return */
632 pci->phb->dma_window_size = 0x80000000ul; /* To be divided */
634 while (pci->phb->dma_window_size * children > 0x80000000ul)
635 pci->phb->dma_window_size >>= 1;
636 pr_debug("No ISA/IDE, window size is 0x%llx\n",
637 pci->phb->dma_window_size);
638 pci->phb->dma_window_base_cur = 0;
643 /* If we have ISA, then we probably have an IDE
644 * controller too. Allocate a 128MB table but
645 * skip the first 128MB to avoid stepping on ISA
648 pci->phb->dma_window_size = 0x8000000ul;
649 pci->phb->dma_window_base_cur = 0x8000000ul;
651 pci->table_group = iommu_pseries_alloc_group(pci->phb->node);
652 tbl = pci->table_group->tables[0];
654 iommu_table_setparms(pci->phb, dn, tbl);
656 if (!iommu_init_table(tbl, pci->phb->node, 0, 0))
657 panic("Failed to initialize iommu table");
659 /* Divide the rest (1.75GB) among the children */
660 pci->phb->dma_window_size = 0x80000000ul;
661 while (pci->phb->dma_window_size * children > 0x70000000ul)
662 pci->phb->dma_window_size >>= 1;
664 pr_debug("ISA/IDE, window size is 0x%llx\n", pci->phb->dma_window_size);
667 #ifdef CONFIG_IOMMU_API
668 static int tce_exchange_pseries(struct iommu_table *tbl, long index, unsigned
669 long *tce, enum dma_data_direction *direction)
672 unsigned long ioba = (unsigned long) index << tbl->it_page_shift;
673 unsigned long flags, oldtce = 0;
674 u64 proto_tce = iommu_direction_to_tce_perm(*direction);
675 unsigned long newtce = *tce | proto_tce;
677 spin_lock_irqsave(&tbl->large_pool.lock, flags);
679 rc = plpar_tce_get((u64)tbl->it_index, ioba, &oldtce);
681 rc = plpar_tce_put((u64)tbl->it_index, ioba, newtce);
684 *direction = iommu_tce_direction(oldtce);
685 *tce = oldtce & ~(TCE_PCI_READ | TCE_PCI_WRITE);
688 spin_unlock_irqrestore(&tbl->large_pool.lock, flags);
694 struct iommu_table_ops iommu_table_lpar_multi_ops = {
695 .set = tce_buildmulti_pSeriesLP,
696 #ifdef CONFIG_IOMMU_API
697 .xchg_no_kill = tce_exchange_pseries,
699 .clear = tce_freemulti_pSeriesLP,
700 .get = tce_get_pSeriesLP
703 static void pci_dma_bus_setup_pSeriesLP(struct pci_bus *bus)
705 struct iommu_table *tbl;
706 struct device_node *dn, *pdn;
708 const __be32 *dma_window = NULL;
710 dn = pci_bus_to_OF_node(bus);
712 pr_debug("pci_dma_bus_setup_pSeriesLP: setting up bus %pOF\n",
716 * Find nearest ibm,dma-window (default DMA window), walking up the
719 for (pdn = dn; pdn != NULL; pdn = pdn->parent) {
720 dma_window = of_get_property(pdn, "ibm,dma-window", NULL);
721 if (dma_window != NULL)
725 if (dma_window == NULL) {
726 pr_debug(" no ibm,dma-window property !\n");
732 pr_debug(" parent is %pOF, iommu_table: 0x%p\n",
733 pdn, ppci->table_group);
735 if (!ppci->table_group) {
736 ppci->table_group = iommu_pseries_alloc_group(ppci->phb->node);
737 tbl = ppci->table_group->tables[0];
738 iommu_table_setparms_lpar(ppci->phb, pdn, tbl,
739 ppci->table_group, dma_window);
741 if (!iommu_init_table(tbl, ppci->phb->node, 0, 0))
742 panic("Failed to initialize iommu table");
743 iommu_register_group(ppci->table_group,
744 pci_domain_nr(bus), 0);
745 pr_debug(" created table: %p\n", ppci->table_group);
750 static void pci_dma_dev_setup_pSeries(struct pci_dev *dev)
752 struct device_node *dn;
753 struct iommu_table *tbl;
755 pr_debug("pci_dma_dev_setup_pSeries: %s\n", pci_name(dev));
757 dn = dev->dev.of_node;
759 /* If we're the direct child of a root bus, then we need to allocate
760 * an iommu table ourselves. The bus setup code should have setup
761 * the window sizes already.
763 if (!dev->bus->self) {
764 struct pci_controller *phb = PCI_DN(dn)->phb;
766 pr_debug(" --> first child, no bridge. Allocating iommu table.\n");
767 PCI_DN(dn)->table_group = iommu_pseries_alloc_group(phb->node);
768 tbl = PCI_DN(dn)->table_group->tables[0];
769 iommu_table_setparms(phb, dn, tbl);
771 if (!iommu_init_table(tbl, phb->node, 0, 0))
772 panic("Failed to initialize iommu table");
774 set_iommu_table_base(&dev->dev, tbl);
778 /* If this device is further down the bus tree, search upwards until
779 * an already allocated iommu table is found and use that.
782 while (dn && PCI_DN(dn) && PCI_DN(dn)->table_group == NULL)
785 if (dn && PCI_DN(dn))
786 set_iommu_table_base(&dev->dev,
787 PCI_DN(dn)->table_group->tables[0]);
789 printk(KERN_WARNING "iommu: Device %s has no iommu table\n",
793 static int __read_mostly disable_ddw;
795 static int __init disable_ddw_setup(char *str)
798 printk(KERN_INFO "ppc iommu: disabling ddw.\n");
803 early_param("disable_ddw", disable_ddw_setup);
805 static void clean_dma_window(struct device_node *np, struct dynamic_dma_window_prop *dwp)
809 ret = tce_clearrange_multi_pSeriesLP(0,
810 1ULL << (be32_to_cpu(dwp->window_shift) - PAGE_SHIFT), dwp);
812 pr_warn("%pOF failed to clear tces in window.\n",
815 pr_debug("%pOF successfully cleared tces in window.\n",
820 * Call only if DMA window is clean.
822 static void __remove_dma_window(struct device_node *np, u32 *ddw_avail, u64 liobn)
826 ret = rtas_call(ddw_avail[DDW_REMOVE_PE_DMA_WIN], 1, 1, NULL, liobn);
828 pr_warn("%pOF: failed to remove DMA window: rtas returned "
829 "%d to ibm,remove-pe-dma-window(%x) %llx\n",
830 np, ret, ddw_avail[DDW_REMOVE_PE_DMA_WIN], liobn);
832 pr_debug("%pOF: successfully removed DMA window: rtas returned "
833 "%d to ibm,remove-pe-dma-window(%x) %llx\n",
834 np, ret, ddw_avail[DDW_REMOVE_PE_DMA_WIN], liobn);
837 static void remove_dma_window(struct device_node *np, u32 *ddw_avail,
838 struct property *win)
840 struct dynamic_dma_window_prop *dwp;
844 liobn = (u64)be32_to_cpu(dwp->liobn);
846 clean_dma_window(np, dwp);
847 __remove_dma_window(np, ddw_avail, liobn);
850 static int remove_ddw(struct device_node *np, bool remove_prop, const char *win_name)
852 struct property *win;
853 u32 ddw_avail[DDW_APPLICABLE_SIZE];
856 win = of_find_property(np, win_name, NULL);
860 ret = of_property_read_u32_array(np, "ibm,ddw-applicable",
861 &ddw_avail[0], DDW_APPLICABLE_SIZE);
866 if (win->length >= sizeof(struct dynamic_dma_window_prop))
867 remove_dma_window(np, ddw_avail, win);
872 ret = of_remove_property(np, win);
874 pr_warn("%pOF: failed to remove DMA window property: %d\n",
879 static bool find_existing_ddw(struct device_node *pdn, u64 *dma_addr, int *window_shift)
881 struct dma_win *window;
882 const struct dynamic_dma_window_prop *dma64;
885 spin_lock(&dma_win_list_lock);
886 /* check if we already created a window and dupe that config if so */
887 list_for_each_entry(window, &dma_win_list, list) {
888 if (window->device == pdn) {
889 dma64 = window->prop;
890 *dma_addr = be64_to_cpu(dma64->dma_base);
891 *window_shift = be32_to_cpu(dma64->window_shift);
896 spin_unlock(&dma_win_list_lock);
901 static struct dma_win *ddw_list_new_entry(struct device_node *pdn,
902 const struct dynamic_dma_window_prop *dma64)
904 struct dma_win *window;
906 window = kzalloc(sizeof(*window), GFP_KERNEL);
910 window->device = pdn;
911 window->prop = dma64;
916 static void find_existing_ddw_windows_named(const char *name)
919 struct device_node *pdn;
920 struct dma_win *window;
921 const struct dynamic_dma_window_prop *dma64;
923 for_each_node_with_property(pdn, name) {
924 dma64 = of_get_property(pdn, name, &len);
925 if (!dma64 || len < sizeof(*dma64)) {
926 remove_ddw(pdn, true, name);
930 window = ddw_list_new_entry(pdn, dma64);
936 spin_lock(&dma_win_list_lock);
937 list_add(&window->list, &dma_win_list);
938 spin_unlock(&dma_win_list_lock);
942 static int find_existing_ddw_windows(void)
944 if (!firmware_has_feature(FW_FEATURE_LPAR))
947 find_existing_ddw_windows_named(DIRECT64_PROPNAME);
948 find_existing_ddw_windows_named(DMA64_PROPNAME);
952 machine_arch_initcall(pseries, find_existing_ddw_windows);
955 * ddw_read_ext - Get the value of an DDW extension
956 * @np: device node from which the extension value is to be read.
957 * @extnum: index number of the extension.
958 * @value: pointer to return value, modified when extension is available.
960 * Checks if "ibm,ddw-extensions" exists for this node, and get the value
962 * It can be used only to check if a property exists, passing value == NULL.
965 * 0 if extension successfully read
966 * -EINVAL if the "ibm,ddw-extensions" does not exist,
967 * -ENODATA if "ibm,ddw-extensions" does not have a value, and
968 * -EOVERFLOW if "ibm,ddw-extensions" does not contain this extension.
970 static inline int ddw_read_ext(const struct device_node *np, int extnum,
973 static const char propname[] = "ibm,ddw-extensions";
977 ret = of_property_read_u32_index(np, propname, DDW_EXT_SIZE, &count);
987 return of_property_read_u32_index(np, propname, extnum, value);
990 static int query_ddw(struct pci_dev *dev, const u32 *ddw_avail,
991 struct ddw_query_response *query,
992 struct device_node *parent)
994 struct device_node *dn;
996 u32 cfg_addr, ext_query, query_out[5];
1001 * From LoPAR level 2.8, "ibm,ddw-extensions" index 3 can rule how many
1002 * output parameters ibm,query-pe-dma-windows will have, ranging from
1005 ret = ddw_read_ext(parent, DDW_EXT_QUERY_OUT_SIZE, &ext_query);
1006 if (!ret && ext_query == 1)
1012 * Get the config address and phb buid of the PE window.
1013 * Rely on eeh to retrieve this for us.
1014 * Retrieve them from the pci device, not the node with the
1015 * dma-window property
1017 dn = pci_device_to_OF_node(dev);
1019 buid = pdn->phb->buid;
1020 cfg_addr = ((pdn->busno << 16) | (pdn->devfn << 8));
1022 ret = rtas_call(ddw_avail[DDW_QUERY_PE_DMA_WIN], 3, out_sz, query_out,
1023 cfg_addr, BUID_HI(buid), BUID_LO(buid));
1024 dev_info(&dev->dev, "ibm,query-pe-dma-windows(%x) %x %x %x returned %d\n",
1025 ddw_avail[DDW_QUERY_PE_DMA_WIN], cfg_addr, BUID_HI(buid),
1026 BUID_LO(buid), ret);
1030 query->windows_available = query_out[0];
1031 query->largest_available_block = query_out[1];
1032 query->page_size = query_out[2];
1033 query->migration_capable = query_out[3];
1036 query->windows_available = query_out[0];
1037 query->largest_available_block = ((u64)query_out[1] << 32) |
1039 query->page_size = query_out[3];
1040 query->migration_capable = query_out[4];
1047 static int create_ddw(struct pci_dev *dev, const u32 *ddw_avail,
1048 struct ddw_create_response *create, int page_shift,
1051 struct device_node *dn;
1058 * Get the config address and phb buid of the PE window.
1059 * Rely on eeh to retrieve this for us.
1060 * Retrieve them from the pci device, not the node with the
1061 * dma-window property
1063 dn = pci_device_to_OF_node(dev);
1065 buid = pdn->phb->buid;
1066 cfg_addr = ((pdn->busno << 16) | (pdn->devfn << 8));
1069 /* extra outputs are LIOBN and dma-addr (hi, lo) */
1070 ret = rtas_call(ddw_avail[DDW_CREATE_PE_DMA_WIN], 5, 4,
1071 (u32 *)create, cfg_addr, BUID_HI(buid),
1072 BUID_LO(buid), page_shift, window_shift);
1073 } while (rtas_busy_delay(ret));
1075 "ibm,create-pe-dma-window(%x) %x %x %x %x %x returned %d "
1076 "(liobn = 0x%x starting addr = %x %x)\n",
1077 ddw_avail[DDW_CREATE_PE_DMA_WIN], cfg_addr, BUID_HI(buid),
1078 BUID_LO(buid), page_shift, window_shift, ret, create->liobn,
1079 create->addr_hi, create->addr_lo);
1084 struct failed_ddw_pdn {
1085 struct device_node *pdn;
1086 struct list_head list;
1089 static LIST_HEAD(failed_ddw_pdn_list);
1091 static phys_addr_t ddw_memory_hotplug_max(void)
1093 phys_addr_t max_addr = memory_hotplug_max();
1094 struct device_node *memory;
1096 for_each_node_by_type(memory, "memory") {
1097 unsigned long start, size;
1098 int n_mem_addr_cells, n_mem_size_cells, len;
1099 const __be32 *memcell_buf;
1101 memcell_buf = of_get_property(memory, "reg", &len);
1102 if (!memcell_buf || len <= 0)
1105 n_mem_addr_cells = of_n_addr_cells(memory);
1106 n_mem_size_cells = of_n_size_cells(memory);
1108 start = of_read_number(memcell_buf, n_mem_addr_cells);
1109 memcell_buf += n_mem_addr_cells;
1110 size = of_read_number(memcell_buf, n_mem_size_cells);
1111 memcell_buf += n_mem_size_cells;
1113 max_addr = max_t(phys_addr_t, max_addr, start + size);
1120 * Platforms supporting the DDW option starting with LoPAR level 2.7 implement
1121 * ibm,ddw-extensions, which carries the rtas token for
1122 * ibm,reset-pe-dma-windows.
1123 * That rtas-call can be used to restore the default DMA window for the device.
1125 static void reset_dma_window(struct pci_dev *dev, struct device_node *par_dn)
1128 u32 cfg_addr, reset_dma_win;
1130 struct device_node *dn;
1133 ret = ddw_read_ext(par_dn, DDW_EXT_RESET_DMA_WIN, &reset_dma_win);
1137 dn = pci_device_to_OF_node(dev);
1139 buid = pdn->phb->buid;
1140 cfg_addr = (pdn->busno << 16) | (pdn->devfn << 8);
1142 ret = rtas_call(reset_dma_win, 3, 1, NULL, cfg_addr, BUID_HI(buid),
1146 "ibm,reset-pe-dma-windows(%x) %x %x %x returned %d ",
1147 reset_dma_win, cfg_addr, BUID_HI(buid), BUID_LO(buid),
1151 /* Return largest page shift based on "IO Page Sizes" output of ibm,query-pe-dma-window. */
1152 static int iommu_get_page_shift(u32 query_page_size)
1154 /* Supported IO page-sizes according to LoPAR, note that 2M is out of order */
1155 const int shift[] = {
1156 __builtin_ctzll(SZ_4K), __builtin_ctzll(SZ_64K), __builtin_ctzll(SZ_16M),
1157 __builtin_ctzll(SZ_32M), __builtin_ctzll(SZ_64M), __builtin_ctzll(SZ_128M),
1158 __builtin_ctzll(SZ_256M), __builtin_ctzll(SZ_16G), __builtin_ctzll(SZ_2M)
1161 int i = ARRAY_SIZE(shift) - 1;
1165 * On LoPAR, ibm,query-pe-dma-window outputs "IO Page Sizes" using a bit field:
1166 * - bit 31 means 4k pages are supported,
1167 * - bit 30 means 64k pages are supported, and so on.
1168 * Larger pagesizes map more memory with the same amount of TCEs, so start probing them.
1170 for (; i >= 0 ; i--) {
1171 if (query_page_size & (1 << i))
1172 ret = max(ret, shift[i]);
1178 static struct property *ddw_property_create(const char *propname, u32 liobn, u64 dma_addr,
1179 u32 page_shift, u32 window_shift)
1181 struct dynamic_dma_window_prop *ddwprop;
1182 struct property *win64;
1184 win64 = kzalloc(sizeof(*win64), GFP_KERNEL);
1188 win64->name = kstrdup(propname, GFP_KERNEL);
1189 ddwprop = kzalloc(sizeof(*ddwprop), GFP_KERNEL);
1190 win64->value = ddwprop;
1191 win64->length = sizeof(*ddwprop);
1192 if (!win64->name || !win64->value) {
1194 kfree(win64->value);
1199 ddwprop->liobn = cpu_to_be32(liobn);
1200 ddwprop->dma_base = cpu_to_be64(dma_addr);
1201 ddwprop->tce_shift = cpu_to_be32(page_shift);
1202 ddwprop->window_shift = cpu_to_be32(window_shift);
1208 * If the PE supports dynamic dma windows, and there is space for a table
1209 * that can map all pages in a linear offset, then setup such a table,
1210 * and record the dma-offset in the struct device.
1212 * dev: the pci device we are checking
1213 * pdn: the parent pe node with the ibm,dma_window property
1214 * Future: also check if we can remap the base window for our base page size
1216 * returns true if can map all pages (direct mapping), false otherwise..
1218 static bool enable_ddw(struct pci_dev *dev, struct device_node *pdn)
1221 int max_ram_len = order_base_2(ddw_memory_hotplug_max());
1222 struct ddw_query_response query;
1223 struct ddw_create_response create;
1226 const char *win_name;
1227 struct device_node *dn;
1228 u32 ddw_avail[DDW_APPLICABLE_SIZE];
1229 struct dma_win *window;
1230 struct property *win64;
1231 struct failed_ddw_pdn *fpdn;
1232 bool default_win_removed = false, direct_mapping = false;
1234 struct pci_dn *pci = PCI_DN(pdn);
1235 struct iommu_table *tbl = pci->table_group->tables[0];
1237 dn = of_find_node_by_type(NULL, "ibm,pmemory");
1238 pmem_present = dn != NULL;
1241 mutex_lock(&dma_win_init_mutex);
1243 if (find_existing_ddw(pdn, &dev->dev.archdata.dma_offset, &len)) {
1244 direct_mapping = (len >= max_ram_len);
1249 * If we already went through this for a previous function of
1250 * the same device and failed, we don't want to muck with the
1251 * DMA window again, as it will race with in-flight operations
1252 * and can lead to EEHs. The above mutex protects access to the
1255 list_for_each_entry(fpdn, &failed_ddw_pdn_list, list) {
1256 if (fpdn->pdn == pdn)
1261 * the ibm,ddw-applicable property holds the tokens for:
1262 * ibm,query-pe-dma-window
1263 * ibm,create-pe-dma-window
1264 * ibm,remove-pe-dma-window
1265 * for the given node in that order.
1266 * the property is actually in the parent, not the PE
1268 ret = of_property_read_u32_array(pdn, "ibm,ddw-applicable",
1269 &ddw_avail[0], DDW_APPLICABLE_SIZE);
1274 * Query if there is a second window of size to map the
1275 * whole partition. Query returns number of windows, largest
1276 * block assigned to PE (partition endpoint), and two bitmasks
1277 * of page sizes: supported and supported for migrate-dma.
1279 dn = pci_device_to_OF_node(dev);
1280 ret = query_ddw(dev, ddw_avail, &query, pdn);
1285 * If there is no window available, remove the default DMA window,
1286 * if it's present. This will make all the resources available to the
1288 * If anything fails after this, we need to restore it, so also check
1289 * for extensions presence.
1291 if (query.windows_available == 0) {
1292 struct property *default_win;
1295 /* DDW + IOMMU on single window may fail if there is any allocation */
1296 if (iommu_table_in_use(tbl)) {
1297 dev_warn(&dev->dev, "current IOMMU table in use, can't be replaced.\n");
1301 default_win = of_find_property(pdn, "ibm,dma-window", NULL);
1305 reset_win_ext = ddw_read_ext(pdn, DDW_EXT_RESET_DMA_WIN, NULL);
1309 remove_dma_window(pdn, ddw_avail, default_win);
1310 default_win_removed = true;
1312 /* Query again, to check if the window is available */
1313 ret = query_ddw(dev, ddw_avail, &query, pdn);
1317 if (query.windows_available == 0) {
1318 /* no windows are available for this device. */
1319 dev_dbg(&dev->dev, "no free dynamic windows");
1324 page_shift = iommu_get_page_shift(query.page_size);
1326 dev_dbg(&dev->dev, "no supported page size in mask %x",
1333 * The "ibm,pmemory" can appear anywhere in the address space.
1334 * Assuming it is still backed by page structs, try MAX_PHYSMEM_BITS
1335 * for the upper limit and fallback to max RAM otherwise but this
1336 * disables device::dma_ops_bypass.
1340 if (query.largest_available_block >=
1341 (1ULL << (MAX_PHYSMEM_BITS - page_shift)))
1342 len = MAX_PHYSMEM_BITS;
1344 dev_info(&dev->dev, "Skipping ibm,pmemory");
1347 /* check if the available block * number of ptes will map everything */
1348 if (query.largest_available_block < (1ULL << (len - page_shift))) {
1350 "can't map partition max 0x%llx with %llu %llu-sized pages\n",
1352 query.largest_available_block,
1353 1ULL << page_shift);
1355 len = order_base_2(query.largest_available_block << page_shift);
1356 win_name = DMA64_PROPNAME;
1358 direct_mapping = !default_win_removed ||
1359 (len == MAX_PHYSMEM_BITS) ||
1360 (!pmem_present && (len == max_ram_len));
1361 win_name = direct_mapping ? DIRECT64_PROPNAME : DMA64_PROPNAME;
1364 ret = create_ddw(dev, ddw_avail, &create, page_shift, len);
1368 dev_dbg(&dev->dev, "created tce table LIOBN 0x%x for %pOF\n",
1371 win_addr = ((u64)create.addr_hi << 32) | create.addr_lo;
1372 win64 = ddw_property_create(win_name, create.liobn, win_addr, page_shift, len);
1376 "couldn't allocate property, property name, or value\n");
1377 goto out_remove_win;
1380 ret = of_add_property(pdn, win64);
1382 dev_err(&dev->dev, "unable to add DMA window property for %pOF: %d",
1387 window = ddw_list_new_entry(pdn, win64->value);
1391 if (direct_mapping) {
1392 /* DDW maps the whole partition, so enable direct DMA mapping */
1393 ret = walk_system_ram_range(0, memblock_end_of_DRAM() >> PAGE_SHIFT,
1394 win64->value, tce_setrange_multi_pSeriesLP_walk);
1396 dev_info(&dev->dev, "failed to map DMA window for %pOF: %d\n",
1399 /* Make sure to clean DDW if any TCE was set*/
1400 clean_dma_window(pdn, win64->value);
1404 struct iommu_table *newtbl;
1406 unsigned long start = 0, end = 0;
1408 for (i = 0; i < ARRAY_SIZE(pci->phb->mem_resources); i++) {
1409 const unsigned long mask = IORESOURCE_MEM_64 | IORESOURCE_MEM;
1411 /* Look for MMIO32 */
1412 if ((pci->phb->mem_resources[i].flags & mask) == IORESOURCE_MEM) {
1413 start = pci->phb->mem_resources[i].start;
1414 end = pci->phb->mem_resources[i].end;
1419 /* New table for using DDW instead of the default DMA window */
1420 newtbl = iommu_pseries_alloc_table(pci->phb->node);
1422 dev_dbg(&dev->dev, "couldn't create new IOMMU table\n");
1426 iommu_table_setparms_common(newtbl, pci->phb->bus->number, create.liobn, win_addr,
1427 1UL << len, page_shift, NULL, &iommu_table_lpar_multi_ops);
1428 iommu_init_table(newtbl, pci->phb->node, start, end);
1430 pci->table_group->tables[1] = newtbl;
1432 /* Keep default DMA window struct if removed */
1433 if (default_win_removed) {
1439 set_iommu_table_base(&dev->dev, newtbl);
1442 spin_lock(&dma_win_list_lock);
1443 list_add(&window->list, &dma_win_list);
1444 spin_unlock(&dma_win_list_lock);
1446 dev->dev.archdata.dma_offset = win_addr;
1453 of_remove_property(pdn, win64);
1457 kfree(win64->value);
1461 /* DDW is clean, so it's ok to call this directly. */
1462 __remove_dma_window(pdn, ddw_avail, create.liobn);
1465 if (default_win_removed)
1466 reset_dma_window(dev, pdn);
1468 fpdn = kzalloc(sizeof(*fpdn), GFP_KERNEL);
1472 list_add(&fpdn->list, &failed_ddw_pdn_list);
1475 mutex_unlock(&dma_win_init_mutex);
1478 * If we have persistent memory and the window size is only as big
1479 * as RAM, then we failed to create a window to cover persistent
1480 * memory and need to set the DMA limit.
1482 if (pmem_present && direct_mapping && len == max_ram_len)
1483 dev->dev.bus_dma_limit = dev->dev.archdata.dma_offset + (1ULL << len);
1485 return direct_mapping;
1488 static void pci_dma_dev_setup_pSeriesLP(struct pci_dev *dev)
1490 struct device_node *pdn, *dn;
1491 struct iommu_table *tbl;
1492 const __be32 *dma_window = NULL;
1495 pr_debug("pci_dma_dev_setup_pSeriesLP: %s\n", pci_name(dev));
1497 /* dev setup for LPAR is a little tricky, since the device tree might
1498 * contain the dma-window properties per-device and not necessarily
1499 * for the bus. So we need to search upwards in the tree until we
1500 * either hit a dma-window property, OR find a parent with a table
1501 * already allocated.
1503 dn = pci_device_to_OF_node(dev);
1504 pr_debug(" node is %pOF\n", dn);
1506 for (pdn = dn; pdn && PCI_DN(pdn) && !PCI_DN(pdn)->table_group;
1507 pdn = pdn->parent) {
1508 dma_window = of_get_property(pdn, "ibm,dma-window", NULL);
1513 if (!pdn || !PCI_DN(pdn)) {
1514 printk(KERN_WARNING "pci_dma_dev_setup_pSeriesLP: "
1515 "no DMA window found for pci dev=%s dn=%pOF\n",
1519 pr_debug(" parent is %pOF\n", pdn);
1522 if (!pci->table_group) {
1523 pci->table_group = iommu_pseries_alloc_group(pci->phb->node);
1524 tbl = pci->table_group->tables[0];
1525 iommu_table_setparms_lpar(pci->phb, pdn, tbl,
1526 pci->table_group, dma_window);
1528 iommu_init_table(tbl, pci->phb->node, 0, 0);
1529 iommu_register_group(pci->table_group,
1530 pci_domain_nr(pci->phb->bus), 0);
1531 pr_debug(" created table: %p\n", pci->table_group);
1533 pr_debug(" found DMA window, table: %p\n", pci->table_group);
1536 set_iommu_table_base(&dev->dev, pci->table_group->tables[0]);
1537 iommu_add_device(pci->table_group, &dev->dev);
1540 static bool iommu_bypass_supported_pSeriesLP(struct pci_dev *pdev, u64 dma_mask)
1542 struct device_node *dn = pci_device_to_OF_node(pdev), *pdn;
1543 const __be32 *dma_window = NULL;
1545 /* only attempt to use a new window if 64-bit DMA is requested */
1546 if (dma_mask < DMA_BIT_MASK(64))
1549 dev_dbg(&pdev->dev, "node is %pOF\n", dn);
1552 * the device tree might contain the dma-window properties
1553 * per-device and not necessarily for the bus. So we need to
1554 * search upwards in the tree until we either hit a dma-window
1555 * property, OR find a parent with a table already allocated.
1557 for (pdn = dn; pdn && PCI_DN(pdn) && !PCI_DN(pdn)->table_group;
1558 pdn = pdn->parent) {
1559 dma_window = of_get_property(pdn, "ibm,dma-window", NULL);
1564 if (pdn && PCI_DN(pdn))
1565 return enable_ddw(pdev, pdn);
1570 static int iommu_mem_notifier(struct notifier_block *nb, unsigned long action,
1573 struct dma_win *window;
1574 struct memory_notify *arg = data;
1578 case MEM_GOING_ONLINE:
1579 spin_lock(&dma_win_list_lock);
1580 list_for_each_entry(window, &dma_win_list, list) {
1581 ret |= tce_setrange_multi_pSeriesLP(arg->start_pfn,
1582 arg->nr_pages, window->prop);
1585 spin_unlock(&dma_win_list_lock);
1587 case MEM_CANCEL_ONLINE:
1589 spin_lock(&dma_win_list_lock);
1590 list_for_each_entry(window, &dma_win_list, list) {
1591 ret |= tce_clearrange_multi_pSeriesLP(arg->start_pfn,
1592 arg->nr_pages, window->prop);
1595 spin_unlock(&dma_win_list_lock);
1600 if (ret && action != MEM_CANCEL_ONLINE)
1606 static struct notifier_block iommu_mem_nb = {
1607 .notifier_call = iommu_mem_notifier,
1610 static int iommu_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *data)
1612 int err = NOTIFY_OK;
1613 struct of_reconfig_data *rd = data;
1614 struct device_node *np = rd->dn;
1615 struct pci_dn *pci = PCI_DN(np);
1616 struct dma_win *window;
1619 case OF_RECONFIG_DETACH_NODE:
1621 * Removing the property will invoke the reconfig
1622 * notifier again, which causes dead-lock on the
1623 * read-write semaphore of the notifier chain. So
1624 * we have to remove the property when releasing
1627 if (remove_ddw(np, false, DIRECT64_PROPNAME))
1628 remove_ddw(np, false, DMA64_PROPNAME);
1630 if (pci && pci->table_group)
1631 iommu_pseries_free_group(pci->table_group,
1634 spin_lock(&dma_win_list_lock);
1635 list_for_each_entry(window, &dma_win_list, list) {
1636 if (window->device == np) {
1637 list_del(&window->list);
1642 spin_unlock(&dma_win_list_lock);
1651 static struct notifier_block iommu_reconfig_nb = {
1652 .notifier_call = iommu_reconfig_notifier,
1655 /* These are called very early. */
1656 void __init iommu_init_early_pSeries(void)
1658 if (of_chosen && of_get_property(of_chosen, "linux,iommu-off", NULL))
1661 if (firmware_has_feature(FW_FEATURE_LPAR)) {
1662 pseries_pci_controller_ops.dma_bus_setup = pci_dma_bus_setup_pSeriesLP;
1663 pseries_pci_controller_ops.dma_dev_setup = pci_dma_dev_setup_pSeriesLP;
1665 pseries_pci_controller_ops.iommu_bypass_supported =
1666 iommu_bypass_supported_pSeriesLP;
1668 pseries_pci_controller_ops.dma_bus_setup = pci_dma_bus_setup_pSeries;
1669 pseries_pci_controller_ops.dma_dev_setup = pci_dma_dev_setup_pSeries;
1673 of_reconfig_notifier_register(&iommu_reconfig_nb);
1674 register_memory_notifier(&iommu_mem_nb);
1676 set_pci_dma_ops(&dma_iommu_ops);
1679 static int __init disable_multitce(char *str)
1681 if (strcmp(str, "off") == 0 &&
1682 firmware_has_feature(FW_FEATURE_LPAR) &&
1683 (firmware_has_feature(FW_FEATURE_PUT_TCE_IND) ||
1684 firmware_has_feature(FW_FEATURE_STUFF_TCE))) {
1685 printk(KERN_INFO "Disabling MULTITCE firmware feature\n");
1686 powerpc_firmware_features &=
1687 ~(FW_FEATURE_PUT_TCE_IND | FW_FEATURE_STUFF_TCE);
1692 __setup("multitce=", disable_multitce);
1694 static int tce_iommu_bus_notifier(struct notifier_block *nb,
1695 unsigned long action, void *data)
1697 struct device *dev = data;
1700 case BUS_NOTIFY_DEL_DEVICE:
1701 iommu_del_device(dev);
1708 static struct notifier_block tce_iommu_bus_nb = {
1709 .notifier_call = tce_iommu_bus_notifier,
1712 static int __init tce_iommu_bus_notifier_init(void)
1714 bus_register_notifier(&pci_bus_type, &tce_iommu_bus_nb);
1717 machine_subsys_initcall_sync(pseries, tce_iommu_bus_notifier_init);