1 /*
2  * Copyright (C) 2013 Google, Inc.
3  *
4  * This software is licensed under the terms of the GNU General Public
5  * License version 2, as published by the Free Software Foundation, and
6  * may be copied, distributed, and modified under those terms.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  */
14 
15 #ifndef _UAPI_VIDEO_ADF_H_
16 #define _UAPI_VIDEO_ADF_H_
17 
18 #include <linux/ioctl.h>
19 #include <linux/types.h>
20 
21 #include <drm/drm_fourcc.h>
22 #include <drm/drm_mode.h>
23 
24 #define ADF_NAME_LEN 32
25 #define ADF_MAX_CUSTOM_DATA_SIZE 4096
26 
27 enum adf_interface_type {
28 	ADF_INTF_DSI = 0,
29 	ADF_INTF_eDP = 1,
30 	ADF_INTF_DPI = 2,
31 	ADF_INTF_VGA = 3,
32 	ADF_INTF_DVI = 4,
33 	ADF_INTF_HDMI = 5,
34 	ADF_INTF_MEMORY = 6,
35 	ADF_INTF_TYPE_DEVICE_CUSTOM = 128,
36 	ADF_INTF_TYPE_MAX = (~(__u32)0),
37 };
38 
39 #define ADF_INTF_FLAG_PRIMARY (1 << 0)
40 #define ADF_INTF_FLAG_EXTERNAL (1 << 1)
41 
42 enum adf_event_type {
43 	ADF_EVENT_VSYNC = 0,
44 	ADF_EVENT_HOTPLUG = 1,
45 	ADF_EVENT_DEVICE_CUSTOM = 128,
46 	ADF_EVENT_TYPE_MAX = 255,
47 };
48 
49 /**
50  * struct adf_set_event - start or stop subscribing to ADF events
51  *
52  * @type: the type of event to (un)subscribe
53  * @enabled: subscribe or unsubscribe
54  *
55  * After subscribing to an event, userspace may poll() the ADF object's fd
56  * to wait for events or read() to consume the event's data.
57  *
58  * ADF reserves event types 0 to %ADF_EVENT_DEVICE_CUSTOM-1 for its own events.
59  * Devices may use event types %ADF_EVENT_DEVICE_CUSTOM to %ADF_EVENT_TYPE_MAX-1
60  * for driver-private events.
61  */
62 struct adf_set_event {
63 	__u8 type;
64 	__u8 enabled;
65 };
66 
67 /**
68  * struct adf_event - common header for ADF event data
69  *
70  * @type: event type
71  * @length: total size of event data, header inclusive
72  */
73 struct adf_event {
74 	__u8 type;
75 	__u32 length;
76 };
77 
78 /**
79  * struct adf_vsync_event - ADF vsync event
80  *
81  * @base: event header (see &struct adf_event)
82  * @timestamp: time of vsync event, in nanoseconds
83  */
84 struct adf_vsync_event {
85 	struct adf_event base;
86 	__aligned_u64 timestamp;
87 };
88 
89 /**
90  * struct adf_vsync_event - ADF display hotplug event
91  *
92  * @base: event header (see &struct adf_event)
93  * @connected: whether a display is now connected to the interface
94  */
95 struct adf_hotplug_event {
96 	struct adf_event base;
97 	__u8 connected;
98 };
99 
100 #define ADF_MAX_PLANES 4
101 /**
102  * struct adf_buffer_config - description of buffer displayed by adf_post_config
103  *
104  * @overlay_engine: id of the target overlay engine
105  * @w: width of display region in pixels
106  * @h: height of display region in pixels
107  * @format: DRM-style fourcc, see drm_fourcc.h for standard formats
108  * @fd: dma_buf fd for each plane
109  * @offset: location of first pixel to scan out, in bytes
110  * @pitch: stride (i.e. length of a scanline including padding) in bytes
111  * @n_planes: number of planes in buffer
112  * @acquire_fence: sync_fence fd which will clear when the buffer is
113  *	ready for display, or <0 if the buffer is already ready
114  */
115 struct adf_buffer_config {
116 	__u32 overlay_engine;
117 
118 	__u32 w;
119 	__u32 h;
120 	__u32 format;
121 
122 	__s32 fd[ADF_MAX_PLANES];
123 	__u32 offset[ADF_MAX_PLANES];
124 	__u32 pitch[ADF_MAX_PLANES];
125 	__u8 n_planes;
126 
127 	__s32 acquire_fence;
128 };
129 #define ADF_MAX_BUFFERS (4096 / sizeof(struct adf_buffer_config))
130 
131 /**
132  * struct adf_post_config - request to flip to a new set of buffers
133  *
134  * @n_interfaces: number of interfaces targeted by the flip (input)
135  * @interfaces: ids of interfaces targeted by the flip (input)
136  * @n_bufs: number of buffers displayed (input)
137  * @bufs: description of buffers displayed (input)
138  * @custom_data_size: size of driver-private data (input)
139  * @custom_data: driver-private data (input)
140  * @complete_fence: sync_fence fd which will clear when this
141  *	configuration has left the screen (output)
142  */
143 struct adf_post_config {
144 	size_t n_interfaces;
145 	__u32 __user *interfaces;
146 
147 	size_t n_bufs;
148 	struct adf_buffer_config __user *bufs;
149 
150 	size_t custom_data_size;
151 	void __user *custom_data;
152 
153 	__s32 complete_fence;
154 };
155 #define ADF_MAX_INTERFACES (4096 / sizeof(__u32))
156 
157 /**
158  * struct adf_simple_buffer_allocate - request to allocate a "simple" buffer
159  *
160  * @w: width of buffer in pixels (input)
161  * @h: height of buffer in pixels (input)
162  * @format: DRM-style fourcc (input)
163  *
164  * @fd: dma_buf fd (output)
165  * @offset: location of first pixel, in bytes (output)
166  * @pitch: length of a scanline including padding, in bytes (output)
167  *
168  * Simple buffers are analogous to DRM's "dumb" buffers.  They have a single
169  * plane of linear RGB data which can be allocated and scanned out without
170  * any driver-private ioctls or data.
171  *
172  * @format must be a standard RGB format defined in drm_fourcc.h.
173  *
174  * ADF clients must NOT assume that an interface can scan out a simple buffer
175  * allocated by a different ADF interface, even if the two interfaces belong to
176  * the same ADF device.
177  */
178 struct adf_simple_buffer_alloc {
179 	__u16 w;
180 	__u16 h;
181 	__u32 format;
182 
183 	__s32 fd;
184 	__u32 offset;
185 	__u32 pitch;
186 };
187 
188 /**
189  * struct adf_simple_post_config - request to flip to a single buffer without
190  * driver-private data
191  *
192  * @buf: description of buffer displayed (input)
193  * @complete_fence: sync_fence fd which will clear when this buffer has left the
194  * screen (output)
195  */
196 struct adf_simple_post_config {
197 	struct adf_buffer_config buf;
198 	__s32 complete_fence;
199 };
200 
201 /**
202  * struct adf_attachment_config - description of attachment between an overlay
203  * engine and an interface
204  *
205  * @overlay_engine: id of the overlay engine
206  * @interface: id of the interface
207  */
208 struct adf_attachment_config {
209 	__u32 overlay_engine;
210 	__u32 interface;
211 };
212 
213 /**
214  * struct adf_device_data - describes a display device
215  *
216  * @name: display device's name
217  * @n_attachments: the number of current attachments
218  * @attachments: list of current attachments
219  * @n_allowed_attachments: the number of allowed attachments
220  * @allowed_attachments: list of allowed attachments
221  * @custom_data_size: size of driver-private data
222  * @custom_data: driver-private data
223  */
224 struct adf_device_data {
225 	char name[ADF_NAME_LEN];
226 
227 	size_t n_attachments;
228 	struct adf_attachment_config __user *attachments;
229 
230 	size_t n_allowed_attachments;
231 	struct adf_attachment_config __user *allowed_attachments;
232 
233 	size_t custom_data_size;
234 	void __user *custom_data;
235 };
236 #define ADF_MAX_ATTACHMENTS (4096 / sizeof(struct adf_attachment_config))
237 
238 /**
239  * struct adf_device_data - describes a display interface
240  *
241  * @name: display interface's name
242  * @type: interface type (see enum @adf_interface_type)
243  * @id: which interface of type @type;
244  *	e.g. interface DSI.1 -> @type=@ADF_INTF_TYPE_DSI, @id=1
245  * @flags: informational flags (bitmask of %ADF_INTF_FLAG_* values)
246  * @dpms_state: DPMS state (one of @DRM_MODE_DPMS_* defined in drm_mode.h)
247  * @hotplug_detect: whether a display is plugged in
248  * @width_mm: screen width in millimeters, or 0 if unknown
249  * @height_mm: screen height in millimeters, or 0 if unknown
250  * @current_mode: current display mode
251  * @n_available_modes: the number of hardware display modes
252  * @available_modes: list of hardware display modes
253  * @custom_data_size: size of driver-private data
254  * @custom_data: driver-private data
255  */
256 struct adf_interface_data {
257 	char name[ADF_NAME_LEN];
258 
259 	__u32 type;
260 	__u32 id;
261 	/* e.g. type=ADF_INTF_TYPE_DSI, id=1 => DSI.1 */
262 	__u32 flags;
263 
264 	__u8 dpms_state;
265 	__u8 hotplug_detect;
266 	__u16 width_mm;
267 	__u16 height_mm;
268 
269 	struct drm_mode_modeinfo current_mode;
270 	size_t n_available_modes;
271 	struct drm_mode_modeinfo __user *available_modes;
272 
273 	size_t custom_data_size;
274 	void __user *custom_data;
275 };
276 #define ADF_MAX_MODES (4096 / sizeof(struct drm_mode_modeinfo))
277 
278 /**
279  * struct adf_overlay_engine_data - describes an overlay engine
280  *
281  * @name: overlay engine's name
282  * @n_supported_formats: number of supported formats
283  * @supported_formats: list of supported formats
284  * @custom_data_size: size of driver-private data
285  * @custom_data: driver-private data
286  */
287 struct adf_overlay_engine_data {
288 	char name[ADF_NAME_LEN];
289 
290 	size_t n_supported_formats;
291 	__u32 __user *supported_formats;
292 
293 	size_t custom_data_size;
294 	void __user *custom_data;
295 };
296 #define ADF_MAX_SUPPORTED_FORMATS (4096 / sizeof(__u32))
297 
298 #define ADF_IOCTL_TYPE		'D'
299 #define ADF_IOCTL_NR_CUSTOM	128
300 
301 #define ADF_SET_EVENT		_IOW(ADF_IOCTL_TYPE, 0, struct adf_set_event)
302 #define ADF_BLANK		_IOW(ADF_IOCTL_TYPE, 1, __u8)
303 #define ADF_POST_CONFIG		_IOW(ADF_IOCTL_TYPE, 2, struct adf_post_config)
304 #define ADF_SET_MODE		_IOW(ADF_IOCTL_TYPE, 3, \
305 					struct drm_mode_modeinfo)
306 #define ADF_GET_DEVICE_DATA	_IOR(ADF_IOCTL_TYPE, 4, struct adf_device_data)
307 #define ADF_GET_INTERFACE_DATA	_IOR(ADF_IOCTL_TYPE, 5, \
308 					struct adf_interface_data)
309 #define ADF_GET_OVERLAY_ENGINE_DATA \
310 				_IOR(ADF_IOCTL_TYPE, 6, \
311 					struct adf_overlay_engine_data)
312 #define ADF_SIMPLE_POST_CONFIG	_IOW(ADF_IOCTL_TYPE, 7, \
313 					struct adf_simple_post_config)
314 #define ADF_SIMPLE_BUFFER_ALLOC	_IOW(ADF_IOCTL_TYPE, 8, \
315 					struct adf_simple_buffer_alloc)
316 #define ADF_ATTACH		_IOW(ADF_IOCTL_TYPE, 9, \
317 					struct adf_attachment_config)
318 #define ADF_DETACH		_IOW(ADF_IOCTL_TYPE, 10, \
319 					struct adf_attachment_config)
320 
321 #endif /* _UAPI_VIDEO_ADF_H_ */
322