xref: /linux-6.15/include/uapi/linux/media.h (revision df2f94e5)
1 /*
2  * Multimedia device API
3  *
4  * Copyright (C) 2010 Nokia Corporation
5  *
6  * Contacts: Laurent Pinchart <[email protected]>
7  *	     Sakari Ailus <[email protected]>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22 
23 #ifndef __LINUX_MEDIA_H
24 #define __LINUX_MEDIA_H
25 
26 #include <linux/ioctl.h>
27 #include <linux/types.h>
28 #include <linux/version.h>
29 
30 #define MEDIA_API_VERSION	KERNEL_VERSION(0, 1, 0)
31 
32 struct media_device_info {
33 	char driver[16];
34 	char model[32];
35 	char serial[40];
36 	char bus_info[32];
37 	__u32 media_version;
38 	__u32 hw_revision;
39 	__u32 driver_version;
40 	__u32 reserved[31];
41 };
42 
43 #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
44 
45 /*
46  * Initial value to be used when a new entity is created
47  * Drivers should change it to something useful
48  */
49 #define MEDIA_ENT_T_UNKNOWN	0x00000000
50 
51 /*
52  * Base numbers for entity types
53  *
54  * Please notice that the huge gap of 16 bits for each base is overkill!
55  * 8 bits is more than enough to avoid starving entity types for each
56  * subsystem.
57  *
58  * However, It is kept this way just to avoid binary breakages with the
59  * namespace provided on legacy versions of this header.
60  */
61 #define MEDIA_ENT_T_DVB_BASE		0x00000000
62 #define MEDIA_ENT_T_V4L2_BASE		0x00010000
63 #define MEDIA_ENT_T_V4L2_SUBDEV_BASE	0x00020000
64 
65 /*
66  * V4L2 entities - Those are used for DMA (mmap/DMABUF) and
67  *	read()/write() data I/O associated with the V4L2 devnodes.
68  */
69 #define MEDIA_ENT_T_V4L2_VIDEO		(MEDIA_ENT_T_V4L2_BASE + 1)
70 	/*
71 	 * Please notice that numbers between MEDIA_ENT_T_V4L2_BASE + 2 and
72 	 * MEDIA_ENT_T_V4L2_BASE + 4 can't be used, as those values used
73 	 * to be declared for FB, ALSA and DVB entities.
74 	 * As those values were never actually used in practice, we're just
75 	 * adding them as backward compatibility macros and keeping the
76 	 * numberspace clean here. This way, we avoid breaking compilation,
77 	 * in the case of having some userspace application using the old
78 	 * symbols.
79 	 */
80 #define MEDIA_ENT_T_V4L2_VBI		(MEDIA_ENT_T_V4L2_BASE + 5)
81 #define MEDIA_ENT_T_V4L2_SWRADIO	(MEDIA_ENT_T_V4L2_BASE + 6)
82 
83 /* V4L2 Sub-device entities */
84 
85 /*
86  * Subdevs are initialized with MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN,
87  * in order to preserve backward compatibility.
88  * Drivers should change to the proper subdev type before
89  * registering the entity.
90  */
91 #define MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN	MEDIA_ENT_T_V4L2_SUBDEV_BASE
92 
93 #define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 1)
94 #define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 2)
95 #define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 3)
96 	/* A converter of analogue video to its digital representation. */
97 #define MEDIA_ENT_T_V4L2_SUBDEV_DECODER	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 4)
98 	/* Tuner entity is actually both V4L2 and DVB subdev */
99 #define MEDIA_ENT_T_V4L2_SUBDEV_TUNER	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 5)
100 
101 /* DVB entities */
102 #define MEDIA_ENT_T_DVB_DEMOD		(MEDIA_ENT_T_DVB_BASE + 1)
103 #define MEDIA_ENT_T_DVB_DEMUX		(MEDIA_ENT_T_DVB_BASE + 2)
104 #define MEDIA_ENT_T_DVB_TSOUT		(MEDIA_ENT_T_DVB_BASE + 3)
105 #define MEDIA_ENT_T_DVB_CA		(MEDIA_ENT_T_DVB_BASE + 4)
106 #define MEDIA_ENT_T_DVB_NET_DECAP	(MEDIA_ENT_T_DVB_BASE + 5)
107 
108 #ifndef __KERNEL__
109 /* Legacy symbols used to avoid userspace compilation breakages */
110 #define MEDIA_ENT_TYPE_SHIFT		16
111 #define MEDIA_ENT_TYPE_MASK		0x00ff0000
112 #define MEDIA_ENT_SUBTYPE_MASK		0x0000ffff
113 
114 #define MEDIA_ENT_T_DEVNODE		MEDIA_ENT_T_V4L2_BASE
115 #define MEDIA_ENT_T_V4L2_SUBDEV		MEDIA_ENT_T_V4L2_SUBDEV_BASE
116 
117 #define MEDIA_ENT_T_DEVNODE_V4L		MEDIA_ENT_T_V4L2_VIDEO
118 
119 #define MEDIA_ENT_T_DEVNODE_FB		(MEDIA_ENT_T_DEVNODE + 2)
120 #define MEDIA_ENT_T_DEVNODE_ALSA	(MEDIA_ENT_T_DEVNODE + 3)
121 #define MEDIA_ENT_T_DEVNODE_DVB		(MEDIA_ENT_T_DEVNODE + 4)
122 #endif
123 
124 /* Entity types */
125 
126 #define MEDIA_ENT_FL_DEFAULT		(1 << 0)
127 
128 struct media_entity_desc {
129 	__u32 id;
130 	char name[32];
131 	__u32 type;
132 	__u32 revision;
133 	__u32 flags;
134 	__u32 group_id;
135 	__u16 pads;
136 	__u16 links;
137 
138 	__u32 reserved[4];
139 
140 	union {
141 		/* Node specifications */
142 		struct {
143 			__u32 major;
144 			__u32 minor;
145 		} dev;
146 
147 #if 1
148 		/*
149 		 * TODO: this shouldn't have been added without
150 		 * actual drivers that use this. When the first real driver
151 		 * appears that sets this information, special attention
152 		 * should be given whether this information is 1) enough, and
153 		 * 2) can deal with udev rules that rename devices. The struct
154 		 * dev would not be sufficient for this since that does not
155 		 * contain the subdevice information. In addition, struct dev
156 		 * can only refer to a single device, and not to multiple (e.g.
157 		 * pcm and mixer devices).
158 		 *
159 		 * So for now mark this as a to do.
160 		 */
161 		struct {
162 			__u32 card;
163 			__u32 device;
164 			__u32 subdevice;
165 		} alsa;
166 #endif
167 
168 #if 1
169 		/*
170 		 * DEPRECATED: previous node specifications. Kept just to
171 		 * avoid breaking compilation, but media_entity_desc.dev
172 		 * should be used instead. In particular, alsa and dvb
173 		 * fields below are wrong: for all devnodes, there should
174 		 * be just major/minor inside the struct, as this is enough
175 		 * to represent any devnode, no matter what type.
176 		 */
177 		struct {
178 			__u32 major;
179 			__u32 minor;
180 		} v4l;
181 		struct {
182 			__u32 major;
183 			__u32 minor;
184 		} fb;
185 		int dvb;
186 #endif
187 
188 		/* Sub-device specifications */
189 		/* Nothing needed yet */
190 		__u8 raw[184];
191 	};
192 };
193 
194 #define MEDIA_PAD_FL_SINK		(1 << 0)
195 #define MEDIA_PAD_FL_SOURCE		(1 << 1)
196 #define MEDIA_PAD_FL_MUST_CONNECT	(1 << 2)
197 
198 struct media_pad_desc {
199 	__u32 entity;		/* entity ID */
200 	__u16 index;		/* pad index */
201 	__u32 flags;		/* pad flags */
202 	__u32 reserved[2];
203 };
204 
205 #define MEDIA_LNK_FL_ENABLED		(1 << 0)
206 #define MEDIA_LNK_FL_IMMUTABLE		(1 << 1)
207 #define MEDIA_LNK_FL_DYNAMIC		(1 << 2)
208 
209 struct media_link_desc {
210 	struct media_pad_desc source;
211 	struct media_pad_desc sink;
212 	__u32 flags;
213 	__u32 reserved[2];
214 };
215 
216 struct media_links_enum {
217 	__u32 entity;
218 	/* Should have enough room for pads elements */
219 	struct media_pad_desc __user *pads;
220 	/* Should have enough room for links elements */
221 	struct media_link_desc __user *links;
222 	__u32 reserved[4];
223 };
224 
225 /* Interface type ranges */
226 
227 #define MEDIA_INTF_T_DVB_BASE	0x00000100
228 #define MEDIA_INTF_T_V4L_BASE	0x00000200
229 
230 /* Interface types */
231 
232 #define MEDIA_INTF_T_DVB_FE    	(MEDIA_INTF_T_DVB_BASE)
233 #define MEDIA_INTF_T_DVB_DEMUX  (MEDIA_INTF_T_DVB_BASE + 1)
234 #define MEDIA_INTF_T_DVB_DVR    (MEDIA_INTF_T_DVB_BASE + 2)
235 #define MEDIA_INTF_T_DVB_CA     (MEDIA_INTF_T_DVB_BASE + 3)
236 #define MEDIA_INTF_T_DVB_NET    (MEDIA_INTF_T_DVB_BASE + 4)
237 
238 #define MEDIA_INTF_T_V4L_VIDEO  (MEDIA_INTF_T_V4L_BASE)
239 #define MEDIA_INTF_T_V4L_VBI    (MEDIA_INTF_T_V4L_BASE + 1)
240 #define MEDIA_INTF_T_V4L_RADIO  (MEDIA_INTF_T_V4L_BASE + 2)
241 #define MEDIA_INTF_T_V4L_SUBDEV (MEDIA_INTF_T_V4L_BASE + 3)
242 #define MEDIA_INTF_T_V4L_SWRADIO (MEDIA_INTF_T_V4L_BASE + 4)
243 
244 /* TBD: declare the structs needed for the new G_TOPOLOGY ioctl */
245 
246 #define MEDIA_IOC_DEVICE_INFO		_IOWR('|', 0x00, struct media_device_info)
247 #define MEDIA_IOC_ENUM_ENTITIES		_IOWR('|', 0x01, struct media_entity_desc)
248 #define MEDIA_IOC_ENUM_LINKS		_IOWR('|', 0x02, struct media_links_enum)
249 #define MEDIA_IOC_SETUP_LINK		_IOWR('|', 0x03, struct media_link_desc)
250 
251 #endif /* __LINUX_MEDIA_H */
252