Skip to content

Commit df9ecb0

Browse files
Hans Verkuilmchehab
Hans Verkuil
authored andcommitted
[media] vb2: drop v4l2_format argument from queue_setup
The queue_setup callback has a void pointer that is just for V4L2 and is the pointer to the v4l2_format struct that was passed to VIDIOC_CREATE_BUFS. The idea was that drivers would use the information from that struct to buffers suitable for the requested format. After the vb2 split series this pointer is now a void pointer, which is ugly, and the reality is that all existing drivers will effectively just look at the sizeimage field of v4l2_format. To make this more generic the queue_setup callback is changed: the void pointer is dropped, instead if the *num_planes argument is 0, then use the current format size, if it is non-zero, then it contains the number of requested planes and the sizes array contains the requested sizes. If either is unsupported, then return -EINVAL, otherwise use the requested size(s). Signed-off-by: Hans Verkuil <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent ecc2fe2 commit df9ecb0

File tree

81 files changed

+356
-520
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+356
-520
lines changed

Documentation/video4linux/v4l2-pci-skeleton.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,10 @@ static irqreturn_t skeleton_irq(int irq, void *dev_id)
163163
* minimum number: many DMA engines need a minimum of 2 buffers in the
164164
* queue and you need to have another available for userspace processing.
165165
*/
166-
static int queue_setup(struct vb2_queue *vq, const void *parg,
166+
static int queue_setup(struct vb2_queue *vq,
167167
unsigned int *nbuffers, unsigned int *nplanes,
168168
unsigned int sizes[], void *alloc_ctxs[])
169169
{
170-
const struct v4l2_format *fmt = parg;
171170
struct skeleton *skel = vb2_get_drv_priv(vq);
172171

173172
skel->field = skel->format.field;
@@ -183,12 +182,12 @@ static int queue_setup(struct vb2_queue *vq, const void *parg,
183182

184183
if (vq->num_buffers + *nbuffers < 3)
185184
*nbuffers = 3 - vq->num_buffers;
185+
alloc_ctxs[0] = skel->alloc_ctx;
186186

187-
if (fmt && fmt->fmt.pix.sizeimage < skel->format.sizeimage)
188-
return -EINVAL;
187+
if (*nplanes)
188+
return sizes[0] < skel->format.sizeimage ? -EINVAL : 0;
189189
*nplanes = 1;
190-
sizes[0] = fmt ? fmt->fmt.pix.sizeimage : skel->format.sizeimage;
191-
alloc_ctxs[0] = skel->alloc_ctx;
190+
sizes[0] = skel->format.sizeimage;
192191
return 0;
193192
}
194193

drivers/input/touchscreen/sur40.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -644,22 +644,21 @@ static void sur40_disconnect(struct usb_interface *interface)
644644
* minimum number: many DMA engines need a minimum of 2 buffers in the
645645
* queue and you need to have another available for userspace processing.
646646
*/
647-
static int sur40_queue_setup(struct vb2_queue *q, const void *parg,
647+
static int sur40_queue_setup(struct vb2_queue *q,
648648
unsigned int *nbuffers, unsigned int *nplanes,
649649
unsigned int sizes[], void *alloc_ctxs[])
650650
{
651-
const struct v4l2_format *fmt = parg;
652651
struct sur40_state *sur40 = vb2_get_drv_priv(q);
653652

654653
if (q->num_buffers + *nbuffers < 3)
655654
*nbuffers = 3 - q->num_buffers;
655+
alloc_ctxs[0] = sur40->alloc_ctx;
656656

657-
if (fmt && fmt->fmt.pix.sizeimage < sur40_video_format.sizeimage)
658-
return -EINVAL;
657+
if (*nplanes)
658+
return sizes[0] < sur40_video_format.sizeimage ? -EINVAL : 0;
659659

660660
*nplanes = 1;
661-
sizes[0] = fmt ? fmt->fmt.pix.sizeimage : sur40_video_format.sizeimage;
662-
alloc_ctxs[0] = sur40->alloc_ctx;
661+
sizes[0] = sur40_video_format.sizeimage;
663662

664663
return 0;
665664
}

drivers/media/dvb-frontends/rtl2832_sdr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ static int rtl2832_sdr_querycap(struct file *file, void *fh,
490490

491491
/* Videobuf2 operations */
492492
static int rtl2832_sdr_queue_setup(struct vb2_queue *vq,
493-
const void *parg, unsigned int *nbuffers,
493+
unsigned int *nbuffers,
494494
unsigned int *nplanes, unsigned int sizes[], void *alloc_ctxs[])
495495
{
496496
struct rtl2832_sdr_dev *dev = vb2_get_drv_priv(vq);

drivers/media/pci/cobalt/cobalt-v4l2.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,22 @@ static const struct v4l2_dv_timings cea1080p60 = V4L2_DV_BT_CEA_1920X1080P60;
4343

4444
/* vb2 DMA streaming ops */
4545

46-
static int cobalt_queue_setup(struct vb2_queue *q, const void *parg,
46+
static int cobalt_queue_setup(struct vb2_queue *q,
4747
unsigned int *num_buffers, unsigned int *num_planes,
4848
unsigned int sizes[], void *alloc_ctxs[])
4949
{
50-
const struct v4l2_format *fmt = parg;
5150
struct cobalt_stream *s = q->drv_priv;
5251
unsigned size = s->stride * s->height;
5352

5453
if (*num_buffers < 3)
5554
*num_buffers = 3;
5655
if (*num_buffers > NR_BUFS)
5756
*num_buffers = NR_BUFS;
57+
alloc_ctxs[0] = s->cobalt->alloc_ctx;
58+
if (*num_planes)
59+
return sizes[0] < size ? -EINVAL : 0;
5860
*num_planes = 1;
59-
if (fmt) {
60-
if (fmt->fmt.pix.sizeimage < size)
61-
return -EINVAL;
62-
size = fmt->fmt.pix.sizeimage;
63-
}
6461
sizes[0] = size;
65-
alloc_ctxs[0] = s->cobalt->alloc_ctx;
6662
return 0;
6763
}
6864

drivers/media/pci/cx23885/cx23885-417.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ static int cx23885_initialize_codec(struct cx23885_dev *dev, int startencoder)
11381138

11391139
/* ------------------------------------------------------------------ */
11401140

1141-
static int queue_setup(struct vb2_queue *q, const void *parg,
1141+
static int queue_setup(struct vb2_queue *q,
11421142
unsigned int *num_buffers, unsigned int *num_planes,
11431143
unsigned int sizes[], void *alloc_ctxs[])
11441144
{

drivers/media/pci/cx23885/cx23885-dvb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
9292

9393
/* ------------------------------------------------------------------ */
9494

95-
static int queue_setup(struct vb2_queue *q, const void *parg,
95+
static int queue_setup(struct vb2_queue *q,
9696
unsigned int *num_buffers, unsigned int *num_planes,
9797
unsigned int sizes[], void *alloc_ctxs[])
9898
{

drivers/media/pci/cx23885/cx23885-vbi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static int cx23885_start_vbi_dma(struct cx23885_dev *dev,
120120

121121
/* ------------------------------------------------------------------ */
122122

123-
static int queue_setup(struct vb2_queue *q, const void *parg,
123+
static int queue_setup(struct vb2_queue *q,
124124
unsigned int *num_buffers, unsigned int *num_planes,
125125
unsigned int sizes[], void *alloc_ctxs[])
126126
{

drivers/media/pci/cx23885/cx23885-video.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ static int cx23885_start_video_dma(struct cx23885_dev *dev,
333333
return 0;
334334
}
335335

336-
static int queue_setup(struct vb2_queue *q, const void *parg,
336+
static int queue_setup(struct vb2_queue *q,
337337
unsigned int *num_buffers, unsigned int *num_planes,
338338
unsigned int sizes[], void *alloc_ctxs[])
339339
{

drivers/media/pci/cx25821/cx25821-video.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,20 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
141141
return handled;
142142
}
143143

144-
static int cx25821_queue_setup(struct vb2_queue *q, const void *parg,
144+
static int cx25821_queue_setup(struct vb2_queue *q,
145145
unsigned int *num_buffers, unsigned int *num_planes,
146146
unsigned int sizes[], void *alloc_ctxs[])
147147
{
148-
const struct v4l2_format *fmt = parg;
149148
struct cx25821_channel *chan = q->drv_priv;
150149
unsigned size = (chan->fmt->depth * chan->width * chan->height) >> 3;
151150

152-
if (fmt && fmt->fmt.pix.sizeimage < size)
153-
return -EINVAL;
151+
alloc_ctxs[0] = chan->dev->alloc_ctx;
152+
153+
if (*num_planes)
154+
return sizes[0] < size ? -EINVAL : 0;
154155

155156
*num_planes = 1;
156-
sizes[0] = fmt ? fmt->fmt.pix.sizeimage : size;
157-
alloc_ctxs[0] = chan->dev->alloc_ctx;
157+
sizes[0] = size;
158158
return 0;
159159
}
160160

drivers/media/pci/cx88/cx88-blackbird.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ static int blackbird_stop_codec(struct cx8802_dev *dev)
637637

638638
/* ------------------------------------------------------------------ */
639639

640-
static int queue_setup(struct vb2_queue *q, const void *parg,
640+
static int queue_setup(struct vb2_queue *q,
641641
unsigned int *num_buffers, unsigned int *num_planes,
642642
unsigned int sizes[], void *alloc_ctxs[])
643643
{

drivers/media/pci/cx88/cx88-dvb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
8282

8383
/* ------------------------------------------------------------------ */
8484

85-
static int queue_setup(struct vb2_queue *q, const void *parg,
85+
static int queue_setup(struct vb2_queue *q,
8686
unsigned int *num_buffers, unsigned int *num_planes,
8787
unsigned int sizes[], void *alloc_ctxs[])
8888
{

drivers/media/pci/cx88/cx88-vbi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ int cx8800_restart_vbi_queue(struct cx8800_dev *dev,
107107

108108
/* ------------------------------------------------------------------ */
109109

110-
static int queue_setup(struct vb2_queue *q, const void *parg,
110+
static int queue_setup(struct vb2_queue *q,
111111
unsigned int *num_buffers, unsigned int *num_planes,
112112
unsigned int sizes[], void *alloc_ctxs[])
113113
{

drivers/media/pci/cx88/cx88-video.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ static int restart_video_queue(struct cx8800_dev *dev,
429429

430430
/* ------------------------------------------------------------------ */
431431

432-
static int queue_setup(struct vb2_queue *q, const void *parg,
432+
static int queue_setup(struct vb2_queue *q,
433433
unsigned int *num_buffers, unsigned int *num_planes,
434434
unsigned int sizes[], void *alloc_ctxs[])
435435
{

drivers/media/pci/dt3155/dt3155.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,21 @@ static int wait_i2c_reg(void __iomem *addr)
131131
}
132132

133133
static int
134-
dt3155_queue_setup(struct vb2_queue *vq, const void *parg,
134+
dt3155_queue_setup(struct vb2_queue *vq,
135135
unsigned int *nbuffers, unsigned int *num_planes,
136136
unsigned int sizes[], void *alloc_ctxs[])
137137

138138
{
139-
const struct v4l2_format *fmt = parg;
140139
struct dt3155_priv *pd = vb2_get_drv_priv(vq);
141140
unsigned size = pd->width * pd->height;
142141

143142
if (vq->num_buffers + *nbuffers < 2)
144143
*nbuffers = 2 - vq->num_buffers;
145-
if (fmt && fmt->fmt.pix.sizeimage < size)
146-
return -EINVAL;
147-
*num_planes = 1;
148-
sizes[0] = fmt ? fmt->fmt.pix.sizeimage : size;
149144
alloc_ctxs[0] = pd->alloc_ctx;
145+
if (*num_planes)
146+
return sizes[0] < size ? -EINVAL : 0;
147+
*num_planes = 1;
148+
sizes[0] = size;
150149
return 0;
151150
}
152151

drivers/media/pci/netup_unidvb/netup_unidvb_core.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ static irqreturn_t netup_unidvb_isr(int irq, void *dev_id)
277277
}
278278

279279
static int netup_unidvb_queue_setup(struct vb2_queue *vq,
280-
const void *parg,
281280
unsigned int *nbuffers,
282281
unsigned int *nplanes,
283282
unsigned int sizes[],

drivers/media/pci/saa7134/saa7134-ts.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ int saa7134_ts_buffer_prepare(struct vb2_buffer *vb2)
116116
}
117117
EXPORT_SYMBOL_GPL(saa7134_ts_buffer_prepare);
118118

119-
int saa7134_ts_queue_setup(struct vb2_queue *q, const void *parg,
119+
int saa7134_ts_queue_setup(struct vb2_queue *q,
120120
unsigned int *nbuffers, unsigned int *nplanes,
121121
unsigned int sizes[], void *alloc_ctxs[])
122122
{

drivers/media/pci/saa7134/saa7134-vbi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static int buffer_prepare(struct vb2_buffer *vb2)
138138
saa7134_buffer_startpage(buf));
139139
}
140140

141-
static int queue_setup(struct vb2_queue *q, const void *parg,
141+
static int queue_setup(struct vb2_queue *q,
142142
unsigned int *nbuffers, unsigned int *nplanes,
143143
unsigned int sizes[], void *alloc_ctxs[])
144144
{

drivers/media/pci/saa7134/saa7134-video.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ static int buffer_prepare(struct vb2_buffer *vb2)
904904
saa7134_buffer_startpage(buf));
905905
}
906906

907-
static int queue_setup(struct vb2_queue *q, const void *parg,
907+
static int queue_setup(struct vb2_queue *q,
908908
unsigned int *nbuffers, unsigned int *nplanes,
909909
unsigned int sizes[], void *alloc_ctxs[])
910910
{

drivers/media/pci/saa7134/saa7134.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ void saa7134_video_fini(struct saa7134_dev *dev);
820820

821821
int saa7134_ts_buffer_init(struct vb2_buffer *vb2);
822822
int saa7134_ts_buffer_prepare(struct vb2_buffer *vb2);
823-
int saa7134_ts_queue_setup(struct vb2_queue *q, const void *parg,
823+
int saa7134_ts_queue_setup(struct vb2_queue *q,
824824
unsigned int *nbuffers, unsigned int *nplanes,
825825
unsigned int sizes[], void *alloc_ctxs[]);
826826
int saa7134_ts_start_streaming(struct vb2_queue *vq, unsigned int count);

drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,6 @@ static int solo_ring_thread(void *data)
663663
}
664664

665665
static int solo_enc_queue_setup(struct vb2_queue *q,
666-
const void *parg,
667666
unsigned int *num_buffers,
668667
unsigned int *num_planes, unsigned int sizes[],
669668
void *alloc_ctxs[])

drivers/media/pci/solo6x10/solo6x10-v4l2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ static void solo_stop_thread(struct solo_dev *solo_dev)
313313
solo_dev->kthread = NULL;
314314
}
315315

316-
static int solo_queue_setup(struct vb2_queue *q, const void *parg,
316+
static int solo_queue_setup(struct vb2_queue *q,
317317
unsigned int *num_buffers, unsigned int *num_planes,
318318
unsigned int sizes[], void *alloc_ctxs[])
319319
{

drivers/media/pci/sta2x11/sta2x11_vip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ static void vip_active_buf_next(struct sta2x11_vip *vip)
265265

266266

267267
/* Videobuf2 Operations */
268-
static int queue_setup(struct vb2_queue *vq, const void *parg,
268+
static int queue_setup(struct vb2_queue *vq,
269269
unsigned int *nbuffers, unsigned int *nplanes,
270270
unsigned int sizes[], void *alloc_ctxs[])
271271
{

drivers/media/pci/tw68/tw68-video.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -376,28 +376,28 @@ static int tw68_buffer_count(unsigned int size, unsigned int count)
376376
/* ------------------------------------------------------------- */
377377
/* vb2 queue operations */
378378

379-
static int tw68_queue_setup(struct vb2_queue *q, const void *parg,
379+
static int tw68_queue_setup(struct vb2_queue *q,
380380
unsigned int *num_buffers, unsigned int *num_planes,
381381
unsigned int sizes[], void *alloc_ctxs[])
382382
{
383-
const struct v4l2_format *fmt = parg;
384383
struct tw68_dev *dev = vb2_get_drv_priv(q);
385384
unsigned tot_bufs = q->num_buffers + *num_buffers;
385+
unsigned size = (dev->fmt->depth * dev->width * dev->height) >> 3;
386386

387-
sizes[0] = (dev->fmt->depth * dev->width * dev->height) >> 3;
387+
if (tot_bufs < 2)
388+
tot_bufs = 2;
389+
tot_bufs = tw68_buffer_count(size, tot_bufs);
390+
*num_buffers = tot_bufs - q->num_buffers;
388391
alloc_ctxs[0] = dev->alloc_ctx;
389392
/*
390-
* We allow create_bufs, but only if the sizeimage is the same as the
393+
* We allow create_bufs, but only if the sizeimage is >= as the
391394
* current sizeimage. The tw68_buffer_count calculation becomes quite
392395
* difficult otherwise.
393396
*/
394-
if (fmt && fmt->fmt.pix.sizeimage < sizes[0])
395-
return -EINVAL;
397+
if (*num_planes)
398+
return sizes[0] < size ? -EINVAL : 0;
396399
*num_planes = 1;
397-
if (tot_bufs < 2)
398-
tot_bufs = 2;
399-
tot_bufs = tw68_buffer_count(sizes[0], tot_bufs);
400-
*num_buffers = tot_bufs - q->num_buffers;
400+
sizes[0] = size;
401401

402402
return 0;
403403
}

drivers/media/platform/am437x/am437x-vpfe.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,7 +1898,6 @@ static void vpfe_calculate_offsets(struct vpfe_device *vpfe)
18981898
/*
18991899
* vpfe_queue_setup - Callback function for buffer setup.
19001900
* @vq: vb2_queue ptr
1901-
* @fmt: v4l2 format
19021901
* @nbuffers: ptr to number of buffers requested by application
19031902
* @nplanes:: contains number of distinct video planes needed to hold a frame
19041903
* @sizes[]: contains the size (in bytes) of each plane.
@@ -1908,22 +1907,24 @@ static void vpfe_calculate_offsets(struct vpfe_device *vpfe)
19081907
* the buffer count and buffer size
19091908
*/
19101909
static int vpfe_queue_setup(struct vb2_queue *vq,
1911-
const void *parg,
19121910
unsigned int *nbuffers, unsigned int *nplanes,
19131911
unsigned int sizes[], void *alloc_ctxs[])
19141912
{
1915-
const struct v4l2_format *fmt = parg;
19161913
struct vpfe_device *vpfe = vb2_get_drv_priv(vq);
1917-
1918-
if (fmt && fmt->fmt.pix.sizeimage < vpfe->fmt.fmt.pix.sizeimage)
1919-
return -EINVAL;
1914+
unsigned size = vpfe->fmt.fmt.pix.sizeimage;
19201915

19211916
if (vq->num_buffers + *nbuffers < 3)
19221917
*nbuffers = 3 - vq->num_buffers;
1918+
alloc_ctxs[0] = vpfe->alloc_ctx;
1919+
1920+
if (*nplanes) {
1921+
if (sizes[0] < size)
1922+
return -EINVAL;
1923+
size = sizes[0];
1924+
}
19231925

19241926
*nplanes = 1;
1925-
sizes[0] = fmt ? fmt->fmt.pix.sizeimage : vpfe->fmt.fmt.pix.sizeimage;
1926-
alloc_ctxs[0] = vpfe->alloc_ctx;
1927+
sizes[0] = size;
19271928

19281929
vpfe_dbg(1, vpfe,
19291930
"nbuffers=%d, size=%u\n", *nbuffers, sizes[0]);

0 commit comments

Comments
 (0)