| 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 |
#include <va/va.h> |
| 32 |
|
| 33 |
|
| 34 |
/** \brief DRM authentication type. */ |
| 35 |
enum { |
| 36 |
/** \brief Disconnected. */ |
| 37 |
VA_DRM_AUTH_NONE = 0, |
| 38 |
/** |
| 39 |
* \brief Connected. Authenticated with DRI1 protocol. |
| 40 |
* |
| 41 |
* @deprecated |
| 42 |
* This is a deprecated authentication type. All DRI-based drivers have |
| 43 |
* been migrated to use the DRI2 protocol. Newly written drivers shall |
| 44 |
* use DRI2 protocol only, or a custom authentication means. e.g. opt |
| 45 |
* for authenticating on the VA driver side, instead of libva side. |
| 46 |
*/ |
| 47 |
VA_DRM_AUTH_DRI1 = 1, |
| 48 |
/** |
| 49 |
* \brief Connected. Authenticated with DRI2 protocol. |
| 50 |
* |
| 51 |
* This is only useful to VA/X11 drivers. The libva-x11 library provides |
| 52 |
* a helper function VA_DRI2Authenticate() for authenticating the |
| 53 |
* connection. However, DRI2 conformant drivers don't need to call that |
| 54 |
* function since authentication happens on the libva side, implicitly. |
| 55 |
*/ |
| 56 |
VA_DRM_AUTH_DRI2 = 2, |
| 57 |
/** |
| 58 |
* \brief Connected. Authenticated with some alternate raw protocol. |
| 59 |
* |
| 60 |
* This authentication mode is mainly used in non-VA/X11 drivers. |
| 61 |
* Authentication happens through some alternative method, at the |
| 62 |
* discretion of the VA driver implementation. |
| 63 |
*/ |
| 64 |
VA_DRM_AUTH_CUSTOM = 3 |
| 65 |
}; |
| 66 |
|
| 67 |
/** \brief Base DRM state. */ |
| 68 |
struct drm_state { |
| 69 |
/** \brief DRM connection descriptor. */ |
| 70 |
int fd; |
| 71 |
/** \brief DRM authentication type. */ |
| 72 |
int auth_type; |
| 73 |
/** \brief Reserved bytes for future use, must be zero */ |
| 74 |
int va_reserved[8]; |
| 75 |
}; |
| 76 |
|
| 77 |
/** \brief Kernel DRM buffer memory type. */ |
| 78 |
#define VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM 0x10000000 |
| 79 |
/** \brief DRM PRIME memory type (old version) |
| 80 |
* |
| 81 |
* This supports only single objects with restricted memory layout. |
| 82 |
* Used with VASurfaceAttribExternalBuffers. |
| 83 |
*/ |
| 84 |
#define VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME 0x20000000 |
| 85 |
/** \brief DRM PRIME memory type |
| 86 |
* |
| 87 |
* Used with VADRMPRIMESurfaceDescriptor. |
| 88 |
*/ |
| 89 |
#define VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2 0x40000000 |
| 90 |
/** \brief DRM PRIME3 memory type |
| 91 |
* |
| 92 |
* Used with VADRMPRIME3SurfaceDescriptor. |
| 93 |
*/ |
| 94 |
#define VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_3 0x08000000 |
| 95 |
|
| 96 |
/** |
| 97 |
* \brief External buffer descriptor for a DRM PRIME surface. |
| 98 |
* |
| 99 |
* For export, call vaExportSurfaceHandle() with mem_type set to |
| 100 |
* VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2 and pass a pointer to an |
| 101 |
* instance of this structure to fill. |
| 102 |
* If VA_EXPORT_SURFACE_SEPARATE_LAYERS is specified on export, each |
| 103 |
* layer will contain exactly one plane. For example, an NV12 |
| 104 |
* surface will be exported as two layers, one of DRM_FORMAT_R8 and |
| 105 |
* one of DRM_FORMAT_GR88. |
| 106 |
* If VA_EXPORT_SURFACE_COMPOSED_LAYERS is specified on export, |
| 107 |
* there will be exactly one layer. |
| 108 |
* |
| 109 |
* For import, call vaCreateSurfaces() with the MemoryType attribute |
| 110 |
* set to VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2 and the |
| 111 |
* ExternalBufferDescriptor attribute set to point to an array of |
| 112 |
* num_surfaces instances of this structure. |
| 113 |
* The number of planes which need to be provided for a given layer |
| 114 |
* is dependent on both the format and the format modifier used for |
| 115 |
* the objects containing it. For example, the format DRM_FORMAT_RGBA |
| 116 |
* normally requires one plane, but with the format modifier |
| 117 |
* I915_FORMAT_MOD_Y_TILED_CCS it requires two planes - the first |
| 118 |
* being the main data plane and the second containing the color |
| 119 |
* control surface. |
| 120 |
* Note that a given driver may only support a subset of possible |
| 121 |
* representations of a particular format. For example, it may only |
| 122 |
* support NV12 surfaces when they are contained within a single DRM |
| 123 |
* object, and therefore fail to create such surfaces if the two |
| 124 |
* planes are in different DRM objects. |
| 125 |
* Note that backend driver will retrieve the resource represent by fd, |
| 126 |
* and a valid surface ID is generated. Backend driver will not close |
| 127 |
* the file descriptor. Application should handle the release of the fd. |
| 128 |
* releasing the fd will not impact the existence of the surface. |
| 129 |
*/ |
| 130 |
typedef struct _VADRMPRIMESurfaceDescriptor { |
| 131 |
/** Pixel format fourcc of the whole surface (VA_FOURCC_*). */ |
| 132 |
uint32_t fourcc; |
| 133 |
/** Width of the surface in pixels. */ |
| 134 |
uint32_t width; |
| 135 |
/** Height of the surface in pixels. */ |
| 136 |
uint32_t height; |
| 137 |
/** Number of distinct DRM objects making up the surface. */ |
| 138 |
uint32_t num_objects; |
| 139 |
/** Description of each object. */ |
| 140 |
struct { |
| 141 |
/** DRM PRIME file descriptor for this object. */ |
| 142 |
int fd; |
| 143 |
/** Total size of this object (may include regions which are |
| 144 |
* not part of the surface). */ |
| 145 |
uint32_t size; |
| 146 |
/** Format modifier applied to this object. */ |
| 147 |
uint64_t drm_format_modifier; |
| 148 |
} objects[4]; |
| 149 |
/** Number of layers making up the surface. */ |
| 150 |
uint32_t num_layers; |
| 151 |
/** Description of each layer in the surface. */ |
| 152 |
struct { |
| 153 |
/** DRM format fourcc of this layer (DRM_FOURCC_*). */ |
| 154 |
uint32_t drm_format; |
| 155 |
/** Number of planes in this layer. */ |
| 156 |
uint32_t num_planes; |
| 157 |
/** Index in the objects array of the object containing each |
| 158 |
* plane. */ |
| 159 |
uint32_t object_index[4]; |
| 160 |
/** Offset within the object of each plane. */ |
| 161 |
uint32_t offset[4]; |
| 162 |
/** Pitch of each plane. */ |
| 163 |
uint32_t pitch[4]; |
| 164 |
} layers[4]; |
| 165 |
} VADRMPRIMESurfaceDescriptor; |
| 166 |
|
| 167 |
/** |
| 168 |
* \brief External buffer descriptor for a DRM PRIME surface with flags |
| 169 |
* |
| 170 |
* This structure is an extention for VADRMPRIMESurfaceDescriptor, |
| 171 |
* it has the same behavior as if used with VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2. |
| 172 |
* |
| 173 |
* The field "flags" is added, see "Surface external buffer descriptor flags". |
| 174 |
* To use this structure, use VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_3 instead. |
| 175 |
*/ |
| 176 |
typedef struct _VADRMPRIME3SurfaceDescriptor { |
| 177 |
/** Pixel format fourcc of the whole surface (VA_FOURCC_*). */ |
| 178 |
uint32_t fourcc; |
| 179 |
/** Width of the surface in pixels. */ |
| 180 |
uint32_t width; |
| 181 |
/** Height of the surface in pixels. */ |
| 182 |
uint32_t height; |
| 183 |
/** Number of distinct DRM objects making up the surface. */ |
| 184 |
uint32_t num_objects; |
| 185 |
/** Description of each object. */ |
| 186 |
struct { |
| 187 |
/** DRM PRIME file descriptor for this object. */ |
| 188 |
int fd; |
| 189 |
/** Total size of this object (may include regions which are |
| 190 |
* not part of the surface). */ |
| 191 |
uint32_t size; |
| 192 |
/** Format modifier applied to this object. */ |
| 193 |
uint64_t drm_format_modifier; |
| 194 |
} objects[4]; |
| 195 |
/** Number of layers making up the surface. */ |
| 196 |
uint32_t num_layers; |
| 197 |
/** Description of each layer in the surface. */ |
| 198 |
struct { |
| 199 |
/** DRM format fourcc of this layer (DRM_FOURCC_*). */ |
| 200 |
uint32_t drm_format; |
| 201 |
/** Number of planes in this layer. */ |
| 202 |
uint32_t num_planes; |
| 203 |
/** Index in the objects array of the object containing each |
| 204 |
* plane. */ |
| 205 |
uint32_t object_index[4]; |
| 206 |
/** Offset within the object of each plane. */ |
| 207 |
uint32_t offset[4]; |
| 208 |
/** Pitch of each plane. */ |
| 209 |
uint32_t pitch[4]; |
| 210 |
} layers[4]; |
| 211 |
/** \brief flags. See "Surface external buffer descriptor flags". */ |
| 212 |
uint32_t flags; |
| 213 |
/** reserved bytes, must be zero */ |
| 214 |
uint32_t reserved[VA_PADDING_MEDIUM - 1]; |
| 215 |
} VADRMPRIME3SurfaceDescriptor; |
| 216 |
/** |
| 217 |
* \brief List of DRM format modifiers. |
| 218 |
* |
| 219 |
* To allocate surfaces with one of the modifiers specified in the array, call |
| 220 |
* vaCreateSurfaces() with the VASurfaceAttribDRMFormatModifiers attribute set |
| 221 |
* to point to an array of num_surfaces instances of this structure. The driver |
| 222 |
* will select the optimal modifier in the list. |
| 223 |
* |
| 224 |
* DRM format modifiers are defined in drm_fourcc.h in the Linux kernel. |
| 225 |
*/ |
| 226 |
typedef struct _VADRMFormatModifierList { |
| 227 |
/** Number of modifiers. */ |
| 228 |
uint32_t num_modifiers; |
| 229 |
/** Array of modifiers. */ |
| 230 |
uint64_t *modifiers; |
| 231 |
} VADRMFormatModifierList; |
| 232 |
|
| 233 |
|
| 234 |
#endif /* VA_DRM_COMMON_H */ |