Skip to content

Commit

Permalink
[media] vb2: drop v4l2_format argument from queue_setup
Browse files Browse the repository at this point in the history
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 <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
  • Loading branch information
Hans Verkuil authored and mchehab committed Dec 18, 2015
1 parent ecc2fe2 commit df9ecb0
Show file tree
Hide file tree
Showing 81 changed files with 356 additions and 520 deletions.
11 changes: 5 additions & 6 deletions Documentation/video4linux/v4l2-pci-skeleton.c
Expand Up @@ -163,11 +163,10 @@ static irqreturn_t skeleton_irq(int irq, void *dev_id)
* minimum number: many DMA engines need a minimum of 2 buffers in the
* queue and you need to have another available for userspace processing.
*/
static int queue_setup(struct vb2_queue *vq, const void *parg,
static int queue_setup(struct vb2_queue *vq,
unsigned int *nbuffers, unsigned int *nplanes,
unsigned int sizes[], void *alloc_ctxs[])
{
const struct v4l2_format *fmt = parg;
struct skeleton *skel = vb2_get_drv_priv(vq);

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

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

if (fmt && fmt->fmt.pix.sizeimage < skel->format.sizeimage)
return -EINVAL;
if (*nplanes)
return sizes[0] < skel->format.sizeimage ? -EINVAL : 0;
*nplanes = 1;
sizes[0] = fmt ? fmt->fmt.pix.sizeimage : skel->format.sizeimage;
alloc_ctxs[0] = skel->alloc_ctx;
sizes[0] = skel->format.sizeimage;
return 0;
}

Expand Down
11 changes: 5 additions & 6 deletions drivers/input/touchscreen/sur40.c
Expand Up @@ -644,22 +644,21 @@ static void sur40_disconnect(struct usb_interface *interface)
* minimum number: many DMA engines need a minimum of 2 buffers in the
* queue and you need to have another available for userspace processing.
*/
static int sur40_queue_setup(struct vb2_queue *q, const void *parg,
static int sur40_queue_setup(struct vb2_queue *q,
unsigned int *nbuffers, unsigned int *nplanes,
unsigned int sizes[], void *alloc_ctxs[])
{
const struct v4l2_format *fmt = parg;
struct sur40_state *sur40 = vb2_get_drv_priv(q);

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

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

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

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/dvb-frontends/rtl2832_sdr.c
Expand Up @@ -490,7 +490,7 @@ static int rtl2832_sdr_querycap(struct file *file, void *fh,

/* Videobuf2 operations */
static int rtl2832_sdr_queue_setup(struct vb2_queue *vq,
const void *parg, unsigned int *nbuffers,
unsigned int *nbuffers,
unsigned int *nplanes, unsigned int sizes[], void *alloc_ctxs[])
{
struct rtl2832_sdr_dev *dev = vb2_get_drv_priv(vq);
Expand Down
12 changes: 4 additions & 8 deletions drivers/media/pci/cobalt/cobalt-v4l2.c
Expand Up @@ -43,26 +43,22 @@ static const struct v4l2_dv_timings cea1080p60 = V4L2_DV_BT_CEA_1920X1080P60;

/* vb2 DMA streaming ops */

static int cobalt_queue_setup(struct vb2_queue *q, const void *parg,
static int cobalt_queue_setup(struct vb2_queue *q,
unsigned int *num_buffers, unsigned int *num_planes,
unsigned int sizes[], void *alloc_ctxs[])
{
const struct v4l2_format *fmt = parg;
struct cobalt_stream *s = q->drv_priv;
unsigned size = s->stride * s->height;

if (*num_buffers < 3)
*num_buffers = 3;
if (*num_buffers > NR_BUFS)
*num_buffers = NR_BUFS;
alloc_ctxs[0] = s->cobalt->alloc_ctx;
if (*num_planes)
return sizes[0] < size ? -EINVAL : 0;
*num_planes = 1;
if (fmt) {
if (fmt->fmt.pix.sizeimage < size)
return -EINVAL;
size = fmt->fmt.pix.sizeimage;
}
sizes[0] = size;
alloc_ctxs[0] = s->cobalt->alloc_ctx;
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/media/pci/cx23885/cx23885-417.c
Expand Up @@ -1138,7 +1138,7 @@ static int cx23885_initialize_codec(struct cx23885_dev *dev, int startencoder)

/* ------------------------------------------------------------------ */

static int queue_setup(struct vb2_queue *q, const void *parg,
static int queue_setup(struct vb2_queue *q,
unsigned int *num_buffers, unsigned int *num_planes,
unsigned int sizes[], void *alloc_ctxs[])
{
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/pci/cx23885/cx23885-dvb.c
Expand Up @@ -92,7 +92,7 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);

/* ------------------------------------------------------------------ */

static int queue_setup(struct vb2_queue *q, const void *parg,
static int queue_setup(struct vb2_queue *q,
unsigned int *num_buffers, unsigned int *num_planes,
unsigned int sizes[], void *alloc_ctxs[])
{
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/pci/cx23885/cx23885-vbi.c
Expand Up @@ -120,7 +120,7 @@ static int cx23885_start_vbi_dma(struct cx23885_dev *dev,

/* ------------------------------------------------------------------ */

static int queue_setup(struct vb2_queue *q, const void *parg,
static int queue_setup(struct vb2_queue *q,
unsigned int *num_buffers, unsigned int *num_planes,
unsigned int sizes[], void *alloc_ctxs[])
{
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/pci/cx23885/cx23885-video.c
Expand Up @@ -333,7 +333,7 @@ static int cx23885_start_video_dma(struct cx23885_dev *dev,
return 0;
}

static int queue_setup(struct vb2_queue *q, const void *parg,
static int queue_setup(struct vb2_queue *q,
unsigned int *num_buffers, unsigned int *num_planes,
unsigned int sizes[], void *alloc_ctxs[])
{
Expand Down
12 changes: 6 additions & 6 deletions drivers/media/pci/cx25821/cx25821-video.c
Expand Up @@ -141,20 +141,20 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
return handled;
}

static int cx25821_queue_setup(struct vb2_queue *q, const void *parg,
static int cx25821_queue_setup(struct vb2_queue *q,
unsigned int *num_buffers, unsigned int *num_planes,
unsigned int sizes[], void *alloc_ctxs[])
{
const struct v4l2_format *fmt = parg;
struct cx25821_channel *chan = q->drv_priv;
unsigned size = (chan->fmt->depth * chan->width * chan->height) >> 3;

if (fmt && fmt->fmt.pix.sizeimage < size)
return -EINVAL;
alloc_ctxs[0] = chan->dev->alloc_ctx;

if (*num_planes)
return sizes[0] < size ? -EINVAL : 0;

*num_planes = 1;
sizes[0] = fmt ? fmt->fmt.pix.sizeimage : size;
alloc_ctxs[0] = chan->dev->alloc_ctx;
sizes[0] = size;
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/media/pci/cx88/cx88-blackbird.c
Expand Up @@ -637,7 +637,7 @@ static int blackbird_stop_codec(struct cx8802_dev *dev)

/* ------------------------------------------------------------------ */

static int queue_setup(struct vb2_queue *q, const void *parg,
static int queue_setup(struct vb2_queue *q,
unsigned int *num_buffers, unsigned int *num_planes,
unsigned int sizes[], void *alloc_ctxs[])
{
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/pci/cx88/cx88-dvb.c
Expand Up @@ -82,7 +82,7 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);

/* ------------------------------------------------------------------ */

static int queue_setup(struct vb2_queue *q, const void *parg,
static int queue_setup(struct vb2_queue *q,
unsigned int *num_buffers, unsigned int *num_planes,
unsigned int sizes[], void *alloc_ctxs[])
{
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/pci/cx88/cx88-vbi.c
Expand Up @@ -107,7 +107,7 @@ int cx8800_restart_vbi_queue(struct cx8800_dev *dev,

/* ------------------------------------------------------------------ */

static int queue_setup(struct vb2_queue *q, const void *parg,
static int queue_setup(struct vb2_queue *q,
unsigned int *num_buffers, unsigned int *num_planes,
unsigned int sizes[], void *alloc_ctxs[])
{
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/pci/cx88/cx88-video.c
Expand Up @@ -429,7 +429,7 @@ static int restart_video_queue(struct cx8800_dev *dev,

/* ------------------------------------------------------------------ */

static int queue_setup(struct vb2_queue *q, const void *parg,
static int queue_setup(struct vb2_queue *q,
unsigned int *num_buffers, unsigned int *num_planes,
unsigned int sizes[], void *alloc_ctxs[])
{
Expand Down
11 changes: 5 additions & 6 deletions drivers/media/pci/dt3155/dt3155.c
Expand Up @@ -131,22 +131,21 @@ static int wait_i2c_reg(void __iomem *addr)
}

static int
dt3155_queue_setup(struct vb2_queue *vq, const void *parg,
dt3155_queue_setup(struct vb2_queue *vq,
unsigned int *nbuffers, unsigned int *num_planes,
unsigned int sizes[], void *alloc_ctxs[])

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

if (vq->num_buffers + *nbuffers < 2)
*nbuffers = 2 - vq->num_buffers;
if (fmt && fmt->fmt.pix.sizeimage < size)
return -EINVAL;
*num_planes = 1;
sizes[0] = fmt ? fmt->fmt.pix.sizeimage : size;
alloc_ctxs[0] = pd->alloc_ctx;
if (*num_planes)
return sizes[0] < size ? -EINVAL : 0;
*num_planes = 1;
sizes[0] = size;
return 0;
}

Expand Down
1 change: 0 additions & 1 deletion drivers/media/pci/netup_unidvb/netup_unidvb_core.c
Expand Up @@ -277,7 +277,6 @@ static irqreturn_t netup_unidvb_isr(int irq, void *dev_id)
}

static int netup_unidvb_queue_setup(struct vb2_queue *vq,
const void *parg,
unsigned int *nbuffers,
unsigned int *nplanes,
unsigned int sizes[],
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/pci/saa7134/saa7134-ts.c
Expand Up @@ -116,7 +116,7 @@ int saa7134_ts_buffer_prepare(struct vb2_buffer *vb2)
}
EXPORT_SYMBOL_GPL(saa7134_ts_buffer_prepare);

int saa7134_ts_queue_setup(struct vb2_queue *q, const void *parg,
int saa7134_ts_queue_setup(struct vb2_queue *q,
unsigned int *nbuffers, unsigned int *nplanes,
unsigned int sizes[], void *alloc_ctxs[])
{
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/pci/saa7134/saa7134-vbi.c
Expand Up @@ -138,7 +138,7 @@ static int buffer_prepare(struct vb2_buffer *vb2)
saa7134_buffer_startpage(buf));
}

static int queue_setup(struct vb2_queue *q, const void *parg,
static int queue_setup(struct vb2_queue *q,
unsigned int *nbuffers, unsigned int *nplanes,
unsigned int sizes[], void *alloc_ctxs[])
{
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/pci/saa7134/saa7134-video.c
Expand Up @@ -904,7 +904,7 @@ static int buffer_prepare(struct vb2_buffer *vb2)
saa7134_buffer_startpage(buf));
}

static int queue_setup(struct vb2_queue *q, const void *parg,
static int queue_setup(struct vb2_queue *q,
unsigned int *nbuffers, unsigned int *nplanes,
unsigned int sizes[], void *alloc_ctxs[])
{
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/pci/saa7134/saa7134.h
Expand Up @@ -820,7 +820,7 @@ void saa7134_video_fini(struct saa7134_dev *dev);

int saa7134_ts_buffer_init(struct vb2_buffer *vb2);
int saa7134_ts_buffer_prepare(struct vb2_buffer *vb2);
int saa7134_ts_queue_setup(struct vb2_queue *q, const void *parg,
int saa7134_ts_queue_setup(struct vb2_queue *q,
unsigned int *nbuffers, unsigned int *nplanes,
unsigned int sizes[], void *alloc_ctxs[]);
int saa7134_ts_start_streaming(struct vb2_queue *vq, unsigned int count);
Expand Down
1 change: 0 additions & 1 deletion drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c
Expand Up @@ -663,7 +663,6 @@ static int solo_ring_thread(void *data)
}

static int solo_enc_queue_setup(struct vb2_queue *q,
const void *parg,
unsigned int *num_buffers,
unsigned int *num_planes, unsigned int sizes[],
void *alloc_ctxs[])
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/pci/solo6x10/solo6x10-v4l2.c
Expand Up @@ -313,7 +313,7 @@ static void solo_stop_thread(struct solo_dev *solo_dev)
solo_dev->kthread = NULL;
}

static int solo_queue_setup(struct vb2_queue *q, const void *parg,
static int solo_queue_setup(struct vb2_queue *q,
unsigned int *num_buffers, unsigned int *num_planes,
unsigned int sizes[], void *alloc_ctxs[])
{
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/pci/sta2x11/sta2x11_vip.c
Expand Up @@ -265,7 +265,7 @@ static void vip_active_buf_next(struct sta2x11_vip *vip)


/* Videobuf2 Operations */
static int queue_setup(struct vb2_queue *vq, const void *parg,
static int queue_setup(struct vb2_queue *vq,
unsigned int *nbuffers, unsigned int *nplanes,
unsigned int sizes[], void *alloc_ctxs[])
{
Expand Down
20 changes: 10 additions & 10 deletions drivers/media/pci/tw68/tw68-video.c
Expand Up @@ -376,28 +376,28 @@ static int tw68_buffer_count(unsigned int size, unsigned int count)
/* ------------------------------------------------------------- */
/* vb2 queue operations */

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

sizes[0] = (dev->fmt->depth * dev->width * dev->height) >> 3;
if (tot_bufs < 2)
tot_bufs = 2;
tot_bufs = tw68_buffer_count(size, tot_bufs);
*num_buffers = tot_bufs - q->num_buffers;
alloc_ctxs[0] = dev->alloc_ctx;
/*
* We allow create_bufs, but only if the sizeimage is the same as the
* We allow create_bufs, but only if the sizeimage is >= as the
* current sizeimage. The tw68_buffer_count calculation becomes quite
* difficult otherwise.
*/
if (fmt && fmt->fmt.pix.sizeimage < sizes[0])
return -EINVAL;
if (*num_planes)
return sizes[0] < size ? -EINVAL : 0;
*num_planes = 1;
if (tot_bufs < 2)
tot_bufs = 2;
tot_bufs = tw68_buffer_count(sizes[0], tot_bufs);
*num_buffers = tot_bufs - q->num_buffers;
sizes[0] = size;

return 0;
}
Expand Down
17 changes: 9 additions & 8 deletions drivers/media/platform/am437x/am437x-vpfe.c
Expand Up @@ -1898,7 +1898,6 @@ static void vpfe_calculate_offsets(struct vpfe_device *vpfe)
/*
* vpfe_queue_setup - Callback function for buffer setup.
* @vq: vb2_queue ptr
* @fmt: v4l2 format
* @nbuffers: ptr to number of buffers requested by application
* @nplanes:: contains number of distinct video planes needed to hold a frame
* @sizes[]: contains the size (in bytes) of each plane.
Expand All @@ -1908,22 +1907,24 @@ static void vpfe_calculate_offsets(struct vpfe_device *vpfe)
* the buffer count and buffer size
*/
static int vpfe_queue_setup(struct vb2_queue *vq,
const void *parg,
unsigned int *nbuffers, unsigned int *nplanes,
unsigned int sizes[], void *alloc_ctxs[])
{
const struct v4l2_format *fmt = parg;
struct vpfe_device *vpfe = vb2_get_drv_priv(vq);

if (fmt && fmt->fmt.pix.sizeimage < vpfe->fmt.fmt.pix.sizeimage)
return -EINVAL;
unsigned size = vpfe->fmt.fmt.pix.sizeimage;

if (vq->num_buffers + *nbuffers < 3)
*nbuffers = 3 - vq->num_buffers;
alloc_ctxs[0] = vpfe->alloc_ctx;

if (*nplanes) {
if (sizes[0] < size)
return -EINVAL;
size = sizes[0];
}

*nplanes = 1;
sizes[0] = fmt ? fmt->fmt.pix.sizeimage : vpfe->fmt.fmt.pix.sizeimage;
alloc_ctxs[0] = vpfe->alloc_ctx;
sizes[0] = size;

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

0 comments on commit df9ecb0

Please sign in to comment.