Subversion Repositories Kolibri OS

Rev

Rev 2344 | Rev 2352 | 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
 
2344 Serge 91
#define SRV_GETVERSION       0
92
#define SRV_ENUM_MODES       1
93
#define SRV_SET_MODE         2
2351 Serge 94
#define SRV_GET_CAPS         3
2342 Serge 95
 
2344 Serge 96
#define SRV_CREATE_SURFACE  10
97
 
98
#define SRV_BLIT_VIDEO      20
99
 
2338 Serge 100
#define check_input(size) \
101
    if( unlikely((inp==NULL)||(io->inp_size != (size))) )   \
102
        break;
103
 
104
#define check_output(size) \
105
    if( unlikely((outp==NULL)||(io->out_size != (size))) )   \
106
        break;
107
 
108
int _stdcall display_handler(ioctl_t *io)
109
{
110
    int    retval = -1;
111
    u32_t *inp;
112
    u32_t *outp;
113
 
114
    inp = io->input;
115
    outp = io->output;
116
 
117
    switch(io->io_code)
118
    {
119
        case SRV_GETVERSION:
120
            check_output(4);
2344 Serge 121
            *outp  = DISPLAY_VERSION;
2338 Serge 122
            retval = 0;
123
            break;
124
 
125
        case SRV_ENUM_MODES:
126
            dbgprintf("SRV_ENUM_MODES inp %x inp_size %x out_size %x\n",
127
                       inp, io->inp_size, io->out_size );
2340 Serge 128
            check_output(4);
2338 Serge 129
//            check_input(*outp * sizeof(videomode_t));
130
            if( i915_modeset)
131
                retval = get_videomodes((videomode_t*)inp, outp);
132
            break;
133
 
134
        case SRV_SET_MODE:
135
            dbgprintf("SRV_SET_MODE inp %x inp_size %x\n",
136
                       inp, io->inp_size);
137
            check_input(sizeof(videomode_t));
138
            if( i915_modeset )
139
                retval = set_user_mode((videomode_t*)inp);
140
            break;
141
 
2351 Serge 142
        case SRV_GET_CAPS:
143
            retval = get_driver_caps((hwcaps_t*)inp);
144
            break;
145
 
2344 Serge 146
        case SRV_CREATE_SURFACE:
147
//            check_input(8);
148
            retval = create_surface((struct io_call_10*)inp);
2338 Serge 149
            break;
150
 
2342 Serge 151
 
2338 Serge 152
        case SRV_BLIT_VIDEO:
2351 Serge 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],
2342 Serge 157
                    inp[3], inp[4], inp[5], inp[6]);
2338 Serge 158
 
159
            retval = 0;
160
            break;
161
    };
162
 
163
    return retval;
164
}
165
 
166
 
2325 Serge 167
#define PCI_CLASS_REVISION      0x08
168
#define PCI_CLASS_DISPLAY_VGA   0x0300
169
#define PCI_CLASS_BRIDGE_HOST   0x0600
2326 Serge 170
#define PCI_CLASS_BRIDGE_ISA    0x0601
2325 Serge 171
 
172
int pci_scan_filter(u32_t id, u32_t busnr, u32_t devfn)
173
{
174
    u16_t vendor, device;
175
    u32_t class;
176
    int   ret = 0;
177
 
178
    vendor   = id & 0xffff;
179
    device   = (id >> 16) & 0xffff;
180
 
181
    if(vendor == 0x8086)
182
    {
183
        class = PciRead32(busnr, devfn, PCI_CLASS_REVISION);
184
        class >>= 16;
185
 
186
        if( (class == PCI_CLASS_DISPLAY_VGA) ||
2326 Serge 187
            (class == PCI_CLASS_BRIDGE_HOST) ||
188
            (class == PCI_CLASS_BRIDGE_ISA))
2325 Serge 189
            ret = 1;
190
    }
191
    return ret;
192
};
2340 Serge 193
 
194
 
195
static char* parse_path(char *p, char *log)
196
{
197
    char  c;
198
 
199
    while( (c = *p++) == ' ');
200
        p--;
201
    while( (c = *log++ = *p++) && (c != ' '));
202
    *log = 0;
203
 
204
    return p;
205
};
206
 
207
void parse_cmdline(char *cmdline, char *log)
208
{
209
    char *p = cmdline;
210
 
211
    char c = *p++;
212
 
213
    while( c )
214
    {
215
        if( c == '-')
216
        {
217
            switch(*p++)
218
            {
219
                case 'l':
220
                    p = parse_path(p, log);
221
                    break;
222
            };
223
        };
224
        c = *p++;
225
    };
226
};
227
 
2351 Serge 228
 
2344 Serge 229
static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
2351 Serge 230
                unsigned int *ecx, unsigned int *edx)
2344 Serge 231
{
232
    /* ecx is often an input as well as an output. */
2351 Serge 233
    asm volatile("cpuid"
2344 Serge 234
        : "=a" (*eax),
235
          "=b" (*ebx),
236
          "=c" (*ecx),
237
          "=d" (*edx)
2351 Serge 238
        : "0" (*eax), "2" (*ecx)
239
        : "memory");
2344 Serge 240
}
241
 
2351 Serge 242
 
243
 
2344 Serge 244
static inline void cpuid(unsigned int op,
245
                         unsigned int *eax, unsigned int *ebx,
246
                         unsigned int *ecx, unsigned int *edx)
247
{
248
        *eax = op;
249
        *ecx = 0;
250
        __cpuid(eax, ebx, ecx, edx);
251
}
252
 
253
void cpu_detect()
254
{
255
    u32 junk, tfms, cap0, misc;
256
 
257
    cpuid(0x00000001, &tfms, &misc, &junk, &cap0);
258
 
259
    if (cap0 & (1<<19))
260
    {
261
        x86_clflush_size = ((misc >> 8) & 0xff) * 8;
262
    }
263
}
264