Home | History | Annotate | Download | only in video
      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 enum adf_complete_fence_type {
     50 	/* no fence */
     51 	ADF_COMPLETE_FENCE_NONE = 0,
     52 	/* fence fires when the configuration appears on the screen */
     53 	ADF_COMPLETE_FENCE_PRESENT = 1,
     54 	/* fence fires when the configuration leaves the screen */
     55 	ADF_COMPLETE_FENCE_RELEASE = 2,
     56 };
     57 
     58 /**
     59  * struct adf_set_event - start or stop subscribing to ADF events
     60  *
     61  * @type: the type of event to (un)subscribe
     62  * @enabled: subscribe or unsubscribe
     63  *
     64  * After subscribing to an event, userspace may poll() the ADF object's fd
     65  * to wait for events or read() to consume the event's data.
     66  *
     67  * ADF reserves event types 0 to %ADF_EVENT_DEVICE_CUSTOM-1 for its own events.
     68  * Devices may use event types %ADF_EVENT_DEVICE_CUSTOM to %ADF_EVENT_TYPE_MAX-1
     69  * for driver-private events.
     70  */
     71 struct adf_set_event {
     72 	__u8 type;
     73 	__u8 enabled;
     74 };
     75 
     76 /**
     77  * struct adf_event - common header for ADF event data
     78  *
     79  * @type: event type
     80  * @length: total size of event data, header inclusive
     81  */
     82 struct adf_event {
     83 	__u8 type;
     84 	__u32 length;
     85 };
     86 
     87 /**
     88  * struct adf_vsync_event - ADF vsync event
     89  *
     90  * @base: event header (see &struct adf_event)
     91  * @timestamp: time of vsync event, in nanoseconds
     92  */
     93 struct adf_vsync_event {
     94 	struct adf_event base;
     95 	__aligned_u64 timestamp;
     96 };
     97 
     98 /**
     99  * struct adf_vsync_event - ADF display hotplug event
    100  *
    101  * @base: event header (see &struct adf_event)
    102  * @connected: whether a display is now connected to the interface
    103  */
    104 struct adf_hotplug_event {
    105 	struct adf_event base;
    106 	__u8 connected;
    107 };
    108 
    109 #define ADF_MAX_PLANES 4
    110 /**
    111  * struct adf_buffer_config - description of buffer displayed by adf_post_config
    112  *
    113  * @overlay_engine: id of the target overlay engine
    114  * @w: width of display region in pixels
    115  * @h: height of display region in pixels
    116  * @format: DRM-style fourcc, see drm_fourcc.h for standard formats
    117  * @fd: dma_buf fd for each plane
    118  * @offset: location of first pixel to scan out, in bytes
    119  * @pitch: stride (i.e. length of a scanline including padding) in bytes
    120  * @n_planes: number of planes in buffer
    121  * @acquire_fence: sync_fence fd which will clear when the buffer is
    122  *	ready for display, or <0 if the buffer is already ready
    123  */
    124 struct adf_buffer_config {
    125 	__u32 overlay_engine;
    126 
    127 	__u32 w;
    128 	__u32 h;
    129 	__u32 format;
    130 
    131 	__s32 fd[ADF_MAX_PLANES];
    132 	__u32 offset[ADF_MAX_PLANES];
    133 	__u32 pitch[ADF_MAX_PLANES];
    134 	__u8 n_planes;
    135 
    136 	__s32 acquire_fence;
    137 };
    138 #define ADF_MAX_BUFFERS (4096 / sizeof(struct adf_buffer_config))
    139 
    140 /**
    141  * struct adf_post_config - request to flip to a new set of buffers
    142  *
    143  * This request is equivalent to &struct adf_post_config_v2 with
    144  * @complete_fence_type = %ADF_COMPLETE_FENCE_RELEASE.
    145  *
    146  * @n_interfaces: number of interfaces targeted by the flip (input)
    147  * @interfaces: ids of interfaces targeted by the flip (input)
    148  * @n_bufs: number of buffers displayed (input)
    149  * @bufs: description of buffers displayed (input)
    150  * @custom_data_size: size of driver-private data (input)
    151  * @custom_data: driver-private data (input)
    152  * @complete_fence: sync_fence fd which will clear when this
    153  *	configuration has left the screen (output)
    154  */
    155 struct adf_post_config {
    156 	size_t n_interfaces;
    157 	__u32 __user *interfaces;
    158 
    159 	size_t n_bufs;
    160 	struct adf_buffer_config __user *bufs;
    161 
    162 	size_t custom_data_size;
    163 	void __user *custom_data;
    164 
    165 	__s32 complete_fence;
    166 };
    167 
    168 /**
    169  * struct adf_post_config_v2 - request to flip to a new set of buffers
    170  *
    171  * @n_interfaces: number of interfaces targeted by the flip (input)
    172  * @interfaces: ids of interfaces targeted by the flip (input)
    173  * @n_bufs: number of buffers displayed (input)
    174  * @bufs: description of buffers displayed (input)
    175  * @custom_data_size: size of driver-private data (input)
    176  * @custom_data: driver-private data (input)
    177  * @complete_fence_type: one of &enum adf_complete_fence_type describing what
    178  * 	fence to return (input)
    179  * @complete_fence: sync_fence fd which will fire at the time
    180  * 	requested by @complete_fence_type (output)
    181  */
    182 struct adf_post_config_v2 {
    183 	__u32 n_interfaces;
    184 	__u64 interfaces; /* __u32 * packed into __u64 */
    185 
    186 	__u32 n_bufs;
    187 	__u64 bufs; /* struct adf_buffer_config * packed into __u64 */
    188 
    189 	__u64 custom_data_size;
    190 	__u64 custom_data; /* void * packed into __u64 */
    191 
    192 	__s32 complete_fence;
    193 	__u8 complete_fence_type;
    194 };
    195 #define ADF_MAX_INTERFACES (4096 / sizeof(__u32))
    196 
    197 /**
    198  * struct adf_simple_buffer_allocate - request to allocate a "simple" buffer
    199  *
    200  * @w: width of buffer in pixels (input)
    201  * @h: height of buffer in pixels (input)
    202  * @format: DRM-style fourcc (input)
    203  *
    204  * @fd: dma_buf fd (output)
    205  * @offset: location of first pixel, in bytes (output)
    206  * @pitch: length of a scanline including padding, in bytes (output)
    207  *
    208  * Simple buffers are analogous to DRM's "dumb" buffers.  They have a single
    209  * plane of linear RGB data which can be allocated and scanned out without
    210  * any driver-private ioctls or data.
    211  *
    212  * @format must be a standard RGB format defined in drm_fourcc.h.
    213  *
    214  * ADF clients must NOT assume that an interface can scan out a simple buffer
    215  * allocated by a different ADF interface, even if the two interfaces belong to
    216  * the same ADF device.
    217  */
    218 struct adf_simple_buffer_alloc {
    219 	__u16 w;
    220 	__u16 h;
    221 	__u32 format;
    222 
    223 	__s32 fd;
    224 	__u32 offset;
    225 	__u32 pitch;
    226 };
    227 
    228 /**
    229  * struct adf_simple_post_config - request to flip to a single buffer without
    230  * driver-private data
    231  *
    232  * This request is equivalent to &struct adf_simple_post_config_v2 with
    233  * @complete_fence_type = %ADF_COMPLETE_FENCE_RELEASE.
    234  *
    235  * @buf: description of buffer displayed (input)
    236  * @complete_fence: sync_fence fd which will clear when this buffer has left the
    237  * screen (output)
    238  */
    239 struct adf_simple_post_config {
    240 	struct adf_buffer_config buf;
    241 	__s32 complete_fence;
    242 };
    243 
    244 /**
    245  * struct adf_simple_post_config_v2 - request to flip to a single buffer without
    246  * driver-private data
    247  *
    248  * @buf: description of buffer displayed (input)
    249  * @complete_fence_type: one of &enum adf_complete_fence_type describing what
    250  * 	fence to return (input)
    251  * @complete_fence: sync_fence fd which will fire at the time
    252  * 	requested by @complete_fence_type (output)
    253  */
    254 struct adf_simple_post_config_v2 {
    255 	struct adf_buffer_config buf;
    256 	__s32 complete_fence;
    257 	__u8 complete_fence_type;
    258 };
    259 
    260 /**
    261  * struct adf_attachment_config - description of attachment between an overlay
    262  * engine and an interface
    263  *
    264  * @overlay_engine: id of the overlay engine
    265  * @interface: id of the interface
    266  */
    267 struct adf_attachment_config {
    268 	__u32 overlay_engine;
    269 	__u32 interface;
    270 };
    271 
    272 /**
    273  * struct adf_device_data - describes a display device
    274  *
    275  * @name: display device's name
    276  * @n_attachments: the number of current attachments
    277  * @attachments: list of current attachments
    278  * @n_allowed_attachments: the number of allowed attachments
    279  * @allowed_attachments: list of allowed attachments
    280  * @custom_data_size: size of driver-private data
    281  * @custom_data: driver-private data
    282  */
    283 struct adf_device_data {
    284 	char name[ADF_NAME_LEN];
    285 
    286 	size_t n_attachments;
    287 	struct adf_attachment_config __user *attachments;
    288 
    289 	size_t n_allowed_attachments;
    290 	struct adf_attachment_config __user *allowed_attachments;
    291 
    292 	size_t custom_data_size;
    293 	void __user *custom_data;
    294 };
    295 #define ADF_MAX_ATTACHMENTS (4096 / sizeof(struct adf_attachment_config))
    296 
    297 /**
    298  * struct adf_device_data - describes a display interface
    299  *
    300  * @name: display interface's name
    301  * @type: interface type (see enum @adf_interface_type)
    302  * @id: which interface of type @type;
    303  *	e.g. interface DSI.1 -> @type=@ADF_INTF_TYPE_DSI, @id=1
    304  * @flags: informational flags (bitmask of %ADF_INTF_FLAG_* values)
    305  * @dpms_state: DPMS state (one of @DRM_MODE_DPMS_* defined in drm_mode.h)
    306  * @hotplug_detect: whether a display is plugged in
    307  * @width_mm: screen width in millimeters, or 0 if unknown
    308  * @height_mm: screen height in millimeters, or 0 if unknown
    309  * @current_mode: current display mode
    310  * @n_available_modes: the number of hardware display modes
    311  * @available_modes: list of hardware display modes
    312  * @custom_data_size: size of driver-private data
    313  * @custom_data: driver-private data
    314  */
    315 struct adf_interface_data {
    316 	char name[ADF_NAME_LEN];
    317 
    318 	__u32 type;
    319 	__u32 id;
    320 	/* e.g. type=ADF_INTF_TYPE_DSI, id=1 => DSI.1 */
    321 	__u32 flags;
    322 
    323 	__u8 dpms_state;
    324 	__u8 hotplug_detect;
    325 	__u16 width_mm;
    326 	__u16 height_mm;
    327 
    328 	struct drm_mode_modeinfo current_mode;
    329 	size_t n_available_modes;
    330 	struct drm_mode_modeinfo __user *available_modes;
    331 
    332 	size_t custom_data_size;
    333 	void __user *custom_data;
    334 };
    335 #define ADF_MAX_MODES (4096 / sizeof(struct drm_mode_modeinfo))
    336 
    337 /**
    338  * struct adf_overlay_engine_data - describes an overlay engine
    339  *
    340  * @name: overlay engine's name
    341  * @n_supported_formats: number of supported formats
    342  * @supported_formats: list of supported formats
    343  * @custom_data_size: size of driver-private data
    344  * @custom_data: driver-private data
    345  */
    346 struct adf_overlay_engine_data {
    347 	char name[ADF_NAME_LEN];
    348 
    349 	size_t n_supported_formats;
    350 	__u32 __user *supported_formats;
    351 
    352 	size_t custom_data_size;
    353 	void __user *custom_data;
    354 };
    355 #define ADF_MAX_SUPPORTED_FORMATS (4096 / sizeof(__u32))
    356 
    357 #define ADF_IOCTL_TYPE		'D'
    358 #define ADF_IOCTL_NR_CUSTOM	128
    359 
    360 #define ADF_SET_EVENT		_IOW(ADF_IOCTL_TYPE, 0, struct adf_set_event)
    361 #define ADF_BLANK		_IOW(ADF_IOCTL_TYPE, 1, __u8)
    362 #define ADF_POST_CONFIG		_IOW(ADF_IOCTL_TYPE, 2, struct adf_post_config)
    363 #define ADF_SET_MODE		_IOW(ADF_IOCTL_TYPE, 3, \
    364 					struct drm_mode_modeinfo)
    365 #define ADF_GET_DEVICE_DATA	_IOR(ADF_IOCTL_TYPE, 4, struct adf_device_data)
    366 #define ADF_GET_INTERFACE_DATA	_IOR(ADF_IOCTL_TYPE, 5, \
    367 					struct adf_interface_data)
    368 #define ADF_GET_OVERLAY_ENGINE_DATA \
    369 				_IOR(ADF_IOCTL_TYPE, 6, \
    370 					struct adf_overlay_engine_data)
    371 #define ADF_SIMPLE_POST_CONFIG	_IOW(ADF_IOCTL_TYPE, 7, \
    372 					struct adf_simple_post_config)
    373 #define ADF_SIMPLE_BUFFER_ALLOC	_IOW(ADF_IOCTL_TYPE, 8, \
    374 					struct adf_simple_buffer_alloc)
    375 #define ADF_ATTACH		_IOW(ADF_IOCTL_TYPE, 9, \
    376 					struct adf_attachment_config)
    377 #define ADF_DETACH		_IOW(ADF_IOCTL_TYPE, 10, \
    378 					struct adf_attachment_config)
    379 
    380 #define ADF_POST_CONFIG_V2	_IOW(ADF_IOCTL_TYPE, 11, \
    381 					struct adf_post_config_v2)
    382 #define ADF_SIMPLE_POST_CONFIG_V2 \
    383 				_IOW(ADF_IOCTL_TYPE, 12, \
    384 					struct adf_simple_post_config_v2)
    385 
    386 #endif /* _UAPI_VIDEO_ADF_H_ */
    387