Skip to content

Commit

Permalink
[media] v4l2: use __u32 rather than enums in ioctl() structs
Browse files Browse the repository at this point in the history
V4L2 uses the enum type in IOCTL arguments in IOCTLs that were defined until
the use of enum was considered less than ideal. Recently Rémi Denis-Courmont
brought up the issue by proposing a patch to convert the enums to unsigned:

<URL:http://www.spinics.net/lists/linux-media/msg46167.html>

This sparked a long discussion where another solution to the issue was
proposed: two sets of IOCTL structures, one with __u32 and the other with
enums, and conversion code between the two:

<URL:http://www.spinics.net/lists/linux-media/msg47168.html>

Both approaches implement a complete solution that resolves the problem. The
first one is simple but requires assuming enums and __u32 are the same in
size (so we won't break the ABI) while the second one is more complex and
less clean but does not require making that assumption.

The issue boils down to whether enums are fundamentally different from __u32
or not, and can the former be substituted by the latter. During the
discussion it was concluded that the __u32 has the same size as enums on all
archs Linux is supported: it has not been shown that replacing those enums
in IOCTL arguments would break neither source or binary compatibility. If no
such reason is found, just replacing the enums with __u32s is the way to go.

This is what this patch does. This patch is slightly different from Remi's
first RFC (link above): it uses __u32 instead of unsigned and also changes
the arguments of VIDIOC_G_PRIORITY and VIDIOC_S_PRIORITY.

Signed-off-by: Rémi Denis-Courmont <remi@remlab.net>
Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
  • Loading branch information
Sakari Ailus authored and Mauro Carvalho Chehab committed May 14, 2012
1 parent 121b3dd commit 6016af8
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 66 deletions.
12 changes: 7 additions & 5 deletions Documentation/DocBook/media/v4l/io.xml
Original file line number Diff line number Diff line change
Expand Up @@ -543,12 +543,13 @@ and can range from zero to the number of buffers allocated
with the &VIDIOC-REQBUFS; ioctl (&v4l2-requestbuffers; <structfield>count</structfield>) minus one.</entry>
</row>
<row>
<entry>&v4l2-buf-type;</entry>
<entry>__u32</entry>
<entry><structfield>type</structfield></entry>
<entry></entry>
<entry>Type of the buffer, same as &v4l2-format;
<structfield>type</structfield> or &v4l2-requestbuffers;
<structfield>type</structfield>, set by the application.</entry>
<structfield>type</structfield>, set by the application. See <xref
linkend="v4l2-buf-type" /></entry>
</row>
<row>
<entry>__u32</entry>
Expand All @@ -568,7 +569,7 @@ refers to an input stream, applications when an output stream.</entry>
linkend="buffer-flags" />.</entry>
</row>
<row>
<entry>&v4l2-field;</entry>
<entry>__u32</entry>
<entry><structfield>field</structfield></entry>
<entry></entry>
<entry>Indicates the field order of the image in the
Expand Down Expand Up @@ -630,11 +631,12 @@ bandwidth. These devices identify by not enumerating any video
standards, see <xref linkend="standard" />.</para></entry>
</row>
<row>
<entry>&v4l2-memory;</entry>
<entry>__u32</entry>
<entry><structfield>memory</structfield></entry>
<entry></entry>
<entry>This field must be set by applications and/or drivers
in accordance with the selected I/O method.</entry>
in accordance with the selected I/O method. See <xref linkend="v4l2-memory"
/></entry>
</row>
<row>
<entry>union</entry>
Expand Down
10 changes: 6 additions & 4 deletions Documentation/DocBook/media/v4l/vidioc-create-bufs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,18 @@ information.</para>
<entry>The number of buffers requested or granted.</entry>
</row>
<row>
<entry>&v4l2-memory;</entry>
<entry>__u32</entry>
<entry><structfield>memory</structfield></entry>
<entry>Applications set this field to
<constant>V4L2_MEMORY_MMAP</constant> or
<constant>V4L2_MEMORY_USERPTR</constant>.</entry>
<constant>V4L2_MEMORY_USERPTR</constant>. See <xref linkend="v4l2-memory"
/></entry>
</row>
<row>
<entry>&v4l2-format;</entry>
<entry>__u32</entry>
<entry><structfield>format</structfield></entry>
<entry>Filled in by the application, preserved by the driver.</entry>
<entry>Filled in by the application, preserved by the driver.
See <xref linkend="v4l2-format" />.</entry>
</row>
<row>
<entry>__u32</entry>
Expand Down
4 changes: 2 additions & 2 deletions Documentation/DocBook/media/v4l/vidioc-cropcap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ output.</para>
&cs-str;
<tbody valign="top">
<row>
<entry>&v4l2-buf-type;</entry>
<entry>__u32</entry>
<entry><structfield>type</structfield></entry>
<entry>Type of the data stream, set by the application.
Only these types are valid here:
<constant>V4L2_BUF_TYPE_VIDEO_CAPTURE</constant>,
<constant>V4L2_BUF_TYPE_VIDEO_OUTPUT</constant>,
<constant>V4L2_BUF_TYPE_VIDEO_OVERLAY</constant>, and custom (driver
defined) types with code <constant>V4L2_BUF_TYPE_PRIVATE</constant>
and higher.</entry>
and higher. See <xref linkend="v4l2-buf-type" />.</entry>
</row>
<row>
<entry>struct <link linkend="v4l2-rect-crop">v4l2_rect</link></entry>
Expand Down
4 changes: 2 additions & 2 deletions Documentation/DocBook/media/v4l/vidioc-enum-fmt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ the application. This is in no way related to the <structfield>
pixelformat</structfield> field.</entry>
</row>
<row>
<entry>&v4l2-buf-type;</entry>
<entry>__u32</entry>
<entry><structfield>type</structfield></entry>
<entry>Type of the data stream, set by the application.
Only these types are valid here:
Expand All @@ -81,7 +81,7 @@ Only these types are valid here:
<constant>V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE</constant>,
<constant>V4L2_BUF_TYPE_VIDEO_OVERLAY</constant>, and custom (driver
defined) types with code <constant>V4L2_BUF_TYPE_PRIVATE</constant>
and higher.</entry>
and higher. See <xref linkend="v4l2-buf-type" />.</entry>
</row>
<row>
<entry>__u32</entry>
Expand Down
4 changes: 2 additions & 2 deletions Documentation/DocBook/media/v4l/vidioc-g-crop.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ changed and <constant>VIDIOC_S_CROP</constant> returns the
&cs-str;
<tbody valign="top">
<row>
<entry>&v4l2-buf-type;</entry>
<entry>__u32</entry>
<entry><structfield>type</structfield></entry>
<entry>Type of the data stream, set by the application.
Only these types are valid here: <constant>V4L2_BUF_TYPE_VIDEO_CAPTURE</constant>,
<constant>V4L2_BUF_TYPE_VIDEO_OUTPUT</constant>,
<constant>V4L2_BUF_TYPE_VIDEO_OVERLAY</constant>, and custom (driver
defined) types with code <constant>V4L2_BUF_TYPE_PRIVATE</constant>
and higher.</entry>
and higher. See <xref linkend="v4l2-buf-type" />.</entry>
</row>
<row>
<entry>&v4l2-rect;</entry>
Expand Down
2 changes: 1 addition & 1 deletion Documentation/DocBook/media/v4l/vidioc-g-fmt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ this ioctl.</para>
<colspec colname="c4" />
<tbody valign="top">
<row>
<entry>&v4l2-buf-type;</entry>
<entry>__u32</entry>
<entry><structfield>type</structfield></entry>
<entry></entry>
<entry>Type of the data stream, see <xref
Expand Down
6 changes: 3 additions & 3 deletions Documentation/DocBook/media/v4l/vidioc-g-frequency.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ the &v4l2-output; <structfield>modulator</structfield> field and the
&v4l2-modulator; <structfield>index</structfield> field.</entry>
</row>
<row>
<entry>&v4l2-tuner-type;</entry>
<entry>__u32</entry>
<entry><structfield>type</structfield></entry>
<entry>The tuner type. This is the same value as in the
&v4l2-tuner; <structfield>type</structfield> field. The type must be set
&v4l2-tuner; <structfield>type</structfield> field. See The type must be set
to <constant>V4L2_TUNER_RADIO</constant> for <filename>/dev/radioX</filename>
device nodes, and to <constant>V4L2_TUNER_ANALOG_TV</constant>
for all others. The field is not applicable to modulators, &ie; ignored
by drivers.</entry>
by drivers. See <xref linkend="v4l2-tuner-type" /></entry>
</row>
<row>
<entry>__u32</entry>
Expand Down
5 changes: 3 additions & 2 deletions Documentation/DocBook/media/v4l/vidioc-g-parm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ devices.</para>
&cs-ustr;
<tbody valign="top">
<row>
<entry>&v4l2-buf-type;</entry>
<entry>__u32</entry>
<entry><structfield>type</structfield></entry>
<entry></entry>
<entry>The buffer (stream) type, same as &v4l2-format;
<structfield>type</structfield>, set by the application.</entry>
<structfield>type</structfield>, set by the application. See <xref
linkend="v4l2-buf-type" /></entry>
</row>
<row>
<entry>union</entry>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ using the &VIDIOC-S-FMT; ioctl as described in <xref
<structfield>service_lines</structfield>[1][0] to zero.</entry>
</row>
<row>
<entry>&v4l2-buf-type;</entry>
<entry>__u32</entry>
<entry><structfield>type</structfield></entry>
<entry>Type of the data stream, see <xref
linkend="v4l2-buf-type" />. Should be
Expand Down
2 changes: 1 addition & 1 deletion Documentation/DocBook/media/v4l/vidioc-g-tuner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ user.<!-- FIXME Video inputs already have a name, the purpose of this
field is not quite clear.--></para></entry>
</row>
<row>
<entry>&v4l2-tuner-type;</entry>
<entry>__u32</entry>
<entry><structfield>type</structfield></entry>
<entry spanname="hspan">Type of the tuner, see <xref
linkend="v4l2-tuner-type" />.</entry>
Expand Down
2 changes: 1 addition & 1 deletion Documentation/DocBook/media/v4l/vidioc-queryctrl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ the first control with a higher ID. Drivers which do not support this
flag yet always return an &EINVAL;.</entry>
</row>
<row>
<entry>&v4l2-ctrl-type;</entry>
<entry>__u32</entry>
<entry><structfield>type</structfield></entry>
<entry>Type of control, see <xref
linkend="v4l2-ctrl-type" />.</entry>
Expand Down
7 changes: 4 additions & 3 deletions Documentation/DocBook/media/v4l/vidioc-reqbufs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,19 @@ streamoff.--></para>
<entry>The number of buffers requested or granted.</entry>
</row>
<row>
<entry>&v4l2-buf-type;</entry>
<entry>__u32</entry>
<entry><structfield>type</structfield></entry>
<entry>Type of the stream or buffers, this is the same
as the &v4l2-format; <structfield>type</structfield> field. See <xref
linkend="v4l2-buf-type" /> for valid values.</entry>
</row>
<row>
<entry>&v4l2-memory;</entry>
<entry>__u32</entry>
<entry><structfield>memory</structfield></entry>
<entry>Applications set this field to
<constant>V4L2_MEMORY_MMAP</constant> or
<constant>V4L2_MEMORY_USERPTR</constant>.</entry>
<constant>V4L2_MEMORY_USERPTR</constant>. See <xref linkend="v4l2-memory"
/>.</entry>
</row>
<row>
<entry>__u32</entry>
Expand Down
5 changes: 3 additions & 2 deletions Documentation/DocBook/media/v4l/vidioc-s-hw-freq-seek.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ same value as in the &v4l2-input; <structfield>tuner</structfield>
field and the &v4l2-tuner; <structfield>index</structfield> field.</entry>
</row>
<row>
<entry>&v4l2-tuner-type;</entry>
<entry>__u32</entry>
<entry><structfield>type</structfield></entry>
<entry>The tuner type. This is the same value as in the
&v4l2-tuner; <structfield>type</structfield> field.</entry>
&v4l2-tuner; <structfield>type</structfield> field. See <xref
linkend="v4l2-tuner-type" /></entry>
</row>
<row>
<entry>__u32</entry>
Expand Down
12 changes: 6 additions & 6 deletions drivers/media/video/v4l2-compat-ioctl32.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct v4l2_clip32 {

struct v4l2_window32 {
struct v4l2_rect w;
enum v4l2_field field;
__u32 field; /* enum v4l2_field */
__u32 chromakey;
compat_caddr_t clips; /* actually struct v4l2_clip32 * */
__u32 clipcount;
Expand Down Expand Up @@ -147,7 +147,7 @@ static inline int put_v4l2_sliced_vbi_format(struct v4l2_sliced_vbi_format *kp,
}

struct v4l2_format32 {
enum v4l2_buf_type type;
__u32 type; /* enum v4l2_buf_type */
union {
struct v4l2_pix_format pix;
struct v4l2_pix_format_mplane pix_mp;
Expand All @@ -170,7 +170,7 @@ struct v4l2_format32 {
struct v4l2_create_buffers32 {
__u32 index;
__u32 count;
enum v4l2_memory memory;
__u32 memory; /* enum v4l2_memory */
struct v4l2_format32 format;
__u32 reserved[8];
};
Expand Down Expand Up @@ -311,16 +311,16 @@ struct v4l2_plane32 {

struct v4l2_buffer32 {
__u32 index;
enum v4l2_buf_type type;
__u32 type; /* enum v4l2_buf_type */
__u32 bytesused;
__u32 flags;
enum v4l2_field field;
__u32 field; /* enum v4l2_field */
struct compat_timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;

/* memory location */
enum v4l2_memory memory;
__u32 memory; /* enum v4l2_memory */
union {
__u32 offset;
compat_long_t userptr;
Expand Down
Loading

0 comments on commit 6016af8

Please sign in to comment.