Subversion Repositories Kolibri OS

Rev

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

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