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