Subversion Repositories Kolibri OS

Rev

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