Subversion Repositories Kolibri OS

Rev

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