On Aug 2, 2022, at 3:33 PM, Tomasz Figa <tfiga@chromium.org> wrote:
struct vb2_queue.mem_opsOn Mon, Aug 1, 2022 at 8:43 PM ayaka <ayaka@soulik.info> wrote:Sent from my iPadOn Aug 1, 2022, at 5:46 PM, Tomasz Figa <tfiga@chromium.org> wrote:CAUTION: Email originated externally, do not click links or open attachments unless you recognize the sender and know the content is safe.On Mon, Aug 1, 2022 at 3:44 PM Hsia-Jun Li <Randy.Li@synaptics.com> wrote:On 8/1/22 14:19, Tomasz Figa wrote:Hello Tomasz?Hi Randy,On Mon, Aug 1, 2022 at 5:21 AM <ayaka@soulik.info> wrote:From: Randy Li <ayaka@soulik.info>This module is still at a early stage, I wrote this for showing whatAPIs we need here.Let me explain why we need such a module here.If you won't allocate buffers from a V4L2 M2M device, this modulemay not be very useful. I am sure the most of users won't know adevice would require them allocate buffers from a DMA-Heap thenimport those buffers into a V4L2's queue.Then the question goes back to why DMA-Heap. From the Android'sdescription, we know it is about the copyright's DRM.When we allocate a buffer in a DMA-Heap, it may register that bufferin the trusted execution environment so the firmware which is runningor could only be acccesed from there could use that buffer later.The answer above leads to another thing which is not done in thisversion, the DMA mapping. Although in some platforms, a DMA-Heapresponses a IOMMU device as well. For the genernal purpose, we wouldbe better assuming the device mapping should be done for each deviceitself. The problem here we only know alloc_devs in those DMAbufmethods, which are DMA-heaps in my design, the device from the queueis not enough, a plane may requests another IOMMU device or tablefor mapping.Signed-off-by: Randy Li <ayaka@soulik.info>---drivers/media/common/videobuf2/Kconfig | 6 +drivers/media/common/videobuf2/Makefile | 1 +.../common/videobuf2/videobuf2-dma-heap.c | 350 ++++++++++++++++++include/media/videobuf2-dma-heap.h | 30 ++4 files changed, 387 insertions(+)create mode 100644 drivers/media/common/videobuf2/videobuf2-dma-heap.ccreate mode 100644 include/media/videobuf2-dma-heap.hFirst of all, thanks for the series.Possibly a stupid question, but why not just allocate the DMA-bufsdirectly from the DMA-buf heap device in the userspace and just importthe buffers to the V4L2 device using V4L2_MEMORY_DMABUF?Sometimes the allocation policy could be very complex, let's suppose amultiple planes pixel format enabling with frame buffer compression.Its luma, chroma data could be allocated from a pool which is delegatedfor large buffers while its metadata would come from a pool which manyusers could take some few slices from it(likes system pool).Then when we have a new users knowing nothing about this platform, if wejust configure the alloc_devs in each queues well. The user won't needto know those complex rules.The real situation could be more complex, Samsung MFC's left and rightbanks could be regarded as two pools, many devices would benefit fromthis either from the allocation times or the security buffers policy.In our design, when we need to do some security decoding(DRM video),codecs2 would allocate buffers from the pool delegated for that. Whilethe non-DRM video, users could not care about this.I'm a little bit surprised about this, because on Android all thegraphics buffers are allocated from the system IAllocator and importedto the specific devices.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.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.Would it make sense to instead extend the UAPI to expose enoughinformation about the allocation requirements to the userspace, so itcan allocate correctly?Yes, it could. But as I said it would need the users to do more works.My reasoning here is that it's not a driver's decision to allocatefrom a DMA-buf heap (and which one) or not. It's the userspace whichknows that, based on the specific use case that it wants to fulfill.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.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.So why not we offer a quick way that users don’t need to try and error.
In principle, I'm not against integrating DMA-buf heap with vb2,
however I see some problems I mentioned before:
1) How would the driver know if it should allocate from a DMA-buf heap or not?
2) How would the driver know which heap to allocate from?
Because “each DMA-BUF heap is a separate character device”.3) How would the heap know how to allocate properly for the device?
Best regards,
Tomasz