hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/media/pci/ivtv/ivtv-ioctl.c
....@@ -1,21 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 ioctl system call
34 Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com>
45 Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl>
56
6
- This program is free software; you can redistribute it and/or modify
7
- it under the terms of the GNU General Public License as published by
8
- the Free Software Foundation; either version 2 of the License, or
9
- (at your option) any later version.
10
-
11
- This program is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- GNU General Public License for more details.
15
-
16
- You should have received a copy of the GNU General Public License
17
- along with this program; if not, write to the Free Software
18
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
197 */
208
219 #include "ivtv-driver.h"
....@@ -36,6 +24,7 @@
3624 #include <media/tveeprom.h>
3725 #include <media/v4l2-event.h>
3826 #ifdef CONFIG_VIDEO_IVTV_DEPRECATED_IOCTLS
27
+#include <linux/compat.h>
3928 #include <linux/dvb/audio.h>
4029 #include <linux/dvb/video.h>
4130 #endif
....@@ -84,8 +73,8 @@
8473 return 0;
8574 }
8675 for (i = 0; i < 32; i++) {
87
- if ((1 << i) & set)
88
- return 1 << i;
76
+ if (BIT(i) & set)
77
+ return BIT(i);
8978 }
9079 return 0;
9180 }
....@@ -454,7 +443,7 @@
454443 struct ivtv_stream *s = &itv->streams[fh2id(fh)->type];
455444 struct v4l2_window *winfmt = &fmt->fmt.win;
456445
457
- if (!(s->caps & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
446
+ if (!(s->vdev.device_caps & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
458447 return -EINVAL;
459448 if (!itv->osd_video_pbase)
460449 return -EINVAL;
....@@ -565,7 +554,7 @@
565554 u32 chromakey = fmt->fmt.win.chromakey;
566555 u8 global_alpha = fmt->fmt.win.global_alpha;
567556
568
- if (!(s->caps & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
557
+ if (!(s->vdev.device_caps & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
569558 return -EINVAL;
570559 if (!itv->osd_video_pbase)
571560 return -EINVAL;
....@@ -745,18 +734,11 @@
745734 {
746735 struct ivtv_open_id *id = fh2id(file->private_data);
747736 struct ivtv *itv = id->itv;
748
- struct ivtv_stream *s = &itv->streams[id->type];
749737
750
- strlcpy(vcap->driver, IVTV_DRIVER_NAME, sizeof(vcap->driver));
751
- strlcpy(vcap->card, itv->card_name, sizeof(vcap->card));
738
+ strscpy(vcap->driver, IVTV_DRIVER_NAME, sizeof(vcap->driver));
739
+ strscpy(vcap->card, itv->card_name, sizeof(vcap->card));
752740 snprintf(vcap->bus_info, sizeof(vcap->bus_info), "PCI:%s", pci_name(itv->pdev));
753741 vcap->capabilities = itv->v4l2_cap | V4L2_CAP_DEVICE_CAPS;
754
- vcap->device_caps = s->caps;
755
- if ((s->caps & V4L2_CAP_VIDEO_OUTPUT_OVERLAY) &&
756
- !itv->osd_video_pbase) {
757
- vcap->capabilities &= ~V4L2_CAP_VIDEO_OUTPUT_OVERLAY;
758
- vcap->device_caps &= ~V4L2_CAP_VIDEO_OUTPUT_OVERLAY;
759
- }
760742 return 0;
761743 }
762744
....@@ -828,17 +810,18 @@
828810 return ivtv_get_output(itv, vout->index, vout);
829811 }
830812
831
-static int ivtv_cropcap(struct file *file, void *fh, struct v4l2_cropcap *cropcap)
813
+static int ivtv_g_pixelaspect(struct file *file, void *fh,
814
+ int type, struct v4l2_fract *f)
832815 {
833816 struct ivtv_open_id *id = fh2id(fh);
834817 struct ivtv *itv = id->itv;
835818
836
- if (cropcap->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
837
- cropcap->pixelaspect.numerator = itv->is_50hz ? 54 : 11;
838
- cropcap->pixelaspect.denominator = itv->is_50hz ? 59 : 10;
839
- } else if (cropcap->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
840
- cropcap->pixelaspect.numerator = itv->is_out_50hz ? 54 : 11;
841
- cropcap->pixelaspect.denominator = itv->is_out_50hz ? 59 : 10;
819
+ if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
820
+ f->numerator = itv->is_50hz ? 54 : 11;
821
+ f->denominator = itv->is_50hz ? 59 : 10;
822
+ } else if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
823
+ f->numerator = itv->is_out_50hz ? 54 : 11;
824
+ f->denominator = itv->is_out_50hz ? 59 : 10;
842825 } else {
843826 return -EINVAL;
844827 }
....@@ -937,14 +920,15 @@
937920 static int ivtv_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc *fmt)
938921 {
939922 static const struct v4l2_fmtdesc hm12 = {
940
- 0, V4L2_BUF_TYPE_VIDEO_CAPTURE, 0,
941
- "HM12 (YUV 4:2:0)", V4L2_PIX_FMT_HM12,
942
- { 0, 0, 0, 0 }
923
+ .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
924
+ .description = "HM12 (YUV 4:2:0)",
925
+ .pixelformat = V4L2_PIX_FMT_HM12,
943926 };
944927 static const struct v4l2_fmtdesc mpeg = {
945
- 0, V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FMT_FLAG_COMPRESSED,
946
- "MPEG", V4L2_PIX_FMT_MPEG,
947
- { 0, 0, 0, 0 }
928
+ .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
929
+ .flags = V4L2_FMT_FLAG_COMPRESSED,
930
+ .description = "MPEG",
931
+ .pixelformat = V4L2_PIX_FMT_MPEG,
948932 };
949933 struct ivtv *itv = fh2id(fh)->itv;
950934 struct ivtv_stream *s = &itv->streams[fh2id(fh)->type];
....@@ -963,14 +947,15 @@
963947 static int ivtv_enum_fmt_vid_out(struct file *file, void *fh, struct v4l2_fmtdesc *fmt)
964948 {
965949 static const struct v4l2_fmtdesc hm12 = {
966
- 0, V4L2_BUF_TYPE_VIDEO_OUTPUT, 0,
967
- "HM12 (YUV 4:2:0)", V4L2_PIX_FMT_HM12,
968
- { 0, 0, 0, 0 }
950
+ .type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
951
+ .description = "HM12 (YUV 4:2:0)",
952
+ .pixelformat = V4L2_PIX_FMT_HM12,
969953 };
970954 static const struct v4l2_fmtdesc mpeg = {
971
- 0, V4L2_BUF_TYPE_VIDEO_OUTPUT, V4L2_FMT_FLAG_COMPRESSED,
972
- "MPEG", V4L2_PIX_FMT_MPEG,
973
- { 0, 0, 0, 0 }
955
+ .type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
956
+ .flags = V4L2_FMT_FLAG_COMPRESSED,
957
+ .description = "MPEG",
958
+ .pixelformat = V4L2_PIX_FMT_MPEG,
974959 };
975960 struct ivtv *itv = fh2id(fh)->itv;
976961 struct ivtv_stream *s = &itv->streams[fh2id(fh)->type];
....@@ -1227,9 +1212,9 @@
12271212 ivtv_call_all(itv, tuner, g_tuner, vt);
12281213
12291214 if (vt->type == V4L2_TUNER_RADIO)
1230
- strlcpy(vt->name, "ivtv Radio Tuner", sizeof(vt->name));
1215
+ strscpy(vt->name, "ivtv Radio Tuner", sizeof(vt->name));
12311216 else
1232
- strlcpy(vt->name, "ivtv TV Tuner", sizeof(vt->name));
1217
+ strscpy(vt->name, "ivtv TV Tuner", sizeof(vt->name));
12331218 return 0;
12341219 }
12351220
....@@ -1403,7 +1388,7 @@
14031388 0,
14041389 };
14051390
1406
- if (!(s->caps & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
1391
+ if (!(s->vdev.device_caps & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
14071392 return -ENOTTY;
14081393 if (!itv->osd_video_pbase)
14091394 return -ENOTTY;
....@@ -1470,7 +1455,7 @@
14701455 struct ivtv_stream *s = &itv->streams[fh2id(fh)->type];
14711456 struct yuv_playback_info *yi = &itv->yuv_info;
14721457
1473
- if (!(s->caps & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
1458
+ if (!(s->vdev.device_caps & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
14741459 return -ENOTTY;
14751460 if (!itv->osd_video_pbase)
14761461 return -ENOTTY;
....@@ -1490,7 +1475,7 @@
14901475 struct ivtv *itv = id->itv;
14911476 struct ivtv_stream *s = &itv->streams[fh2id(fh)->type];
14921477
1493
- if (!(s->caps & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
1478
+ if (!(s->vdev.device_caps & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
14941479 return -ENOTTY;
14951480 if (!itv->osd_video_pbase)
14961481 return -ENOTTY;
....@@ -1627,6 +1612,21 @@
16271612 pr_warn_once("warning: the %s ioctl is deprecated. Don't use it, as it will be removed soon\n",
16281613 name);
16291614 }
1615
+
1616
+#ifdef CONFIG_COMPAT
1617
+struct compat_video_event {
1618
+ __s32 type;
1619
+ /* unused, make sure to use atomic time for y2038 if it ever gets used */
1620
+ compat_long_t timestamp;
1621
+ union {
1622
+ video_size_t size;
1623
+ unsigned int frame_rate; /* in frames per 1000sec */
1624
+ unsigned char vsync_field; /* unknown/odd/even/progressive */
1625
+ } u;
1626
+};
1627
+#define VIDEO_GET_EVENT32 _IOR('o', 28, struct compat_video_event)
1628
+#endif
1629
+
16301630 #endif
16311631
16321632 static int ivtv_decoder_ioctls(struct file *filp, unsigned int cmd, void *arg)
....@@ -1749,7 +1749,13 @@
17491749 return ivtv_video_command(itv, id, dc, try);
17501750 }
17511751
1752
+#ifdef CONFIG_COMPAT
1753
+ case VIDEO_GET_EVENT32:
1754
+#endif
17521755 case VIDEO_GET_EVENT: {
1756
+#ifdef CONFIG_COMPAT
1757
+ struct compat_video_event *ev32 = arg;
1758
+#endif
17531759 struct video_event *ev = arg;
17541760 DEFINE_WAIT(wait);
17551761
....@@ -1763,14 +1769,22 @@
17631769 if (test_and_clear_bit(IVTV_F_I_EV_DEC_STOPPED, &itv->i_flags))
17641770 ev->type = VIDEO_EVENT_DECODER_STOPPED;
17651771 else if (test_and_clear_bit(IVTV_F_I_EV_VSYNC, &itv->i_flags)) {
1772
+ unsigned char vsync_field;
1773
+
17661774 ev->type = VIDEO_EVENT_VSYNC;
1767
- ev->u.vsync_field = test_bit(IVTV_F_I_EV_VSYNC_FIELD, &itv->i_flags) ?
1775
+ vsync_field = test_bit(IVTV_F_I_EV_VSYNC_FIELD, &itv->i_flags) ?
17681776 VIDEO_VSYNC_FIELD_ODD : VIDEO_VSYNC_FIELD_EVEN;
17691777 if (itv->output_mode == OUT_UDMA_YUV &&
17701778 (itv->yuv_info.lace_mode & IVTV_YUV_MODE_MASK) ==
17711779 IVTV_YUV_MODE_PROGRESSIVE) {
1772
- ev->u.vsync_field = VIDEO_VSYNC_FIELD_PROGRESSIVE;
1780
+ vsync_field = VIDEO_VSYNC_FIELD_PROGRESSIVE;
17731781 }
1782
+#ifdef CONFIG_COMPAT
1783
+ if (cmd == VIDEO_GET_EVENT32)
1784
+ ev32->u.vsync_field = vsync_field;
1785
+ else
1786
+#endif
1787
+ ev->u.vsync_field = vsync_field;
17741788 }
17751789 if (ev->type)
17761790 return 0;
....@@ -1893,7 +1907,7 @@
18931907 .vidioc_enum_input = ivtv_enum_input,
18941908 .vidioc_enum_output = ivtv_enum_output,
18951909 .vidioc_enumaudout = ivtv_enumaudout,
1896
- .vidioc_cropcap = ivtv_cropcap,
1910
+ .vidioc_g_pixelaspect = ivtv_g_pixelaspect,
18971911 .vidioc_s_selection = ivtv_s_selection,
18981912 .vidioc_g_selection = ivtv_g_selection,
18991913 .vidioc_g_input = ivtv_g_input,