<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><br><br><div dir="ltr">Sent from my iPad</div><div dir="ltr"><br><blockquote type="cite">On Aug 2, 2022, at 3:33 PM, Tomasz Figa <tfiga@chromium.org> wrote:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr"><span>On Mon, Aug 1, 2022 at 8:43 PM ayaka <ayaka@soulik.info> wrote:</span><br><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>Sent from my iPad</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><blockquote type="cite"><span>On Aug 1, 2022, at 5:46 PM, Tomasz Figa <tfiga@chromium.org> wrote:</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>CAUTION: Email originated externally, do not click links or open attachments unless you recognize the sender and know the content is safe.</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>On Mon, Aug 1, 2022 at 3:44 PM Hsia-Jun Li <Randy.Li@synaptics.com> wrote:</span><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>On 8/1/22 14:19, Tomasz Figa wrote:</span><br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>Hello Tomasz</span><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>?Hi Randy,</span><br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>On Mon, Aug 1, 2022 at 5:21 AM <ayaka@soulik.info> wrote:</span><br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>From: Randy Li <ayaka@soulik.info></span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>This module is still at a early stage, I wrote this for showing what</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>APIs we need here.</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>Let me explain why we need such a module here.</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>If you won't allocate buffers from a V4L2 M2M device, this module</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>may not be very useful. I am sure the most of users won't know a</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>device would require them allocate buffers from a DMA-Heap then</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>import those buffers into a V4L2's queue.</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>Then the question goes back to why DMA-Heap. From the Android's</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>description, we know it is about the copyright's DRM.</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>When we allocate a buffer in a DMA-Heap, it may register that buffer</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>in the trusted execution environment so the firmware which is running</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>or could only be acccesed from there could use that buffer later.</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>The answer above leads to another thing which is not done in this</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>version, the DMA mapping. Although in some platforms, a DMA-Heap</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>responses a IOMMU device as well. For the genernal purpose, we would</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>be better assuming the device mapping should be done for each device</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>itself. The problem here we only know alloc_devs in those DMAbuf</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>methods, which are DMA-heaps in my design, the device from the queue</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>is not enough, a plane may requests another IOMMU device or table</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>for mapping.</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>Signed-off-by: Randy Li <ayaka@soulik.info></span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>---</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>drivers/media/common/videobuf2/Kconfig | 6 +</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>drivers/media/common/videobuf2/Makefile | 1 +</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>.../common/videobuf2/videobuf2-dma-heap.c | 350 ++++++++++++++++++</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>include/media/videobuf2-dma-heap.h | 30 ++</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>4 files changed, 387 insertions(+)</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>create mode 100644 drivers/media/common/videobuf2/videobuf2-dma-heap.c</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>create mode 100644 include/media/videobuf2-dma-heap.h</span><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>First of all, thanks for the series.</span><br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>Possibly a stupid question, but why not just allocate the DMA-bufs</span><br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>directly from the DMA-buf heap device in the userspace and just import</span><br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>the buffers to the V4L2 device using V4L2_MEMORY_DMABUF?</span><br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>Sometimes the allocation policy could be very complex, let's suppose a</span><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>multiple planes pixel format enabling with frame buffer compression.</span><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>Its luma, chroma data could be allocated from a pool which is delegated</span><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>for large buffers while its metadata would come from a pool which many</span><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>users could take some few slices from it(likes system pool).</span><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>Then when we have a new users knowing nothing about this platform, if we</span><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>just configure the alloc_devs in each queues well. The user won't need</span><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>to know those complex rules.</span><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>The real situation could be more complex, Samsung MFC's left and right</span><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>banks could be regarded as two pools, many devices would benefit from</span><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>this either from the allocation times or the security buffers policy.</span><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>In our design, when we need to do some security decoding(DRM video),</span><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>codecs2 would allocate buffers from the pool delegated for that. While</span><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>the non-DRM video, users could not care about this.</span><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>I'm a little bit surprised about this, because on Android all the</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>graphics buffers are allocated from the system IAllocator and imported</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>to the specific devices.</span><br></blockquote></blockquote><blockquote type="cite"><span>In the non-tunnel mode, yes it is. While the tunnel mode is completely vendor defined. Neither HWC nor codec2 cares about where the buffers coming from, you could do what ever you want.</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>Besides there are DRM video in GNU Linux platform, I heard the webkit has made huge effort here and Playready is one could work in non-Android Linux.</span><br></blockquote><blockquote type="cite"><blockquote type="cite"><span>Would it make sense to instead extend the UAPI to expose enough</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>information about the allocation requirements to the userspace, so it</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>can allocate correctly?</span><br></blockquote></blockquote><blockquote type="cite"><span>Yes, it could. But as I said it would need the users to do more works.</span><br></blockquote><blockquote type="cite"><blockquote type="cite"><span>My reasoning here is that it's not a driver's decision to allocate</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>from a DMA-buf heap (and which one) or not. It's the userspace which</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>knows that, based on the specific use case that it wants to fulfill.</span><br></blockquote></blockquote><blockquote type="cite"><span>Although I would like to let the users decide that, users just can’t do that which would violate the security rules in some platforms.</span><br></blockquote><blockquote type="cite"><span>For example, video codec and display device could only access a region of memory, any other device or trusted apps can’t access it. Users have to allocate the buffer from the pool the vendor decided.</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>So why not we offer a quick way that users don’t need to try and error.</span><br></blockquote><span></span><br><span>In principle, I'm not against integrating DMA-buf heap with vb2,</span><br><span>however I see some problems I mentioned before:</span><br><span></span><br><span>1) How would the driver know if it should allocate from a DMA-buf heap or not?</span></div></blockquote>struct vb2_queue.mem_ops<div><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);"><br></span></div><div><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">int (*queue_setup)(struct vb2_queue *q,unsigned int *num_buffers, unsigned int *num_planes, unsigned int sizes[], struct device *alloc_devs[]);</span></div><div><font color="#000000"><span style="caret-color: rgb(0, 0, 0);"><br></span></font><div><blockquote type="cite"><div dir="ltr"><span>2) How would the driver know which heap to allocate from?</span><br></div></blockquote><div>From vb2_queue.alloc_devs</div><div><br></div><div>What I did now is likes what MFC does, create some mem_alloc_devs.</div><div>It would be better that we could retrieve the DMA-heaps’ devices from kernel, but that is not enough, we need a place to store the heap flags although none of them are defined yet.</div><div><br></div><div>From Android documents, I think it is unlikely we would have heap flags.</div><div>“Standardization: The DMA-BUF heaps framework offers a well-defined UAPI. ION allowed custom flags and heap IDs that prevented developing a common testing framework because each device’s ION implementation could behave differently.”</div><div><br><blockquote type="cite"><div dir="ltr"><span>3) How would the heap know how to allocate properly for the device?</span><br><span></span><br></div></blockquote>Because “each DMA-BUF heap is a separate character device”.</div><div>But as I said in the first draft I am not sure about the DMA mapping part. alloc_devs responds for the heap, we have a device variable in the queue that mapping function could access, but that may not be enough. A plane may apply a different mapping policy or IOMMU here.</div><div><br></div><div>Would it be better that I create a interface here that creating a memdev with DMA-heap description ? <br><blockquote type="cite"><div dir="ltr"><span>Best regards,</span><br><span>Tomasz</span><br></div></blockquote></div></div></div></body></html>