Rev 3263 | Rev 3290 | 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 | |
3255 | Serge | 16 | struct pci_device { |
17 | uint16_t domain; |
||
18 | uint8_t bus; |
||
19 | uint8_t dev; |
||
20 | uint8_t func; |
||
21 | uint16_t vendor_id; |
||
22 | uint16_t device_id; |
||
23 | uint16_t subvendor_id; |
||
24 | uint16_t subdevice_id; |
||
25 | uint32_t device_class; |
||
26 | uint8_t revision; |
||
27 | }; |
||
28 | |||
3033 | serge | 29 | extern struct drm_device *main_device; |
3255 | Serge | 30 | extern struct drm_file *drm_file_handlers[256]; |
3033 | serge | 31 | |
2344 | Serge | 32 | void cpu_detect(); |
33 | |||
2340 | Serge | 34 | void parse_cmdline(char *cmdline, char *log); |
2338 | Serge | 35 | int _stdcall display_handler(ioctl_t *io); |
2325 | Serge | 36 | int init_agp(void); |
37 | |||
3120 | serge | 38 | int srv_blit_bitmap(u32 hbitmap, int dst_x, int dst_y, |
2351 | Serge | 39 | int src_x, int src_y, u32 w, u32 h); |
2340 | Serge | 40 | |
2351 | Serge | 41 | int blit_textured(u32 hbitmap, int dst_x, int dst_y, |
42 | int src_x, int src_y, u32 w, u32 h); |
||
43 | |||
2361 | Serge | 44 | int blit_tex(u32 hbitmap, int dst_x, int dst_y, |
45 | int src_x, int src_y, u32 w, u32 h); |
||
46 | |||
3255 | Serge | 47 | void get_pci_info(struct pci_device *dev); |
48 | int gem_getparam(struct drm_device *dev, void *data); |
||
49 | |||
3277 | Serge | 50 | int i915_mask_update(struct drm_device *dev, void *data, |
51 | struct drm_file *file); |
||
3255 | Serge | 52 | |
3277 | Serge | 53 | |
2325 | Serge | 54 | static char log[256]; |
55 | |||
2344 | Serge | 56 | int x86_clflush_size; |
57 | |||
2338 | Serge | 58 | int i915_modeset = 1; |
59 | |||
2325 | Serge | 60 | u32_t drvEntry(int action, char *cmdline) |
61 | { |
||
62 | |||
63 | int err = 0; |
||
64 | |||
65 | if(action != 1) |
||
66 | return 0; |
||
67 | |||
68 | if( GetService("DISPLAY") != 0 ) |
||
69 | return 0; |
||
70 | |||
2340 | Serge | 71 | if( cmdline && *cmdline ) |
72 | parse_cmdline(cmdline, log); |
||
2325 | Serge | 73 | |
74 | if(!dbg_open(log)) |
||
75 | { |
||
3263 | Serge | 76 | strcpy(log, "/tmp1/1/i915.log"); |
77 | // strcpy(log, "/RD/1/DRIVERS/i915.log"); |
||
2325 | Serge | 78 | |
79 | if(!dbg_open(log)) |
||
80 | { |
||
81 | printf("Can't open %s\nExit\n", log); |
||
82 | return 0; |
||
83 | }; |
||
84 | } |
||
3243 | Serge | 85 | dbgprintf("i915 RC 10\n cmdline: %s\n", cmdline); |
2325 | Serge | 86 | |
2351 | Serge | 87 | cpu_detect(); |
88 | dbgprintf("\ncache line size %d\n", x86_clflush_size); |
||
89 | |||
2325 | Serge | 90 | enum_pci_devices(); |
91 | |||
92 | err = i915_init(); |
||
93 | |||
2338 | Serge | 94 | if(err) |
95 | { |
||
96 | dbgprintf("Epic Fail :(/n"); |
||
97 | }; |
||
2325 | Serge | 98 | |
2338 | Serge | 99 | err = RegService("DISPLAY", display_handler); |
2325 | Serge | 100 | |
2338 | Serge | 101 | if( err != 0) |
102 | dbgprintf("Set DISPLAY handler\n"); |
||
103 | |||
2325 | Serge | 104 | return err; |
105 | }; |
||
106 | |||
2344 | Serge | 107 | #define CURRENT_API 0x0200 /* 2.00 */ |
108 | #define COMPATIBLE_API 0x0100 /* 1.00 */ |
||
2338 | Serge | 109 | |
2344 | Serge | 110 | #define API_VERSION (COMPATIBLE_API << 16) | CURRENT_API |
2351 | Serge | 111 | #define DISPLAY_VERSION API_VERSION |
2338 | Serge | 112 | |
113 | |||
2352 | Serge | 114 | #define SRV_GETVERSION 0 |
115 | #define SRV_ENUM_MODES 1 |
||
116 | #define SRV_SET_MODE 2 |
||
117 | #define SRV_GET_CAPS 3 |
||
2342 | Serge | 118 | |
2352 | Serge | 119 | #define SRV_CREATE_SURFACE 10 |
120 | #define SRV_DESTROY_SURFACE 11 |
||
121 | #define SRV_LOCK_SURFACE 12 |
||
122 | #define SRV_UNLOCK_SURFACE 13 |
||
3039 | serge | 123 | #define SRV_RESIZE_SURFACE 14 |
3120 | serge | 124 | #define SRV_BLIT_BITMAP 15 |
125 | #define SRV_BLIT_TEXTURE 16 |
||
126 | #define SRV_BLIT_VIDEO 17 |
||
2344 | Serge | 127 | |
3260 | Serge | 128 | #define SRV_GET_PCI_INFO 20 |
3255 | Serge | 129 | #define SRV_GET_PARAM 21 |
130 | #define SRV_I915_GEM_CREATE 22 |
||
131 | #define SRV_DRM_GEM_CLOSE 23 |
||
132 | #define SRV_I915_GEM_PIN 24 |
||
3260 | Serge | 133 | #define SRV_I915_GEM_SET_CACHEING 25 |
134 | #define SRV_I915_GEM_GET_APERTURE 26 |
||
135 | #define SRV_I915_GEM_PWRITE 27 |
||
136 | #define SRV_I915_GEM_BUSY 28 |
||
137 | #define SRV_I915_GEM_SET_DOMAIN 29 |
||
3263 | Serge | 138 | #define SRV_I915_GEM_MMAP 30 |
3255 | Serge | 139 | |
3263 | Serge | 140 | #define SRV_I915_GEM_THROTTLE 32 |
141 | #define SRV_FBINFO 33 |
||
142 | #define SRV_I915_GEM_EXECBUFFER2 34 |
||
3260 | Serge | 143 | |
3263 | Serge | 144 | |
145 | |||
2338 | Serge | 146 | #define check_input(size) \ |
147 | if( unlikely((inp==NULL)||(io->inp_size != (size))) ) \ |
||
148 | break; |
||
149 | |||
150 | #define check_output(size) \ |
||
151 | if( unlikely((outp==NULL)||(io->out_size != (size))) ) \ |
||
152 | break; |
||
153 | |||
154 | int _stdcall display_handler(ioctl_t *io) |
||
155 | { |
||
3255 | Serge | 156 | struct drm_file *file; |
157 | |||
2338 | Serge | 158 | int retval = -1; |
159 | u32_t *inp; |
||
160 | u32_t *outp; |
||
161 | |||
162 | inp = io->input; |
||
163 | outp = io->output; |
||
164 | |||
3255 | Serge | 165 | file = drm_file_handlers[0]; |
166 | |||
2338 | Serge | 167 | switch(io->io_code) |
168 | { |
||
169 | case SRV_GETVERSION: |
||
170 | check_output(4); |
||
2344 | Serge | 171 | *outp = DISPLAY_VERSION; |
2338 | Serge | 172 | retval = 0; |
173 | break; |
||
174 | |||
175 | case SRV_ENUM_MODES: |
||
3031 | serge | 176 | // dbgprintf("SRV_ENUM_MODES inp %x inp_size %x out_size %x\n", |
177 | // inp, io->inp_size, io->out_size ); |
||
2340 | Serge | 178 | check_output(4); |
2338 | Serge | 179 | // check_input(*outp * sizeof(videomode_t)); |
180 | if( i915_modeset) |
||
181 | retval = get_videomodes((videomode_t*)inp, outp); |
||
182 | break; |
||
183 | |||
184 | case SRV_SET_MODE: |
||
3031 | serge | 185 | // dbgprintf("SRV_SET_MODE inp %x inp_size %x\n", |
186 | // inp, io->inp_size); |
||
2338 | Serge | 187 | check_input(sizeof(videomode_t)); |
188 | if( i915_modeset ) |
||
189 | retval = set_user_mode((videomode_t*)inp); |
||
190 | break; |
||
3033 | serge | 191 | |
2351 | Serge | 192 | case SRV_GET_CAPS: |
193 | retval = get_driver_caps((hwcaps_t*)inp); |
||
194 | break; |
||
195 | |||
2344 | Serge | 196 | case SRV_CREATE_SURFACE: |
197 | // check_input(8); |
||
3243 | Serge | 198 | // retval = create_surface(main_device, (struct io_call_10*)inp); |
2338 | Serge | 199 | break; |
200 | |||
2352 | Serge | 201 | case SRV_LOCK_SURFACE: |
3243 | Serge | 202 | // retval = lock_surface((struct io_call_12*)inp); |
2352 | Serge | 203 | break; |
2342 | Serge | 204 | |
3039 | serge | 205 | case SRV_RESIZE_SURFACE: |
3243 | Serge | 206 | // retval = resize_surface((struct io_call_14*)inp); |
3039 | serge | 207 | break; |
208 | |||
3255 | Serge | 209 | case SRV_BLIT_BITMAP: |
3243 | Serge | 210 | // srv_blit_bitmap( inp[0], inp[1], inp[2], |
211 | // inp[3], inp[4], inp[5], inp[6]); |
||
3033 | serge | 212 | |
213 | // blit_tex( inp[0], inp[1], inp[2], |
||
2351 | Serge | 214 | // inp[3], inp[4], inp[5], inp[6]); |
215 | |||
3255 | Serge | 216 | break; |
2338 | Serge | 217 | |
3260 | Serge | 218 | case SRV_GET_PCI_INFO: |
3255 | Serge | 219 | get_pci_info((struct pci_device *)inp); |
2338 | Serge | 220 | retval = 0; |
221 | break; |
||
3031 | serge | 222 | |
3255 | Serge | 223 | case SRV_GET_PARAM: |
224 | retval = gem_getparam(main_device, inp); |
||
225 | break; |
||
226 | |||
227 | case SRV_I915_GEM_CREATE: |
||
228 | retval = i915_gem_create_ioctl(main_device, inp, file); |
||
229 | break; |
||
230 | |||
231 | case SRV_DRM_GEM_CLOSE: |
||
232 | retval = drm_gem_close_ioctl(main_device, inp, file); |
||
233 | break; |
||
234 | |||
235 | case SRV_I915_GEM_PIN: |
||
236 | retval = i915_gem_pin_ioctl(main_device, inp, file); |
||
237 | break; |
||
3260 | Serge | 238 | |
239 | case SRV_I915_GEM_SET_CACHEING: |
||
240 | retval = i915_gem_set_caching_ioctl(main_device, inp, file); |
||
241 | break; |
||
242 | |||
243 | case SRV_I915_GEM_GET_APERTURE: |
||
244 | retval = i915_gem_get_aperture_ioctl(main_device, inp, file); |
||
245 | break; |
||
246 | |||
247 | case SRV_I915_GEM_PWRITE: |
||
248 | retval = i915_gem_pwrite_ioctl(main_device, inp, file); |
||
249 | break; |
||
250 | |||
251 | case SRV_I915_GEM_BUSY: |
||
252 | retval = i915_gem_busy_ioctl(main_device, inp, file); |
||
253 | break; |
||
254 | |||
255 | case SRV_I915_GEM_SET_DOMAIN: |
||
256 | retval = i915_gem_set_domain_ioctl(main_device, inp, file); |
||
257 | break; |
||
258 | |||
3263 | Serge | 259 | case SRV_I915_GEM_THROTTLE: |
260 | retval = i915_gem_throttle_ioctl(main_device, inp, file); |
||
261 | break; |
||
262 | |||
263 | case SRV_I915_GEM_MMAP: |
||
264 | retval = i915_gem_mmap_ioctl(main_device, inp, file); |
||
265 | break; |
||
266 | |||
267 | case SRV_FBINFO: |
||
268 | retval = i915_fbinfo(inp); |
||
269 | break; |
||
270 | |||
271 | case SRV_I915_GEM_EXECBUFFER2: |
||
272 | retval = i915_gem_execbuffer2(main_device, inp, file); |
||
273 | break; |
||
274 | |||
2338 | Serge | 275 | }; |
276 | |||
277 | return retval; |
||
278 | } |
||
279 | |||
280 | |||
2325 | Serge | 281 | #define PCI_CLASS_REVISION 0x08 |
282 | #define PCI_CLASS_DISPLAY_VGA 0x0300 |
||
283 | #define PCI_CLASS_BRIDGE_HOST 0x0600 |
||
2326 | Serge | 284 | #define PCI_CLASS_BRIDGE_ISA 0x0601 |
2325 | Serge | 285 | |
286 | int pci_scan_filter(u32_t id, u32_t busnr, u32_t devfn) |
||
287 | { |
||
288 | u16_t vendor, device; |
||
289 | u32_t class; |
||
290 | int ret = 0; |
||
291 | |||
292 | vendor = id & 0xffff; |
||
293 | device = (id >> 16) & 0xffff; |
||
294 | |||
295 | if(vendor == 0x8086) |
||
296 | { |
||
297 | class = PciRead32(busnr, devfn, PCI_CLASS_REVISION); |
||
298 | class >>= 16; |
||
299 | |||
300 | if( (class == PCI_CLASS_DISPLAY_VGA) || |
||
2326 | Serge | 301 | (class == PCI_CLASS_BRIDGE_HOST) || |
302 | (class == PCI_CLASS_BRIDGE_ISA)) |
||
2325 | Serge | 303 | ret = 1; |
304 | } |
||
305 | return ret; |
||
306 | }; |
||
2340 | Serge | 307 | |
308 | |||
309 | static char* parse_path(char *p, char *log) |
||
310 | { |
||
311 | char c; |
||
312 | |||
313 | while( (c = *p++) == ' '); |
||
314 | p--; |
||
315 | while( (c = *log++ = *p++) && (c != ' ')); |
||
316 | *log = 0; |
||
317 | |||
318 | return p; |
||
319 | }; |
||
320 | |||
321 | void parse_cmdline(char *cmdline, char *log) |
||
322 | { |
||
323 | char *p = cmdline; |
||
324 | |||
325 | char c = *p++; |
||
326 | |||
327 | while( c ) |
||
328 | { |
||
329 | if( c == '-') |
||
330 | { |
||
331 | switch(*p++) |
||
332 | { |
||
333 | case 'l': |
||
334 | p = parse_path(p, log); |
||
335 | break; |
||
336 | }; |
||
337 | }; |
||
338 | c = *p++; |
||
339 | }; |
||
340 | }; |
||
341 | |||
2351 | Serge | 342 | |
2344 | Serge | 343 | static inline void __cpuid(unsigned int *eax, unsigned int *ebx, |
2351 | Serge | 344 | unsigned int *ecx, unsigned int *edx) |
2344 | Serge | 345 | { |
346 | /* ecx is often an input as well as an output. */ |
||
2351 | Serge | 347 | asm volatile("cpuid" |
2344 | Serge | 348 | : "=a" (*eax), |
349 | "=b" (*ebx), |
||
350 | "=c" (*ecx), |
||
351 | "=d" (*edx) |
||
2351 | Serge | 352 | : "0" (*eax), "2" (*ecx) |
353 | : "memory"); |
||
2344 | Serge | 354 | } |
355 | |||
2351 | Serge | 356 | |
357 | |||
2344 | Serge | 358 | static inline void cpuid(unsigned int op, |
359 | unsigned int *eax, unsigned int *ebx, |
||
360 | unsigned int *ecx, unsigned int *edx) |
||
361 | { |
||
362 | *eax = op; |
||
363 | *ecx = 0; |
||
364 | __cpuid(eax, ebx, ecx, edx); |
||
365 | } |
||
366 | |||
367 | void cpu_detect() |
||
368 | { |
||
369 | u32 junk, tfms, cap0, misc; |
||
370 | |||
371 | cpuid(0x00000001, &tfms, &misc, &junk, &cap0); |
||
372 | |||
373 | if (cap0 & (1<<19)) |
||
374 | { |
||
375 | x86_clflush_size = ((misc >> 8) & 0xff) * 8; |
||
376 | } |
||
377 | } |
||
378 | |||
3243 | Serge | 379 | |
380 | int get_driver_caps(hwcaps_t *caps) |
||
381 | { |
||
382 | int ret = 0; |
||
383 | |||
384 | switch(caps->idx) |
||
385 | { |
||
386 | case 0: |
||
387 | caps->opt[0] = 0; |
||
388 | caps->opt[1] = 0; |
||
389 | break; |
||
390 | |||
391 | case 1: |
||
392 | caps->cap1.max_tex_width = 4096; |
||
393 | caps->cap1.max_tex_height = 4096; |
||
394 | break; |
||
395 | default: |
||
396 | ret = 1; |
||
397 | }; |
||
398 | caps->idx = 1; |
||
399 | return ret; |
||
400 | } |
||
401 | |||
3255 | Serge | 402 | |
403 | void get_pci_info(struct pci_device *dev) |
||
404 | { |
||
405 | struct pci_dev *pdev = main_device->pdev; |
||
406 | |||
407 | memset(dev, sizeof(*dev), 0); |
||
408 | |||
409 | dev->domain = 0; |
||
410 | dev->bus = pdev->busnr; |
||
411 | dev->dev = pdev->devfn >> 3; |
||
412 | dev->func = pdev->devfn & 7; |
||
413 | dev->vendor_id = pdev->vendor; |
||
414 | dev->device_id = pdev->device; |
||
415 | dev->revision = pdev->revision; |
||
416 | };19)) |