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
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
12 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
14 staging: vchiq_arm: Use g_dma_dev for dma_unmap_sg
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.
20 See: https://github.com/raspberrypi/linux/issues/3647
22 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
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(-)
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
31 #include <soc/bcm2835/raspberrypi-firmware.h>
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)
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;
45 static DEFINE_SEMAPHORE(g_free_fragments_mutex);
47 @@ -82,6 +81,7 @@ free_pagelist(struct vchiq_pagelist_info
48 int vchiq_platform_init(struct platform_device *pdev, struct vchiq_state *state)
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;
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");
65 + struct platform_device *pdev;
67 + pdev = of_find_device_by_node(dma_node);
69 + dma_dev = &pdev->dev;
70 + of_node_put(dma_node);
71 + g_use_36bit_addrs = true;
73 + dev_err(dev, "40-bit DMA controller not found\n");
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_
84 - if (!IS_VC_SAFE(slot_phys)) {
85 - dev_err(dev, "allocated DMA memory %pad is not VC-safe\n",
90 WARN_ON(((unsigned long)slot_mem & (PAGE_SIZE - 1)) != 0);
91 - channelbase = VC_SAFE(slot_phys);
92 + channelbase = slot_phys;
94 vchiq_slot_zero = vchiq_init_slots(slot_mem, slot_mem_size);
96 @@ -171,6 +181,8 @@ int vchiq_platform_init(struct platform_
100 + g_dma_dev = dma_dev ?: dev;
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
109 - bulk->data = (void *)VC_SAFE(pagelistinfo->dma_addr);
110 + bulk->data = pagelistinfo->dma_addr;
113 * Store the pagelistinfo address in remote_data,
114 @@ -295,7 +307,7 @@ static void
115 cleanup_pagelistinfo(struct vchiq_pagelist_info *pagelistinfo)
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);
123 @@ -444,7 +456,7 @@ create_pagelist(char *buf, char __user *
127 - dma_buffers = dma_map_sg(g_dev,
128 + dma_buffers = dma_map_sg(g_dma_dev,
131 pagelistinfo->dma_dir);
132 @@ -494,7 +506,7 @@ create_pagelist(char *buf, char __user *
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;
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.
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;
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
154 child->dev.of_node = np;
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.
163 - np = of_find_node_by_path("dma");
165 - np = pdev->dev.of_node;
167 of_dma_configure(&child->dev, np, true);
169 - if (np != pdev->dev.of_node)