]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/hv/hv_mouse.c
19cfc231ab99425db5cca84d6c8cc61b569af7f9
[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         wait_queue_head_t       protocol_wait_event;
166         wait_queue_head_t       dev_info_wait_event;
167         int                     protocol_wait_condition;
168         int                     device_wait_condition;
169         int                     dev_info_status;
170
171         struct hid_descriptor   *hid_desc;
172         unsigned char           *report_desc;
173         u32                     report_desc_size;
174         struct hv_input_dev_info hid_dev_info;
175         int                     connected;
176         struct hid_device       *hid_device;
177 };
178
179
180 static struct mousevsc_dev *alloc_input_device(struct hv_device *device)
181 {
182         struct mousevsc_dev *input_dev;
183
184         input_dev = kzalloc(sizeof(struct mousevsc_dev), GFP_KERNEL);
185
186         if (!input_dev)
187                 return NULL;
188
189         /*
190          * Set to 2 to allow both inbound and outbound traffics
191          * (ie get_input_device() and must_get_input_device()) to proceed.
192          */
193         atomic_cmpxchg(&input_dev->ref_count, 0, 2);
194
195         input_dev->device = device;
196         hv_set_drvdata(device, input_dev);
197
198         return input_dev;
199 }
200
201 static void free_input_device(struct mousevsc_dev *device)
202 {
203         WARN_ON(atomic_read(&device->ref_count) != 0);
204         kfree(device);
205 }
206
207 /*
208  * Get the inputdevice object if exists and its refcount > 1
209  */
210 static struct mousevsc_dev *get_input_device(struct hv_device *device)
211 {
212         struct mousevsc_dev *input_dev;
213
214         input_dev = hv_get_drvdata(device);
215
216 /*
217  *      FIXME
218  *      This sure isn't a valid thing to print for debugging, no matter
219  *      what the intention is...
220  *
221  *      printk(KERN_ERR "-------------------------> REFCOUNT = %d",
222  *             input_dev->ref_count);
223  */
224
225         if (input_dev && atomic_read(&input_dev->ref_count) > 1)
226                 atomic_inc(&input_dev->ref_count);
227         else
228                 input_dev = NULL;
229
230         return input_dev;
231 }
232
233 /*
234  * Get the inputdevice object iff exists and its refcount > 0
235  */
236 static struct mousevsc_dev *must_get_input_device(struct hv_device *device)
237 {
238         struct mousevsc_dev *input_dev;
239
240         input_dev = hv_get_drvdata(device);
241
242         if (input_dev && atomic_read(&input_dev->ref_count))
243                 atomic_inc(&input_dev->ref_count);
244         else
245                 input_dev = NULL;
246
247         return input_dev;
248 }
249
250 static void put_input_device(struct hv_device *device)
251 {
252         struct mousevsc_dev *input_dev;
253
254         input_dev = hv_get_drvdata(device);
255
256         atomic_dec(&input_dev->ref_count);
257 }
258
259 /*
260  * Drop ref count to 1 to effectively disable get_input_device()
261  */
262 static struct mousevsc_dev *release_input_device(struct hv_device *device)
263 {
264         struct mousevsc_dev *input_dev;
265
266         input_dev = hv_get_drvdata(device);
267
268         /* Busy wait until the ref drop to 2, then set it to 1  */
269         while (atomic_cmpxchg(&input_dev->ref_count, 2, 1) != 2)
270                 udelay(100);
271
272         return input_dev;
273 }
274
275 /*
276  * Drop ref count to 0. No one can use input_device object.
277  */
278 static struct mousevsc_dev *final_release_input_device(struct hv_device *device)
279 {
280         struct mousevsc_dev *input_dev;
281
282         input_dev = hv_get_drvdata(device);
283
284         /* Busy wait until the ref drop to 1, then set it to 0  */
285         while (atomic_cmpxchg(&input_dev->ref_count, 1, 0) != 1)
286                 udelay(100);
287
288         hv_set_drvdata(device, NULL);
289         return input_dev;
290 }
291
292 static void mousevsc_on_send_completion(struct hv_device *device,
293                                         struct vmpacket_descriptor *packet)
294 {
295         struct mousevsc_dev *input_dev;
296         void *request;
297
298         input_dev = must_get_input_device(device);
299         if (!input_dev) {
300                 pr_err("unable to get input device...device being destroyed?");
301                 return;
302         }
303
304         request = (void *)(unsigned long)packet->trans_id;
305
306         if (request == &input_dev->protocol_req) {
307                 /* FIXME */
308                 /* Shouldn't we be doing something here? */
309         }
310
311         put_input_device(device);
312 }
313
314 static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
315                                 struct synthhid_device_info *device_info)
316 {
317         int ret = 0;
318         struct hid_descriptor *desc;
319         struct mousevsc_prt_msg ack;
320
321         /* Assume success for now */
322         input_device->dev_info_status = 0;
323
324         /* Save the device attr */
325         memcpy(&input_device->hid_dev_info, &device_info->hid_dev_info,
326                 sizeof(struct hv_input_dev_info));
327
328         /* Save the hid desc */
329         desc = &device_info->hid_descriptor;
330         WARN_ON(desc->bLength == 0);
331
332         input_device->hid_desc = kzalloc(desc->bLength, GFP_ATOMIC);
333
334         if (!input_device->hid_desc) {
335                 pr_err("unable to allocate hid descriptor - size %d",
336                          desc->bLength);
337                 goto cleanup;
338         }
339
340         memcpy(input_device->hid_desc, desc, desc->bLength);
341
342         /* Save the report desc */
343         input_device->report_desc_size = desc->desc[0].wDescriptorLength;
344         if (input_device->report_desc_size == 0)
345                 goto cleanup;
346         input_device->report_desc = kzalloc(input_device->report_desc_size,
347                                           GFP_ATOMIC);
348
349         if (!input_device->report_desc) {
350                 pr_err("unable to allocate report descriptor - size %d",
351                            input_device->report_desc_size);
352                 goto cleanup;
353         }
354
355         memcpy(input_device->report_desc,
356                ((unsigned char *)desc) + desc->bLength,
357                desc->desc[0].wDescriptorLength);
358
359         /* Send the ack */
360         memset(&ack, 0, sizeof(struct mousevsc_prt_msg));
361
362         ack.type = PipeMessageData;
363         ack.size = sizeof(struct synthhid_device_info_ack);
364
365         ack.ack.header.type = SynthHidInitialDeviceInfoAck;
366         ack.ack.header.size = 1;
367         ack.ack.reserved = 0;
368
369         ret = vmbus_sendpacket(input_device->device->channel,
370                         &ack,
371                         sizeof(struct pipe_prt_msg) - sizeof(unsigned char) +
372                         sizeof(struct synthhid_device_info_ack),
373                         (unsigned long)&ack,
374                         VM_PKT_DATA_INBAND,
375                         VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
376         if (ret != 0) {
377                 pr_err("unable to send synthhid device info ack - ret %d",
378                            ret);
379                 goto cleanup;
380         }
381
382         input_device->device_wait_condition = 1;
383         wake_up(&input_device->dev_info_wait_event);
384
385         return;
386
387 cleanup:
388         kfree(input_device->hid_desc);
389         input_device->hid_desc = NULL;
390
391         kfree(input_device->report_desc);
392         input_device->report_desc = NULL;
393
394         input_device->dev_info_status = -1;
395         input_device->device_wait_condition = 1;
396         wake_up(&input_device->dev_info_wait_event);
397 }
398
399 static void mousevsc_on_receive_input_report(struct mousevsc_dev *input_device,
400                                 struct synthhid_input_report *input_report)
401 {
402         struct hv_driver *input_drv;
403
404         if (!input_device->init_complete) {
405                 pr_info("Initialization incomplete...ignoring input_report msg");
406                 return;
407         }
408
409         input_drv = drv_to_hv_drv(input_device->device->device.driver);
410
411
412         hid_input_report(input_device->hid_device,
413                               HID_INPUT_REPORT, input_report->buffer, input_report->header.size, 1);
414
415 }
416
417 static void mousevsc_on_receive(struct hv_device *device,
418                                 struct vmpacket_descriptor *packet)
419 {
420         struct pipe_prt_msg *pipe_msg;
421         struct synthhid_msg *hid_msg;
422         struct mousevsc_dev *input_dev;
423
424         input_dev = must_get_input_device(device);
425         if (!input_dev) {
426                 pr_err("unable to get input device...device being destroyed?");
427                 return;
428         }
429
430         pipe_msg = (struct pipe_prt_msg *)((unsigned long)packet +
431                                                 (packet->offset8 << 3));
432
433         if (pipe_msg->type != PipeMessageData) {
434                 pr_err("unknown pipe msg type - type %d len %d",
435                            pipe_msg->type, pipe_msg->size);
436                 put_input_device(device);
437                 return ;
438         }
439
440         hid_msg = (struct synthhid_msg *)&pipe_msg->data[0];
441
442         switch (hid_msg->header.type) {
443         case SynthHidProtocolResponse:
444                 memcpy(&input_dev->protocol_resp, pipe_msg,
445                        pipe_msg->size + sizeof(struct pipe_prt_msg) -
446                        sizeof(unsigned char));
447                 input_dev->protocol_wait_condition = 1;
448                 wake_up(&input_dev->protocol_wait_event);
449                 break;
450
451         case SynthHidInitialDeviceInfo:
452                 WARN_ON(pipe_msg->size < sizeof(struct hv_input_dev_info));
453
454                 /*
455                  * Parse out the device info into device attr,
456                  * hid desc and report desc
457                  */
458                 mousevsc_on_receive_device_info(input_dev,
459                         (struct synthhid_device_info *)&pipe_msg->data[0]);
460                 break;
461         case SynthHidInputReport:
462                 mousevsc_on_receive_input_report(input_dev,
463                         (struct synthhid_input_report *)&pipe_msg->data[0]);
464
465                 break;
466         default:
467                 pr_err("unsupported hid msg type - type %d len %d",
468                        hid_msg->header.type, hid_msg->header.size);
469                 break;
470         }
471
472         put_input_device(device);
473 }
474
475 static void mousevsc_on_channel_callback(void *context)
476 {
477         const int packetSize = 0x100;
478         int ret = 0;
479         struct hv_device *device = (struct hv_device *)context;
480         struct mousevsc_dev *input_dev;
481
482         u32 bytes_recvd;
483         u64 req_id;
484         unsigned char packet[0x100];
485         struct vmpacket_descriptor *desc;
486         unsigned char   *buffer = packet;
487         int     bufferlen = packetSize;
488
489         input_dev = must_get_input_device(device);
490
491         if (!input_dev) {
492                 pr_err("unable to get input device...device being destroyed?");
493                 return;
494         }
495
496         do {
497                 ret = vmbus_recvpacket_raw(device->channel, buffer,
498                                         bufferlen, &bytes_recvd, &req_id);
499
500                 if (ret == 0) {
501                         if (bytes_recvd > 0) {
502                                 desc = (struct vmpacket_descriptor *)buffer;
503
504                                 switch (desc->type) {
505                                 case VM_PKT_COMP:
506                                         mousevsc_on_send_completion(
507                                                 device, desc);
508                                         break;
509
510                                 case VM_PKT_DATA_INBAND:
511                                         mousevsc_on_receive(
512                                                 device, desc);
513                                         break;
514
515                                 default:
516                                         pr_err("unhandled packet type %d, tid %llx len %d\n",
517                                                    desc->type,
518                                                    req_id,
519                                                    bytes_recvd);
520                                         break;
521                                 }
522
523                                 /* reset */
524                                 if (bufferlen > packetSize) {
525                                         kfree(buffer);
526
527                                         buffer = packet;
528                                         bufferlen = packetSize;
529                                 }
530                         } else {
531                                 /*
532                                  * pr_debug("nothing else to read...");
533                                  * reset
534                                  */
535                                 if (bufferlen > packetSize) {
536                                         kfree(buffer);
537
538                                         buffer = packet;
539                                         bufferlen = packetSize;
540                                 }
541                                 break;
542                         }
543                 } else if (ret == -ENOBUFS) {
544                         /* Handle large packet */
545                         bufferlen = bytes_recvd;
546                         buffer = kzalloc(bytes_recvd, GFP_ATOMIC);
547
548                         if (buffer == NULL) {
549                                 buffer = packet;
550                                 bufferlen = packetSize;
551
552                                 /* Try again next time around */
553                                 pr_err("unable to allocate buffer of size %d!",
554                                        bytes_recvd);
555                                 break;
556                         }
557                 }
558         } while (1);
559
560         put_input_device(device);
561
562         return;
563 }
564
565 static int mousevsc_connect_to_vsp(struct hv_device *device)
566 {
567         int ret = 0;
568         struct mousevsc_dev *input_dev;
569         struct mousevsc_prt_msg *request;
570         struct mousevsc_prt_msg *response;
571
572         input_dev = get_input_device(device);
573
574         if (!input_dev) {
575                 pr_err("unable to get input device...device being destroyed?");
576                 return -1;
577         }
578
579         init_waitqueue_head(&input_dev->protocol_wait_event);
580         init_waitqueue_head(&input_dev->dev_info_wait_event);
581
582         request = &input_dev->protocol_req;
583
584         /*
585          * Now, initiate the vsc/vsp initialization protocol on the open channel
586          */
587         memset(request, 0, sizeof(struct mousevsc_prt_msg));
588
589         request->type = PipeMessageData;
590         request->size = sizeof(struct synthhid_protocol_request);
591
592         request->request.header.type = SynthHidProtocolRequest;
593         request->request.header.size = sizeof(unsigned long);
594         request->request.version_requested.version = SYNTHHID_INPUT_VERSION;
595
596         pr_info("synthhid protocol request...");
597
598         ret = vmbus_sendpacket(device->channel, request,
599                                 sizeof(struct pipe_prt_msg) -
600                                 sizeof(unsigned char) +
601                                 sizeof(struct synthhid_protocol_request),
602                                 (unsigned long)request,
603                                 VM_PKT_DATA_INBAND,
604                                 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
605         if (ret != 0) {
606                 pr_err("unable to send synthhid protocol request.");
607                 goto cleanup;
608         }
609
610         input_dev->protocol_wait_condition = 0;
611         wait_event_timeout(input_dev->protocol_wait_event,
612                 input_dev->protocol_wait_condition, msecs_to_jiffies(1000));
613         if (input_dev->protocol_wait_condition == 0) {
614                 ret = -ETIMEDOUT;
615                 goto cleanup;
616         }
617
618         response = &input_dev->protocol_resp;
619
620         if (!response->response.approved) {
621                 pr_err("synthhid protocol request failed (version %d)",
622                        SYNTHHID_INPUT_VERSION);
623                 ret = -1;
624                 goto cleanup;
625         }
626
627         input_dev->device_wait_condition = 0;
628         wait_event_timeout(input_dev->dev_info_wait_event,
629                 input_dev->device_wait_condition, msecs_to_jiffies(1000));
630         if (input_dev->device_wait_condition == 0) {
631                 ret = -ETIMEDOUT;
632                 goto cleanup;
633         }
634
635         /*
636          * We should have gotten the device attr, hid desc and report
637          * desc at this point
638          */
639         if (!input_dev->dev_info_status)
640                 pr_info("**** input channel up and running!! ****");
641         else
642                 ret = -1;
643
644 cleanup:
645         put_input_device(device);
646
647         return ret;
648 }
649
650 static int mousevsc_hid_open(struct hid_device *hid)
651 {
652         return 0;
653 }
654
655 static void mousevsc_hid_close(struct hid_device *hid)
656 {
657 }
658
659 static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len)
660 {
661         struct hid_device *hid_dev;
662         struct mousevsc_dev *input_device = hv_get_drvdata(dev);
663
664         /* hid_debug = -1; */
665         hid_dev = kmalloc(sizeof(struct hid_device), GFP_KERNEL);
666
667         if (hid_parse_report(hid_dev, packet, len)) {
668                 DPRINT_INFO(INPUTVSC_DRV, "Unable to call hd_parse_report");
669                 return;
670         }
671
672         if (hid_dev) {
673                 DPRINT_INFO(INPUTVSC_DRV, "hid_device created");
674
675                 hid_dev->ll_driver->open  = mousevsc_hid_open;
676                 hid_dev->ll_driver->close = mousevsc_hid_close;
677
678                 hid_dev->bus = BUS_VIRTUAL;
679                 hid_dev->vendor = input_device->hid_dev_info.vendor;
680                 hid_dev->product = input_device->hid_dev_info.product;
681                 hid_dev->version = input_device->hid_dev_info.version;
682                 hid_dev->dev = dev->device;
683
684                 sprintf(hid_dev->name, "%s",
685                         "Microsoft Vmbus HID-compliant Mouse");
686
687                 /*
688                  * HJ Do we want to call it with a 0
689                  */
690                 if (!hidinput_connect(hid_dev, 0)) {
691                         hid_dev->claimed |= HID_CLAIMED_INPUT;
692
693                         input_device->connected = 1;
694
695                         DPRINT_INFO(INPUTVSC_DRV,
696                                      "HID device claimed by input\n");
697                 }
698
699                 if (!hid_dev->claimed) {
700                         DPRINT_ERR(INPUTVSC_DRV,
701                                     "HID device not claimed by "
702                                     "input or hiddev\n");
703                 }
704
705                 input_device->hid_device = hid_dev;
706         }
707
708         kfree(hid_dev);
709 }
710
711 static int mousevsc_on_device_add(struct hv_device *device,
712                                         void *additional_info)
713 {
714         int ret = 0;
715         struct mousevsc_dev *input_dev;
716         struct hv_driver *input_drv;
717
718         input_dev = alloc_input_device(device);
719
720         if (!input_dev) {
721                 ret = -1;
722                 goto cleanup;
723         }
724
725         input_dev->init_complete = false;
726
727         /* Open the channel */
728         ret = vmbus_open(device->channel,
729                 INPUTVSC_SEND_RING_BUFFER_SIZE,
730                 INPUTVSC_RECV_RING_BUFFER_SIZE,
731                 NULL,
732                 0,
733                 mousevsc_on_channel_callback,
734                 device
735                 );
736
737         if (ret != 0) {
738                 pr_err("unable to open channel: %d", ret);
739                 free_input_device(input_dev);
740                 return -1;
741         }
742
743         pr_info("InputVsc channel open: %d", ret);
744
745         ret = mousevsc_connect_to_vsp(device);
746
747         if (ret != 0) {
748                 pr_err("unable to connect channel: %d", ret);
749
750                 vmbus_close(device->channel);
751                 free_input_device(input_dev);
752                 return ret;
753         }
754
755         input_drv = drv_to_hv_drv(input_dev->device->device.driver);
756
757
758
759         /* Send the report desc back up */
760         /* workaround SA-167 */
761         if (input_dev->report_desc[14] == 0x25)
762                 input_dev->report_desc[14] = 0x29;
763
764         reportdesc_callback(device, input_dev->report_desc,
765                             input_dev->report_desc_size);
766
767         input_dev->init_complete = true;
768
769 cleanup:
770         return ret;
771 }
772
773 static int mousevsc_on_device_remove(struct hv_device *device)
774 {
775         struct mousevsc_dev *input_dev;
776         int ret = 0;
777
778         pr_info("disabling input device (%p)...",
779                     hv_get_drvdata(device));
780
781         input_dev = release_input_device(device);
782
783
784         /*
785          * At this point, all outbound traffic should be disable. We only
786          * allow inbound traffic (responses) to proceed
787          *
788          * so that outstanding requests can be completed.
789          */
790         while (input_dev->num_outstanding_req) {
791                 pr_info("waiting for %d requests to complete...",
792                         input_dev->num_outstanding_req);
793
794                 udelay(100);
795         }
796
797         pr_info("removing input device (%p)...", hv_get_drvdata(device));
798
799         input_dev = final_release_input_device(device);
800
801         pr_info("input device (%p) safe to remove", input_dev);
802
803         /* Close the channel */
804         vmbus_close(device->channel);
805
806         free_input_device(input_dev);
807
808         return ret;
809 }
810
811
812 static int mousevsc_probe(struct hv_device *dev,
813                         const struct hv_vmbus_device_id *dev_id)
814 {
815         int ret = 0;
816
817
818         /* Call to the vsc driver to add the device */
819         ret = mousevsc_on_device_add(dev, NULL);
820
821         if (ret != 0) {
822                 DPRINT_ERR(INPUTVSC_DRV, "unable to add input vsc device");
823
824                 return -1;
825         }
826
827         return 0;
828 }
829
830 static int mousevsc_remove(struct hv_device *dev)
831 {
832         struct mousevsc_dev *input_dev = hv_get_drvdata(dev);
833         int ret;
834
835         if (input_dev->connected) {
836                 hidinput_disconnect(input_dev->hid_device);
837                 input_dev->connected = 0;
838         }
839
840         /*
841          * Call to the vsc driver to let it know that the device
842          * is being removed
843          */
844         ret = mousevsc_on_device_remove(dev);
845         if (ret != 0) {
846                 DPRINT_ERR(INPUTVSC_DRV,
847                            "unable to remove vsc device (ret %d)", ret);
848         }
849
850         return ret;
851 }
852
853 static const struct hv_vmbus_device_id id_table[] = {
854         /* Mouse guid */
855         { VMBUS_DEVICE(0x9E, 0xB6, 0xA8, 0xCF, 0x4A, 0x5B, 0xc0, 0x4c,
856                        0xB9, 0x8B, 0x8B, 0xA1, 0xA1, 0xF3, 0xF9, 0x5A) },
857         { },
858 };
859
860 /*
861  * The mouse driver is not functional; do not auto-load it.
862  */
863 /* MODULE_DEVICE_TABLE(vmbus, id_table); */
864
865 static struct  hv_driver mousevsc_drv = {
866         .name = "mousevsc",
867         .id_table = id_table,
868         .probe = mousevsc_probe,
869         .remove = mousevsc_remove,
870 };
871
872 static int __init mousevsc_init(void)
873 {
874         return vmbus_driver_register(&mousevsc_drv);
875 }
876
877 static void __exit mousevsc_exit(void)
878 {
879         vmbus_driver_unregister(&mousevsc_drv);
880 }
881
882 MODULE_LICENSE("GPL");
883 MODULE_VERSION(HV_DRV_VERSION);
884 module_init(mousevsc_init);
885 module_exit(mousevsc_exit);
886