1 /* 2 * va_drmcommon.h - Common utilities for DRM-based drivers 3 * 4 * Copyright (c) 2012 Intel Corporation. All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 */ 26 27 #ifndef VA_DRM_COMMON_H 28 #define VA_DRM_COMMON_H 29 30 #include <stdint.h> 31 32 33 /** \brief DRM authentication type. */ 34 enum { 35 /** \brief Disconnected. */ 36 VA_DRM_AUTH_NONE = 0, 37 /** 38 * \brief Connected. Authenticated with DRI1 protocol. 39 * 40 * @deprecated 41 * This is a deprecated authentication type. All DRI-based drivers have 42 * been migrated to use the DRI2 protocol. Newly written drivers shall 43 * use DRI2 protocol only, or a custom authentication means. e.g. opt 44 * for authenticating on the VA driver side, instead of libva side. 45 */ 46 VA_DRM_AUTH_DRI1 = 1, 47 /** 48 * \brief Connected. Authenticated with DRI2 protocol. 49 * 50 * This is only useful to VA/X11 drivers. The libva-x11 library provides 51 * a helper function VA_DRI2Authenticate() for authenticating the 52 * connection. However, DRI2 conformant drivers don't need to call that 53 * function since authentication happens on the libva side, implicitly. 54 */ 55 VA_DRM_AUTH_DRI2 = 2, 56 /** 57 * \brief Connected. Authenticated with some alternate raw protocol. 58 * 59 * This authentication mode is mainly used in non-VA/X11 drivers. 60 * Authentication happens through some alternative method, at the 61 * discretion of the VA driver implementation. 62 */ 63 VA_DRM_AUTH_CUSTOM = 3 64 }; 65 66 /** \brief Base DRM state. */ 67 struct drm_state { 68 /** \brief DRM connection descriptor. */ 69 int fd; 70 /** \brief DRM authentication type. */ 71 int auth_type; 72 /** \brief Reserved bytes for future use, must be zero */ 73 int va_reserved[8]; 74 }; 75 76 /** \brief Kernel DRM buffer memory type. */ 77 #define VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM 0x10000000 78 /** \brief DRM PRIME memory type (old version) 79 * 80 * This supports only single objects with restricted memory layout. 81 * Used with VASurfaceAttribExternalBuffers. 82 */ 83 #define VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME 0x20000000 84 /** \brief DRM PRIME memory type 85 * 86 * Used with VADRMPRIMESurfaceDescriptor. 87 */ 88 #define VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2 0x40000000 89 90 /** 91 * \brief External buffer descriptor for a DRM PRIME surface. 92 * 93 * For export, call vaExportSurfaceHandle() with mem_type set to 94 * VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2 and pass a pointer to an 95 * instance of this structure to fill. 96 * If VA_EXPORT_SURFACE_SEPARATE_LAYERS is specified on export, each 97 * layer will contain exactly one plane. For example, an NV12 98 * surface will be exported as two layers, one of DRM_FORMAT_R8 and 99 * one of DRM_FORMAT_GR88. 100 * If VA_EXPORT_SURFACE_COMPOSED_LAYERS is specified on export, 101 * there will be exactly one layer. 102 * 103 * For import, call vaCreateSurfaces() with the MemoryType attribute 104 * set to VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2 and the 105 * ExternalBufferDescriptor attribute set to point to an array of 106 * num_surfaces instances of this structure. 107 * The number of planes which need to be provided for a given layer 108 * is dependent on both the format and the format modifier used for 109 * the objects containing it. For example, the format DRM_FORMAT_RGBA 110 * normally requires one plane, but with the format modifier 111 * I915_FORMAT_MOD_Y_TILED_CCS it requires two planes - the first 112 * being the main data plane and the second containing the color 113 * control surface. 114 * Note that a given driver may only support a subset of possible 115 * representations of a particular format. For example, it may only 116 * support NV12 surfaces when they are contained within a single DRM 117 * object, and therefore fail to create such surfaces if the two 118 * planes are in different DRM objects. 119 */ 120 typedef struct _VADRMPRIMESurfaceDescriptor { 121 /** Pixel format fourcc of the whole surface (VA_FOURCC_*). */ 122 uint32_t fourcc; 123 /** Width of the surface in pixels. */ 124 uint32_t width; 125 /** Height of the surface in pixels. */ 126 uint32_t height; 127 /** Number of distinct DRM objects making up the surface. */ 128 uint32_t num_objects; 129 /** Description of each object. */ 130 struct { 131 /** DRM PRIME file descriptor for this object. */ 132 int fd; 133 /** Total size of this object (may include regions which are 134 * not part of the surface). */ 135 uint32_t size; 136 /** Format modifier applied to this object. */ 137 uint64_t drm_format_modifier; 138 } objects[4]; 139 /** Number of layers making up the surface. */ 140 uint32_t num_layers; 141 /** Description of each layer in the surface. */ 142 struct { 143 /** DRM format fourcc of this layer (DRM_FOURCC_*). */ 144 uint32_t drm_format; 145 /** Number of planes in this layer. */ 146 uint32_t num_planes; 147 /** Index in the objects array of the object containing each 148 * plane. */ 149 uint32_t object_index[4]; 150 /** Offset within the object of each plane. */ 151 uint32_t offset[4]; 152 /** Pitch of each plane. */ 153 uint32_t pitch[4]; 154 } layers[4]; 155 } VADRMPRIMESurfaceDescriptor; 156 157 /** 158 * \brief List of DRM format modifiers. 159 * 160 * To allocate surfaces with one of the modifiers specified in the array, call 161 * vaCreateSurfaces() with the VASurfaceAttribDRMFormatModifiers attribute set 162 * to point to an array of num_surfaces instances of this structure. The driver 163 * will select the optimal modifier in the list. 164 * 165 * DRM format modifiers are defined in drm_fourcc.h in the Linux kernel. 166 */ 167 typedef struct _VADRMFormatModifierList { 168 /** Number of modifiers. */ 169 uint32_t num_modifiers; 170 /** Array of modifiers. */ 171 uint64_t *modifiers; 172 } VADRMFormatModifierList; 173 174 175 #endif /* VA_DRM_COMMON_H */ 176