Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
2338 Serge 1
#include "drmP.h"
2
#include "drm.h"
3
#include "i915_drm.h"
4
#include "i915_drv.h"
5
#include "intel_drv.h"
6
 
7
 
2325 Serge 8
#include 
9
#include 
10
#include 
11
#include 
12
#include 
13
#include 
14
 
2342 Serge 15
#include "bitmap.h"
2340 Serge 16
 
2344 Serge 17
void cpu_detect();
18
 
2340 Serge 19
void parse_cmdline(char *cmdline, char *log);
2338 Serge 20
int _stdcall display_handler(ioctl_t *io);
2325 Serge 21
int init_agp(void);
22
 
2351 Serge 23
int blit_video(u32 hbitmap, int  dst_x, int dst_y,
24
               int src_x, int src_y, u32 w, u32 h);
2340 Serge 25
 
2351 Serge 26
int blit_textured(u32 hbitmap, int  dst_x, int dst_y,
27
               int src_x, int src_y, u32 w, u32 h);
28
 
2325 Serge 29
static char  log[256];
30
 
2344 Serge 31
int x86_clflush_size;
32
 
2338 Serge 33
int i915_modeset = 1;
34
 
2325 Serge 35
u32_t drvEntry(int action, char *cmdline)
36
{
37
    struct pci_device_id  *ent;
38
 
39
    int     err = 0;
40
 
41
    if(action != 1)
42
        return 0;
43
 
44
    if( GetService("DISPLAY") != 0 )
45
        return 0;
46
 
2340 Serge 47
    if( cmdline && *cmdline )
48
        parse_cmdline(cmdline, log);
2325 Serge 49
 
50
    if(!dbg_open(log))
51
    {
2351 Serge 52
//        strcpy(log, "/RD/1/DRIVERS/i915.log");
53
        strcpy(log, "/HD1/2/i915.log");
2325 Serge 54
 
55
        if(!dbg_open(log))
56
        {
57
            printf("Can't open %s\nExit\n", log);
58
            return 0;
59
        };
60
    }
2342 Serge 61
    dbgprintf("i915 blitter preview\n cmdline: %s\n", cmdline);
2325 Serge 62
 
2351 Serge 63
    cpu_detect();
64
    dbgprintf("\ncache line size %d\n", x86_clflush_size);
65
 
2325 Serge 66
    enum_pci_devices();
67
 
68
    err = i915_init();
69
 
2338 Serge 70
    if(err)
71
    {
72
        dbgprintf("Epic Fail :(/n");
2325 Serge 73
 
2338 Serge 74
    };
2325 Serge 75
 
2338 Serge 76
    err = RegService("DISPLAY", display_handler);
2325 Serge 77
 
2338 Serge 78
    if( err != 0)
79
        dbgprintf("Set DISPLAY handler\n");
80
 
2325 Serge 81
    return err;
82
};
83
 
2344 Serge 84
#define CURRENT_API     0x0200      /*      2.00     */
85
#define COMPATIBLE_API  0x0100      /*      1.00     */
2338 Serge 86
 
2344 Serge 87
#define API_VERSION     (COMPATIBLE_API << 16) | CURRENT_API
2351 Serge 88
#define DISPLAY_VERSION  API_VERSION
2338 Serge 89
 
90
 
2352 Serge 91
#define SRV_GETVERSION          0
92
#define SRV_ENUM_MODES          1
93
#define SRV_SET_MODE            2
94
#define SRV_GET_CAPS            3
2342 Serge 95
 
2352 Serge 96
#define SRV_CREATE_SURFACE      10
97
#define SRV_DESTROY_SURFACE     11
98
#define SRV_LOCK_SURFACE        12
99
#define SRV_UNLOCK_SURFACE      13
2344 Serge 100
 
2352 Serge 101
#define SRV_BLIT_VIDEO          20
2344 Serge 102
 
2338 Serge 103
#define check_input(size) \
104
    if( unlikely((inp==NULL)||(io->inp_size != (size))) )   \
105
        break;
106
 
107
#define check_output(size) \
108
    if( unlikely((outp==NULL)||(io->out_size != (size))) )   \
109
        break;
110
 
111
int _stdcall display_handler(ioctl_t *io)
112
{
113
    int    retval = -1;
114
    u32_t *inp;
115
    u32_t *outp;
116
 
117
    inp = io->input;
118
    outp = io->output;
119
 
120
    switch(io->io_code)
121
    {
122
        case SRV_GETVERSION:
123
            check_output(4);
2344 Serge 124
            *outp  = DISPLAY_VERSION;
2338 Serge 125
            retval = 0;
126
            break;
127
 
128
        case SRV_ENUM_MODES:
129
            dbgprintf("SRV_ENUM_MODES inp %x inp_size %x out_size %x\n",
130
                       inp, io->inp_size, io->out_size );
2340 Serge 131
            check_output(4);
2338 Serge 132
//            check_input(*outp * sizeof(videomode_t));
133
            if( i915_modeset)
134
                retval = get_videomodes((videomode_t*)inp, outp);
135
            break;
136
 
137
        case SRV_SET_MODE:
138
            dbgprintf("SRV_SET_MODE inp %x inp_size %x\n",
139
                       inp, io->inp_size);
140
            check_input(sizeof(videomode_t));
141
            if( i915_modeset )
142
                retval = set_user_mode((videomode_t*)inp);
143
            break;
144
 
2351 Serge 145
        case SRV_GET_CAPS:
146
            retval = get_driver_caps((hwcaps_t*)inp);
147
            break;
148
 
2344 Serge 149
        case SRV_CREATE_SURFACE:
150
//            check_input(8);
151
            retval = create_surface((struct io_call_10*)inp);
2338 Serge 152
            break;
153
 
2352 Serge 154
        case SRV_LOCK_SURFACE:
155
            retval = lock_surface((struct io_call_12*)inp);
156
            break;
2342 Serge 157
 
2338 Serge 158
        case SRV_BLIT_VIDEO:
2351 Serge 159
//            blit_video( inp[0], inp[1], inp[2],
160
//                    inp[3], inp[4], inp[5], inp[6]);
161
 
162
            blit_textured( inp[0], inp[1], inp[2],
2342 Serge 163
                    inp[3], inp[4], inp[5], inp[6]);
2338 Serge 164
 
2352 Serge 165
 
2338 Serge 166
            retval = 0;
167
            break;
168
    };
169
 
170
    return retval;
171
}
172
 
173
 
2325 Serge 174
#define PCI_CLASS_REVISION      0x08
175
#define PCI_CLASS_DISPLAY_VGA   0x0300
176
#define PCI_CLASS_BRIDGE_HOST   0x0600
2326 Serge 177
#define PCI_CLASS_BRIDGE_ISA    0x0601
2325 Serge 178
 
179
int pci_scan_filter(u32_t id, u32_t busnr, u32_t devfn)
180
{
181
    u16_t vendor, device;
182
    u32_t class;
183
    int   ret = 0;
184
 
185
    vendor   = id & 0xffff;
186
    device   = (id >> 16) & 0xffff;
187
 
188
    if(vendor == 0x8086)
189
    {
190
        class = PciRead32(busnr, devfn, PCI_CLASS_REVISION);
191
        class >>= 16;
192
 
193
        if( (class == PCI_CLASS_DISPLAY_VGA) ||
2326 Serge 194
            (class == PCI_CLASS_BRIDGE_HOST) ||
195
            (class == PCI_CLASS_BRIDGE_ISA))
2325 Serge 196
            ret = 1;
197
    }
198
    return ret;
199
};
2340 Serge 200
 
201
 
202
static char* parse_path(char *p, char *log)
203
{
204
    char  c;
205
 
206
    while( (c = *p++) == ' ');
207
        p--;
208
    while( (c = *log++ = *p++) && (c != ' '));
209
    *log = 0;
210
 
211
    return p;
212
};
213
 
214
void parse_cmdline(char *cmdline, char *log)
215
{
216
    char *p = cmdline;
217
 
218
    char c = *p++;
219
 
220
    while( c )
221
    {
222
        if( c == '-')
223
        {
224
            switch(*p++)
225
            {
226
                case 'l':
227
                    p = parse_path(p, log);
228
                    break;
229
            };
230
        };
231
        c = *p++;
232
    };
233
};
234
 
2351 Serge 235
 
2344 Serge 236
static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
2351 Serge 237
                unsigned int *ecx, unsigned int *edx)
2344 Serge 238
{
239
    /* ecx is often an input as well as an output. */
2351 Serge 240
    asm volatile("cpuid"
2344 Serge 241
        : "=a" (*eax),
242
          "=b" (*ebx),
243
          "=c" (*ecx),
244
          "=d" (*edx)
2351 Serge 245
        : "0" (*eax), "2" (*ecx)
246
        : "memory");
2344 Serge 247
}
248
 
2351 Serge 249
 
250
 
2344 Serge 251
static inline void cpuid(unsigned int op,
252
                         unsigned int *eax, unsigned int *ebx,
253
                         unsigned int *ecx, unsigned int *edx)
254
{
255
        *eax = op;
256
        *ecx = 0;
257
        __cpuid(eax, ebx, ecx, edx);
258
}
259
 
260
void cpu_detect()
261
{
262
    u32 junk, tfms, cap0, misc;
263
 
264
    cpuid(0x00000001, &tfms, &misc, &junk, &cap0);
265
 
266
    if (cap0 & (1<<19))
267
    {
268
        x86_clflush_size = ((misc >> 8) & 0xff) * 8;
269
    }
270
}
271