Skip to content

Commit

Permalink
media: videobuf2: Replace bufs array by a list
Browse files Browse the repository at this point in the history
Replacing bufs array by a list allows to remove the 32 buffers
limit per queue.

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
  • Loading branch information
Benjamin Gaignard authored and intel-lab-lkp committed Mar 13, 2023
1 parent ca690d4 commit c6ebf39
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
14 changes: 2 additions & 12 deletions drivers/media/common/videobuf2/videobuf2-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,6 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory,
struct vb2_buffer *vb;
int ret;

/* Ensure that q->num_buffers+num_buffers is below VB2_MAX_FRAME */
num_buffers = min_t(unsigned int, num_buffers,
VB2_MAX_FRAME - q->num_buffers);

for (buffer = 0; buffer < num_buffers; ++buffer) {
/* Allocate vb2 buffer structures */
vb = kzalloc(q->buf_struct_size, GFP_KERNEL);
Expand Down Expand Up @@ -797,9 +793,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
/*
* Make sure the requested values and current defaults are sane.
*/
WARN_ON(q->min_buffers_needed > VB2_MAX_FRAME);
num_buffers = max_t(unsigned int, *count, q->min_buffers_needed);
num_buffers = min_t(unsigned int, num_buffers, VB2_MAX_FRAME);
memset(q->alloc_devs, 0, sizeof(q->alloc_devs));
/*
* Set this now to ensure that drivers see the correct q->memory value
Expand Down Expand Up @@ -915,11 +909,6 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory,
bool no_previous_buffers = !q->num_buffers;
int ret;

if (q->num_buffers == VB2_MAX_FRAME) {
dprintk(q, 1, "maximum number of buffers already allocated\n");
return -ENOBUFS;
}

if (no_previous_buffers) {
if (q->waiting_in_dqbuf && *count) {
dprintk(q, 1, "another dup()ped fd is waiting for a buffer\n");
Expand All @@ -944,7 +933,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory,
return -EINVAL;
}

num_buffers = min(*count, VB2_MAX_FRAME - q->num_buffers);
num_buffers = *count;

if (requested_planes && requested_sizes) {
num_planes = requested_planes;
Expand Down Expand Up @@ -2444,6 +2433,7 @@ int vb2_core_queue_init(struct vb2_queue *q)

INIT_LIST_HEAD(&q->queued_list);
INIT_LIST_HEAD(&q->done_list);
INIT_LIST_HEAD(&q->allocated_bufs);
spin_lock_init(&q->done_lock);
mutex_init(&q->mmap_lock);
init_waitqueue_head(&q->done_wq);
Expand Down
19 changes: 13 additions & 6 deletions include/media/videobuf2-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ struct vb2_buffer {
* done_entry: entry on the list that stores all buffers ready
* to be dequeued to userspace
* vb2_plane: per-plane information; do not change
* allocated_entry: entry on the list that stores all buffers allocated
* for the queue.
*/
enum vb2_buffer_state state;
unsigned int synced:1;
Expand All @@ -287,6 +289,7 @@ struct vb2_buffer {
struct vb2_plane planes[VB2_MAX_PLANES];
struct list_head queued_entry;
struct list_head done_entry;
struct list_head allocated_entry;
#ifdef CONFIG_VIDEO_ADV_DEBUG
/*
* Counters for how often these buffer-related ops are
Expand Down Expand Up @@ -556,7 +559,7 @@ struct vb2_buf_ops {
* @mmap_lock: private mutex used when buffers are allocated/freed/mmapped
* @memory: current memory type used
* @dma_dir: DMA mapping direction.
* @bufs: videobuf2 buffer structures
* @allocated_bufs: list of buffer allocated for the queue.
* @num_buffers: number of allocated/used buffers
* @queued_list: list of buffers currently queued from userspace
* @queued_count: number of buffers queued and ready for streaming.
Expand Down Expand Up @@ -619,7 +622,7 @@ struct vb2_queue {
struct mutex mmap_lock;
unsigned int memory;
enum dma_data_direction dma_dir;
struct vb2_buffer *bufs[VB2_MAX_FRAME];
struct list_head allocated_bufs;
unsigned int num_buffers;

struct list_head queued_list;
Expand Down Expand Up @@ -1239,8 +1242,12 @@ static inline void vb2_clear_last_buffer_dequeued(struct vb2_queue *q)
static inline struct vb2_buffer *vb2_get_buffer(struct vb2_queue *q,
unsigned int index)
{
if (index < q->num_buffers)
return q->bufs[index];
struct vb2_buffer *vb;

list_for_each_entry(vb, &q->allocated_bufs, allocated_entry)
if (vb->index == index)
return vb;

return NULL;
}

Expand All @@ -1251,7 +1258,7 @@ static inline struct vb2_buffer *vb2_get_buffer(struct vb2_queue *q,
*/
static inline void vb2_set_buffer(struct vb2_queue *q, struct vb2_buffer *vb)
{
q->bufs[vb->index] = vb;
list_add_tail(&vb->allocated_entry, &q->allocated_bufs);
}

/**
Expand All @@ -1261,7 +1268,7 @@ static inline void vb2_set_buffer(struct vb2_queue *q, struct vb2_buffer *vb)
*/
static inline void vb2_del_buffer(struct vb2_queue *q, struct vb2_buffer *vb)
{
q->bufs[vb->index] = NULL;
list_del(&vb->allocated_entry);
}

/*
Expand Down

0 comments on commit c6ebf39

Please sign in to comment.