Skip to content

Commit 14a996c

Browse files
committed
Merge tag 'media/v4.20-5' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media
Pull media fixes from Mauro Carvalho Chehab: - one regression at vsp1 driver - some last time changes for the upcoming request API logic and for stateless codec support. As the stateless codec "cedrus" driver is at staging, don't apply the MPEG controls as part of the main V4L2 API, as those may not be ready for production yet. * tag 'media/v4.20-5' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: media: Add a Kconfig option for the Request API media: extended-controls.rst: add note to the MPEG2 state controls media: mpeg2-ctrls.h: move MPEG2 state controls to non-public header media: vicodec: set state resolution from raw format media: vivid: drop v4l2_ctrl_request_complete() from start_streaming media: vb2: don't unbind/put the object when going to state QUEUED media: vb2: keep a reference to the request until dqbuf media: vb2: skip request checks for VIDIOC_PREPARE_BUF media: vb2: don't call __vb2_queue_cancel if vb2_start_streaming failed media: cedrus: Fix a NULL vs IS_ERR() check media: vsp1: Fix LIF buffer thresholds
2 parents e6333d7 + 078ab3e commit 14a996c

File tree

20 files changed

+181
-103
lines changed

20 files changed

+181
-103
lines changed

Documentation/media/uapi/v4l/extended-controls.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,11 @@ enum v4l2_mpeg_video_h264_hierarchical_coding_type -
15051505
configuring a stateless hardware decoding pipeline for MPEG-2.
15061506
The bitstream parameters are defined according to :ref:`mpeg2part2`.
15071507

1508+
.. note::
1509+
1510+
This compound control is not yet part of the public kernel API and
1511+
it is expected to change.
1512+
15081513
.. c:type:: v4l2_ctrl_mpeg2_slice_params
15091514
15101515
.. cssclass:: longtable
@@ -1625,6 +1630,11 @@ enum v4l2_mpeg_video_h264_hierarchical_coding_type -
16251630
Specifies quantization matrices (as extracted from the bitstream) for the
16261631
associated MPEG-2 slice data.
16271632

1633+
.. note::
1634+
1635+
This compound control is not yet part of the public kernel API and
1636+
it is expected to change.
1637+
16281638
.. c:type:: v4l2_ctrl_mpeg2_quantization
16291639
16301640
.. cssclass:: longtable

drivers/media/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,19 @@ config MEDIA_CONTROLLER_DVB
110110

111111
This is currently experimental.
112112

113+
config MEDIA_CONTROLLER_REQUEST_API
114+
bool "Enable Media controller Request API (EXPERIMENTAL)"
115+
depends on MEDIA_CONTROLLER && STAGING_MEDIA
116+
default n
117+
---help---
118+
DO NOT ENABLE THIS OPTION UNLESS YOU KNOW WHAT YOU'RE DOING.
119+
120+
This option enables the Request API for the Media controller and V4L2
121+
interfaces. It is currently needed by a few stateless codec drivers.
122+
123+
There is currently no intention to provide API or ABI stability for
124+
this new API as of yet.
125+
113126
#
114127
# Video4Linux support
115128
# Only enables if one of the V4L2 types (ATV, webcam, radio) is selected

drivers/media/common/videobuf2/videobuf2-core.c

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
947947
}
948948
atomic_dec(&q->owned_by_drv_count);
949949

950-
if (vb->req_obj.req) {
950+
if (state != VB2_BUF_STATE_QUEUED && vb->req_obj.req) {
951951
/* This is not supported at the moment */
952952
WARN_ON(state == VB2_BUF_STATE_REQUEUEING);
953953
media_request_object_unbind(&vb->req_obj);
@@ -1359,8 +1359,12 @@ static void vb2_req_release(struct media_request_object *obj)
13591359
{
13601360
struct vb2_buffer *vb = container_of(obj, struct vb2_buffer, req_obj);
13611361

1362-
if (vb->state == VB2_BUF_STATE_IN_REQUEST)
1362+
if (vb->state == VB2_BUF_STATE_IN_REQUEST) {
13631363
vb->state = VB2_BUF_STATE_DEQUEUED;
1364+
if (vb->request)
1365+
media_request_put(vb->request);
1366+
vb->request = NULL;
1367+
}
13641368
}
13651369

13661370
static const struct media_request_object_ops vb2_core_req_ops = {
@@ -1528,6 +1532,18 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb,
15281532
return ret;
15291533

15301534
vb->state = VB2_BUF_STATE_IN_REQUEST;
1535+
1536+
/*
1537+
* Increment the refcount and store the request.
1538+
* The request refcount is decremented again when the
1539+
* buffer is dequeued. This is to prevent vb2_buffer_done()
1540+
* from freeing the request from interrupt context, which can
1541+
* happen if the application closed the request fd after
1542+
* queueing the request.
1543+
*/
1544+
media_request_get(req);
1545+
vb->request = req;
1546+
15311547
/* Fill buffer information for the userspace */
15321548
if (pb) {
15331549
call_void_bufop(q, copy_timestamp, vb, pb);
@@ -1749,10 +1765,6 @@ static void __vb2_dqbuf(struct vb2_buffer *vb)
17491765
call_void_memop(vb, unmap_dmabuf, vb->planes[i].mem_priv);
17501766
vb->planes[i].dbuf_mapped = 0;
17511767
}
1752-
if (vb->req_obj.req) {
1753-
media_request_object_unbind(&vb->req_obj);
1754-
media_request_object_put(&vb->req_obj);
1755-
}
17561768
call_void_bufop(q, init_buffer, vb);
17571769
}
17581770

@@ -1797,6 +1809,14 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb,
17971809
/* go back to dequeued state */
17981810
__vb2_dqbuf(vb);
17991811

1812+
if (WARN_ON(vb->req_obj.req)) {
1813+
media_request_object_unbind(&vb->req_obj);
1814+
media_request_object_put(&vb->req_obj);
1815+
}
1816+
if (vb->request)
1817+
media_request_put(vb->request);
1818+
vb->request = NULL;
1819+
18001820
dprintk(2, "dqbuf of buffer %d, with state %d\n",
18011821
vb->index, vb->state);
18021822

@@ -1903,6 +1923,14 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
19031923
vb->prepared = false;
19041924
}
19051925
__vb2_dqbuf(vb);
1926+
1927+
if (vb->req_obj.req) {
1928+
media_request_object_unbind(&vb->req_obj);
1929+
media_request_object_put(&vb->req_obj);
1930+
}
1931+
if (vb->request)
1932+
media_request_put(vb->request);
1933+
vb->request = NULL;
19061934
}
19071935
}
19081936

@@ -1940,10 +1968,8 @@ int vb2_core_streamon(struct vb2_queue *q, unsigned int type)
19401968
if (ret)
19411969
return ret;
19421970
ret = vb2_start_streaming(q);
1943-
if (ret) {
1944-
__vb2_queue_cancel(q);
1971+
if (ret)
19451972
return ret;
1946-
}
19471973
}
19481974

19491975
q->streaming = 1;

drivers/media/common/videobuf2/videobuf2-v4l2.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,10 @@ static int vb2_fill_vb2_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b
333333
}
334334

335335
static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct media_device *mdev,
336-
struct v4l2_buffer *b,
337-
const char *opname,
336+
struct v4l2_buffer *b, bool is_prepare,
338337
struct media_request **p_req)
339338
{
339+
const char *opname = is_prepare ? "prepare_buf" : "qbuf";
340340
struct media_request *req;
341341
struct vb2_v4l2_buffer *vbuf;
342342
struct vb2_buffer *vb;
@@ -378,6 +378,9 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct media_device *md
378378
return ret;
379379
}
380380

381+
if (is_prepare)
382+
return 0;
383+
381384
if (!(b->flags & V4L2_BUF_FLAG_REQUEST_FD)) {
382385
if (q->uses_requests) {
383386
dprintk(1, "%s: queue uses requests\n", opname);
@@ -631,8 +634,10 @@ static void fill_buf_caps(struct vb2_queue *q, u32 *caps)
631634
*caps |= V4L2_BUF_CAP_SUPPORTS_USERPTR;
632635
if (q->io_modes & VB2_DMABUF)
633636
*caps |= V4L2_BUF_CAP_SUPPORTS_DMABUF;
637+
#ifdef CONFIG_MEDIA_CONTROLLER_REQUEST_API
634638
if (q->supports_requests)
635639
*caps |= V4L2_BUF_CAP_SUPPORTS_REQUESTS;
640+
#endif
636641
}
637642

638643
int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
@@ -657,7 +662,7 @@ int vb2_prepare_buf(struct vb2_queue *q, struct media_device *mdev,
657662
if (b->flags & V4L2_BUF_FLAG_REQUEST_FD)
658663
return -EINVAL;
659664

660-
ret = vb2_queue_or_prepare_buf(q, mdev, b, "prepare_buf", NULL);
665+
ret = vb2_queue_or_prepare_buf(q, mdev, b, true, NULL);
661666

662667
return ret ? ret : vb2_core_prepare_buf(q, b->index, b);
663668
}
@@ -729,7 +734,7 @@ int vb2_qbuf(struct vb2_queue *q, struct media_device *mdev,
729734
return -EBUSY;
730735
}
731736

732-
ret = vb2_queue_or_prepare_buf(q, mdev, b, "qbuf", &req);
737+
ret = vb2_queue_or_prepare_buf(q, mdev, b, false, &req);
733738
if (ret)
734739
return ret;
735740
ret = vb2_core_qbuf(q, b->index, b, req);

drivers/media/media-device.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,14 @@ static long media_device_get_topology(struct media_device *mdev, void *arg)
381381
static long media_device_request_alloc(struct media_device *mdev,
382382
int *alloc_fd)
383383
{
384+
#ifdef CONFIG_MEDIA_CONTROLLER_REQUEST_API
384385
if (!mdev->ops || !mdev->ops->req_validate || !mdev->ops->req_queue)
385386
return -ENOTTY;
386387

387388
return media_request_alloc(mdev, alloc_fd);
389+
#else
390+
return -ENOTTY;
391+
#endif
388392
}
389393

390394
static long copy_arg_from_user(void *karg, void __user *uarg, unsigned int cmd)

drivers/media/platform/vicodec/vicodec-core.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -997,11 +997,18 @@ static int vicodec_start_streaming(struct vb2_queue *q,
997997

998998
q_data->sequence = 0;
999999

1000-
if (!V4L2_TYPE_IS_OUTPUT(q->type))
1000+
if (!V4L2_TYPE_IS_OUTPUT(q->type)) {
1001+
if (!ctx->is_enc) {
1002+
state->width = q_data->width;
1003+
state->height = q_data->height;
1004+
}
10011005
return 0;
1006+
}
10021007

1003-
state->width = q_data->width;
1004-
state->height = q_data->height;
1008+
if (ctx->is_enc) {
1009+
state->width = q_data->width;
1010+
state->height = q_data->height;
1011+
}
10051012
state->ref_frame.width = state->ref_frame.height = 0;
10061013
state->ref_frame.luma = kvmalloc(size + 2 * size / chroma_div,
10071014
GFP_KERNEL);

drivers/media/platform/vivid/vivid-sdr-cap.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,6 @@ static int sdr_cap_start_streaming(struct vb2_queue *vq, unsigned count)
276276

277277
list_for_each_entry_safe(buf, tmp, &dev->sdr_cap_active, list) {
278278
list_del(&buf->list);
279-
v4l2_ctrl_request_complete(buf->vb.vb2_buf.req_obj.req,
280-
&dev->ctrl_hdl_sdr_cap);
281279
vb2_buffer_done(&buf->vb.vb2_buf,
282280
VB2_BUF_STATE_QUEUED);
283281
}

drivers/media/platform/vivid/vivid-vbi-cap.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,6 @@ static int vbi_cap_start_streaming(struct vb2_queue *vq, unsigned count)
204204

205205
list_for_each_entry_safe(buf, tmp, &dev->vbi_cap_active, list) {
206206
list_del(&buf->list);
207-
v4l2_ctrl_request_complete(buf->vb.vb2_buf.req_obj.req,
208-
&dev->ctrl_hdl_vbi_cap);
209207
vb2_buffer_done(&buf->vb.vb2_buf,
210208
VB2_BUF_STATE_QUEUED);
211209
}

drivers/media/platform/vivid/vivid-vbi-out.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ static int vbi_out_start_streaming(struct vb2_queue *vq, unsigned count)
9696

9797
list_for_each_entry_safe(buf, tmp, &dev->vbi_out_active, list) {
9898
list_del(&buf->list);
99-
v4l2_ctrl_request_complete(buf->vb.vb2_buf.req_obj.req,
100-
&dev->ctrl_hdl_vbi_out);
10199
vb2_buffer_done(&buf->vb.vb2_buf,
102100
VB2_BUF_STATE_QUEUED);
103101
}

drivers/media/platform/vivid/vivid-vid-cap.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,6 @@ static int vid_cap_start_streaming(struct vb2_queue *vq, unsigned count)
243243

244244
list_for_each_entry_safe(buf, tmp, &dev->vid_cap_active, list) {
245245
list_del(&buf->list);
246-
v4l2_ctrl_request_complete(buf->vb.vb2_buf.req_obj.req,
247-
&dev->ctrl_hdl_vid_cap);
248246
vb2_buffer_done(&buf->vb.vb2_buf,
249247
VB2_BUF_STATE_QUEUED);
250248
}

drivers/media/platform/vivid/vivid-vid-out.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,6 @@ static int vid_out_start_streaming(struct vb2_queue *vq, unsigned count)
162162

163163
list_for_each_entry_safe(buf, tmp, &dev->vid_out_active, list) {
164164
list_del(&buf->list);
165-
v4l2_ctrl_request_complete(buf->vb.vb2_buf.req_obj.req,
166-
&dev->ctrl_hdl_vid_out);
167165
vb2_buffer_done(&buf->vb.vb2_buf,
168166
VB2_BUF_STATE_QUEUED);
169167
}

drivers/media/platform/vsp1/vsp1_lif.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static void lif_configure_stream(struct vsp1_entity *entity,
9595
format = vsp1_entity_get_pad_format(&lif->entity, lif->entity.config,
9696
LIF_PAD_SOURCE);
9797

98-
switch (entity->vsp1->version & VI6_IP_VERSION_SOC_MASK) {
98+
switch (entity->vsp1->version & VI6_IP_VERSION_MODEL_MASK) {
9999
case VI6_IP_VERSION_MODEL_VSPD_GEN2:
100100
case VI6_IP_VERSION_MODEL_VSPD_V2H:
101101
hbth = 1536;

drivers/media/v4l2-core/v4l2-ctrls.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,7 @@ static int std_validate(const struct v4l2_ctrl *ctrl, u32 idx,
15631563
u64 offset;
15641564
s64 val;
15651565

1566-
switch (ctrl->type) {
1566+
switch ((u32)ctrl->type) {
15671567
case V4L2_CTRL_TYPE_INTEGER:
15681568
return ROUND_TO_RANGE(ptr.p_s32[idx], u32, ctrl);
15691569
case V4L2_CTRL_TYPE_INTEGER64:
@@ -2232,7 +2232,7 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
22322232
is_array = nr_of_dims > 0;
22332233

22342234
/* Prefill elem_size for all types handled by std_type_ops */
2235-
switch (type) {
2235+
switch ((u32)type) {
22362236
case V4L2_CTRL_TYPE_INTEGER64:
22372237
elem_size = sizeof(s64);
22382238
break;

drivers/staging/media/sunxi/cedrus/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ config VIDEO_SUNXI_CEDRUS
33
depends on VIDEO_DEV && VIDEO_V4L2 && MEDIA_CONTROLLER
44
depends on HAS_DMA
55
depends on OF
6+
depends on MEDIA_CONTROLLER_REQUEST_API
67
select SUNXI_SRAM
78
select VIDEOBUF2_DMA_CONTIG
89
select V4L2_MEM2MEM_DEV

drivers/staging/media/sunxi/cedrus/cedrus_hw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,10 @@ int cedrus_hw_probe(struct cedrus_dev *dev)
255255

256256
res = platform_get_resource(dev->pdev, IORESOURCE_MEM, 0);
257257
dev->base = devm_ioremap_resource(dev->dev, res);
258-
if (!dev->base) {
258+
if (IS_ERR(dev->base)) {
259259
v4l2_err(&dev->v4l2_dev, "Failed to map registers\n");
260260

261-
ret = -ENOMEM;
261+
ret = PTR_ERR(dev->base);
262262
goto err_sram;
263263
}
264264

0 commit comments

Comments
 (0)