xref: /linux/include/uapi/linux/media.h (revision 4e4dab4bb6029dbee63f12a249ddc44b0124ea63)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  * Multimedia device API
4  *
5  * Copyright (C) 2010 Nokia Corporation
6  *
7  * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8  *	     Sakari Ailus <sakari.ailus@iki.fi>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  */
19 
20 #ifndef __LINUX_MEDIA_H
21 #define __LINUX_MEDIA_H
22 
23 #ifndef __KERNEL__
24 #include <stdint.h>
25 #endif
26 #include <linux/ioctl.h>
27 #include <linux/types.h>
28 
29 struct media_device_info {
30 	char driver[16];
31 	char model[32];
32 	char serial[40];
33 	char bus_info[32];
34 	__u32 media_version;
35 	__u32 hw_revision;
36 	__u32 driver_version;
37 	__u32 reserved[31];
38 };
39 
40 /*
41  * Base number ranges for entity functions
42  *
43  * NOTE: Userspace should not rely on these ranges to identify a group
44  * of function types, as newer functions can be added with any name within
45  * the full u32 range.
46  *
47  * Some older functions use the MEDIA_ENT_F_OLD_*_BASE range. Do not
48  * change this, this is for backwards compatibility. When adding new
49  * functions always use MEDIA_ENT_F_BASE.
50  */
51 #define MEDIA_ENT_F_BASE			0x00000000
52 #define MEDIA_ENT_F_OLD_BASE			0x00010000
53 #define MEDIA_ENT_F_OLD_SUBDEV_BASE		0x00020000
54 
55 /*
56  * Initial value to be used when a new entity is created
57  * Drivers should change it to something useful.
58  */
59 #define MEDIA_ENT_F_UNKNOWN			MEDIA_ENT_F_BASE
60 
61 /*
62  * Subdevs are initialized with MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN in order
63  * to preserve backward compatibility. Drivers must change to the proper
64  * subdev type before registering the entity.
65  */
66 #define MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN		MEDIA_ENT_F_OLD_SUBDEV_BASE
67 
68 /*
69  * DVB entity functions
70  */
71 #define MEDIA_ENT_F_DTV_DEMOD			(MEDIA_ENT_F_BASE + 0x00001)
72 #define MEDIA_ENT_F_TS_DEMUX			(MEDIA_ENT_F_BASE + 0x00002)
73 #define MEDIA_ENT_F_DTV_CA			(MEDIA_ENT_F_BASE + 0x00003)
74 #define MEDIA_ENT_F_DTV_NET_DECAP		(MEDIA_ENT_F_BASE + 0x00004)
75 
76 /*
77  * I/O entity functions
78  */
79 #define MEDIA_ENT_F_IO_V4L			(MEDIA_ENT_F_OLD_BASE + 1)
80 #define MEDIA_ENT_F_IO_DTV			(MEDIA_ENT_F_BASE + 0x01001)
81 #define MEDIA_ENT_F_IO_VBI			(MEDIA_ENT_F_BASE + 0x01002)
82 #define MEDIA_ENT_F_IO_SWRADIO			(MEDIA_ENT_F_BASE + 0x01003)
83 
84 /*
85  * Sensor functions
86  */
87 #define MEDIA_ENT_F_CAM_SENSOR			(MEDIA_ENT_F_OLD_SUBDEV_BASE + 1)
88 #define MEDIA_ENT_F_FLASH			(MEDIA_ENT_F_OLD_SUBDEV_BASE + 2)
89 #define MEDIA_ENT_F_LENS			(MEDIA_ENT_F_OLD_SUBDEV_BASE + 3)
90 
91 /*
92  * Digital TV, analog TV, radio and/or software defined radio tuner functions.
93  *
94  * It is a responsibility of the master/bridge drivers to add connectors
95  * and links for MEDIA_ENT_F_TUNER. Please notice that some old tuners
96  * may require the usage of separate I2C chips to decode analog TV signals,
97  * when the master/bridge chipset doesn't have its own TV standard decoder.
98  * On such cases, the IF-PLL staging is mapped via one or two entities:
99  * MEDIA_ENT_F_IF_VID_DECODER and/or MEDIA_ENT_F_IF_AUD_DECODER.
100  */
101 #define MEDIA_ENT_F_TUNER			(MEDIA_ENT_F_OLD_SUBDEV_BASE + 5)
102 
103 /*
104  * Analog TV IF-PLL decoder functions
105  *
106  * It is a responsibility of the master/bridge drivers to create links
107  * for MEDIA_ENT_F_IF_VID_DECODER and MEDIA_ENT_F_IF_AUD_DECODER.
108  */
109 #define MEDIA_ENT_F_IF_VID_DECODER		(MEDIA_ENT_F_BASE + 0x02001)
110 #define MEDIA_ENT_F_IF_AUD_DECODER		(MEDIA_ENT_F_BASE + 0x02002)
111 
112 /*
113  * Audio entity functions
114  */
115 #define MEDIA_ENT_F_AUDIO_CAPTURE		(MEDIA_ENT_F_BASE + 0x03001)
116 #define MEDIA_ENT_F_AUDIO_PLAYBACK		(MEDIA_ENT_F_BASE + 0x03002)
117 #define MEDIA_ENT_F_AUDIO_MIXER			(MEDIA_ENT_F_BASE + 0x03003)
118 
119 /*
120  * Processing entity functions
121  */
122 #define MEDIA_ENT_F_PROC_VIDEO_COMPOSER		(MEDIA_ENT_F_BASE + 0x4001)
123 #define MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER	(MEDIA_ENT_F_BASE + 0x4002)
124 #define MEDIA_ENT_F_PROC_VIDEO_PIXEL_ENC_CONV	(MEDIA_ENT_F_BASE + 0x4003)
125 #define MEDIA_ENT_F_PROC_VIDEO_LUT		(MEDIA_ENT_F_BASE + 0x4004)
126 #define MEDIA_ENT_F_PROC_VIDEO_SCALER		(MEDIA_ENT_F_BASE + 0x4005)
127 #define MEDIA_ENT_F_PROC_VIDEO_STATISTICS	(MEDIA_ENT_F_BASE + 0x4006)
128 #define MEDIA_ENT_F_PROC_VIDEO_ENCODER		(MEDIA_ENT_F_BASE + 0x4007)
129 #define MEDIA_ENT_F_PROC_VIDEO_DECODER		(MEDIA_ENT_F_BASE + 0x4008)
130 #define MEDIA_ENT_F_PROC_VIDEO_ISP		(MEDIA_ENT_F_BASE + 0x4009)
131 
132 /*
133  * Switch and bridge entity functions
134  */
135 #define MEDIA_ENT_F_VID_MUX			(MEDIA_ENT_F_BASE + 0x5001)
136 #define MEDIA_ENT_F_VID_IF_BRIDGE		(MEDIA_ENT_F_BASE + 0x5002)
137 
138 /*
139  * Video decoder/encoder functions
140  */
141 #define MEDIA_ENT_F_ATV_DECODER			(MEDIA_ENT_F_OLD_SUBDEV_BASE + 4)
142 #define MEDIA_ENT_F_DV_DECODER			(MEDIA_ENT_F_BASE + 0x6001)
143 #define MEDIA_ENT_F_DV_ENCODER			(MEDIA_ENT_F_BASE + 0x6002)
144 
145 /* Entity flags */
146 #define MEDIA_ENT_FL_DEFAULT			(1 << 0)
147 #define MEDIA_ENT_FL_CONNECTOR			(1 << 1)
148 
149 /* OR with the entity id value to find the next entity */
150 #define MEDIA_ENT_ID_FLAG_NEXT			(1U << 31)
151 
152 struct media_entity_desc {
153 	__u32 id;
154 	char name[32];
155 	__u32 type;
156 	__u32 revision;
157 	__u32 flags;
158 	__u32 group_id;
159 	__u16 pads;
160 	__u16 links;
161 
162 	__u32 reserved[4];
163 
164 	union {
165 		/* Node specifications */
166 		struct {
167 			__u32 major;
168 			__u32 minor;
169 		} dev;
170 
171 #if !defined(__KERNEL__)
172 		/*
173 		 * TODO: this shouldn't have been added without
174 		 * actual drivers that use this. When the first real driver
175 		 * appears that sets this information, special attention
176 		 * should be given whether this information is 1) enough, and
177 		 * 2) can deal with udev rules that rename devices. The struct
178 		 * dev would not be sufficient for this since that does not
179 		 * contain the subdevice information. In addition, struct dev
180 		 * can only refer to a single device, and not to multiple (e.g.
181 		 * pcm and mixer devices).
182 		 */
183 		struct {
184 			__u32 card;
185 			__u32 device;
186 			__u32 subdevice;
187 		} alsa;
188 
189 		/*
190 		 * DEPRECATED: previous node specifications. Kept just to
191 		 * avoid breaking compilation. Use media_entity_desc.dev
192 		 * instead.
193 		 */
194 		struct {
195 			__u32 major;
196 			__u32 minor;
197 		} v4l;
198 		struct {
199 			__u32 major;
200 			__u32 minor;
201 		} fb;
202 		int dvb;
203 #endif
204 
205 		/* Sub-device specifications */
206 		/* Nothing needed yet */
207 		__u8 raw[184];
208 	};
209 };
210 
211 #define MEDIA_PAD_FL_SINK			(1 << 0)
212 #define MEDIA_PAD_FL_SOURCE			(1 << 1)
213 #define MEDIA_PAD_FL_MUST_CONNECT		(1 << 2)
214 
215 struct media_pad_desc {
216 	__u32 entity;		/* entity ID */
217 	__u16 index;		/* pad index */
218 	__u32 flags;		/* pad flags */
219 	__u32 reserved[2];
220 };
221 
222 #define MEDIA_LNK_FL_ENABLED			(1 << 0)
223 #define MEDIA_LNK_FL_IMMUTABLE			(1 << 1)
224 #define MEDIA_LNK_FL_DYNAMIC			(1 << 2)
225 
226 #define MEDIA_LNK_FL_LINK_TYPE			(0xf << 28)
227 #  define MEDIA_LNK_FL_DATA_LINK		(0 << 28)
228 #  define MEDIA_LNK_FL_INTERFACE_LINK		(1 << 28)
229 #  define MEDIA_LNK_FL_ANCILLARY_LINK		(2 << 28)
230 
231 struct media_link_desc {
232 	struct media_pad_desc source;
233 	struct media_pad_desc sink;
234 	__u32 flags;
235 	__u32 reserved[2];
236 };
237 
238 struct media_links_enum {
239 	__u32 entity;
240 	/* Should have enough room for pads elements */
241 	struct media_pad_desc __user *pads;
242 	/* Should have enough room for links elements */
243 	struct media_link_desc __user *links;
244 	__u32 reserved[4];
245 };
246 
247 /* Interface type ranges */
248 
249 #define MEDIA_INTF_T_DVB_BASE			0x00000100
250 #define MEDIA_INTF_T_V4L_BASE			0x00000200
251 
252 /* Interface types */
253 
254 #define MEDIA_INTF_T_DVB_FE			(MEDIA_INTF_T_DVB_BASE)
255 #define MEDIA_INTF_T_DVB_DEMUX			(MEDIA_INTF_T_DVB_BASE + 1)
256 #define MEDIA_INTF_T_DVB_DVR			(MEDIA_INTF_T_DVB_BASE + 2)
257 #define MEDIA_INTF_T_DVB_CA			(MEDIA_INTF_T_DVB_BASE + 3)
258 #define MEDIA_INTF_T_DVB_NET			(MEDIA_INTF_T_DVB_BASE + 4)
259 
260 #define MEDIA_INTF_T_V4L_VIDEO			(MEDIA_INTF_T_V4L_BASE)
261 #define MEDIA_INTF_T_V4L_VBI			(MEDIA_INTF_T_V4L_BASE + 1)
262 #define MEDIA_INTF_T_V4L_RADIO			(MEDIA_INTF_T_V4L_BASE + 2)
263 #define MEDIA_INTF_T_V4L_SUBDEV			(MEDIA_INTF_T_V4L_BASE + 3)
264 #define MEDIA_INTF_T_V4L_SWRADIO		(MEDIA_INTF_T_V4L_BASE + 4)
265 #define MEDIA_INTF_T_V4L_TOUCH			(MEDIA_INTF_T_V4L_BASE + 5)
266 
267 #define MEDIA_INTF_T_ALSA_BASE			0x00000300
268 #define MEDIA_INTF_T_ALSA_PCM_CAPTURE		(MEDIA_INTF_T_ALSA_BASE)
269 #define MEDIA_INTF_T_ALSA_PCM_PLAYBACK		(MEDIA_INTF_T_ALSA_BASE + 1)
270 #define MEDIA_INTF_T_ALSA_CONTROL		(MEDIA_INTF_T_ALSA_BASE + 2)
271 
272 #if defined(__KERNEL__)
273 
274 /*
275  * Connector functions
276  *
277  * For now these should not be used in userspace, as some definitions may
278  * change.
279  *
280  * It is the responsibility of the entity drivers to add connectors and links.
281  */
282 #define MEDIA_ENT_F_CONN_RF			(MEDIA_ENT_F_BASE + 0x30001)
283 #define MEDIA_ENT_F_CONN_SVIDEO			(MEDIA_ENT_F_BASE + 0x30002)
284 #define MEDIA_ENT_F_CONN_COMPOSITE		(MEDIA_ENT_F_BASE + 0x30003)
285 
286 #endif
287 
288 /*
289  * MC next gen API definitions
290  */
291 
292 /*
293  * Appeared in 4.19.0.
294  *
295  * The media_version argument comes from the media_version field in
296  * struct media_device_info.
297  */
298 #define MEDIA_V2_ENTITY_HAS_FLAGS(media_version) \
299 	((media_version) >= ((4 << 16) | (19 << 8) | 0))
300 
301 struct media_v2_entity {
302 	__u32 id;
303 	char name[64];
304 	__u32 function;		/* Main function of the entity */
305 	__u32 flags;
306 	__u32 reserved[5];
307 } __attribute__ ((packed));
308 
309 /* Should match the specific fields at media_intf_devnode */
310 struct media_v2_intf_devnode {
311 	__u32 major;
312 	__u32 minor;
313 } __attribute__ ((packed));
314 
315 struct media_v2_interface {
316 	__u32 id;
317 	__u32 intf_type;
318 	__u32 flags;
319 	__u32 reserved[9];
320 
321 	union {
322 		struct media_v2_intf_devnode devnode;
323 		__u32 raw[16];
324 	};
325 } __attribute__ ((packed));
326 
327 /*
328  * Appeared in 4.19.0.
329  *
330  * The media_version argument comes from the media_version field in
331  * struct media_device_info.
332  */
333 #define MEDIA_V2_PAD_HAS_INDEX(media_version) \
334 	((media_version) >= ((4 << 16) | (19 << 8) | 0))
335 
336 struct media_v2_pad {
337 	__u32 id;
338 	__u32 entity_id;
339 	__u32 flags;
340 	__u32 index;
341 	__u32 reserved[4];
342 } __attribute__ ((packed));
343 
344 struct media_v2_link {
345 	__u32 id;
346 	__u32 source_id;
347 	__u32 sink_id;
348 	__u32 flags;
349 	__u32 reserved[6];
350 } __attribute__ ((packed));
351 
352 struct media_v2_topology {
353 	__u64 topology_version;
354 
355 	__u32 num_entities;
356 	__u32 reserved1;
357 	__u64 ptr_entities;
358 
359 	__u32 num_interfaces;
360 	__u32 reserved2;
361 	__u64 ptr_interfaces;
362 
363 	__u32 num_pads;
364 	__u32 reserved3;
365 	__u64 ptr_pads;
366 
367 	__u32 num_links;
368 	__u32 reserved4;
369 	__u64 ptr_links;
370 } __attribute__ ((packed));
371 
372 /* ioctls */
373 
374 #define MEDIA_IOC_DEVICE_INFO	_IOWR('|', 0x00, struct media_device_info)
375 #define MEDIA_IOC_ENUM_ENTITIES	_IOWR('|', 0x01, struct media_entity_desc)
376 #define MEDIA_IOC_ENUM_LINKS	_IOWR('|', 0x02, struct media_links_enum)
377 #define MEDIA_IOC_SETUP_LINK	_IOWR('|', 0x03, struct media_link_desc)
378 #define MEDIA_IOC_G_TOPOLOGY	_IOWR('|', 0x04, struct media_v2_topology)
379 #define MEDIA_IOC_REQUEST_ALLOC	_IOR ('|', 0x05, int)
380 
381 /*
382  * These ioctls are called on the request file descriptor as returned
383  * by MEDIA_IOC_REQUEST_ALLOC.
384  */
385 #define MEDIA_REQUEST_IOC_QUEUE		_IO('|',  0x80)
386 #define MEDIA_REQUEST_IOC_REINIT	_IO('|',  0x81)
387 
388 #ifndef __KERNEL__
389 
390 /*
391  * Legacy symbols used to avoid userspace compilation breakages.
392  * Do not use any of this in new applications!
393  *
394  * Those symbols map the entity function into types and should be
395  * used only on legacy programs for legacy hardware. Don't rely
396  * on those for MEDIA_IOC_G_TOPOLOGY.
397  */
398 #define MEDIA_ENT_TYPE_SHIFT			16
399 #define MEDIA_ENT_TYPE_MASK			0x00ff0000
400 #define MEDIA_ENT_SUBTYPE_MASK			0x0000ffff
401 
402 #define MEDIA_ENT_T_DEVNODE_UNKNOWN		(MEDIA_ENT_F_OLD_BASE | \
403 						 MEDIA_ENT_SUBTYPE_MASK)
404 
405 #define MEDIA_ENT_T_DEVNODE			MEDIA_ENT_F_OLD_BASE
406 #define MEDIA_ENT_T_DEVNODE_V4L			MEDIA_ENT_F_IO_V4L
407 #define MEDIA_ENT_T_DEVNODE_FB			(MEDIA_ENT_F_OLD_BASE + 2)
408 #define MEDIA_ENT_T_DEVNODE_ALSA		(MEDIA_ENT_F_OLD_BASE + 3)
409 #define MEDIA_ENT_T_DEVNODE_DVB			(MEDIA_ENT_F_OLD_BASE + 4)
410 
411 #define MEDIA_ENT_T_UNKNOWN			MEDIA_ENT_F_UNKNOWN
412 #define MEDIA_ENT_T_V4L2_VIDEO			MEDIA_ENT_F_IO_V4L
413 #define MEDIA_ENT_T_V4L2_SUBDEV			MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN
414 #define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR		MEDIA_ENT_F_CAM_SENSOR
415 #define MEDIA_ENT_T_V4L2_SUBDEV_FLASH		MEDIA_ENT_F_FLASH
416 #define MEDIA_ENT_T_V4L2_SUBDEV_LENS		MEDIA_ENT_F_LENS
417 #define MEDIA_ENT_T_V4L2_SUBDEV_DECODER		MEDIA_ENT_F_ATV_DECODER
418 #define MEDIA_ENT_T_V4L2_SUBDEV_TUNER		MEDIA_ENT_F_TUNER
419 
420 #define MEDIA_ENT_F_DTV_DECODER			MEDIA_ENT_F_DV_DECODER
421 
422 /*
423  * There is still no full ALSA support in the media controller. These
424  * defines should not have been added and we leave them here only
425  * in case some application tries to use these defines.
426  *
427  * The ALSA defines that are in use have been moved into __KERNEL__
428  * scope. As support gets added to these interface types, they should
429  * be moved into __KERNEL__ scope with the code that uses them.
430  */
431 #define MEDIA_INTF_T_ALSA_COMPRESS             (MEDIA_INTF_T_ALSA_BASE + 3)
432 #define MEDIA_INTF_T_ALSA_RAWMIDI              (MEDIA_INTF_T_ALSA_BASE + 4)
433 #define MEDIA_INTF_T_ALSA_HWDEP                (MEDIA_INTF_T_ALSA_BASE + 5)
434 #define MEDIA_INTF_T_ALSA_SEQUENCER            (MEDIA_INTF_T_ALSA_BASE + 6)
435 #define MEDIA_INTF_T_ALSA_TIMER                (MEDIA_INTF_T_ALSA_BASE + 7)
436 
437 /* Obsolete symbol for media_version, no longer used in the kernel */
438 #define MEDIA_API_VERSION			((0 << 16) | (1 << 8) | 0)
439 
440 #endif
441 
442 #endif /* __LINUX_MEDIA_H */
443