32fc0a9ad5987fb950f32566e4dd153b48882bc2
[openwrt/staging/mkresin.git] / target / linux / mediatek / patches-5.10 / 710-pci-pcie-mediatek-add-support-for-coherent-DMA.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Fri, 4 Sep 2020 18:42:42 +0200
3 Subject: [PATCH] pci: pcie-mediatek: add support for coherent DMA
4
5 It improves performance by eliminating the need for a cache flush for DMA on
6 attached devices
7
8 Signed-off-by: Felix Fietkau <nbd@nbd.name>
9 ---
10
11 --- a/arch/arm64/boot/dts/mediatek/mt7622.dtsi
12 +++ b/arch/arm64/boot/dts/mediatek/mt7622.dtsi
13 @@ -813,6 +813,8 @@
14 reg = <0 0x1a143000 0 0x1000>;
15 reg-names = "port0";
16 mediatek,pcie-cfg = <&pciecfg>;
17 + mediatek,hifsys = <&hifsys>;
18 + mediatek,cci-control = <&cci_control2>;
19 #address-cells = <3>;
20 #size-cells = <2>;
21 interrupts = <GIC_SPI 228 IRQ_TYPE_LEVEL_LOW>;
22 @@ -830,6 +832,7 @@
23 bus-range = <0x00 0xff>;
24 ranges = <0x82000000 0 0x20000000 0x0 0x20000000 0 0x8000000>;
25 status = "disabled";
26 + dma-coherent;
27
28 slot0: pcie@0,0 {
29 reg = <0x0000 0 0 0 0>;
30 @@ -856,6 +859,8 @@
31 reg = <0 0x1a145000 0 0x1000>;
32 reg-names = "port1";
33 mediatek,pcie-cfg = <&pciecfg>;
34 + mediatek,hifsys = <&hifsys>;
35 + mediatek,cci-control = <&cci_control2>;
36 #address-cells = <3>;
37 #size-cells = <2>;
38 interrupts = <GIC_SPI 229 IRQ_TYPE_LEVEL_LOW>;
39 @@ -874,6 +879,7 @@
40 bus-range = <0x00 0xff>;
41 ranges = <0x82000000 0 0x28000000 0x0 0x28000000 0 0x8000000>;
42 status = "disabled";
43 + dma-coherent;
44
45 slot1: pcie@1,0 {
46 reg = <0x0800 0 0 0 0>;
47 --- a/drivers/pci/controller/pcie-mediatek.c
48 +++ b/drivers/pci/controller/pcie-mediatek.c
49 @@ -20,6 +20,7 @@
50 #include <linux/of_address.h>
51 #include <linux/of_pci.h>
52 #include <linux/of_platform.h>
53 +#include <linux/of_address.h>
54 #include <linux/pci.h>
55 #include <linux/phy/phy.h>
56 #include <linux/platform_device.h>
57 @@ -139,6 +140,11 @@
58 #define PCIE_LINK_STATUS_V2 0x804
59 #define PCIE_PORT_LINKUP_V2 BIT(10)
60
61 +/* DMA channel mapping */
62 +#define HIFSYS_DMA_AG_MAP 0x008
63 +#define HIFSYS_DMA_AG_MAP_PCIE0 BIT(0)
64 +#define HIFSYS_DMA_AG_MAP_PCIE1 BIT(1)
65 +
66 struct mtk_pcie_port;
67
68 /**
69 @@ -1042,6 +1048,27 @@ static int mtk_pcie_setup(struct mtk_pci
70 struct mtk_pcie_port *port, *tmp;
71 int err;
72
73 + if (of_dma_is_coherent(node)) {
74 + struct regmap *con;
75 + u32 mask;
76 +
77 + con = syscon_regmap_lookup_by_phandle(node,
78 + "mediatek,cci-control");
79 + /* enable CPU/bus coherency */
80 + if (!IS_ERR(con))
81 + regmap_write(con, 0, 3);
82 +
83 + con = syscon_regmap_lookup_by_phandle(node,
84 + "mediatek,hifsys");
85 + if (IS_ERR(con)) {
86 + dev_err(dev, "missing hifsys node\n");
87 + return PTR_ERR(con);
88 + }
89 +
90 + mask = HIFSYS_DMA_AG_MAP_PCIE0 | HIFSYS_DMA_AG_MAP_PCIE1;
91 + regmap_update_bits(con, HIFSYS_DMA_AG_MAP, mask, mask);
92 + }
93 +
94 for_each_available_child_of_node(node, child) {
95 int slot;
96