710-pci-pcie-mediatek-add-support-for-coherent-DMA.patch 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. From: Felix Fietkau <[email protected]>
  2. Date: Fri, 4 Sep 2020 18:42:42 +0200
  3. Subject: [PATCH] pci: pcie-mediatek: add support for coherent DMA
  4. It improves performance by eliminating the need for a cache flush for DMA on
  5. attached devices
  6. Signed-off-by: Felix Fietkau <[email protected]>
  7. ---
  8. --- a/arch/arm64/boot/dts/mediatek/mt7622.dtsi
  9. +++ b/arch/arm64/boot/dts/mediatek/mt7622.dtsi
  10. @@ -837,6 +837,9 @@
  11. bus-range = <0x00 0xff>;
  12. ranges = <0x82000000 0 0x20000000 0x0 0x20000000 0 0x8000000>;
  13. status = "disabled";
  14. + dma-coherent;
  15. + mediatek,hifsys = <&hifsys>;
  16. + mediatek,cci-control = <&cci_control2>;
  17. #interrupt-cells = <1>;
  18. interrupt-map-mask = <0 0 0 7>;
  19. @@ -881,6 +884,9 @@
  20. bus-range = <0x00 0xff>;
  21. ranges = <0x82000000 0 0x28000000 0x0 0x28000000 0 0x8000000>;
  22. status = "disabled";
  23. + dma-coherent;
  24. + mediatek,hifsys = <&hifsys>;
  25. + mediatek,cci-control = <&cci_control2>;
  26. #interrupt-cells = <1>;
  27. interrupt-map-mask = <0 0 0 7>;
  28. --- a/drivers/pci/controller/pcie-mediatek.c
  29. +++ b/drivers/pci/controller/pcie-mediatek.c
  30. @@ -20,6 +20,7 @@
  31. #include <linux/of_address.h>
  32. #include <linux/of_pci.h>
  33. #include <linux/of_platform.h>
  34. +#include <linux/of_address.h>
  35. #include <linux/pci.h>
  36. #include <linux/phy/phy.h>
  37. #include <linux/platform_device.h>
  38. @@ -139,6 +140,11 @@
  39. #define PCIE_LINK_STATUS_V2 0x804
  40. #define PCIE_PORT_LINKUP_V2 BIT(10)
  41. +/* DMA channel mapping */
  42. +#define HIFSYS_DMA_AG_MAP 0x008
  43. +#define HIFSYS_DMA_AG_MAP_PCIE0 BIT(0)
  44. +#define HIFSYS_DMA_AG_MAP_PCIE1 BIT(1)
  45. +
  46. struct mtk_pcie_port;
  47. /**
  48. @@ -1060,6 +1066,27 @@ static int mtk_pcie_setup(struct mtk_pci
  49. struct mtk_pcie_port *port, *tmp;
  50. int err, slot;
  51. + if (of_dma_is_coherent(node)) {
  52. + struct regmap *con;
  53. + u32 mask;
  54. +
  55. + con = syscon_regmap_lookup_by_phandle(node,
  56. + "mediatek,cci-control");
  57. + /* enable CPU/bus coherency */
  58. + if (!IS_ERR(con))
  59. + regmap_write(con, 0, 3);
  60. +
  61. + con = syscon_regmap_lookup_by_phandle(node,
  62. + "mediatek,hifsys");
  63. + if (IS_ERR(con)) {
  64. + dev_err(dev, "missing hifsys node\n");
  65. + return PTR_ERR(con);
  66. + }
  67. +
  68. + mask = HIFSYS_DMA_AG_MAP_PCIE0 | HIFSYS_DMA_AG_MAP_PCIE1;
  69. + regmap_update_bits(con, HIFSYS_DMA_AG_MAP, mask, mask);
  70. + }
  71. +
  72. slot = of_get_pci_domain_nr(dev->of_node);
  73. if (slot < 0) {
  74. for_each_available_child_of_node(node, child) {