OSDN Git Service

Check whether there is a fully loaded HuC firmware
[android-x86/hardware-intel-common-vaapi.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 "sysdeps.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 uint32_t g_intel_debug_option_flags = 0;
38
39 #ifdef I915_PARAM_HAS_BSD2
40 #define LOCAL_I915_PARAM_HAS_BSD2 I915_PARAM_HAS_BSD2
41 #endif
42
43 #ifndef LOCAL_I915_PARAM_HAS_BSD2
44 #define LOCAL_I915_PARAM_HAS_BSD2       30
45 #endif
46
47 #ifdef I915_PARAM_HAS_HUC
48 #define LOCAL_I915_PARAM_HAS_HUC I915_PARAM_HAS_HUC
49 #else
50 #define LOCAL_I915_PARAM_HAS_HUC 42
51 #endif
52
53 static Bool
54 intel_driver_get_param(struct intel_driver_data *intel, int param, int *value)
55 {
56    struct drm_i915_getparam gp;
57
58    gp.param = param;
59    gp.value = value;
60
61    return drmCommandWriteRead(intel->fd, DRM_I915_GETPARAM, &gp, sizeof(gp)) == 0;
62 }
63
64 static void intel_driver_get_revid(struct intel_driver_data *intel, int *value)
65 {
66 #define PCI_REVID       8
67         FILE *fp;
68         char config_data[16];
69         
70         fp = fopen("/sys/devices/pci0000:00/0000:00:02.0/config", "r");
71
72         if (fp) {
73             if (fread(config_data, 1, 16, fp))
74                 *value = config_data[PCI_REVID];
75             else
76                 *value = 2; /* assume it is at least  B-steping */
77             fclose(fp);
78         } else {
79             *value = 2; /* assume it is at least  B-steping */
80         }
81
82         return;
83 }
84
85 extern const struct intel_device_info *i965_get_device_info(int devid);
86
87 bool 
88 intel_driver_init(VADriverContextP ctx)
89 {
90     struct intel_driver_data *intel = intel_driver_data(ctx);
91     struct drm_state * const drm_state = (struct drm_state *)ctx->drm_state;
92     int has_exec2 = 0, has_bsd = 0, has_blt = 0, has_vebox = 0;
93     char *env_str = NULL;
94     int ret_value = 0;
95
96     g_intel_debug_option_flags = 0;
97     if ((env_str = getenv("VA_INTEL_DEBUG")))
98         g_intel_debug_option_flags = atoi(env_str);
99
100     if (g_intel_debug_option_flags)
101         fprintf(stderr, "g_intel_debug_option_flags:%x\n", g_intel_debug_option_flags);
102
103     assert(drm_state);
104     assert(VA_CHECK_DRM_AUTH_TYPE(ctx, VA_DRM_AUTH_DRI1) ||
105            VA_CHECK_DRM_AUTH_TYPE(ctx, VA_DRM_AUTH_DRI2) ||
106            VA_CHECK_DRM_AUTH_TYPE(ctx, VA_DRM_AUTH_CUSTOM));
107
108     intel->fd = drm_state->fd;
109     intel->dri2Enabled = (VA_CHECK_DRM_AUTH_TYPE(ctx, VA_DRM_AUTH_DRI2) ||
110                           VA_CHECK_DRM_AUTH_TYPE(ctx, VA_DRM_AUTH_CUSTOM));
111
112     if (!intel->dri2Enabled) {
113         return false;
114     }
115
116     intel->locked = 0;
117     pthread_mutex_init(&intel->ctxmutex, NULL);
118
119     intel_memman_init(intel);
120     intel->device_id = drm_intel_bufmgr_gem_get_devid(intel->bufmgr);
121     intel->device_info = i965_get_device_info(intel->device_id);
122
123     if (!intel->device_info)
124         return false;
125
126     if (intel_driver_get_param(intel, I915_PARAM_HAS_EXECBUF2, &has_exec2))
127         intel->has_exec2 = has_exec2;
128     if (intel_driver_get_param(intel, I915_PARAM_HAS_BSD, &has_bsd))
129         intel->has_bsd = has_bsd;
130     if (intel_driver_get_param(intel, I915_PARAM_HAS_BLT, &has_blt))
131         intel->has_blt = has_blt;
132     if (intel_driver_get_param(intel, I915_PARAM_HAS_VEBOX, &has_vebox))
133         intel->has_vebox = !!has_vebox;
134
135     intel->has_bsd2 = 0;
136     if (intel_driver_get_param(intel, LOCAL_I915_PARAM_HAS_BSD2, &ret_value))
137         intel->has_bsd2 = !!ret_value;
138
139     intel->has_huc = 0;
140     ret_value = 0;
141
142     if (intel_driver_get_param(intel, LOCAL_I915_PARAM_HAS_HUC, &ret_value))
143         intel->has_huc = !!ret_value;
144
145     intel_driver_get_revid(intel, &intel->revision);
146     return true;
147 }
148
149 void 
150 intel_driver_terminate(VADriverContextP ctx)
151 {
152     struct intel_driver_data *intel = intel_driver_data(ctx);
153
154     intel_memman_terminate(intel);
155     pthread_mutex_destroy(&intel->ctxmutex);
156 }