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