hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/arch/sparc/kernel/pci_sun4v.c
....@@ -16,6 +16,7 @@
1616 #include <linux/export.h>
1717 #include <linux/log2.h>
1818 #include <linux/of_device.h>
19
+#include <linux/dma-map-ops.h>
1920 #include <asm/iommu-common.h>
2021
2122 #include <asm/iommu.h>
....@@ -73,6 +74,11 @@
7374 p->npages = 0;
7475 }
7576
77
+static inline bool iommu_use_atu(struct iommu *iommu, u64 mask)
78
+{
79
+ return iommu->atu && mask > DMA_BIT_MASK(32);
80
+}
81
+
7682 /* Interrupts must be disabled. */
7783 static long iommu_batch_flush(struct iommu_batch *p, u64 mask)
7884 {
....@@ -92,7 +98,7 @@
9298 prot &= (HV_PCI_MAP_ATTR_READ | HV_PCI_MAP_ATTR_WRITE);
9399
94100 while (npages != 0) {
95
- if (mask <= DMA_BIT_MASK(32)) {
101
+ if (!iommu_use_atu(pbm->iommu, mask)) {
96102 num = pci_sun4v_iommu_map(devhandle,
97103 HV_PCI_TSBID(0, entry),
98104 npages,
....@@ -179,7 +185,6 @@
179185 unsigned long flags, order, first_page, npages, n;
180186 unsigned long prot = 0;
181187 struct iommu *iommu;
182
- struct atu *atu;
183188 struct iommu_map_table *tbl;
184189 struct page *page;
185190 void *ret;
....@@ -205,13 +210,11 @@
205210 memset((char *)first_page, 0, PAGE_SIZE << order);
206211
207212 iommu = dev->archdata.iommu;
208
- atu = iommu->atu;
209
-
210213 mask = dev->coherent_dma_mask;
211
- if (mask <= DMA_BIT_MASK(32))
214
+ if (!iommu_use_atu(iommu, mask))
212215 tbl = &iommu->tbl;
213216 else
214
- tbl = &atu->tbl;
217
+ tbl = &iommu->atu->tbl;
215218
216219 entry = iommu_tbl_range_alloc(dev, tbl, npages, NULL,
217220 (unsigned long)(-1), 0);
....@@ -333,7 +336,7 @@
333336 atu = iommu->atu;
334337 devhandle = pbm->devhandle;
335338
336
- if (dvma <= DMA_BIT_MASK(32)) {
339
+ if (!iommu_use_atu(iommu, dvma)) {
337340 tbl = &iommu->tbl;
338341 iotsb_num = 0; /* we don't care for legacy iommu */
339342 } else {
....@@ -374,7 +377,7 @@
374377 npages >>= IO_PAGE_SHIFT;
375378
376379 mask = *dev->dma_mask;
377
- if (mask <= DMA_BIT_MASK(32))
380
+ if (!iommu_use_atu(iommu, mask))
378381 tbl = &iommu->tbl;
379382 else
380383 tbl = &atu->tbl;
....@@ -414,12 +417,12 @@
414417 bad:
415418 if (printk_ratelimit())
416419 WARN_ON(1);
417
- return SPARC_MAPPING_ERROR;
420
+ return DMA_MAPPING_ERROR;
418421
419422 iommu_map_fail:
420423 local_irq_restore(flags);
421424 iommu_tbl_range_free(tbl, bus_addr, npages, IOMMU_ERROR_CODE);
422
- return SPARC_MAPPING_ERROR;
425
+ return DMA_MAPPING_ERROR;
423426 }
424427
425428 static void dma_4v_unmap_page(struct device *dev, dma_addr_t bus_addr,
....@@ -506,11 +509,10 @@
506509 iommu_batch_start(dev, prot, ~0UL);
507510
508511 max_seg_size = dma_get_max_seg_size(dev);
509
- seg_boundary_size = ALIGN(dma_get_seg_boundary(dev) + 1,
510
- IO_PAGE_SIZE) >> IO_PAGE_SHIFT;
512
+ seg_boundary_size = dma_get_seg_boundary_nr_pages(dev, IO_PAGE_SHIFT);
511513
512514 mask = *dev->dma_mask;
513
- if (mask <= DMA_BIT_MASK(32))
515
+ if (!iommu_use_atu(iommu, mask))
514516 tbl = &iommu->tbl;
515517 else
516518 tbl = &atu->tbl;
....@@ -592,7 +594,7 @@
592594
593595 if (outcount < incount) {
594596 outs = sg_next(outs);
595
- outs->dma_address = SPARC_MAPPING_ERROR;
597
+ outs->dma_address = DMA_MAPPING_ERROR;
596598 outs->dma_length = 0;
597599 }
598600
....@@ -609,7 +611,7 @@
609611 iommu_tbl_range_free(tbl, vaddr, npages,
610612 IOMMU_ERROR_CODE);
611613 /* XXX demap? XXX */
612
- s->dma_address = SPARC_MAPPING_ERROR;
614
+ s->dma_address = DMA_MAPPING_ERROR;
613615 s->dma_length = 0;
614616 }
615617 if (s == outs)
....@@ -674,23 +676,12 @@
674676 static int dma_4v_supported(struct device *dev, u64 device_mask)
675677 {
676678 struct iommu *iommu = dev->archdata.iommu;
677
- u64 dma_addr_mask = iommu->dma_addr_mask;
678679
679
- if (device_mask > DMA_BIT_MASK(32)) {
680
- if (iommu->atu)
681
- dma_addr_mask = iommu->atu->dma_addr_mask;
682
- else
683
- return 0;
684
- }
685
-
686
- if ((device_mask & dma_addr_mask) == dma_addr_mask)
680
+ if (ali_sound_dma_hack(dev, device_mask))
687681 return 1;
688
- return pci64_dma_supported(to_pci_dev(dev), device_mask);
689
-}
690
-
691
-static int dma_4v_mapping_error(struct device *dev, dma_addr_t dma_addr)
692
-{
693
- return dma_addr == SPARC_MAPPING_ERROR;
682
+ if (device_mask < iommu->dma_addr_mask)
683
+ return 0;
684
+ return 1;
694685 }
695686
696687 static const struct dma_map_ops sun4v_dma_ops = {
....@@ -701,7 +692,6 @@
701692 .map_sg = dma_4v_map_sg,
702693 .unmap_sg = dma_4v_unmap_sg,
703694 .dma_supported = dma_4v_supported,
704
- .mapping_error = dma_4v_mapping_error,
705695 };
706696
707697 static void pci_sun4v_scan_bus(struct pci_pbm_info *pbm, struct device *parent)