]> git.ipfire.org Git - thirdparty/openwrt.git/blob
83d2c5d473596322e6375fa04d7260f54cdf9d1f
[thirdparty/openwrt.git] /
1 From 27aa35221819fec513ce1b886fba3b0ab6504245 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Wed, 22 Nov 2023 19:17:44 +0000
4 Subject: [PATCH 0743/1085] drm: vc4: Block swiotlb bounce buffers being
5 imported as dmabuf
6
7 The dmabuf import already checks that the backing buffer is contiguous
8 and rejects it if it isn't. vc4 also requires that the buffer is
9 in the bottom 1GB of RAM, and this is all correctly defined via
10 dma-ranges.
11
12 However the kernel silently uses swiotlb to bounce dma buffers
13 around if they are in the wrong region. This relies on dma sync
14 functions to be called in order to copy the data to/from the
15 bounce buffer.
16
17 DRM is based on all memory allocations being coherent with the
18 GPU so that any updates to a framebuffer will be acted on without
19 the need for any additional update. This is fairly fundamentally
20 incompatible with needing to call dma_sync_ to handle the bounce
21 buffer copies, and therefore we have to detect and reject mappings
22 that use bounce buffers.
23
24 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
25 ---
26 drivers/gpu/drm/vc4/vc4_drv.c | 20 ++++++++++++++++++--
27 1 file changed, 18 insertions(+), 2 deletions(-)
28
29 --- a/drivers/gpu/drm/vc4/vc4_drv.c
30 +++ b/drivers/gpu/drm/vc4/vc4_drv.c
31 @@ -29,6 +29,7 @@
32 #include <linux/of_device.h>
33 #include <linux/platform_device.h>
34 #include <linux/pm_runtime.h>
35 +#include <linux/dma-direct.h>
36
37 #include <drm/drm_aperture.h>
38 #include <drm/drm_atomic_helper.h>
39 @@ -175,6 +176,19 @@ static void vc4_close(struct drm_device
40 kfree(vc4file);
41 }
42
43 +struct drm_gem_object *
44 +vc4_prime_import_sg_table(struct drm_device *dev,
45 + struct dma_buf_attachment *attach,
46 + struct sg_table *sgt)
47 +{
48 + phys_addr_t phys = dma_to_phys(dev->dev, sg_dma_address(sgt->sgl));
49 +
50 + if (is_swiotlb_buffer(dev->dev, phys))
51 + return ERR_PTR(-EINVAL);
52 +
53 + return drm_gem_dma_prime_import_sg_table(dev, attach, sgt);
54 +}
55 +
56 DEFINE_DRM_GEM_FOPS(vc4_drm_fops);
57
58 static const struct drm_ioctl_desc vc4_drm_ioctls[] = {
59 @@ -211,7 +225,8 @@ const struct drm_driver vc4_drm_driver =
60
61 .gem_create_object = vc4_create_object,
62
63 - DRM_GEM_DMA_DRIVER_OPS_WITH_DUMB_CREATE(vc4_bo_dumb_create),
64 + .dumb_create = vc4_bo_dumb_create,
65 + .gem_prime_import_sg_table = vc4_prime_import_sg_table,
66
67 .ioctls = vc4_drm_ioctls,
68 .num_ioctls = ARRAY_SIZE(vc4_drm_ioctls),
69 @@ -234,7 +249,8 @@ const struct drm_driver vc5_drm_driver =
70 .debugfs_init = vc4_debugfs_init,
71 #endif
72
73 - DRM_GEM_DMA_DRIVER_OPS_WITH_DUMB_CREATE(vc5_dumb_create),
74 + .dumb_create = vc5_dumb_create,
75 + .gem_prime_import_sg_table = vc4_prime_import_sg_table,
76
77 .fops = &vc4_drm_fops,
78