341-MIPS-mm-remove-no-op-dma_map_ops-where-possible.patch 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. From: Felix Fietkau <nbd@nbd.name>
  2. Date: Tue, 5 Dec 2017 12:46:01 +0100
  3. Subject: [PATCH] MIPS: mm: remove no-op dma_map_ops where possible
  4. If no post-DMA flush is required, and the platform does not provide
  5. plat_unmap_dma_mem(), there is no need to include unmap or sync_for_cpu
  6. ops.
  7. With this patch they are compiled out to improve icache footprint
  8. on devices that handle lots of DMA traffic (especially network routers).
  9. Signed-off-by: Felix Fietkau <nbd@nbd.name>
  10. ---
  11. --- a/arch/mips/Kconfig
  12. +++ b/arch/mips/Kconfig
  13. @@ -221,6 +221,7 @@ config BMIPS_GENERIC
  14. select BRCMSTB_L2_IRQ
  15. select IRQ_MIPS_CPU
  16. select DMA_NONCOHERENT
  17. + select DMA_UNMAP_POST_FLUSH
  18. select SYS_SUPPORTS_32BIT_KERNEL
  19. select SYS_SUPPORTS_LITTLE_ENDIAN
  20. select SYS_SUPPORTS_BIG_ENDIAN
  21. @@ -346,6 +347,7 @@ config MACH_JAZZ
  22. select CSRC_R4K
  23. select DEFAULT_SGI_PARTITION if CPU_BIG_ENDIAN
  24. select GENERIC_ISA_DMA
  25. + select DMA_UNMAP_POST_FLUSH
  26. select HAVE_PCSPKR_PLATFORM
  27. select IRQ_MIPS_CPU
  28. select I8253
  29. @@ -1128,6 +1130,9 @@ config DMA_NONCOHERENT
  30. bool
  31. select NEED_DMA_MAP_STATE
  32. +config DMA_UNMAP_POST_FLUSH
  33. + bool
  34. +
  35. config NEED_DMA_MAP_STATE
  36. bool
  37. @@ -1652,6 +1657,7 @@ config CPU_R10000
  38. select CPU_SUPPORTS_64BIT_KERNEL
  39. select CPU_SUPPORTS_HIGHMEM
  40. select CPU_SUPPORTS_HUGEPAGES
  41. + select DMA_UNMAP_POST_FLUSH
  42. help
  43. MIPS Technologies R10000-series processors.
  44. @@ -1900,9 +1906,11 @@ config SYS_HAS_CPU_MIPS32_R3_5
  45. bool
  46. config SYS_HAS_CPU_MIPS32_R5
  47. + select DMA_UNMAP_POST_FLUSH
  48. bool
  49. config SYS_HAS_CPU_MIPS32_R6
  50. + select DMA_UNMAP_POST_FLUSH
  51. bool
  52. config SYS_HAS_CPU_MIPS64_R1
  53. @@ -1912,6 +1920,7 @@ config SYS_HAS_CPU_MIPS64_R2
  54. bool
  55. config SYS_HAS_CPU_MIPS64_R6
  56. + select DMA_UNMAP_POST_FLUSH
  57. bool
  58. config SYS_HAS_CPU_R3000
  59. --- a/arch/mips/mm/dma-default.c
  60. +++ b/arch/mips/mm/dma-default.c
  61. @@ -267,8 +267,9 @@ static inline void __dma_sync(struct pag
  62. } while (left);
  63. }
  64. -static void mips_dma_unmap_page(struct device *dev, dma_addr_t dma_addr,
  65. - size_t size, enum dma_data_direction direction, unsigned long attrs)
  66. +static void __maybe_unused
  67. +mips_dma_unmap_page(struct device *dev, dma_addr_t dma_addr, size_t size,
  68. + enum dma_data_direction direction, unsigned long attrs)
  69. {
  70. if (cpu_needs_post_dma_flush(dev) && !(attrs & DMA_ATTR_SKIP_CPU_SYNC))
  71. __dma_sync(dma_addr_to_page(dev, dma_addr),
  72. @@ -308,9 +309,10 @@ static dma_addr_t mips_dma_map_page(stru
  73. return plat_map_dma_mem_page(dev, page) + offset;
  74. }
  75. -static void mips_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
  76. - int nhwentries, enum dma_data_direction direction,
  77. - unsigned long attrs)
  78. +static void __maybe_unused
  79. +mips_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
  80. + int nhwentries, enum dma_data_direction direction,
  81. + unsigned long attrs)
  82. {
  83. int i;
  84. struct scatterlist *sg;
  85. @@ -325,8 +327,9 @@ static void mips_dma_unmap_sg(struct dev
  86. }
  87. }
  88. -static void mips_dma_sync_single_for_cpu(struct device *dev,
  89. - dma_addr_t dma_handle, size_t size, enum dma_data_direction direction)
  90. +static void __maybe_unused
  91. +mips_dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
  92. + size_t size, enum dma_data_direction direction)
  93. {
  94. if (cpu_needs_post_dma_flush(dev))
  95. __dma_sync(dma_addr_to_page(dev, dma_handle),
  96. @@ -342,9 +345,9 @@ static void mips_dma_sync_single_for_dev
  97. dma_handle & ~PAGE_MASK, size, direction);
  98. }
  99. -static void mips_dma_sync_sg_for_cpu(struct device *dev,
  100. - struct scatterlist *sglist, int nelems,
  101. - enum dma_data_direction direction)
  102. +static void __maybe_unused
  103. +mips_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sglist,
  104. + int nelems, enum dma_data_direction direction)
  105. {
  106. int i;
  107. struct scatterlist *sg;
  108. @@ -394,12 +397,14 @@ static const struct dma_map_ops mips_def
  109. .free = mips_dma_free_coherent,
  110. .mmap = mips_dma_mmap,
  111. .map_page = mips_dma_map_page,
  112. - .unmap_page = mips_dma_unmap_page,
  113. .map_sg = mips_dma_map_sg,
  114. +#ifdef CONFIG_DMA_UNMAP_POST_FLUSH
  115. + .unmap_page = mips_dma_unmap_page,
  116. .unmap_sg = mips_dma_unmap_sg,
  117. .sync_single_for_cpu = mips_dma_sync_single_for_cpu,
  118. - .sync_single_for_device = mips_dma_sync_single_for_device,
  119. .sync_sg_for_cpu = mips_dma_sync_sg_for_cpu,
  120. +#endif
  121. + .sync_single_for_device = mips_dma_sync_single_for_device,
  122. .sync_sg_for_device = mips_dma_sync_sg_for_device,
  123. .dma_supported = mips_dma_supported
  124. };