]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/hv/hv_mouse.c
Staging: hv: mousevsc: Cleanup and properly implement reportdesc_callback()
[karo-tx-linux.git] / drivers / staging / hv / hv_mouse.c
1 /*
2  *  Copyright (c) 2009, Citrix Systems, Inc.
3  *  Copyright (c) 2010, Microsoft Corporation.
4  *  Copyright (c) 2011, Novell Inc.
5  *
6  *  This program is free software; you can redistribute it and/or modify it
7  *  under the terms and conditions of the GNU General Public License,
8  *  version 2, as published by the Free Software Foundation.
9  *
10  *  This program is distributed in the hope it will be useful, but WITHOUT
11  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  *  more details.
14  */
15 #include <linux/init.h>
16 #include <linux/module.h>
17 #include <linux/delay.h>
18 #include <linux/device.h>
19 #include <linux/workqueue.h>
20 #include <linux/sched.h>
21 #include <linux/wait.h>
22 #include <linux/input.h>
23 #include <linux/hid.h>
24 #include <linux/hiddev.h>
25
26 #include "hyperv.h"
27
28
29 /*
30  * Data types
31  */
32 struct hv_input_dev_info {
33         unsigned int size;
34         unsigned short vendor;
35         unsigned short product;
36         unsigned short version;
37         unsigned short reserved[11];
38 };
39
40 /* The maximum size of a synthetic input message. */
41 #define SYNTHHID_MAX_INPUT_REPORT_SIZE 16
42
43 /*
44  * Current version
45  *
46  * History:
47  * Beta, RC < 2008/1/22        1,0
48  * RC > 2008/1/22              2,0
49  */
50 #define SYNTHHID_INPUT_VERSION_MAJOR    2
51 #define SYNTHHID_INPUT_VERSION_MINOR    0
52 #define SYNTHHID_INPUT_VERSION          (SYNTHHID_INPUT_VERSION_MINOR | \
53                                          (SYNTHHID_INPUT_VERSION_MAJOR << 16))
54
55
56 #pragma pack(push, 1)
57 /*
58  * Message types in the synthetic input protocol
59  */
60 enum synthhid_msg_type {
61         SynthHidProtocolRequest,
62         SynthHidProtocolResponse,
63         SynthHidInitialDeviceInfo,
64         SynthHidInitialDeviceInfoAck,
65         SynthHidInputReport,
66         SynthHidMax
67 };
68
69 /*
70  * Basic message structures.
71  */
72 struct synthhid_msg_hdr {
73         enum synthhid_msg_type type;
74         u32 size;
75 };
76
77 struct synthhid_msg {
78         struct synthhid_msg_hdr header;
79         char data[1]; /* Enclosed message */
80 };
81
82 union synthhid_version {
83         struct {
84                 u16 minor_version;
85                 u16 major_version;
86         };
87         u32 version;
88 };
89
90 /*
91  * Protocol messages
92  */
93 struct synthhid_protocol_request {
94         struct synthhid_msg_hdr header;
95         union synthhid_version version_requested;
96 };
97
98 struct synthhid_protocol_response {
99         struct synthhid_msg_hdr header;
100         union synthhid_version version_requested;
101         unsigned char approved;
102 };
103
104 struct synthhid_device_info {
105         struct synthhid_msg_hdr header;
106         struct hv_input_dev_info hid_dev_info;
107         struct hid_descriptor hid_descriptor;
108 };
109
110 struct synthhid_device_info_ack {
111         struct synthhid_msg_hdr header;
112         unsigned char reserved;
113 };
114
115 struct synthhid_input_report {
116         struct synthhid_msg_hdr header;
117         char buffer[1];
118 };
119
120 #pragma pack(pop)
121
122 #define INPUTVSC_SEND_RING_BUFFER_SIZE          (10*PAGE_SIZE)
123 #define INPUTVSC_RECV_RING_BUFFER_SIZE          (10*PAGE_SIZE)
124
125 #define NBITS(x) (((x)/BITS_PER_LONG)+1)
126
127 enum pipe_prot_msg_type {
128         PipeMessageInvalid = 0,
129         PipeMessageData,
130         PipeMessageMaximum
131 };
132
133
134 struct pipe_prt_msg {
135         enum pipe_prot_msg_type type;
136         u32 size;
137         char data[1];
138 };
139
140 /*
141  * Data types
142  */
143 struct  mousevsc_prt_msg {
144         enum pipe_prot_msg_type type;
145         u32 size;
146         union {
147                 struct synthhid_protocol_request request;
148                 struct synthhid_protocol_response response;
149                 struct synthhid_device_info_ack ack;
150         };
151 };
152
153 /*
154  * Represents an mousevsc device
155  */
156 struct mousevsc_dev {
157         struct hv_device        *device;
158         /* 0 indicates the device is being destroyed */
159         atomic_t                ref_count;
160         int                     num_outstanding_req;
161         unsigned char           init_complete;
162         struct mousevsc_prt_msg protocol_req;
163         struct mousevsc_prt_msg protocol_resp;
164         /* Synchronize the request/response if needed */
165         struct completion       wait_event;
166         int                     dev_info_status;
167
168         struct hid_descriptor   *hid_desc;
169         unsigned char           *report_desc;
170         u32                     report_desc_size;
171         struct hv_input_dev_info hid_dev_info;
172         int                     connected;
173         struct hid_device       *hid_device;
174 };
175
176
177 static struct mousevsc_dev *alloc_input_device(struct hv_device *device)
178 {
179         struct mousevsc_dev *input_dev;
180
181         input_dev = kzalloc(sizeof(struct mousevsc_dev), GFP_KERNEL);
182
183         if (!input_dev)
184                 return NULL;
185
186         /*
187          * Set to 2 to allow both inbound and outbound traffics
188          * (ie get_input_device() and must_get_input_device()) to proceed.
189          */
190         atomic_cmpxchg(&input_dev->ref_count, 0, 2);
191
192         input_dev->device = device;
193         hv_set_drvdata(device, input_dev);
194         init_completion(&input_dev->wait_event);
195
196         return input_dev;
197 }
198
199 static void free_input_device(struct mousevsc_dev *device)
200 {
201         WARN_ON(atomic_read(&device->ref_count) != 0);
202         kfree(device);
203 }
204
205 /*
206  * Get the inputdevice object if exists and its refcount > 1
207  */
208 static struct mousevsc_dev *get_input_device(struct hv_device *device)
209 {
210         struct mousevsc_dev *input_dev;
211
212         input_dev = hv_get_drvdata(device);
213
214 /*
215  *      FIXME
216  *      This sure isn't a valid thing to print for debugging, no matter
217  *      what the intention is...
218  *
219  *      printk(KERN_ERR "-------------------------> REFCOUNT = %d",
220  *             input_dev->ref_count);
221  */
222
223         if (input_dev && atomic_read(&input_dev->ref_count) > 1)
224                 atomic_inc(&input_dev->ref_count);
225         else
226                 input_dev = NULL;
227
228         return input_dev;
229 }
230
231 /*
232  * Get the inputdevice object iff exists and its refcount > 0
233  */
234 static struct mousevsc_dev *must_get_input_device(struct hv_device *device)
235 {
236         struct mousevsc_dev *input_dev;
237
238         input_dev = hv_get_drvdata(device);
239
240         if (input_dev && atomic_read(&input_dev->ref_count))
241                 atomic_inc(&input_dev->ref_count);
242         else
243                 input_dev = NULL;
244
245         return input_dev;
246 }
247
248 static void put_input_device(struct hv_device *device)
249 {
250         struct mousevsc_dev *input_dev;
251
252         input_dev = hv_get_drvdata(device);
253
254         atomic_dec(&input_dev->ref_count);
255 }
256
257 /*
258  * Drop ref count to 1 to effectively disable get_input_device()
259  */
260 static struct mousevsc_dev *release_input_device(struct hv_device *device)
261 {
262         struct mousevsc_dev *input_dev;
263
264         input_dev = hv_get_drvdata(device);
265
266         /* Busy wait until the ref drop to 2, then set it to 1  */
267         while (atomic_cmpxchg(&input_dev->ref_count, 2, 1) != 2)
268                 udelay(100);
269
270         return input_dev;
271 }
272
273 /*
274  * Drop ref count to 0. No one can use input_device object.
275  */
276 static struct mousevsc_dev *final_release_input_device(struct hv_device *device)
277 {
278         struct mousevsc_dev *input_dev;
279
280         input_dev = hv_get_drvdata(device);
281
282         /* Busy wait until the ref drop to 1, then set it to 0  */
283         while (atomic_cmpxchg(&input_dev->ref_count, 1, 0) != 1)
284                 udelay(100);
285
286         hv_set_drvdata(device, NULL);
287         return input_dev;
288 }
289
290 static void mousevsc_on_send_completion(struct hv_device *device,
291                                         struct vmpacket_descriptor *packet)
292 {
293         struct mousevsc_dev *input_dev;
294         void *request;
295
296         input_dev = must_get_input_device(device);
297         if (!input_dev) {
298                 pr_err("unable to get input device...device being destroyed?");
299                 return;
300         }
301
302         request = (void *)(unsigned long)packet->trans_id;
303
304         if (request == &input_dev->protocol_req) {
305                 /* FIXME */
306                 /* Shouldn't we be doing something here? */
307         }
308
309         put_input_device(device);
310 }
311
312 static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
313                                 struct synthhid_device_info *device_info)
314 {
315         int ret = 0;
316         struct hid_descriptor *desc;
317         struct mousevsc_prt_msg ack;
318
319         /* Assume success for now */
320         input_device->dev_info_status = 0;
321
322         /* Save the device attr */
323         memcpy(&input_device->hid_dev_info, &device_info->hid_dev_info,
324                 sizeof(struct hv_input_dev_info));
325
326         /* Save the hid desc */
327         desc = &device_info->hid_descriptor;
328         WARN_ON(desc->bLength == 0);
329
330         input_device->hid_desc = kzalloc(desc->bLength, GFP_ATOMIC);
331
332         if (!input_device->hid_desc) {
333                 pr_err("unable to allocate hid descriptor - size %d",
334                          desc->bLength);
335                 goto cleanup;
336         }
337
338         memcpy(input_device->hid_desc, desc, desc->bLength);
339
340         /* Save the report desc */
341         input_device->report_desc_size = desc->desc[0].wDescriptorLength;
342         if (input_device->report_desc_size == 0)
343                 goto cleanup;
344         input_device->report_desc = kzalloc(input_device->report_desc_size,
345                                           GFP_ATOMIC);
346
347         if (!input_device->report_desc) {
348                 pr_err("unable to allocate report descriptor - size %d",
349                            input_device->report_desc_size);
350                 goto cleanup;
351         }
352
353         memcpy(input_device->report_desc,
354                ((unsigned char *)desc) + desc->bLength,
355                desc->desc[0].wDescriptorLength);
356
357         /* Send the ack */
358         memset(&ack, 0, sizeof(struct mousevsc_prt_msg));
359
360         ack.type = PipeMessageData;
361         ack.size = sizeof(struct synthhid_device_info_ack);
362
363         ack.ack.header.type = SynthHidInitialDeviceInfoAck;
364         ack.ack.header.size = 1;
365         ack.ack.reserved = 0;
366
367         ret = vmbus_sendpacket(input_device->device->channel,
368                         &ack,
369                         sizeof(struct pipe_prt_msg) - sizeof(unsigned char) +
370                         sizeof(struct synthhid_device_info_ack),
371                         (unsigned long)&ack,
372                         VM_PKT_DATA_INBAND,
373                         VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
374         if (ret != 0) {
375                 pr_err("unable to send synthhid device info ack - ret %d",
376                            ret);
377                 goto cleanup;
378         }
379
380         complete(&input_device->wait_event);
381
382         return;
383
384 cleanup:
385         kfree(input_device->hid_desc);
386         input_device->hid_desc = NULL;
387
388         kfree(input_device->report_desc);
389         input_device->report_desc = NULL;
390
391         input_device->dev_info_status = -1;
392         complete(&input_device->wait_event);
393 }
394
395 static void mousevsc_on_receive_input_report(struct mousevsc_dev *input_device,
396                                 struct synthhid_input_report *input_report)
397 {
398         struct hv_driver *input_drv;
399
400         if (!input_device->init_complete) {
401                 pr_info("Initialization incomplete...ignoring input_report msg");
402                 return;
403         }
404
405         input_drv = drv_to_hv_drv(input_device->device->device.driver);
406
407
408         hid_input_report(input_device->hid_device,
409                               HID_INPUT_REPORT, input_report->buffer, input_report->header.size, 1);
410
411 }
412
413 static void mousevsc_on_receive(struct hv_device *device,
414                                 struct vmpacket_descriptor *packet)
415 {
416         struct pipe_prt_msg *pipe_msg;
417         struct synthhid_msg *hid_msg;
418         struct mousevsc_dev *input_dev;
419
420         input_dev = must_get_input_device(device);
421         if (!input_dev) {
422                 pr_err("unable to get input device...device being destroyed?");
423                 return;
424         }
425
426         pipe_msg = (struct pipe_prt_msg *)((unsigned long)packet +
427                                                 (packet->offset8 << 3));
428
429         if (pipe_msg->type != PipeMessageData) {
430                 pr_err("unknown pipe msg type - type %d len %d",
431                            pipe_msg->type, pipe_msg->size);
432                 put_input_device(device);
433                 return ;
434         }
435
436         hid_msg = (struct synthhid_msg *)&pipe_msg->data[0];
437
438         switch (hid_msg->header.type) {
439         case SynthHidProtocolResponse:
440                 memcpy(&input_dev->protocol_resp, pipe_msg,
441                        pipe_msg->size + sizeof(struct pipe_prt_msg) -
442                        sizeof(unsigned char));
443                 complete(&input_dev->wait_event);
444                 break;
445
446         case SynthHidInitialDeviceInfo:
447                 WARN_ON(pipe_msg->size < sizeof(struct hv_input_dev_info));
448
449                 /*
450                  * Parse out the device info into device attr,
451                  * hid desc and report desc
452                  */
453                 mousevsc_on_receive_device_info(input_dev,
454                         (struct synthhid_device_info *)&pipe_msg->data[0]);
455                 break;
456         case SynthHidInputReport:
457                 mousevsc_on_receive_input_report(input_dev,
458                         (struct synthhid_input_report *)&pipe_msg->data[0]);
459
460                 break;
461         default:
462                 pr_err("unsupported hid msg type - type %d len %d",
463                        hid_msg->header.type, hid_msg->header.size);
464                 break;
465         }
466
467         put_input_device(device);
468 }
469
470 static void mousevsc_on_channel_callback(void *context)
471 {
472         const int packetSize = 0x100;
473         int ret = 0;
474         struct hv_device *device = (struct hv_device *)context;
475         struct mousevsc_dev *input_dev;
476
477         u32 bytes_recvd;
478         u64 req_id;
479         unsigned char packet[0x100];
480         struct vmpacket_descriptor *desc;
481         unsigned char   *buffer = packet;
482         int     bufferlen = packetSize;
483
484         input_dev = must_get_input_device(device);
485
486         if (!input_dev) {
487                 pr_err("unable to get input device...device being destroyed?");
488                 return;
489         }
490
491         do {
492                 ret = vmbus_recvpacket_raw(device->channel, buffer,
493                                         bufferlen, &bytes_recvd, &req_id);
494
495                 if (ret == 0) {
496                         if (bytes_recvd > 0) {
497                                 desc = (struct vmpacket_descriptor *)buffer;
498
499                                 switch (desc->type) {
500                                 case VM_PKT_COMP:
501                                         mousevsc_on_send_completion(
502                                                 device, desc);
503                                         break;
504
505                                 case VM_PKT_DATA_INBAND:
506                                         mousevsc_on_receive(
507                                                 device, desc);
508                                         break;
509
510                                 default:
511                                         pr_err("unhandled packet type %d, tid %llx len %d\n",
512                                                    desc->type,
513                                                    req_id,
514                                                    bytes_recvd);
515                                         break;
516                                 }
517
518                                 /* reset */
519                                 if (bufferlen > packetSize) {
520                                         kfree(buffer);
521
522                                         buffer = packet;
523                                         bufferlen = packetSize;
524                                 }
525                         } else {
526                                 /*
527                                  * pr_debug("nothing else to read...");
528                                  * reset
529                                  */
530                                 if (bufferlen > packetSize) {
531                                         kfree(buffer);
532
533                                         buffer = packet;
534                                         bufferlen = packetSize;
535                                 }
536                                 break;
537                         }
538                 } else if (ret == -ENOBUFS) {
539                         /* Handle large packet */
540                         bufferlen = bytes_recvd;
541                         buffer = kzalloc(bytes_recvd, GFP_ATOMIC);
542
543                         if (buffer == NULL) {
544                                 buffer = packet;
545                                 bufferlen = packetSize;
546
547                                 /* Try again next time around */
548                                 pr_err("unable to allocate buffer of size %d!",
549                                        bytes_recvd);
550                                 break;
551                         }
552                 }
553         } while (1);
554
555         put_input_device(device);
556
557         return;
558 }
559
560 static int mousevsc_connect_to_vsp(struct hv_device *device)
561 {
562         int ret = 0;
563         int t;
564         struct mousevsc_dev *input_dev;
565         struct mousevsc_prt_msg *request;
566         struct mousevsc_prt_msg *response;
567
568         input_dev = get_input_device(device);
569
570         if (!input_dev) {
571                 pr_err("unable to get input device...device being destroyed?");
572                 return -1;
573         }
574
575
576         request = &input_dev->protocol_req;
577
578         /*
579          * Now, initiate the vsc/vsp initialization protocol on the open channel
580          */
581         memset(request, 0, sizeof(struct mousevsc_prt_msg));
582
583         request->type = PipeMessageData;
584         request->size = sizeof(struct synthhid_protocol_request);
585
586         request->request.header.type = SynthHidProtocolRequest;
587         request->request.header.size = sizeof(unsigned int);
588         request->request.version_requested.version = SYNTHHID_INPUT_VERSION;
589
590         pr_info("synthhid protocol request...");
591
592         ret = vmbus_sendpacket(device->channel, request,
593                                 sizeof(struct pipe_prt_msg) -
594                                 sizeof(unsigned char) +
595                                 sizeof(struct synthhid_protocol_request),
596                                 (unsigned long)request,
597                                 VM_PKT_DATA_INBAND,
598                                 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
599         if (ret != 0) {
600                 pr_err("unable to send synthhid protocol request.");
601                 goto cleanup;
602         }
603
604         t = wait_for_completion_timeout(&input_dev->wait_event, 5*HZ);
605         if (t == 0) {
606                 ret = -ETIMEDOUT;
607                 goto cleanup;
608         }
609
610         response = &input_dev->protocol_resp;
611
612         if (!response->response.approved) {
613                 pr_err("synthhid protocol request failed (version %d)",
614                        SYNTHHID_INPUT_VERSION);
615                 ret = -1;
616                 goto cleanup;
617         }
618
619         t = wait_for_completion_timeout(&input_dev->wait_event, 5*HZ);
620         if (t == 0) {
621                 ret = -ETIMEDOUT;
622                 goto cleanup;
623         }
624
625         /*
626          * We should have gotten the device attr, hid desc and report
627          * desc at this point
628          */
629         if (!input_dev->dev_info_status)
630                 pr_info("**** input channel up and running!! ****");
631         else
632                 ret = -1;
633
634 cleanup:
635         put_input_device(device);
636
637         return ret;
638 }
639
640 static int mousevsc_hid_open(struct hid_device *hid)
641 {
642         return 0;
643 }
644
645 static void mousevsc_hid_close(struct hid_device *hid)
646 {
647 }
648
649 static struct hid_ll_driver mousevsc_ll_driver = {
650         .open = mousevsc_hid_open,
651         .close = mousevsc_hid_close,
652 };
653
654 static struct hid_driver mousevsc_hid_driver;
655
656 static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len)
657 {
658         struct hid_device *hid_dev;
659         struct mousevsc_dev *input_device = hv_get_drvdata(dev);
660
661         hid_dev = hid_allocate_device();
662         if (IS_ERR(hid_dev))
663                 return;
664
665         hid_dev->ll_driver = &mousevsc_ll_driver;
666         hid_dev->driver = &mousevsc_hid_driver;
667
668         if (hid_parse_report(hid_dev, packet, len)) {
669                 DPRINT_INFO(INPUTVSC_DRV, "Unable to call hd_parse_report");
670                 return;
671         }
672
673         hid_dev->bus = BUS_VIRTUAL;
674         hid_dev->vendor = input_device->hid_dev_info.vendor;
675         hid_dev->product = input_device->hid_dev_info.product;
676         hid_dev->version = input_device->hid_dev_info.version;
677
678         sprintf(hid_dev->name, "%s", "Microsoft Vmbus HID-compliant Mouse");
679
680         if (!hidinput_connect(hid_dev, 0)) {
681                 hid_dev->claimed |= HID_CLAIMED_INPUT;
682
683                 input_device->connected = 1;
684
685         }
686
687         input_device->hid_device = hid_dev;
688 }
689
690 static int mousevsc_on_device_add(struct hv_device *device,
691                                         void *additional_info)
692 {
693         int ret = 0;
694         struct mousevsc_dev *input_dev;
695         struct hv_driver *input_drv;
696
697         input_dev = alloc_input_device(device);
698
699         if (!input_dev) {
700                 ret = -1;
701                 goto cleanup;
702         }
703
704         input_dev->init_complete = false;
705
706         /* Open the channel */
707         ret = vmbus_open(device->channel,
708                 INPUTVSC_SEND_RING_BUFFER_SIZE,
709                 INPUTVSC_RECV_RING_BUFFER_SIZE,
710                 NULL,
711                 0,
712                 mousevsc_on_channel_callback,
713                 device
714                 );
715
716         if (ret != 0) {
717                 pr_err("unable to open channel: %d", ret);
718                 free_input_device(input_dev);
719                 return -1;
720         }
721
722         pr_info("InputVsc channel open: %d", ret);
723
724         ret = mousevsc_connect_to_vsp(device);
725
726         if (ret != 0) {
727                 pr_err("unable to connect channel: %d", ret);
728
729                 vmbus_close(device->channel);
730                 free_input_device(input_dev);
731                 return ret;
732         }
733
734         input_drv = drv_to_hv_drv(input_dev->device->device.driver);
735
736
737
738         /* Send the report desc back up */
739         /* workaround SA-167 */
740         if (input_dev->report_desc[14] == 0x25)
741                 input_dev->report_desc[14] = 0x29;
742
743         reportdesc_callback(device, input_dev->report_desc,
744                             input_dev->report_desc_size);
745
746         input_dev->init_complete = true;
747
748 cleanup:
749         return ret;
750 }
751
752 static int mousevsc_on_device_remove(struct hv_device *device)
753 {
754         struct mousevsc_dev *input_dev;
755         int ret = 0;
756
757         pr_info("disabling input device (%p)...",
758                     hv_get_drvdata(device));
759
760         input_dev = release_input_device(device);
761
762
763         /*
764          * At this point, all outbound traffic should be disable. We only
765          * allow inbound traffic (responses) to proceed
766          *
767          * so that outstanding requests can be completed.
768          */
769         while (input_dev->num_outstanding_req) {
770                 pr_info("waiting for %d requests to complete...",
771                         input_dev->num_outstanding_req);
772
773                 udelay(100);
774         }
775
776         pr_info("removing input device (%p)...", hv_get_drvdata(device));
777
778         input_dev = final_release_input_device(device);
779
780         pr_info("input device (%p) safe to remove", input_dev);
781
782         /* Close the channel */
783         vmbus_close(device->channel);
784
785         free_input_device(input_dev);
786
787         return ret;
788 }
789
790
791 static int mousevsc_probe(struct hv_device *dev,
792                         const struct hv_vmbus_device_id *dev_id)
793 {
794         int ret = 0;
795
796
797         /* Call to the vsc driver to add the device */
798         ret = mousevsc_on_device_add(dev, NULL);
799
800         if (ret != 0) {
801                 DPRINT_ERR(INPUTVSC_DRV, "unable to add input vsc device");
802
803                 return -1;
804         }
805
806         return 0;
807 }
808
809 static int mousevsc_remove(struct hv_device *dev)
810 {
811         struct mousevsc_dev *input_dev = hv_get_drvdata(dev);
812         int ret;
813
814         if (input_dev->connected) {
815                 hidinput_disconnect(input_dev->hid_device);
816                 input_dev->connected = 0;
817                 hid_destroy_device(input_dev->hid_device);
818         }
819
820         /*
821          * Call to the vsc driver to let it know that the device
822          * is being removed
823          */
824         ret = mousevsc_on_device_remove(dev);
825         if (ret != 0) {
826                 DPRINT_ERR(INPUTVSC_DRV,
827                            "unable to remove vsc device (ret %d)", ret);
828         }
829
830         return ret;
831 }
832
833 static const struct hv_vmbus_device_id id_table[] = {
834         /* Mouse guid */
835         { VMBUS_DEVICE(0x9E, 0xB6, 0xA8, 0xCF, 0x4A, 0x5B, 0xc0, 0x4c,
836                        0xB9, 0x8B, 0x8B, 0xA1, 0xA1, 0xF3, 0xF9, 0x5A) },
837         { },
838 };
839
840 /*
841  * The mouse driver is not functional; do not auto-load it.
842  */
843 /* MODULE_DEVICE_TABLE(vmbus, id_table); */
844
845 static struct  hv_driver mousevsc_drv = {
846         .name = "mousevsc",
847         .id_table = id_table,
848         .probe = mousevsc_probe,
849         .remove = mousevsc_remove,
850 };
851
852 static int __init mousevsc_init(void)
853 {
854         return vmbus_driver_register(&mousevsc_drv);
855 }
856
857 static void __exit mousevsc_exit(void)
858 {
859         vmbus_driver_unregister(&mousevsc_drv);
860 }
861
862 MODULE_LICENSE("GPL");
863 MODULE_VERSION(HV_DRV_VERSION);
864 module_init(mousevsc_init);
865 module_exit(mousevsc_exit);
866