Hi Jacopo, On Mon, Jun 03, 2024 at 05:25:44PM +0200, Jacopo Mondi wrote: > Hello > > I have the need to allocate a scratch buffer to mirror the content of the > vb2_buffer planes (more detail on this on request). > > The allocation of such 'scratch' buffer should ideally be done once, at buffer > creation time (and released at buffer release time ?) > > Looking at the videobuf2 framework implementation I noticed that the ideal entry > point for this would be vb2_queue.buf_ops.init_buffer, which is called in the > __vb2_queue_alloc() call path. > > I have noticed that the vb2_queue.buf_ops members seems to be there to be made > overridable by drivers, but are instead: > > 1) unconditionally set by the framework in vb2_queue_init_name() > 2) the core helpers are not exported > > hence I was wondering if this is the result some half-baked attempt to make > them ovverridable or the possibility of override them was instead deprecated. > As I found no traces of this in the log, I thought it was easier to send an > RFC. > > I also checked what other entry points I could have used to allocate backing > memory for a buffer, and I have considered vb2_queue.vb2_ops.buf_init which > is however called in the vb2_req_prepare() call path (I'm not using the request > API atm) or in the VIDIOC_PREPARE_BUF call path, which requires ad-hoc > instrumentation in user space (something I would like to avoid if possibile). > > What do you think ? I've been thinking more about this. I wonder if you could use .buf_init() for your use case. It's called in three places: - __vb2_queue_alloc() - __prepare_userptr() - __prepare_dmabuf() As your scratch buffer needs are limited to the ISP parameters queue, which should use MMAP only, I think .buf_init() would be just fine. > Jacopo Mondi (3): > media: videobuf2: WARN if !vb2_queue.buf_ops > media: Allow drivers to overwrite vb2_queue.buf_ops > media: rkisp1-params: Override vb2_queue.buf_ops > > .../media/common/videobuf2/videobuf2-core.c | 12 ++++--- > .../media/common/videobuf2/videobuf2-v4l2.c | 34 +++++++++++-------- > .../platform/rockchip/rkisp1/rkisp1-params.c | 18 +++++++++- > include/media/videobuf2-core.h | 7 ++++ > include/media/videobuf2-v4l2.h | 8 +++++ > 5 files changed, 60 insertions(+), 19 deletions(-) -- Regards, Laurent Pinchart