2 * Copyright (c) 2012 Intel Corporation. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include "va_backend.h"
29 #include "va_drmcommon.h"
30 #include "va_drm_auth.h"
31 #include "va_drm_utils.h"
34 va_DisplayContextIsValid(VADisplayContextP pDisplayContext)
36 VADriverContextP const pDriverContext = pDisplayContext->pDriverContext;
38 return (pDriverContext &&
39 ((pDriverContext->display_type & VA_DISPLAY_MAJOR_MASK) ==
44 va_DisplayContextDestroy(VADisplayContextP pDisplayContext)
49 free(pDisplayContext->pDriverContext->drm_state);
50 free(pDisplayContext->pDriverContext);
51 free(pDisplayContext);
55 va_DisplayContextGetDriverName(
56 VADisplayContextP pDisplayContext,
57 char **driver_name_ptr
61 VADriverContextP const ctx = pDisplayContext->pDriverContext;
62 struct drm_state * const drm_state = ctx->drm_state;
67 status = VA_DRM_GetDriverName(ctx, driver_name_ptr);
68 if (status != VA_STATUS_SUCCESS)
71 /* Authentication is only needed for a legacy DRM device */
72 if (ctx->display_type != VA_DISPLAY_DRM_RENDERNODES) {
73 ret = drmGetMagic(drm_state->fd, &magic);
75 return VA_STATUS_ERROR_OPERATION_FAILED;
77 if (!va_drm_authenticate(drm_state->fd, magic))
78 return VA_STATUS_ERROR_OPERATION_FAILED;
81 drm_state->auth_type = VA_DRM_AUTH_CUSTOM;
83 return VA_STATUS_SUCCESS;
87 vaGetDisplayDRM(int fd)
89 VADisplayContextP pDisplayContext = NULL;
90 VADriverContextP pDriverContext = NULL;
91 struct drm_state *drm_state = NULL;
94 if (fd < 0 || (is_render_nodes = VA_DRM_IsRenderNodeFd(fd)) < 0)
97 /* Create new entry */
98 /* XXX: handle cache? */
99 drm_state = calloc(1, sizeof(*drm_state));
104 pDriverContext = calloc(1, sizeof(*pDriverContext));
107 pDriverContext->native_dpy = NULL;
108 pDriverContext->display_type = is_render_nodes ?
109 VA_DISPLAY_DRM_RENDERNODES : VA_DISPLAY_DRM;
110 pDriverContext->drm_state = drm_state;
112 pDisplayContext = calloc(1, sizeof(*pDisplayContext));
113 if (!pDisplayContext)
116 pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC;
117 pDisplayContext->pDriverContext = pDriverContext;
118 pDisplayContext->vaIsValid = va_DisplayContextIsValid;
119 pDisplayContext->vaDestroy = va_DisplayContextDestroy;
120 pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
121 return pDisplayContext;
124 free(pDisplayContext);
125 free(pDriverContext);