2 * Copyright (c) 2009, Citrix Systems, Inc.
3 * Copyright (c) 2010, Microsoft Corporation.
4 * Copyright (c) 2011, Novell Inc.
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.
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
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 #include <linux/pci.h>
26 #include <linux/dmi.h>
27 #include <linux/delay.h>
31 #include "version_info.h"
33 #include "vmbus_api.h"
35 #include "vmbus_packet_format.h"
41 struct hv_input_dev_info
{
42 unsigned short vendor
;
43 unsigned short product
;
44 unsigned short version
;
48 /* Represents the input vsc driver */
49 /* FIXME - can be removed entirely */
50 struct mousevsc_drv_obj
{
51 struct hv_driver base
;
55 /* The maximum size of a synthetic input message. */
56 #define SYNTHHID_MAX_INPUT_REPORT_SIZE 16
62 * Beta, RC < 2008/1/22 1,0
65 #define SYNTHHID_INPUT_VERSION_MAJOR 2
66 #define SYNTHHID_INPUT_VERSION_MINOR 0
67 #define SYNTHHID_INPUT_VERSION (SYNTHHID_INPUT_VERSION_MINOR | \
68 (SYNTHHID_INPUT_VERSION_MAJOR << 16))
73 * Message types in the synthetic input protocol
75 enum synthhid_msg_type
{
76 SynthHidProtocolRequest
,
77 SynthHidProtocolResponse
,
78 SynthHidInitialDeviceInfo
,
79 SynthHidInitialDeviceInfoAck
,
85 * Basic message structures.
87 struct synthhid_msg_hdr
{
88 enum synthhid_msg_type type
;
93 struct synthhid_msg_hdr header
;
94 char data
[1]; /* Enclosed message */
97 union synthhid_version
{
108 struct synthhid_protocol_request
{
109 struct synthhid_msg_hdr header
;
110 union synthhid_version version_requested
;
113 struct synthhid_protocol_response
{
114 struct synthhid_msg_hdr header
;
115 union synthhid_version version_requested
;
116 unsigned char approved
;
119 struct synthhid_device_info
{
120 struct synthhid_msg_hdr header
;
121 struct hv_input_dev_info hid_dev_info
;
122 struct hid_descriptor hid_descriptor
;
125 struct synthhid_device_info_ack
{
126 struct synthhid_msg_hdr header
;
127 unsigned char reserved
;
130 struct synthhid_input_report
{
131 struct synthhid_msg_hdr header
;
137 #define INPUTVSC_SEND_RING_BUFFER_SIZE 10*PAGE_SIZE
138 #define INPUTVSC_RECV_RING_BUFFER_SIZE 10*PAGE_SIZE
140 #define NBITS(x) (((x)/BITS_PER_LONG)+1)
142 enum pipe_prot_msg_type
{
143 PipeMessageInvalid
= 0,
149 struct pipe_prt_msg
{
150 enum pipe_prot_msg_type type
;
158 struct mousevsc_prt_msg
{
159 enum pipe_prot_msg_type type
;
162 struct synthhid_protocol_request request
;
163 struct synthhid_protocol_response response
;
164 struct synthhid_device_info_ack ack
;
169 * Represents an mousevsc device
171 struct mousevsc_dev
{
172 struct hv_device
*device
;
173 /* 0 indicates the device is being destroyed */
175 int num_outstanding_req
;
176 unsigned char init_complete
;
177 struct mousevsc_prt_msg protocol_req
;
178 struct mousevsc_prt_msg protocol_resp
;
179 /* Synchronize the request/response if needed */
180 wait_queue_head_t protocol_wait_event
;
181 wait_queue_head_t dev_info_wait_event
;
182 int protocol_wait_condition
;
183 int device_wait_condition
;
186 struct hid_descriptor
*hid_desc
;
187 unsigned char *report_desc
;
188 u32 report_desc_size
;
189 struct hv_input_dev_info hid_dev_info
;
193 static const char *driver_name
= "mousevsc";
195 /* {CFA8B69E-5B4A-4cc0-B98B-8BA1A1F3F95A} */
196 static const struct hv_guid mouse_guid
= {
197 .data
= {0x9E, 0xB6, 0xA8, 0xCF, 0x4A, 0x5B, 0xc0, 0x4c,
198 0xB9, 0x8B, 0x8B, 0xA1, 0xA1, 0xF3, 0xF9, 0x5A}
201 static void deviceinfo_callback(struct hv_device
*dev
, struct hv_input_dev_info
*info
);
202 static void inputreport_callback(struct hv_device
*dev
, void *packet
, u32 len
);
203 static void reportdesc_callback(struct hv_device
*dev
, void *packet
, u32 len
);
205 static struct mousevsc_dev
*alloc_input_device(struct hv_device
*device
)
207 struct mousevsc_dev
*input_dev
;
209 input_dev
= kzalloc(sizeof(struct mousevsc_dev
), GFP_KERNEL
);
215 * Set to 2 to allow both inbound and outbound traffics
216 * (ie get_input_device() and must_get_input_device()) to proceed.
218 atomic_cmpxchg(&input_dev
->ref_count
, 0, 2);
220 input_dev
->device
= device
;
221 device
->ext
= input_dev
;
226 static void free_input_device(struct mousevsc_dev
*device
)
228 WARN_ON(atomic_read(&device
->ref_count
) == 0);
233 * Get the inputdevice object if exists and its refcount > 1
235 static struct mousevsc_dev
*get_input_device(struct hv_device
*device
)
237 struct mousevsc_dev
*input_dev
;
239 input_dev
= (struct mousevsc_dev
*)device
->ext
;
243 * This sure isn't a valid thing to print for debugging, no matter
244 * what the intention is...
246 * printk(KERN_ERR "-------------------------> REFCOUNT = %d",
247 * input_dev->ref_count);
250 if (input_dev
&& atomic_read(&input_dev
->ref_count
) > 1)
251 atomic_inc(&input_dev
->ref_count
);
259 * Get the inputdevice object iff exists and its refcount > 0
261 static struct mousevsc_dev
*must_get_input_device(struct hv_device
*device
)
263 struct mousevsc_dev
*input_dev
;
265 input_dev
= (struct mousevsc_dev
*)device
->ext
;
267 if (input_dev
&& atomic_read(&input_dev
->ref_count
))
268 atomic_inc(&input_dev
->ref_count
);
275 static void put_input_device(struct hv_device
*device
)
277 struct mousevsc_dev
*input_dev
;
279 input_dev
= (struct mousevsc_dev
*)device
->ext
;
281 atomic_dec(&input_dev
->ref_count
);
285 * Drop ref count to 1 to effectively disable get_input_device()
287 static struct mousevsc_dev
*release_input_device(struct hv_device
*device
)
289 struct mousevsc_dev
*input_dev
;
291 input_dev
= (struct mousevsc_dev
*)device
->ext
;
293 /* Busy wait until the ref drop to 2, then set it to 1 */
294 while (atomic_cmpxchg(&input_dev
->ref_count
, 2, 1) != 2)
301 * Drop ref count to 0. No one can use input_device object.
303 static struct mousevsc_dev
*final_release_input_device(struct hv_device
*device
)
305 struct mousevsc_dev
*input_dev
;
307 input_dev
= (struct mousevsc_dev
*)device
->ext
;
309 /* Busy wait until the ref drop to 1, then set it to 0 */
310 while (atomic_cmpxchg(&input_dev
->ref_count
, 1, 0) != 1)
317 static void mousevsc_on_send_completion(struct hv_device
*device
,
318 struct vmpacket_descriptor
*packet
)
320 struct mousevsc_dev
*input_dev
;
323 input_dev
= must_get_input_device(device
);
325 pr_err("unable to get input device...device being destroyed?");
329 request
= (void *)(unsigned long)packet
->trans_id
;
331 if (request
== &input_dev
->protocol_req
) {
333 /* Shouldn't we be doing something here? */
336 put_input_device(device
);
339 static void mousevsc_on_receive_device_info(struct mousevsc_dev
*input_device
,
340 struct synthhid_device_info
*device_info
)
343 struct hid_descriptor
*desc
;
344 struct mousevsc_prt_msg ack
;
346 /* Assume success for now */
347 input_device
->dev_info_status
= 0;
349 /* Save the device attr */
350 memcpy(&input_device
->hid_dev_info
, &device_info
->hid_dev_info
,
351 sizeof(struct hv_input_dev_info
));
353 /* Save the hid desc */
354 desc
= &device_info
->hid_descriptor
;
355 WARN_ON(desc
->bLength
> 0);
357 input_device
->hid_desc
= kzalloc(desc
->bLength
, GFP_KERNEL
);
359 if (!input_device
->hid_desc
) {
360 pr_err("unable to allocate hid descriptor - size %d", desc
->bLength
);
364 memcpy(input_device
->hid_desc
, desc
, desc
->bLength
);
366 /* Save the report desc */
367 input_device
->report_desc_size
= desc
->desc
[0].wDescriptorLength
;
368 input_device
->report_desc
= kzalloc(input_device
->report_desc_size
,
371 if (!input_device
->report_desc
) {
372 pr_err("unable to allocate report descriptor - size %d",
373 input_device
->report_desc_size
);
377 memcpy(input_device
->report_desc
,
378 ((unsigned char *)desc
) + desc
->bLength
,
379 desc
->desc
[0].wDescriptorLength
);
382 memset(&ack
, 0, sizeof(struct mousevsc_prt_msg
));
384 ack
.type
= PipeMessageData
;
385 ack
.size
= sizeof(struct synthhid_device_info_ack
);
387 ack
.ack
.header
.type
= SynthHidInitialDeviceInfoAck
;
388 ack
.ack
.header
.size
= 1;
389 ack
.ack
.reserved
= 0;
391 ret
= vmbus_sendpacket(input_device
->device
->channel
,
393 sizeof(struct pipe_prt_msg
) - sizeof(unsigned char) +
394 sizeof(struct synthhid_device_info_ack
),
397 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED
);
399 pr_err("unable to send synthhid device info ack - ret %d",
404 input_device
->device_wait_condition
= 1;
405 wake_up(&input_device
->dev_info_wait_event
);
410 kfree(input_device
->hid_desc
);
411 input_device
->hid_desc
= NULL
;
413 kfree(input_device
->report_desc
);
414 input_device
->report_desc
= NULL
;
416 input_device
->dev_info_status
= -1;
417 input_device
->device_wait_condition
= 1;
418 wake_up(&input_device
->dev_info_wait_event
);
421 static void mousevsc_on_receive_input_report(struct mousevsc_dev
*input_device
,
422 struct synthhid_input_report
*input_report
)
424 struct mousevsc_drv_obj
*input_drv
;
426 if (!input_device
->init_complete
) {
427 pr_info("Initialization incomplete...ignoring input_report msg");
431 input_drv
= (struct mousevsc_drv_obj
*)input_device
->device
->drv
;
433 inputreport_callback(input_device
->device
,
434 input_report
->buffer
,
435 input_report
->header
.size
);
438 static void mousevsc_on_receive(struct hv_device
*device
,
439 struct vmpacket_descriptor
*packet
)
441 struct pipe_prt_msg
*pipe_msg
;
442 struct synthhid_msg
*hid_msg
;
443 struct mousevsc_dev
*input_dev
;
445 input_dev
= must_get_input_device(device
);
447 pr_err("unable to get input device...device being destroyed?");
451 pipe_msg
= (struct pipe_prt_msg
*)((unsigned long)packet
+
452 (packet
->offset8
<< 3));
454 if (pipe_msg
->type
!= PipeMessageData
) {
455 pr_err("unknown pipe msg type - type %d len %d",
456 pipe_msg
->type
, pipe_msg
->size
);
457 put_input_device(device
);
461 hid_msg
= (struct synthhid_msg
*)&pipe_msg
->data
[0];
463 switch (hid_msg
->header
.type
) {
464 case SynthHidProtocolResponse
:
465 memcpy(&input_dev
->protocol_resp
, pipe_msg
,
466 pipe_msg
->size
+ sizeof(struct pipe_prt_msg
) -
467 sizeof(unsigned char));
468 input_dev
->protocol_wait_condition
= 1;
469 wake_up(&input_dev
->protocol_wait_event
);
472 case SynthHidInitialDeviceInfo
:
473 WARN_ON(pipe_msg
->size
>= sizeof(struct hv_input_dev_info
));
476 * Parse out the device info into device attr,
477 * hid desc and report desc
479 mousevsc_on_receive_device_info(input_dev
,
480 (struct synthhid_device_info
*)&pipe_msg
->data
[0]);
482 case SynthHidInputReport
:
483 mousevsc_on_receive_input_report(input_dev
,
484 (struct synthhid_input_report
*)&pipe_msg
->data
[0]);
488 pr_err("unsupported hid msg type - type %d len %d",
489 hid_msg
->header
.type
, hid_msg
->header
.size
);
493 put_input_device(device
);
496 static void mousevsc_on_channel_callback(void *context
)
498 const int packetSize
= 0x100;
500 struct hv_device
*device
= (struct hv_device
*)context
;
501 struct mousevsc_dev
*input_dev
;
505 unsigned char packet
[packetSize
];
506 struct vmpacket_descriptor
*desc
;
507 unsigned char *buffer
= packet
;
508 int bufferlen
= packetSize
;
510 input_dev
= must_get_input_device(device
);
513 pr_err("unable to get input device...device being destroyed?");
518 ret
= vmbus_recvpacket_raw(device
->channel
, buffer
,
519 bufferlen
, &bytes_recvd
, &req_id
);
522 if (bytes_recvd
> 0) {
523 desc
= (struct vmpacket_descriptor
*)buffer
;
525 switch (desc
->type
) {
527 mousevsc_on_send_completion(
531 case VM_PKT_DATA_INBAND
:
537 pr_err("unhandled packet type %d, tid %llx len %d\n",
545 if (bufferlen
> packetSize
) {
549 bufferlen
= packetSize
;
553 * pr_debug("nothing else to read...");
556 if (bufferlen
> packetSize
) {
560 bufferlen
= packetSize
;
564 } else if (ret
== -2) {
565 /* Handle large packet */
566 bufferlen
= bytes_recvd
;
567 buffer
= kzalloc(bytes_recvd
, GFP_KERNEL
);
569 if (buffer
== NULL
) {
571 bufferlen
= packetSize
;
573 /* Try again next time around */
574 pr_err("unable to allocate buffer of size %d!",
581 put_input_device(device
);
586 static int mousevsc_connect_to_vsp(struct hv_device
*device
)
589 struct mousevsc_dev
*input_dev
;
590 struct mousevsc_prt_msg
*request
;
591 struct mousevsc_prt_msg
*response
;
593 input_dev
= get_input_device(device
);
596 pr_err("unable to get input device...device being destroyed?");
600 init_waitqueue_head(&input_dev
->protocol_wait_event
);
601 init_waitqueue_head(&input_dev
->dev_info_wait_event
);
603 request
= &input_dev
->protocol_req
;
606 * Now, initiate the vsc/vsp initialization protocol on the open channel
608 memset(request
, 0, sizeof(struct mousevsc_prt_msg
));
610 request
->type
= PipeMessageData
;
611 request
->size
= sizeof(struct synthhid_protocol_request
);
613 request
->request
.header
.type
= SynthHidProtocolRequest
;
614 request
->request
.header
.size
= sizeof(unsigned long);
615 request
->request
.version_requested
.version
= SYNTHHID_INPUT_VERSION
;
617 pr_info("synthhid protocol request...");
619 ret
= vmbus_sendpacket(device
->channel
, request
,
620 sizeof(struct pipe_prt_msg
) -
621 sizeof(unsigned char) +
622 sizeof(struct synthhid_protocol_request
),
623 (unsigned long)request
,
625 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED
);
627 pr_err("unable to send synthhid protocol request.");
631 input_dev
->protocol_wait_condition
= 0;
632 wait_event_timeout(input_dev
->protocol_wait_event
,
633 input_dev
->protocol_wait_condition
, msecs_to_jiffies(1000));
634 if (input_dev
->protocol_wait_condition
== 0) {
639 response
= &input_dev
->protocol_resp
;
641 if (!response
->response
.approved
) {
642 pr_err("synthhid protocol request failed (version %d)",
643 SYNTHHID_INPUT_VERSION
);
648 input_dev
->device_wait_condition
= 0;
649 wait_event_timeout(input_dev
->dev_info_wait_event
,
650 input_dev
->device_wait_condition
, msecs_to_jiffies(1000));
651 if (input_dev
->device_wait_condition
== 0) {
657 * We should have gotten the device attr, hid desc and report
660 if (!input_dev
->dev_info_status
)
661 pr_info("**** input channel up and running!! ****");
666 put_input_device(device
);
671 static int mousevsc_on_device_add(struct hv_device
*device
,
672 void *additional_info
)
675 struct mousevsc_dev
*input_dev
;
676 struct mousevsc_drv_obj
*input_drv
;
677 struct hv_input_dev_info dev_info
;
679 input_dev
= alloc_input_device(device
);
686 input_dev
->init_complete
= false;
688 /* Open the channel */
689 ret
= vmbus_open(device
->channel
,
690 INPUTVSC_SEND_RING_BUFFER_SIZE
,
691 INPUTVSC_RECV_RING_BUFFER_SIZE
,
694 mousevsc_on_channel_callback
,
699 pr_err("unable to open channel: %d", ret
);
700 free_input_device(input_dev
);
704 pr_info("InputVsc channel open: %d", ret
);
706 ret
= mousevsc_connect_to_vsp(device
);
709 pr_err("unable to connect channel: %d", ret
);
711 vmbus_close(device
->channel
);
712 free_input_device(input_dev
);
716 input_drv
= (struct mousevsc_drv_obj
*)input_dev
->device
->drv
;
718 dev_info
.vendor
= input_dev
->hid_dev_info
.vendor
;
719 dev_info
.product
= input_dev
->hid_dev_info
.product
;
720 dev_info
.version
= input_dev
->hid_dev_info
.version
;
721 strcpy(dev_info
.name
, "Microsoft Vmbus HID-compliant Mouse");
723 /* Send the device info back up */
724 deviceinfo_callback(device
, &dev_info
);
726 /* Send the report desc back up */
727 /* workaround SA-167 */
728 if (input_dev
->report_desc
[14] == 0x25)
729 input_dev
->report_desc
[14] = 0x29;
731 reportdesc_callback(device
, input_dev
->report_desc
,
732 input_dev
->report_desc_size
);
734 input_dev
->init_complete
= true;
740 static int mousevsc_on_device_remove(struct hv_device
*device
)
742 struct mousevsc_dev
*input_dev
;
745 pr_info("disabling input device (%p)...",
748 input_dev
= release_input_device(device
);
752 * At this point, all outbound traffic should be disable. We only
753 * allow inbound traffic (responses) to proceed
755 * so that outstanding requests can be completed.
757 while (input_dev
->num_outstanding_req
) {
758 pr_info("waiting for %d requests to complete...",
759 input_dev
->num_outstanding_req
);
764 pr_info("removing input device (%p)...", device
->ext
);
766 input_dev
= final_release_input_device(device
);
768 pr_info("input device (%p) safe to remove", input_dev
);
770 /* Close the channel */
771 vmbus_close(device
->channel
);
773 free_input_device(input_dev
);
778 static void mousevsc_on_cleanup(struct hv_driver
*drv
)
785 struct input_device_context
{
786 struct hv_device
*device_ctx
;
787 struct hid_device
*hid_device
;
788 struct hv_input_dev_info device_info
;
793 static struct mousevsc_drv_obj g_mousevsc_drv
;
795 static void deviceinfo_callback(struct hv_device
*dev
, struct hv_input_dev_info
*info
)
797 struct input_device_context
*input_device_ctx
=
798 dev_get_drvdata(&dev
->device
);
800 memcpy(&input_device_ctx
->device_info
, info
,
801 sizeof(struct hv_input_dev_info
));
803 DPRINT_INFO(INPUTVSC_DRV
, "%s", __func__
);
806 static void inputreport_callback(struct hv_device
*dev
, void *packet
, u32 len
)
810 struct input_device_context
*input_dev_ctx
=
811 dev_get_drvdata(&dev
->device
);
813 ret
= hid_input_report(input_dev_ctx
->hid_device
,
814 HID_INPUT_REPORT
, packet
, len
, 1);
816 DPRINT_DBG(INPUTVSC_DRV
, "hid_input_report (ret %d)", ret
);
819 static int mousevsc_hid_open(struct hid_device
*hid
)
824 static void mousevsc_hid_close(struct hid_device
*hid
)
828 static int mousevsc_probe(struct device
*device
)
832 struct hv_driver
*drv
=
833 drv_to_hv_drv(device
->driver
);
834 struct mousevsc_drv_obj
*mousevsc_drv_obj
= drv
->priv
;
836 struct hv_device
*device_obj
= device_to_hv_device(device
);
837 struct input_device_context
*input_dev_ctx
;
839 input_dev_ctx
= kmalloc(sizeof(struct input_device_context
),
842 dev_set_drvdata(device
, input_dev_ctx
);
844 /* Call to the vsc driver to add the device */
845 ret
= mousevsc_drv_obj
->base
.dev_add(device_obj
, NULL
);
848 DPRINT_ERR(INPUTVSC_DRV
, "unable to add input vsc device");
856 static int mousevsc_remove(struct device
*device
)
860 struct hv_driver
*drv
=
861 drv_to_hv_drv(device
->driver
);
862 struct mousevsc_drv_obj
*mousevsc_drv_obj
= drv
->priv
;
864 struct hv_device
*device_obj
= device_to_hv_device(device
);
865 struct input_device_context
*input_dev_ctx
;
867 input_dev_ctx
= kmalloc(sizeof(struct input_device_context
),
870 dev_set_drvdata(device
, input_dev_ctx
);
872 if (input_dev_ctx
->connected
) {
873 hidinput_disconnect(input_dev_ctx
->hid_device
);
874 input_dev_ctx
->connected
= 0;
877 if (!mousevsc_drv_obj
->base
.dev_rm
)
881 * Call to the vsc driver to let it know that the device
884 ret
= mousevsc_drv_obj
->base
.dev_rm(device_obj
);
887 DPRINT_ERR(INPUTVSC_DRV
,
888 "unable to remove vsc device (ret %d)", ret
);
891 kfree(input_dev_ctx
);
896 static void reportdesc_callback(struct hv_device
*dev
, void *packet
, u32 len
)
898 struct input_device_context
*input_device_ctx
=
899 dev_get_drvdata(&dev
->device
);
900 struct hid_device
*hid_dev
;
902 /* hid_debug = -1; */
903 hid_dev
= kmalloc(sizeof(struct hid_device
), GFP_KERNEL
);
905 if (hid_parse_report(hid_dev
, packet
, len
)) {
906 DPRINT_INFO(INPUTVSC_DRV
, "Unable to call hd_parse_report");
911 DPRINT_INFO(INPUTVSC_DRV
, "hid_device created");
913 hid_dev
->ll_driver
->open
= mousevsc_hid_open
;
914 hid_dev
->ll_driver
->close
= mousevsc_hid_close
;
916 hid_dev
->bus
= BUS_VIRTUAL
;
917 hid_dev
->vendor
= input_device_ctx
->device_info
.vendor
;
918 hid_dev
->product
= input_device_ctx
->device_info
.product
;
919 hid_dev
->version
= input_device_ctx
->device_info
.version
;
920 hid_dev
->dev
= dev
->device
;
922 sprintf(hid_dev
->name
, "%s",
923 input_device_ctx
->device_info
.name
);
926 * HJ Do we want to call it with a 0
928 if (!hidinput_connect(hid_dev
, 0)) {
929 hid_dev
->claimed
|= HID_CLAIMED_INPUT
;
931 input_device_ctx
->connected
= 1;
933 DPRINT_INFO(INPUTVSC_DRV
,
934 "HID device claimed by input\n");
937 if (!hid_dev
->claimed
) {
938 DPRINT_ERR(INPUTVSC_DRV
,
939 "HID device not claimed by "
940 "input or hiddev\n");
943 input_device_ctx
->hid_device
= hid_dev
;
949 static int mousevsc_drv_exit_cb(struct device
*dev
, void *data
)
951 struct device
**curr
= (struct device
**)data
;
957 static void mousevsc_drv_exit(void)
959 struct mousevsc_drv_obj
*mousevsc_drv_obj
= &g_mousevsc_drv
;
960 struct hv_driver
*drv
= &g_mousevsc_drv
.base
;
963 struct device
*current_dev
= NULL
;
969 ret
= driver_for_each_device(&drv
->driver
, NULL
,
970 (void *)¤t_dev
,
971 mousevsc_drv_exit_cb
);
973 printk(KERN_ERR
"Can't find mouse device!\n");
975 if (current_dev
== NULL
)
978 /* Initiate removal from the top-down */
979 device_unregister(current_dev
);
982 if (mousevsc_drv_obj
->base
.cleanup
)
983 mousevsc_drv_obj
->base
.cleanup(&mousevsc_drv_obj
->base
);
985 vmbus_child_driver_unregister(&drv
->driver
);
990 static int mouse_vsc_initialize(struct hv_driver
*driver
)
992 struct mousevsc_drv_obj
*input_drv
=
993 (struct mousevsc_drv_obj
*)driver
;
996 driver
->name
= driver_name
;
997 memcpy(&driver
->dev_type
, &mouse_guid
,
998 sizeof(struct hv_guid
));
1000 /* Setup the dispatch table */
1001 input_drv
->base
.dev_add
= mousevsc_on_device_add
;
1002 input_drv
->base
.dev_rm
= mousevsc_on_device_remove
;
1003 input_drv
->base
.cleanup
= mousevsc_on_cleanup
;
1009 static int __init
mousevsc_init(void)
1011 struct mousevsc_drv_obj
*input_drv_obj
= &g_mousevsc_drv
;
1012 struct hv_driver
*drv
= &g_mousevsc_drv
.base
;
1014 DPRINT_INFO(INPUTVSC_DRV
, "Hyper-V Mouse driver initializing.");
1016 /* Callback to client driver to complete the initialization */
1017 mouse_vsc_initialize(&input_drv_obj
->base
);
1019 drv
->driver
.name
= input_drv_obj
->base
.name
;
1020 drv
->priv
= input_drv_obj
;
1022 drv
->driver
.probe
= mousevsc_probe
;
1023 drv
->driver
.remove
= mousevsc_remove
;
1025 /* The driver belongs to vmbus */
1026 vmbus_child_driver_register(&drv
->driver
);
1031 static void __exit
mousevsc_exit(void)
1033 mousevsc_drv_exit();
1037 * We don't want to automatically load this driver just yet, it's quite
1038 * broken. It's safe if you want to load it yourself manually, but
1039 * don't inflict it on unsuspecting users, that's just mean.
1044 * We use a PCI table to determine if we should autoload this driver This is
1045 * needed by distro tools to determine if the hyperv drivers should be
1046 * installed and/or configured. We don't do anything else with the table, but
1047 * it needs to be present.
1049 const static struct pci_device_id microsoft_hv_pci_table
[] = {
1050 { PCI_DEVICE(0x1414, 0x5353) }, /* VGA compatible controller */
1053 MODULE_DEVICE_TABLE(pci
, microsoft_hv_pci_table
);
1056 MODULE_LICENSE("GPL");
1057 MODULE_VERSION(HV_DRV_VERSION
);
1058 module_init(mousevsc_init
);
1059 module_exit(mousevsc_exit
);