Subversion Repositories Kolibri OS

Rev

Rev 5078 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5078 Rev 6296
Line -... Line 1...
-
 
1
#include 
-
 
2
 
1
#include 
3
#include 
2
#include 
-
 
Line 3... Line 4...
3
 
4
 
4
#include 
5
#include 
5
#include 
-
 
6
 
-
 
7
#include "vmwgfx_drv.h"
-
 
8
 
6
#include 
9
#include 
-
 
10
#include 
7
#include 
11
#include 
-
 
Line 12... Line 8...
12
#include 
8
#include 
Line 13... Line 9...
13
 
9
 
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;
-
 
Line -... Line 10...
-
 
10
#include "vmwgfx_drv.h"
-
 
11
 
-
 
12
#include 
-
 
13
 
-
 
14
#define VMW_DEV_CLOSE 0
-
 
15
#define VMW_DEV_INIT  1
-
 
16
#define VMW_DEV_READY 2
-
 
17
void cpu_detect1();
-
 
18
int kmap_init();
-
 
19
 
-
 
20
unsigned long volatile jiffies;
-
 
21
int oops_in_progress;
25
    uint32_t    device_class;
22
int x86_clflush_size;
26
    uint8_t     revision;
23
unsigned int tsc_khz;
-
 
24
struct workqueue_struct *system_wq;
-
 
25
int driver_wq_state;
Line 27... Line 26...
27
};
26
struct drm_device *main_device;
28
 
27
struct drm_file   *drm_file_handlers[256];
29
struct drm_device *main_device;
28
int kms_modeset = 1;
30
struct drm_file   *drm_file_handlers[256];
-
 
31
 
-
 
Line 32... Line 29...
32
int vmw_init(void);
29
static char  log[256];
33
int kms_init(struct drm_device *dev);
30
 
-
 
31
int vmw_init(void);
-
 
32
int kms_init(struct drm_device *dev);
Line 34... Line -...
34
void vmw_driver_thread();
-
 
35
void kms_update();
-
 
36
void cpu_detect();
33
void vmw_driver_thread();
Line -... Line 34...
-
 
34
 
-
 
35
void parse_cmdline(char *cmdline, char *log);
37
 
36
int _stdcall display_handler(ioctl_t *io);
38
void parse_cmdline(char *cmdline, char *log);
37
void kms_update();
-
 
38
void vmw_fb_update(struct vmw_private *vmw_priv);
Line -... Line 39...
-
 
39
 
Line -... Line 40...
-
 
40
int gem_getparam(struct drm_device *dev, void *data);
-
 
41
 
-
 
42
void vmw_driver_thread()
39
int _stdcall display_handler(ioctl_t *io);
43
{
-
 
44
	struct vmw_private *dev_priv = NULL;
Line 40... Line 45...
40
 
45
    struct workqueue_struct *cwq = NULL;
-
 
46
    unsigned long irqflags;
41
 
47
 
-
 
48
    printf("%s\n",__FUNCTION__);
Line 42... Line 49...
42
void get_pci_info(struct pci_device *dev);
49
 
43
int gem_getparam(struct drm_device *dev, void *data);
50
    while(driver_wq_state == VMW_DEV_INIT)
Line -... Line 51...
-
 
51
    {
-
 
52
        jiffies = GetClockNs() / 10000000;
-
 
53
        delay(1);
-
 
54
    };
44
 
55
 
Line -... Line 56...
-
 
56
    if( driver_wq_state == VMW_DEV_CLOSE)
45
int i915_mask_update(struct drm_device *dev, void *data,
57
    {
46
            struct drm_file *file);
58
        asm volatile ("int $0x40"::"a"(-1));
-
 
59
    };
-
 
60
 
-
 
61
    dev_priv = main_device->dev_private;
-
 
62
    cwq = system_wq;
-
 
63
 
-
 
64
    while(driver_wq_state != VMW_DEV_CLOSE )
-
 
65
    {
-
 
66
        jiffies = GetClockNs() / 10000000;
-
 
67
 
-
 
68
 //       kms_update();
Line -... Line 69...
-
 
69
 
-
 
70
        spin_lock_irqsave(&cwq->lock, irqflags);
-
 
71
        while (!list_empty(&cwq->worklist))
-
 
72
        {
-
 
73
            struct work_struct *work = list_entry(cwq->worklist.next,
-
 
74
                                        struct work_struct, entry);
-
 
75
            work_func_t f = work->func;
-
 
76
            list_del_init(cwq->worklist.next);
-
 
77
 
-
 
78
            spin_unlock_irqrestore(&cwq->lock, irqflags);
-
 
79
            f(work);
-
 
80
            spin_lock_irqsave(&cwq->lock, irqflags);
47
 
81
        }
Line 48... Line 82...
48
 
82
        spin_unlock_irqrestore(&cwq->lock, irqflags);
49
static char  log[256];
83
 
50
 
84
        vmw_fb_update(dev_priv);
51
struct workqueue_struct *system_wq;
85
        delay(2);
52
int driver_wq_state;
86
    };
Line 53... Line 87...
53
 
87
 
54
int x86_clflush_size;
88
    asm volatile ("int $0x40"::"a"(-1));
Line 77... Line 111...
77
    {
111
    {
78
            printf("Can't open %s\nExit\n", log);
112
            printf("Can't open %s\nExit\n", log);
79
            return 0;
113
            return 0;
80
    }
114
    }
Line 81... Line 115...
81
 
115
 
Line 82... Line 116...
82
    dbgprintf(" vmw v3.14-rc1\n cmdline: %s\n", cmdline);
116
    cpu_detect1();
-
 
117
 
-
 
118
    err = enum_pci_devices();
83
 
119
    if( unlikely(err != 0) )
-
 
120
    {
-
 
121
        dbgprintf("Device enumeration failed\n");
Line 84... Line 122...
84
    cpu_detect();
122
        return 0;
-
 
123
    }
-
 
124
 
-
 
125
    err = kmap_init();
-
 
126
    if( unlikely(err != 0) )
-
 
127
    {
Line -... Line 128...
-
 
128
        dbgprintf("kmap initialization failed\n");
-
 
129
        return 0;
85
    dbgprintf("\ncache line size %d\n", x86_clflush_size);
130
    }
86
 
131
 
87
    enum_pci_devices();
132
    driver_wq_state = VMW_DEV_INIT;
-
 
133
    CreateKernelThread(vmw_driver_thread);
88
 
134
    err = vmw_init();
-
 
135
    if(unlikely(err!= 0))
89
    err = vmw_init();
136
    {
90
    if(err)
137
        driver_wq_state = VMW_DEV_CLOSE;
-
 
138
        dbgprintf("Epic Fail :(\n");
-
 
139
        delay(100);
-
 
140
        return 0;
-
 
141
    };
91
    {
142
LINE();
Line 92... Line 143...
92
        dbgprintf("Epic Fail :(\n");
143
 
Line 93... Line 144...
93
        return 0;
144
    driver_wq_state = VMW_DEV_READY;
94
    };
145
 
Line 95... Line -...
95
    kms_init(main_device);
-
 
Line 96... Line -...
96
 
-
 
Line 97... Line 146...
97
    err = RegService("DISPLAY", display_handler);
146
//    kms_init(main_device);
98
 
147
 
Line 99... Line -...
99
    if( err != 0)
-
 
100
        dbgprintf("Set DISPLAY handler\n");
148
    err = RegService("DISPLAY", display_handler);
101
 
149
 
Line 102... Line 150...
102
    driver_wq_state = 1;
150
    if( err != 0)
103
 
151
        dbgprintf("Set DISPLAY handler\n");
Line 116... Line 164...
116
 
164
 
117
#define SRV_GETVERSION          0
165
#define SRV_GETVERSION          0
118
#define SRV_ENUM_MODES          1
166
#define SRV_ENUM_MODES          1
119
#define SRV_SET_MODE            2
167
#define SRV_SET_MODE            2
120
#define SRV_GET_CAPS            3
-
 
121
 
-
 
122
#define SRV_CREATE_SURFACE      10
-
 
123
#define SRV_DESTROY_SURFACE     11
-
 
124
#define SRV_LOCK_SURFACE        12
-
 
125
#define SRV_UNLOCK_SURFACE      13
-
 
126
#define SRV_RESIZE_SURFACE      14
-
 
127
#define SRV_BLIT_BITMAP         15
-
 
128
#define SRV_BLIT_TEXTURE        16
168
#define SRV_GET_CAPS            3
129
#define SRV_BLIT_VIDEO          17
-
 
Line 130... Line 169...
130
 
169
#define SRV_CMDLINE                 4
131
 
-
 
132
#define SRV_GET_PCI_INFO            20
-
 
133
#define SRV_GET_PARAM               21
-
 
134
#define SRV_I915_GEM_CREATE         22
-
 
135
#define SRV_DRM_GEM_CLOSE           23
-
 
136
#define SRV_I915_GEM_PIN            24
-
 
137
#define SRV_I915_GEM_SET_CACHEING   25
-
 
138
#define SRV_I915_GEM_GET_APERTURE   26
-
 
139
#define SRV_I915_GEM_PWRITE         27
-
 
140
#define SRV_I915_GEM_BUSY           28
-
 
141
#define SRV_I915_GEM_SET_DOMAIN     29
-
 
142
#define SRV_I915_GEM_MMAP           30
-
 
143
#define SRV_I915_GEM_MMAP_GTT       31
-
 
144
#define SRV_I915_GEM_THROTTLE       32
-
 
145
#define SRV_FBINFO                  33
-
 
146
#define SRV_I915_GEM_EXECBUFFER2    34
-
 
147
#define SRV_MASK_UPDATE             35
-
 
Line 148... Line 170...
148
 
170
 
149
 
171
#define SRV_GET_PCI_INFO            20
150
 
172
 
Line 159... Line 181...
159
int _stdcall display_handler(ioctl_t *io)
181
int _stdcall display_handler(ioctl_t *io)
160
{
182
{
161
    struct drm_file *file;
183
    struct drm_file *file;
Line 162... Line 184...
162
 
184
 
163
    int    retval = -1;
185
    int    retval = -1;
164
    u32_t *inp;
186
    u32 *inp;
Line 165... Line 187...
165
    u32_t *outp;
187
    u32 *outp;
166
 
188
 
Line 167... Line 189...
167
    inp = io->input;
189
    inp = io->input;
Line 197... Line 219...
197
#if 0
219
#if 0
198
        case SRV_GET_CAPS:
220
        case SRV_GET_CAPS:
199
            retval = get_driver_caps((hwcaps_t*)inp);
221
            retval = get_driver_caps((hwcaps_t*)inp);
200
            break;
222
            break;
Line 201... Line -...
201
 
-
 
202
        case SRV_CREATE_SURFACE:
-
 
203
//            check_input(8);
-
 
204
//            retval = create_surface(main_device, (struct io_call_10*)inp);
-
 
205
            break;
-
 
206
 
-
 
207
        case SRV_LOCK_SURFACE:
-
 
208
//            retval = lock_surface((struct io_call_12*)inp);
-
 
209
            break;
-
 
210
 
-
 
211
        case SRV_RESIZE_SURFACE:
-
 
212
//            retval = resize_surface((struct io_call_14*)inp);
-
 
213
            break;
-
 
214
 
-
 
215
        case SRV_BLIT_BITMAP:
-
 
216
//            srv_blit_bitmap( inp[0], inp[1], inp[2],
-
 
217
//                        inp[3], inp[4], inp[5], inp[6]);
-
 
218
 
-
 
219
//            blit_tex( inp[0], inp[1], inp[2],
-
 
220
//                    inp[3], inp[4], inp[5], inp[6]);
-
 
221
 
-
 
Line 222... Line 223...
222
            break;
223
 
223
 
224
 
224
        case SRV_GET_PCI_INFO:
225
        case SRV_GET_PCI_INFO:
225
            get_pci_info((struct pci_device *)inp);
226
            get_pci_info((struct pci_device *)inp);
Line 297... Line 298...
297
#define PCI_CLASS_REVISION      0x08
298
#define PCI_CLASS_REVISION      0x08
298
#define PCI_CLASS_DISPLAY_VGA   0x0300
299
#define PCI_CLASS_DISPLAY_VGA   0x0300
299
#define PCI_CLASS_BRIDGE_HOST   0x0600
300
#define PCI_CLASS_BRIDGE_HOST   0x0600
300
#define PCI_CLASS_BRIDGE_ISA    0x0601
301
#define PCI_CLASS_BRIDGE_ISA    0x0601
Line 301... Line 302...
301
 
302
 
302
int pci_scan_filter(u32_t id, u32_t busnr, u32_t devfn)
303
int pci_scan_filter(u32 id, u32 busnr, u32 devfn)
303
{
304
{
304
    u16_t vendor, device;
305
    u16 vendor, device;
305
    u32_t class;
306
    u32 class;
Line 306... Line 307...
306
    int   ret = 0;
307
    int   ret = 0;
307
 
308
 
Line 351... Line 352...
351
        };
352
        };
352
        c = *p++;
353
        c = *p++;
353
    };
354
    };
354
};
355
};
Line 355... Line -...
355
 
-
 
356
 
-
 
357
static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
356
 
358
                unsigned int *ecx, unsigned int *edx)
357
struct mtrr
359
{
-
 
360
    /* ecx is often an input as well as an output. */
-
 
361
    asm volatile("cpuid"
-
 
362
        : "=a" (*eax),
358
{
363
          "=b" (*ebx),
-
 
364
          "=c" (*ecx),
-
 
365
          "=d" (*edx)
-
 
366
        : "0" (*eax), "2" (*ecx)
359
    u64  base;
367
        : "memory");
360
    u64  mask;
Line -... Line 361...
-
 
361
};
-
 
362
 
-
 
363
struct cpuinfo
-
 
364
{
-
 
365
    u64  caps;
-
 
366
    u64  def_mtrr;
-
 
367
    u64  mtrr_cap;
-
 
368
    int    var_mtrr_count;
-
 
369
    int    fix_mtrr_count;
-
 
370
    struct mtrr var_mtrr[9];
Line -... Line 371...
-
 
371
    char   model_name[64];
Line 368... Line 372...
368
}
372
};
369
 
-
 
370
 
-
 
371
 
373
 
372
static inline void cpuid(unsigned int op,
374
static u32 deftype_lo, deftype_hi;
373
                         unsigned int *eax, unsigned int *ebx,
-
 
374
                         unsigned int *ecx, unsigned int *edx)
-
 
375
{
-
 
Line 376... Line -...
376
        *eax = op;
-
 
377
        *ecx = 0;
-
 
378
        __cpuid(eax, ebx, ecx, edx);
375
 
-
 
376
void cpu_detect1()
Line 379... Line 377...
379
}
377
{
Line 380... Line 378...
380
 
378
    struct cpuinfo cpuinfo;
381
void cpu_detect()
379
 
Line 437... Line 435...
437
#include 
435
#include 
438
#include 
436
#include 
439
#include 
437
#include 
Line 440... Line -...
440
 
-
 
441
 
-
 
442
static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes)
-
 
443
{
-
 
444
        while (bytes) {
-
 
445
                if (*start != value)
-
 
446
                        return (void *)start;
-
 
447
                start++;
-
 
448
                bytes--;
-
 
449
        }
-
 
450
        return NULL;
-
 
451
}
-
 
452
 
-
 
453
/**
-
 
454
 * memchr_inv - Find an unmatching character in an area of memory.
-
 
455
 * @start: The memory area
-
 
456
 * @c: Find a character other than c
-
 
457
 * @bytes: The size of the area.
-
 
458
 *
-
 
459
 * returns the address of the first character other than @c, or %NULL
-
 
460
 * if the whole buffer contains just @c.
-
 
461
 */
-
 
462
void *memchr_inv(const void *start, int c, size_t bytes)
-
 
463
{
-
 
464
        u8 value = c;
-
 
465
        u64 value64;
-
 
466
        unsigned int words, prefix;
-
 
467
 
-
 
468
        if (bytes <= 16)
-
 
469
                return check_bytes8(start, value, bytes);
-
 
470
 
-
 
471
        value64 = value;
-
 
472
#if defined(ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64
-
 
473
        value64 *= 0x0101010101010101;
-
 
474
#elif defined(ARCH_HAS_FAST_MULTIPLIER)
-
 
475
        value64 *= 0x01010101;
-
 
476
        value64 |= value64 << 32;
-
 
477
#else
-
 
478
        value64 |= value64 << 8;
-
 
479
        value64 |= value64 << 16;
-
 
480
        value64 |= value64 << 32;
-
 
481
#endif
-
 
482
 
-
 
483
        prefix = (unsigned long)start % 8;
-
 
484
        if (prefix) {
-
 
485
                u8 *r;
-
 
486
 
-
 
487
                prefix = 8 - prefix;
-
 
488
                r = check_bytes8(start, value, prefix);
-
 
489
                if (r)
-
 
490
                        return r;
-
 
491
                start += prefix;
-
 
492
                bytes -= prefix;
-
 
493
        }
-
 
494
 
-
 
495
        words = bytes / 8;
-
 
496
 
-
 
497
        while (words) {
-
 
498
                if (*(u64 *)start != value64)
-
 
499
                        return check_bytes8(start, value, 8);
-
 
500
                start += 8;
-
 
501
                words--;
-
 
502
        }
-
 
503
 
-
 
504
        return check_bytes8(start, value, bytes % 8);
-
 
505
}
-
 
506
 
-
 
507
int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
-
 
508
{
-
 
509
    int i;
-
 
510
 
-
 
511
    i = vsnprintf(buf, size, fmt, args);
-
 
512
 
-
 
513
    if (likely(i < size))
-
 
514
            return i;
-
 
515
    if (size != 0)
-
 
516
            return size - 1;
-
 
517
    return 0;
-
 
518
}
-
 
519
 
-
 
520
 
-
 
521
int scnprintf(char *buf, size_t size, const char *fmt, ...)
-
 
522
{
-
 
523
        va_list args;
-
 
524
        int i;
-
 
525
 
-
 
526
        va_start(args, fmt);
-
 
527
        i = vscnprintf(buf, size, fmt, args);
-
 
528
        va_end(args);
-
 
529
 
-
 
530
        return i;
-
 
531
}
-
 
532
 
-
 
533
 
-
 
534
 
-
 
535
#define _U  0x01    /* upper */
-
 
536
#define _L  0x02    /* lower */
-
 
537
#define _D  0x04    /* digit */
-
 
538
#define _C  0x08    /* cntrl */
-
 
539
#define _P  0x10    /* punct */
-
 
540
#define _S  0x20    /* white space (space/lf/tab) */
-
 
541
#define _X  0x40    /* hex digit */
-
 
542
#define _SP 0x80    /* hard space (0x20) */
-
 
543
 
-
 
544
extern const unsigned char _ctype[];
-
 
545
 
-
 
546
#define __ismask(x) (_ctype[(int)(unsigned char)(x)])
-
 
547
 
-
 
548
#define isalnum(c)  ((__ismask(c)&(_U|_L|_D)) != 0)
-
 
549
#define isalpha(c)  ((__ismask(c)&(_U|_L)) != 0)
-
 
550
#define iscntrl(c)  ((__ismask(c)&(_C)) != 0)
-
 
551
#define isdigit(c)  ((__ismask(c)&(_D)) != 0)
-
 
552
#define isgraph(c)  ((__ismask(c)&(_P|_U|_L|_D)) != 0)
-
 
553
#define islower(c)  ((__ismask(c)&(_L)) != 0)
-
 
554
#define isprint(c)  ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0)
-
 
555
#define ispunct(c)  ((__ismask(c)&(_P)) != 0)
-
 
556
/* Note: isspace() must return false for %NUL-terminator */
-
 
557
#define isspace(c)  ((__ismask(c)&(_S)) != 0)
-
 
558
#define isupper(c)  ((__ismask(c)&(_U)) != 0)
-
 
559
#define isxdigit(c) ((__ismask(c)&(_D|_X)) != 0)
-
 
560
 
-
 
561
#define isascii(c) (((unsigned char)(c))<=0x7f)
-
 
562
#define toascii(c) (((unsigned char)(c))&0x7f)
-
 
563
 
-
 
564
 
-
 
565
 
-
 
566
//const char hex_asc[] = "0123456789abcdef";
-
 
567
 
-
 
568
/**
-
 
569
 * hex_to_bin - convert a hex digit to its real value
-
 
570
 * @ch: ascii character represents hex digit
-
 
571
 *
-
 
572
 * hex_to_bin() converts one hex digit to its actual value or -1 in case of bad
-
 
573
 * input.
-
 
574
 */
-
 
575
int hex_to_bin(char ch)
-
 
576
{
-
 
577
    if ((ch >= '0') && (ch <= '9'))
-
 
578
        return ch - '0';
-
 
579
    ch = tolower(ch);
-
 
580
    if ((ch >= 'a') && (ch <= 'f'))
-
 
581
        return ch - 'a' + 10;
-
 
582
    return -1;
-
 
583
}
-
 
584
EXPORT_SYMBOL(hex_to_bin);
-
 
585
 
-
 
586
/**
-
 
587
 * hex2bin - convert an ascii hexadecimal string to its binary representation
-
 
588
 * @dst: binary result
-
 
589
 * @src: ascii hexadecimal string
-
 
590
 * @count: result length
-
 
591
 *
-
 
592
 * Return 0 on success, -1 in case of bad input.
-
 
593
 */
-
 
594
int hex2bin(u8 *dst, const char *src, size_t count)
-
 
595
{
-
 
596
    while (count--) {
-
 
597
        int hi = hex_to_bin(*src++);
-
 
598
        int lo = hex_to_bin(*src++);
-
 
599
 
-
 
600
        if ((hi < 0) || (lo < 0))
-
 
601
            return -1;
-
 
602
 
-
 
603
        *dst++ = (hi << 4) | lo;
-
 
604
    }
-
 
605
    return 0;
-
 
606
}
-
 
607
EXPORT_SYMBOL(hex2bin);
-
 
608
 
-
 
609
/**
-
 
610
 * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory
-
 
611
 * @buf: data blob to dump
-
 
612
 * @len: number of bytes in the @buf
-
 
613
 * @rowsize: number of bytes to print per line; must be 16 or 32
-
 
614
 * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1)
-
 
615
 * @linebuf: where to put the converted data
-
 
616
 * @linebuflen: total size of @linebuf, including space for terminating NUL
-
 
617
 * @ascii: include ASCII after the hex output
-
 
618
 *
-
 
619
 * hex_dump_to_buffer() works on one "line" of output at a time, i.e.,
-
 
620
 * 16 or 32 bytes of input data converted to hex + ASCII output.
-
 
621
 *
-
 
622
 * Given a buffer of u8 data, hex_dump_to_buffer() converts the input data
-
 
623
 * to a hex + ASCII dump at the supplied memory location.
-
 
624
 * The converted output is always NUL-terminated.
-
 
625
 *
-
 
626
 * E.g.:
-
 
627
 *   hex_dump_to_buffer(frame->data, frame->len, 16, 1,
-
 
628
 *          linebuf, sizeof(linebuf), true);
-
 
629
 *
-
 
630
 * example output buffer:
-
 
631
 * 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f  @ABCDEFGHIJKLMNO
-
 
632
 */
-
 
633
void hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
-
 
634
            int groupsize, char *linebuf, size_t linebuflen,
-
 
635
            bool ascii)
-
 
636
{
-
 
637
    const u8 *ptr = buf;
-
 
638
    u8 ch;
-
 
639
    int j, lx = 0;
-
 
640
    int ascii_column;
-
 
641
 
-
 
642
    if (rowsize != 16 && rowsize != 32)
-
 
643
        rowsize = 16;
-
 
644
 
-
 
645
    if (!len)
-
 
646
        goto nil;
-
 
647
    if (len > rowsize)      /* limit to one line at a time */
-
 
648
        len = rowsize;
-
 
649
    if ((len % groupsize) != 0) /* no mixed size output */
-
 
650
        groupsize = 1;
-
 
651
 
-
 
652
    switch (groupsize) {
-
 
653
    case 8: {
-
 
654
        const u64 *ptr8 = buf;
-
 
655
        int ngroups = len / groupsize;
-
 
656
 
-
 
657
        for (j = 0; j < ngroups; j++)
-
 
658
            lx += scnprintf(linebuf + lx, linebuflen - lx,
-
 
659
                    "%s%16.16llx", j ? " " : "",
-
 
660
                    (unsigned long long)*(ptr8 + j));
-
 
661
        ascii_column = 17 * ngroups + 2;
-
 
662
        break;
-
 
663
    }
-
 
664
 
-
 
665
    case 4: {
-
 
666
        const u32 *ptr4 = buf;
-
 
667
        int ngroups = len / groupsize;
-
 
668
 
-
 
669
        for (j = 0; j < ngroups; j++)
-
 
670
            lx += scnprintf(linebuf + lx, linebuflen - lx,
-
 
671
                    "%s%8.8x", j ? " " : "", *(ptr4 + j));
-
 
672
        ascii_column = 9 * ngroups + 2;
-
 
673
        break;
-
 
674
    }
-
 
675
 
-
 
676
    case 2: {
-
 
677
        const u16 *ptr2 = buf;
-
 
678
        int ngroups = len / groupsize;
-
 
679
 
-
 
680
        for (j = 0; j < ngroups; j++)
-
 
681
            lx += scnprintf(linebuf + lx, linebuflen - lx,
-
 
682
                    "%s%4.4x", j ? " " : "", *(ptr2 + j));
-
 
683
        ascii_column = 5 * ngroups + 2;
-
 
684
        break;
-
 
685
    }
-
 
686
 
-
 
687
    default:
-
 
688
        for (j = 0; (j < len) && (lx + 3) <= linebuflen; j++) {
-
 
689
            ch = ptr[j];
-
 
690
            linebuf[lx++] = hex_asc_hi(ch);
-
 
691
            linebuf[lx++] = hex_asc_lo(ch);
-
 
692
            linebuf[lx++] = ' ';
-
 
693
        }
-
 
694
        if (j)
-
 
695
            lx--;
-
 
696
 
-
 
697
        ascii_column = 3 * rowsize + 2;
-
 
698
        break;
-
 
699
    }
-
 
700
    if (!ascii)
-
 
701
        goto nil;
-
 
702
 
-
 
703
    while (lx < (linebuflen - 1) && lx < (ascii_column - 1))
-
 
704
        linebuf[lx++] = ' ';
-
 
705
    for (j = 0; (j < len) && (lx + 2) < linebuflen; j++) {
-
 
706
        ch = ptr[j];
-
 
707
        linebuf[lx++] = (isascii(ch) && isprint(ch)) ? ch : '.';
-
 
708
    }
-
 
709
nil:
-
 
710
    linebuf[lx++] = '\0';
-
 
711
}
-
 
712
 
-
 
713
/**
-
 
714
 * print_hex_dump - print a text hex dump to syslog for a binary blob of data
-
 
715
 * @level: kernel log level (e.g. KERN_DEBUG)
-
 
716
 * @prefix_str: string to prefix each line with;
-
 
717
 *  caller supplies trailing spaces for alignment if desired
-
 
718
 * @prefix_type: controls whether prefix of an offset, address, or none
-
 
719
 *  is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE)
-
 
720
 * @rowsize: number of bytes to print per line; must be 16 or 32
-
 
721
 * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1)
-
 
722
 * @buf: data blob to dump
-
 
723
 * @len: number of bytes in the @buf
-
 
724
 * @ascii: include ASCII after the hex output
-
 
725
 *
-
 
726
 * Given a buffer of u8 data, print_hex_dump() prints a hex + ASCII dump
-
 
727
 * to the kernel log at the specified kernel log level, with an optional
-
 
728
 * leading prefix.
-
 
729
 *
-
 
730
 * print_hex_dump() works on one "line" of output at a time, i.e.,
-
 
731
 * 16 or 32 bytes of input data converted to hex + ASCII output.
-
 
732
 * print_hex_dump() iterates over the entire input @buf, breaking it into
-
 
733
 * "line size" chunks to format and print.
-
 
734
 *
-
 
735
 * E.g.:
-
 
736
 *   print_hex_dump(KERN_DEBUG, "raw data: ", DUMP_PREFIX_ADDRESS,
-
 
737
 *          16, 1, frame->data, frame->len, true);
-
 
738
 *
-
 
739
 * Example output using %DUMP_PREFIX_OFFSET and 1-byte mode:
-
 
740
 * 0009ab42: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f  @ABCDEFGHIJKLMNO
-
 
741
 * Example output using %DUMP_PREFIX_ADDRESS and 4-byte mode:
-
 
742
 * ffffffff88089af0: 73727170 77767574 7b7a7978 7f7e7d7c  pqrstuvwxyz{|}~.
-
 
743
 */
-
 
744
void print_hex_dump(const char *level, const char *prefix_str, int prefix_type,
-
 
745
            int rowsize, int groupsize,
-
 
746
            const void *buf, size_t len, bool ascii)
-
 
747
{
-
 
748
    const u8 *ptr = buf;
-
 
749
    int i, linelen, remaining = len;
-
 
750
    unsigned char linebuf[32 * 3 + 2 + 32 + 1];
-
 
751
 
-
 
752
    if (rowsize != 16 && rowsize != 32)
-
 
753
        rowsize = 16;
-
 
754
 
-
 
755
    for (i = 0; i < len; i += rowsize) {
-
 
756
        linelen = min(remaining, rowsize);
-
 
757
        remaining -= rowsize;
-
 
758
 
-
 
759
        hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize,
-
 
760
                   linebuf, sizeof(linebuf), ascii);
-
 
761
 
-
 
762
        switch (prefix_type) {
-
 
763
        case DUMP_PREFIX_ADDRESS:
-
 
764
            printk("%s%s%p: %s\n",
-
 
765
                   level, prefix_str, ptr + i, linebuf);
-
 
766
            break;
-
 
767
        case DUMP_PREFIX_OFFSET:
-
 
768
            printk("%s%s%.8x: %s\n", level, prefix_str, i, linebuf);
-
 
769
            break;
-
 
770
        default:
-
 
771
            printk("%s%s%s\n", level, prefix_str, linebuf);
-
 
772
            break;
-
 
773
        }
-
 
774
    }
-
 
775
}
-
 
776
 
-
 
777
void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
-
 
778
                          const void *buf, size_t len)
-
 
779
{
-
 
780
    print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, 16, 1,
-
 
781
                       buf, len, true);
-
 
782
}
-
 
783
 
-
 
784
 
-
 
785
 
-
 
786
 
-
 
787
 
-
 
Line 788... Line 438...
788
 
438
 
Line 789... Line 439...
789
 
439
 
Line 790... Line 440...
790
 
440
 
Line 791... Line -...
791
 
-
 
792
#include "vmwgfx_kms.h"
-
 
793
 
-
 
794
void kms_update();
-
 
795
 
-
 
796
 
-
 
797
extern struct drm_device *main_device;
-
 
798
 
-
 
799
typedef struct
-
 
800
{
-
 
801
    kobj_t     header;
-
 
802
 
-
 
803
    uint32_t  *data;
441
 
804
    uint32_t   hot_x;
442
#include "vmwgfx_kms.h"
Line 805... Line -...
805
    uint32_t   hot_y;
-
 
806
 
-
 
807
    struct list_head   list;
-
 
808
    void      *priv;
-
 
809
}cursor_t;
-
 
810
 
-
 
811
#define CURSOR_WIDTH 64
-
 
812
#define CURSOR_HEIGHT 64
-
 
813
 
-
 
814
struct tag_display
-
 
815
{
-
 
816
    int  x;
-
 
817
    int  y;
-
 
818
    int  width;
-
 
819
    int  height;
-
 
820
    int  bpp;
-
 
821
    int  vrefresh;
-
 
822
    int  pitch;
-
 
823
    int  lfb;
-
 
824
 
-
 
825
    int  supported_modes;
-
 
826
    struct drm_device    *ddev;
-
 
827
    struct drm_connector *connector;
-
 
828
    struct drm_crtc      *crtc;
-
 
829
 
-
 
830
    struct list_head   cursors;
-
 
831
 
-
 
832
    cursor_t   *cursor;
-
 
833
    int       (*init_cursor)(cursor_t*);
-
 
Line 834... Line 443...
834
    cursor_t* (__stdcall *select_cursor)(cursor_t*);
443
 
Line 835... Line 444...
835
    void      (*show_cursor)(int show);
444
void kms_update();
836
    void      (__stdcall *move_cursor)(cursor_t *cursor, int x, int y);
445
 
Line 883... Line 492...
883
    vmw_cursor_update_position(dev_priv, true,
492
    vmw_cursor_update_position(dev_priv, true,
884
                   du->cursor_x, du->cursor_y);
493
                   du->cursor_x, du->cursor_y);
885
    return old;
494
    return old;
886
};
495
};
Line 887... Line -...
887
 
-
 
888
void vmw_driver_thread()
-
 
889
{
-
 
890
    DRM_DEBUG_KMS("%s\n",__FUNCTION__);
-
 
891
 
-
 
892
    select_cursor_kms(os_display->cursor);
-
 
893
 
-
 
894
    while(driver_wq_state)
-
 
895
    {
-
 
896
        kms_update();
-
 
897
        delay(2);
-
 
898
    };
-
 
899
     __asm__ __volatile__ (
-
 
900
     "int $0x40"
-
 
901
     ::"a"(-1));
-
 
902
}
-
 
903
 
496
 
904
int kms_init(struct drm_device *dev)
497
int kms_init(struct drm_device *dev)
905
{
498
{
906
    struct drm_connector    *connector;
499
    struct drm_connector    *connector;
907
    struct drm_encoder      *encoder;
500
    struct drm_encoder      *encoder;
908
    struct drm_crtc         *crtc = NULL;
501
    struct drm_crtc         *crtc = NULL;
909
    struct vmw_display_unit *du;
502
    struct vmw_display_unit *du;
910
    cursor_t  *cursor;
503
    cursor_t  *cursor;
911
    int        mode_count;
504
    int        mode_count;
912
    u32_t      ifl;
505
    u32        ifl;
Line 913... Line 506...
913
    int        err;
506
    int        err;
914
 
507
 
915
    crtc = list_entry(dev->mode_config.crtc_list.next, typeof(*crtc), head);
508
    crtc = list_entry(dev->mode_config.crtc_list.next, typeof(*crtc), head);
Line 964... Line 557...
964
 
557
 
965
void kms_update()
558
void kms_update()
966
{
559
{
967
    struct vmw_private *dev_priv = vmw_priv(main_device);
560
    struct vmw_private *dev_priv = vmw_priv(main_device);
968
    size_t fifo_size;
561
    size_t fifo_size;
969
    u32_t  ifl;
562
    u32    ifl;
Line 970... Line 563...
970
    int i;
563
    int i;
971
 
564
 
972
    struct {
565
    struct {
Line 979... Line 572...
979
    cmd = vmw_fifo_reserve(dev_priv, fifo_size);
572
    cmd = vmw_fifo_reserve(dev_priv, fifo_size);
980
    if (unlikely(cmd == NULL)) {
573
    if (unlikely(cmd == NULL)) {
981
        DRM_ERROR("Fifo reserve failed.\n");
574
        DRM_ERROR("Fifo reserve failed.\n");
982
        return;
575
        return;
983
    }
576
    }
984
 
-
 
-
 
577
    os_display = GetDisplay();
985
    cmd->header = cpu_to_le32(SVGA_CMD_UPDATE);
578
    cmd->header = cpu_to_le32(SVGA_CMD_UPDATE);
986
    cmd->body.x = 0;
579
    cmd->body.x = 0;
987
    cmd->body.y = 0;
580
    cmd->body.y = 0;
988
    cmd->body.width  = os_display->width;
581
    cmd->body.width  = os_display->width;
989
    cmd->body.height = os_display->height;
582
    cmd->body.height = os_display->height;
Line 1010... Line 603...
1010
 
603
 
1011
        list_for_each_entry(drmmode, &os_display->connector->modes, head)
604
        list_for_each_entry(drmmode, &os_display->connector->modes, head)
1012
        {
605
        {
1013
            if( i < *count)
606
            if( i < *count)
1014
            {
607
            {
1015
                mode->width  = drm_mode_width(drmmode);
608
//                mode->width  = drm_mode_width(drmmode);
1016
                mode->height = drm_mode_height(drmmode);
609
//                mode->height = drm_mode_height(drmmode);
1017
                mode->bpp    = 32;
610
                mode->bpp    = 32;
1018
                mode->freq   = drmmode->vrefresh;
611
                mode->freq   = drmmode->vrefresh;
1019
                i++;
612
                i++;
1020
                mode++;
613
                mode++;
Line 1046... Line 639...
1046
        (mode->freq   != 0 ) &&
639
        (mode->freq   != 0 ) &&
1047
        ( (mode->width   != os_display->width)  ||
640
        ( (mode->width   != os_display->width)  ||
1048
          (mode->height  != os_display->height) ||
641
          (mode->height  != os_display->height) ||
1049
          (mode->freq    != os_display->vrefresh) ) )
642
          (mode->freq    != os_display->vrefresh) ) )
1050
    {
643
    {
1051
        if( set_mode(os_display->ddev, os_display->connector, mode, true) )
644
//        if( set_mode(os_display->ddev, os_display->connector, mode, true) )
1052
            err = 0;
645
//            err = 0;
1053
    };
646
    };
Line 1054... Line 647...
1054
 
647
 
1055
    return err;
648
    return err;
Line 1056... Line 649...
1056
};
649
};
1057
 
650
 
1058
struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags)
651
struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags)
1059
{
652
{
Line 1060... Line 653...
1060
    struct file *filep;
653
    struct file *filep;
Line 1061... Line 654...
1061
    int count;
654
    int count;
1062
 
655
 
Line 1063... Line 656...
1063
    filep = malloc(sizeof(*filep));
656
    filep = __builtin_malloc(sizeof(*filep));
Line 1107... Line 700...
1107
    };
700
    };
Line 1108... Line 701...
1108
 
701
 
1109
    return page;
702
    return page;
Line -... Line 703...
-
 
703
};
-
 
704
 
-
 
705
ktime_t ktime_get(void)
-
 
706
{
-
 
707
    ktime_t t;
-
 
708
 
-
 
709
    t.tv64 = GetClockNs();
-
 
710
 
-
 
711
    return t;
-
 
712
}
-
 
713
 
-
 
714
bool reservation_object_test_signaled_rcu(struct reservation_object *obj,
-
 
715
                                           bool test_all)
-
 
716
{
-
 
717
    return true;
-
 
718
}
-
 
719
 
-
 
720
int reservation_object_reserve_shared(struct reservation_object *obj)
-
 
721
{
-
 
722
    return 0;
-
 
723
}
-
 
724
 
-
 
725
void reservation_object_add_shared_fence(struct reservation_object *obj,
-
 
726
                                          struct fence *fence)
-
 
727
{};
-
 
728
 
-
 
729
void reservation_object_add_excl_fence(struct reservation_object *obj,
-
 
730
                                       struct fence *fence)
-
 
731
{};
-
 
732
 
-
 
733
#define KMAP_MAX    256
-
 
734
 
-
 
735
static struct mutex kmap_mutex;
-
 
736
static struct page* kmap_table[KMAP_MAX];
-
 
737
static int kmap_av;
-
 
738
static int kmap_first;
-
 
739
static void* kmap_base;
-
 
740
 
-
 
741
 
-
 
742
int kmap_init()
-
 
743
{
-
 
744
    kmap_base = AllocKernelSpace(KMAP_MAX*4096);
-
 
745
    if(kmap_base == NULL)
-
 
746
        return -1;
-
 
747
 
-
 
748
    kmap_av = KMAP_MAX;
-
 
749
    MutexInit(&kmap_mutex);
-
 
750
    return 0;
-
 
751
};
-
 
752
 
-
 
753
void *kmap(struct page *page)
-
 
754
{
-
 
755
    void *vaddr = NULL;
-
 
756
    int i;
-
 
757
 
-
 
758
    do
-
 
759
    {
-
 
760
        MutexLock(&kmap_mutex);
-
 
761
        if(kmap_av != 0)
-
 
762
        {
-
 
763
            for(i = kmap_first; i < KMAP_MAX; i++)
-
 
764
            {
-
 
765
                if(kmap_table[i] == NULL)
-
 
766
                {
-
 
767
                    kmap_av--;
-
 
768
                    kmap_first = i;
-
 
769
                    kmap_table[i] = page;
-
 
770
                    vaddr = kmap_base + (i<<12);
-
 
771
                    MapPage(vaddr,(addr_t)page,3);
-
 
772
                    break;
-
 
773
                };
-
 
774
            };
-
 
775
        };
-
 
776
        MutexUnlock(&kmap_mutex);
-
 
777
    }while(vaddr == NULL);
-
 
778
 
-
 
779
    return vaddr;
-
 
780
};
-
 
781
 
-
 
782
void *kmap_atomic(struct page *page) __attribute__ ((alias ("kmap")));
-
 
783
 
-
 
784
void kunmap(struct page *page)
-
 
785
{
-
 
786
    void *vaddr;
-
 
787
    int   i;
-
 
788
 
-
 
789
    MutexLock(&kmap_mutex);
-
 
790
 
-
 
791
    for(i = 0; i < KMAP_MAX; i++)
-
 
792
    {
-
 
793
        if(kmap_table[i] == page)
-
 
794
        {
-
 
795
            kmap_av++;
-
 
796
            if(i < kmap_first)
-
 
797
                kmap_first = i;
-
 
798
            kmap_table[i] = NULL;
-
 
799
            vaddr = kmap_base + (i<<12);
-
 
800
            MapPage(vaddr,0,0);
-
 
801
            break;
-
 
802
        };
-
 
803
    };
-
 
804
 
-
 
805
    MutexUnlock(&kmap_mutex);
-
 
806
};
-
 
807
 
-
 
808
void kunmap_atomic(void *vaddr)
-
 
809
{
-
 
810
    int i;
-
 
811
 
-
 
812
    MapPage(vaddr,0,0);
-
 
813
 
-
 
814
    i = (vaddr - kmap_base) >> 12;
-
 
815
 
-
 
816
    MutexLock(&kmap_mutex);
-
 
817
 
-
 
818
    kmap_av++;
-
 
819
    if(i < kmap_first)
-
 
820
        kmap_first = i;
-
 
821
    kmap_table[i] = NULL;
-
 
822
 
-
 
823
    MutexUnlock(&kmap_mutex);
-
 
824
}
-
 
825
 
-
 
826
 
-
 
827
#include 
-
 
828
 
-
 
829
struct rcu_ctrlblk {
-
 
830
        struct rcu_head *rcucblist;     /* List of pending callbacks (CBs). */
-
 
831
        struct rcu_head **donetail;     /* ->next pointer of last "done" CB. */
-
 
832
        struct rcu_head **curtail;      /* ->next pointer of last CB. */
-
 
833
//        RCU_TRACE(long qlen);           /* Number of pending CBs. */
-
 
834
//        RCU_TRACE(unsigned long gp_start); /* Start time for stalls. */
-
 
835
//        RCU_TRACE(unsigned long ticks_this_gp); /* Statistic for stalls. */
-
 
836
//        RCU_TRACE(unsigned long jiffies_stall); /* Jiffies at next stall. */
-
 
837
//        RCU_TRACE(const char *name);    /* Name of RCU type. */
-
 
838
};
-
 
839
 
-
 
840
/* Definition for rcupdate control block. */
-
 
841
static struct rcu_ctrlblk rcu_sched_ctrlblk = {
-
 
842
        .donetail       = &rcu_sched_ctrlblk.rcucblist,
-
 
843
        .curtail        = &rcu_sched_ctrlblk.rcucblist,
-
 
844
//        RCU_TRACE(.name = "rcu_sched")
-
 
845
};
-
 
846
 
-
 
847
static void __call_rcu(struct rcu_head *head,
-
 
848
                       void (*func)(struct rcu_head *rcu),
-
 
849
                       struct rcu_ctrlblk *rcp)
-
 
850
{
-
 
851
        unsigned long flags;
-
 
852
 
-
 
853
//        debug_rcu_head_queue(head);
-
 
854
        head->func = func;
-
 
855
        head->next = NULL;
-
 
856
 
-
 
857
        local_irq_save(flags);
-
 
858
        *rcp->curtail = head;
-
 
859
        rcp->curtail = &head->next;
-
 
860
//        RCU_TRACE(rcp->qlen++);
-
 
861
        local_irq_restore(flags);
-
 
862
}
-
 
863
 
-
 
864
/*
-
 
865
 * Post an RCU callback to be invoked after the end of an RCU-sched grace
-
 
866
 * period.  But since we have but one CPU, that would be after any
-
 
867
 * quiescent state.
-
 
868
 */
-
 
869
void call_rcu_sched(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
-
 
870
{
-
 
871
        __call_rcu(head, func, &rcu_sched_ctrlblk);
-
 
872
}
-
 
873
 
-
 
874
 
-
 
875
fb_get_options(const char *name, char **option)
-
 
876
{
-
 
877
    return 1;
-
 
878
}
-
 
879
 
-
 
880
static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes)
-
 
881
{
-
 
882
        while (bytes) {
-
 
883
                if (*start != value)
-
 
884
                        return (void *)start;
-
 
885
                start++;
-
 
886
                bytes--;
-
 
887
        }
-
 
888
        return NULL;
-
 
889
}
-
 
890
 
-
 
891
/**
-
 
892
 * memchr_inv - Find an unmatching character in an area of memory.
-
 
893
 * @start: The memory area
-
 
894
 * @c: Find a character other than c
-
 
895
 * @bytes: The size of the area.
-
 
896
 *
-
 
897
 * returns the address of the first character other than @c, or %NULL
-
 
898
 * if the whole buffer contains just @c.
-
 
899
 */
-
 
900
void *memchr_inv(const void *start, int c, size_t bytes)
-
 
901
{
-
 
902
        u8 value = c;
-
 
903
        u64 value64;
-
 
904
        unsigned int words, prefix;
-
 
905
 
-
 
906
        if (bytes <= 16)
-
 
907
                return check_bytes8(start, value, bytes);
-
 
908
 
-
 
909
        value64 = value;
-
 
910
#if defined(ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64
-
 
911
        value64 *= 0x0101010101010101;
-
 
912
#elif defined(ARCH_HAS_FAST_MULTIPLIER)
-
 
913
        value64 *= 0x01010101;
-
 
914
        value64 |= value64 << 32;
-
 
915
#else
-
 
916
        value64 |= value64 << 8;
-
 
917
        value64 |= value64 << 16;
-
 
918
        value64 |= value64 << 32;
-
 
919
#endif
-
 
920
 
-
 
921
        prefix = (unsigned long)start % 8;
-
 
922
        if (prefix) {
-
 
923
                u8 *r;
-
 
924
 
-
 
925
                prefix = 8 - prefix;
-
 
926
                r = check_bytes8(start, value, prefix);
-
 
927
                if (r)
-
 
928
                        return r;
-
 
929
                start += prefix;
-
 
930
                bytes -= prefix;
-
 
931
        }
-
 
932
 
-
 
933
        words = bytes / 8;
-
 
934
 
-
 
935
        while (words) {
-
 
936
                if (*(u64 *)start != value64)
-
 
937
                        return check_bytes8(start, value, 8);
-
 
938
                start += 8;
-
 
939
                words--;
-
 
940
        }
-
 
941
 
-
 
942
        return check_bytes8(start, value, bytes % 8);
-
 
943
}
-
 
944
 
-
 
945
 
-
 
946
void drm_master_put(struct drm_master **master)
-
 
947
{};
-
 
948
 
-
 
949
 
-
 
950
bool ttm_ref_object_exists(struct ttm_object_file *tfile,
-
 
951
                           struct ttm_base_object *base)
-
 
952
{
-
 
953
    return true;
-
 
954
};
-
 
955
 
-
 
956
int autoremove_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key)
-
 
957
{
-
 
958
    list_del_init(&wait->task_list);
-
 
959
    return 1;
-
 
960
}
-
 
961
 
-
 
962
 
-
 
963
struct file *fd_array[32];
-
 
964
 
-
 
965
struct file *fget(unsigned int fd)
-
 
966
{
-
 
967
    struct file *file;
-
 
968
 
-
 
969
    file = fd_array[fd];
-
 
970
    get_file_rcu(file);
-
 
971
    return file;
-
 
972
}
-
 
973
 
-
 
974
void fput(struct file *file)
-
 
975
{
-
 
976
    if (atomic_long_dec_and_test(&file->f_count))
-
 
977
    {
-
 
978
 
-
 
979
    }
-
 
980
}
-
 
981
 
-
 
982
struct dma_buf *dma_buf_get(int fd)
-
 
983
{
-
 
984
        struct file *file;
-
 
985
 
-
 
986
        file = fget(fd);
-
 
987
 
-
 
988
        if (!file)
-
 
989
                return ERR_PTR(-EBADF);
-
 
990
 
-
 
991
//        if (!is_dma_buf_file(file)) {
-
 
992
//                fput(file);
-
 
993
//                return ERR_PTR(-EINVAL);
-
 
994
//        }
-
 
995
 
-
 
996
        return file->private_data;
-
 
997
}
-
 
998
 
-
 
999
int get_unused_fd_flags(unsigned flags)
-
 
1000
{
-
 
1001
    return 1;
-
 
1002
}
-
 
1003
 
-
 
1004
void fd_install(unsigned int fd, struct file *file)
-
 
1005
{
-
 
1006
    fd_array[fd] = file;
-
 
1007
}
-
 
1008
 
-
 
1009
int dma_buf_fd(struct dma_buf *dmabuf, int flags)
-
 
1010
{
-
 
1011
        int fd;
-
 
1012
 
-
 
1013
        if (!dmabuf || !dmabuf->file)
-
 
1014
                return -EINVAL;
-
 
1015
 
-
 
1016
        fd = get_unused_fd_flags(flags);
-
 
1017
        if (fd < 0)
-
 
1018
                return fd;
-
 
1019
 
-
 
1020
        fd_install(fd, dmabuf->file);
-
 
1021
 
-
 
1022
        return fd;
-
 
1023
}
-
 
1024
 
-
 
1025
void dma_buf_put(struct dma_buf *dmabuf)
-
 
1026
{
-
 
1027
        if (WARN_ON(!dmabuf || !dmabuf->file))
-
 
1028
                return;
-
 
1029
 
-
 
1030
        fput(dmabuf->file);
-
 
1031
}
-
 
1032
 
-
 
1033
 
-
 
1034
struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
-
 
1035
{
-
 
1036
        struct dma_buf *dmabuf;
-
 
1037
        struct reservation_object *resv = exp_info->resv;
-
 
1038
        struct file *file;
-
 
1039
        size_t alloc_size = sizeof(struct dma_buf);
-
 
1040
 
-
 
1041
        if (!exp_info->resv)
-
 
1042
                alloc_size += sizeof(struct reservation_object);
-
 
1043
        else
-
 
1044
                /* prevent &dma_buf[1] == dma_buf->resv */
-
 
1045
                alloc_size += 1;
-
 
1046
 
-
 
1047
        if (WARN_ON(!exp_info->priv
-
 
1048
                          || !exp_info->ops
-
 
1049
                          || !exp_info->ops->map_dma_buf
-
 
1050
                          || !exp_info->ops->unmap_dma_buf
-
 
1051
                          || !exp_info->ops->release
-
 
1052
                          || !exp_info->ops->kmap_atomic
-
 
1053
                          || !exp_info->ops->kmap
-
 
1054
                          || !exp_info->ops->mmap)) {
-
 
1055
                return ERR_PTR(-EINVAL);
-
 
1056
        }
-
 
1057
 
-
 
1058
        dmabuf = kzalloc(alloc_size, GFP_KERNEL);
-
 
1059
        if (!dmabuf) {
-
 
1060
                return ERR_PTR(-ENOMEM);
-
 
1061
        }
-
 
1062
 
-
 
1063
        dmabuf->priv = exp_info->priv;
-
 
1064
        dmabuf->ops = exp_info->ops;
-
 
1065
        dmabuf->size = exp_info->size;
-
 
1066
        dmabuf->exp_name = exp_info->exp_name;
-
 
1067
 
-
 
1068
        if (!resv) {
-
 
1069
                resv = (struct reservation_object *)&dmabuf[1];
-
 
1070
                reservation_object_init(resv);
-
 
1071
        }
-
 
1072
//        dmabuf->resv = resv;
-
 
1073
 
-
 
1074
//        file = anon_inode_getfile("dmabuf", &dma_buf_fops, dmabuf,
-
 
1075
//                                        exp_info->flags);
-
 
1076
//        if (IS_ERR(file)) {
-
 
1077
//                kfree(dmabuf);
-
 
1078
//                return ERR_CAST(file);
-
 
1079
//        }
-
 
1080
 
-
 
1081
//        file->f_mode |= FMODE_LSEEK;
-
 
1082
//        dmabuf->file = file;
-
 
1083
 
-
 
1084
        mutex_init(&dmabuf->lock);
-
 
1085
        INIT_LIST_HEAD(&dmabuf->attachments);
-
 
1086
 
-
 
1087
//        mutex_lock(&db_list.lock);
-
 
1088
//        list_add(&dmabuf->list_node, &db_list.head);
-
 
1089
//        mutex_unlock(&db_list.lock);
-
 
1090
 
-
 
1091
        return dmabuf;
-
 
1092
}
-
 
1093
 
-
 
1094
int dma_map_sg(struct device *dev, struct scatterlist *sglist,
-
 
1095
                           int nelems, int dir)
-
 
1096
{
-
 
1097
    struct scatterlist *s;
-
 
1098
    int i;
-
 
1099
 
-
 
1100
    for_each_sg(sglist, s, nelems, i) {
-
 
1101
        s->dma_address = (dma_addr_t)sg_phys(s);
-
 
1102
#ifdef CONFIG_NEED_SG_DMA_LENGTH
-
 
1103
        s->dma_length  = s->length;
-
 
1104
#endif
-
 
1105
    }
-
 
1106
 
-
 
1107
    return nelems;
-
 
1108
}
-
 
1109
 
-
 
1110
void *vmalloc(unsigned long size)
-
 
1111
{
-
 
1112
    return KernelAlloc(size);
-
 
1113
}
-
 
1114
 
-
 
1115
void vfree(const void *addr)
-
 
1116
{