Subversion Repositories Kolibri OS

Rev

Rev 4398 | Rev 4557 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2340 Serge 1
 
2
3
 
2338 Serge 4
#include "drm.h"
5
#include "i915_drm.h"
6
#include "i915_drv.h"
7
#include "intel_drv.h"
8
9
 
10
#include 
11
#include 
12
#include 
13
#include 
14
15
 
16
17
 
2340 Serge 18
2338 Serge 19
 
20
{
21
    kobj_t     header;
22
23
 
24
    uint32_t   hot_x;
25
    uint32_t   hot_y;
26
27
 
28
    struct drm_i915_gem_object  *cobj;
29
}cursor_t;
30
31
 
32
#define CURSOR_HEIGHT 64
33
34
 
35
 
36
{
37
    int  x;
38
    int  y;
39
    int  width;
40
    int  height;
41
    int  bpp;
42
    int  vrefresh;
43
    int  pitch;
44
    int  lfb;
45
46
 
47
    struct drm_device    *ddev;
48
    struct drm_connector *connector;
49
    struct drm_crtc      *crtc;
50
51
 
52
53
 
54
    int       (*init_cursor)(cursor_t*);
55
    cursor_t* (__stdcall *select_cursor)(cursor_t*);
56
    void      (*show_cursor)(int show);
57
    void      (__stdcall *move_cursor)(cursor_t *cursor, int x, int y);
58
    void      (__stdcall *restore_cursor)(int x, int y);
59
    void      (*disable_mouse)(void);
60
    u32  mask_seqno;
2361 Serge 61
    u32  check_mouse;
3031 serge 62
    u32  check_m_pixel;
63
64
 
2338 Serge 65
66
 
67
 
68
69
 
2340 Serge 70
u32_t cmd_offset;
71
72
 
2351 Serge 73
int  sna_init();
74
75
 
2338 Serge 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);
78
79
 
80
{};
81
82
 
83
{};
84
85
 
3031 serge 86
{
87
    static char name[4];
88
89
 
90
    name[1] = ((x[0] & 0x03) << 3) + ((x[1] & 0xE0) >> 5) + '@';
91
    name[2] = (x[1] & 0x1F) + '@';
92
    name[3] = 0;
93
94
 
95
}
96
97
 
98
              videomode_t *reqmode, bool strict)
99
{
100
    drm_i915_private_t      *dev_priv   = dev->dev_private;
101
    struct drm_fb_helper    *fb_helper  = &dev_priv->fbdev->helper;
102
103
 
104
    struct drm_display_mode *mode       = NULL, *tmpmode;
105
    struct drm_framebuffer  *fb         = NULL;
106
    struct drm_crtc         *crtc;
107
    struct drm_encoder      *encoder;
108
    struct drm_i915_gem_object *fb_obj;
4280 Serge 109
    struct drm_mode_set     set;
3031 serge 110
    const char *con_name;
4371 Serge 111
    const char *enc_name;
112
    unsigned hdisplay, vdisplay;
3031 serge 113
    int ret;
114
115
 
116
117
 
118
    {
119
        if( (drm_mode_width(tmpmode)    == reqmode->width)  &&
120
            (drm_mode_height(tmpmode)   == reqmode->height) &&
121
            (drm_mode_vrefresh(tmpmode) == reqmode->freq) )
122
        {
123
            mode = tmpmode;
124
            goto do_set;
125
        }
126
    };
127
128
 
129
    {
130
        list_for_each_entry(tmpmode, &connector->modes, head)
131
        {
132
            if( (drm_mode_width(tmpmode)  == reqmode->width)  &&
133
                (drm_mode_height(tmpmode) == reqmode->height) )
134
            {
135
                mode = tmpmode;
136
                goto do_set;
137
            }
138
        };
139
    };
140
141
 
3037 serge 142
3031 serge 143
 
144
145
 
146
147
 
148
    crtc = encoder->crtc;
149
150
 
151
    enc_name = drm_get_encoder_name(encoder);
152
153
 
154
              reqmode->width, reqmode->height, crtc->base.id,
155
              con_name, enc_name);
156
157
 
158
159
 
160
    vdisplay = mode->vdisplay;
161
162
 
163
        swap(hdisplay, vdisplay);
164
165
 
4280 Serge 166
    fb = fb_helper->fb;
3031 serge 167
168
 
169
    fb->height = reqmode->height;
170
171
 
4280 Serge 172
                      fb->pitches[3]  = ALIGN(reqmode->width * 4, 512);
173
174
 
175
176
 
3031 serge 177
    fb->depth = 24;
178
179
 
180
    crtc->enabled = true;
181
    os_display->crtc = crtc;
182
183
 
4280 Serge 184
185
 
3031 serge 186
    set.x = 0;
187
    set.y = 0;
188
    set.mode = mode;
189
    set.connectors = &connector;
190
    set.num_connectors = 1;
191
    set.fb = fb;
192
    ret = crtc->funcs->set_config(&set);
193
    mutex_unlock(&dev->mode_config.mutex);
194
195
 
196
    {
197
        os_display->width    = fb->width;
198
        os_display->height   = fb->height;
199
        os_display->vrefresh = drm_mode_vrefresh(mode);
200
201
 
202
203
 
3037 serge 204
                       fb->width, fb->height, fb->pitches[0]);
3031 serge 205
    }
206
    else
207
        DRM_ERROR("failed to set mode %d_%d on crtc %p\n",
208
                   fb->width, fb->height, crtc);
209
210
 
211
}
212
213
 
2338 Serge 214
{
215
    struct drm_display_mode  *mode;
216
    int count = 0;
217
218
 
219
    {
220
        count++;
221
    };
222
    return count;
223
};
224
225
 
3031 serge 226
{
227
    struct drm_connector  *connector;
228
    struct drm_connector_helper_funcs *connector_funcs;
229
230
 
231
232
 
233
    {
234
        struct drm_encoder  *encoder;
235
        struct drm_crtc     *crtc;
236
237
 
238
            continue;
239
240
 
241
        encoder = connector_funcs->best_encoder(connector);
242
        if( encoder == NULL)
243
            continue;
244
245
 
246
247
 
248
249
 
3037 serge 250
                   connector, connector->base.id,
3031 serge 251
                   connector->status, connector->encoder,
252
                   crtc);
253
254
 
255
//            continue;
256
257
 
258
259
 
260
    };
261
262
 
263
};
264
265
 
4371 Serge 266
{
2338 Serge 267
    struct drm_connector *tmp = NULL;
4371 Serge 268
    struct drm_connector_helper_funcs *connector_funcs;
2338 Serge 269
    struct drm_encoder      *encoder;
270
271
 
4371 Serge 272
    {
2338 Serge 273
        if( tmp->status != connector_status_connected)
4371 Serge 274
            continue;
2338 Serge 275
276
 
4371 Serge 277
        encoder = connector_funcs->best_encoder(tmp);
278
        if( encoder == NULL)
2338 Serge 279
        {
280
            DRM_DEBUG_KMS("CONNECTOR %x ID: %d no active encoders\n",
3037 serge 281
                      tmp, tmp->base.id);
4371 Serge 282
            continue;
2338 Serge 283
        };
4371 Serge 284
2338 Serge 285
 
4371 Serge 286
287
 
4280 Serge 288
               tmp, tmp->base.id, tmp->status, tmp->encoder,
4371 Serge 289
               tmp->encoder->crtc, tmp->encoder->crtc->base.id );
290
2338 Serge 291
 
4371 Serge 292
    };
2338 Serge 293
294
 
4371 Serge 295
}
296
4280 Serge 297
 
4371 Serge 298
{
4398 Serge 299
        struct drm_crtc *tmp_crtc;
2338 Serge 300
        int crtc_mask = 1;
301
302
 
303
        {
304
            if (encoder->possible_crtcs & crtc_mask)
305
            {
306
            encoder->crtc = tmp_crtc;
4371 Serge 307
            dbgprintf("CRTC %p\n", tmp_crtc);
308
            return tmp_crtc;
309
            };
2338 Serge 310
            crtc_mask <<= 1;
311
        };
312
    return NULL;
4371 Serge 313
};
4398 Serge 314
2338 Serge 315
 
4371 Serge 316
{
317
    struct drm_display_mode *mode;
318
319
 
320
    {
321
        DRM_DEBUG_KMS("check mode w:%d h:%d %dHz\n",
4389 Serge 322
                drm_mode_width(mode), drm_mode_height(mode),
4371 Serge 323
                drm_mode_vrefresh(mode));
324
325
 
326
            os_display->height == drm_mode_height(mode) &&
327
            drm_mode_vrefresh(mode) == 60)
328
        {
329
            usermode->width  = os_display->width;
330
            usermode->height = os_display->height;
331
            usermode->freq   = 60;
332
            return 1;
333
        }
334
    }
335
    return 0;
336
}
337
338
 
339
{
340
    struct drm_connector    *connector;
341
    struct drm_connector_helper_funcs *connector_funcs;
342
    struct drm_encoder      *encoder;
343
    struct drm_crtc         *crtc;
344
    struct drm_framebuffer  *fb;
345
346
 
347
    u32_t      ifl;
348
    int        err;
349
350
 
351
352
 
353
    if(connector == NULL)
354
    {
355
        DRM_DEBUG_KMS("No active connectors!\n");
356
        mutex_unlock(&dev->mode_config.mutex);
357
        return -1;
358
    };
359
360
 
361
    crtc = encoder->crtc;
362
363
 
364
        crtc = get_possible_crtc(dev, encoder);
365
366
 
2338 Serge 367
    {
368
        DRM_DEBUG_KMS("No CRTC for encoder %d\n", encoder->base.id);
4280 Serge 369
        mutex_unlock(&dev->mode_config.mutex);
370
        return -1;
2338 Serge 371
    };
372
373
 
4280 Serge 374
2338 Serge 375
 
376
    os_display->ddev = dev;
377
    os_display->connector = connector;
378
    os_display->crtc = crtc;
379
380
 
381
382
 
383
 
384
    {
385
        struct intel_crtc *intel_crtc = to_intel_crtc(os_display->crtc);
386
387
 
388
        {
389
            init_cursor(cursor);
390
        };
391
392
 
393
        os_display->init_cursor    = init_cursor;
394
        os_display->select_cursor  = select_cursor_kms;
395
        os_display->show_cursor    = NULL;
396
        os_display->move_cursor    = move_cursor_kms;
397
        os_display->restore_cursor = restore_cursor;
398
        os_display->disable_mouse  = disable_mouse;
399
400
 
401
        intel_crtc->cursor_y = os_display->height/2;
402
403
 
404
    };
405
    safe_sti(ifl);
406
407
 
4280 Serge 408
        (usermode->height == 0))
409
    {
410
        if( !get_boot_mode(connector, usermode))
4371 Serge 411
        {
412
        struct drm_display_mode *mode;
4280 Serge 413
414
 
415
            usermode->width  = drm_mode_width(mode);
416
            usermode->height = drm_mode_height(mode);
417
            usermode->freq   = drm_mode_vrefresh(mode);
418
        };
419
    };
420
421
 
422
423
 
424
425
 
3243 Serge 426
    err = init_bitmaps();
2342 Serge 427
#endif
3243 Serge 428
2340 Serge 429
 
4280 Serge 430
431
 
2338 Serge 432
};
433
434
 
435
 
436
{
437
    int err = -1;
438
439
 
3031 serge 440
2338 Serge 441
 
442
    {
443
        *count = os_display->supported_modes;
444
        err = 0;
445
    }
446
    else if( mode != NULL )
447
    {
448
        struct drm_display_mode  *drmmode;
449
        int i = 0;
450
451
 
452
            *count = os_display->supported_modes;
453
454
 
455
        {
456
            if( i < *count)
457
            {
458
                mode->width  = drm_mode_width(drmmode);
459
                mode->height = drm_mode_height(drmmode);
460
                mode->bpp    = 32;
461
                mode->freq   = drm_mode_vrefresh(drmmode);
462
                i++;
463
                mode++;
464
            }
465
            else break;
466
        };
467
        *count = i;
468
        err = 0;
469
    };
470
    return err;
471
};
472
473
 
474
{
475
    int err = -1;
476
477
 
3031 serge 478
//               mode->width, mode->height, mode->freq);
479
2338 Serge 480
 
481
        (mode->height != 0)  &&
482
        (mode->freq   != 0 ) &&
483
        ( (mode->width   != os_display->width)  ||
484
          (mode->height  != os_display->height) ||
485
          (mode->freq    != os_display->vrefresh) ) )
486
    {
487
        if( set_mode(os_display->ddev, os_display->connector, mode, true) )
488
            err = 0;
489
    };
490
491
 
492
};
493
494
 
4126 Serge 495
{
496
    const struct drm_connector_funcs *f = os_display->connector->funcs;
4371 Serge 497
4126 Serge 498
 
499
};
500
501
 
2338 Serge 502
{
503
    list_del(&cursor->list);
3037 serge 504
2342 Serge 505
 
3037 serge 506
507
 
508
    drm_gem_object_unreference(&cursor->cobj->base);
509
    mutex_unlock(&main_device->struct_mutex);
510
511
 
2338 Serge 512
};
513
514
 
515
{
516
    struct drm_i915_private *dev_priv = os_display->ddev->dev_private;
517
    struct drm_i915_gem_object *obj;
518
    uint32_t *bits;
519
    uint32_t *src;
520
    void     *mapped;
3037 serge 521
2338 Serge 522
 
523
    int       ret;
524
525
 
526
    {
527
        bits = (uint32_t*)KernelAlloc(CURSOR_WIDTH*CURSOR_HEIGHT*4);
528
        if (unlikely(bits == NULL))
529
            return ENOMEM;
530
        cursor->cobj = (struct drm_i915_gem_object *)GetPgAddr(bits);
531
    }
532
    else
533
    {
534
        obj = i915_gem_alloc_object(os_display->ddev, CURSOR_WIDTH*CURSOR_HEIGHT*4);
535
        if (unlikely(obj == NULL))
536
            return -ENOMEM;
537
538
 
4104 Serge 539
        if (ret) {
2338 Serge 540
            drm_gem_object_unreference(&obj->base);
2344 Serge 541
            return ret;
2338 Serge 542
        }
543
544
 
4104 Serge 545
        if (ret)
546
        {
547
            i915_gem_object_unpin(obj);
548
            drm_gem_object_unreference(&obj->base);
549
            return ret;
550
        }
551
/* You don't need to worry about fragmentation issues.
2338 Serge 552
 * GTT space is continuous. I guarantee it.                           */
553
554
 
4104 Serge 555
                    CURSOR_WIDTH*CURSOR_HEIGHT*4, PG_SW);
2338 Serge 556
557
 
558
        {
559
            i915_gem_object_unpin(obj);
2344 Serge 560
            drm_gem_object_unreference(&obj->base);
561
            return -ENOMEM;
2338 Serge 562
        };
563
        cursor->cobj = obj;
564
    };
565
566
 
567
568
 
569
    {
570
        for(j = 0; j < 32; j++)
571
            *bits++ = *src++;
572
        for(j = 32; j < CURSOR_WIDTH; j++)
573
            *bits++ = 0;
574
    }
575
    for(i = 0; i < CURSOR_WIDTH*(CURSOR_HEIGHT-32); i++)
576
        *bits++ = 0;
577
578
 
3037 serge 579
580
 
2338 Serge 581
582
 
2340 Serge 583
2338 Serge 584
 
585
586
 
587
588
 
589
}
590
591
 
592
 
593
{
594
    struct drm_device *dev = crtc->dev;
595
    struct drm_i915_private *dev_priv = dev->dev_private;
596
    struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
597
    int pipe = intel_crtc->pipe;
598
    bool visible = base != 0;
599
600
 
601
        uint32_t cntl = I915_READ(CURCNTR(pipe));
602
        if (base) {
603
            cntl &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT);
604
            cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
605
            cntl |= pipe << 28; /* Connect to correct pipe */
606
        } else {
607
            cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
608
            cntl |= CURSOR_MODE_DISABLE;
609
        }
610
        I915_WRITE(CURCNTR(pipe), cntl);
611
612
 
613
    }
614
    /* and commit changes on next vblank */
615
    I915_WRITE(CURBASE(pipe), base);
616
}
617
618
 
619
{
620
    struct drm_i915_private *dev_priv = os_display->ddev->dev_private;
621
    struct intel_crtc *intel_crtc = to_intel_crtc(os_display->crtc);
622
    u32 base, pos;
623
    bool visible;
624
625
 
626
627
 
628
    intel_crtc->cursor_y = y;
629
630
 
631
    y = y - cursor->hot_y;
632
633
 
634
 
635
636
 
637
    if (x >= os_display->width)
638
        base = 0;
639
640
 
641
        base = 0;
642
643
 
644
    {
645
        if (x + intel_crtc->cursor_width < 0)
646
            base = 0;
647
648
 
649
        x = -x;
650
    }
651
    pos |= x << CURSOR_X_SHIFT;
652
653
 
654
    {
655
        if (y + intel_crtc->cursor_height < 0)
656
            base = 0;
657
658
 
659
        y = -y;
660
    }
661
    pos |= y << CURSOR_Y_SHIFT;
662
663
 
664
    if (!visible && !intel_crtc->cursor_visible)
665
        return;
666
667
 
668
//    if (IS_845G(dev) || IS_I865G(dev))
669
//        i845_update_cursor(crtc, base);
670
//    else
671
        i9xx_update_cursor(os_display->crtc, base);
672
673
 
674
675
 
676
 
677
{
678
    struct drm_i915_private *dev_priv = os_display->ddev->dev_private;
679
    struct intel_crtc *intel_crtc = to_intel_crtc(os_display->crtc);
680
    cursor_t *old;
681
682
 
683
    os_display->cursor = cursor;
684
685
 
686
       intel_crtc->cursor_addr = i915_gem_obj_ggtt_offset(cursor->cobj);
4104 Serge 687
    else
2338 Serge 688
        intel_crtc->cursor_addr = (addr_t)cursor->cobj;
2352 Serge 689
2338 Serge 690
 
691
    intel_crtc->cursor_height = 32;
692
693
 
694
    return old;
695
};
696
697
 
4371 Serge 698
{
3263 Serge 699
    struct drm_i915_private *dev_priv = os_display->ddev->dev_private;
4389 Serge 700
    struct intel_crtc *crtc = to_intel_crtc(os_display->crtc);
701
702
 
4371 Serge 703
2340 Serge 704
 
4371 Serge 705
    fb->width  = os_display->width;
3263 Serge 706
    fb->height = os_display->height;
707
    fb->pitch  = obj->stride;
4371 Serge 708
    fb->tiling = obj->tiling_mode;
709
    fb->crtc   = crtc->base.base.id;
4389 Serge 710
    fb->pipe   = crtc->pipe;
711
2340 Serge 712
 
3263 Serge 713
}
4371 Serge 714
3263 Serge 715
 
4371 Serge 716
 
3277 Serge 717
{
718
    int left;
719
    int top;
720
    int right;
721
    int bottom;
722
}rect_t;
723
3263 Serge 724
 
3277 Serge 725
 
726
727
 
728
{
729
    u32_t   addr;
730
731
 
732
    addr+= sizeof(display_t);            /*  shoot me  */
733
    return *(u32_t*)addr;
734
}
735
736
 
737
738
 
739
            struct drm_file *file)
740
{
741
    struct drm_i915_mask *mask = data;
742
    struct drm_gem_object *obj;
743
    static unsigned int mask_seqno[256];
744
    rect_t winrc;
745
    u32    slot;
746
    int    ret=0;
4371 Serge 747
3277 Serge 748
 
749
    if (obj == NULL)
750
        return -ENOENT;
751
752
 
753
        drm_gem_object_unreference_unlocked(obj);
754
        return -EINVAL;
755
    }
756
757
 
758
    {
759
//        static warn_count;
3298 Serge 760
3277 Serge 761
 
3290 Serge 762
        mask->height   = winrc.bottom - winrc.top + 1;
763
        mask->bo_pitch = (mask->width+15) & ~15;
764
765
 
3298 Serge 766
        if(warn_count < 1)
3277 Serge 767
        {
768
            printf("left %d top %d right %d bottom %d\n",
769
                    winrc.left, winrc.top, winrc.right, winrc.bottom);
770
            printf("mask pitch %d data %p\n", mask->bo_pitch, mask->bo_size);
771
            warn_count++;
772
        };
773
#endif
3298 Serge 774
775
 
4104 Serge 776
3277 Serge 777
 
3290 Serge 778
 
3277 Serge 779
780
 
781
    {
782
        u8* src_offset;
783
        u8* dst_offset;
784
        u32 ifl;
785
786
 
787
        if (ret)
788
            goto err1;
4371 Serge 789
3277 Serge 790
 
791
        if(ret != 0 )
4398 Serge 792
        {
3277 Serge 793
            dbgprintf("%s: i915_gem_object_set_to_cpu_domain failed\n", __FUNCTION__);
4371 Serge 794
            goto err2;
795
        };
3277 Serge 796
797
 
798
799
 
800
801
 
802
 
803
        src_offset+= get_display_map();
804
        dst_offset = (u8*)mask->bo_map;
805
806
 
3290 Serge 807
3277 Serge 808
 
809
        {
810
            mask_seqno[slot] = os_display->mask_seqno;
811
812
 
813
814
 
815
                "movd       %[slot],   %%xmm6    \n"
816
            "punpckldq  %%xmm6, %%xmm6            \n"
817
            "punpcklqdq %%xmm6, %%xmm6            \n"
818
            :: [slot]  "m" (slot)
819
            :"xmm6");
820
821
 
822
            {
823
                int tmp_w = mask->width;
4398 Serge 824
3277 Serge 825
 
826
                u8* tmp_dst = dst_offset;
827
828
 
829
                dst_offset+= mask->bo_pitch;
830
831
 
832
                {
833
                    __asm__ __volatile__ (
834
                    "movdqu     (%0),   %%xmm0            \n"
835
                    "movdqu   16(%0),   %%xmm1            \n"
836
                    "movdqu   32(%0),   %%xmm2            \n"
837
                    "movdqu   48(%0),   %%xmm3            \n"
838
                    "pcmpeqb    %%xmm6, %%xmm0            \n"
839
                    "pcmpeqb    %%xmm6, %%xmm1            \n"
840
                    "pcmpeqb    %%xmm6, %%xmm2            \n"
841
                    "pcmpeqb    %%xmm6, %%xmm3            \n"
842
                    "movdqa     %%xmm0,   (%%edi)         \n"
843
                    "movdqa     %%xmm1, 16(%%edi)         \n"
844
                    "movdqa     %%xmm2, 32(%%edi)         \n"
845
                    "movdqa     %%xmm3, 48(%%edi)         \n"
846
847
 
848
                    :"xmm0","xmm1","xmm2","xmm3");
849
                    tmp_w -= 64;
850
                    tmp_src += 64;
851
                    tmp_dst += 64;
852
                }
853
854
 
855
                {
856
                    __asm__ __volatile__ (
857
                    "movdqu     (%0),   %%xmm0            \n"
858
                    "movdqu   16(%0),   %%xmm1            \n"
859
                    "pcmpeqb    %%xmm6, %%xmm0            \n"
860
                    "pcmpeqb    %%xmm6, %%xmm1            \n"
861
                    "movdqa     %%xmm0,   (%%edi)         \n"
862
                    "movdqa     %%xmm1, 16(%%edi)         \n"
863
864
 
865
                    :"xmm0","xmm1");
866
                    tmp_w -= 32;
867
                    tmp_src += 32;
868
                    tmp_dst += 32;
869
                }
870
871
 
4398 Serge 872
                {
3277 Serge 873
                    __asm__ __volatile__ (
874
                    "movdqu     (%0),   %%xmm0            \n"
875
                    "pcmpeqb    %%xmm6, %%xmm0            \n"
876
                    "movdqa     %%xmm0,   (%%edi)         \n"
877
                    :: "r" (tmp_src), "D" (tmp_dst)
878
                    :"xmm0");
879
                    tmp_w -= 16;
880
                    tmp_src += 16;
881
                    tmp_dst += 16;
882
                }
883
4398 Serge 884
 
885
                {
886
                    __asm__ __volatile__ (
887
                    "movq       (%0),   %%xmm0            \n"
888
                    "pcmpeqb    %%xmm6, %%xmm0            \n"
889
                    "movq       %%xmm0,   (%%edi)         \n"
890
                    :: "r" (tmp_src), "D" (tmp_dst)
891
                    :"xmm0");
892
                    tmp_w -= 8;
893
                    tmp_src += 8;
894
                    tmp_dst += 8;
895
                }
896
                if( tmp_w >= 4 )
897
                {
898
                    __asm__ __volatile__ (
899
                    "movd       (%0),   %%xmm0            \n"
900
                    "pcmpeqb    %%xmm6, %%xmm0            \n"
901
                    "movd       %%xmm0,   (%%edi)         \n"
902
                    :: "r" (tmp_src), "D" (tmp_dst)
903
                    :"xmm0");
904
                    tmp_w -= 4;
905
                    tmp_src += 4;
906
                    tmp_dst += 4;
907
                }
908
                while(tmp_w--)
909
                    *tmp_dst++ = (*tmp_src++ == (u8)slot) ? 0xFF:0x00;
910
            };
3277 Serge 911
        };
912
        safe_sti(ifl);
913
4371 Serge 914
 
915
    }
4539 Serge 916
917
 
918
    mutex_unlock(&dev->struct_mutex);
919
err1:
920
    drm_gem_object_unreference(obj);
921
922
 
923
}
924
925
 
926
            struct drm_file *file)
927
{
928
    struct drm_i915_mask_update *mask = data;
929
    struct drm_gem_object *obj;
930
    static unsigned int mask_seqno[256];
931
    static warn_count;
932
933
 
934
    u32    winw,winh;
935
    u32    ml,mt,mr,mb;
936
    u32    slot;
937
    int    ret = 0;
938
    slot = *((u8*)CURRENT_TASK);
939
940
 
941
        return 0;
942
943
 
944
    win.right+= 1;
945
    win.bottom+=  1;
946
947
 
948
    winh = win.bottom - win.top;
949
950
 
951
       mask->dy >= winh)
952
       return 1;
953
954
 
955
    mt = win.top  + mask->dy;
956
    mr = ml + mask->width;
957
    mb = mt + mask->height;
958
959
 
960
        mr < win.left   || mb < win.top )
961
        return 1;
962
963
 
964
        mr = win.right;
965
966
 
967
        mb = win.bottom;
968
969
 
970
    mask->height = mb - mt;
971
972
 
973
        mask->height== 0 )
974
        return 1;
975
976
 
977
    if (obj == NULL)
978
        return -ENOENT;
979
980
 
981
        drm_gem_object_unreference_unlocked(obj);
982
        return -EINVAL;
983
    }
984
985
 
986
    if(warn_count < 1000)
987
    {
988
        printf("left %d top %d right %d bottom %d\n",
989
                ml, mt, mr, mb);
990
        warn_count++;
991
    };
992
#endif
993
994
 
995
 
996
997
 
998
        u8* src_offset;
999
        u8* dst_offset;
1000
        u32 ifl;
1001
1002
 
1003
        if (ret)
1004
            goto err1;
1005
1006
 
1007
1008
 
1009
        src_offset+= get_display_map();
1010
        dst_offset = (u8*)mask->bo_map;
1011
1012
 
1013
1014
 
1015
        {
4371 Serge 1016
            mask_seqno[slot] = os_display->mask_seqno;
4539 Serge 1017
1018
 
1019
1020
 
1021
            "movd       %[slot],   %%xmm6         \n"
1022
            "punpckldq  %%xmm6, %%xmm6            \n"
1023
            "punpcklqdq %%xmm6, %%xmm6            \n"
1024
            :: [slot]  "m" (slot)
1025
            :"xmm6");
1026
1027
 
1028
            {
1029
                int tmp_w = mask->width;
1030
1031
 
1032
                u8* tmp_dst = dst_offset;
1033
1034
 
1035
                dst_offset+= mask->bo_pitch;
1036
1037
 
1038
                {
1039
                    __asm__ __volatile__ (
1040
                    "movdqu     (%0),   %%xmm0            \n"
1041
                    "movdqu   16(%0),   %%xmm1            \n"
1042
                    "movdqu   32(%0),   %%xmm2            \n"
1043
                    "movdqu   48(%0),   %%xmm3            \n"
1044
                    "pcmpeqb    %%xmm6, %%xmm0            \n"
1045
                    "pcmpeqb    %%xmm6, %%xmm1            \n"
1046
                    "pcmpeqb    %%xmm6, %%xmm2            \n"
1047
                    "pcmpeqb    %%xmm6, %%xmm3            \n"
1048
                    "movdqa     %%xmm0,   (%%edi)         \n"
1049
                    "movdqa     %%xmm1, 16(%%edi)         \n"
1050
                    "movdqa     %%xmm2, 32(%%edi)         \n"
1051
                    "movdqa     %%xmm3, 48(%%edi)         \n"
1052
1053
 
1054
                    :"xmm0","xmm1","xmm2","xmm3");
1055
                    tmp_w -= 64;
1056
                    tmp_src += 64;
1057
                    tmp_dst += 64;
1058
                }
1059
1060
 
1061
                {
1062
                    __asm__ __volatile__ (
1063
                    "movdqu     (%0),   %%xmm0            \n"
1064
                    "movdqu   16(%0),   %%xmm1            \n"
1065
                    "pcmpeqb    %%xmm6, %%xmm0            \n"
1066
                    "pcmpeqb    %%xmm6, %%xmm1            \n"
1067
                    "movdqa     %%xmm0,   (%%edi)         \n"
1068
                    "movdqa     %%xmm1, 16(%%edi)         \n"
1069
1070
 
1071
                    :"xmm0","xmm1");
1072
                    tmp_w -= 32;
1073
                    tmp_src += 32;
1074
                    tmp_dst += 32;
1075
                }
1076
1077
 
1078
                {
1079
                    __asm__ __volatile__ (
1080
                    "movdqu     (%0),   %%xmm0            \n"
1081
                    "pcmpeqb    %%xmm6, %%xmm0            \n"
1082
                    "movdqa     %%xmm0,   (%%edi)         \n"
1083
                    :: "r" (tmp_src), "D" (tmp_dst)
1084
                    :"xmm0");
1085
                    tmp_w -= 16;
1086
                    tmp_src += 16;
1087
                    tmp_dst += 16;
1088
                }
1089
1090
 
1091
                {
1092
                    __asm__ __volatile__ (
1093
                    "movq       (%0),   %%xmm0            \n"
1094
                    "pcmpeqb    %%xmm6, %%xmm0            \n"
1095
                    "movq       %%xmm0,   (%%edi)         \n"
1096
                    :: "r" (tmp_src), "D" (tmp_dst)
1097
                    :"xmm0");
1098
                    tmp_w -= 8;
1099
                    tmp_src += 8;
1100
                    tmp_dst += 8;
1101
                }
1102
                if( tmp_w >= 4 )
1103
        {
1104
                    __asm__ __volatile__ (
1105
                    "movd       (%0),   %%xmm0            \n"
1106
                    "pcmpeqb    %%xmm6, %%xmm0            \n"
1107
                    "movd       %%xmm0,   (%%edi)         \n"
1108
                    :: "r" (tmp_src), "D" (tmp_dst)
1109
                    :"xmm0");
1110
                    tmp_w -= 4;
1111
                    tmp_src += 4;
1112
                    tmp_dst += 4;
1113
                }
1114
                while(tmp_w--)
1115
                    *tmp_dst++ = (*tmp_src++ == (u8)slot) ? 0xFF:0x00;
1116
            };
1117
        };
4371 Serge 1118
        safe_sti(ifl);
4539 Serge 1119
1120
 
1121
    }
3277 Serge 1122
#endif
4539 Serge 1123
3277 Serge 1124
 
4371 Serge 1125
    mutex_unlock(&dev->struct_mutex);
1126
err1:
1127
    drm_gem_object_unreference(obj);
3277 Serge 1128
1129
 
4371 Serge 1130
}
3277 Serge 1131
1132
 
1133
 
1134
 
2360 Serge 1135
 
1136
 
1137
 
1138
 
1139
 
1140
 
1141
 
1142
 
3031 serge 1143
2360 Serge 1144
 
3031 serge 1145
{
1146
    u32 tmp = GetTimerTicks();
1147
2360 Serge 1148
 
3031 serge 1149
    ts->tv_nsec = (tmp - ts->tv_sec*100)*10000000;
1150
}
1151
2360 Serge 1152
 
4104 Serge 1153
{
3031 serge 1154
    while (nsec >= NSEC_PER_SEC) {
4104 Serge 1155
        /*
1156
         * The following asm() prevents the compiler from
1157
         * optimising this loop into a modulo operation. See
1158
         * also __iter_div_u64_rem() in include/linux/time.h
1159
         */
1160
        asm("" : "+rm"(nsec));
1161
        nsec -= NSEC_PER_SEC;
1162
        ++sec;
1163
    }
1164
    while (nsec < 0) {
1165
        asm("" : "+rm"(nsec));
1166
        nsec += NSEC_PER_SEC;
1167
        --sec;
1168
    }
1169
    ts->tv_sec = sec;
1170
    ts->tv_nsec = nsec;
1171
}
3031 serge 1172
2360 Serge 1173
 
3480 Serge 1174
prepare_to_wait(wait_queue_head_t *q, wait_queue_t *wait, int state)
1175
{
1176
    unsigned long flags;
1177
3031 serge 1178
 
3480 Serge 1179
    spin_lock_irqsave(&q->lock, flags);
1180
    if (list_empty(&wait->task_list))
1181
            __add_wait_queue(q, wait);
1182
    spin_unlock_irqrestore(&q->lock, flags);
1183
}
1184
1185
 
1186
 * finish_wait - clean up after waiting in a queue
1187
 * @q: waitqueue waited on
1188
 * @wait: wait descriptor
1189
 *
1190
 * Sets current thread back to running state and removes
1191
 * the wait descriptor from the given waitqueue if still
1192
 * queued.
1193
 */
1194
void finish_wait(wait_queue_head_t *q, wait_queue_t *wait)
1195
{
1196
    unsigned long flags;
1197
1198
 
1199
    /*
1200
     * We can check for list emptiness outside the lock
1201
     * IFF:
1202
     *  - we use the "careful" check that verifies both
1203
     *    the next and prev pointers, so that there cannot
1204
     *    be any half-pending updates in progress on other
1205
     *    CPU's that we haven't seen yet (and that might
1206
     *    still change the stack area.
1207
     * and
1208
     *  - all other users take the lock (ie we can only
1209
     *    have _one_ other CPU that looks at or modifies
1210
     *    the list).
1211
     */
1212
    if (!list_empty_careful(&wait->task_list)) {
1213
            spin_lock_irqsave(&q->lock, flags);
1214
            list_del_init(&wait->task_list);
1215
            spin_unlock_irqrestore(&q->lock, flags);
1216
    }
1217
1218
 
1219
}
1220
1221
 
1222
{
1223
    list_del_init(&wait->task_list);
1224
    return 1;
1225
}
1226
1227
 
3482 Serge 1228
{
1229
    unsigned int res = w - ((w >> 1) & 0x5555);
1230
    res = (res & 0x3333) + ((res >> 2) & 0x3333);
1231
    res = (res + (res >> 4)) & 0x0F0F;
1232
    return (res + (res >> 8)) & 0x00FF;
1233
}
1234
3480 Serge 1235
 
1236
 
3482 Serge 1237
{
1238
    unsigned long j0 = GetTimerTicks();
1239
3480 Serge 1240
 
3482 Serge 1241
    return round_jiffies_common(j + j0, true) - j0;
1242
}
1243
3480 Serge 1244
 
3482 Serge 1245