Subversion Repositories Kolibri OS

Rev

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