bcm27xx: add kernel 5.10 support
[openwrt/staging/chunkeey.git] / target / linux / bcm27xx / patches-5.10 / 950-0253-staging-vchiq_arm-Clean-up-40-bit-DMA-support.patch
1 From 461092c036303037c0efe37002079ce6e9ed8ba5 Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.com>
3 Date: Wed, 20 May 2020 16:36:33 +0100
4 Subject: [PATCH] staging: vchiq_arm: Clean up 40-bit DMA support
5
6 Manage the split between addresses for the VPU and addresses for the
7 40-bit DMA controller with a dedicated DMA device pointer that on non-
8 BCM2711 platforms is the same as the main VCHIQ device. This allows
9 the VCHIQ node to stay in the usual place in the DT, and removes the
10 ugly VC_SAFE macros.
11
12 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
13
14 staging: vchiq_arm: Use g_dma_dev for dma_unmap_sg
15
16 Commit "staging: vchiq_arm: Clean up 40-bit DMA support" failed to
17 change one of the calls to dma_unmap_sg to pass in g_dma_dev (rather
18 than g_dev). Correct that oversight.
19
20 See: https://github.com/raspberrypi/linux/issues/3647
21
22 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
23 ---
24 .../interface/vchiq_arm/vchiq_2835_arm.c | 42 ++++++++++++-------
25 .../interface/vchiq_arm/vchiq_arm.c | 14 -------
26 2 files changed, 27 insertions(+), 29 deletions(-)
27
28 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
29 +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
30 @@ -16,8 +16,6 @@
31 #include <soc/bcm2835/raspberrypi-firmware.h>
32
33 #define TOTAL_SLOTS (VCHIQ_SLOT_ZERO_SLOTS + 2 * 32)
34 -#define VC_SAFE(x) (g_use_36bit_addrs ? ((u32)(x) | 0xc0000000) : (u32)(x))
35 -#define IS_VC_SAFE(x) (g_use_36bit_addrs ? !((x) & ~0x3fffffffull) : 1)
36
37 #include "vchiq_arm.h"
38 #include "vchiq_connected.h"
39 @@ -66,6 +64,7 @@ static char *g_fragments_base;
40 static char *g_free_fragments;
41 static struct semaphore g_free_fragments_sema;
42 static struct device *g_dev;
43 +static struct device *g_dma_dev;
44
45 static DEFINE_SEMAPHORE(g_free_fragments_mutex);
46
47 @@ -82,6 +81,7 @@ free_pagelist(struct vchiq_pagelist_info
48 int vchiq_platform_init(struct platform_device *pdev, struct vchiq_state *state)
49 {
50 struct device *dev = &pdev->dev;
51 + struct device *dma_dev = NULL;
52 struct vchiq_drvdata *drvdata = platform_get_drvdata(pdev);
53 struct rpi_firmware *fw = drvdata->fw;
54 struct vchiq_slot_zero *vchiq_slot_zero;
55 @@ -103,7 +103,23 @@ int vchiq_platform_init(struct platform_
56 g_cache_line_size = drvdata->cache_line_size;
57 g_fragments_size = 2 * g_cache_line_size;
58
59 - g_use_36bit_addrs = (dev->dma_pfn_offset == 0);
60 + if (drvdata->use_36bit_addrs) {
61 + struct device_node *dma_node =
62 + of_find_compatible_node(NULL, NULL, "brcm,bcm2711-dma");
63 +
64 + if (dma_node) {
65 + struct platform_device *pdev;
66 +
67 + pdev = of_find_device_by_node(dma_node);
68 + if (pdev)
69 + dma_dev = &pdev->dev;
70 + of_node_put(dma_node);
71 + g_use_36bit_addrs = true;
72 + } else {
73 + dev_err(dev, "40-bit DMA controller not found\n");
74 + return -EINVAL;
75 + }
76 + }
77
78 /* Allocate space for the channels in coherent memory */
79 slot_mem_size = PAGE_ALIGN(TOTAL_SLOTS * VCHIQ_SLOT_SIZE);
80 @@ -116,14 +132,8 @@ int vchiq_platform_init(struct platform_
81 return -ENOMEM;
82 }
83
84 - if (!IS_VC_SAFE(slot_phys)) {
85 - dev_err(dev, "allocated DMA memory %pad is not VC-safe\n",
86 - &slot_phys);
87 - return -ENOMEM;
88 - }
89 -
90 WARN_ON(((unsigned long)slot_mem & (PAGE_SIZE - 1)) != 0);
91 - channelbase = VC_SAFE(slot_phys);
92 + channelbase = slot_phys;
93
94 vchiq_slot_zero = vchiq_init_slots(slot_mem, slot_mem_size);
95 if (!vchiq_slot_zero)
96 @@ -171,6 +181,8 @@ int vchiq_platform_init(struct platform_
97 }
98
99 g_dev = dev;
100 + g_dma_dev = dma_dev ?: dev;
101 +
102 vchiq_log_info(vchiq_arm_log_level,
103 "vchiq_init - done (slots %pK, phys %pad)",
104 vchiq_slot_zero, &slot_phys);
105 @@ -240,7 +252,7 @@ vchiq_prepare_bulk_data(struct vchiq_bul
106 if (!pagelistinfo)
107 return VCHIQ_ERROR;
108
109 - bulk->data = (void *)VC_SAFE(pagelistinfo->dma_addr);
110 + bulk->data = pagelistinfo->dma_addr;
111
112 /*
113 * Store the pagelistinfo address in remote_data,
114 @@ -295,7 +307,7 @@ static void
115 cleanup_pagelistinfo(struct vchiq_pagelist_info *pagelistinfo)
116 {
117 if (pagelistinfo->scatterlist_mapped) {
118 - dma_unmap_sg(g_dev, pagelistinfo->scatterlist,
119 + dma_unmap_sg(g_dma_dev, pagelistinfo->scatterlist,
120 pagelistinfo->num_pages, pagelistinfo->dma_dir);
121 }
122
123 @@ -444,7 +456,7 @@ create_pagelist(char *buf, char __user *
124 count -= len;
125 }
126
127 - dma_buffers = dma_map_sg(g_dev,
128 + dma_buffers = dma_map_sg(g_dma_dev,
129 scatterlist,
130 num_pages,
131 pagelistinfo->dma_dir);
132 @@ -494,7 +506,7 @@ create_pagelist(char *buf, char __user *
133 } else {
134 for_each_sg(scatterlist, sg, dma_buffers, i) {
135 u32 len = sg_dma_len(sg);
136 - u32 addr = VC_SAFE(sg_dma_address(sg));
137 + u32 addr = sg_dma_address(sg);
138 u32 new_pages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
139
140 /* Note: addrs is the address + page_count - 1
141 @@ -555,7 +567,7 @@ free_pagelist(struct vchiq_pagelist_info
142 * NOTE: dma_unmap_sg must be called before the
143 * cpu can touch any of the data/pages.
144 */
145 - dma_unmap_sg(g_dev, pagelistinfo->scatterlist,
146 + dma_unmap_sg(g_dma_dev, pagelistinfo->scatterlist,
147 pagelistinfo->num_pages, pagelistinfo->dma_dir);
148 pagelistinfo->scatterlist_mapped = 0;
149
150 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
151 +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
152 @@ -2720,22 +2720,8 @@ vchiq_register_child(struct platform_dev
153
154 child->dev.of_node = np;
155
156 - /*
157 - * We want the dma-ranges etc to be copied from a device with the
158 - * correct dma-ranges for the VPU.
159 - * VCHIQ on Pi4 is now under scb which doesn't get those dma-ranges.
160 - * Take the "dma" node as going to be suitable as it sees the world
161 - * through the same eyes as the VPU.
162 - */
163 - np = of_find_node_by_path("dma");
164 - if (!np)
165 - np = pdev->dev.of_node;
166 -
167 of_dma_configure(&child->dev, np, true);
168
169 - if (np != pdev->dev.of_node)
170 - of_node_put(np);
171 -
172 return child;
173 }
174