Subversion Repositories Kolibri OS

Rev

Rev 3299 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3299 Rev 3769
Line 1... Line -...
1
//#include "../bitmap.h"
-
 
-
 
1
#include 
Line 2... Line 2...
2
 
2
#include 
3
#include 
3
#include 
-
 
4
#include 
-
 
5
 
Line 4... Line 6...
4
#include 
6
#include "sna.h"
Line 5... Line 7...
5
 
7
 
Line 6... Line 8...
6
#include "sna.h"
8
#define to_surface(x) (surface_t*)((x)->handle)
7
 
9
 
Line 8... Line 10...
8
#include 
10
static struct sna_fb sna_fb;
Line 9... Line 11...
9
 
11
static int    tls_mask;
10
static struct sna_fb sna_fb;
12
 
11
static struct kgem_bo *mask_bo;
-
 
12
 
-
 
13
static int mask_width, mask_height;
13
int tls_alloc(void);
14
 
14
 
15
typedef struct __attribute__((packed))
-
 
16
{
-
 
17
  unsigned      handle;
-
 
18
  unsigned      io_code;
-
 
19
  void          *input;
-
 
20
  int           inp_size;
-
 
21
  void          *output;
-
 
22
  int           out_size;
-
 
23
}ioctl_t;
-
 
24
 
15
static inline void *tls_get(int key)
25
 
16
{
26
static int call_service(ioctl_t *io)
-
 
27
{
17
    void *val;
Line 28... Line 18...
28
  int retval;
18
    __asm__ __volatile__(
29
 
19
    "movl %%fs:(%1), %0"
Line -... Line 20...
-
 
20
    :"=r"(val)
30
  asm volatile("int $0x40"
21
    :"r"(key));
-
 
22
 
-
 
23
  return val;
31
      :"=a"(retval)
24
};
32
      :"a"(68),"b"(17),"c"(io)
25
 
-
 
26
static inline int
-
 
27
tls_set(int key, const void *ptr)
33
      :"memory","cc");
28
{
34
 
29
    if(!(key & 3))
35
  return retval;
30
    {
36
};
31
        __asm__ __volatile__(
Line -... Line 32...
-
 
32
        "movl %0, %%fs:(%1)"
-
 
33
        ::"r"(ptr),"r"(key));
-
 
34
        return 0;
-
 
35
    }
-
 
36
    else return -1;
-
 
37
}
-
 
38
 
-
 
39
 
-
 
40
 
-
 
41
 
-
 
42
int kgem_init_fb(struct kgem *kgem, struct sna_fb *fb);
-
 
43
int kgem_update_fb(struct kgem *kgem, struct sna_fb *fb);
37
 
44
uint32_t kgem_surface_size(struct kgem *kgem,bool relaxed_fencing,
38
static inline void get_proc_info(char *info)
45
				  unsigned flags, uint32_t width, uint32_t height,
Line 39... Line 46...
39
{
46
				  uint32_t bpp, uint32_t tiling, uint32_t *pitch);
Line 40... Line 47...
40
    __asm__ __volatile__(
47
 
Line 41... Line 48...
41
    "int $0x40"
48
void kgem_close_batches(struct kgem *kgem);
Line -... Line 49...
-
 
49
void sna_bo_destroy(struct kgem *kgem, struct kgem_bo *bo);
-
 
50
 
42
    :
51
const struct intel_device_info *
43
    :"a"(9), "b"(info), "c"(-1));
52
intel_detect_chipset(struct pci_device *pci);
44
}
53
 
45
 
54
//struct kgem_bo *create_bo(bitmap_t *bitmap);
Line 147... Line 156...
147
}
156
int sna_init(uint32_t service)
Line 148... Line 157...
148
 
157
{
149
int sna_init(uint32_t service)
158
    ioctl_t   io;
150
{
159
    int caps = 0;
-
 
160
 
Line 151... Line 161...
151
    ioctl_t   io;
161
    static struct pci_device device;
152
 
162
    struct sna *sna;
Line 153... Line 163...
153
    static struct pci_device device;
163
 
Line 154... Line 164...
154
    struct sna *sna;
164
    DBG(("%s\n", __FUNCTION__));
155
 
-
 
156
    DBG(("%s\n", __FUNCTION__));
-
 
Line 157... Line 165...
157
 
165
 
-
 
166
    __lock_acquire_recursive(__sna_lock);
Line 158... Line 167...
158
    sna = malloc(sizeof(*sna));
167
 
159
    if (sna == NULL)
168
    if(sna_device)
160
        return 0;
169
        goto done;
161
 
170
    
162
    memset(sna, 0, sizeof(*sna));
171
    io.handle   = service;
163
    
172
    io.io_code  = SRV_GET_PCI_INFO;
Line 164... Line 173...
164
    io.handle   = service;
173
    io.input    = &device;
165
    io.io_code  = SRV_GET_PCI_INFO;
174
    io.inp_size = sizeof(device);
-
 
175
    io.output   = NULL;
166
    io.input    = &device;
176
    io.out_size = 0;
-
 
177
 
167
    io.inp_size = sizeof(device);
178
    if (call_service(&io)!=0)
168
    io.output   = NULL;
179
        goto err1;
-
 
180
    
Line 169... Line 181...
169
    io.out_size = 0;
181
    sna = malloc(sizeof(*sna));
Line 170... Line 182...
170
 
182
    if (sna == NULL)
Line 207... Line 219...
207
 
219
 
Line 208... Line 220...
208
    sna->flags = 0;
220
    sna_accel_init(sna);
Line 209... Line 221...
209
 
221
 
-
 
222
    tls_mask = tls_alloc();
-
 
223
    
-
 
224
//    printf("tls mask %x\n", tls_mask);
-
 
225
    
-
 
226
done:
-
 
227
    caps = sna_device->render.caps;
-
 
228
 
-
 
229
err1:
Line 210... Line 230...
210
    sna_accel_init(sna);
230
    __lock_release_recursive(__sna_lock);
211
 
231
    
Line 212... Line 232...
212
    delay(10);
232
    return caps;    
213
    
233
}
214
    return sna->render.caps;
234
 
215
}
235
void sna_fini()
-
 
236
{
-
 
237
    if( sna_device )
-
 
238
    {
-
 
239
        struct kgem_bo *mask;
-
 
240
        
-
 
241
        __lock_acquire_recursive(__sna_lock);
216
 
242
        
-
 
243
        mask = tls_get(tls_mask);
217
void sna_fini()
244
        
218
{
245
        sna_device->render.fini(sna_device);
219
    if( sna_device )
246
        if(mask)
-
 
247
            kgem_bo_destroy(&sna_device->kgem, mask);
-
 
248
        kgem_close_batches(&sna_device->kgem);        
-
 
249
   	    kgem_cleanup_cache(&sna_device->kgem);
220
    {
250
   	    
221
        sna_device->render.fini(sna_device);
251
   	    sna_device = NULL;
Line 222... Line 252...
222
        kgem_bo_destroy(&sna_device->kgem, mask_bo);
252
        __lock_release_recursive(__sna_lock);
Line 352... Line 382...
352
done:
382
    return kgem_bo_reference(cache->bo[i]);
353
    cache->last = i;
383
}
354
    return kgem_bo_reference(cache->bo[i]);
384
 
355
}
385
#endif
Line -... Line 386...
-
 
386
 
Line 356... Line 387...
356
 
387
 
357
 
388
int sna_blit_copy(bitmap_t *src_bitmap, int dst_x, int dst_y,
Line 395... Line 426...
395
        copy.done(sna_device, ©);
426
 
396
    }
427
    kgem_submit(&sna_device->kgem);
Line 397... Line 428...
397
 
428
    
Line -... Line 429...
-
 
429
    return 0;
-
 
430
    
398
    kgem_submit(&sna_device->kgem);
431
//    __asm__ __volatile__("int3");
Line 399... Line 432...
399
    
432
    
-
 
433
};
400
//    __asm__ __volatile__("int3");
434
 
-
 
435
typedef struct 
-
 
436
{
-
 
437
    uint32_t        width;
-
 
438
    uint32_t        height;
-
 
439
    void           *data;
-
 
440
    uint32_t        pitch;
-
 
441
    struct kgem_bo *bo;    
-
 
442
    uint32_t        bo_size; 
-
 
443
    uint32_t        flags; 
-
 
444
}surface_t;
Line 401... Line 445...
401
    
445
 
402
};
446
 
-
 
447
 
403
#endif
448
int sna_create_bitmap(bitmap_t *bitmap)
Line -... Line 449...
-
 
449
{
-
 
450
    surface_t *sf;
-
 
451
	struct kgem_bo *bo;
-
 
452
    
-
 
453
    sf = malloc(sizeof(*sf));
-
 
454
    if(sf == NULL)
404
 
455
        goto err_1;
405
 
456
    
Line 406... Line 457...
406
int sna_create_bitmap(bitmap_t *bitmap)
457
    __lock_acquire_recursive(__sna_lock);
407
{
458
 
Line 408... Line 459...
408
	struct kgem_bo *bo;
459
    bo = kgem_create_2d(&sna_device->kgem, bitmap->width, bitmap->height,
409
    
460
                        32,I915_TILING_NONE, CREATE_CPU_MAP);
410
    bo = kgem_create_2d(&sna_device->kgem, bitmap->width, bitmap->height,
461
    
Line -... Line 462...
-
 
462
    if(bo == NULL)
411
                        32,I915_TILING_NONE, CREATE_CPU_MAP);
463
        goto err_2;
-
 
464
     
412
    
465
    void *map = kgem_bo_map(&sna_device->kgem, bo);
-
 
466
    if(map == NULL)
-
 
467
        goto err_3;
-
 
468
        
-
 
469
    sf->width   = bitmap->width;
413
    if(bo == NULL)
470
    sf->height  = bitmap->height;
-
 
471
    sf->data    = map;
Line 414... Line 472...
414
        goto err_1;
472
    sf->pitch   = bo->pitch;
Line 415... Line 473...
415
     
473
    sf->bo      = bo;
416
    void *map = kgem_bo_map(&sna_device->kgem, bo);
474
    sf->bo_size = PAGE_SIZE * bo->size.pages.count;
417
    if(map == NULL)
475
    sf->flags   = bitmap->flags;
-
 
476
    
-
 
477
    bitmap->handle = (uint32_t)sf;
418
        goto err_2;
478
    __lock_release_recursive(__sna_lock);
419
        
479
    
-
 
480
    return 0;
-
 
481
    
-
 
482
err_3:
-
 
483
    kgem_bo_destroy(&sna_device->kgem, bo);
-
 
484
err_2:
-
 
485
    __lock_release_recursive(__sna_lock);
-
 
486
    free(sf);    
-
 
487
err_1:
-
 
488
    return -1; 
-
 
489
};
-
 
490
 
-
 
491
int sna_destroy_bitmap(bitmap_t *bitmap)
-
 
492
{
-
 
493
    surface_t *sf = to_surface(bitmap);
-
 
494
    
-
 
495
    __lock_acquire_recursive(__sna_lock);
-
 
496
    
Line -... Line 497...
-
 
497
    kgem_bo_destroy(&sna_device->kgem, sf->bo);
420
    bitmap->handle = (uint32_t)bo;
498
           
Line 421... Line 499...
421
    bitmap->pitch  = bo->pitch;
499
    __lock_release_recursive(__sna_lock);
422
    bitmap->data   = map;
500
 
423
    
501
    free(sf);
Line -... Line 502...
-
 
502
    
424
    return 0;
503
    bitmap->handle = -1;
Line 425... Line 504...
425
    
504
    bitmap->data   = (void*)-1;
-
 
505
    bitmap->pitch  = -1;
-
 
506
 
-
 
507
    return 0;
-
 
508
};
-
 
509
 
Line -... Line 510...
-
 
510
int sna_lock_bitmap(bitmap_t *bitmap)
426
err_2:
511
{
Line 427... Line 512...
427
    kgem_bo_destroy(&sna_device->kgem, bo);
512
    surface_t *sf = to_surface(bitmap);    
428
    
513
    
-
 
514
//    printf("%s\n", __FUNCTION__);
-
 
515
    __lock_acquire_recursive(__sna_lock);
429
err_1:
516
    
Line -... Line 517...
-
 
517
    kgem_bo_sync__cpu(&sna_device->kgem, sf->bo);
430
    return -1; 
518
 
Line -... Line 519...
-
 
519
    __lock_release_recursive(__sna_lock);
431
           
520
        
Line -... Line 521...
-
 
521
    bitmap->data  = sf->data;
-
 
522
    bitmap->pitch = sf->pitch;    
-
 
523
 
-
 
524
    return 0;
-
 
525
};
-
 
526
 
-
 
527
int sna_resize_bitmap(bitmap_t *bitmap)
-
 
528
{
-
 
529
    surface_t *sf = to_surface(bitmap);
-
 
530
    struct kgem *kgem = &sna_device->kgem;
-
 
531
    struct kgem_bo *bo = sf->bo;    
-
 
532
    
-
 
533
    uint32_t   size;
-
 
534
    uint32_t   pitch;
-
 
535
 
-
 
536
   	bitmap->pitch = -1;
-
 
537
    bitmap->data = (void *) -1;
-
 
538
 
-
 
539
	size = kgem_surface_size(kgem,kgem->has_relaxed_fencing, CREATE_CPU_MAP,
-
 
540
				 bitmap->width, bitmap->height, 32, I915_TILING_NONE, &pitch);
-
 
541
	assert(size && size <= kgem->max_object_size);
-
 
542
        
-
 
543
    if(sf->bo_size >= size)
-
 
544
    {
-
 
545
        sf->width   = bitmap->width;
-
 
546
        sf->height  = bitmap->height;
-
 
547
        sf->pitch   = pitch;
-
 
548
        bo->pitch   = pitch; 
-
 
549
        
-
 
550
	    return 0;
-
 
551
    }
-
 
552
    else
-
 
553
    {
-
 
554
        __lock_acquire_recursive(__sna_lock);
-
 
555
        
-
 
556
        sna_bo_destroy(kgem, bo);
-
 
557
        
-
 
558
        sf->bo = NULL;
-
 
559
        
-
 
560
        bo = kgem_create_2d(kgem, bitmap->width, bitmap->height,
-
 
561
                            32, I915_TILING_NONE, CREATE_CPU_MAP);
-
 
562
 
-
 
563
        if(bo == NULL)
-
 
564
        {
-
 
565
            __lock_release_recursive(__sna_lock);
-
 
566
            return -1;
-
 
567
        };
-
 
568
        
-
 
569
        void *map = kgem_bo_map(kgem, bo);
432
};
570
        if(map == NULL)
Line -... Line 571...
-
 
571
        {
-
 
572
            sna_bo_destroy(kgem, bo);
433
 
573
            __lock_release_recursive(__sna_lock);
434
void sna_destroy_bitmap(bitmap_t *bitmap)
574
            return -1;
435
{
575
        };
436
	struct kgem_bo *bo;
-
 
437
    
-
 
Line 438... Line 576...
438
    bo = (struct kgem_bo *)bitmap->handle;
576
        
Line -... Line 577...
-
 
577
        __lock_release_recursive(__sna_lock);
-
 
578
        
439
        
579
        sf->width   = bitmap->width;
440
    kgem_bo_destroy(&sna_device->kgem, bo);
580
        sf->height  = bitmap->height;
Line 441... Line 581...
441
 
581
        sf->data    = map;
442
};
582
        sf->pitch   = bo->pitch;
Line 443... Line 583...
443
 
583
        sf->bo      = bo;
444
void sna_lock_bitmap(bitmap_t *bitmap)
584
        sf->bo_size = PAGE_SIZE * bo->size.pages.count;
445
{
585
    }
Line 446... Line 586...
446
	struct kgem_bo *bo;
586
 
Line 447... Line -...
447
    
-
 
448
    bo = (struct kgem_bo *)bitmap->handle;
587
    return 0;    
-
 
588
};
449
        
589
 
Line 450... Line 590...
450
    kgem_bo_sync__cpu(&sna_device->kgem, bo);
590
 
Line 451... Line 591...
451
 
591
 
452
};
592
int sna_create_mask()
453
 
-
 
454
int sna_create_mask()
593
{
-
 
594
	struct kgem_bo *bo;
455
{
595
 
456
	struct kgem_bo *bo;
-
 
457
    int width, height;
596
//    printf("%s width %d height %d\n", __FUNCTION__, sna_fb.width, sna_fb.height);
Line 458... Line 597...
458
    int i;
597
    
459
 
598
    __lock_acquire_recursive(__sna_lock);
Line 499... Line 638...
499
              struct sna_composite_op *tmp);
638
 
Line 500... Line 639...
500
 
639
#define MAP(ptr) ((void*)((uintptr_t)(ptr) & ~3))
Line 501... Line 640...
501
 
640
 
502
#define MAP(ptr) ((void*)((uintptr_t)(ptr) & ~3))
641
int sna_blit_tex(bitmap_t *bitmap, bool scale, int dst_x, int dst_y,
Line 503... Line 642...
503
 
642
                  int w, int h, int src_x, int src_y)
504
int sna_blit_tex(bitmap_t *src_bitmap, int dst_x, int dst_y,
-
 
505
                  int w, int h, int src_x, int src_y)
-
 
506
 
-
 
507
{
-
 
508
 
-
 
509
//    box.x1 = dst_x;
-
 
510
//    box.y1 = dst_y;
-
 
511
//    box.x2 = dst_x+w;
643
 
Line 512... Line 644...
512
//    box.y2 = dst_y+h;
644
{
Line 513... Line 645...
513
 
645
    surface_t *sf = to_surface(bitmap);    
514
 
646
 
515
 //   cop.box(sna_device, &cop, &box);
647
    struct drm_i915_mask_update update;
-
 
648
    
Line 516... Line 649...
516
 
649
    struct sna_composite_op composite;
517
    struct drm_i915_mask_update update;
-
 
Line 518... Line 650...
518
    
650
    struct _Pixmap src, dst, mask;
Line 519... Line 651...
519
    struct sna_composite_op composite;
651
    struct kgem_bo *src_bo, *mask_bo;
520
    struct _Pixmap src, dst, mask;
652
    int winx, winy;
521
    struct kgem_bo *src_bo;
653
 
522
 
654
    char proc_info[1024];
-
 
655
 
-
 
656
    get_proc_info(proc_info);
-
 
657
 
-
 
658
    winx = *(uint32_t*)(proc_info+34);
-
 
659
    winy = *(uint32_t*)(proc_info+38);
-
 
660
//    winw = *(uint32_t*)(proc_info+42)+1;
-
 
661
//    winh = *(uint32_t*)(proc_info+46)+1;
-
 
662
    
-
 
663
    mask_bo = tls_get(tls_mask);
-
 
664
    
-
 
665
    if(unlikely(mask_bo == NULL))
-
 
666
    {
-
 
667
        sna_create_mask();
-
 
668
        mask_bo = tls_get(tls_mask);
-
 
669
        if( mask_bo == NULL)
-
 
670
            return -1;  
-
 
671
    };
-
 
672
    
-
 
673
    if(kgem_update_fb(&sna_device->kgem, &sna_fb))
-
 
674
    {
-
 
675
        __lock_acquire_recursive(__sna_lock);
-
 
676
        kgem_bo_destroy(&sna_device->kgem, mask_bo);
Line 523... Line 677...
523
    char proc_info[1024];
677
        __lock_release_recursive(__sna_lock);
524
    int winx, winy, winw, winh;
678
        
525
 
-
 
526
    get_proc_info(proc_info);
-
 
527
 
679
        sna_create_mask();
528
    winx = *(uint32_t*)(proc_info+34);
680
        mask_bo = tls_get(tls_mask);
529
    winy = *(uint32_t*)(proc_info+38);
681
        if( mask_bo == NULL)
Line 530... Line 682...
530
    winw = *(uint32_t*)(proc_info+42)+1;
682
            return -1;  
531
    winh = *(uint32_t*)(proc_info+46)+1;
683
    }
532
    
684
    
Line 533... Line 685...
533
    VG_CLEAR(update);
685
    VG_CLEAR(update);
-
 
686
	update.handle = mask_bo->handle;
534
	update.handle = mask_bo->handle;
687
	update.bo_map    = (__u32)MAP(mask_bo->map);
535
//	update.bo_size   = __kgem_bo_size(mask_bo);
688
	drmIoctl(sna_device->kgem.fd, SRV_MASK_UPDATE, &update);
Line 536... Line 689...
536
//	update.bo_pitch  = mask_bo->pitch;
689
    mask_bo->pitch = update.bo_pitch;
537
	update.bo_map    = (__u32)MAP(mask_bo->map);
690
    
538
	drmIoctl(sna_device->kgem.fd, SRV_MASK_UPDATE, &update);
691
    memset(&src, 0, sizeof(src));
Line 554... Line 707...
554
    mask.drawable.width  = update.width;
707
 
555
    mask.drawable.height = update.height;
708
    memset(&composite, 0, sizeof(composite));
Line 556... Line 709...
556
 
709
 
Line -... Line 710...
-
 
710
    src_bo = sf->bo;
-
 
711
    
557
    memset(&composite, 0, sizeof(composite));
712
    __lock_acquire_recursive(__sna_lock);
Line 558... Line 713...
558
 
713
 
559
    src_bo = (struct kgem_bo*)src_bitmap->handle;
714
    
560
    
715
    if( sna_device->render.blit_tex(sna_device, PictOpSrc,scale,
561
    
716
		      &src, src_bo,
562
    if( sna_device->render.blit_tex(sna_device, PictOpSrc,
717
		      &mask, mask_bo,
563
		      &src, src_bo,
718
		      &dst, sna_fb.fb_bo, 
Line 580... Line 735...
580
	    r.width  = w;
735
        
581
	    r.height = h;
736
        composite.blt(sna_device, &composite, &r);
Line 582... Line 737...
582
        
737
        composite.done(sna_device, &composite);
583
        composite.blt(sna_device, &composite, &r);
738
        
-
 
739
    };
584
        composite.done(sna_device, &composite);
740
    
Line 585... Line 741...
585
    };
741
    kgem_submit(&sna_device->kgem);
Line -... Line 742...
-
 
742
 
-
 
743
    __lock_release_recursive(__sna_lock);
-
 
744
 
-
 
745
    bitmap->data   = (void*)-1;
-
 
746
    bitmap->pitch  = -1;
586
    
747
 
587
    kgem_submit(&sna_device->kgem);
748
    return 0;            
Line 756... Line 917...
756
 
917
intel_detect_chipset(struct pci_device *pci)
757
const struct intel_device_info *
918
{
758
intel_detect_chipset(struct pci_device *pci)
919
    const struct pci_id_match *ent = NULL;
759
{
920
 
760
    const struct pci_id_match *ent = NULL;
-
 
761
	const char *name = NULL;
-
 
Line 762... Line 921...
762
	int i;
921
    ent = PciDevMatch(pci->device_id, intel_device_match); 
Line 763... Line 922...
763
 
922
    
764
    ent = PciDevMatch(pci->device_id, intel_device_match); 
923
    if(ent != NULL)