bcm27xx: update patches from RPi foundation
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0756-staging-vchiq_arm-Clean-up-40-bit-DMA-support.patch
1 From d8cbdaa729d5d3e9a1c18150bf4de69335a85a40 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 .../interface/vchiq_arm/vchiq_2835_arm.c | 39 ++++++++++++-------
15 .../interface/vchiq_arm/vchiq_arm.c | 14 -------
16 2 files changed, 25 insertions(+), 28 deletions(-)
17
18 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
19 +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
20 @@ -16,8 +16,6 @@
21 #include <soc/bcm2835/raspberrypi-firmware.h>
22
23 #define TOTAL_SLOTS (VCHIQ_SLOT_ZERO_SLOTS + 2 * 32)
24 -#define VC_SAFE(x) (g_use_36bit_addrs ? ((u32)(x) | 0xc0000000) : (u32)(x))
25 -#define IS_VC_SAFE(x) (g_use_36bit_addrs ? !((x) & ~0x3fffffffull) : 1)
26
27 #include "vchiq_arm.h"
28 #include "vchiq_connected.h"
29 @@ -71,6 +69,7 @@ static char *g_fragments_base;
30 static char *g_free_fragments;
31 static struct semaphore g_free_fragments_sema;
32 static struct device *g_dev;
33 +static struct device *g_dma_dev;
34
35 static DEFINE_SEMAPHORE(g_free_fragments_mutex);
36
37 @@ -87,6 +86,7 @@ free_pagelist(struct vchiq_pagelist_info
38 int vchiq_platform_init(struct platform_device *pdev, struct vchiq_state *state)
39 {
40 struct device *dev = &pdev->dev;
41 + struct device *dma_dev = NULL;
42 struct vchiq_drvdata *drvdata = platform_get_drvdata(pdev);
43 struct rpi_firmware *fw = drvdata->fw;
44 struct vchiq_slot_zero *vchiq_slot_zero;
45 @@ -109,7 +109,23 @@ int vchiq_platform_init(struct platform_
46 g_cache_line_size = drvdata->cache_line_size;
47 g_fragments_size = 2 * g_cache_line_size;
48
49 - g_use_36bit_addrs = (dev->dma_pfn_offset == 0);
50 + if (drvdata->use_36bit_addrs) {
51 + struct device_node *dma_node =
52 + of_find_compatible_node(NULL, NULL, "brcm,bcm2711-dma");
53 +
54 + if (dma_node) {
55 + struct platform_device *pdev;
56 +
57 + pdev = of_find_device_by_node(dma_node);
58 + if (pdev)
59 + dma_dev = &pdev->dev;
60 + of_node_put(dma_node);
61 + g_use_36bit_addrs = true;
62 + } else {
63 + dev_err(dev, "40-bit DMA controller not found\n");
64 + return -EINVAL;
65 + }
66 + }
67
68 /* Allocate space for the channels in coherent memory */
69 slot_mem_size = PAGE_ALIGN(TOTAL_SLOTS * VCHIQ_SLOT_SIZE);
70 @@ -122,14 +138,8 @@ int vchiq_platform_init(struct platform_
71 return -ENOMEM;
72 }
73
74 - if (!IS_VC_SAFE(slot_phys)) {
75 - dev_err(dev, "allocated DMA memory %pad is not VC-safe\n",
76 - &slot_phys);
77 - return -ENOMEM;
78 - }
79 -
80 WARN_ON(((unsigned long)slot_mem & (PAGE_SIZE - 1)) != 0);
81 - channelbase = VC_SAFE(slot_phys);
82 + channelbase = slot_phys;
83
84 vchiq_slot_zero = vchiq_init_slots(slot_mem, slot_mem_size);
85 if (!vchiq_slot_zero)
86 @@ -178,6 +188,7 @@ int vchiq_platform_init(struct platform_
87 }
88
89 g_dev = dev;
90 + g_dma_dev = dma_dev ?: dev;
91 g_dma_pool = dmam_pool_create("vchiq_scatter_pool", dev,
92 VCHIQ_DMA_POOL_SIZE, g_cache_line_size,
93 0);
94 @@ -255,7 +266,7 @@ vchiq_prepare_bulk_data(struct vchiq_bul
95 if (!pagelistinfo)
96 return VCHIQ_ERROR;
97
98 - bulk->data = (void *)(uintptr_t)VC_SAFE(pagelistinfo->dma_addr);
99 + bulk->data = (void *)(uintptr_t)pagelistinfo->dma_addr;
100
101 /*
102 * Store the pagelistinfo address in remote_data,
103 @@ -354,7 +365,7 @@ static void
104 cleanup_pagelistinfo(struct vchiq_pagelist_info *pagelistinfo)
105 {
106 if (pagelistinfo->scatterlist_mapped) {
107 - dma_unmap_sg(g_dev, pagelistinfo->scatterlist,
108 + dma_unmap_sg(g_dma_dev, pagelistinfo->scatterlist,
109 pagelistinfo->num_pages, pagelistinfo->dma_dir);
110 }
111
112 @@ -519,7 +530,7 @@ create_pagelist(char __user *buf, size_t
113 count -= len;
114 }
115
116 - dma_buffers = dma_map_sg(g_dev,
117 + dma_buffers = dma_map_sg(g_dma_dev,
118 scatterlist,
119 num_pages,
120 pagelistinfo->dma_dir);
121 @@ -569,7 +580,7 @@ create_pagelist(char __user *buf, size_t
122 } else {
123 for_each_sg(scatterlist, sg, dma_buffers, i) {
124 u32 len = sg_dma_len(sg);
125 - u32 addr = VC_SAFE(sg_dma_address(sg));
126 + u32 addr = sg_dma_address(sg);
127 u32 new_pages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
128
129 /* Note: addrs is the address + page_count - 1
130 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
131 +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
132 @@ -3205,22 +3205,8 @@ vchiq_register_child(struct platform_dev
133
134 child->dev.of_node = np;
135
136 - /*
137 - * We want the dma-ranges etc to be copied from a device with the
138 - * correct dma-ranges for the VPU.
139 - * VCHIQ on Pi4 is now under scb which doesn't get those dma-ranges.
140 - * Take the "dma" node as going to be suitable as it sees the world
141 - * through the same eyes as the VPU.
142 - */
143 - np = of_find_node_by_path("dma");
144 - if (!np)
145 - np = pdev->dev.of_node;
146 -
147 of_dma_configure(&child->dev, np, true);
148
149 - if (np != pdev->dev.of_node)
150 - of_node_put(np);
151 -
152 return child;
153 }
154