.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | ** System Bus Adapter (SBA) I/O MMU manager |
---|
3 | 4 | ** |
---|
.. | .. |
---|
7 | 8 | ** |
---|
8 | 9 | ** Portions (c) 1999 Dave S. Miller (from sparc64 I/O MMU code) |
---|
9 | 10 | ** |
---|
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. |
---|
14 | 11 | ** |
---|
15 | 12 | ** |
---|
16 | 13 | ** This module initializes the IOC (I/O Controller) found on B1000/C3000/ |
---|
.. | .. |
---|
28 | 25 | #include <linux/mm.h> |
---|
29 | 26 | #include <linux/string.h> |
---|
30 | 27 | #include <linux/pci.h> |
---|
| 28 | +#include <linux/dma-map-ops.h> |
---|
31 | 29 | #include <linux/scatterlist.h> |
---|
32 | 30 | #include <linux/iommu-helper.h> |
---|
33 | 31 | |
---|
.. | .. |
---|
48 | 46 | #include <asm/pdc.h> /* for PDC_MODEL_* */ |
---|
49 | 47 | #include <asm/pdcpat.h> /* for is_pdc_pat() */ |
---|
50 | 48 | #include <asm/parisc-device.h> |
---|
| 49 | + |
---|
| 50 | +#include "iommu.h" |
---|
51 | 51 | |
---|
52 | 52 | #define MODULE_NAME "SBA" |
---|
53 | 53 | |
---|
.. | .. |
---|
92 | 92 | #define SBA_INLINE __inline__ |
---|
93 | 93 | |
---|
94 | 94 | #define DEFAULT_DMA_HINT_REG 0 |
---|
95 | | - |
---|
96 | | -#define SBA_MAPPING_ERROR (~(dma_addr_t)0) |
---|
97 | 95 | |
---|
98 | 96 | struct sba_device *sba_list; |
---|
99 | 97 | EXPORT_SYMBOL_GPL(sba_list); |
---|
.. | .. |
---|
345 | 343 | unsigned long shift; |
---|
346 | 344 | int ret; |
---|
347 | 345 | |
---|
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); |
---|
350 | 347 | |
---|
351 | 348 | #if defined(ZX1_SUPPORT) |
---|
352 | 349 | BUG_ON(ioc->ibase & ~IOVP_MASK); |
---|
.. | .. |
---|
572 | 569 | u64 pa; /* physical address */ |
---|
573 | 570 | register unsigned ci; /* coherent index */ |
---|
574 | 571 | |
---|
575 | | - pa = virt_to_phys(vba); |
---|
| 572 | + pa = lpa(vba); |
---|
576 | 573 | pa &= IOVP_MASK; |
---|
577 | 574 | |
---|
578 | 575 | asm("lci 0(%1), %0" : "=r" (ci) : "r" (vba)); |
---|
.. | .. |
---|
586 | 583 | * (bit #61, big endian), we have to flush and sync every time |
---|
587 | 584 | * IO-PDIR is changed in Ike/Astro. |
---|
588 | 585 | */ |
---|
589 | | - if (ioc_needs_fdc) |
---|
590 | | - asm volatile("fdc %%r0(%0)" : : "r" (pdir_ptr)); |
---|
| 586 | + asm_io_fdc(pdir_ptr); |
---|
591 | 587 | } |
---|
592 | 588 | |
---|
593 | 589 | |
---|
.. | .. |
---|
640 | 636 | do { |
---|
641 | 637 | /* clear I/O Pdir entry "valid" bit first */ |
---|
642 | 638 | ((u8 *) pdir_ptr)[7] = 0; |
---|
| 639 | + asm_io_fdc(pdir_ptr); |
---|
643 | 640 | if (ioc_needs_fdc) { |
---|
644 | | - asm volatile("fdc %%r0(%0)" : : "r" (pdir_ptr)); |
---|
645 | 641 | #if 0 |
---|
646 | 642 | entries_per_cacheline = L1_CACHE_SHIFT - 3; |
---|
647 | 643 | #endif |
---|
.. | .. |
---|
660 | 656 | ** could dump core on HPMC. |
---|
661 | 657 | */ |
---|
662 | 658 | ((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); |
---|
665 | 660 | |
---|
666 | 661 | WRITE_REG( SBA_IOVA(ioc, iovp, 0, 0), ioc->ioc_hpa+IOC_PCOM); |
---|
667 | 662 | } |
---|
.. | .. |
---|
671 | 666 | * @dev: instance of PCI owned by the driver that's asking |
---|
672 | 667 | * @mask: number of address bits this PCI device can handle |
---|
673 | 668 | * |
---|
674 | | - * See Documentation/DMA-API-HOWTO.txt |
---|
| 669 | + * See Documentation/core-api/dma-api-howto.rst |
---|
675 | 670 | */ |
---|
676 | 671 | static int sba_dma_supported( struct device *dev, u64 mask) |
---|
677 | 672 | { |
---|
.. | .. |
---|
682 | 677 | BUG(); |
---|
683 | 678 | return(0); |
---|
684 | 679 | } |
---|
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; |
---|
693 | 680 | |
---|
694 | 681 | ioc = GET_IOC(dev); |
---|
695 | 682 | if (!ioc) |
---|
.. | .. |
---|
711 | 698 | * @size: number of bytes to map in driver buffer. |
---|
712 | 699 | * @direction: R/W or both. |
---|
713 | 700 | * |
---|
714 | | - * See Documentation/DMA-API-HOWTO.txt |
---|
| 701 | + * See Documentation/core-api/dma-api-howto.rst |
---|
715 | 702 | */ |
---|
716 | 703 | static dma_addr_t |
---|
717 | 704 | sba_map_single(struct device *dev, void *addr, size_t size, |
---|
.. | .. |
---|
726 | 713 | |
---|
727 | 714 | ioc = GET_IOC(dev); |
---|
728 | 715 | if (!ioc) |
---|
729 | | - return SBA_MAPPING_ERROR; |
---|
| 716 | + return DMA_MAPPING_ERROR; |
---|
730 | 717 | |
---|
731 | 718 | /* save offset bits */ |
---|
732 | 719 | offset = ((dma_addr_t) (long) addr) & ~IOVP_MASK; |
---|
.. | .. |
---|
772 | 759 | } |
---|
773 | 760 | |
---|
774 | 761 | /* 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(); |
---|
777 | 763 | |
---|
778 | 764 | #ifdef ASSERT_PDIR_SANITY |
---|
779 | 765 | sba_check_pdir(ioc,"Check after sba_map_single()"); |
---|
.. | .. |
---|
802 | 788 | * @size: number of bytes mapped in driver buffer. |
---|
803 | 789 | * @direction: R/W or both. |
---|
804 | 790 | * |
---|
805 | | - * See Documentation/DMA-API-HOWTO.txt |
---|
| 791 | + * See Documentation/core-api/dma-api-howto.rst |
---|
806 | 792 | */ |
---|
807 | 793 | static void |
---|
808 | 794 | sba_unmap_page(struct device *dev, dma_addr_t iova, size_t size, |
---|
.. | .. |
---|
857 | 843 | sba_free_range(ioc, iova, size); |
---|
858 | 844 | |
---|
859 | 845 | /* 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(); |
---|
862 | 847 | |
---|
863 | 848 | READ_REG(ioc->ioc_hpa+IOC_PCOM); /* flush purges */ |
---|
864 | 849 | #endif /* DELAYED_RESOURCE_CNT == 0 */ |
---|
.. | .. |
---|
882 | 867 | * @size: number of bytes mapped in driver buffer. |
---|
883 | 868 | * @dma_handle: IOVA of new buffer. |
---|
884 | 869 | * |
---|
885 | | - * See Documentation/DMA-API-HOWTO.txt |
---|
| 870 | + * See Documentation/core-api/dma-api-howto.rst |
---|
886 | 871 | */ |
---|
887 | 872 | static void *sba_alloc(struct device *hwdev, size_t size, dma_addr_t *dma_handle, |
---|
888 | 873 | gfp_t gfp, unsigned long attrs) |
---|
.. | .. |
---|
913 | 898 | * @vaddr: virtual address IOVA of "consistent" buffer. |
---|
914 | 899 | * @dma_handler: IO virtual address of "consistent" buffer. |
---|
915 | 900 | * |
---|
916 | | - * See Documentation/DMA-API-HOWTO.txt |
---|
| 901 | + * See Documentation/core-api/dma-api-howto.rst |
---|
917 | 902 | */ |
---|
918 | 903 | static void |
---|
919 | 904 | sba_free(struct device *hwdev, size_t size, void *vaddr, |
---|
.. | .. |
---|
948 | 933 | * @nents: number of entries in list |
---|
949 | 934 | * @direction: R/W or both. |
---|
950 | 935 | * |
---|
951 | | - * See Documentation/DMA-API-HOWTO.txt |
---|
| 936 | + * See Documentation/core-api/dma-api-howto.rst |
---|
952 | 937 | */ |
---|
953 | 938 | static int |
---|
954 | 939 | sba_map_sg(struct device *dev, struct scatterlist *sglist, int nents, |
---|
.. | .. |
---|
1007 | 992 | filled = iommu_fill_pdir(ioc, sglist, nents, 0, sba_io_pdir_entry); |
---|
1008 | 993 | |
---|
1009 | 994 | /* 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(); |
---|
1012 | 996 | |
---|
1013 | 997 | #ifdef ASSERT_PDIR_SANITY |
---|
1014 | 998 | if (sba_check_pdir(ioc,"Check after sba_map_sg()")) |
---|
.. | .. |
---|
1033 | 1017 | * @nents: number of entries in list |
---|
1034 | 1018 | * @direction: R/W or both. |
---|
1035 | 1019 | * |
---|
1036 | | - * See Documentation/DMA-API-HOWTO.txt |
---|
| 1020 | + * See Documentation/core-api/dma-api-howto.rst |
---|
1037 | 1021 | */ |
---|
1038 | 1022 | static void |
---|
1039 | 1023 | sba_unmap_sg(struct device *dev, struct scatterlist *sglist, int nents, |
---|
.. | .. |
---|
1085 | 1069 | |
---|
1086 | 1070 | } |
---|
1087 | 1071 | |
---|
1088 | | -static int sba_mapping_error(struct device *dev, dma_addr_t dma_addr) |
---|
1089 | | -{ |
---|
1090 | | - return dma_addr == SBA_MAPPING_ERROR; |
---|
1091 | | -} |
---|
1092 | | - |
---|
1093 | 1072 | static const struct dma_map_ops sba_ops = { |
---|
1094 | 1073 | .dma_supported = sba_dma_supported, |
---|
1095 | 1074 | .alloc = sba_alloc, |
---|
.. | .. |
---|
1098 | 1077 | .unmap_page = sba_unmap_page, |
---|
1099 | 1078 | .map_sg = sba_map_sg, |
---|
1100 | 1079 | .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, |
---|
1102 | 1083 | }; |
---|
1103 | 1084 | |
---|
1104 | 1085 | |
---|
.. | .. |
---|
1419 | 1400 | ** for DMA hints - ergo only 30 bits max. |
---|
1420 | 1401 | */ |
---|
1421 | 1402 | |
---|
1422 | | - iova_space_size = (u32) (totalram_pages/global_ioc_cnt); |
---|
| 1403 | + iova_space_size = (u32) (totalram_pages()/global_ioc_cnt); |
---|
1423 | 1404 | |
---|
1424 | 1405 | /* limit IOVA space size to 1MB-1GB */ |
---|
1425 | 1406 | if (iova_space_size < (1 << (20 - PAGE_SHIFT))) { |
---|
.. | .. |
---|
1444 | 1425 | DBG_INIT("%s() hpa 0x%lx mem %ldMB IOV %dMB (%d bits)\n", |
---|
1445 | 1426 | __func__, |
---|
1446 | 1427 | ioc->ioc_hpa, |
---|
1447 | | - (unsigned long) totalram_pages >> (20 - PAGE_SHIFT), |
---|
| 1428 | + (unsigned long) totalram_pages() >> (20 - PAGE_SHIFT), |
---|
1448 | 1429 | iova_space_size>>20, |
---|
1449 | 1430 | iov_order + PAGE_SHIFT); |
---|
1450 | 1431 | |
---|
.. | .. |
---|
1535 | 1516 | |
---|
1536 | 1517 | static void __iomem *ioc_remap(struct sba_device *sba_dev, unsigned int offset) |
---|
1537 | 1518 | { |
---|
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); |
---|
1539 | 1520 | } |
---|
1540 | 1521 | |
---|
1541 | 1522 | static void sba_hw_init(struct sba_device *sba_dev) |
---|
.. | .. |
---|
1905 | 1886 | u32 func_class; |
---|
1906 | 1887 | int i; |
---|
1907 | 1888 | 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); |
---|
1909 | 1890 | #ifdef CONFIG_PROC_FS |
---|
1910 | 1891 | struct proc_dir_entry *root; |
---|
1911 | 1892 | #endif |
---|