Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
3031 serge 1
#include 
2
#include 
3
#include 
2338 Serge 4
#include "i915_drv.h"
3031 serge 5
//#include "intel_drv.h"
2338 Serge 6
 
2325 Serge 7
#include 
8
#include 
9
#include 
10
#include 
11
#include 
12
#include 
13
 
2342 Serge 14
#include "bitmap.h"
2340 Serge 15
 
3255 Serge 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
 
4104 Serge 29
struct drm_device *main_device;
30
struct drm_file   *drm_file_handlers[256];
3033 serge 31
 
2344 Serge 32
void cpu_detect();
33
 
2340 Serge 34
void parse_cmdline(char *cmdline, char *log);
2338 Serge 35
int _stdcall display_handler(ioctl_t *io);
2325 Serge 36
int init_agp(void);
37
 
3120 serge 38
int srv_blit_bitmap(u32 hbitmap, int  dst_x, int dst_y,
2351 Serge 39
               int src_x, int src_y, u32 w, u32 h);
2340 Serge 40
 
2351 Serge 41
int blit_textured(u32 hbitmap, int  dst_x, int dst_y,
42
               int src_x, int src_y, u32 w, u32 h);
43
 
2361 Serge 44
int blit_tex(u32 hbitmap, int  dst_x, int dst_y,
45
             int src_x, int src_y, u32 w, u32 h);
46
 
3255 Serge 47
void get_pci_info(struct pci_device *dev);
48
int gem_getparam(struct drm_device *dev, void *data);
49
 
3277 Serge 50
int i915_mask_update(struct drm_device *dev, void *data,
51
            struct drm_file *file);
3255 Serge 52
 
3277 Serge 53
 
2325 Serge 54
static char  log[256];
55
 
3482 Serge 56
struct workqueue_struct *system_wq;
3764 Serge 57
int driver_wq_state;
3482 Serge 58
 
2344 Serge 59
int x86_clflush_size;
3482 Serge 60
unsigned int tsc_khz;
2344 Serge 61
 
2338 Serge 62
int i915_modeset = 1;
63
 
3480 Serge 64
u32_t  __attribute__((externally_visible)) drvEntry(int action, char *cmdline)
2325 Serge 65
{
4104 Serge 66
    int err = 0;
2325 Serge 67
 
68
    if(action != 1)
3764 Serge 69
    {
70
        driver_wq_state = 0;
2325 Serge 71
        return 0;
3764 Serge 72
    };
2325 Serge 73
 
74
    if( GetService("DISPLAY") != 0 )
75
        return 0;
76
 
2340 Serge 77
    if( cmdline && *cmdline )
78
        parse_cmdline(cmdline, log);
2325 Serge 79
 
80
    if(!dbg_open(log))
81
    {
4104 Serge 82
//        strcpy(log, "/tmp1/1/i915.log");
3263 Serge 83
//        strcpy(log, "/RD/1/DRIVERS/i915.log");
4104 Serge 84
        strcpy(log, "/BD1/4/i915.log");
2325 Serge 85
 
86
        if(!dbg_open(log))
87
        {
88
            printf("Can't open %s\nExit\n", log);
89
            return 0;
90
        };
91
    }
4104 Serge 92
    dbgprintf(" i915 v3.12-6\n cmdline: %s\n", cmdline);
2325 Serge 93
 
2351 Serge 94
    cpu_detect();
3480 Serge 95
//    dbgprintf("\ncache line size %d\n", x86_clflush_size);
2351 Serge 96
 
2325 Serge 97
    enum_pci_devices();
98
 
99
    err = i915_init();
2338 Serge 100
    if(err)
101
    {
3298 Serge 102
        dbgprintf("Epic Fail :(\n");
103
        return 0;
2338 Serge 104
    };
4104 Serge 105
    init_display_kms(main_device);
2325 Serge 106
 
2338 Serge 107
    err = RegService("DISPLAY", display_handler);
2325 Serge 108
 
2338 Serge 109
    if( err != 0)
110
        dbgprintf("Set DISPLAY handler\n");
111
 
3482 Serge 112
    struct drm_i915_private *dev_priv = main_device->dev_private;
4104 Serge 113
 
3764 Serge 114
    driver_wq_state = 1;
4104 Serge 115
 
3482 Serge 116
    run_workqueue(dev_priv->wq);
117
 
2325 Serge 118
    return err;
119
};
120
 
3480 Serge 121
 
2344 Serge 122
#define CURRENT_API     0x0200      /*      2.00     */
123
#define COMPATIBLE_API  0x0100      /*      1.00     */
2338 Serge 124
 
2344 Serge 125
#define API_VERSION     (COMPATIBLE_API << 16) | CURRENT_API
2351 Serge 126
#define DISPLAY_VERSION  API_VERSION
2338 Serge 127
 
128
 
2352 Serge 129
#define SRV_GETVERSION          0
130
#define SRV_ENUM_MODES          1
131
#define SRV_SET_MODE            2
132
#define SRV_GET_CAPS            3
2342 Serge 133
 
2352 Serge 134
#define SRV_CREATE_SURFACE      10
135
#define SRV_DESTROY_SURFACE     11
136
#define SRV_LOCK_SURFACE        12
137
#define SRV_UNLOCK_SURFACE      13
3039 serge 138
#define SRV_RESIZE_SURFACE      14
3120 serge 139
#define SRV_BLIT_BITMAP         15
140
#define SRV_BLIT_TEXTURE        16
141
#define SRV_BLIT_VIDEO          17
2344 Serge 142
 
3290 Serge 143
 
3260 Serge 144
#define SRV_GET_PCI_INFO            20
4104 Serge 145
#define SRV_GET_PARAM               21
146
#define SRV_I915_GEM_CREATE         22
147
#define SRV_DRM_GEM_CLOSE           23
148
#define SRV_I915_GEM_PIN            24
3260 Serge 149
#define SRV_I915_GEM_SET_CACHEING   25
150
#define SRV_I915_GEM_GET_APERTURE   26
151
#define SRV_I915_GEM_PWRITE         27
152
#define SRV_I915_GEM_BUSY           28
153
#define SRV_I915_GEM_SET_DOMAIN     29
3263 Serge 154
#define SRV_I915_GEM_MMAP           30
3480 Serge 155
#define SRV_I915_GEM_MMAP_GTT       31
3263 Serge 156
#define SRV_I915_GEM_THROTTLE       32
157
#define SRV_FBINFO                  33
158
#define SRV_I915_GEM_EXECBUFFER2    34
3290 Serge 159
#define SRV_MASK_UPDATE             35
3260 Serge 160
 
3263 Serge 161
 
162
 
2338 Serge 163
#define check_input(size) \
164
    if( unlikely((inp==NULL)||(io->inp_size != (size))) )   \
165
        break;
166
 
167
#define check_output(size) \
168
    if( unlikely((outp==NULL)||(io->out_size != (size))) )   \
169
        break;
170
 
171
int _stdcall display_handler(ioctl_t *io)
172
{
3255 Serge 173
    struct drm_file *file;
174
 
2338 Serge 175
    int    retval = -1;
176
    u32_t *inp;
177
    u32_t *outp;
178
 
179
    inp = io->input;
180
    outp = io->output;
181
 
3255 Serge 182
    file = drm_file_handlers[0];
183
 
2338 Serge 184
    switch(io->io_code)
185
    {
186
        case SRV_GETVERSION:
187
            check_output(4);
2344 Serge 188
            *outp  = DISPLAY_VERSION;
2338 Serge 189
            retval = 0;
190
            break;
191
 
192
        case SRV_ENUM_MODES:
3031 serge 193
//            dbgprintf("SRV_ENUM_MODES inp %x inp_size %x out_size %x\n",
194
//                       inp, io->inp_size, io->out_size );
2340 Serge 195
            check_output(4);
2338 Serge 196
//            check_input(*outp * sizeof(videomode_t));
197
            if( i915_modeset)
198
                retval = get_videomodes((videomode_t*)inp, outp);
199
            break;
200
 
201
        case SRV_SET_MODE:
3031 serge 202
//            dbgprintf("SRV_SET_MODE inp %x inp_size %x\n",
203
//                       inp, io->inp_size);
2338 Serge 204
            check_input(sizeof(videomode_t));
205
            if( i915_modeset )
206
                retval = set_user_mode((videomode_t*)inp);
207
            break;
3033 serge 208
 
2351 Serge 209
        case SRV_GET_CAPS:
210
            retval = get_driver_caps((hwcaps_t*)inp);
211
            break;
212
 
2344 Serge 213
        case SRV_CREATE_SURFACE:
214
//            check_input(8);
3243 Serge 215
//            retval = create_surface(main_device, (struct io_call_10*)inp);
2338 Serge 216
            break;
217
 
2352 Serge 218
        case SRV_LOCK_SURFACE:
3243 Serge 219
//            retval = lock_surface((struct io_call_12*)inp);
2352 Serge 220
            break;
2342 Serge 221
 
3039 serge 222
        case SRV_RESIZE_SURFACE:
3243 Serge 223
//            retval = resize_surface((struct io_call_14*)inp);
3039 serge 224
            break;
225
 
3255 Serge 226
        case SRV_BLIT_BITMAP:
3243 Serge 227
//            srv_blit_bitmap( inp[0], inp[1], inp[2],
228
//                        inp[3], inp[4], inp[5], inp[6]);
3033 serge 229
 
230
//            blit_tex( inp[0], inp[1], inp[2],
2351 Serge 231
//                    inp[3], inp[4], inp[5], inp[6]);
232
 
3255 Serge 233
            break;
2338 Serge 234
 
3260 Serge 235
        case SRV_GET_PCI_INFO:
3255 Serge 236
            get_pci_info((struct pci_device *)inp);
2338 Serge 237
            retval = 0;
238
            break;
3031 serge 239
 
3255 Serge 240
        case SRV_GET_PARAM:
241
            retval = gem_getparam(main_device, inp);
242
            break;
243
 
244
        case SRV_I915_GEM_CREATE:
245
            retval = i915_gem_create_ioctl(main_device, inp, file);
246
            break;
247
 
248
        case SRV_DRM_GEM_CLOSE:
249
            retval = drm_gem_close_ioctl(main_device, inp, file);
250
            break;
251
 
252
        case SRV_I915_GEM_PIN:
253
            retval = i915_gem_pin_ioctl(main_device, inp, file);
254
            break;
3260 Serge 255
 
256
        case SRV_I915_GEM_SET_CACHEING:
257
            retval = i915_gem_set_caching_ioctl(main_device, inp, file);
258
            break;
259
 
260
        case SRV_I915_GEM_GET_APERTURE:
261
            retval = i915_gem_get_aperture_ioctl(main_device, inp, file);
262
            break;
263
 
264
        case SRV_I915_GEM_PWRITE:
265
            retval = i915_gem_pwrite_ioctl(main_device, inp, file);
266
            break;
267
 
268
        case SRV_I915_GEM_BUSY:
269
            retval = i915_gem_busy_ioctl(main_device, inp, file);
270
            break;
271
 
272
        case SRV_I915_GEM_SET_DOMAIN:
273
            retval = i915_gem_set_domain_ioctl(main_device, inp, file);
274
            break;
275
 
3263 Serge 276
        case SRV_I915_GEM_THROTTLE:
277
            retval = i915_gem_throttle_ioctl(main_device, inp, file);
278
            break;
279
 
280
        case SRV_I915_GEM_MMAP:
281
            retval = i915_gem_mmap_ioctl(main_device, inp, file);
282
            break;
283
 
3480 Serge 284
        case SRV_I915_GEM_MMAP_GTT:
285
            retval = i915_gem_mmap_gtt_ioctl(main_device, inp, file);
286
            break;
287
 
288
 
3263 Serge 289
        case SRV_FBINFO:
290
            retval = i915_fbinfo(inp);
291
            break;
292
 
293
        case SRV_I915_GEM_EXECBUFFER2:
294
            retval = i915_gem_execbuffer2(main_device, inp, file);
295
            break;
296
 
3290 Serge 297
        case SRV_MASK_UPDATE:
298
            retval = i915_mask_update(main_device, inp, file);
299
            break;
300
 
2338 Serge 301
    };
302
 
303
    return retval;
304
}
305
 
306
 
2325 Serge 307
#define PCI_CLASS_REVISION      0x08
308
#define PCI_CLASS_DISPLAY_VGA   0x0300
309
#define PCI_CLASS_BRIDGE_HOST   0x0600
2326 Serge 310
#define PCI_CLASS_BRIDGE_ISA    0x0601
2325 Serge 311
 
312
int pci_scan_filter(u32_t id, u32_t busnr, u32_t devfn)
313
{
314
    u16_t vendor, device;
315
    u32_t class;
316
    int   ret = 0;
317
 
318
    vendor   = id & 0xffff;
319
    device   = (id >> 16) & 0xffff;
320
 
321
    if(vendor == 0x8086)
322
    {
323
        class = PciRead32(busnr, devfn, PCI_CLASS_REVISION);
324
        class >>= 16;
325
 
326
        if( (class == PCI_CLASS_DISPLAY_VGA) ||
2326 Serge 327
            (class == PCI_CLASS_BRIDGE_HOST) ||
328
            (class == PCI_CLASS_BRIDGE_ISA))
2325 Serge 329
            ret = 1;
330
    }
331
    return ret;
332
};
2340 Serge 333
 
334
 
335
static char* parse_path(char *p, char *log)
336
{
337
    char  c;
338
 
339
    while( (c = *p++) == ' ');
340
        p--;
341
    while( (c = *log++ = *p++) && (c != ' '));
342
    *log = 0;
343
 
344
    return p;
345
};
346
 
347
void parse_cmdline(char *cmdline, char *log)
348
{
349
    char *p = cmdline;
350
 
351
    char c = *p++;
352
 
353
    while( c )
354
    {
355
        if( c == '-')
356
        {
357
            switch(*p++)
358
            {
359
                case 'l':
360
                    p = parse_path(p, log);
361
                    break;
362
            };
363
        };
364
        c = *p++;
365
    };
366
};
367
 
2351 Serge 368
 
2344 Serge 369
static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
2351 Serge 370
                unsigned int *ecx, unsigned int *edx)
2344 Serge 371
{
372
    /* ecx is often an input as well as an output. */
2351 Serge 373
    asm volatile("cpuid"
2344 Serge 374
        : "=a" (*eax),
375
          "=b" (*ebx),
376
          "=c" (*ecx),
377
          "=d" (*edx)
2351 Serge 378
        : "0" (*eax), "2" (*ecx)
379
        : "memory");
2344 Serge 380
}
381
 
2351 Serge 382
 
383
 
2344 Serge 384
static inline void cpuid(unsigned int op,
385
                         unsigned int *eax, unsigned int *ebx,
386
                         unsigned int *ecx, unsigned int *edx)
387
{
388
        *eax = op;
389
        *ecx = 0;
390
        __cpuid(eax, ebx, ecx, edx);
391
}
392
 
393
void cpu_detect()
394
{
395
    u32 junk, tfms, cap0, misc;
396
 
397
    cpuid(0x00000001, &tfms, &misc, &junk, &cap0);
398
 
399
    if (cap0 & (1<<19))
400
    {
401
        x86_clflush_size = ((misc >> 8) & 0xff) * 8;
402
    }
3482 Serge 403
 
404
    tsc_khz = (unsigned int)(GetCpuFreq()/1000);
2344 Serge 405
}
406
 
3243 Serge 407
 
408
int get_driver_caps(hwcaps_t *caps)
409
{
410
    int ret = 0;
411
 
412
    switch(caps->idx)
413
    {
414
        case 0:
415
            caps->opt[0] = 0;
416
            caps->opt[1] = 0;
417
            break;
418
 
419
        case 1:
420
            caps->cap1.max_tex_width  = 4096;
421
            caps->cap1.max_tex_height = 4096;
422
            break;
423
        default:
424
            ret = 1;
425
    };
426
    caps->idx = 1;
427
    return ret;
428
}
429
 
3255 Serge 430
 
431
void get_pci_info(struct pci_device *dev)
432
{
433
    struct pci_dev *pdev = main_device->pdev;
434
 
435
    memset(dev, sizeof(*dev), 0);
436
 
437
    dev->domain     = 0;
438
    dev->bus        = pdev->busnr;
439
    dev->dev        = pdev->devfn >> 3;
440
    dev->func       = pdev->devfn & 7;
441
    dev->vendor_id  = pdev->vendor;
442
    dev->device_id  = pdev->device;
443
    dev->revision   = pdev->revision;
444
};