mediatek: refresh patches for Linux 5.15
[openwrt/staging/mkresin.git] / target / linux / mediatek / patches-5.15 / 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 @@ -835,6 +835,9 @@
14 bus-range = <0x00 0xff>;
15 ranges = <0x82000000 0 0x20000000 0x0 0x20000000 0 0x8000000>;
16 status = "disabled";
17 + dma-coherent;
18 + mediatek,hifsys = <&hifsys>;
19 + mediatek,cci-control = <&cci_control2>;
20
21 #interrupt-cells = <1>;
22 interrupt-map-mask = <0 0 0 7>;
23 @@ -879,6 +882,9 @@
24 bus-range = <0x00 0xff>;
25 ranges = <0x82000000 0 0x28000000 0x0 0x28000000 0 0x8000000>;
26 status = "disabled";
27 + dma-coherent;
28 + mediatek,hifsys = <&hifsys>;
29 + mediatek,cci-control = <&cci_control2>;
30
31 #interrupt-cells = <1>;
32 interrupt-map-mask = <0 0 0 7>;
33 --- a/drivers/pci/controller/pcie-mediatek.c
34 +++ b/drivers/pci/controller/pcie-mediatek.c
35 @@ -20,6 +20,7 @@
36 #include <linux/of_address.h>
37 #include <linux/of_pci.h>
38 #include <linux/of_platform.h>
39 +#include <linux/of_address.h>
40 #include <linux/pci.h>
41 #include <linux/phy/phy.h>
42 #include <linux/platform_device.h>
43 @@ -139,6 +140,11 @@
44 #define PCIE_LINK_STATUS_V2 0x804
45 #define PCIE_PORT_LINKUP_V2 BIT(10)
46
47 +/* DMA channel mapping */
48 +#define HIFSYS_DMA_AG_MAP 0x008
49 +#define HIFSYS_DMA_AG_MAP_PCIE0 BIT(0)
50 +#define HIFSYS_DMA_AG_MAP_PCIE1 BIT(1)
51 +
52 struct mtk_pcie_port;
53
54 /**
55 @@ -1053,6 +1059,27 @@ static int mtk_pcie_setup(struct mtk_pci
56 struct mtk_pcie_port *port, *tmp;
57 int err, slot;
58
59 + if (of_dma_is_coherent(node)) {
60 + struct regmap *con;
61 + u32 mask;
62 +
63 + con = syscon_regmap_lookup_by_phandle(node,
64 + "mediatek,cci-control");
65 + /* enable CPU/bus coherency */
66 + if (!IS_ERR(con))
67 + regmap_write(con, 0, 3);
68 +
69 + con = syscon_regmap_lookup_by_phandle(node,
70 + "mediatek,hifsys");
71 + if (IS_ERR(con)) {
72 + dev_err(dev, "missing hifsys node\n");
73 + return PTR_ERR(con);
74 + }
75 +
76 + mask = HIFSYS_DMA_AG_MAP_PCIE0 | HIFSYS_DMA_AG_MAP_PCIE1;
77 + regmap_update_bits(con, HIFSYS_DMA_AG_MAP, mask, mask);
78 + }
79 +
80 slot = of_get_pci_domain_nr(dev->of_node);
81 if (slot < 0) {
82 for_each_available_child_of_node(node, child) {