Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
4075 Serge 1
#include 
2
#include 
3
 
4
#include 
5
#include 
6
 
7
#include "vmwgfx_drv.h"
8
 
9
#include 
10
#include 
11
#include 
12
#include 
13
 
14
#include "bitmap.h"
15
 
16
struct pci_device {
17
    uint16_t    domain;
18
    uint8_t     bus;
19
    uint8_t     dev;
20
    uint8_t     func;
21
    uint16_t    vendor_id;
22
    uint16_t    device_id;
23
    uint16_t    subvendor_id;
24
    uint16_t    subdevice_id;
25
    uint32_t    device_class;
26
    uint8_t     revision;
27
};
28
 
4111 Serge 29
struct drm_device *main_device;
30
struct drm_file   *drm_file_handlers[256];
4075 Serge 31
 
32
int vmw_init(void);
4111 Serge 33
int kms_init(struct drm_device *dev);
34
void kms_update();
35
 
4075 Serge 36
void cpu_detect();
37
 
38
void parse_cmdline(char *cmdline, char *log);
39
int _stdcall display_handler(ioctl_t *io);
40
 
41
int srv_blit_bitmap(u32 hbitmap, int  dst_x, int dst_y,
42
               int src_x, int src_y, u32 w, u32 h);
43
 
44
int blit_textured(u32 hbitmap, int  dst_x, int dst_y,
45
               int src_x, int src_y, u32 w, u32 h);
46
 
47
int blit_tex(u32 hbitmap, int  dst_x, int dst_y,
48
             int src_x, int src_y, u32 w, u32 h);
49
 
50
void get_pci_info(struct pci_device *dev);
51
int gem_getparam(struct drm_device *dev, void *data);
52
 
53
int i915_mask_update(struct drm_device *dev, void *data,
54
            struct drm_file *file);
55
 
56
 
57
static char  log[256];
58
 
59
struct workqueue_struct *system_wq;
60
int driver_wq_state;
61
 
62
int x86_clflush_size;
63
unsigned int tsc_khz;
64
 
4080 Serge 65
int kms_modeset = 1;
4075 Serge 66
 
4111 Serge 67
 
68
void vmw_driver_thread()
69
{
70
    dbgprintf("%s\n",__FUNCTION__);
71
 
72
//    run_workqueue(dev_priv->wq);
73
 
74
    while(driver_wq_state)
75
    {
76
        kms_update();
77
        delay(1);
78
    };
79
     __asm__ __volatile__ (
80
     "int $0x40"
81
     ::"a"(-1));
82
}
83
 
4075 Serge 84
u32_t  __attribute__((externally_visible)) drvEntry(int action, char *cmdline)
85
{
86
 
87
    int     err = 0;
88
 
89
    if(action != 1)
90
    {
91
        driver_wq_state = 0;
92
        return 0;
93
    };
94
 
95
    if( GetService("DISPLAY") != 0 )
96
        return 0;
97
 
98
    if( cmdline && *cmdline )
99
        parse_cmdline(cmdline, log);
100
 
4570 Serge 101
    if( *log && !dbg_open(log))
4075 Serge 102
    {
103
            printf("Can't open %s\nExit\n", log);
104
            return 0;
105
    }
106
 
4570 Serge 107
    dbgprintf(" vmw v3.14-rc1\n cmdline: %s\n", cmdline);
108
 
4075 Serge 109
    cpu_detect();
110
    dbgprintf("\ncache line size %d\n", x86_clflush_size);
111
 
112
    enum_pci_devices();
113
 
114
    err = vmw_init();
115
    if(err)
116
    {
117
        dbgprintf("Epic Fail :(\n");
118
        return 0;
119
    };
4111 Serge 120
    kms_init(main_device);
4075 Serge 121
 
122
    err = RegService("DISPLAY", display_handler);
123
 
124
    if( err != 0)
125
        dbgprintf("Set DISPLAY handler\n");
126
 
4111 Serge 127
    driver_wq_state = 1;
4075 Serge 128
 
4111 Serge 129
    CreateKernelThread(vmw_driver_thread);
130
 
4075 Serge 131
    return err;
132
};
133
 
134
 
135
#define CURRENT_API     0x0200      /*      2.00     */
136
#define COMPATIBLE_API  0x0100      /*      1.00     */
137
 
138
#define API_VERSION     (COMPATIBLE_API << 16) | CURRENT_API
139
#define DISPLAY_VERSION  API_VERSION
140
 
141
 
142
#define SRV_GETVERSION          0
143
#define SRV_ENUM_MODES          1
144
#define SRV_SET_MODE            2
145
#define SRV_GET_CAPS            3
146
 
147
#define SRV_CREATE_SURFACE      10
148
#define SRV_DESTROY_SURFACE     11
149
#define SRV_LOCK_SURFACE        12
150
#define SRV_UNLOCK_SURFACE      13
151
#define SRV_RESIZE_SURFACE      14
152
#define SRV_BLIT_BITMAP         15
153
#define SRV_BLIT_TEXTURE        16
154
#define SRV_BLIT_VIDEO          17
155
 
156
 
157
#define SRV_GET_PCI_INFO            20
158
#define SRV_GET_PARAM               21
159
#define SRV_I915_GEM_CREATE         22
160
#define SRV_DRM_GEM_CLOSE           23
161
#define SRV_I915_GEM_PIN            24
162
#define SRV_I915_GEM_SET_CACHEING   25
163
#define SRV_I915_GEM_GET_APERTURE   26
164
#define SRV_I915_GEM_PWRITE         27
165
#define SRV_I915_GEM_BUSY           28
166
#define SRV_I915_GEM_SET_DOMAIN     29
167
#define SRV_I915_GEM_MMAP           30
168
#define SRV_I915_GEM_MMAP_GTT       31
169
#define SRV_I915_GEM_THROTTLE       32
170
#define SRV_FBINFO                  33
171
#define SRV_I915_GEM_EXECBUFFER2    34
172
#define SRV_MASK_UPDATE             35
173
 
174
 
175
 
176
#define check_input(size) \
177
    if( unlikely((inp==NULL)||(io->inp_size != (size))) )   \
178
        break;
179
 
180
#define check_output(size) \
181
    if( unlikely((outp==NULL)||(io->out_size != (size))) )   \
182
        break;
183
 
184
int _stdcall display_handler(ioctl_t *io)
185
{
186
    struct drm_file *file;
187
 
188
    int    retval = -1;
189
    u32_t *inp;
190
    u32_t *outp;
191
 
192
    inp = io->input;
193
    outp = io->output;
194
 
195
    file = drm_file_handlers[0];
196
 
197
    switch(io->io_code)
198
    {
199
        case SRV_GETVERSION:
200
            check_output(4);
201
            *outp  = DISPLAY_VERSION;
202
            retval = 0;
203
            break;
4080 Serge 204
 
4075 Serge 205
        case SRV_ENUM_MODES:
4080 Serge 206
            dbgprintf("SRV_ENUM_MODES inp %x inp_size %x out_size %x\n",
207
                       inp, io->inp_size, io->out_size );
4075 Serge 208
            check_output(4);
209
//            check_input(*outp * sizeof(videomode_t));
4080 Serge 210
            if( kms_modeset)
4075 Serge 211
                retval = get_videomodes((videomode_t*)inp, outp);
212
            break;
213
 
214
        case SRV_SET_MODE:
4080 Serge 215
            dbgprintf("SRV_SET_MODE inp %x inp_size %x\n",
216
                       inp, io->inp_size);
4075 Serge 217
            check_input(sizeof(videomode_t));
4080 Serge 218
            if( kms_modeset )
4075 Serge 219
                retval = set_user_mode((videomode_t*)inp);
220
            break;
221
 
4080 Serge 222
#if 0
4075 Serge 223
        case SRV_GET_CAPS:
224
            retval = get_driver_caps((hwcaps_t*)inp);
225
            break;
226
 
227
        case SRV_CREATE_SURFACE:
228
//            check_input(8);
229
//            retval = create_surface(main_device, (struct io_call_10*)inp);
230
            break;
231
 
232
        case SRV_LOCK_SURFACE:
233
//            retval = lock_surface((struct io_call_12*)inp);
234
            break;
235
 
236
        case SRV_RESIZE_SURFACE:
237
//            retval = resize_surface((struct io_call_14*)inp);
238
            break;
239
 
240
        case SRV_BLIT_BITMAP:
241
//            srv_blit_bitmap( inp[0], inp[1], inp[2],
242
//                        inp[3], inp[4], inp[5], inp[6]);
243
 
244
//            blit_tex( inp[0], inp[1], inp[2],
245
//                    inp[3], inp[4], inp[5], inp[6]);
246
 
247
            break;
248
 
249
        case SRV_GET_PCI_INFO:
250
            get_pci_info((struct pci_device *)inp);
251
            retval = 0;
252
            break;
253
 
254
        case SRV_GET_PARAM:
255
            retval = gem_getparam(main_device, inp);
256
            break;
257
 
258
        case SRV_I915_GEM_CREATE:
259
            retval = i915_gem_create_ioctl(main_device, inp, file);
260
            break;
261
 
262
        case SRV_DRM_GEM_CLOSE:
263
            retval = drm_gem_close_ioctl(main_device, inp, file);
264
            break;
265
 
266
        case SRV_I915_GEM_PIN:
267
            retval = i915_gem_pin_ioctl(main_device, inp, file);
268
            break;
269
 
270
        case SRV_I915_GEM_SET_CACHEING:
271
            retval = i915_gem_set_caching_ioctl(main_device, inp, file);
272
            break;
273
 
274
        case SRV_I915_GEM_GET_APERTURE:
275
            retval = i915_gem_get_aperture_ioctl(main_device, inp, file);
276
            break;
277
 
278
        case SRV_I915_GEM_PWRITE:
279
            retval = i915_gem_pwrite_ioctl(main_device, inp, file);
280
            break;
281
 
282
        case SRV_I915_GEM_BUSY:
283
            retval = i915_gem_busy_ioctl(main_device, inp, file);
284
            break;
285
 
286
        case SRV_I915_GEM_SET_DOMAIN:
287
            retval = i915_gem_set_domain_ioctl(main_device, inp, file);
288
            break;
289
 
290
        case SRV_I915_GEM_THROTTLE:
291
            retval = i915_gem_throttle_ioctl(main_device, inp, file);
292
            break;
293
 
294
        case SRV_I915_GEM_MMAP:
295
            retval = i915_gem_mmap_ioctl(main_device, inp, file);
296
            break;
297
 
298
        case SRV_I915_GEM_MMAP_GTT:
299
            retval = i915_gem_mmap_gtt_ioctl(main_device, inp, file);
300
            break;
301
 
302
 
303
        case SRV_FBINFO:
304
            retval = i915_fbinfo(inp);
305
            break;
306
 
307
        case SRV_I915_GEM_EXECBUFFER2:
308
            retval = i915_gem_execbuffer2(main_device, inp, file);
309
            break;
310
 
311
        case SRV_MASK_UPDATE:
312
            retval = i915_mask_update(main_device, inp, file);
313
            break;
314
#endif
315
 
316
    };
317
 
318
    return retval;
319
}
320
 
321
 
322
#define PCI_CLASS_REVISION      0x08
323
#define PCI_CLASS_DISPLAY_VGA   0x0300
324
#define PCI_CLASS_BRIDGE_HOST   0x0600
325
#define PCI_CLASS_BRIDGE_ISA    0x0601
326
 
327
int pci_scan_filter(u32_t id, u32_t busnr, u32_t devfn)
328
{
329
    u16_t vendor, device;
330
    u32_t class;
331
    int   ret = 0;
332
 
333
    vendor   = id & 0xffff;
334
    device   = (id >> 16) & 0xffff;
335
 
336
    if(vendor == 0x15AD )
337
    {
338
        class = PciRead32(busnr, devfn, PCI_CLASS_REVISION);
339
        class >>= 16;
340
 
341
        if( class == PCI_CLASS_DISPLAY_VGA )
342
            ret = 1;
343
    }
344
    return ret;
345
};
346
 
347
 
348
static char* parse_path(char *p, char *log)
349
{
350
    char  c;
351
 
352
    while( (c = *p++) == ' ');
353
        p--;
354
    while( (c = *log++ = *p++) && (c != ' '));
355
    *log = 0;
356
 
357
    return p;
358
};
359
 
360
void parse_cmdline(char *cmdline, char *log)
361
{
362
    char *p = cmdline;
363
 
364
    char c = *p++;
365
 
366
    while( c )
367
    {
368
        if( c == '-')
369
        {
370
            switch(*p++)
371
            {
372
                case 'l':
373
                    p = parse_path(p, log);
374
                    break;
375
            };
376
        };
377
        c = *p++;
378
    };
379
};
380
 
381
 
382
static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
383
                unsigned int *ecx, unsigned int *edx)
384
{
385
    /* ecx is often an input as well as an output. */
386
    asm volatile("cpuid"
387
        : "=a" (*eax),
388
          "=b" (*ebx),
389
          "=c" (*ecx),
390
          "=d" (*edx)
391
        : "0" (*eax), "2" (*ecx)
392
        : "memory");
393
}
394
 
395
 
396
 
397
static inline void cpuid(unsigned int op,
398
                         unsigned int *eax, unsigned int *ebx,
399
                         unsigned int *ecx, unsigned int *edx)
400
{
401
        *eax = op;
402
        *ecx = 0;
403
        __cpuid(eax, ebx, ecx, edx);
404
}
405
 
406
void cpu_detect()
407
{
408
    u32 junk, tfms, cap0, misc;
409
 
410
    cpuid(0x00000001, &tfms, &misc, &junk, &cap0);
411
 
412
    if (cap0 & (1<<19))
413
    {
414
        x86_clflush_size = ((misc >> 8) & 0xff) * 8;
415
    }
416
 
417
    tsc_khz = (unsigned int)(GetCpuFreq()/1000);
418
}
419
 
420
/*
421
int get_driver_caps(hwcaps_t *caps)
422
{
423
    int ret = 0;
424
 
425
    switch(caps->idx)
426
    {
427
        case 0:
428
            caps->opt[0] = 0;
429
            caps->opt[1] = 0;
430
            break;
431
 
432
        case 1:
433
            caps->cap1.max_tex_width  = 4096;
434
            caps->cap1.max_tex_height = 4096;
435
            break;
436
        default:
437
            ret = 1;
438
    };
439
    caps->idx = 1;
440
    return ret;
441
}
442
 
443
 
444
void get_pci_info(struct pci_device *dev)
445
{
446
    struct pci_dev *pdev = main_device->pdev;
447
 
448
    memset(dev, sizeof(*dev), 0);
449
 
450
    dev->domain     = 0;
451
    dev->bus        = pdev->busnr;
452
    dev->dev        = pdev->devfn >> 3;
453
    dev->func       = pdev->devfn & 7;
454
    dev->vendor_id  = pdev->vendor;
455
    dev->device_id  = pdev->device;
456
    dev->revision   = pdev->revision;
457
};
458
 
459
*/
460
 
461
#include 
462
#include 
463
#include 
464
#include 
465
 
466
 
467
static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes)
468
{
469
        while (bytes) {
470
                if (*start != value)
471
                        return (void *)start;
472
                start++;
473
                bytes--;
474
        }
475
        return NULL;
476
}
477
 
478
/**
479
 * memchr_inv - Find an unmatching character in an area of memory.
480
 * @start: The memory area
481
 * @c: Find a character other than c
482
 * @bytes: The size of the area.
483
 *
484
 * returns the address of the first character other than @c, or %NULL
485
 * if the whole buffer contains just @c.
486
 */
487
void *memchr_inv(const void *start, int c, size_t bytes)
488
{
489
        u8 value = c;
490
        u64 value64;
491
        unsigned int words, prefix;
492
 
493
        if (bytes <= 16)
494
                return check_bytes8(start, value, bytes);
495
 
496
        value64 = value;
497
#if defined(ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64
498
        value64 *= 0x0101010101010101;
499
#elif defined(ARCH_HAS_FAST_MULTIPLIER)
500
        value64 *= 0x01010101;
501
        value64 |= value64 << 32;
502
#else
503
        value64 |= value64 << 8;
504
        value64 |= value64 << 16;
505
        value64 |= value64 << 32;
506
#endif
507
 
508
        prefix = (unsigned long)start % 8;
509
        if (prefix) {
510
                u8 *r;
511
 
512
                prefix = 8 - prefix;
513
                r = check_bytes8(start, value, prefix);
514
                if (r)
515
                        return r;
516
                start += prefix;
517
                bytes -= prefix;
518
        }
519
 
520
        words = bytes / 8;
521
 
522
        while (words) {
523
                if (*(u64 *)start != value64)
524
                        return check_bytes8(start, value, 8);
525
                start += 8;
526
                words--;
527
        }
528
 
529
        return check_bytes8(start, value, bytes % 8);
530
}
531
 
532
int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
533
{
534
    int i;
535
 
536
    i = vsnprintf(buf, size, fmt, args);
537
 
538
    if (likely(i < size))
539
            return i;
540
    if (size != 0)
541
            return size - 1;
542
    return 0;
543
}
544
 
545
 
546
int scnprintf(char *buf, size_t size, const char *fmt, ...)
547
{
548
        va_list args;
549
        int i;
550
 
551
        va_start(args, fmt);
552
        i = vscnprintf(buf, size, fmt, args);
553
        va_end(args);
554
 
555
        return i;
556
}
557
 
558
 
559
 
560
#define _U  0x01    /* upper */
561
#define _L  0x02    /* lower */
562
#define _D  0x04    /* digit */
563
#define _C  0x08    /* cntrl */
564
#define _P  0x10    /* punct */
565
#define _S  0x20    /* white space (space/lf/tab) */
566
#define _X  0x40    /* hex digit */
567
#define _SP 0x80    /* hard space (0x20) */
568
 
569
extern const unsigned char _ctype[];
570
 
571
#define __ismask(x) (_ctype[(int)(unsigned char)(x)])
572
 
573
#define isalnum(c)  ((__ismask(c)&(_U|_L|_D)) != 0)
574
#define isalpha(c)  ((__ismask(c)&(_U|_L)) != 0)
575
#define iscntrl(c)  ((__ismask(c)&(_C)) != 0)
576
#define isdigit(c)  ((__ismask(c)&(_D)) != 0)
577
#define isgraph(c)  ((__ismask(c)&(_P|_U|_L|_D)) != 0)
578
#define islower(c)  ((__ismask(c)&(_L)) != 0)
579
#define isprint(c)  ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0)
580
#define ispunct(c)  ((__ismask(c)&(_P)) != 0)
581
/* Note: isspace() must return false for %NUL-terminator */
582
#define isspace(c)  ((__ismask(c)&(_S)) != 0)
583
#define isupper(c)  ((__ismask(c)&(_U)) != 0)
584
#define isxdigit(c) ((__ismask(c)&(_D|_X)) != 0)
585
 
586
#define isascii(c) (((unsigned char)(c))<=0x7f)
587
#define toascii(c) (((unsigned char)(c))&0x7f)
588
 
589
 
590
 
591
//const char hex_asc[] = "0123456789abcdef";
592
 
593
/**
594
 * hex_to_bin - convert a hex digit to its real value
595
 * @ch: ascii character represents hex digit
596
 *
597
 * hex_to_bin() converts one hex digit to its actual value or -1 in case of bad
598
 * input.
599
 */
600
int hex_to_bin(char ch)
601
{
602
    if ((ch >= '0') && (ch <= '9'))
603
        return ch - '0';
604
    ch = tolower(ch);
605
    if ((ch >= 'a') && (ch <= 'f'))
606
        return ch - 'a' + 10;
607
    return -1;
608
}
609
EXPORT_SYMBOL(hex_to_bin);
610
 
611
/**
612
 * hex2bin - convert an ascii hexadecimal string to its binary representation
613
 * @dst: binary result
614
 * @src: ascii hexadecimal string
615
 * @count: result length
616
 *
617
 * Return 0 on success, -1 in case of bad input.
618
 */
619
int hex2bin(u8 *dst, const char *src, size_t count)
620
{
621
    while (count--) {
622
        int hi = hex_to_bin(*src++);
623
        int lo = hex_to_bin(*src++);
624
 
625
        if ((hi < 0) || (lo < 0))
626
            return -1;
627
 
628
        *dst++ = (hi << 4) | lo;
629
    }
630
    return 0;
631
}
632
EXPORT_SYMBOL(hex2bin);
633
 
634
/**
635
 * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory
636
 * @buf: data blob to dump
637
 * @len: number of bytes in the @buf
638
 * @rowsize: number of bytes to print per line; must be 16 or 32
639
 * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1)
640
 * @linebuf: where to put the converted data
641
 * @linebuflen: total size of @linebuf, including space for terminating NUL
642
 * @ascii: include ASCII after the hex output
643
 *
644
 * hex_dump_to_buffer() works on one "line" of output at a time, i.e.,
645
 * 16 or 32 bytes of input data converted to hex + ASCII output.
646
 *
647
 * Given a buffer of u8 data, hex_dump_to_buffer() converts the input data
648
 * to a hex + ASCII dump at the supplied memory location.
649
 * The converted output is always NUL-terminated.
650
 *
651
 * E.g.:
652
 *   hex_dump_to_buffer(frame->data, frame->len, 16, 1,
653
 *          linebuf, sizeof(linebuf), true);
654
 *
655
 * example output buffer:
656
 * 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f  @ABCDEFGHIJKLMNO
657
 */
658
void hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
659
            int groupsize, char *linebuf, size_t linebuflen,
660
            bool ascii)
661
{
662
    const u8 *ptr = buf;
663
    u8 ch;
664
    int j, lx = 0;
665
    int ascii_column;
666
 
667
    if (rowsize != 16 && rowsize != 32)
668
        rowsize = 16;
669
 
670
    if (!len)
671
        goto nil;
672
    if (len > rowsize)      /* limit to one line at a time */
673
        len = rowsize;
674
    if ((len % groupsize) != 0) /* no mixed size output */
675
        groupsize = 1;
676
 
677
    switch (groupsize) {
678
    case 8: {
679
        const u64 *ptr8 = buf;
680
        int ngroups = len / groupsize;
681
 
682
        for (j = 0; j < ngroups; j++)
683
            lx += scnprintf(linebuf + lx, linebuflen - lx,
684
                    "%s%16.16llx", j ? " " : "",
685
                    (unsigned long long)*(ptr8 + j));
686
        ascii_column = 17 * ngroups + 2;
687
        break;
688
    }
689
 
690
    case 4: {
691
        const u32 *ptr4 = buf;
692
        int ngroups = len / groupsize;
693
 
694
        for (j = 0; j < ngroups; j++)
695
            lx += scnprintf(linebuf + lx, linebuflen - lx,
696
                    "%s%8.8x", j ? " " : "", *(ptr4 + j));
697
        ascii_column = 9 * ngroups + 2;
698
        break;
699
    }
700
 
701
    case 2: {
702
        const u16 *ptr2 = buf;
703
        int ngroups = len / groupsize;
704
 
705
        for (j = 0; j < ngroups; j++)
706
            lx += scnprintf(linebuf + lx, linebuflen - lx,
707
                    "%s%4.4x", j ? " " : "", *(ptr2 + j));
708
        ascii_column = 5 * ngroups + 2;
709
        break;
710
    }
711
 
712
    default:
713
        for (j = 0; (j < len) && (lx + 3) <= linebuflen; j++) {
714
            ch = ptr[j];
715
            linebuf[lx++] = hex_asc_hi(ch);
716
            linebuf[lx++] = hex_asc_lo(ch);
717
            linebuf[lx++] = ' ';
718
        }
719
        if (j)
720
            lx--;
721
 
722
        ascii_column = 3 * rowsize + 2;
723
        break;
724
    }
725
    if (!ascii)
726
        goto nil;
727
 
728
    while (lx < (linebuflen - 1) && lx < (ascii_column - 1))
729
        linebuf[lx++] = ' ';
730
    for (j = 0; (j < len) && (lx + 2) < linebuflen; j++) {
731
        ch = ptr[j];
732
        linebuf[lx++] = (isascii(ch) && isprint(ch)) ? ch : '.';
733
    }
734
nil:
735
    linebuf[lx++] = '\0';
736
}
737
 
738
/**
739
 * print_hex_dump - print a text hex dump to syslog for a binary blob of data
740
 * @level: kernel log level (e.g. KERN_DEBUG)
741
 * @prefix_str: string to prefix each line with;
742
 *  caller supplies trailing spaces for alignment if desired
743
 * @prefix_type: controls whether prefix of an offset, address, or none
744
 *  is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE)
745
 * @rowsize: number of bytes to print per line; must be 16 or 32
746
 * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1)
747
 * @buf: data blob to dump
748
 * @len: number of bytes in the @buf
749
 * @ascii: include ASCII after the hex output
750
 *
751
 * Given a buffer of u8 data, print_hex_dump() prints a hex + ASCII dump
752
 * to the kernel log at the specified kernel log level, with an optional
753
 * leading prefix.
754
 *
755
 * print_hex_dump() works on one "line" of output at a time, i.e.,
756
 * 16 or 32 bytes of input data converted to hex + ASCII output.
757
 * print_hex_dump() iterates over the entire input @buf, breaking it into
758
 * "line size" chunks to format and print.
759
 *
760
 * E.g.:
761
 *   print_hex_dump(KERN_DEBUG, "raw data: ", DUMP_PREFIX_ADDRESS,
762
 *          16, 1, frame->data, frame->len, true);
763
 *
764
 * Example output using %DUMP_PREFIX_OFFSET and 1-byte mode:
765
 * 0009ab42: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f  @ABCDEFGHIJKLMNO
766
 * Example output using %DUMP_PREFIX_ADDRESS and 4-byte mode:
767
 * ffffffff88089af0: 73727170 77767574 7b7a7978 7f7e7d7c  pqrstuvwxyz{|}~.
768
 */
769
void print_hex_dump(const char *level, const char *prefix_str, int prefix_type,
770
            int rowsize, int groupsize,
771
            const void *buf, size_t len, bool ascii)
772
{
773
    const u8 *ptr = buf;
774
    int i, linelen, remaining = len;
775
    unsigned char linebuf[32 * 3 + 2 + 32 + 1];
776
 
777
    if (rowsize != 16 && rowsize != 32)
778
        rowsize = 16;
779
 
780
    for (i = 0; i < len; i += rowsize) {
781
        linelen = min(remaining, rowsize);
782
        remaining -= rowsize;
783
 
784
        hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize,
785
                   linebuf, sizeof(linebuf), ascii);
786
 
787
        switch (prefix_type) {
788
        case DUMP_PREFIX_ADDRESS:
789
            printk("%s%s%p: %s\n",
790
                   level, prefix_str, ptr + i, linebuf);
791
            break;
792
        case DUMP_PREFIX_OFFSET:
793
            printk("%s%s%.8x: %s\n", level, prefix_str, i, linebuf);
794
            break;
795
        default:
796
            printk("%s%s%s\n", level, prefix_str, linebuf);
797
            break;
798
        }
799
    }
800
}
801
 
802
void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
803
                          const void *buf, size_t len)
804
{
805
    print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, 16, 1,
806
                       buf, len, true);
807
}
808
 
809
 
4080 Serge 810
 
811
 
812
 
813
 
814
 
815
 
816
 
817
#include "vmwgfx_kms.h"
818
 
819
void kms_update();
820
 
821
 
822
extern struct drm_device *main_device;
823
 
824
typedef struct
825
{
826
    kobj_t     header;
827
 
828
    uint32_t  *data;
829
    uint32_t   hot_x;
830
    uint32_t   hot_y;
831
 
832
    struct list_head   list;
833
}cursor_t;
834
 
835
#define CURSOR_WIDTH 64
836
#define CURSOR_HEIGHT 64
837
 
838
struct tag_display
839
{
840
    int  x;
841
    int  y;
842
    int  width;
843
    int  height;
844
    int  bpp;
845
    int  vrefresh;
846
    int  pitch;
847
    int  lfb;
848
 
849
    int  supported_modes;
850
    struct drm_device    *ddev;
851
    struct drm_connector *connector;
852
    struct drm_crtc      *crtc;
853
 
854
    struct list_head   cursors;
855
 
856
    cursor_t   *cursor;
857
    int       (*init_cursor)(cursor_t*);
858
    cursor_t* (__stdcall *select_cursor)(cursor_t*);
859
    void      (*show_cursor)(int show);
860
    void      (__stdcall *move_cursor)(cursor_t *cursor, int x, int y);
861
    void      (__stdcall *restore_cursor)(int x, int y);
862
    void      (*disable_mouse)(void);
863
    u32  mask_seqno;
864
    u32  check_mouse;
865
    u32  check_m_pixel;
866
};
867
 
4111 Serge 868
 
4080 Serge 869
static display_t *os_display;
870
 
871
static int count_connector_modes(struct drm_connector* connector)
872
{
873
    struct drm_display_mode  *mode;
874
    int count = 0;
875
 
876
    list_for_each_entry(mode, &connector->modes, head)
877
    {
878
        count++;
879
    };
880
    return count;
881
};
882
 
4570 Serge 883
static void __stdcall restore_cursor(int x, int y){};
884
static void disable_mouse(void) {};
885
 
886
static void __stdcall move_cursor_kms(cursor_t *cursor, int x, int y)
887
{
888
    struct drm_crtc *crtc = os_display->crtc;
889
    struct vmw_private *dev_priv = vmw_priv(crtc->dev);
890
    struct vmw_display_unit *du = vmw_crtc_to_du(crtc);
891
 
892
    vmw_cursor_update_position(dev_priv, true, x,y);
893
};
894
 
895
static cursor_t* __stdcall select_cursor_kms(cursor_t *cursor)
896
{
897
    struct vmw_private *dev_priv = vmw_priv(os_display->ddev);
898
    cursor_t *old;
899
 
900
    old = os_display->cursor;
901
    os_display->cursor = cursor;
902
 
903
    vmw_cursor_update_image(dev_priv, cursor->data,
904
                    64, 64, cursor->hot_x, cursor->hot_y);
905
 
906
//    vmw_cursor_update_position(dev_priv, true,
907
//                   du->cursor_x + du->hotspot_x,
908
//                   du->cursor_y + du->hotspot_y);
909
 
910
    return old;
911
};
912
 
913
 
4080 Serge 914
int kms_init(struct drm_device *dev)
915
{
916
    struct drm_connector    *connector;
917
    struct drm_connector_helper_funcs *connector_funcs;
918
    struct drm_encoder      *encoder;
919
    struct drm_crtc         *crtc = NULL;
920
    struct drm_framebuffer  *fb;
921
 
922
    cursor_t  *cursor;
923
    int        mode_count;
924
    u32_t      ifl;
925
    int        err;
926
 
927
    ENTER();
928
 
929
    crtc = list_entry(dev->mode_config.crtc_list.next, typeof(*crtc), head);
930
    encoder = list_entry(dev->mode_config.encoder_list.next, typeof(*encoder), head);
931
    connector = list_entry(dev->mode_config.connector_list.next, typeof(*connector), head);
932
    connector->encoder = encoder;
933
 
934
    mode_count = count_connector_modes(connector);
935
    if(mode_count == 0)
936
    {
937
        struct drm_display_mode *mode;
938
 
939
        connector->funcs->fill_modes(connector,
940
                                     dev->mode_config.max_width,
941
                                     dev->mode_config.max_height);
942
 
943
        list_for_each_entry(mode, &connector->modes, head)
944
        mode_count++;
945
    };
946
 
947
    printf("%s %d\n",__FUNCTION__, mode_count);
948
 
949
    DRM_DEBUG_KMS("CONNECTOR %x ID:%d status:%d ENCODER %x CRTC %x ID:%d\n",
950
               connector, connector->base.id,
951
               connector->status, connector->encoder,
952
               crtc, crtc->base.id );
953
 
954
    DRM_DEBUG_KMS("[Select CRTC:%d]\n", crtc->base.id);
955
 
956
    os_display = GetDisplay();
957
 
958
    ifl = safe_cli();
959
    {
960
        os_display->ddev = dev;
961
        os_display->connector = connector;
962
        os_display->crtc = crtc;
963
        os_display->supported_modes = mode_count;
964
 
4570 Serge 965
        os_display->restore_cursor(0,0);
966
        os_display->select_cursor  = select_cursor_kms;
967
        os_display->show_cursor    = NULL;
968
        os_display->move_cursor    = move_cursor_kms;
969
        os_display->restore_cursor = restore_cursor;
970
        os_display->disable_mouse  = disable_mouse;
971
        select_cursor_kms(os_display->cursor);
4080 Serge 972
    };
973
    safe_sti(ifl);
974
 
975
#ifdef __HWA__
976
    err = init_bitmaps();
977
#endif
978
 
979
    LEAVE();
980
 
981
    return 0;
982
};
983
 
984
 
985
void kms_update()
986
{
987
    struct vmw_private *dev_priv = vmw_priv(main_device);
988
    size_t fifo_size;
989
    int i;
990
 
991
    struct {
992
        uint32_t header;
993
        SVGAFifoCmdUpdate body;
994
    } *cmd;
995
 
996
    fifo_size = sizeof(*cmd);
997
 
998
    cmd = vmw_fifo_reserve(dev_priv, fifo_size);
999
    if (unlikely(cmd == NULL)) {
1000
        DRM_ERROR("Fifo reserve failed.\n");
1001
        return;
1002
    }
1003
 
1004
    cmd->header = cpu_to_le32(SVGA_CMD_UPDATE);
1005
    cmd->body.x = 0;
1006
    cmd->body.y = 0;
1007
    cmd->body.width  = os_display->width; //cpu_to_le32(clips->x2 - clips->x1);
1008
    cmd->body.height = os_display->height; //cpu_to_le32(clips->y2 - clips->y1);
1009
 
1010
    vmw_fifo_commit(dev_priv, fifo_size);
1011
}
1012
 
1013
int get_videomodes(videomode_t *mode, int *count)
1014
{
1015
    int err = -1;
1016
 
1017
    dbgprintf("mode %x count %d\n", mode, *count);
1018
 
1019
    if( *count == 0 )
1020
    {
1021
        *count = os_display->supported_modes;
1022
        err = 0;
1023
    }
1024
    else if( mode != NULL )
1025
    {
1026
        struct drm_display_mode  *drmmode;
1027
        int i = 0;
1028
 
1029
        if( *count > os_display->supported_modes)
1030
            *count = os_display->supported_modes;
1031
 
1032
        list_for_each_entry(drmmode, &os_display->connector->modes, head)
1033
        {
1034
            if( i < *count)
1035
            {
1036
                mode->width  = drm_mode_width(drmmode);
1037
                mode->height = drm_mode_height(drmmode);
1038
                mode->bpp    = 32;
1039
                mode->freq   = drm_mode_vrefresh(drmmode);
1040
                i++;
1041
                mode++;
1042
            }
1043
            else break;
1044
        };
1045
        *count = i;
1046
        err = 0;
1047
    };
1048
    return err;
1049
};
1050
 
1051
 
1052
bool set_mode(struct drm_device *dev, struct drm_connector *connector,
1053
              videomode_t *reqmode, bool strict);
1054
 
1055
 
1056
int set_user_mode(videomode_t *mode)
1057
{
1058
    int err = -1;
1059
 
1060
    dbgprintf("width %d height %d vrefresh %d\n",
1061
               mode->width, mode->height, mode->freq);
1062
 
1063
    if( (mode->width  != 0)  &&
1064
        (mode->height != 0)  &&
1065
        (mode->freq   != 0 ) &&
1066
        ( (mode->width   != os_display->width)  ||
1067
          (mode->height  != os_display->height) ||
1068
          (mode->freq    != os_display->vrefresh) ) )
1069
    {
1070
        if( set_mode(os_display->ddev, os_display->connector, mode, true) )
1071
            err = 0;
1072
    };
1073
 
1074
    return err;
1075
};
1076
 
4111 Serge 1077
struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags)
1078
{
1079
    struct file *filep;
1080
    int count;
1081
 
1082
    filep = malloc(sizeof(*filep));
1083
 
1084
    if(unlikely(filep == NULL))
1085
        return ERR_PTR(-ENOMEM);
1086
 
1087
    count = size / PAGE_SIZE;
1088
 
1089
    filep->pages = kzalloc(sizeof(struct page *) * count, 0);
1090
    if(unlikely(filep->pages == NULL))
1091
    {
1092
        kfree(filep);
1093
        return ERR_PTR(-ENOMEM);
1094
    };
1095
 
1096
    filep->count     = count;
1097
    filep->allocated = 0;
1098
    filep->vma       = NULL;
1099
 
1100
//    printf("%s file %p pages %p count %d\n",
1101
//              __FUNCTION__,filep, filep->pages, count);
1102
 
1103
    return filep;
1104
}
1105
 
1106
struct page *shmem_read_mapping_page_gfp(struct file *filep,
1107
                                         pgoff_t index, gfp_t gfp)
1108
{
1109
    struct page *page;
1110
 
1111
//    dbgprintf("%s, file %p index %d\n", __FUNCTION__, filep, index);
1112
 
1113
    if(unlikely(index >= filep->count))
1114
        return ERR_PTR(-EINVAL);
1115
 
1116
    page = filep->pages[index];
1117
 
1118
    if(unlikely(page == NULL))
1119
    {
1120
        page = (struct page *)AllocPage();
1121
 
1122
        if(unlikely(page == NULL))
1123
            return ERR_PTR(-ENOMEM);
1124
 
1125
        filep->pages[index] = page;
1126
    };
1127
 
1128
    return page;
1129
};
1130