1 From 1770efc97981dbf756a18f5eb7615c4bafab665b Mon Sep 17 00:00:00 2001
2 From: John Cox <jc@kynesim.co.uk>
3 Date: Mon, 2 Oct 2023 15:12:52 +0100
4 Subject: [PATCH] media/rpivid: Allow use of iommu in rpivid
6 In order to use iommu on hevc set dma mask_and_coherent in probe.
7 I am assured dma_set_mask_and_coherent is benign on Pi4 (which has
8 no iommu) and it seems to be so in practice.
9 Also adds a bit of debug to make internal buffer allocation failure
10 easier to spot in future
12 Signed-off-by: John Cox <jc@kynesim.co.uk>
14 drivers/staging/media/rpivid/rpivid.c | 7 +++++++
15 drivers/staging/media/rpivid/rpivid_h265.c | 12 ++++++++++--
16 2 files changed, 17 insertions(+), 2 deletions(-)
18 --- a/drivers/staging/media/rpivid/rpivid.c
19 +++ b/drivers/staging/media/rpivid/rpivid.c
20 @@ -360,6 +360,13 @@ static int rpivid_probe(struct platform_
21 snprintf(vfd->name, sizeof(vfd->name), "%s", rpivid_video_device.name);
22 video_set_drvdata(vfd, dev);
24 + ret = dma_set_mask_and_coherent(dev->dev, DMA_BIT_MASK(36));
26 + v4l2_err(&dev->v4l2_dev,
27 + "Failed dma_set_mask_and_coherent\n");
31 dev->m2m_dev = v4l2_m2m_init(&rpivid_m2m_ops);
32 if (IS_ERR(dev->m2m_dev)) {
33 v4l2_err(&dev->v4l2_dev,
34 --- a/drivers/staging/media/rpivid/rpivid_h265.c
35 +++ b/drivers/staging/media/rpivid/rpivid_h265.c
36 @@ -2495,11 +2495,19 @@ static int rpivid_h265_start(struct rpiv
37 for (i = 0; i != ARRAY_SIZE(ctx->pu_bufs); ++i) {
38 // Don't actually need a kernel mapping here
39 if (gptr_alloc(dev, ctx->pu_bufs + i, pu_alloc,
40 - DMA_ATTR_NO_KERNEL_MAPPING))
41 + DMA_ATTR_NO_KERNEL_MAPPING)) {
42 + v4l2_err(&dev->v4l2_dev,
43 + "Failed to alloc %#zx PU%d buffer\n",
47 if (gptr_alloc(dev, ctx->coeff_bufs + i, coeff_alloc,
48 - DMA_ATTR_NO_KERNEL_MAPPING))
49 + DMA_ATTR_NO_KERNEL_MAPPING)) {
50 + v4l2_err(&dev->v4l2_dev,
51 + "Failed to alloc %#zx Coeff%d buffer\n",