Subversion Repositories Kolibri OS

Rev

Rev 3033 | Rev 3120 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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