Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sparc: remove arch specific dma_supported implementations

Usually dma_supported decisions are done by the dma_map_ops instance.
Switch sparc to that model by providing a ->dma_supported instance for
sbus that always returns false, and implementations tailored to the sun4u
and sun4v cases for sparc64, and leave it unimplemented for PCI on
sparc32, which means always supported.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: David S. Miller <davem@davemloft.net>

+39 -43
-3
arch/sparc/include/asm/dma-mapping.h
··· 5 5 #include <linux/mm.h> 6 6 #include <linux/dma-debug.h> 7 7 8 - #define HAVE_ARCH_DMA_SUPPORTED 1 9 - int dma_supported(struct device *dev, u64 mask); 10 - 11 8 static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size, 12 9 enum dma_data_direction dir) 13 10 {
+16 -24
arch/sparc/kernel/iommu.c
··· 746 746 return dma_addr == SPARC_MAPPING_ERROR; 747 747 } 748 748 749 + static int dma_4u_supported(struct device *dev, u64 device_mask) 750 + { 751 + struct iommu *iommu = dev->archdata.iommu; 752 + 753 + if (device_mask > DMA_BIT_MASK(32)) 754 + return 0; 755 + if ((device_mask & iommu->dma_addr_mask) == iommu->dma_addr_mask) 756 + return 1; 757 + #ifdef CONFIG_PCI 758 + if (dev_is_pci(dev)) 759 + return pci64_dma_supported(to_pci_dev(dev), device_mask); 760 + #endif 761 + return 0; 762 + } 763 + 749 764 static const struct dma_map_ops sun4u_dma_ops = { 750 765 .alloc = dma_4u_alloc_coherent, 751 766 .free = dma_4u_free_coherent, ··· 770 755 .unmap_sg = dma_4u_unmap_sg, 771 756 .sync_single_for_cpu = dma_4u_sync_single_for_cpu, 772 757 .sync_sg_for_cpu = dma_4u_sync_sg_for_cpu, 758 + .dma_supported = dma_4u_supported, 773 759 .mapping_error = dma_4u_mapping_error, 774 760 }; 775 761 776 762 const struct dma_map_ops *dma_ops = &sun4u_dma_ops; 777 763 EXPORT_SYMBOL(dma_ops); 778 - 779 - int dma_supported(struct device *dev, u64 device_mask) 780 - { 781 - struct iommu *iommu = dev->archdata.iommu; 782 - u64 dma_addr_mask = iommu->dma_addr_mask; 783 - 784 - if (device_mask > DMA_BIT_MASK(32)) { 785 - if (iommu->atu) 786 - dma_addr_mask = iommu->atu->dma_addr_mask; 787 - else 788 - return 0; 789 - } 790 - 791 - if ((device_mask & dma_addr_mask) == dma_addr_mask) 792 - return 1; 793 - 794 - #ifdef CONFIG_PCI 795 - if (dev_is_pci(dev)) 796 - return pci64_dma_supported(to_pci_dev(dev), device_mask); 797 - #endif 798 - 799 - return 0; 800 - } 801 - EXPORT_SYMBOL(dma_supported);
+6 -16
arch/sparc/kernel/ioport.c
··· 401 401 BUG(); 402 402 } 403 403 404 + static int sbus_dma_supported(struct device *dev, u64 mask) 405 + { 406 + return 0; 407 + } 408 + 404 409 static const struct dma_map_ops sbus_dma_ops = { 405 410 .alloc = sbus_alloc_coherent, 406 411 .free = sbus_free_coherent, ··· 415 410 .unmap_sg = sbus_unmap_sg, 416 411 .sync_sg_for_cpu = sbus_sync_sg_for_cpu, 417 412 .sync_sg_for_device = sbus_sync_sg_for_device, 413 + .dma_supported = sbus_dma_supported, 418 414 }; 419 415 420 416 static int __init sparc_register_ioport(void) ··· 660 654 661 655 const struct dma_map_ops *dma_ops = &sbus_dma_ops; 662 656 EXPORT_SYMBOL(dma_ops); 663 - 664 - 665 - /* 666 - * Return whether the given PCI device DMA address mask can be 667 - * supported properly. For example, if your device can only drive the 668 - * low 24-bits during PCI bus mastering, then you would pass 669 - * 0x00ffffff as the mask to this function. 670 - */ 671 - int dma_supported(struct device *dev, u64 mask) 672 - { 673 - if (dev_is_pci(dev)) 674 - return 1; 675 - 676 - return 0; 677 - } 678 - EXPORT_SYMBOL(dma_supported); 679 657 680 658 #ifdef CONFIG_PROC_FS 681 659
+17
arch/sparc/kernel/pci_sun4v.c
··· 24 24 25 25 #include "pci_impl.h" 26 26 #include "iommu_common.h" 27 + #include "kernel.h" 27 28 28 29 #include "pci_sun4v.h" 29 30 ··· 670 669 local_irq_restore(flags); 671 670 } 672 671 672 + static int dma_4v_supported(struct device *dev, u64 device_mask) 673 + { 674 + struct iommu *iommu = dev->archdata.iommu; 675 + u64 dma_addr_mask; 676 + 677 + if (device_mask > DMA_BIT_MASK(32) && iommu->atu) 678 + dma_addr_mask = iommu->atu->dma_addr_mask; 679 + else 680 + dma_addr_mask = iommu->dma_addr_mask; 681 + 682 + if ((device_mask & dma_addr_mask) == dma_addr_mask) 683 + return 1; 684 + return pci64_dma_supported(to_pci_dev(dev), device_mask); 685 + } 686 + 673 687 static int dma_4v_mapping_error(struct device *dev, dma_addr_t dma_addr) 674 688 { 675 689 return dma_addr == SPARC_MAPPING_ERROR; ··· 697 681 .unmap_page = dma_4v_unmap_page, 698 682 .map_sg = dma_4v_map_sg, 699 683 .unmap_sg = dma_4v_unmap_sg, 684 + .dma_supported = dma_4v_supported, 700 685 .mapping_error = dma_4v_mapping_error, 701 686 }; 702 687