ANDROID: media: v4l2-core: extend the v4l2 format to support request

This patch is to extend the related interface to support the request-based operations. We use extension fields in the parameters of MEDIA_IOC_SETUP_LINK, VIDIOC_S_FMT, VIDIOC_SUBDEV_S_SELECTION, VIDIOC_SUBDEV_S_FMT as request fd.
The driver uses media_request_get_by_fd() to retrieve the media request and save the pending change in it, so that we can apply the pending change in req_queue() callback then.
Besides, We also add three vendor hook functions to handle related changes in v4l2-framework.

Bug: 187480619

Signed-off-by: Louis Kuo <louis.kuo@mediatek.com>
Change-Id: I22762136f980afaec29be70c32cca8b04e0805a0
This commit is contained in:
Louis Kuo 2021-05-07 17:14:02 +08:00 committed by Todd Kjos
parent bf769b7216
commit f1a161b019
6 changed files with 86 additions and 6 deletions

View File

@ -57,6 +57,8 @@
#include <trace/hooks/selinux.h>
#include <trace/hooks/hung_task.h>
#include <trace/hooks/mmc_core.h>
#include <trace/hooks/v4l2core.h>
#include <trace/hooks/v4l2mc.h>
/*
* Export tracepoints that act as a bare tracehook (ie: have no trace event
@ -302,3 +304,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_save_track_hash);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_set_task_comm);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cpufreq_acct_update_power);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_typec_tcpm_log);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_media_device_setup_link);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_clear_reserved_fmt_fields);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_fill_ext_fmtdesc);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_clear_mask_adjust);

View File

@ -18,6 +18,7 @@
#include <linux/pci.h>
#include <linux/usb.h>
#include <linux/version.h>
#include <trace/hooks/v4l2mc.h>
#include <media/media-device.h>
#include <media/media-devnode.h>
@ -203,6 +204,7 @@ static long media_device_setup_link(struct media_device *mdev, void *arg)
struct media_link *link = NULL;
struct media_entity *source;
struct media_entity *sink;
int ret = 0;
/* Find the source and sink entities and link.
*/
@ -221,9 +223,12 @@ static long media_device_setup_link(struct media_device *mdev, void *arg)
if (link == NULL)
return -EINVAL;
memset(linkd->reserved, 0, sizeof(linkd->reserved));
/* Setup the link on both entities */
trace_android_vh_media_device_setup_link(link, linkd, &ret);
if (ret)
return ret;
/* Setup the link on both entities. */
memset(linkd->reserved, 0, sizeof(linkd->reserved));
return __media_entity_setup_link(link, linkd->flags);
}

View File

@ -28,6 +28,8 @@
#include <media/v4l2-mem2mem.h>
#include <trace/events/v4l2.h>
#include <trace/hooks/v4l2core.h>
/* Zero out the end of the struct pointed to by p. Everything after, but
* not including, the specified field is cleared. */
@ -76,6 +78,15 @@ static const struct std_descr standards[] = {
{ 0, "Unknown" }
};
static void clear_reserved(struct v4l2_format *p)
{
int ret = 0;
trace_android_vh_clear_reserved_fmt_fields(p, &ret);
if (!ret)
CLEAR_AFTER_FIELD(p, fmt.pix_mp.xfer_func);
}
/* video4linux standard ID conversion to standard name
*/
const char *v4l2_norm_to_name(v4l2_std_id id)
@ -1452,6 +1463,9 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_PIX_FMT_MT21C: descr = "Mediatek Compressed Format"; break;
case V4L2_PIX_FMT_SUNXI_TILED_NV12: descr = "Sunxi Tiled NV12 Format"; break;
default:
trace_android_vh_fill_ext_fmtdesc(fmt, &descr);
if (descr)
break;
if (fmt->description[0])
return;
WARN(1, "Unknown pixelformat 0x%08x\n", fmt->pixelformat);
@ -1673,7 +1687,7 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops,
case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
if (unlikely(!ops->vidioc_s_fmt_vid_cap_mplane))
break;
CLEAR_AFTER_FIELD(p, fmt.pix_mp.xfer_func);
clear_reserved(p);
for (i = 0; i < p->fmt.pix_mp.num_planes; i++)
CLEAR_AFTER_FIELD(&p->fmt.pix_mp.plane_fmt[i],
bytesperline);
@ -1704,7 +1718,7 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops,
case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
if (unlikely(!ops->vidioc_s_fmt_vid_out_mplane))
break;
CLEAR_AFTER_FIELD(p, fmt.pix_mp.xfer_func);
clear_reserved(p);
for (i = 0; i < p->fmt.pix_mp.num_planes; i++)
CLEAR_AFTER_FIELD(&p->fmt.pix_mp.plane_fmt[i],
bytesperline);
@ -1775,7 +1789,7 @@ static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops,
case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
if (unlikely(!ops->vidioc_try_fmt_vid_cap_mplane))
break;
CLEAR_AFTER_FIELD(p, fmt.pix_mp.xfer_func);
clear_reserved(p);
for (i = 0; i < p->fmt.pix_mp.num_planes; i++)
CLEAR_AFTER_FIELD(&p->fmt.pix_mp.plane_fmt[i],
bytesperline);
@ -1806,7 +1820,7 @@ static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops,
case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
if (unlikely(!ops->vidioc_try_fmt_vid_out_mplane))
break;
CLEAR_AFTER_FIELD(p, fmt.pix_mp.xfer_func);
clear_reserved(p);
for (i = 0; i < p->fmt.pix_mp.num_planes; i++)
CLEAR_AFTER_FIELD(&p->fmt.pix_mp.plane_fmt[i],
bytesperline);
@ -3167,6 +3181,7 @@ static int video_get_user(void __user *arg, void *parg, unsigned int cmd,
if (flags & INFO_FL_CLEAR_MASK)
n = (flags & INFO_FL_CLEAR_MASK) >> 16;
*always_copy = flags & INFO_FL_ALWAYS_COPY;
trace_android_vh_clear_mask_adjust(v4l2_ioctls[_IOC_NR(cmd)].ioctl, &n);
}
if (copy_from_user(parg, (void __user *)arg, n))

View File

@ -17,6 +17,7 @@
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/media.h>
#include <linux/android_vendor.h>
/* Enums used internally at the media controller to represent graphs */
@ -145,6 +146,7 @@ struct media_link {
struct media_link *reverse;
unsigned long flags;
bool is_backlink;
ANDROID_VENDOR_DATA(1);
};
/**

View File

@ -0,0 +1,30 @@
/* SPDX-License-Identifier: GPL-2.0 */
#undef TRACE_SYSTEM
#define TRACE_SYSTEM v4l2core
#define TRACE_INCLUDE_PATH trace/hooks
#if !defined(_TRACE_HOOK_V4L2CORE_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_HOOK_V4L2_CORE_H
#include <linux/tracepoint.h>
#include <trace/hooks/vendor_hooks.h>
struct v4l2_format;
DECLARE_HOOK(android_vh_clear_reserved_fmt_fields,
TP_PROTO(struct v4l2_format *fmt, int *ret),
TP_ARGS(fmt, ret));
struct v4l2_fmtdesc;
DECLARE_HOOK(android_vh_fill_ext_fmtdesc,
TP_PROTO(struct v4l2_fmtdesc *fmtd, const char **descr),
TP_ARGS(fmtd, descr));
DECLARE_HOOK(android_vh_clear_mask_adjust,
TP_PROTO(unsigned int ctrl, int *n),
TP_ARGS(ctrl, n));
#endif /* _TRACE_HOOK_V4L2CORE_H */
/* This part must be outside protection */
#include <trace/define_trace.h>

View File

@ -0,0 +1,22 @@
/* SPDX-License-Identifier: GPL-2.0 */
#undef TRACE_SYSTEM
#define TRACE_SYSTEM v4l2mc
#define TRACE_INCLUDE_PATH trace/hooks
#if !defined(_TRACE_HOOK_V4L2MC_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_HOOK_V4L2MC_H
#include <linux/tracepoint.h>
#include <trace/hooks/vendor_hooks.h>
struct media_link;
struct media_link_desc;
DECLARE_HOOK(android_vh_media_device_setup_link,
TP_PROTO(struct media_link *link, struct media_link_desc *linkd, int *ret),
TP_ARGS(link, linkd, ret));
#endif /* _TRACE_HOOK_V4L2MC_H */
/* This part must be outside protection */
#include <trace/define_trace.h>