hc
2024-09-20 a36159eec6ca17402b0e146b86efaf76568dc353
kernel/drivers/parisc/sba_iommu.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 ** System Bus Adapter (SBA) I/O MMU manager
34 **
....@@ -7,10 +8,6 @@
78 **
89 ** Portions (c) 1999 Dave S. Miller (from sparc64 I/O MMU code)
910 **
10
-** This program is free software; you can redistribute it and/or modify
11
-** it under the terms of the GNU General Public License as published by
12
-** the Free Software Foundation; either version 2 of the License, or
13
-** (at your option) any later version.
1411 **
1512 **
1613 ** This module initializes the IOC (I/O Controller) found on B1000/C3000/
....@@ -28,6 +25,7 @@
2825 #include <linux/mm.h>
2926 #include <linux/string.h>
3027 #include <linux/pci.h>
28
+#include <linux/dma-map-ops.h>
3129 #include <linux/scatterlist.h>
3230 #include <linux/iommu-helper.h>
3331
....@@ -48,6 +46,8 @@
4846 #include <asm/pdc.h> /* for PDC_MODEL_* */
4947 #include <asm/pdcpat.h> /* for is_pdc_pat() */
5048 #include <asm/parisc-device.h>
49
+
50
+#include "iommu.h"
5151
5252 #define MODULE_NAME "SBA"
5353
....@@ -92,8 +92,6 @@
9292 #define SBA_INLINE __inline__
9393
9494 #define DEFAULT_DMA_HINT_REG 0
95
-
96
-#define SBA_MAPPING_ERROR (~(dma_addr_t)0)
9795
9896 struct sba_device *sba_list;
9997 EXPORT_SYMBOL_GPL(sba_list);
....@@ -345,8 +343,7 @@
345343 unsigned long shift;
346344 int ret;
347345
348
- boundary_size = ALIGN((unsigned long long)dma_get_seg_boundary(dev) + 1,
349
- 1ULL << IOVP_SHIFT) >> IOVP_SHIFT;
346
+ boundary_size = dma_get_seg_boundary_nr_pages(dev, IOVP_SHIFT);
350347
351348 #if defined(ZX1_SUPPORT)
352349 BUG_ON(ioc->ibase & ~IOVP_MASK);
....@@ -572,7 +569,7 @@
572569 u64 pa; /* physical address */
573570 register unsigned ci; /* coherent index */
574571
575
- pa = virt_to_phys(vba);
572
+ pa = lpa(vba);
576573 pa &= IOVP_MASK;
577574
578575 asm("lci 0(%1), %0" : "=r" (ci) : "r" (vba));
....@@ -586,8 +583,7 @@
586583 * (bit #61, big endian), we have to flush and sync every time
587584 * IO-PDIR is changed in Ike/Astro.
588585 */
589
- if (ioc_needs_fdc)
590
- asm volatile("fdc %%r0(%0)" : : "r" (pdir_ptr));
586
+ asm_io_fdc(pdir_ptr);
591587 }
592588
593589
....@@ -640,8 +636,8 @@
640636 do {
641637 /* clear I/O Pdir entry "valid" bit first */
642638 ((u8 *) pdir_ptr)[7] = 0;
639
+ asm_io_fdc(pdir_ptr);
643640 if (ioc_needs_fdc) {
644
- asm volatile("fdc %%r0(%0)" : : "r" (pdir_ptr));
645641 #if 0
646642 entries_per_cacheline = L1_CACHE_SHIFT - 3;
647643 #endif
....@@ -660,8 +656,7 @@
660656 ** could dump core on HPMC.
661657 */
662658 ((u8 *) pdir_ptr)[7] = 0;
663
- if (ioc_needs_fdc)
664
- asm volatile("fdc %%r0(%0)" : : "r" (pdir_ptr));
659
+ asm_io_fdc(pdir_ptr);
665660
666661 WRITE_REG( SBA_IOVA(ioc, iovp, 0, 0), ioc->ioc_hpa+IOC_PCOM);
667662 }
....@@ -671,7 +666,7 @@
671666 * @dev: instance of PCI owned by the driver that's asking
672667 * @mask: number of address bits this PCI device can handle
673668 *
674
- * See Documentation/DMA-API-HOWTO.txt
669
+ * See Documentation/core-api/dma-api-howto.rst
675670 */
676671 static int sba_dma_supported( struct device *dev, u64 mask)
677672 {
....@@ -682,14 +677,6 @@
682677 BUG();
683678 return(0);
684679 }
685
-
686
- /* Documentation/DMA-API-HOWTO.txt tells drivers to try 64-bit
687
- * first, then fall back to 32-bit if that fails.
688
- * We are just "encouraging" 32-bit DMA masks here since we can
689
- * never allow IOMMU bypass unless we add special support for ZX1.
690
- */
691
- if (mask > ~0U)
692
- return 0;
693680
694681 ioc = GET_IOC(dev);
695682 if (!ioc)
....@@ -711,7 +698,7 @@
711698 * @size: number of bytes to map in driver buffer.
712699 * @direction: R/W or both.
713700 *
714
- * See Documentation/DMA-API-HOWTO.txt
701
+ * See Documentation/core-api/dma-api-howto.rst
715702 */
716703 static dma_addr_t
717704 sba_map_single(struct device *dev, void *addr, size_t size,
....@@ -726,7 +713,7 @@
726713
727714 ioc = GET_IOC(dev);
728715 if (!ioc)
729
- return SBA_MAPPING_ERROR;
716
+ return DMA_MAPPING_ERROR;
730717
731718 /* save offset bits */
732719 offset = ((dma_addr_t) (long) addr) & ~IOVP_MASK;
....@@ -772,8 +759,7 @@
772759 }
773760
774761 /* force FDC ops in io_pdir_entry() to be visible to IOMMU */
775
- if (ioc_needs_fdc)
776
- asm volatile("sync" : : );
762
+ asm_io_sync();
777763
778764 #ifdef ASSERT_PDIR_SANITY
779765 sba_check_pdir(ioc,"Check after sba_map_single()");
....@@ -802,7 +788,7 @@
802788 * @size: number of bytes mapped in driver buffer.
803789 * @direction: R/W or both.
804790 *
805
- * See Documentation/DMA-API-HOWTO.txt
791
+ * See Documentation/core-api/dma-api-howto.rst
806792 */
807793 static void
808794 sba_unmap_page(struct device *dev, dma_addr_t iova, size_t size,
....@@ -857,8 +843,7 @@
857843 sba_free_range(ioc, iova, size);
858844
859845 /* If fdc's were issued, force fdc's to be visible now */
860
- if (ioc_needs_fdc)
861
- asm volatile("sync" : : );
846
+ asm_io_sync();
862847
863848 READ_REG(ioc->ioc_hpa+IOC_PCOM); /* flush purges */
864849 #endif /* DELAYED_RESOURCE_CNT == 0 */
....@@ -882,7 +867,7 @@
882867 * @size: number of bytes mapped in driver buffer.
883868 * @dma_handle: IOVA of new buffer.
884869 *
885
- * See Documentation/DMA-API-HOWTO.txt
870
+ * See Documentation/core-api/dma-api-howto.rst
886871 */
887872 static void *sba_alloc(struct device *hwdev, size_t size, dma_addr_t *dma_handle,
888873 gfp_t gfp, unsigned long attrs)
....@@ -913,7 +898,7 @@
913898 * @vaddr: virtual address IOVA of "consistent" buffer.
914899 * @dma_handler: IO virtual address of "consistent" buffer.
915900 *
916
- * See Documentation/DMA-API-HOWTO.txt
901
+ * See Documentation/core-api/dma-api-howto.rst
917902 */
918903 static void
919904 sba_free(struct device *hwdev, size_t size, void *vaddr,
....@@ -948,7 +933,7 @@
948933 * @nents: number of entries in list
949934 * @direction: R/W or both.
950935 *
951
- * See Documentation/DMA-API-HOWTO.txt
936
+ * See Documentation/core-api/dma-api-howto.rst
952937 */
953938 static int
954939 sba_map_sg(struct device *dev, struct scatterlist *sglist, int nents,
....@@ -1007,8 +992,7 @@
1007992 filled = iommu_fill_pdir(ioc, sglist, nents, 0, sba_io_pdir_entry);
1008993
1009994 /* force FDC ops in io_pdir_entry() to be visible to IOMMU */
1010
- if (ioc_needs_fdc)
1011
- asm volatile("sync" : : );
995
+ asm_io_sync();
1012996
1013997 #ifdef ASSERT_PDIR_SANITY
1014998 if (sba_check_pdir(ioc,"Check after sba_map_sg()"))
....@@ -1033,7 +1017,7 @@
10331017 * @nents: number of entries in list
10341018 * @direction: R/W or both.
10351019 *
1036
- * See Documentation/DMA-API-HOWTO.txt
1020
+ * See Documentation/core-api/dma-api-howto.rst
10371021 */
10381022 static void
10391023 sba_unmap_sg(struct device *dev, struct scatterlist *sglist, int nents,
....@@ -1085,11 +1069,6 @@
10851069
10861070 }
10871071
1088
-static int sba_mapping_error(struct device *dev, dma_addr_t dma_addr)
1089
-{
1090
- return dma_addr == SBA_MAPPING_ERROR;
1091
-}
1092
-
10931072 static const struct dma_map_ops sba_ops = {
10941073 .dma_supported = sba_dma_supported,
10951074 .alloc = sba_alloc,
....@@ -1098,7 +1077,9 @@
10981077 .unmap_page = sba_unmap_page,
10991078 .map_sg = sba_map_sg,
11001079 .unmap_sg = sba_unmap_sg,
1101
- .mapping_error = sba_mapping_error,
1080
+ .get_sgtable = dma_common_get_sgtable,
1081
+ .alloc_pages = dma_common_alloc_pages,
1082
+ .free_pages = dma_common_free_pages,
11021083 };
11031084
11041085
....@@ -1419,7 +1400,7 @@
14191400 ** for DMA hints - ergo only 30 bits max.
14201401 */
14211402
1422
- iova_space_size = (u32) (totalram_pages/global_ioc_cnt);
1403
+ iova_space_size = (u32) (totalram_pages()/global_ioc_cnt);
14231404
14241405 /* limit IOVA space size to 1MB-1GB */
14251406 if (iova_space_size < (1 << (20 - PAGE_SHIFT))) {
....@@ -1444,7 +1425,7 @@
14441425 DBG_INIT("%s() hpa 0x%lx mem %ldMB IOV %dMB (%d bits)\n",
14451426 __func__,
14461427 ioc->ioc_hpa,
1447
- (unsigned long) totalram_pages >> (20 - PAGE_SHIFT),
1428
+ (unsigned long) totalram_pages() >> (20 - PAGE_SHIFT),
14481429 iova_space_size>>20,
14491430 iov_order + PAGE_SHIFT);
14501431
....@@ -1535,7 +1516,7 @@
15351516
15361517 static void __iomem *ioc_remap(struct sba_device *sba_dev, unsigned int offset)
15371518 {
1538
- return ioremap_nocache(sba_dev->dev->hpa.start + offset, SBA_FUNC_SIZE);
1519
+ return ioremap(sba_dev->dev->hpa.start + offset, SBA_FUNC_SIZE);
15391520 }
15401521
15411522 static void sba_hw_init(struct sba_device *sba_dev)
....@@ -1905,7 +1886,7 @@
19051886 u32 func_class;
19061887 int i;
19071888 char *version;
1908
- void __iomem *sba_addr = ioremap_nocache(dev->hpa.start, SBA_FUNC_SIZE);
1889
+ void __iomem *sba_addr = ioremap(dev->hpa.start, SBA_FUNC_SIZE);
19091890 #ifdef CONFIG_PROC_FS
19101891 struct proc_dir_entry *root;
19111892 #endif