Subversion Repositories Kolibri OS

Rev

Rev 4104 | Rev 4293 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4104 Rev 4126
1
#define iowrite32(v, addr)      writel((v), (addr))
1
#define iowrite32(v, addr)      writel((v), (addr))
2
 
2
 
3
#include "drmP.h"
3
#include "drmP.h"
4
#include "drm.h"
4
#include "drm.h"
5
#include "i915_drm.h"
5
#include "i915_drm.h"
6
#include "i915_drv.h"
6
#include "i915_drv.h"
7
#include "intel_drv.h"
7
#include "intel_drv.h"
8
 
8
 
9
#include 
9
#include 
10
#include 
10
#include 
11
#include 
11
#include 
12
#include 
12
#include 
13
#include 
13
#include 
14
 
14
 
15
#include 
15
#include 
16
 
16
 
17
#include "bitmap.h"
17
#include "bitmap.h"
18
 
18
 
19
typedef struct
19
typedef struct
20
{
20
{
21
    kobj_t     header;
21
    kobj_t     header;
22
 
22
 
23
    uint32_t  *data;
23
    uint32_t  *data;
24
    uint32_t   hot_x;
24
    uint32_t   hot_x;
25
    uint32_t   hot_y;
25
    uint32_t   hot_y;
26
 
26
 
27
    struct list_head   list;
27
    struct list_head   list;
28
    struct drm_i915_gem_object  *cobj;
28
    struct drm_i915_gem_object  *cobj;
29
}cursor_t;
29
}cursor_t;
30
 
30
 
31
#define CURSOR_WIDTH 64
31
#define CURSOR_WIDTH 64
32
#define CURSOR_HEIGHT 64
32
#define CURSOR_HEIGHT 64
33
 
33
 
34
 
34
 
35
struct tag_display
35
struct tag_display
36
{
36
{
37
    int  x;
37
    int  x;
38
    int  y;
38
    int  y;
39
    int  width;
39
    int  width;
40
    int  height;
40
    int  height;
41
    int  bpp;
41
    int  bpp;
42
    int  vrefresh;
42
    int  vrefresh;
43
    int  pitch;
43
    int  pitch;
44
    int  lfb;
44
    int  lfb;
45
 
45
 
46
    int  supported_modes;
46
    int  supported_modes;
47
    struct drm_device    *ddev;
47
    struct drm_device    *ddev;
48
    struct drm_connector *connector;
48
    struct drm_connector *connector;
49
    struct drm_crtc      *crtc;
49
    struct drm_crtc      *crtc;
50
 
50
 
51
    struct list_head   cursors;
51
    struct list_head   cursors;
52
 
52
 
53
    cursor_t   *cursor;
53
    cursor_t   *cursor;
54
    int       (*init_cursor)(cursor_t*);
54
    int       (*init_cursor)(cursor_t*);
55
    cursor_t* (__stdcall *select_cursor)(cursor_t*);
55
    cursor_t* (__stdcall *select_cursor)(cursor_t*);
56
    void      (*show_cursor)(int show);
56
    void      (*show_cursor)(int show);
57
    void      (__stdcall *move_cursor)(cursor_t *cursor, int x, int y);
57
    void      (__stdcall *move_cursor)(cursor_t *cursor, int x, int y);
58
    void      (__stdcall *restore_cursor)(int x, int y);
58
    void      (__stdcall *restore_cursor)(int x, int y);
59
    void      (*disable_mouse)(void);
59
    void      (*disable_mouse)(void);
60
    u32  mask_seqno;
60
    u32  mask_seqno;
61
    u32  check_mouse;
61
    u32  check_mouse;
62
    u32  check_m_pixel;
62
    u32  check_m_pixel;
63
 
63
 
64
};
64
};
65
 
65
 
66
 
66
 
67
static display_t *os_display;
67
static display_t *os_display;
68
 
68
 
69
u32_t cmd_buffer;
69
u32_t cmd_buffer;
70
u32_t cmd_offset;
70
u32_t cmd_offset;
71
 
71
 
72
void init_render();
72
void init_render();
73
int  sna_init();
73
int  sna_init();
74
 
74
 
75
int init_cursor(cursor_t *cursor);
75
int init_cursor(cursor_t *cursor);
76
static cursor_t*  __stdcall select_cursor_kms(cursor_t *cursor);
76
static cursor_t*  __stdcall select_cursor_kms(cursor_t *cursor);
77
static void       __stdcall move_cursor_kms(cursor_t *cursor, int x, int y);
77
static void       __stdcall move_cursor_kms(cursor_t *cursor, int x, int y);
78
 
78
 
79
void __stdcall restore_cursor(int x, int y)
79
void __stdcall restore_cursor(int x, int y)
80
{};
80
{};
81
 
81
 
82
void disable_mouse(void)
82
void disable_mouse(void)
83
{};
83
{};
84
 
84
 
85
static char *manufacturer_name(unsigned char *x)
85
static char *manufacturer_name(unsigned char *x)
86
{
86
{
87
    static char name[4];
87
    static char name[4];
88
 
88
 
89
    name[0] = ((x[0] & 0x7C) >> 2) + '@';
89
    name[0] = ((x[0] & 0x7C) >> 2) + '@';
90
    name[1] = ((x[0] & 0x03) << 3) + ((x[1] & 0xE0) >> 5) + '@';
90
    name[1] = ((x[0] & 0x03) << 3) + ((x[1] & 0xE0) >> 5) + '@';
91
    name[2] = (x[1] & 0x1F) + '@';
91
    name[2] = (x[1] & 0x1F) + '@';
92
    name[3] = 0;
92
    name[3] = 0;
93
 
93
 
94
    return name;
94
    return name;
95
}
95
}
96
 
96
 
97
bool set_mode(struct drm_device *dev, struct drm_connector *connector,
97
bool set_mode(struct drm_device *dev, struct drm_connector *connector,
98
              videomode_t *reqmode, bool strict)
98
              videomode_t *reqmode, bool strict)
99
{
99
{
100
    drm_i915_private_t      *dev_priv   = dev->dev_private;
100
    drm_i915_private_t      *dev_priv   = dev->dev_private;
101
    struct drm_fb_helper    *fb_helper  = &dev_priv->fbdev->helper;
101
    struct drm_fb_helper    *fb_helper  = &dev_priv->fbdev->helper;
102
 
102
 
103
    struct drm_mode_config  *config     = &dev->mode_config;
103
    struct drm_mode_config  *config     = &dev->mode_config;
104
    struct drm_display_mode *mode       = NULL, *tmpmode;
104
    struct drm_display_mode *mode       = NULL, *tmpmode;
105
    struct drm_framebuffer  *fb         = NULL;
105
    struct drm_framebuffer  *fb         = NULL;
106
    struct drm_crtc         *crtc;
106
    struct drm_crtc         *crtc;
107
    struct drm_encoder      *encoder;
107
    struct drm_encoder      *encoder;
108
    struct drm_mode_set     set;
108
    struct drm_mode_set     set;
109
    char *con_name;
109
    char *con_name;
110
    char *enc_name;
110
    char *enc_name;
111
    unsigned hdisplay, vdisplay;
111
    unsigned hdisplay, vdisplay;
112
    int ret;
112
    int ret;
113
 
113
 
114
    mutex_lock(&dev->mode_config.mutex);
114
    mutex_lock(&dev->mode_config.mutex);
115
 
115
 
116
    list_for_each_entry(tmpmode, &connector->modes, head)
116
    list_for_each_entry(tmpmode, &connector->modes, head)
117
    {
117
    {
118
        if( (drm_mode_width(tmpmode)    == reqmode->width)  &&
118
        if( (drm_mode_width(tmpmode)    == reqmode->width)  &&
119
            (drm_mode_height(tmpmode)   == reqmode->height) &&
119
            (drm_mode_height(tmpmode)   == reqmode->height) &&
120
            (drm_mode_vrefresh(tmpmode) == reqmode->freq) )
120
            (drm_mode_vrefresh(tmpmode) == reqmode->freq) )
121
        {
121
        {
122
            mode = tmpmode;
122
            mode = tmpmode;
123
            goto do_set;
123
            goto do_set;
124
        }
124
        }
125
    };
125
    };
126
 
126
 
127
    if( (mode == NULL) && (strict == false) )
127
    if( (mode == NULL) && (strict == false) )
128
    {
128
    {
129
        list_for_each_entry(tmpmode, &connector->modes, head)
129
        list_for_each_entry(tmpmode, &connector->modes, head)
130
        {
130
        {
131
            if( (drm_mode_width(tmpmode)  == reqmode->width)  &&
131
            if( (drm_mode_width(tmpmode)  == reqmode->width)  &&
132
                (drm_mode_height(tmpmode) == reqmode->height) )
132
                (drm_mode_height(tmpmode) == reqmode->height) )
133
            {
133
            {
134
                mode = tmpmode;
134
                mode = tmpmode;
135
                goto do_set;
135
                goto do_set;
136
            }
136
            }
137
        };
137
        };
138
    };
138
    };
139
 
139
 
140
    DRM_ERROR("%s failed\n", __FUNCTION__);
140
    DRM_ERROR("%s failed\n", __FUNCTION__);
141
 
141
 
142
    return -1;
142
    return -1;
143
 
143
 
144
do_set:
144
do_set:
145
 
145
 
146
    encoder = connector->encoder;
146
    encoder = connector->encoder;
147
    crtc = encoder->crtc;
147
    crtc = encoder->crtc;
148
 
148
 
149
    con_name = drm_get_connector_name(connector);
149
    con_name = drm_get_connector_name(connector);
150
    enc_name = drm_get_encoder_name(encoder);
150
    enc_name = drm_get_encoder_name(encoder);
151
 
151
 
152
    DRM_DEBUG_KMS("set mode %d %d: crtc %d connector %s encoder %s\n",
152
    DRM_DEBUG_KMS("set mode %d %d: crtc %d connector %s encoder %s\n",
153
              reqmode->width, reqmode->height, crtc->base.id,
153
              reqmode->width, reqmode->height, crtc->base.id,
154
              con_name, enc_name);
154
              con_name, enc_name);
155
 
155
 
156
    drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
156
    drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
157
 
157
 
158
    hdisplay = mode->hdisplay;
158
    hdisplay = mode->hdisplay;
159
    vdisplay = mode->vdisplay;
159
    vdisplay = mode->vdisplay;
160
 
160
 
161
    if (crtc->invert_dimensions)
161
    if (crtc->invert_dimensions)
162
        swap(hdisplay, vdisplay);
162
        swap(hdisplay, vdisplay);
163
 
163
 
164
    fb = fb_helper->fb;
164
    fb = fb_helper->fb;
165
 
165
 
166
    fb->width  = reqmode->width;
166
    fb->width  = reqmode->width;
167
    fb->height = reqmode->height;
167
    fb->height = reqmode->height;
168
    fb->pitches[0]  = ALIGN(reqmode->width * 4, 64);
168
    fb->pitches[0]  = ALIGN(reqmode->width * 4, 64);
169
    fb->pitches[1]  = ALIGN(reqmode->width * 4, 64);
169
    fb->pitches[1]  = ALIGN(reqmode->width * 4, 64);
170
    fb->pitches[2]  = ALIGN(reqmode->width * 4, 64);
170
    fb->pitches[2]  = ALIGN(reqmode->width * 4, 64);
171
    fb->pitches[3]  = ALIGN(reqmode->width * 4, 64);
171
    fb->pitches[3]  = ALIGN(reqmode->width * 4, 64);
172
 
172
 
173
    fb->bits_per_pixel = 32;
173
    fb->bits_per_pixel = 32;
174
    fb->depth = 24;
174
    fb->depth = 24;
175
 
175
 
176
    crtc->fb = fb;
176
    crtc->fb = fb;
177
    crtc->enabled = true;
177
    crtc->enabled = true;
178
    os_display->crtc = crtc;
178
    os_display->crtc = crtc;
179
 
179
 
180
    set.crtc = crtc;
180
    set.crtc = crtc;
181
    set.x = 0;
181
    set.x = 0;
182
    set.y = 0;
182
    set.y = 0;
183
    set.mode = mode;
183
    set.mode = mode;
184
    set.connectors = &connector;
184
    set.connectors = &connector;
185
    set.num_connectors = 1;
185
    set.num_connectors = 1;
186
    set.fb = fb;
186
    set.fb = fb;
187
    ret = crtc->funcs->set_config(&set);
187
    ret = crtc->funcs->set_config(&set);
188
    mutex_unlock(&dev->mode_config.mutex);
188
    mutex_unlock(&dev->mode_config.mutex);
189
 
189
 
190
    if ( !ret )
190
    if ( !ret )
191
    {
191
    {
192
        os_display->width    = fb->width;
192
        os_display->width    = fb->width;
193
        os_display->height   = fb->height;
193
        os_display->height   = fb->height;
194
        os_display->pitch    = fb->pitches[0];
194
        os_display->pitch    = fb->pitches[0];
195
        os_display->vrefresh = drm_mode_vrefresh(mode);
195
        os_display->vrefresh = drm_mode_vrefresh(mode);
196
 
196
 
197
        sysSetScreen(fb->width, fb->height, fb->pitches[0]);
197
        sysSetScreen(fb->width, fb->height, fb->pitches[0]);
198
 
198
 
199
        DRM_DEBUG_KMS("new mode %d x %d pitch %d\n",
199
        DRM_DEBUG_KMS("new mode %d x %d pitch %d\n",
200
                       fb->width, fb->height, fb->pitches[0]);
200
                       fb->width, fb->height, fb->pitches[0]);
201
    }
201
    }
202
    else
202
    else
203
        DRM_ERROR("failed to set mode %d_%d on crtc %p\n",
203
        DRM_ERROR("failed to set mode %d_%d on crtc %p\n",
204
                   fb->width, fb->height, crtc);
204
                   fb->width, fb->height, crtc);
205
 
205
 
206
 
206
 
207
    return ret;
207
    return ret;
208
}
208
}
209
 
209
 
210
static int count_connector_modes(struct drm_connector* connector)
210
static int count_connector_modes(struct drm_connector* connector)
211
{
211
{
212
    struct drm_display_mode  *mode;
212
    struct drm_display_mode  *mode;
213
    int count = 0;
213
    int count = 0;
214
 
214
 
215
    list_for_each_entry(mode, &connector->modes, head)
215
    list_for_each_entry(mode, &connector->modes, head)
216
    {
216
    {
217
        count++;
217
        count++;
218
    };
218
    };
219
    return count;
219
    return count;
220
};
220
};
221
 
221
 
222
static struct drm_connector* get_def_connector(struct drm_device *dev)
222
static struct drm_connector* get_def_connector(struct drm_device *dev)
223
{
223
{
224
    struct drm_connector  *connector;
224
    struct drm_connector  *connector;
225
    struct drm_connector_helper_funcs *connector_funcs;
225
    struct drm_connector_helper_funcs *connector_funcs;
226
 
226
 
227
    struct drm_connector  *def_connector = NULL;
227
    struct drm_connector  *def_connector = NULL;
228
 
228
 
229
    list_for_each_entry(connector, &dev->mode_config.connector_list, head)
229
    list_for_each_entry(connector, &dev->mode_config.connector_list, head)
230
    {
230
    {
231
        struct drm_encoder  *encoder;
231
        struct drm_encoder  *encoder;
232
        struct drm_crtc     *crtc;
232
        struct drm_crtc     *crtc;
233
 
233
 
234
        if( connector->status != connector_status_connected)
234
        if( connector->status != connector_status_connected)
235
            continue;
235
            continue;
236
 
236
 
237
        connector_funcs = connector->helper_private;
237
        connector_funcs = connector->helper_private;
238
        encoder = connector_funcs->best_encoder(connector);
238
        encoder = connector_funcs->best_encoder(connector);
239
        if( encoder == NULL)
239
        if( encoder == NULL)
240
            continue;
240
            continue;
241
 
241
 
242
        connector->encoder = encoder;
242
        connector->encoder = encoder;
243
 
243
 
244
        crtc = encoder->crtc;
244
        crtc = encoder->crtc;
245
 
245
 
246
        DRM_DEBUG_KMS("CONNECTOR %x ID:  %d status %d encoder %x\n crtc %x",
246
        DRM_DEBUG_KMS("CONNECTOR %x ID:  %d status %d encoder %x\n crtc %x",
247
                   connector, connector->base.id,
247
                   connector, connector->base.id,
248
                   connector->status, connector->encoder,
248
                   connector->status, connector->encoder,
249
                   crtc);
249
                   crtc);
250
 
250
 
251
//        if (crtc == NULL)
251
//        if (crtc == NULL)
252
//            continue;
252
//            continue;
253
 
253
 
254
        def_connector = connector;
254
        def_connector = connector;
255
 
255
 
256
        break;
256
        break;
257
    };
257
    };
258
 
258
 
259
    return def_connector;
259
    return def_connector;
260
};
260
};
261
 
261
 
262
 
262
 
263
int init_display_kms(struct drm_device *dev)
263
int init_display_kms(struct drm_device *dev)
264
{
264
{
265
    struct drm_connector    *connector;
265
    struct drm_connector    *connector;
266
    struct drm_connector_helper_funcs *connector_funcs;
266
    struct drm_connector_helper_funcs *connector_funcs;
267
    struct drm_encoder      *encoder;
267
    struct drm_encoder      *encoder;
268
    struct drm_crtc         *crtc = NULL;
268
    struct drm_crtc         *crtc = NULL;
269
    struct drm_framebuffer  *fb;
269
    struct drm_framebuffer  *fb;
270
 
270
 
271
    cursor_t  *cursor;
271
    cursor_t  *cursor;
272
    u32_t      ifl;
272
    u32_t      ifl;
273
    int        err;
273
    int        err;
274
 
274
 
275
    list_for_each_entry(connector, &dev->mode_config.connector_list, head)
275
    list_for_each_entry(connector, &dev->mode_config.connector_list, head)
276
    {
276
    {
277
        if( connector->status != connector_status_connected)
277
        if( connector->status != connector_status_connected)
278
            continue;
278
            continue;
279
 
279
 
280
        connector_funcs = connector->helper_private;
280
        connector_funcs = connector->helper_private;
281
        encoder = connector_funcs->best_encoder(connector);
281
        encoder = connector_funcs->best_encoder(connector);
282
        if( encoder == NULL)
282
        if( encoder == NULL)
283
        {
283
        {
284
            DRM_DEBUG_KMS("CONNECTOR %x ID: %d no active encoders\n",
284
            DRM_DEBUG_KMS("CONNECTOR %x ID: %d no active encoders\n",
285
                      connector, connector->base.id);
285
                      connector, connector->base.id);
286
            continue;
286
            continue;
287
        }
287
        }
288
        connector->encoder = encoder;
288
        connector->encoder = encoder;
289
        crtc = encoder->crtc;
289
        crtc = encoder->crtc;
290
 
290
 
291
        DRM_DEBUG_KMS("CONNECTOR %x ID:%d status:%d ENCODER %x CRTC %x ID:%d\n",
291
        DRM_DEBUG_KMS("CONNECTOR %x ID:%d status:%d ENCODER %x CRTC %x ID:%d\n",
292
               connector, connector->base.id,
292
               connector, connector->base.id,
293
               connector->status, connector->encoder,
293
               connector->status, connector->encoder,
294
               crtc, crtc->base.id );
294
               crtc, crtc->base.id );
295
 
295
 
296
        break;
296
        break;
297
    };
297
    };
298
 
298
 
299
    if(connector == NULL)
299
    if(connector == NULL)
300
    {
300
    {
301
        DRM_ERROR("No active connectors!\n");
301
        DRM_ERROR("No active connectors!\n");
302
        return -1;
302
        return -1;
303
    };
303
    };
304
 
304
 
305
    if(crtc == NULL)
305
    if(crtc == NULL)
306
    {
306
    {
307
        struct drm_crtc *tmp_crtc;
307
        struct drm_crtc *tmp_crtc;
308
        int crtc_mask = 1;
308
        int crtc_mask = 1;
309
 
309
 
310
        list_for_each_entry(tmp_crtc, &dev->mode_config.crtc_list, head)
310
        list_for_each_entry(tmp_crtc, &dev->mode_config.crtc_list, head)
311
        {
311
        {
312
            if (encoder->possible_crtcs & crtc_mask)
312
            if (encoder->possible_crtcs & crtc_mask)
313
            {
313
            {
314
                crtc = tmp_crtc;
314
                crtc = tmp_crtc;
315
                encoder->crtc = crtc;
315
                encoder->crtc = crtc;
316
                break;
316
                break;
317
            };
317
            };
318
            crtc_mask <<= 1;
318
            crtc_mask <<= 1;
319
        };
319
        };
320
    };
320
    };
321
 
321
 
322
    if(crtc == NULL)
322
    if(crtc == NULL)
323
    {
323
    {
324
        DRM_ERROR("No CRTC for encoder %d\n", encoder->base.id);
324
        DRM_ERROR("No CRTC for encoder %d\n", encoder->base.id);
325
        return -1;
325
        return -1;
326
    };
326
    };
327
 
327
 
328
 
328
 
329
    DRM_DEBUG_KMS("[Select CRTC:%d]\n", crtc->base.id);
329
    DRM_DEBUG_KMS("[Select CRTC:%d]\n", crtc->base.id);
330
 
330
 
331
    os_display = GetDisplay();
331
    os_display = GetDisplay();
332
    os_display->ddev = dev;
332
    os_display->ddev = dev;
333
    os_display->connector = connector;
333
    os_display->connector = connector;
334
    os_display->crtc = crtc;
334
    os_display->crtc = crtc;
335
 
335
 
336
    os_display->supported_modes = count_connector_modes(connector);
336
    os_display->supported_modes = count_connector_modes(connector);
337
 
337
 
338
 
338
 
339
    ifl = safe_cli();
339
    ifl = safe_cli();
340
    {
340
    {
341
        struct intel_crtc *intel_crtc = to_intel_crtc(os_display->crtc);
341
        struct intel_crtc *intel_crtc = to_intel_crtc(os_display->crtc);
342
 
342
 
343
        list_for_each_entry(cursor, &os_display->cursors, list)
343
        list_for_each_entry(cursor, &os_display->cursors, list)
344
        {
344
        {
345
            init_cursor(cursor);
345
            init_cursor(cursor);
346
        };
346
        };
347
 
347
 
348
        os_display->restore_cursor(0,0);
348
        os_display->restore_cursor(0,0);
349
        os_display->init_cursor    = init_cursor;
349
        os_display->init_cursor    = init_cursor;
350
        os_display->select_cursor  = select_cursor_kms;
350
        os_display->select_cursor  = select_cursor_kms;
351
        os_display->show_cursor    = NULL;
351
        os_display->show_cursor    = NULL;
352
        os_display->move_cursor    = move_cursor_kms;
352
        os_display->move_cursor    = move_cursor_kms;
353
        os_display->restore_cursor = restore_cursor;
353
        os_display->restore_cursor = restore_cursor;
354
        os_display->disable_mouse  = disable_mouse;
354
        os_display->disable_mouse  = disable_mouse;
355
 
355
 
356
        intel_crtc->cursor_x = os_display->width/2;
356
        intel_crtc->cursor_x = os_display->width/2;
357
        intel_crtc->cursor_y = os_display->height/2;
357
        intel_crtc->cursor_y = os_display->height/2;
358
 
358
 
359
        select_cursor_kms(os_display->cursor);
359
        select_cursor_kms(os_display->cursor);
360
    };
360
    };
361
    safe_sti(ifl);
361
    safe_sti(ifl);
362
 
362
 
363
#ifdef __HWA__
363
#ifdef __HWA__
364
    err = init_bitmaps();
364
    err = init_bitmaps();
365
#endif
365
#endif
366
 
366
 
367
    return 0;
367
    return 0;
368
};
368
};
369
 
369
 
370
 
370
 
371
int get_videomodes(videomode_t *mode, int *count)
371
int get_videomodes(videomode_t *mode, int *count)
372
{
372
{
373
    int err = -1;
373
    int err = -1;
374
 
374
 
375
//    dbgprintf("mode %x count %d\n", mode, *count);
375
//    dbgprintf("mode %x count %d\n", mode, *count);
376
 
376
 
377
    if( *count == 0 )
377
    if( *count == 0 )
378
    {
378
    {
379
        *count = os_display->supported_modes;
379
        *count = os_display->supported_modes;
380
        err = 0;
380
        err = 0;
381
    }
381
    }
382
    else if( mode != NULL )
382
    else if( mode != NULL )
383
    {
383
    {
384
        struct drm_display_mode  *drmmode;
384
        struct drm_display_mode  *drmmode;
385
        int i = 0;
385
        int i = 0;
386
 
386
 
387
        if( *count > os_display->supported_modes)
387
        if( *count > os_display->supported_modes)
388
            *count = os_display->supported_modes;
388
            *count = os_display->supported_modes;
389
 
389
 
390
        list_for_each_entry(drmmode, &os_display->connector->modes, head)
390
        list_for_each_entry(drmmode, &os_display->connector->modes, head)
391
        {
391
        {
392
            if( i < *count)
392
            if( i < *count)
393
            {
393
            {
394
                mode->width  = drm_mode_width(drmmode);
394
                mode->width  = drm_mode_width(drmmode);
395
                mode->height = drm_mode_height(drmmode);
395
                mode->height = drm_mode_height(drmmode);
396
                mode->bpp    = 32;
396
                mode->bpp    = 32;
397
                mode->freq   = drm_mode_vrefresh(drmmode);
397
                mode->freq   = drm_mode_vrefresh(drmmode);
398
                i++;
398
                i++;
399
                mode++;
399
                mode++;
400
            }
400
            }
401
            else break;
401
            else break;
402
        };
402
        };
403
        *count = i;
403
        *count = i;
404
        err = 0;
404
        err = 0;
405
    };
405
    };
406
    return err;
406
    return err;
407
};
407
};
408
 
408
 
409
int set_user_mode(videomode_t *mode)
409
int set_user_mode(videomode_t *mode)
410
{
410
{
411
    int err = -1;
411
    int err = -1;
412
 
412
 
413
//    dbgprintf("width %d height %d vrefresh %d\n",
413
//    dbgprintf("width %d height %d vrefresh %d\n",
414
//               mode->width, mode->height, mode->freq);
414
//               mode->width, mode->height, mode->freq);
415
 
415
 
416
    if( (mode->width  != 0)  &&
416
    if( (mode->width  != 0)  &&
417
        (mode->height != 0)  &&
417
        (mode->height != 0)  &&
418
        (mode->freq   != 0 ) &&
418
        (mode->freq   != 0 ) &&
419
        ( (mode->width   != os_display->width)  ||
419
        ( (mode->width   != os_display->width)  ||
420
          (mode->height  != os_display->height) ||
420
          (mode->height  != os_display->height) ||
421
          (mode->freq    != os_display->vrefresh) ) )
421
          (mode->freq    != os_display->vrefresh) ) )
422
    {
422
    {
423
        if( set_mode(os_display->ddev, os_display->connector, mode, true) )
423
        if( set_mode(os_display->ddev, os_display->connector, mode, true) )
424
            err = 0;
424
            err = 0;
425
    };
425
    };
426
 
426
 
427
    return err;
427
    return err;
428
};
428
};
429
 
429
 
-
 
430
void i915_dpms(struct drm_device *dev, int mode)
-
 
431
{
-
 
432
    struct drm_connector_funcs *f = os_display->connector->funcs;
-
 
433
 
-
 
434
    f->dpms(os_display->connector, mode);
-
 
435
};
-
 
436
 
430
void __attribute__((regparm(1))) destroy_cursor(cursor_t *cursor)
437
void __attribute__((regparm(1))) destroy_cursor(cursor_t *cursor)
431
{
438
{
432
    list_del(&cursor->list);
439
    list_del(&cursor->list);
433
 
440
 
434
    i915_gem_object_unpin(cursor->cobj);
441
    i915_gem_object_unpin(cursor->cobj);
435
 
442
 
436
    mutex_lock(&main_device->struct_mutex);
443
    mutex_lock(&main_device->struct_mutex);
437
    drm_gem_object_unreference(&cursor->cobj->base);
444
    drm_gem_object_unreference(&cursor->cobj->base);
438
    mutex_unlock(&main_device->struct_mutex);
445
    mutex_unlock(&main_device->struct_mutex);
439
 
446
 
440
    __DestroyObject(cursor);
447
    __DestroyObject(cursor);
441
};
448
};
442
 
449
 
443
int init_cursor(cursor_t *cursor)
450
int init_cursor(cursor_t *cursor)
444
{
451
{
445
    struct drm_i915_private *dev_priv = os_display->ddev->dev_private;
452
    struct drm_i915_private *dev_priv = os_display->ddev->dev_private;
446
    struct drm_i915_gem_object *obj;
453
    struct drm_i915_gem_object *obj;
447
    uint32_t *bits;
454
    uint32_t *bits;
448
    uint32_t *src;
455
    uint32_t *src;
449
    void     *mapped;
456
    void     *mapped;
450
 
457
 
451
    int       i,j;
458
    int       i,j;
452
    int       ret;
459
    int       ret;
453
 
460
 
454
    if (dev_priv->info->cursor_needs_physical)
461
    if (dev_priv->info->cursor_needs_physical)
455
    {
462
    {
456
        bits = (uint32_t*)KernelAlloc(CURSOR_WIDTH*CURSOR_HEIGHT*4);
463
        bits = (uint32_t*)KernelAlloc(CURSOR_WIDTH*CURSOR_HEIGHT*4);
457
        if (unlikely(bits == NULL))
464
        if (unlikely(bits == NULL))
458
            return ENOMEM;
465
            return ENOMEM;
459
        cursor->cobj = (struct drm_i915_gem_object *)GetPgAddr(bits);
466
        cursor->cobj = (struct drm_i915_gem_object *)GetPgAddr(bits);
460
    }
467
    }
461
    else
468
    else
462
    {
469
    {
463
        obj = i915_gem_alloc_object(os_display->ddev, CURSOR_WIDTH*CURSOR_HEIGHT*4);
470
        obj = i915_gem_alloc_object(os_display->ddev, CURSOR_WIDTH*CURSOR_HEIGHT*4);
464
        if (unlikely(obj == NULL))
471
        if (unlikely(obj == NULL))
465
            return -ENOMEM;
472
            return -ENOMEM;
466
 
473
 
467
        ret = i915_gem_obj_ggtt_pin(obj, CURSOR_WIDTH*CURSOR_HEIGHT*4, true, true);
474
        ret = i915_gem_obj_ggtt_pin(obj, CURSOR_WIDTH*CURSOR_HEIGHT*4, true, true);
468
        if (ret) {
475
        if (ret) {
469
            drm_gem_object_unreference(&obj->base);
476
            drm_gem_object_unreference(&obj->base);
470
            return ret;
477
            return ret;
471
        }
478
        }
472
 
479
 
473
        ret = i915_gem_object_set_to_gtt_domain(obj, true);
480
        ret = i915_gem_object_set_to_gtt_domain(obj, true);
474
        if (ret)
481
        if (ret)
475
        {
482
        {
476
            i915_gem_object_unpin(obj);
483
            i915_gem_object_unpin(obj);
477
            drm_gem_object_unreference(&obj->base);
484
            drm_gem_object_unreference(&obj->base);
478
            return ret;
485
            return ret;
479
        }
486
        }
480
/* You don't need to worry about fragmentation issues.
487
/* You don't need to worry about fragmentation issues.
481
 * GTT space is continuous. I guarantee it.                           */
488
 * GTT space is continuous. I guarantee it.                           */
482
 
489
 
483
        mapped = bits = (u32*)MapIoMem(dev_priv->gtt.mappable_base + i915_gem_obj_ggtt_offset(obj),
490
        mapped = bits = (u32*)MapIoMem(dev_priv->gtt.mappable_base + i915_gem_obj_ggtt_offset(obj),
484
                    CURSOR_WIDTH*CURSOR_HEIGHT*4, PG_SW);
491
                    CURSOR_WIDTH*CURSOR_HEIGHT*4, PG_SW);
485
 
492
 
486
        if (unlikely(bits == NULL))
493
        if (unlikely(bits == NULL))
487
        {
494
        {
488
            i915_gem_object_unpin(obj);
495
            i915_gem_object_unpin(obj);
489
            drm_gem_object_unreference(&obj->base);
496
            drm_gem_object_unreference(&obj->base);
490
            return -ENOMEM;
497
            return -ENOMEM;
491
        };
498
        };
492
        cursor->cobj = obj;
499
        cursor->cobj = obj;
493
    };
500
    };
494
 
501
 
495
    src = cursor->data;
502
    src = cursor->data;
496
 
503
 
497
    for(i = 0; i < 32; i++)
504
    for(i = 0; i < 32; i++)
498
    {
505
    {
499
        for(j = 0; j < 32; j++)
506
        for(j = 0; j < 32; j++)
500
            *bits++ = *src++;
507
            *bits++ = *src++;
501
        for(j = 32; j < CURSOR_WIDTH; j++)
508
        for(j = 32; j < CURSOR_WIDTH; j++)
502
            *bits++ = 0;
509
            *bits++ = 0;
503
    }
510
    }
504
    for(i = 0; i < CURSOR_WIDTH*(CURSOR_HEIGHT-32); i++)
511
    for(i = 0; i < CURSOR_WIDTH*(CURSOR_HEIGHT-32); i++)
505
        *bits++ = 0;
512
        *bits++ = 0;
506
 
513
 
507
    FreeKernelSpace(mapped);
514
    FreeKernelSpace(mapped);
508
 
515
 
509
// release old cursor
516
// release old cursor
510
 
517
 
511
    KernelFree(cursor->data);
518
    KernelFree(cursor->data);
512
 
519
 
513
    cursor->data = bits;
520
    cursor->data = bits;
514
 
521
 
515
    cursor->header.destroy = destroy_cursor;
522
    cursor->header.destroy = destroy_cursor;
516
 
523
 
517
    return 0;
524
    return 0;
518
}
525
}
519
 
526
 
520
 
527
 
521
static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
528
static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
522
{
529
{
523
    struct drm_device *dev = crtc->dev;
530
    struct drm_device *dev = crtc->dev;
524
    struct drm_i915_private *dev_priv = dev->dev_private;
531
    struct drm_i915_private *dev_priv = dev->dev_private;
525
    struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
532
    struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
526
    int pipe = intel_crtc->pipe;
533
    int pipe = intel_crtc->pipe;
527
    bool visible = base != 0;
534
    bool visible = base != 0;
528
 
535
 
529
    if (intel_crtc->cursor_visible != visible) {
536
    if (intel_crtc->cursor_visible != visible) {
530
        uint32_t cntl = I915_READ(CURCNTR(pipe));
537
        uint32_t cntl = I915_READ(CURCNTR(pipe));
531
        if (base) {
538
        if (base) {
532
            cntl &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT);
539
            cntl &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT);
533
            cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
540
            cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
534
            cntl |= pipe << 28; /* Connect to correct pipe */
541
            cntl |= pipe << 28; /* Connect to correct pipe */
535
        } else {
542
        } else {
536
            cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
543
            cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
537
            cntl |= CURSOR_MODE_DISABLE;
544
            cntl |= CURSOR_MODE_DISABLE;
538
        }
545
        }
539
        I915_WRITE(CURCNTR(pipe), cntl);
546
        I915_WRITE(CURCNTR(pipe), cntl);
540
 
547
 
541
        intel_crtc->cursor_visible = visible;
548
        intel_crtc->cursor_visible = visible;
542
    }
549
    }
543
    /* and commit changes on next vblank */
550
    /* and commit changes on next vblank */
544
    I915_WRITE(CURBASE(pipe), base);
551
    I915_WRITE(CURBASE(pipe), base);
545
}
552
}
546
 
553
 
547
void __stdcall move_cursor_kms(cursor_t *cursor, int x, int y)
554
void __stdcall move_cursor_kms(cursor_t *cursor, int x, int y)
548
{
555
{
549
    struct drm_i915_private *dev_priv = os_display->ddev->dev_private;
556
    struct drm_i915_private *dev_priv = os_display->ddev->dev_private;
550
    struct intel_crtc *intel_crtc = to_intel_crtc(os_display->crtc);
557
    struct intel_crtc *intel_crtc = to_intel_crtc(os_display->crtc);
551
    u32 base, pos;
558
    u32 base, pos;
552
    bool visible;
559
    bool visible;
553
 
560
 
554
    int pipe = intel_crtc->pipe;
561
    int pipe = intel_crtc->pipe;
555
 
562
 
556
    intel_crtc->cursor_x = x;
563
    intel_crtc->cursor_x = x;
557
    intel_crtc->cursor_y = y;
564
    intel_crtc->cursor_y = y;
558
 
565
 
559
    x = x - cursor->hot_x;
566
    x = x - cursor->hot_x;
560
    y = y - cursor->hot_y;
567
    y = y - cursor->hot_y;
561
 
568
 
562
 
569
 
563
    pos = 0;
570
    pos = 0;
564
 
571
 
565
    base = intel_crtc->cursor_addr;
572
    base = intel_crtc->cursor_addr;
566
    if (x >= os_display->width)
573
    if (x >= os_display->width)
567
        base = 0;
574
        base = 0;
568
 
575
 
569
    if (y >= os_display->height)
576
    if (y >= os_display->height)
570
        base = 0;
577
        base = 0;
571
 
578
 
572
    if (x < 0)
579
    if (x < 0)
573
    {
580
    {
574
        if (x + intel_crtc->cursor_width < 0)
581
        if (x + intel_crtc->cursor_width < 0)
575
            base = 0;
582
            base = 0;
576
 
583
 
577
        pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
584
        pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
578
        x = -x;
585
        x = -x;
579
    }
586
    }
580
    pos |= x << CURSOR_X_SHIFT;
587
    pos |= x << CURSOR_X_SHIFT;
581
 
588
 
582
    if (y < 0)
589
    if (y < 0)
583
    {
590
    {
584
        if (y + intel_crtc->cursor_height < 0)
591
        if (y + intel_crtc->cursor_height < 0)
585
            base = 0;
592
            base = 0;
586
 
593
 
587
        pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
594
        pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
588
        y = -y;
595
        y = -y;
589
    }
596
    }
590
    pos |= y << CURSOR_Y_SHIFT;
597
    pos |= y << CURSOR_Y_SHIFT;
591
 
598
 
592
    visible = base != 0;
599
    visible = base != 0;
593
    if (!visible && !intel_crtc->cursor_visible)
600
    if (!visible && !intel_crtc->cursor_visible)
594
        return;
601
        return;
595
 
602
 
596
    I915_WRITE(CURPOS(pipe), pos);
603
    I915_WRITE(CURPOS(pipe), pos);
597
//    if (IS_845G(dev) || IS_I865G(dev))
604
//    if (IS_845G(dev) || IS_I865G(dev))
598
//        i845_update_cursor(crtc, base);
605
//        i845_update_cursor(crtc, base);
599
//    else
606
//    else
600
        i9xx_update_cursor(os_display->crtc, base);
607
        i9xx_update_cursor(os_display->crtc, base);
601
 
608
 
602
};
609
};
603
 
610
 
604
 
611
 
605
cursor_t* __stdcall select_cursor_kms(cursor_t *cursor)
612
cursor_t* __stdcall select_cursor_kms(cursor_t *cursor)
606
{
613
{
607
    struct drm_i915_private *dev_priv = os_display->ddev->dev_private;
614
    struct drm_i915_private *dev_priv = os_display->ddev->dev_private;
608
    struct intel_crtc *intel_crtc = to_intel_crtc(os_display->crtc);
615
    struct intel_crtc *intel_crtc = to_intel_crtc(os_display->crtc);
609
    cursor_t *old;
616
    cursor_t *old;
610
 
617
 
611
    old = os_display->cursor;
618
    old = os_display->cursor;
612
    os_display->cursor = cursor;
619
    os_display->cursor = cursor;
613
 
620
 
614
    if (!dev_priv->info->cursor_needs_physical)
621
    if (!dev_priv->info->cursor_needs_physical)
615
       intel_crtc->cursor_addr = i915_gem_obj_ggtt_offset(cursor->cobj);
622
       intel_crtc->cursor_addr = i915_gem_obj_ggtt_offset(cursor->cobj);
616
    else
623
    else
617
        intel_crtc->cursor_addr = (addr_t)cursor->cobj;
624
        intel_crtc->cursor_addr = (addr_t)cursor->cobj;
618
 
625
 
619
    intel_crtc->cursor_width = 32;
626
    intel_crtc->cursor_width = 32;
620
    intel_crtc->cursor_height = 32;
627
    intel_crtc->cursor_height = 32;
621
 
628
 
622
    move_cursor_kms(cursor, intel_crtc->cursor_x, intel_crtc->cursor_y);
629
    move_cursor_kms(cursor, intel_crtc->cursor_x, intel_crtc->cursor_y);
623
    return old;
630
    return old;
624
};
631
};
625
 
632
 
626
struct sna_fb
633
struct sna_fb
627
{
634
{
628
    uint32_t  width;
635
    uint32_t  width;
629
    uint32_t  height;
636
    uint32_t  height;
630
    uint32_t  pitch;
637
    uint32_t  pitch;
631
    uint32_t  tiling;
638
    uint32_t  tiling;
632
};
639
};
633
 
640
 
634
int i915_fbinfo(struct sna_fb *fb)
641
int i915_fbinfo(struct sna_fb *fb)
635
{
642
{
636
    fb->width  = os_display->width;
643
    fb->width  = os_display->width;
637
    fb->height = os_display->height;
644
    fb->height = os_display->height;
638
    fb->pitch  = os_display->pitch;
645
    fb->pitch  = os_display->pitch;
639
    fb->tiling = 0;
646
    fb->tiling = 0;
640
 
647
 
641
    return 0;
648
    return 0;
642
};
649
};
643
 
650
 
644
typedef struct
651
typedef struct
645
{
652
{
646
    int left;
653
    int left;
647
    int top;
654
    int top;
648
    int right;
655
    int right;
649
    int bottom;
656
    int bottom;
650
}rect_t;
657
}rect_t;
651
 
658
 
652
struct drm_i915_mask {
659
struct drm_i915_mask {
653
    __u32 handle;
660
    __u32 handle;
654
    __u32 width;
661
    __u32 width;
655
    __u32 height;
662
    __u32 height;
656
    __u32 bo_size;
663
    __u32 bo_size;
657
    __u32 bo_pitch;
664
    __u32 bo_pitch;
658
    __u32 bo_map;
665
    __u32 bo_map;
659
};
666
};
660
 
667
 
661
#define CURRENT_TASK             (0x80003000)
668
#define CURRENT_TASK             (0x80003000)
662
 
669
 
663
static u32_t get_display_map()
670
static u32_t get_display_map()
664
{
671
{
665
    u32_t   addr;
672
    u32_t   addr;
666
 
673
 
667
    addr = (u32_t)os_display;
674
    addr = (u32_t)os_display;
668
    addr+= sizeof(display_t);            /*  shoot me  */
675
    addr+= sizeof(display_t);            /*  shoot me  */
669
    return *(u32_t*)addr;
676
    return *(u32_t*)addr;
670
}
677
}
671
 
678
 
672
void  FASTCALL GetWindowRect(rect_t *rc)__asm__("GetWindowRect");
679
void  FASTCALL GetWindowRect(rect_t *rc)__asm__("GetWindowRect");
673
 
680
 
674
int i915_mask_update(struct drm_device *dev, void *data,
681
int i915_mask_update(struct drm_device *dev, void *data,
675
            struct drm_file *file)
682
            struct drm_file *file)
676
{
683
{
677
    struct drm_i915_mask *mask = data;
684
    struct drm_i915_mask *mask = data;
678
    struct drm_gem_object *obj;
685
    struct drm_gem_object *obj;
679
    static unsigned int mask_seqno[256];
686
    static unsigned int mask_seqno[256];
680
    rect_t winrc;
687
    rect_t winrc;
681
    u32    slot;
688
    u32    slot;
682
    int    ret;
689
    int    ret;
683
 
690
 
684
     if(mask->handle == -2)
691
     if(mask->handle == -2)
685
     {
692
     {
686
        printf("%s handle %d\n", __FUNCTION__, mask->handle);
693
        printf("%s handle %d\n", __FUNCTION__, mask->handle);
687
        return 0;
694
        return 0;
688
     }
695
     }
689
 
696
 
690
    obj = drm_gem_object_lookup(dev, file, mask->handle);
697
    obj = drm_gem_object_lookup(dev, file, mask->handle);
691
    if (obj == NULL)
698
    if (obj == NULL)
692
        return -ENOENT;
699
        return -ENOENT;
693
 
700
 
694
    if (!obj->filp) {
701
    if (!obj->filp) {
695
        drm_gem_object_unreference_unlocked(obj);
702
        drm_gem_object_unreference_unlocked(obj);
696
        return -EINVAL;
703
        return -EINVAL;
697
    }
704
    }
698
 
705
 
699
    GetWindowRect(&winrc);
706
    GetWindowRect(&winrc);
700
    {
707
    {
701
//        static warn_count;
708
//        static warn_count;
702
 
709
 
703
        mask->width    = winrc.right - winrc.left + 1;
710
        mask->width    = winrc.right - winrc.left + 1;
704
        mask->height   = winrc.bottom - winrc.top + 1;
711
        mask->height   = winrc.bottom - winrc.top + 1;
705
        mask->bo_pitch = (mask->width+15) & ~15;
712
        mask->bo_pitch = (mask->width+15) & ~15;
706
 
713
 
707
#if 0
714
#if 0
708
        if(warn_count < 1)
715
        if(warn_count < 1)
709
        {
716
        {
710
            printf("left %d top %d right %d bottom %d\n",
717
            printf("left %d top %d right %d bottom %d\n",
711
                    winrc.left, winrc.top, winrc.right, winrc.bottom);
718
                    winrc.left, winrc.top, winrc.right, winrc.bottom);
712
            printf("mask pitch %d data %p\n", mask->bo_pitch, mask->bo_size);
719
            printf("mask pitch %d data %p\n", mask->bo_pitch, mask->bo_size);
713
            warn_count++;
720
            warn_count++;
714
        };
721
        };
715
#endif
722
#endif
716
 
723
 
717
     };
724
     };
718
 
725
 
719
 
726
 
720
    slot = *((u8*)CURRENT_TASK);
727
    slot = *((u8*)CURRENT_TASK);
721
 
728
 
722
    if( mask_seqno[slot] != os_display->mask_seqno)
729
    if( mask_seqno[slot] != os_display->mask_seqno)
723
    {
730
    {
724
        u8* src_offset;
731
        u8* src_offset;
725
        u8* dst_offset;
732
        u8* dst_offset;
726
        u32 ifl;
733
        u32 ifl;
727
 
734
 
728
        ret = i915_mutex_lock_interruptible(dev);
735
        ret = i915_mutex_lock_interruptible(dev);
729
        if (ret)
736
        if (ret)
730
            return ret;
737
            return ret;
731
 
738
 
732
        ret = i915_gem_object_set_to_cpu_domain(to_intel_bo(obj), true);
739
        ret = i915_gem_object_set_to_cpu_domain(to_intel_bo(obj), true);
733
        if(ret !=0 )
740
        if(ret !=0 )
734
        {
741
        {
735
            dbgprintf("%s fail\n", __FUNCTION__);
742
            dbgprintf("%s fail\n", __FUNCTION__);
736
            return ret;
743
            return ret;
737
        };
744
        };
738
 
745
 
739
//        printf("width %d height %d\n", winrc.right, winrc.bottom);
746
//        printf("width %d height %d\n", winrc.right, winrc.bottom);
740
 
747
 
741
//        slot = 0x01;
748
//        slot = 0x01;
742
 
749
 
743
 
750
 
744
        src_offset = (u8*)( winrc.top*os_display->width + winrc.left);
751
        src_offset = (u8*)( winrc.top*os_display->width + winrc.left);
745
        src_offset+= get_display_map();
752
        src_offset+= get_display_map();
746
        dst_offset = (u8*)mask->bo_map;
753
        dst_offset = (u8*)mask->bo_map;
747
 
754
 
748
        u32_t tmp_h = mask->height;
755
        u32_t tmp_h = mask->height;
749
 
756
 
750
        ifl = safe_cli();
757
        ifl = safe_cli();
751
        {
758
        {
752
            mask_seqno[slot] = os_display->mask_seqno;
759
            mask_seqno[slot] = os_display->mask_seqno;
753
 
760
 
754
            slot|= (slot<<8)|(slot<<16)|(slot<<24);
761
            slot|= (slot<<8)|(slot<<16)|(slot<<24);
755
 
762
 
756
            __asm__ __volatile__ (
763
            __asm__ __volatile__ (
757
                "movd       %[slot],   %%xmm6    \n"
764
                "movd       %[slot],   %%xmm6    \n"
758
            "punpckldq  %%xmm6, %%xmm6            \n"
765
            "punpckldq  %%xmm6, %%xmm6            \n"
759
            "punpcklqdq %%xmm6, %%xmm6            \n"
766
            "punpcklqdq %%xmm6, %%xmm6            \n"
760
            :: [slot]  "m" (slot)
767
            :: [slot]  "m" (slot)
761
            :"xmm6");
768
            :"xmm6");
762
 
769
 
763
            while( tmp_h--)
770
            while( tmp_h--)
764
            {
771
            {
765
                int tmp_w = mask->bo_pitch;
772
                int tmp_w = mask->bo_pitch;
766
 
773
 
767
                u8* tmp_src = src_offset;
774
                u8* tmp_src = src_offset;
768
                u8* tmp_dst = dst_offset;
775
                u8* tmp_dst = dst_offset;
769
 
776
 
770
                src_offset+= os_display->width;
777
                src_offset+= os_display->width;
771
                dst_offset+= mask->bo_pitch;
778
                dst_offset+= mask->bo_pitch;
772
 
779
 
773
                while(tmp_w >= 64)
780
                while(tmp_w >= 64)
774
                {
781
                {
775
                    __asm__ __volatile__ (
782
                    __asm__ __volatile__ (
776
                    "movdqu     (%0),   %%xmm0            \n"
783
                    "movdqu     (%0),   %%xmm0            \n"
777
                    "movdqu   16(%0),   %%xmm1            \n"
784
                    "movdqu   16(%0),   %%xmm1            \n"
778
                    "movdqu   32(%0),   %%xmm2            \n"
785
                    "movdqu   32(%0),   %%xmm2            \n"
779
                    "movdqu   48(%0),   %%xmm3            \n"
786
                    "movdqu   48(%0),   %%xmm3            \n"
780
                    "pcmpeqb    %%xmm6, %%xmm0            \n"
787
                    "pcmpeqb    %%xmm6, %%xmm0            \n"
781
                    "pcmpeqb    %%xmm6, %%xmm1            \n"
788
                    "pcmpeqb    %%xmm6, %%xmm1            \n"
782
                    "pcmpeqb    %%xmm6, %%xmm2            \n"
789
                    "pcmpeqb    %%xmm6, %%xmm2            \n"
783
                    "pcmpeqb    %%xmm6, %%xmm3            \n"
790
                    "pcmpeqb    %%xmm6, %%xmm3            \n"
784
                    "movdqa     %%xmm0,   (%%edi)         \n"
791
                    "movdqa     %%xmm0,   (%%edi)         \n"
785
                    "movdqa     %%xmm1, 16(%%edi)         \n"
792
                    "movdqa     %%xmm1, 16(%%edi)         \n"
786
                    "movdqa     %%xmm2, 32(%%edi)         \n"
793
                    "movdqa     %%xmm2, 32(%%edi)         \n"
787
                    "movdqa     %%xmm3, 48(%%edi)         \n"
794
                    "movdqa     %%xmm3, 48(%%edi)         \n"
788
 
795
 
789
                    :: "r" (tmp_src), "D" (tmp_dst)
796
                    :: "r" (tmp_src), "D" (tmp_dst)
790
                    :"xmm0","xmm1","xmm2","xmm3");
797
                    :"xmm0","xmm1","xmm2","xmm3");
791
                    tmp_w -= 64;
798
                    tmp_w -= 64;
792
                    tmp_src += 64;
799
                    tmp_src += 64;
793
                    tmp_dst += 64;
800
                    tmp_dst += 64;
794
                }
801
                }
795
 
802
 
796
                if( tmp_w >= 32 )
803
                if( tmp_w >= 32 )
797
                {
804
                {
798
                    __asm__ __volatile__ (
805
                    __asm__ __volatile__ (
799
                    "movdqu     (%0),   %%xmm0            \n"
806
                    "movdqu     (%0),   %%xmm0            \n"
800
                    "movdqu   16(%0),   %%xmm1            \n"
807
                    "movdqu   16(%0),   %%xmm1            \n"
801
                    "pcmpeqb    %%xmm6, %%xmm0            \n"
808
                    "pcmpeqb    %%xmm6, %%xmm0            \n"
802
                    "pcmpeqb    %%xmm6, %%xmm1            \n"
809
                    "pcmpeqb    %%xmm6, %%xmm1            \n"
803
                    "movdqa     %%xmm0,   (%%edi)         \n"
810
                    "movdqa     %%xmm0,   (%%edi)         \n"
804
                    "movdqa     %%xmm1, 16(%%edi)         \n"
811
                    "movdqa     %%xmm1, 16(%%edi)         \n"
805
 
812
 
806
                    :: "r" (tmp_src), "D" (tmp_dst)
813
                    :: "r" (tmp_src), "D" (tmp_dst)
807
                    :"xmm0","xmm1");
814
                    :"xmm0","xmm1");
808
                    tmp_w -= 32;
815
                    tmp_w -= 32;
809
                    tmp_src += 32;
816
                    tmp_src += 32;
810
                    tmp_dst += 32;
817
                    tmp_dst += 32;
811
                }
818
                }
812
 
819
 
813
                while( tmp_w > 0 )
820
                while( tmp_w > 0 )
814
                {
821
                {
815
                    __asm__ __volatile__ (
822
                    __asm__ __volatile__ (
816
                    "movdqu     (%0),   %%xmm0            \n"
823
                    "movdqu     (%0),   %%xmm0            \n"
817
                    "pcmpeqb    %%xmm6, %%xmm0            \n"
824
                    "pcmpeqb    %%xmm6, %%xmm0            \n"
818
                    "movdqa     %%xmm0,   (%%edi)         \n"
825
                    "movdqa     %%xmm0,   (%%edi)         \n"
819
                    :: "r" (tmp_src), "D" (tmp_dst)
826
                    :: "r" (tmp_src), "D" (tmp_dst)
820
                    :"xmm0");
827
                    :"xmm0");
821
                    tmp_w -= 16;
828
                    tmp_w -= 16;
822
                    tmp_src += 16;
829
                    tmp_src += 16;
823
                    tmp_dst += 16;
830
                    tmp_dst += 16;
824
                }
831
                }
825
            };
832
            };
826
        };
833
        };
827
        safe_sti(ifl);
834
        safe_sti(ifl);
828
    }
835
    }
829
 
836
 
830
    drm_gem_object_unreference(obj);
837
    drm_gem_object_unreference(obj);
831
 
838
 
832
    mutex_unlock(&dev->struct_mutex);
839
    mutex_unlock(&dev->struct_mutex);
833
 
840
 
834
    return 0;
841
    return 0;
835
}
842
}
836
 
843
 
837
 
844
 
838
 
845
 
839
 
846
 
840
 
847
 
841
 
848
 
842
 
849
 
843
 
850
 
844
 
851
 
845
 
852
 
846
 
853
 
847
 
854
 
848
#define NSEC_PER_SEC    1000000000L
855
#define NSEC_PER_SEC    1000000000L
849
 
856
 
850
void getrawmonotonic(struct timespec *ts)
857
void getrawmonotonic(struct timespec *ts)
851
{
858
{
852
    u32 tmp = GetTimerTicks();
859
    u32 tmp = GetTimerTicks();
853
 
860
 
854
    ts->tv_sec  = tmp/100;
861
    ts->tv_sec  = tmp/100;
855
    ts->tv_nsec = (tmp - ts->tv_sec*100)*10000000;
862
    ts->tv_nsec = (tmp - ts->tv_sec*100)*10000000;
856
}
863
}
857
 
864
 
858
void set_normalized_timespec(struct timespec *ts, time_t sec, s64 nsec)
865
void set_normalized_timespec(struct timespec *ts, time_t sec, s64 nsec)
859
{
866
{
860
    while (nsec >= NSEC_PER_SEC) {
867
    while (nsec >= NSEC_PER_SEC) {
861
        /*
868
        /*
862
         * The following asm() prevents the compiler from
869
         * The following asm() prevents the compiler from
863
         * optimising this loop into a modulo operation. See
870
         * optimising this loop into a modulo operation. See
864
         * also __iter_div_u64_rem() in include/linux/time.h
871
         * also __iter_div_u64_rem() in include/linux/time.h
865
         */
872
         */
866
        asm("" : "+rm"(nsec));
873
        asm("" : "+rm"(nsec));
867
        nsec -= NSEC_PER_SEC;
874
        nsec -= NSEC_PER_SEC;
868
        ++sec;
875
        ++sec;
869
    }
876
    }
870
    while (nsec < 0) {
877
    while (nsec < 0) {
871
        asm("" : "+rm"(nsec));
878
        asm("" : "+rm"(nsec));
872
        nsec += NSEC_PER_SEC;
879
        nsec += NSEC_PER_SEC;
873
        --sec;
880
        --sec;
874
    }
881
    }
875
    ts->tv_sec = sec;
882
    ts->tv_sec = sec;
876
    ts->tv_nsec = nsec;
883
    ts->tv_nsec = nsec;
877
}
884
}
878
 
885
 
879
void
886
void
880
prepare_to_wait(wait_queue_head_t *q, wait_queue_t *wait, int state)
887
prepare_to_wait(wait_queue_head_t *q, wait_queue_t *wait, int state)
881
{
888
{
882
    unsigned long flags;
889
    unsigned long flags;
883
 
890
 
884
//    wait->flags &= ~WQ_FLAG_EXCLUSIVE;
891
//    wait->flags &= ~WQ_FLAG_EXCLUSIVE;
885
    spin_lock_irqsave(&q->lock, flags);
892
    spin_lock_irqsave(&q->lock, flags);
886
    if (list_empty(&wait->task_list))
893
    if (list_empty(&wait->task_list))
887
            __add_wait_queue(q, wait);
894
            __add_wait_queue(q, wait);
888
    spin_unlock_irqrestore(&q->lock, flags);
895
    spin_unlock_irqrestore(&q->lock, flags);
889
}
896
}
890
 
897
 
891
/**
898
/**
892
 * finish_wait - clean up after waiting in a queue
899
 * finish_wait - clean up after waiting in a queue
893
 * @q: waitqueue waited on
900
 * @q: waitqueue waited on
894
 * @wait: wait descriptor
901
 * @wait: wait descriptor
895
 *
902
 *
896
 * Sets current thread back to running state and removes
903
 * Sets current thread back to running state and removes
897
 * the wait descriptor from the given waitqueue if still
904
 * the wait descriptor from the given waitqueue if still
898
 * queued.
905
 * queued.
899
 */
906
 */
900
void finish_wait(wait_queue_head_t *q, wait_queue_t *wait)
907
void finish_wait(wait_queue_head_t *q, wait_queue_t *wait)
901
{
908
{
902
    unsigned long flags;
909
    unsigned long flags;
903
 
910
 
904
//    __set_current_state(TASK_RUNNING);
911
//    __set_current_state(TASK_RUNNING);
905
    /*
912
    /*
906
     * We can check for list emptiness outside the lock
913
     * We can check for list emptiness outside the lock
907
     * IFF:
914
     * IFF:
908
     *  - we use the "careful" check that verifies both
915
     *  - we use the "careful" check that verifies both
909
     *    the next and prev pointers, so that there cannot
916
     *    the next and prev pointers, so that there cannot
910
     *    be any half-pending updates in progress on other
917
     *    be any half-pending updates in progress on other
911
     *    CPU's that we haven't seen yet (and that might
918
     *    CPU's that we haven't seen yet (and that might
912
     *    still change the stack area.
919
     *    still change the stack area.
913
     * and
920
     * and
914
     *  - all other users take the lock (ie we can only
921
     *  - all other users take the lock (ie we can only
915
     *    have _one_ other CPU that looks at or modifies
922
     *    have _one_ other CPU that looks at or modifies
916
     *    the list).
923
     *    the list).
917
     */
924
     */
918
    if (!list_empty_careful(&wait->task_list)) {
925
    if (!list_empty_careful(&wait->task_list)) {
919
            spin_lock_irqsave(&q->lock, flags);
926
            spin_lock_irqsave(&q->lock, flags);
920
            list_del_init(&wait->task_list);
927
            list_del_init(&wait->task_list);
921
            spin_unlock_irqrestore(&q->lock, flags);
928
            spin_unlock_irqrestore(&q->lock, flags);
922
    }
929
    }
923
 
930
 
924
    DestroyEvent(wait->evnt);
931
    DestroyEvent(wait->evnt);
925
}
932
}
926
 
933
 
927
int autoremove_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key)
934
int autoremove_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key)
928
{
935
{
929
    list_del_init(&wait->task_list);
936
    list_del_init(&wait->task_list);
930
    return 1;
937
    return 1;
931
}
938
}
932
 
939
 
933
unsigned int hweight16(unsigned int w)
940
unsigned int hweight16(unsigned int w)
934
{
941
{
935
    unsigned int res = w - ((w >> 1) & 0x5555);
942
    unsigned int res = w - ((w >> 1) & 0x5555);
936
    res = (res & 0x3333) + ((res >> 2) & 0x3333);
943
    res = (res & 0x3333) + ((res >> 2) & 0x3333);
937
    res = (res + (res >> 4)) & 0x0F0F;
944
    res = (res + (res >> 4)) & 0x0F0F;
938
    return (res + (res >> 8)) & 0x00FF;
945
    return (res + (res >> 8)) & 0x00FF;
939
}
946
}
940
 
947
 
941
 
948
 
942
unsigned long round_jiffies_up_relative(unsigned long j)
949
unsigned long round_jiffies_up_relative(unsigned long j)
943
{
950
{
944
    unsigned long j0 = GetTimerTicks();
951
    unsigned long j0 = GetTimerTicks();
945
 
952
 
946
        /* Use j0 because jiffies might change while we run */
953
        /* Use j0 because jiffies might change while we run */
947
    return round_jiffies_common(j + j0, true) - j0;
954
    return round_jiffies_common(j + j0, true) - j0;
948
}
955
}
949
 
956
 
950
>
957
>
951
 
958
 
952
>
959
>
953
 
960
 
954
>
961
>
955
 
962
 
956
>
963
>
957
 
964
 
958
>
965
>
959
 
966
 
960
>
967
>