Rev 4080 | Rev 4570 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4075 | Serge | 1 | #include |
2 | #include |
||
3 | |||
4 | #include |
||
5 | #include |
||
6 | |||
7 | #include "vmwgfx_drv.h" |
||
8 | |||
9 | #include |
||
10 | #include |
||
11 | #include |
||
12 | #include |
||
13 | |||
14 | #include "bitmap.h" |
||
15 | |||
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 | |||
4111 | Serge | 29 | struct drm_device *main_device; |
30 | struct drm_file *drm_file_handlers[256]; |
||
4075 | Serge | 31 | |
32 | int vmw_init(void); |
||
4111 | Serge | 33 | int kms_init(struct drm_device *dev); |
34 | void kms_update(); |
||
35 | |||
4075 | Serge | 36 | void cpu_detect(); |
37 | |||
38 | void parse_cmdline(char *cmdline, char *log); |
||
39 | int _stdcall display_handler(ioctl_t *io); |
||
40 | |||
41 | int srv_blit_bitmap(u32 hbitmap, int dst_x, int dst_y, |
||
42 | int src_x, int src_y, u32 w, u32 h); |
||
43 | |||
44 | int blit_textured(u32 hbitmap, int dst_x, int dst_y, |
||
45 | int src_x, int src_y, u32 w, u32 h); |
||
46 | |||
47 | int blit_tex(u32 hbitmap, int dst_x, int dst_y, |
||
48 | int src_x, int src_y, u32 w, u32 h); |
||
49 | |||
50 | void get_pci_info(struct pci_device *dev); |
||
51 | int gem_getparam(struct drm_device *dev, void *data); |
||
52 | |||
53 | int i915_mask_update(struct drm_device *dev, void *data, |
||
54 | struct drm_file *file); |
||
55 | |||
56 | |||
57 | static char log[256]; |
||
58 | |||
59 | struct workqueue_struct *system_wq; |
||
60 | int driver_wq_state; |
||
61 | |||
62 | int x86_clflush_size; |
||
63 | unsigned int tsc_khz; |
||
64 | |||
4080 | Serge | 65 | int kms_modeset = 1; |
4075 | Serge | 66 | |
4111 | Serge | 67 | |
68 | void vmw_driver_thread() |
||
69 | { |
||
70 | dbgprintf("%s\n",__FUNCTION__); |
||
71 | |||
72 | // run_workqueue(dev_priv->wq); |
||
73 | |||
74 | while(driver_wq_state) |
||
75 | { |
||
76 | kms_update(); |
||
77 | delay(1); |
||
78 | }; |
||
79 | __asm__ __volatile__ ( |
||
80 | "int $0x40" |
||
81 | ::"a"(-1)); |
||
82 | } |
||
83 | |||
4075 | Serge | 84 | u32_t __attribute__((externally_visible)) drvEntry(int action, char *cmdline) |
85 | { |
||
86 | |||
87 | int err = 0; |
||
88 | |||
89 | if(action != 1) |
||
90 | { |
||
91 | driver_wq_state = 0; |
||
92 | return 0; |
||
93 | }; |
||
94 | |||
95 | if( GetService("DISPLAY") != 0 ) |
||
96 | return 0; |
||
97 | |||
98 | if( cmdline && *cmdline ) |
||
99 | parse_cmdline(cmdline, log); |
||
100 | |||
101 | if(!dbg_open(log)) |
||
102 | { |
||
4111 | Serge | 103 | strcpy(log, "/tmp1/1/vmw.log"); |
4075 | Serge | 104 | // strcpy(log, "/RD/1/DRIVERS/VMW.log"); |
4111 | Serge | 105 | // strcpy(log, "/HD0/1/vmw.log"); |
4075 | Serge | 106 | |
107 | if(!dbg_open(log)) |
||
108 | { |
||
109 | printf("Can't open %s\nExit\n", log); |
||
110 | return 0; |
||
111 | }; |
||
112 | } |
||
4111 | Serge | 113 | dbgprintf(" vmw v3.12-rc6\n cmdline: %s\n", cmdline); |
4075 | Serge | 114 | |
115 | cpu_detect(); |
||
116 | dbgprintf("\ncache line size %d\n", x86_clflush_size); |
||
117 | |||
118 | enum_pci_devices(); |
||
119 | |||
120 | err = vmw_init(); |
||
121 | if(err) |
||
122 | { |
||
123 | dbgprintf("Epic Fail :(\n"); |
||
124 | return 0; |
||
125 | }; |
||
4111 | Serge | 126 | kms_init(main_device); |
4075 | Serge | 127 | |
128 | err = RegService("DISPLAY", display_handler); |
||
129 | |||
130 | if( err != 0) |
||
131 | dbgprintf("Set DISPLAY handler\n"); |
||
132 | |||
4111 | Serge | 133 | driver_wq_state = 1; |
4075 | Serge | 134 | |
4111 | Serge | 135 | CreateKernelThread(vmw_driver_thread); |
136 | |||
4075 | Serge | 137 | return err; |
138 | }; |
||
139 | |||
140 | |||
141 | #define CURRENT_API 0x0200 /* 2.00 */ |
||
142 | #define COMPATIBLE_API 0x0100 /* 1.00 */ |
||
143 | |||
144 | #define API_VERSION (COMPATIBLE_API << 16) | CURRENT_API |
||
145 | #define DISPLAY_VERSION API_VERSION |
||
146 | |||
147 | |||
148 | #define SRV_GETVERSION 0 |
||
149 | #define SRV_ENUM_MODES 1 |
||
150 | #define SRV_SET_MODE 2 |
||
151 | #define SRV_GET_CAPS 3 |
||
152 | |||
153 | #define SRV_CREATE_SURFACE 10 |
||
154 | #define SRV_DESTROY_SURFACE 11 |
||
155 | #define SRV_LOCK_SURFACE 12 |
||
156 | #define SRV_UNLOCK_SURFACE 13 |
||
157 | #define SRV_RESIZE_SURFACE 14 |
||
158 | #define SRV_BLIT_BITMAP 15 |
||
159 | #define SRV_BLIT_TEXTURE 16 |
||
160 | #define SRV_BLIT_VIDEO 17 |
||
161 | |||
162 | |||
163 | #define SRV_GET_PCI_INFO 20 |
||
164 | #define SRV_GET_PARAM 21 |
||
165 | #define SRV_I915_GEM_CREATE 22 |
||
166 | #define SRV_DRM_GEM_CLOSE 23 |
||
167 | #define SRV_I915_GEM_PIN 24 |
||
168 | #define SRV_I915_GEM_SET_CACHEING 25 |
||
169 | #define SRV_I915_GEM_GET_APERTURE 26 |
||
170 | #define SRV_I915_GEM_PWRITE 27 |
||
171 | #define SRV_I915_GEM_BUSY 28 |
||
172 | #define SRV_I915_GEM_SET_DOMAIN 29 |
||
173 | #define SRV_I915_GEM_MMAP 30 |
||
174 | #define SRV_I915_GEM_MMAP_GTT 31 |
||
175 | #define SRV_I915_GEM_THROTTLE 32 |
||
176 | #define SRV_FBINFO 33 |
||
177 | #define SRV_I915_GEM_EXECBUFFER2 34 |
||
178 | #define SRV_MASK_UPDATE 35 |
||
179 | |||
180 | |||
181 | |||
182 | #define check_input(size) \ |
||
183 | if( unlikely((inp==NULL)||(io->inp_size != (size))) ) \ |
||
184 | break; |
||
185 | |||
186 | #define check_output(size) \ |
||
187 | if( unlikely((outp==NULL)||(io->out_size != (size))) ) \ |
||
188 | break; |
||
189 | |||
190 | int _stdcall display_handler(ioctl_t *io) |
||
191 | { |
||
192 | struct drm_file *file; |
||
193 | |||
194 | int retval = -1; |
||
195 | u32_t *inp; |
||
196 | u32_t *outp; |
||
197 | |||
198 | inp = io->input; |
||
199 | outp = io->output; |
||
200 | |||
201 | file = drm_file_handlers[0]; |
||
202 | |||
203 | switch(io->io_code) |
||
204 | { |
||
205 | case SRV_GETVERSION: |
||
206 | check_output(4); |
||
207 | *outp = DISPLAY_VERSION; |
||
208 | retval = 0; |
||
209 | break; |
||
4080 | Serge | 210 | |
4075 | Serge | 211 | case SRV_ENUM_MODES: |
4080 | Serge | 212 | dbgprintf("SRV_ENUM_MODES inp %x inp_size %x out_size %x\n", |
213 | inp, io->inp_size, io->out_size ); |
||
4075 | Serge | 214 | check_output(4); |
215 | // check_input(*outp * sizeof(videomode_t)); |
||
4080 | Serge | 216 | if( kms_modeset) |
4075 | Serge | 217 | retval = get_videomodes((videomode_t*)inp, outp); |
218 | break; |
||
219 | |||
220 | case SRV_SET_MODE: |
||
4080 | Serge | 221 | dbgprintf("SRV_SET_MODE inp %x inp_size %x\n", |
222 | inp, io->inp_size); |
||
4075 | Serge | 223 | check_input(sizeof(videomode_t)); |
4080 | Serge | 224 | if( kms_modeset ) |
4075 | Serge | 225 | retval = set_user_mode((videomode_t*)inp); |
226 | break; |
||
227 | |||
4080 | Serge | 228 | #if 0 |
4075 | Serge | 229 | case SRV_GET_CAPS: |
230 | retval = get_driver_caps((hwcaps_t*)inp); |
||
231 | break; |
||
232 | |||
233 | case SRV_CREATE_SURFACE: |
||
234 | // check_input(8); |
||
235 | // retval = create_surface(main_device, (struct io_call_10*)inp); |
||
236 | break; |
||
237 | |||
238 | case SRV_LOCK_SURFACE: |
||
239 | // retval = lock_surface((struct io_call_12*)inp); |
||
240 | break; |
||
241 | |||
242 | case SRV_RESIZE_SURFACE: |
||
243 | // retval = resize_surface((struct io_call_14*)inp); |
||
244 | break; |
||
245 | |||
246 | case SRV_BLIT_BITMAP: |
||
247 | // srv_blit_bitmap( inp[0], inp[1], inp[2], |
||
248 | // inp[3], inp[4], inp[5], inp[6]); |
||
249 | |||
250 | // blit_tex( inp[0], inp[1], inp[2], |
||
251 | // inp[3], inp[4], inp[5], inp[6]); |
||
252 | |||
253 | break; |
||
254 | |||
255 | case SRV_GET_PCI_INFO: |
||
256 | get_pci_info((struct pci_device *)inp); |
||
257 | retval = 0; |
||
258 | break; |
||
259 | |||
260 | case SRV_GET_PARAM: |
||
261 | retval = gem_getparam(main_device, inp); |
||
262 | break; |
||
263 | |||
264 | case SRV_I915_GEM_CREATE: |
||
265 | retval = i915_gem_create_ioctl(main_device, inp, file); |
||
266 | break; |
||
267 | |||
268 | case SRV_DRM_GEM_CLOSE: |
||
269 | retval = drm_gem_close_ioctl(main_device, inp, file); |
||
270 | break; |
||
271 | |||
272 | case SRV_I915_GEM_PIN: |
||
273 | retval = i915_gem_pin_ioctl(main_device, inp, file); |
||
274 | break; |
||
275 | |||
276 | case SRV_I915_GEM_SET_CACHEING: |
||
277 | retval = i915_gem_set_caching_ioctl(main_device, inp, file); |
||
278 | break; |
||
279 | |||
280 | case SRV_I915_GEM_GET_APERTURE: |
||
281 | retval = i915_gem_get_aperture_ioctl(main_device, inp, file); |
||
282 | break; |
||
283 | |||
284 | case SRV_I915_GEM_PWRITE: |
||
285 | retval = i915_gem_pwrite_ioctl(main_device, inp, file); |
||
286 | break; |
||
287 | |||
288 | case SRV_I915_GEM_BUSY: |
||
289 | retval = i915_gem_busy_ioctl(main_device, inp, file); |
||
290 | break; |
||
291 | |||
292 | case SRV_I915_GEM_SET_DOMAIN: |
||
293 | retval = i915_gem_set_domain_ioctl(main_device, inp, file); |
||
294 | break; |
||
295 | |||
296 | case SRV_I915_GEM_THROTTLE: |
||
297 | retval = i915_gem_throttle_ioctl(main_device, inp, file); |
||
298 | break; |
||
299 | |||
300 | case SRV_I915_GEM_MMAP: |
||
301 | retval = i915_gem_mmap_ioctl(main_device, inp, file); |
||
302 | break; |
||
303 | |||
304 | case SRV_I915_GEM_MMAP_GTT: |
||
305 | retval = i915_gem_mmap_gtt_ioctl(main_device, inp, file); |
||
306 | break; |
||
307 | |||
308 | |||
309 | case SRV_FBINFO: |
||
310 | retval = i915_fbinfo(inp); |
||
311 | break; |
||
312 | |||
313 | case SRV_I915_GEM_EXECBUFFER2: |
||
314 | retval = i915_gem_execbuffer2(main_device, inp, file); |
||
315 | break; |
||
316 | |||
317 | case SRV_MASK_UPDATE: |
||
318 | retval = i915_mask_update(main_device, inp, file); |
||
319 | break; |
||
320 | #endif |
||
321 | |||
322 | }; |
||
323 | |||
324 | return retval; |
||
325 | } |
||
326 | |||
327 | |||
328 | #define PCI_CLASS_REVISION 0x08 |
||
329 | #define PCI_CLASS_DISPLAY_VGA 0x0300 |
||
330 | #define PCI_CLASS_BRIDGE_HOST 0x0600 |
||
331 | #define PCI_CLASS_BRIDGE_ISA 0x0601 |
||
332 | |||
333 | int pci_scan_filter(u32_t id, u32_t busnr, u32_t devfn) |
||
334 | { |
||
335 | u16_t vendor, device; |
||
336 | u32_t class; |
||
337 | int ret = 0; |
||
338 | |||
339 | vendor = id & 0xffff; |
||
340 | device = (id >> 16) & 0xffff; |
||
341 | |||
342 | if(vendor == 0x15AD ) |
||
343 | { |
||
344 | class = PciRead32(busnr, devfn, PCI_CLASS_REVISION); |
||
345 | class >>= 16; |
||
346 | |||
347 | if( class == PCI_CLASS_DISPLAY_VGA ) |
||
348 | ret = 1; |
||
349 | } |
||
350 | return ret; |
||
351 | }; |
||
352 | |||
353 | |||
354 | static char* parse_path(char *p, char *log) |
||
355 | { |
||
356 | char c; |
||
357 | |||
358 | while( (c = *p++) == ' '); |
||
359 | p--; |
||
360 | while( (c = *log++ = *p++) && (c != ' ')); |
||
361 | *log = 0; |
||
362 | |||
363 | return p; |
||
364 | }; |
||
365 | |||
366 | void parse_cmdline(char *cmdline, char *log) |
||
367 | { |
||
368 | char *p = cmdline; |
||
369 | |||
370 | char c = *p++; |
||
371 | |||
372 | while( c ) |
||
373 | { |
||
374 | if( c == '-') |
||
375 | { |
||
376 | switch(*p++) |
||
377 | { |
||
378 | case 'l': |
||
379 | p = parse_path(p, log); |
||
380 | break; |
||
381 | }; |
||
382 | }; |
||
383 | c = *p++; |
||
384 | }; |
||
385 | }; |
||
386 | |||
387 | |||
388 | static inline void __cpuid(unsigned int *eax, unsigned int *ebx, |
||
389 | unsigned int *ecx, unsigned int *edx) |
||
390 | { |
||
391 | /* ecx is often an input as well as an output. */ |
||
392 | asm volatile("cpuid" |
||
393 | : "=a" (*eax), |
||
394 | "=b" (*ebx), |
||
395 | "=c" (*ecx), |
||
396 | "=d" (*edx) |
||
397 | : "0" (*eax), "2" (*ecx) |
||
398 | : "memory"); |
||
399 | } |
||
400 | |||
401 | |||
402 | |||
403 | static inline void cpuid(unsigned int op, |
||
404 | unsigned int *eax, unsigned int *ebx, |
||
405 | unsigned int *ecx, unsigned int *edx) |
||
406 | { |
||
407 | *eax = op; |
||
408 | *ecx = 0; |
||
409 | __cpuid(eax, ebx, ecx, edx); |
||
410 | } |
||
411 | |||
412 | void cpu_detect() |
||
413 | { |
||
414 | u32 junk, tfms, cap0, misc; |
||
415 | |||
416 | cpuid(0x00000001, &tfms, &misc, &junk, &cap0); |
||
417 | |||
418 | if (cap0 & (1<<19)) |
||
419 | { |
||
420 | x86_clflush_size = ((misc >> 8) & 0xff) * 8; |
||
421 | } |
||
422 | |||
423 | tsc_khz = (unsigned int)(GetCpuFreq()/1000); |
||
424 | } |
||
425 | |||
426 | /* |
||
427 | int get_driver_caps(hwcaps_t *caps) |
||
428 | { |
||
429 | int ret = 0; |
||
430 | |||
431 | switch(caps->idx) |
||
432 | { |
||
433 | case 0: |
||
434 | caps->opt[0] = 0; |
||
435 | caps->opt[1] = 0; |
||
436 | break; |
||
437 | |||
438 | case 1: |
||
439 | caps->cap1.max_tex_width = 4096; |
||
440 | caps->cap1.max_tex_height = 4096; |
||
441 | break; |
||
442 | default: |
||
443 | ret = 1; |
||
444 | }; |
||
445 | caps->idx = 1; |
||
446 | return ret; |
||
447 | } |
||
448 | |||
449 | |||
450 | void get_pci_info(struct pci_device *dev) |
||
451 | { |
||
452 | struct pci_dev *pdev = main_device->pdev; |
||
453 | |||
454 | memset(dev, sizeof(*dev), 0); |
||
455 | |||
456 | dev->domain = 0; |
||
457 | dev->bus = pdev->busnr; |
||
458 | dev->dev = pdev->devfn >> 3; |
||
459 | dev->func = pdev->devfn & 7; |
||
460 | dev->vendor_id = pdev->vendor; |
||
461 | dev->device_id = pdev->device; |
||
462 | dev->revision = pdev->revision; |
||
463 | }; |
||
464 | |||
465 | */ |
||
466 | |||
467 | #include |
||
468 | #include |
||
469 | #include |
||
470 | #include |
||
471 | |||
472 | |||
473 | static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes) |
||
474 | { |
||
475 | while (bytes) { |
||
476 | if (*start != value) |
||
477 | return (void *)start; |
||
478 | start++; |
||
479 | bytes--; |
||
480 | } |
||
481 | return NULL; |
||
482 | } |
||
483 | |||
484 | /** |
||
485 | * memchr_inv - Find an unmatching character in an area of memory. |
||
486 | * @start: The memory area |
||
487 | * @c: Find a character other than c |
||
488 | * @bytes: The size of the area. |
||
489 | * |
||
490 | * returns the address of the first character other than @c, or %NULL |
||
491 | * if the whole buffer contains just @c. |
||
492 | */ |
||
493 | void *memchr_inv(const void *start, int c, size_t bytes) |
||
494 | { |
||
495 | u8 value = c; |
||
496 | u64 value64; |
||
497 | unsigned int words, prefix; |
||
498 | |||
499 | if (bytes <= 16) |
||
500 | return check_bytes8(start, value, bytes); |
||
501 | |||
502 | value64 = value; |
||
503 | #if defined(ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64 |
||
504 | value64 *= 0x0101010101010101; |
||
505 | #elif defined(ARCH_HAS_FAST_MULTIPLIER) |
||
506 | value64 *= 0x01010101; |
||
507 | value64 |= value64 << 32; |
||
508 | #else |
||
509 | value64 |= value64 << 8; |
||
510 | value64 |= value64 << 16; |
||
511 | value64 |= value64 << 32; |
||
512 | #endif |
||
513 | |||
514 | prefix = (unsigned long)start % 8; |
||
515 | if (prefix) { |
||
516 | u8 *r; |
||
517 | |||
518 | prefix = 8 - prefix; |
||
519 | r = check_bytes8(start, value, prefix); |
||
520 | if (r) |
||
521 | return r; |
||
522 | start += prefix; |
||
523 | bytes -= prefix; |
||
524 | } |
||
525 | |||
526 | words = bytes / 8; |
||
527 | |||
528 | while (words) { |
||
529 | if (*(u64 *)start != value64) |
||
530 | return check_bytes8(start, value, 8); |
||
531 | start += 8; |
||
532 | words--; |
||
533 | } |
||
534 | |||
535 | return check_bytes8(start, value, bytes % 8); |
||
536 | } |
||
537 | |||
538 | int vscnprintf(char *buf, size_t size, const char *fmt, va_list args) |
||
539 | { |
||
540 | int i; |
||
541 | |||
542 | i = vsnprintf(buf, size, fmt, args); |
||
543 | |||
544 | if (likely(i < size)) |
||
545 | return i; |
||
546 | if (size != 0) |
||
547 | return size - 1; |
||
548 | return 0; |
||
549 | } |
||
550 | |||
551 | |||
552 | int scnprintf(char *buf, size_t size, const char *fmt, ...) |
||
553 | { |
||
554 | va_list args; |
||
555 | int i; |
||
556 | |||
557 | va_start(args, fmt); |
||
558 | i = vscnprintf(buf, size, fmt, args); |
||
559 | va_end(args); |
||
560 | |||
561 | return i; |
||
562 | } |
||
563 | |||
564 | |||
565 | |||
566 | #define _U 0x01 /* upper */ |
||
567 | #define _L 0x02 /* lower */ |
||
568 | #define _D 0x04 /* digit */ |
||
569 | #define _C 0x08 /* cntrl */ |
||
570 | #define _P 0x10 /* punct */ |
||
571 | #define _S 0x20 /* white space (space/lf/tab) */ |
||
572 | #define _X 0x40 /* hex digit */ |
||
573 | #define _SP 0x80 /* hard space (0x20) */ |
||
574 | |||
575 | extern const unsigned char _ctype[]; |
||
576 | |||
577 | #define __ismask(x) (_ctype[(int)(unsigned char)(x)]) |
||
578 | |||
579 | #define isalnum(c) ((__ismask(c)&(_U|_L|_D)) != 0) |
||
580 | #define isalpha(c) ((__ismask(c)&(_U|_L)) != 0) |
||
581 | #define iscntrl(c) ((__ismask(c)&(_C)) != 0) |
||
582 | #define isdigit(c) ((__ismask(c)&(_D)) != 0) |
||
583 | #define isgraph(c) ((__ismask(c)&(_P|_U|_L|_D)) != 0) |
||
584 | #define islower(c) ((__ismask(c)&(_L)) != 0) |
||
585 | #define isprint(c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0) |
||
586 | #define ispunct(c) ((__ismask(c)&(_P)) != 0) |
||
587 | /* Note: isspace() must return false for %NUL-terminator */ |
||
588 | #define isspace(c) ((__ismask(c)&(_S)) != 0) |
||
589 | #define isupper(c) ((__ismask(c)&(_U)) != 0) |
||
590 | #define isxdigit(c) ((__ismask(c)&(_D|_X)) != 0) |
||
591 | |||
592 | #define isascii(c) (((unsigned char)(c))<=0x7f) |
||
593 | #define toascii(c) (((unsigned char)(c))&0x7f) |
||
594 | |||
595 | |||
596 | |||
597 | //const char hex_asc[] = "0123456789abcdef"; |
||
598 | |||
599 | /** |
||
600 | * hex_to_bin - convert a hex digit to its real value |
||
601 | * @ch: ascii character represents hex digit |
||
602 | * |
||
603 | * hex_to_bin() converts one hex digit to its actual value or -1 in case of bad |
||
604 | * input. |
||
605 | */ |
||
606 | int hex_to_bin(char ch) |
||
607 | { |
||
608 | if ((ch >= '0') && (ch <= '9')) |
||
609 | return ch - '0'; |
||
610 | ch = tolower(ch); |
||
611 | if ((ch >= 'a') && (ch <= 'f')) |
||
612 | return ch - 'a' + 10; |
||
613 | return -1; |
||
614 | } |
||
615 | EXPORT_SYMBOL(hex_to_bin); |
||
616 | |||
617 | /** |
||
618 | * hex2bin - convert an ascii hexadecimal string to its binary representation |
||
619 | * @dst: binary result |
||
620 | * @src: ascii hexadecimal string |
||
621 | * @count: result length |
||
622 | * |
||
623 | * Return 0 on success, -1 in case of bad input. |
||
624 | */ |
||
625 | int hex2bin(u8 *dst, const char *src, size_t count) |
||
626 | { |
||
627 | while (count--) { |
||
628 | int hi = hex_to_bin(*src++); |
||
629 | int lo = hex_to_bin(*src++); |
||
630 | |||
631 | if ((hi < 0) || (lo < 0)) |
||
632 | return -1; |
||
633 | |||
634 | *dst++ = (hi << 4) | lo; |
||
635 | } |
||
636 | return 0; |
||
637 | } |
||
638 | EXPORT_SYMBOL(hex2bin); |
||
639 | |||
640 | /** |
||
641 | * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory |
||
642 | * @buf: data blob to dump |
||
643 | * @len: number of bytes in the @buf |
||
644 | * @rowsize: number of bytes to print per line; must be 16 or 32 |
||
645 | * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1) |
||
646 | * @linebuf: where to put the converted data |
||
647 | * @linebuflen: total size of @linebuf, including space for terminating NUL |
||
648 | * @ascii: include ASCII after the hex output |
||
649 | * |
||
650 | * hex_dump_to_buffer() works on one "line" of output at a time, i.e., |
||
651 | * 16 or 32 bytes of input data converted to hex + ASCII output. |
||
652 | * |
||
653 | * Given a buffer of u8 data, hex_dump_to_buffer() converts the input data |
||
654 | * to a hex + ASCII dump at the supplied memory location. |
||
655 | * The converted output is always NUL-terminated. |
||
656 | * |
||
657 | * E.g.: |
||
658 | * hex_dump_to_buffer(frame->data, frame->len, 16, 1, |
||
659 | * linebuf, sizeof(linebuf), true); |
||
660 | * |
||
661 | * example output buffer: |
||
662 | * 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO |
||
663 | */ |
||
664 | void hex_dump_to_buffer(const void *buf, size_t len, int rowsize, |
||
665 | int groupsize, char *linebuf, size_t linebuflen, |
||
666 | bool ascii) |
||
667 | { |
||
668 | const u8 *ptr = buf; |
||
669 | u8 ch; |
||
670 | int j, lx = 0; |
||
671 | int ascii_column; |
||
672 | |||
673 | if (rowsize != 16 && rowsize != 32) |
||
674 | rowsize = 16; |
||
675 | |||
676 | if (!len) |
||
677 | goto nil; |
||
678 | if (len > rowsize) /* limit to one line at a time */ |
||
679 | len = rowsize; |
||
680 | if ((len % groupsize) != 0) /* no mixed size output */ |
||
681 | groupsize = 1; |
||
682 | |||
683 | switch (groupsize) { |
||
684 | case 8: { |
||
685 | const u64 *ptr8 = buf; |
||
686 | int ngroups = len / groupsize; |
||
687 | |||
688 | for (j = 0; j < ngroups; j++) |
||
689 | lx += scnprintf(linebuf + lx, linebuflen - lx, |
||
690 | "%s%16.16llx", j ? " " : "", |
||
691 | (unsigned long long)*(ptr8 + j)); |
||
692 | ascii_column = 17 * ngroups + 2; |
||
693 | break; |
||
694 | } |
||
695 | |||
696 | case 4: { |
||
697 | const u32 *ptr4 = buf; |
||
698 | int ngroups = len / groupsize; |
||
699 | |||
700 | for (j = 0; j < ngroups; j++) |
||
701 | lx += scnprintf(linebuf + lx, linebuflen - lx, |
||
702 | "%s%8.8x", j ? " " : "", *(ptr4 + j)); |
||
703 | ascii_column = 9 * ngroups + 2; |
||
704 | break; |
||
705 | } |
||
706 | |||
707 | case 2: { |
||
708 | const u16 *ptr2 = buf; |
||
709 | int ngroups = len / groupsize; |
||
710 | |||
711 | for (j = 0; j < ngroups; j++) |
||
712 | lx += scnprintf(linebuf + lx, linebuflen - lx, |
||
713 | "%s%4.4x", j ? " " : "", *(ptr2 + j)); |
||
714 | ascii_column = 5 * ngroups + 2; |
||
715 | break; |
||
716 | } |
||
717 | |||
718 | default: |
||
719 | for (j = 0; (j < len) && (lx + 3) <= linebuflen; j++) { |
||
720 | ch = ptr[j]; |
||
721 | linebuf[lx++] = hex_asc_hi(ch); |
||
722 | linebuf[lx++] = hex_asc_lo(ch); |
||
723 | linebuf[lx++] = ' '; |
||
724 | } |
||
725 | if (j) |
||
726 | lx--; |
||
727 | |||
728 | ascii_column = 3 * rowsize + 2; |
||
729 | break; |
||
730 | } |
||
731 | if (!ascii) |
||
732 | goto nil; |
||
733 | |||
734 | while (lx < (linebuflen - 1) && lx < (ascii_column - 1)) |
||
735 | linebuf[lx++] = ' '; |
||
736 | for (j = 0; (j < len) && (lx + 2) < linebuflen; j++) { |
||
737 | ch = ptr[j]; |
||
738 | linebuf[lx++] = (isascii(ch) && isprint(ch)) ? ch : '.'; |
||
739 | } |
||
740 | nil: |
||
741 | linebuf[lx++] = '\0'; |
||
742 | } |
||
743 | |||
744 | /** |
||
745 | * print_hex_dump - print a text hex dump to syslog for a binary blob of data |
||
746 | * @level: kernel log level (e.g. KERN_DEBUG) |
||
747 | * @prefix_str: string to prefix each line with; |
||
748 | * caller supplies trailing spaces for alignment if desired |
||
749 | * @prefix_type: controls whether prefix of an offset, address, or none |
||
750 | * is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE) |
||
751 | * @rowsize: number of bytes to print per line; must be 16 or 32 |
||
752 | * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1) |
||
753 | * @buf: data blob to dump |
||
754 | * @len: number of bytes in the @buf |
||
755 | * @ascii: include ASCII after the hex output |
||
756 | * |
||
757 | * Given a buffer of u8 data, print_hex_dump() prints a hex + ASCII dump |
||
758 | * to the kernel log at the specified kernel log level, with an optional |
||
759 | * leading prefix. |
||
760 | * |
||
761 | * print_hex_dump() works on one "line" of output at a time, i.e., |
||
762 | * 16 or 32 bytes of input data converted to hex + ASCII output. |
||
763 | * print_hex_dump() iterates over the entire input @buf, breaking it into |
||
764 | * "line size" chunks to format and print. |
||
765 | * |
||
766 | * E.g.: |
||
767 | * print_hex_dump(KERN_DEBUG, "raw data: ", DUMP_PREFIX_ADDRESS, |
||
768 | * 16, 1, frame->data, frame->len, true); |
||
769 | * |
||
770 | * Example output using %DUMP_PREFIX_OFFSET and 1-byte mode: |
||
771 | * 0009ab42: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO |
||
772 | * Example output using %DUMP_PREFIX_ADDRESS and 4-byte mode: |
||
773 | * ffffffff88089af0: 73727170 77767574 7b7a7978 7f7e7d7c pqrstuvwxyz{|}~. |
||
774 | */ |
||
775 | void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, |
||
776 | int rowsize, int groupsize, |
||
777 | const void *buf, size_t len, bool ascii) |
||
778 | { |
||
779 | const u8 *ptr = buf; |
||
780 | int i, linelen, remaining = len; |
||
781 | unsigned char linebuf[32 * 3 + 2 + 32 + 1]; |
||
782 | |||
783 | if (rowsize != 16 && rowsize != 32) |
||
784 | rowsize = 16; |
||
785 | |||
786 | for (i = 0; i < len; i += rowsize) { |
||
787 | linelen = min(remaining, rowsize); |
||
788 | remaining -= rowsize; |
||
789 | |||
790 | hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize, |
||
791 | linebuf, sizeof(linebuf), ascii); |
||
792 | |||
793 | switch (prefix_type) { |
||
794 | case DUMP_PREFIX_ADDRESS: |
||
795 | printk("%s%s%p: %s\n", |
||
796 | level, prefix_str, ptr + i, linebuf); |
||
797 | break; |
||
798 | case DUMP_PREFIX_OFFSET: |
||
799 | printk("%s%s%.8x: %s\n", level, prefix_str, i, linebuf); |
||
800 | break; |
||
801 | default: |
||
802 | printk("%s%s%s\n", level, prefix_str, linebuf); |
||
803 | break; |
||
804 | } |
||
805 | } |
||
806 | } |
||
807 | |||
808 | void print_hex_dump_bytes(const char *prefix_str, int prefix_type, |
||
809 | const void *buf, size_t len) |
||
810 | { |
||
811 | print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, 16, 1, |
||
812 | buf, len, true); |
||
813 | } |
||
814 | |||
815 | |||
4080 | Serge | 816 | |
817 | |||
818 | |||
819 | |||
820 | |||
821 | |||
822 | |||
823 | |||
824 | |||
825 | |||
826 | #include "vmwgfx_kms.h" |
||
827 | |||
828 | void kms_update(); |
||
829 | |||
830 | //#define iowrite32(v, addr) writel((v), (addr)) |
||
831 | |||
832 | //#include "bitmap.h" |
||
833 | |||
834 | extern struct drm_device *main_device; |
||
835 | |||
836 | typedef struct |
||
837 | { |
||
838 | kobj_t header; |
||
839 | |||
840 | uint32_t *data; |
||
841 | uint32_t hot_x; |
||
842 | uint32_t hot_y; |
||
843 | |||
844 | struct list_head list; |
||
845 | // struct drm_i915_gem_object *cobj; |
||
846 | }cursor_t; |
||
847 | |||
848 | #define CURSOR_WIDTH 64 |
||
849 | #define CURSOR_HEIGHT 64 |
||
850 | |||
851 | struct tag_display |
||
852 | { |
||
853 | int x; |
||
854 | int y; |
||
855 | int width; |
||
856 | int height; |
||
857 | int bpp; |
||
858 | int vrefresh; |
||
859 | int pitch; |
||
860 | int lfb; |
||
861 | |||
862 | int supported_modes; |
||
863 | struct drm_device *ddev; |
||
864 | struct drm_connector *connector; |
||
865 | struct drm_crtc *crtc; |
||
866 | |||
867 | struct list_head cursors; |
||
868 | |||
869 | cursor_t *cursor; |
||
870 | int (*init_cursor)(cursor_t*); |
||
871 | cursor_t* (__stdcall *select_cursor)(cursor_t*); |
||
872 | void (*show_cursor)(int show); |
||
873 | void (__stdcall *move_cursor)(cursor_t *cursor, int x, int y); |
||
874 | void (__stdcall *restore_cursor)(int x, int y); |
||
875 | void (*disable_mouse)(void); |
||
876 | u32 mask_seqno; |
||
877 | u32 check_mouse; |
||
878 | u32 check_m_pixel; |
||
879 | }; |
||
880 | |||
4111 | Serge | 881 | |
4080 | Serge | 882 | static display_t *os_display; |
883 | |||
884 | static int count_connector_modes(struct drm_connector* connector) |
||
885 | { |
||
886 | struct drm_display_mode *mode; |
||
887 | int count = 0; |
||
888 | |||
889 | list_for_each_entry(mode, &connector->modes, head) |
||
890 | { |
||
891 | count++; |
||
892 | }; |
||
893 | return count; |
||
894 | }; |
||
895 | |||
896 | int kms_init(struct drm_device *dev) |
||
897 | { |
||
898 | struct drm_connector *connector; |
||
899 | struct drm_connector_helper_funcs *connector_funcs; |
||
900 | struct drm_encoder *encoder; |
||
901 | struct drm_crtc *crtc = NULL; |
||
902 | struct drm_framebuffer *fb; |
||
903 | |||
904 | cursor_t *cursor; |
||
905 | int mode_count; |
||
906 | u32_t ifl; |
||
907 | int err; |
||
908 | |||
909 | ENTER(); |
||
910 | |||
911 | crtc = list_entry(dev->mode_config.crtc_list.next, typeof(*crtc), head); |
||
912 | encoder = list_entry(dev->mode_config.encoder_list.next, typeof(*encoder), head); |
||
913 | connector = list_entry(dev->mode_config.connector_list.next, typeof(*connector), head); |
||
914 | connector->encoder = encoder; |
||
915 | |||
916 | mode_count = count_connector_modes(connector); |
||
917 | if(mode_count == 0) |
||
918 | { |
||
919 | struct drm_display_mode *mode; |
||
920 | |||
921 | connector->funcs->fill_modes(connector, |
||
922 | dev->mode_config.max_width, |
||
923 | dev->mode_config.max_height); |
||
924 | |||
925 | list_for_each_entry(mode, &connector->modes, head) |
||
926 | mode_count++; |
||
927 | }; |
||
928 | |||
929 | printf("%s %d\n",__FUNCTION__, mode_count); |
||
930 | |||
931 | DRM_DEBUG_KMS("CONNECTOR %x ID:%d status:%d ENCODER %x CRTC %x ID:%d\n", |
||
932 | connector, connector->base.id, |
||
933 | connector->status, connector->encoder, |
||
934 | crtc, crtc->base.id ); |
||
935 | |||
936 | DRM_DEBUG_KMS("[Select CRTC:%d]\n", crtc->base.id); |
||
937 | |||
938 | os_display = GetDisplay(); |
||
939 | |||
940 | ifl = safe_cli(); |
||
941 | { |
||
942 | os_display->ddev = dev; |
||
943 | os_display->connector = connector; |
||
944 | os_display->crtc = crtc; |
||
945 | os_display->supported_modes = mode_count; |
||
4111 | Serge | 946 | // os_display->update = kms_update; |
4080 | Serge | 947 | |
948 | // struct intel_crtc *intel_crtc = to_intel_crtc(os_display->crtc); |
||
949 | |||
950 | // list_for_each_entry(cursor, &os_display->cursors, list) |
||
951 | // { |
||
952 | // init_cursor(cursor); |
||
953 | // }; |
||
954 | |||
955 | // os_display->restore_cursor(0,0); |
||
956 | // os_display->init_cursor = init_cursor; |
||
957 | // os_display->select_cursor = select_cursor_kms; |
||
958 | // os_display->show_cursor = NULL; |
||
959 | // os_display->move_cursor = move_cursor_kms; |
||
960 | // os_display->restore_cursor = restore_cursor; |
||
961 | // os_display->disable_mouse = disable_mouse; |
||
962 | |||
963 | // intel_crtc->cursor_x = os_display->width/2; |
||
964 | // intel_crtc->cursor_y = os_display->height/2; |
||
965 | |||
966 | // select_cursor_kms(os_display->cursor); |
||
967 | }; |
||
968 | safe_sti(ifl); |
||
969 | |||
970 | #ifdef __HWA__ |
||
971 | err = init_bitmaps(); |
||
972 | #endif |
||
973 | |||
974 | LEAVE(); |
||
975 | |||
976 | return 0; |
||
977 | }; |
||
978 | |||
979 | |||
980 | void kms_update() |
||
981 | { |
||
982 | struct vmw_private *dev_priv = vmw_priv(main_device); |
||
983 | size_t fifo_size; |
||
984 | int i; |
||
985 | |||
986 | struct { |
||
987 | uint32_t header; |
||
988 | SVGAFifoCmdUpdate body; |
||
989 | } *cmd; |
||
990 | |||
991 | fifo_size = sizeof(*cmd); |
||
992 | |||
993 | cmd = vmw_fifo_reserve(dev_priv, fifo_size); |
||
994 | if (unlikely(cmd == NULL)) { |
||
995 | DRM_ERROR("Fifo reserve failed.\n"); |
||
996 | return; |
||
997 | } |
||
998 | |||
999 | cmd->header = cpu_to_le32(SVGA_CMD_UPDATE); |
||
1000 | cmd->body.x = 0; |
||
1001 | cmd->body.y = 0; |
||
1002 | cmd->body.width = os_display->width; //cpu_to_le32(clips->x2 - clips->x1); |
||
1003 | cmd->body.height = os_display->height; //cpu_to_le32(clips->y2 - clips->y1); |
||
1004 | |||
1005 | vmw_fifo_commit(dev_priv, fifo_size); |
||
1006 | } |
||
1007 | |||
1008 | int get_videomodes(videomode_t *mode, int *count) |
||
1009 | { |
||
1010 | int err = -1; |
||
1011 | |||
1012 | dbgprintf("mode %x count %d\n", mode, *count); |
||
1013 | |||
1014 | if( *count == 0 ) |
||
1015 | { |
||
1016 | *count = os_display->supported_modes; |
||
1017 | err = 0; |
||
1018 | } |
||
1019 | else if( mode != NULL ) |
||
1020 | { |
||
1021 | struct drm_display_mode *drmmode; |
||
1022 | int i = 0; |
||
1023 | |||
1024 | if( *count > os_display->supported_modes) |
||
1025 | *count = os_display->supported_modes; |
||
1026 | |||
1027 | list_for_each_entry(drmmode, &os_display->connector->modes, head) |
||
1028 | { |
||
1029 | if( i < *count) |
||
1030 | { |
||
1031 | mode->width = drm_mode_width(drmmode); |
||
1032 | mode->height = drm_mode_height(drmmode); |
||
1033 | mode->bpp = 32; |
||
1034 | mode->freq = drm_mode_vrefresh(drmmode); |
||
1035 | i++; |
||
1036 | mode++; |
||
1037 | } |
||
1038 | else break; |
||
1039 | }; |
||
1040 | *count = i; |
||
1041 | err = 0; |
||
1042 | }; |
||
1043 | return err; |
||
1044 | }; |
||
1045 | |||
1046 | |||
1047 | bool set_mode(struct drm_device *dev, struct drm_connector *connector, |
||
1048 | videomode_t *reqmode, bool strict); |
||
1049 | |||
1050 | |||
1051 | int set_user_mode(videomode_t *mode) |
||
1052 | { |
||
1053 | int err = -1; |
||
1054 | |||
1055 | dbgprintf("width %d height %d vrefresh %d\n", |
||
1056 | mode->width, mode->height, mode->freq); |
||
1057 | |||
1058 | if( (mode->width != 0) && |
||
1059 | (mode->height != 0) && |
||
1060 | (mode->freq != 0 ) && |
||
1061 | ( (mode->width != os_display->width) || |
||
1062 | (mode->height != os_display->height) || |
||
1063 | (mode->freq != os_display->vrefresh) ) ) |
||
1064 | { |
||
1065 | if( set_mode(os_display->ddev, os_display->connector, mode, true) ) |
||
1066 | err = 0; |
||
1067 | }; |
||
1068 | |||
1069 | return err; |
||
1070 | }; |
||
1071 | |||
4111 | Serge | 1072 | struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags) |
1073 | { |
||
1074 | struct file *filep; |
||
1075 | int count; |
||
1076 | |||
1077 | filep = malloc(sizeof(*filep)); |
||
1078 | |||
1079 | if(unlikely(filep == NULL)) |
||
1080 | return ERR_PTR(-ENOMEM); |
||
1081 | |||
1082 | count = size / PAGE_SIZE; |
||
1083 | |||
1084 | filep->pages = kzalloc(sizeof(struct page *) * count, 0); |
||
1085 | if(unlikely(filep->pages == NULL)) |
||
1086 | { |
||
1087 | kfree(filep); |
||
1088 | return ERR_PTR(-ENOMEM); |
||
1089 | }; |
||
1090 | |||
1091 | filep->count = count; |
||
1092 | filep->allocated = 0; |
||
1093 | filep->vma = NULL; |
||
1094 | |||
1095 | // printf("%s file %p pages %p count %d\n", |
||
1096 | // __FUNCTION__,filep, filep->pages, count); |
||
1097 | |||
1098 | return filep; |
||
1099 | } |
||
1100 | |||
1101 | struct page *shmem_read_mapping_page_gfp(struct file *filep, |
||
1102 | pgoff_t index, gfp_t gfp) |
||
1103 | { |
||
1104 | struct page *page; |
||
1105 | |||
1106 | // dbgprintf("%s, file %p index %d\n", __FUNCTION__, filep, index); |
||
1107 | |||
1108 | if(unlikely(index >= filep->count)) |
||
1109 | return ERR_PTR(-EINVAL); |
||
1110 | |||
1111 | page = filep->pages[index]; |
||
1112 | |||
1113 | if(unlikely(page == NULL)) |
||
1114 | { |
||
1115 | page = (struct page *)AllocPage(); |
||
1116 | |||
1117 | if(unlikely(page == NULL)) |
||
1118 | return ERR_PTR(-ENOMEM); |
||
1119 | |||
1120 | filep->pages[index] = page; |
||
1121 | }; |
||
1122 | |||
1123 | return page; |
||
1124 | };>>>>>>=>>>>>><>>>=>=>=0x7f) |
||
1125 |