Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6146 serge 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 
26
 *    Zou Nan hai 
27
 *
28
 */
29
 
30
#include "sysdeps.h"
31
 
32
#include 
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
static Bool
48
intel_driver_get_param(struct intel_driver_data *intel, int param, int *value)
49
{
50
   struct drm_i915_getparam gp;
51
 
52
   gp.param = param;
53
   gp.value = value;
54
 
55
   return drmIoctl(intel->fd, DRM_IOCTL_I915_GETPARAM, &gp) == 0;
56
 
57
//   return drmCommandWriteRead(intel->fd, DRM_I915_GETPARAM, &gp, sizeof(gp)) == 0;
58
}
59
 
60
static void intel_driver_get_revid(struct intel_driver_data *intel, int *value)
61
{
62
#if 0
63
#define PCI_REVID	8
64
	FILE *fp;
65
	char config_data[16];
66
 
67
	fp = fopen("/sys/devices/pci0000:00/0000:00:02.0/config", "r");
68
 
69
        if (fp) {
70
            if (fread(config_data, 1, 16, fp))
71
                *value = config_data[PCI_REVID];
72
            else
73
                *value = 2; /* assume it is at least  B-steping */
74
            fclose(fp);
75
        } else {
76
            *value = 2; /* assume it is at least  B-steping */
77
        }
78
#endif
79
 
80
    *value = 2;
81
	return;
82
}
83
 
84
extern const struct intel_device_info *i965_get_device_info(int devid);
85
 
86
bool
87
intel_driver_init(VADriverContextP ctx)
88
{
89
    struct intel_driver_data *intel = intel_driver_data(ctx);
90
    struct drm_state * const drm_state = (struct drm_state *)ctx->drm_state;
91
    int has_exec2 = 0, has_bsd = 0, has_blt = 0, has_vebox = 0;
92
    int ret_value = 0;
93
 
94
    g_intel_debug_option_flags = 0;
95
//    if ((env_str = getenv("VA_INTEL_DEBUG")))
96
//        g_intel_debug_option_flags = atoi(env_str);
97
 
98
//    if (g_intel_debug_option_flags)
99
//        fprintf(stderr, "g_intel_debug_option_flags:%x\n", g_intel_debug_option_flags);
100
 
101
    assert(drm_state);
102
 
103
    intel->fd = drm_state->fd;
104
    intel->dri2Enabled = 1;
105
 
106
    intel->locked = 0;
107
//    pthread_mutex_init(&intel->ctxmutex, NULL);
108
 
109
    intel_memman_init(intel);
110
    intel->device_id = drm_intel_bufmgr_gem_get_devid(intel->bufmgr);
111
    intel->device_info = i965_get_device_info(intel->device_id);
112
 
113
    if (!intel->device_info)
114
        return false;
115
 
116
    if (intel_driver_get_param(intel, I915_PARAM_HAS_EXECBUF2, &has_exec2))
117
        intel->has_exec2 = has_exec2;
118
    if (intel_driver_get_param(intel, I915_PARAM_HAS_BSD, &has_bsd))
119
        intel->has_bsd = has_bsd;
120
    if (intel_driver_get_param(intel, I915_PARAM_HAS_BLT, &has_blt))
121
        intel->has_blt = has_blt;
122
    if (intel_driver_get_param(intel, I915_PARAM_HAS_VEBOX, &has_vebox))
123
        intel->has_vebox = !!has_vebox;
124
 
125
    intel->has_bsd2 = 0;
126
    if (intel_driver_get_param(intel, LOCAL_I915_PARAM_HAS_BSD2, &ret_value))
127
        intel->has_bsd2 = !!ret_value;
128
 
129
    intel_driver_get_revid(intel, &intel->revision);
130
    return true;
131
}
132
 
133
void
134
intel_driver_terminate(VADriverContextP ctx)
135
{
136
    struct intel_driver_data *intel = intel_driver_data(ctx);
137
 
138
    intel_memman_terminate(intel);
139
//    pthread_mutex_destroy(&intel->ctxmutex);
140
}