ptrace/x86: revert "hw_breakpoints: Fix racy access to ptrace breakpoints"
[linux-2.6.git] / drivers / video / hyperv_fb.c
blobd4d2c5fe24882c045c55ac19e310e5f4638c08e0
1 /*
2 * Copyright (c) 2012, Microsoft Corporation.
4 * Author:
5 * Haiyang Zhang <haiyangz@microsoft.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
14 * NON INFRINGEMENT. See the GNU General Public License for more
15 * details.
19 * Hyper-V Synthetic Video Frame Buffer Driver
21 * This is the driver for the Hyper-V Synthetic Video, which supports
22 * screen resolution up to Full HD 1920x1080 with 32 bit color on Windows
23 * Server 2012, and 1600x1200 with 16 bit color on Windows Server 2008 R2
24 * or earlier.
26 * It also solves the double mouse cursor issue of the emulated video mode.
28 * The default screen resolution is 1152x864, which may be changed by a
29 * kernel parameter:
30 * video=hyperv_fb:<width>x<height>
31 * For example: video=hyperv_fb:1280x1024
33 * Portrait orientation is also supported:
34 * For example: video=hyperv_fb:864x1152
37 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
39 #include <linux/module.h>
40 #include <linux/kernel.h>
41 #include <linux/init.h>
42 #include <linux/completion.h>
43 #include <linux/fb.h>
44 #include <linux/pci.h>
46 #include <linux/hyperv.h>
49 /* Hyper-V Synthetic Video Protocol definitions and structures */
50 #define MAX_VMBUS_PKT_SIZE 0x4000
52 #define SYNTHVID_VERSION(major, minor) ((minor) << 16 | (major))
53 #define SYNTHVID_VERSION_WIN7 SYNTHVID_VERSION(3, 0)
54 #define SYNTHVID_VERSION_WIN8 SYNTHVID_VERSION(3, 2)
56 #define SYNTHVID_DEPTH_WIN7 16
57 #define SYNTHVID_DEPTH_WIN8 32
59 #define SYNTHVID_FB_SIZE_WIN7 (4 * 1024 * 1024)
60 #define SYNTHVID_WIDTH_MAX_WIN7 1600
61 #define SYNTHVID_HEIGHT_MAX_WIN7 1200
63 #define SYNTHVID_FB_SIZE_WIN8 (8 * 1024 * 1024)
65 #define PCI_VENDOR_ID_MICROSOFT 0x1414
66 #define PCI_DEVICE_ID_HYPERV_VIDEO 0x5353
69 enum pipe_msg_type {
70 PIPE_MSG_INVALID,
71 PIPE_MSG_DATA,
72 PIPE_MSG_MAX
75 struct pipe_msg_hdr {
76 u32 type;
77 u32 size; /* size of message after this field */
78 } __packed;
81 enum synthvid_msg_type {
82 SYNTHVID_ERROR = 0,
83 SYNTHVID_VERSION_REQUEST = 1,
84 SYNTHVID_VERSION_RESPONSE = 2,
85 SYNTHVID_VRAM_LOCATION = 3,
86 SYNTHVID_VRAM_LOCATION_ACK = 4,
87 SYNTHVID_SITUATION_UPDATE = 5,
88 SYNTHVID_SITUATION_UPDATE_ACK = 6,
89 SYNTHVID_POINTER_POSITION = 7,
90 SYNTHVID_POINTER_SHAPE = 8,
91 SYNTHVID_FEATURE_CHANGE = 9,
92 SYNTHVID_DIRT = 10,
94 SYNTHVID_MAX = 11
97 struct synthvid_msg_hdr {
98 u32 type;
99 u32 size; /* size of this header + payload after this field*/
100 } __packed;
103 struct synthvid_version_req {
104 u32 version;
105 } __packed;
107 struct synthvid_version_resp {
108 u32 version;
109 u8 is_accepted;
110 u8 max_video_outputs;
111 } __packed;
113 struct synthvid_vram_location {
114 u64 user_ctx;
115 u8 is_vram_gpa_specified;
116 u64 vram_gpa;
117 } __packed;
119 struct synthvid_vram_location_ack {
120 u64 user_ctx;
121 } __packed;
123 struct video_output_situation {
124 u8 active;
125 u32 vram_offset;
126 u8 depth_bits;
127 u32 width_pixels;
128 u32 height_pixels;
129 u32 pitch_bytes;
130 } __packed;
132 struct synthvid_situation_update {
133 u64 user_ctx;
134 u8 video_output_count;
135 struct video_output_situation video_output[1];
136 } __packed;
138 struct synthvid_situation_update_ack {
139 u64 user_ctx;
140 } __packed;
142 struct synthvid_pointer_position {
143 u8 is_visible;
144 u8 video_output;
145 s32 image_x;
146 s32 image_y;
147 } __packed;
150 #define CURSOR_MAX_X 96
151 #define CURSOR_MAX_Y 96
152 #define CURSOR_ARGB_PIXEL_SIZE 4
153 #define CURSOR_MAX_SIZE (CURSOR_MAX_X * CURSOR_MAX_Y * CURSOR_ARGB_PIXEL_SIZE)
154 #define CURSOR_COMPLETE (-1)
156 struct synthvid_pointer_shape {
157 u8 part_idx;
158 u8 is_argb;
159 u32 width; /* CURSOR_MAX_X at most */
160 u32 height; /* CURSOR_MAX_Y at most */
161 u32 hot_x; /* hotspot relative to upper-left of pointer image */
162 u32 hot_y;
163 u8 data[4];
164 } __packed;
166 struct synthvid_feature_change {
167 u8 is_dirt_needed;
168 u8 is_ptr_pos_needed;
169 u8 is_ptr_shape_needed;
170 u8 is_situ_needed;
171 } __packed;
173 struct rect {
174 s32 x1, y1; /* top left corner */
175 s32 x2, y2; /* bottom right corner, exclusive */
176 } __packed;
178 struct synthvid_dirt {
179 u8 video_output;
180 u8 dirt_count;
181 struct rect rect[1];
182 } __packed;
184 struct synthvid_msg {
185 struct pipe_msg_hdr pipe_hdr;
186 struct synthvid_msg_hdr vid_hdr;
187 union {
188 struct synthvid_version_req ver_req;
189 struct synthvid_version_resp ver_resp;
190 struct synthvid_vram_location vram;
191 struct synthvid_vram_location_ack vram_ack;
192 struct synthvid_situation_update situ;
193 struct synthvid_situation_update_ack situ_ack;
194 struct synthvid_pointer_position ptr_pos;
195 struct synthvid_pointer_shape ptr_shape;
196 struct synthvid_feature_change feature_chg;
197 struct synthvid_dirt dirt;
199 } __packed;
203 /* FB driver definitions and structures */
204 #define HVFB_WIDTH 1152 /* default screen width */
205 #define HVFB_HEIGHT 864 /* default screen height */
206 #define HVFB_WIDTH_MIN 640
207 #define HVFB_HEIGHT_MIN 480
209 #define RING_BUFSIZE (256 * 1024)
210 #define VSP_TIMEOUT (10 * HZ)
211 #define HVFB_UPDATE_DELAY (HZ / 20)
213 struct hvfb_par {
214 struct fb_info *info;
215 bool fb_ready; /* fb device is ready */
216 struct completion wait;
217 u32 synthvid_version;
219 struct delayed_work dwork;
220 bool update;
222 u32 pseudo_palette[16];
223 u8 init_buf[MAX_VMBUS_PKT_SIZE];
224 u8 recv_buf[MAX_VMBUS_PKT_SIZE];
227 static uint screen_width = HVFB_WIDTH;
228 static uint screen_height = HVFB_HEIGHT;
229 static uint screen_depth;
230 static uint screen_fb_size;
232 /* Send message to Hyper-V host */
233 static inline int synthvid_send(struct hv_device *hdev,
234 struct synthvid_msg *msg)
236 static atomic64_t request_id = ATOMIC64_INIT(0);
237 int ret;
239 msg->pipe_hdr.type = PIPE_MSG_DATA;
240 msg->pipe_hdr.size = msg->vid_hdr.size;
242 ret = vmbus_sendpacket(hdev->channel, msg,
243 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
244 atomic64_inc_return(&request_id),
245 VM_PKT_DATA_INBAND, 0);
247 if (ret)
248 pr_err("Unable to send packet via vmbus\n");
250 return ret;
254 /* Send screen resolution info to host */
255 static int synthvid_send_situ(struct hv_device *hdev)
257 struct fb_info *info = hv_get_drvdata(hdev);
258 struct synthvid_msg msg;
260 if (!info)
261 return -ENODEV;
263 memset(&msg, 0, sizeof(struct synthvid_msg));
265 msg.vid_hdr.type = SYNTHVID_SITUATION_UPDATE;
266 msg.vid_hdr.size = sizeof(struct synthvid_msg_hdr) +
267 sizeof(struct synthvid_situation_update);
268 msg.situ.user_ctx = 0;
269 msg.situ.video_output_count = 1;
270 msg.situ.video_output[0].active = 1;
271 msg.situ.video_output[0].vram_offset = 0;
272 msg.situ.video_output[0].depth_bits = info->var.bits_per_pixel;
273 msg.situ.video_output[0].width_pixels = info->var.xres;
274 msg.situ.video_output[0].height_pixels = info->var.yres;
275 msg.situ.video_output[0].pitch_bytes = info->fix.line_length;
277 synthvid_send(hdev, &msg);
279 return 0;
282 /* Send mouse pointer info to host */
283 static int synthvid_send_ptr(struct hv_device *hdev)
285 struct synthvid_msg msg;
287 memset(&msg, 0, sizeof(struct synthvid_msg));
288 msg.vid_hdr.type = SYNTHVID_POINTER_POSITION;
289 msg.vid_hdr.size = sizeof(struct synthvid_msg_hdr) +
290 sizeof(struct synthvid_pointer_position);
291 msg.ptr_pos.is_visible = 1;
292 msg.ptr_pos.video_output = 0;
293 msg.ptr_pos.image_x = 0;
294 msg.ptr_pos.image_y = 0;
295 synthvid_send(hdev, &msg);
297 memset(&msg, 0, sizeof(struct synthvid_msg));
298 msg.vid_hdr.type = SYNTHVID_POINTER_SHAPE;
299 msg.vid_hdr.size = sizeof(struct synthvid_msg_hdr) +
300 sizeof(struct synthvid_pointer_shape);
301 msg.ptr_shape.part_idx = CURSOR_COMPLETE;
302 msg.ptr_shape.is_argb = 1;
303 msg.ptr_shape.width = 1;
304 msg.ptr_shape.height = 1;
305 msg.ptr_shape.hot_x = 0;
306 msg.ptr_shape.hot_y = 0;
307 msg.ptr_shape.data[0] = 0;
308 msg.ptr_shape.data[1] = 1;
309 msg.ptr_shape.data[2] = 1;
310 msg.ptr_shape.data[3] = 1;
311 synthvid_send(hdev, &msg);
313 return 0;
316 /* Send updated screen area (dirty rectangle) location to host */
317 static int synthvid_update(struct fb_info *info)
319 struct hv_device *hdev = device_to_hv_device(info->device);
320 struct synthvid_msg msg;
322 memset(&msg, 0, sizeof(struct synthvid_msg));
324 msg.vid_hdr.type = SYNTHVID_DIRT;
325 msg.vid_hdr.size = sizeof(struct synthvid_msg_hdr) +
326 sizeof(struct synthvid_dirt);
327 msg.dirt.video_output = 0;
328 msg.dirt.dirt_count = 1;
329 msg.dirt.rect[0].x1 = 0;
330 msg.dirt.rect[0].y1 = 0;
331 msg.dirt.rect[0].x2 = info->var.xres;
332 msg.dirt.rect[0].y2 = info->var.yres;
334 synthvid_send(hdev, &msg);
336 return 0;
341 * Actions on received messages from host:
342 * Complete the wait event.
343 * Or, reply with screen and cursor info.
345 static void synthvid_recv_sub(struct hv_device *hdev)
347 struct fb_info *info = hv_get_drvdata(hdev);
348 struct hvfb_par *par;
349 struct synthvid_msg *msg;
351 if (!info)
352 return;
354 par = info->par;
355 msg = (struct synthvid_msg *)par->recv_buf;
357 /* Complete the wait event */
358 if (msg->vid_hdr.type == SYNTHVID_VERSION_RESPONSE ||
359 msg->vid_hdr.type == SYNTHVID_VRAM_LOCATION_ACK) {
360 memcpy(par->init_buf, msg, MAX_VMBUS_PKT_SIZE);
361 complete(&par->wait);
362 return;
365 /* Reply with screen and cursor info */
366 if (msg->vid_hdr.type == SYNTHVID_FEATURE_CHANGE) {
367 if (par->fb_ready) {
368 synthvid_send_ptr(hdev);
369 synthvid_send_situ(hdev);
372 par->update = msg->feature_chg.is_dirt_needed;
373 if (par->update)
374 schedule_delayed_work(&par->dwork, HVFB_UPDATE_DELAY);
378 /* Receive callback for messages from the host */
379 static void synthvid_receive(void *ctx)
381 struct hv_device *hdev = ctx;
382 struct fb_info *info = hv_get_drvdata(hdev);
383 struct hvfb_par *par;
384 struct synthvid_msg *recv_buf;
385 u32 bytes_recvd;
386 u64 req_id;
387 int ret;
389 if (!info)
390 return;
392 par = info->par;
393 recv_buf = (struct synthvid_msg *)par->recv_buf;
395 do {
396 ret = vmbus_recvpacket(hdev->channel, recv_buf,
397 MAX_VMBUS_PKT_SIZE,
398 &bytes_recvd, &req_id);
399 if (bytes_recvd > 0 &&
400 recv_buf->pipe_hdr.type == PIPE_MSG_DATA)
401 synthvid_recv_sub(hdev);
402 } while (bytes_recvd > 0 && ret == 0);
405 /* Check synthetic video protocol version with the host */
406 static int synthvid_negotiate_ver(struct hv_device *hdev, u32 ver)
408 struct fb_info *info = hv_get_drvdata(hdev);
409 struct hvfb_par *par = info->par;
410 struct synthvid_msg *msg = (struct synthvid_msg *)par->init_buf;
411 int t, ret = 0;
413 memset(msg, 0, sizeof(struct synthvid_msg));
414 msg->vid_hdr.type = SYNTHVID_VERSION_REQUEST;
415 msg->vid_hdr.size = sizeof(struct synthvid_msg_hdr) +
416 sizeof(struct synthvid_version_req);
417 msg->ver_req.version = ver;
418 synthvid_send(hdev, msg);
420 t = wait_for_completion_timeout(&par->wait, VSP_TIMEOUT);
421 if (!t) {
422 pr_err("Time out on waiting version response\n");
423 ret = -ETIMEDOUT;
424 goto out;
426 if (!msg->ver_resp.is_accepted) {
427 ret = -ENODEV;
428 goto out;
431 par->synthvid_version = ver;
433 out:
434 return ret;
437 /* Connect to VSP (Virtual Service Provider) on host */
438 static int synthvid_connect_vsp(struct hv_device *hdev)
440 struct fb_info *info = hv_get_drvdata(hdev);
441 struct hvfb_par *par = info->par;
442 int ret;
444 ret = vmbus_open(hdev->channel, RING_BUFSIZE, RING_BUFSIZE,
445 NULL, 0, synthvid_receive, hdev);
446 if (ret) {
447 pr_err("Unable to open vmbus channel\n");
448 return ret;
451 /* Negotiate the protocol version with host */
452 if (vmbus_proto_version == VERSION_WS2008 ||
453 vmbus_proto_version == VERSION_WIN7)
454 ret = synthvid_negotiate_ver(hdev, SYNTHVID_VERSION_WIN7);
455 else
456 ret = synthvid_negotiate_ver(hdev, SYNTHVID_VERSION_WIN8);
458 if (ret) {
459 pr_err("Synthetic video device version not accepted\n");
460 goto error;
463 if (par->synthvid_version == SYNTHVID_VERSION_WIN7) {
464 screen_depth = SYNTHVID_DEPTH_WIN7;
465 screen_fb_size = SYNTHVID_FB_SIZE_WIN7;
466 } else {
467 screen_depth = SYNTHVID_DEPTH_WIN8;
468 screen_fb_size = SYNTHVID_FB_SIZE_WIN8;
471 return 0;
473 error:
474 vmbus_close(hdev->channel);
475 return ret;
478 /* Send VRAM and Situation messages to the host */
479 static int synthvid_send_config(struct hv_device *hdev)
481 struct fb_info *info = hv_get_drvdata(hdev);
482 struct hvfb_par *par = info->par;
483 struct synthvid_msg *msg = (struct synthvid_msg *)par->init_buf;
484 int t, ret = 0;
486 /* Send VRAM location */
487 memset(msg, 0, sizeof(struct synthvid_msg));
488 msg->vid_hdr.type = SYNTHVID_VRAM_LOCATION;
489 msg->vid_hdr.size = sizeof(struct synthvid_msg_hdr) +
490 sizeof(struct synthvid_vram_location);
491 msg->vram.user_ctx = msg->vram.vram_gpa = info->fix.smem_start;
492 msg->vram.is_vram_gpa_specified = 1;
493 synthvid_send(hdev, msg);
495 t = wait_for_completion_timeout(&par->wait, VSP_TIMEOUT);
496 if (!t) {
497 pr_err("Time out on waiting vram location ack\n");
498 ret = -ETIMEDOUT;
499 goto out;
501 if (msg->vram_ack.user_ctx != info->fix.smem_start) {
502 pr_err("Unable to set VRAM location\n");
503 ret = -ENODEV;
504 goto out;
507 /* Send pointer and situation update */
508 synthvid_send_ptr(hdev);
509 synthvid_send_situ(hdev);
511 out:
512 return ret;
517 * Delayed work callback:
518 * It is called at HVFB_UPDATE_DELAY or longer time interval to process
519 * screen updates. It is re-scheduled if further update is necessary.
521 static void hvfb_update_work(struct work_struct *w)
523 struct hvfb_par *par = container_of(w, struct hvfb_par, dwork.work);
524 struct fb_info *info = par->info;
526 if (par->fb_ready)
527 synthvid_update(info);
529 if (par->update)
530 schedule_delayed_work(&par->dwork, HVFB_UPDATE_DELAY);
534 /* Framebuffer operation handlers */
536 static int hvfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
538 if (var->xres < HVFB_WIDTH_MIN || var->yres < HVFB_HEIGHT_MIN ||
539 var->xres > screen_width || var->yres > screen_height ||
540 var->bits_per_pixel != screen_depth)
541 return -EINVAL;
543 var->xres_virtual = var->xres;
544 var->yres_virtual = var->yres;
546 return 0;
549 static int hvfb_set_par(struct fb_info *info)
551 struct hv_device *hdev = device_to_hv_device(info->device);
553 return synthvid_send_situ(hdev);
557 static inline u32 chan_to_field(u32 chan, struct fb_bitfield *bf)
559 return ((chan & 0xffff) >> (16 - bf->length)) << bf->offset;
562 static int hvfb_setcolreg(unsigned regno, unsigned red, unsigned green,
563 unsigned blue, unsigned transp, struct fb_info *info)
565 u32 *pal = info->pseudo_palette;
567 if (regno > 15)
568 return -EINVAL;
570 pal[regno] = chan_to_field(red, &info->var.red)
571 | chan_to_field(green, &info->var.green)
572 | chan_to_field(blue, &info->var.blue)
573 | chan_to_field(transp, &info->var.transp);
575 return 0;
579 static struct fb_ops hvfb_ops = {
580 .owner = THIS_MODULE,
581 .fb_check_var = hvfb_check_var,
582 .fb_set_par = hvfb_set_par,
583 .fb_setcolreg = hvfb_setcolreg,
584 .fb_fillrect = cfb_fillrect,
585 .fb_copyarea = cfb_copyarea,
586 .fb_imageblit = cfb_imageblit,
590 /* Get options from kernel paramenter "video=" */
591 static void hvfb_get_option(struct fb_info *info)
593 struct hvfb_par *par = info->par;
594 char *opt = NULL, *p;
595 uint x = 0, y = 0;
597 if (fb_get_options(KBUILD_MODNAME, &opt) || !opt || !*opt)
598 return;
600 p = strsep(&opt, "x");
601 if (!*p || kstrtouint(p, 0, &x) ||
602 !opt || !*opt || kstrtouint(opt, 0, &y)) {
603 pr_err("Screen option is invalid: skipped\n");
604 return;
607 if (x < HVFB_WIDTH_MIN || y < HVFB_HEIGHT_MIN ||
608 (par->synthvid_version == SYNTHVID_VERSION_WIN8 &&
609 x * y * screen_depth / 8 > SYNTHVID_FB_SIZE_WIN8) ||
610 (par->synthvid_version == SYNTHVID_VERSION_WIN7 &&
611 (x > SYNTHVID_WIDTH_MAX_WIN7 || y > SYNTHVID_HEIGHT_MAX_WIN7))) {
612 pr_err("Screen resolution option is out of range: skipped\n");
613 return;
616 screen_width = x;
617 screen_height = y;
618 return;
622 /* Get framebuffer memory from Hyper-V video pci space */
623 static int hvfb_getmem(struct fb_info *info)
625 struct pci_dev *pdev;
626 ulong fb_phys;
627 void __iomem *fb_virt;
629 pdev = pci_get_device(PCI_VENDOR_ID_MICROSOFT,
630 PCI_DEVICE_ID_HYPERV_VIDEO, NULL);
631 if (!pdev) {
632 pr_err("Unable to find PCI Hyper-V video\n");
633 return -ENODEV;
636 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM) ||
637 pci_resource_len(pdev, 0) < screen_fb_size)
638 goto err1;
640 fb_phys = pci_resource_end(pdev, 0) - screen_fb_size + 1;
641 if (!request_mem_region(fb_phys, screen_fb_size, KBUILD_MODNAME))
642 goto err1;
644 fb_virt = ioremap(fb_phys, screen_fb_size);
645 if (!fb_virt)
646 goto err2;
648 info->apertures = alloc_apertures(1);
649 if (!info->apertures)
650 goto err3;
652 info->apertures->ranges[0].base = pci_resource_start(pdev, 0);
653 info->apertures->ranges[0].size = pci_resource_len(pdev, 0);
654 info->fix.smem_start = fb_phys;
655 info->fix.smem_len = screen_fb_size;
656 info->screen_base = fb_virt;
657 info->screen_size = screen_fb_size;
659 pci_dev_put(pdev);
660 return 0;
662 err3:
663 iounmap(fb_virt);
664 err2:
665 release_mem_region(fb_phys, screen_fb_size);
666 err1:
667 pci_dev_put(pdev);
668 return -ENOMEM;
671 /* Release the framebuffer */
672 static void hvfb_putmem(struct fb_info *info)
674 iounmap(info->screen_base);
675 release_mem_region(info->fix.smem_start, screen_fb_size);
679 static int hvfb_probe(struct hv_device *hdev,
680 const struct hv_vmbus_device_id *dev_id)
682 struct fb_info *info;
683 struct hvfb_par *par;
684 int ret;
686 info = framebuffer_alloc(sizeof(struct hvfb_par), &hdev->device);
687 if (!info) {
688 pr_err("No memory for framebuffer info\n");
689 return -ENOMEM;
692 par = info->par;
693 par->info = info;
694 par->fb_ready = false;
695 init_completion(&par->wait);
696 INIT_DELAYED_WORK(&par->dwork, hvfb_update_work);
698 /* Connect to VSP */
699 hv_set_drvdata(hdev, info);
700 ret = synthvid_connect_vsp(hdev);
701 if (ret) {
702 pr_err("Unable to connect to VSP\n");
703 goto error1;
706 ret = hvfb_getmem(info);
707 if (ret) {
708 pr_err("No memory for framebuffer\n");
709 goto error2;
712 hvfb_get_option(info);
713 pr_info("Screen resolution: %dx%d, Color depth: %d\n",
714 screen_width, screen_height, screen_depth);
717 /* Set up fb_info */
718 info->flags = FBINFO_DEFAULT;
720 info->var.xres_virtual = info->var.xres = screen_width;
721 info->var.yres_virtual = info->var.yres = screen_height;
722 info->var.bits_per_pixel = screen_depth;
724 if (info->var.bits_per_pixel == 16) {
725 info->var.red = (struct fb_bitfield){11, 5, 0};
726 info->var.green = (struct fb_bitfield){5, 6, 0};
727 info->var.blue = (struct fb_bitfield){0, 5, 0};
728 info->var.transp = (struct fb_bitfield){0, 0, 0};
729 } else {
730 info->var.red = (struct fb_bitfield){16, 8, 0};
731 info->var.green = (struct fb_bitfield){8, 8, 0};
732 info->var.blue = (struct fb_bitfield){0, 8, 0};
733 info->var.transp = (struct fb_bitfield){24, 8, 0};
736 info->var.activate = FB_ACTIVATE_NOW;
737 info->var.height = -1;
738 info->var.width = -1;
739 info->var.vmode = FB_VMODE_NONINTERLACED;
741 strcpy(info->fix.id, KBUILD_MODNAME);
742 info->fix.type = FB_TYPE_PACKED_PIXELS;
743 info->fix.visual = FB_VISUAL_TRUECOLOR;
744 info->fix.line_length = screen_width * screen_depth / 8;
745 info->fix.accel = FB_ACCEL_NONE;
747 info->fbops = &hvfb_ops;
748 info->pseudo_palette = par->pseudo_palette;
750 /* Send config to host */
751 ret = synthvid_send_config(hdev);
752 if (ret)
753 goto error;
755 ret = register_framebuffer(info);
756 if (ret) {
757 pr_err("Unable to register framebuffer\n");
758 goto error;
761 par->fb_ready = true;
763 return 0;
765 error:
766 hvfb_putmem(info);
767 error2:
768 vmbus_close(hdev->channel);
769 error1:
770 cancel_delayed_work_sync(&par->dwork);
771 hv_set_drvdata(hdev, NULL);
772 framebuffer_release(info);
773 return ret;
777 static int hvfb_remove(struct hv_device *hdev)
779 struct fb_info *info = hv_get_drvdata(hdev);
780 struct hvfb_par *par = info->par;
782 par->update = false;
783 par->fb_ready = false;
785 unregister_framebuffer(info);
786 cancel_delayed_work_sync(&par->dwork);
788 vmbus_close(hdev->channel);
789 hv_set_drvdata(hdev, NULL);
791 hvfb_putmem(info);
792 framebuffer_release(info);
794 return 0;
798 static const struct hv_vmbus_device_id id_table[] = {
799 /* Synthetic Video Device GUID */
800 {HV_SYNTHVID_GUID},
804 MODULE_DEVICE_TABLE(vmbus, id_table);
806 static struct hv_driver hvfb_drv = {
807 .name = KBUILD_MODNAME,
808 .id_table = id_table,
809 .probe = hvfb_probe,
810 .remove = hvfb_remove,
814 static int __init hvfb_drv_init(void)
816 return vmbus_driver_register(&hvfb_drv);
819 static void __exit hvfb_drv_exit(void)
821 vmbus_driver_unregister(&hvfb_drv);
824 module_init(hvfb_drv_init);
825 module_exit(hvfb_drv_exit);
827 MODULE_LICENSE("GPL");
828 MODULE_VERSION(HV_DRV_VERSION);
829 MODULE_DESCRIPTION("Microsoft Hyper-V Synthetic Video Frame Buffer Driver");