MPEG-2 encoding path
[profile/ivi/vaapi-intel-driver.git] / src / intel_driver.c
1 /*
2  * Copyright © 2009 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
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:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  *
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.
23  *
24  * Authors:
25  *    Xiang Haihao <haihao.xiang@intel.com>
26  *    Zou Nan hai <nanhai.zou@intel.com>
27  *
28  */
29
30 #include <assert.h>
31
32 #include <va/va_drmcommon.h>
33
34 #include "intel_batchbuffer.h"
35 #include "intel_memman.h"
36 #include "intel_driver.h"
37
38 static Bool
39 intel_driver_get_param(struct intel_driver_data *intel, int param, int *value)
40 {
41    struct drm_i915_getparam gp;
42
43    gp.param = param;
44    gp.value = value;
45
46    return drmCommandWriteRead(intel->fd, DRM_I915_GETPARAM, &gp, sizeof(gp)) == 0;
47 }
48
49 static void intel_driver_get_revid(struct intel_driver_data *intel, int *value)
50 {
51 #define PCI_REVID       8
52         FILE *fp;
53         char config_data[16];
54         
55         fp = fopen("/sys/devices/pci0000:00/0000:00:02.0/config", "r");
56         fread(config_data, 1, 16, fp);
57         fclose(fp);
58         *value = config_data[PCI_REVID];
59         return;
60 }
61
62 Bool 
63 intel_driver_init(VADriverContextP ctx)
64 {
65     struct intel_driver_data *intel = intel_driver_data(ctx);
66     struct drm_state * const drm_state = (struct drm_state *)ctx->drm_state;
67     int has_exec2, has_bsd, has_blt;
68
69     assert(drm_state);
70     assert(drm_state->auth_type == VA_DRM_AUTH_DRI1 ||
71            drm_state->auth_type == VA_DRM_AUTH_DRI2 ||
72            drm_state->auth_type == VA_DRM_AUTH_CUSTOM);
73
74     intel->fd = drm_state->fd;
75     intel->dri2Enabled = (drm_state->auth_type == VA_DRM_AUTH_DRI2 ||
76                           drm_state->auth_type == VA_DRM_AUTH_CUSTOM);
77
78     if (!intel->dri2Enabled) {
79         return False;
80     }
81
82     intel->locked = 0;
83     pthread_mutex_init(&intel->ctxmutex, NULL);
84
85     intel_driver_get_param(intel, I915_PARAM_CHIPSET_ID, &intel->device_id);
86     if (intel_driver_get_param(intel, I915_PARAM_HAS_EXECBUF2, &has_exec2))
87         intel->has_exec2 = has_exec2;
88     if (intel_driver_get_param(intel, I915_PARAM_HAS_BSD, &has_bsd))
89         intel->has_bsd = has_bsd;
90     if (intel_driver_get_param(intel, I915_PARAM_HAS_BLT, &has_blt))
91         intel->has_blt = has_blt;
92    
93     intel_driver_get_revid(intel, &intel->revision);
94     intel_memman_init(intel);
95     return True;
96 }
97
98 Bool 
99 intel_driver_terminate(VADriverContextP ctx)
100 {
101     struct intel_driver_data *intel = intel_driver_data(ctx);
102
103     intel_memman_terminate(intel);
104     pthread_mutex_destroy(&intel->ctxmutex);
105
106     return True;
107 }