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
5 It improves performance by eliminating the need for a cache flush for DMA on
8 Signed-off-by: Felix Fietkau <nbd@nbd.name>
11 --- a/arch/arm64/boot/dts/mediatek/mt7622.dtsi
12 +++ b/arch/arm64/boot/dts/mediatek/mt7622.dtsi
14 reg = <0 0x1a143000 0 0x1000>;
16 mediatek,pcie-cfg = <&pciecfg>;
17 + mediatek,hifsys = <&hifsys>;
18 + mediatek,cci-control = <&cci_control2>;
21 interrupts = <GIC_SPI 228 IRQ_TYPE_LEVEL_LOW>;
23 bus-range = <0x00 0xff>;
24 ranges = <0x82000000 0 0x20000000 0x0 0x20000000 0 0x8000000>;
29 reg = <0x0000 0 0 0 0>;
31 reg = <0 0x1a145000 0 0x1000>;
33 mediatek,pcie-cfg = <&pciecfg>;
34 + mediatek,hifsys = <&hifsys>;
35 + mediatek,cci-control = <&cci_control2>;
38 interrupts = <GIC_SPI 229 IRQ_TYPE_LEVEL_LOW>;
40 bus-range = <0x00 0xff>;
41 ranges = <0x82000000 0 0x28000000 0x0 0x28000000 0 0x8000000>;
46 reg = <0x0800 0 0 0 0>;
47 --- a/drivers/pci/controller/pcie-mediatek.c
48 +++ b/drivers/pci/controller/pcie-mediatek.c
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>
58 #define PCIE_LINK_STATUS_V2 0x804
59 #define PCIE_PORT_LINKUP_V2 BIT(10)
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)
69 @@ -1042,6 +1048,27 @@ static int mtk_pcie_setup(struct mtk_pci
70 struct mtk_pcie_port *port, *tmp;
73 + if (of_dma_is_coherent(node)) {
77 + con = syscon_regmap_lookup_by_phandle(node,
78 + "mediatek,cci-control");
79 + /* enable CPU/bus coherency */
81 + regmap_write(con, 0, 3);
83 + con = syscon_regmap_lookup_by_phandle(node,
86 + dev_err(dev, "missing hifsys node\n");
87 + return PTR_ERR(con);
90 + mask = HIFSYS_DMA_AG_MAP_PCIE0 | HIFSYS_DMA_AG_MAP_PCIE1;
91 + regmap_update_bits(con, HIFSYS_DMA_AG_MAP, mask, mask);
94 for_each_available_child_of_node(node, child) {