| 1 |
/* |
| 2 |
* Copyright (c) 2020, Intel Corporation |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included |
| 12 |
* in all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
*/ |
| 22 |
//! |
| 23 |
//! \file media_ddi_prot.h |
| 24 |
//! \brief Defines base class for DDI media protected. |
| 25 |
//! |
| 26 |
|
| 27 |
#ifndef _MEDIA_DDI_PROT_H_ |
| 28 |
#define _MEDIA_DDI_PROT_H_ |
| 29 |
|
| 30 |
#include <va/va.h> |
| 31 |
#include "cp_factory.h" |
| 32 |
|
| 33 |
#ifndef VAProtectedSessionID |
| 34 |
#define VAProtectedSessionID VAContextID |
| 35 |
#endif |
| 36 |
|
| 37 |
#define DDI_MEDIA_VACONTEXTID_OFFSET_PROT_LP 0 |
| 38 |
#define DDI_MEDIA_VACONTEXTID_OFFSET_PROT_CP 0x8000000 |
| 39 |
|
| 40 |
#define DDI_MEDIA_MASK_VAPROTECTEDSESSION_ID 0x7FFFFFF |
| 41 |
#define DDI_MEDIA_MASK_VAPROTECTEDSESSION_TYPE 0x8000000 |
| 42 |
|
| 43 |
#define DDI_MEDIA_CONTEXT_TYPE_PROTECTED_LINK 1 |
| 44 |
#define DDI_MEDIA_CONTEXT_TYPE_PROTECTED_CONTENT 2 |
| 45 |
|
| 46 |
#define DDI_PROTECTED_DEFAULT 1 |
| 47 |
#define DDI_PROTECTED_DISPLAY_LINK 2 |
| 48 |
#define DDI_PROTECTED_CONTENT 3 |
| 49 |
|
| 50 |
//! |
| 51 |
//! \class DdiMediaProtected |
| 52 |
//! \brief Ddi media protected |
| 53 |
//! |
| 54 |
class DdiMediaProtected |
| 55 |
{ |
| 56 |
public: |
| 57 |
//! |
| 58 |
//! \brief Constructor |
| 59 |
//! |
| 60 |
DdiMediaProtected() {} |
| 61 |
|
| 62 |
//! |
| 63 |
//! \brief Destructor |
| 64 |
//! |
| 65 |
virtual ~DdiMediaProtected() {} |
| 66 |
|
| 67 |
//! |
| 68 |
//! \brief Check VA entrypoint is supported or not. |
| 69 |
//! |
| 70 |
//! \param [in] entrypoint |
| 71 |
//! VAEntrypoint |
| 72 |
//! |
| 73 |
virtual bool CheckEntrypointSupported( |
| 74 |
VAEntrypoint entrypoint); |
| 75 |
|
| 76 |
//! |
| 77 |
//! \brief Check the attribute list if is valid according to profile and entrypoint |
| 78 |
//! |
| 79 |
//! \param [in] profile |
| 80 |
//! VAProfile |
| 81 |
//! \param [in] entrypoint |
| 82 |
//! VAEntrypoint |
| 83 |
//! \param [in] attrib |
| 84 |
//! Pointer to a pointer of VAConfigAttrib |
| 85 |
//! \param [in] numAttribs |
| 86 |
//! number of of VAConfigAttrib |
| 87 |
//! |
| 88 |
//! \return bool |
| 89 |
//! true if valid |
| 90 |
//! |
| 91 |
virtual bool CheckAttribList( |
| 92 |
VAProfile profile, |
| 93 |
VAEntrypoint entrypoint, |
| 94 |
VAConfigAttrib* attrib, |
| 95 |
uint32_t numAttribs); |
| 96 |
|
| 97 |
//! |
| 98 |
//! \brief Create protected session |
| 99 |
//! |
| 100 |
//! \param [in] ctx |
| 101 |
//! Pointer to VA driver context |
| 102 |
//! \param [in] configId |
| 103 |
//! VA configuration ID |
| 104 |
//! \param [out] protected_session |
| 105 |
//! VA protected session ID |
| 106 |
//! |
| 107 |
//! \return VAStatus |
| 108 |
//! VA_STATUS_SUCCESS if success, else fail reason |
| 109 |
//! |
| 110 |
static VAStatus DdiMedia_CreateProtectedSession( |
| 111 |
VADriverContextP ctx, |
| 112 |
VAConfigID config_id, |
| 113 |
VAProtectedSessionID *protected_session); |
| 114 |
|
| 115 |
//! |
| 116 |
//! \brief Destroy protected session |
| 117 |
//! |
| 118 |
//! \param [in] ctx |
| 119 |
//! Pointer to VA driver context |
| 120 |
//! \param [in] protected_session |
| 121 |
//! VA protected session ID |
| 122 |
//! |
| 123 |
//! \return VAStatus |
| 124 |
//! VA_STATUS_SUCCESS if success, else fail reason |
| 125 |
//! |
| 126 |
static VAStatus DdiMedia_DestroyProtectedSession( |
| 127 |
VADriverContextP ctx, |
| 128 |
VAProtectedSessionID protected_session); |
| 129 |
|
| 130 |
//! |
| 131 |
//! \brief Attach protected session to display or context |
| 132 |
//! |
| 133 |
//! \param [in] ctx |
| 134 |
//! Pointer to VA driver context |
| 135 |
//! \param [in] context |
| 136 |
//! VA context ID to be attached if not 0. |
| 137 |
//! \param [in] protected_session |
| 138 |
//! VA protected session ID |
| 139 |
//! |
| 140 |
//! \return VAStatus |
| 141 |
//! VA_STATUS_SUCCESS if success, else fail reason |
| 142 |
//! |
| 143 |
static VAStatus DdiMedia_AttachProtectedSession( |
| 144 |
VADriverContextP ctx, |
| 145 |
VAContextID context, |
| 146 |
VAProtectedSessionID protected_session); |
| 147 |
|
| 148 |
//! |
| 149 |
//! \brief Detach protected session from display or context |
| 150 |
//! |
| 151 |
//! \param [in] ctx |
| 152 |
//! Pointer to VA driver context |
| 153 |
//! \param [in] context |
| 154 |
//! VA context ID to be Detached if not 0. |
| 155 |
//! |
| 156 |
//! \return VAStatus |
| 157 |
//! VA_STATUS_SUCCESS if success, else fail reason |
| 158 |
//! |
| 159 |
static VAStatus DdiMedia_DetachProtectedSession( |
| 160 |
VADriverContextP ctx, |
| 161 |
VAContextID context); |
| 162 |
|
| 163 |
//! |
| 164 |
//! \brief TEE execution for the particular protected session |
| 165 |
//! |
| 166 |
//! \param [in] ctx |
| 167 |
//! Pointer to VA driver context |
| 168 |
//! \param [in] protected_session |
| 169 |
//! VA protected session ID |
| 170 |
//! \param [in] data |
| 171 |
//! VA buffer ID |
| 172 |
//! |
| 173 |
//! \return VAStatus |
| 174 |
//! VA_STATUS_SUCCESS if success, else fail reason |
| 175 |
//! |
| 176 |
static VAStatus DdiMedia_ProtectedSessionExecute( |
| 177 |
VADriverContextP ctx, |
| 178 |
VAProtectedSessionID protected_session, |
| 179 |
VABufferID data); |
| 180 |
|
| 181 |
//! \brief Create protected session buffer |
| 182 |
//! |
| 183 |
//! \param [in] ctx |
| 184 |
//! Pointer to VA Driver Context |
| 185 |
//! \param [in] context |
| 186 |
//! VA protected session ID |
| 187 |
//! \param [in] type |
| 188 |
//! Va Buffer type |
| 189 |
//! \param [in] size |
| 190 |
//! Size of each element in buffer |
| 191 |
//! \param [in] num_elements |
| 192 |
//! Number of elements |
| 193 |
//! \param [in] data |
| 194 |
//! Buffer data |
| 195 |
//! \param [out] bufId |
| 196 |
//! Pointer to VABufferID |
| 197 |
//! |
| 198 |
//! \return VAStatus |
| 199 |
//! VA_STATUS_SUCCESS if successful, else fail reason |
| 200 |
//! |
| 201 |
static VAStatus DdiMedia_ProtectedSessionCreateBuffer( |
| 202 |
VADriverContextP ctx, |
| 203 |
VAContextID context, |
| 204 |
VABufferType type, |
| 205 |
uint32_t size, |
| 206 |
uint32_t num_elements, |
| 207 |
void *data, |
| 208 |
VABufferID *bufId); |
| 209 |
|
| 210 |
|
| 211 |
//! \brief Get singleton object |
| 212 |
//! |
| 213 |
//! \param [in] id |
| 214 |
//! Type of singleton object |
| 215 |
//! |
| 216 |
//! \return DdiMediaProtected* |
| 217 |
//! DdiMediaProtected object |
| 218 |
//! |
| 219 |
static DdiMediaProtected* GetInstance(uint32_t id = DDI_PROTECTED_DEFAULT); |
| 220 |
|
| 221 |
//! \brief Free singleton objects created in GetInstance() |
| 222 |
static void FreeInstances(); |
| 223 |
|
| 224 |
//! \brief Get protected surface tag |
| 225 |
//! |
| 226 |
//! \param [in] ctx |
| 227 |
//! Media context |
| 228 |
//! |
| 229 |
//! \return uint64_t |
| 230 |
//! Protected surface tag based on cp session created. |
| 231 |
//! |
| 232 |
virtual uint64_t GetProtectedSurfaceTag(PDDI_MEDIA_CONTEXT media_ctx); |
| 233 |
|
| 234 |
protected: |
| 235 |
virtual VAStatus CreateProtectedSession( |
| 236 |
VADriverContextP ctx, |
| 237 |
VAConfigID config_id, |
| 238 |
VAProtectedSessionID *protected_session); |
| 239 |
|
| 240 |
virtual VAStatus DestroyProtectedSession( |
| 241 |
VADriverContextP ctx, |
| 242 |
VAProtectedSessionID protected_session); |
| 243 |
|
| 244 |
virtual VAStatus AttachProtectedSession( |
| 245 |
VADriverContextP ctx, |
| 246 |
VAContextID context, |
| 247 |
VAProtectedSessionID protected_session); |
| 248 |
|
| 249 |
virtual VAStatus DetachProtectedSession( |
| 250 |
VADriverContextP ctx, |
| 251 |
VAContextID context); |
| 252 |
|
| 253 |
virtual VAStatus ProtectedSessionExecute( |
| 254 |
VADriverContextP ctx, |
| 255 |
VAProtectedSessionID protected_session, |
| 256 |
VABufferID data); |
| 257 |
|
| 258 |
virtual VAStatus ProtectedSessionCreateBuffer( |
| 259 |
VADriverContextP ctx, |
| 260 |
VAProtectedSessionID protected_session, |
| 261 |
VABufferType type, |
| 262 |
uint32_t size, |
| 263 |
uint32_t num_elements, |
| 264 |
void *data, |
| 265 |
VABufferID *bufId); |
| 266 |
|
| 267 |
private: |
| 268 |
static std::map<uint32_t, DdiMediaProtected*> _impl; |
| 269 |
|
| 270 |
MEDIA_CLASS_DEFINE_END(DdiMediaProtected) |
| 271 |
}; |
| 272 |
|
| 273 |
typedef CpFactoryWithoutArgs<DdiMediaProtected> DdiProtectedFactory; |
| 274 |
|
| 275 |
void DdiMedia_FreeProtectedSessionHeap( |
| 276 |
VADriverContextP ctx, |
| 277 |
PDDI_MEDIA_HEAP contextHeap, |
| 278 |
int32_t vaContextOffset, |
| 279 |
int32_t ctxNums); |
| 280 |
|
| 281 |
void* DdiMedia_GetContextFromProtectedSessionID( |
| 282 |
VADriverContextP ctx, |
| 283 |
VAProtectedSessionID vaID, |
| 284 |
uint32_t *ctxType); |
| 285 |
|
| 286 |
#endif /* _MEDIA_DDI_PROT_H_ */ |