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 NumOutstandingRequests
;
176 unsigned char bInitializeComplete
;
177 struct mousevsc_prt_msg ProtocolReq
;
178 struct mousevsc_prt_msg ProtocolResp
;
179 /* Synchronize the request/response if needed */
180 wait_queue_head_t ProtocolWaitEvent
;
181 wait_queue_head_t DeviceInfoWaitEvent
;
182 int protocol_wait_condition
;
183 int device_wait_condition
;
184 int DeviceInfoStatus
;
186 struct hid_descriptor
*HidDesc
;
187 unsigned char *ReportDesc
;
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
*AllocInputDevice(struct hv_device
*Device
)
207 struct mousevsc_dev
*inputDevice
;
209 inputDevice
= kzalloc(sizeof(struct mousevsc_dev
), GFP_KERNEL
);
215 * Set to 2 to allow both inbound and outbound traffics
216 * (ie GetInputDevice() and MustGetInputDevice()) to proceed.
218 atomic_cmpxchg(&inputDevice
->RefCount
, 0, 2);
220 inputDevice
->Device
= Device
;
221 Device
->ext
= inputDevice
;
226 static void FreeInputDevice(struct mousevsc_dev
*Device
)
228 WARN_ON(atomic_read(&Device
->RefCount
) == 0);
233 * Get the inputdevice object if exists and its refcount > 1
235 static struct mousevsc_dev
*GetInputDevice(struct hv_device
*Device
)
237 struct mousevsc_dev
*inputDevice
;
239 inputDevice
= (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 * inputDevice->RefCount);
250 if (inputDevice
&& atomic_read(&inputDevice
->RefCount
) > 1)
251 atomic_inc(&inputDevice
->RefCount
);
259 * Get the inputdevice object iff exists and its refcount > 0
261 static struct mousevsc_dev
*MustGetInputDevice(struct hv_device
*Device
)
263 struct mousevsc_dev
*inputDevice
;
265 inputDevice
= (struct mousevsc_dev
*)Device
->ext
;
267 if (inputDevice
&& atomic_read(&inputDevice
->RefCount
))
268 atomic_inc(&inputDevice
->RefCount
);
275 static void PutInputDevice(struct hv_device
*Device
)
277 struct mousevsc_dev
*inputDevice
;
279 inputDevice
= (struct mousevsc_dev
*)Device
->ext
;
281 atomic_dec(&inputDevice
->RefCount
);
285 * Drop ref count to 1 to effectively disable GetInputDevice()
287 static struct mousevsc_dev
*ReleaseInputDevice(struct hv_device
*Device
)
289 struct mousevsc_dev
*inputDevice
;
291 inputDevice
= (struct mousevsc_dev
*)Device
->ext
;
293 /* Busy wait until the ref drop to 2, then set it to 1 */
294 while (atomic_cmpxchg(&inputDevice
->RefCount
, 2, 1) != 2)
301 * Drop ref count to 0. No one can use InputDevice object.
303 static struct mousevsc_dev
*FinalReleaseInputDevice(struct hv_device
*Device
)
305 struct mousevsc_dev
*inputDevice
;
307 inputDevice
= (struct mousevsc_dev
*)Device
->ext
;
309 /* Busy wait until the ref drop to 1, then set it to 0 */
310 while (atomic_cmpxchg(&inputDevice
->RefCount
, 1, 0) != 1)
317 static void MousevscOnSendCompletion(struct hv_device
*Device
, struct vmpacket_descriptor
*Packet
)
319 struct mousevsc_dev
*inputDevice
;
322 inputDevice
= MustGetInputDevice(Device
);
324 pr_err("unable to get input device...device being destroyed?");
328 request
= (void *)(unsigned long)Packet
->trans_id
;
330 if (request
== &inputDevice
->ProtocolReq
) {
332 /* Shouldn't we be doing something here? */
335 PutInputDevice(Device
);
338 static void MousevscOnReceiveDeviceInfo(struct mousevsc_dev
*InputDevice
, struct synthhid_device_info
*DeviceInfo
)
341 struct hid_descriptor
*desc
;
342 struct mousevsc_prt_msg ack
;
344 /* Assume success for now */
345 InputDevice
->DeviceInfoStatus
= 0;
347 /* Save the device attr */
348 memcpy(&InputDevice
->hid_dev_info
, &DeviceInfo
->hid_dev_info
, sizeof(struct hv_input_dev_info
));
350 /* Save the hid desc */
351 desc
= &DeviceInfo
->hid_descriptor
;
352 WARN_ON(desc
->bLength
> 0);
354 InputDevice
->HidDesc
= kzalloc(desc
->bLength
, GFP_KERNEL
);
356 if (!InputDevice
->HidDesc
) {
357 pr_err("unable to allocate hid descriptor - size %d", desc
->bLength
);
361 memcpy(InputDevice
->HidDesc
, desc
, desc
->bLength
);
363 /* Save the report desc */
364 InputDevice
->ReportDescSize
= desc
->desc
[0].wDescriptorLength
;
365 InputDevice
->ReportDesc
= kzalloc(InputDevice
->ReportDescSize
,
368 if (!InputDevice
->ReportDesc
) {
369 pr_err("unable to allocate report descriptor - size %d",
370 InputDevice
->ReportDescSize
);
374 memcpy(InputDevice
->ReportDesc
,
375 ((unsigned char *)desc
) + desc
->bLength
,
376 desc
->desc
[0].wDescriptorLength
);
379 memset(&ack
, 0, sizeof(struct mousevsc_prt_msg
));
381 ack
.type
= PipeMessageData
;
382 ack
.size
= sizeof(struct synthhid_device_info_ack
);
384 ack
.ack
.header
.type
= SynthHidInitialDeviceInfoAck
;
385 ack
.ack
.header
.size
= 1;
386 ack
.ack
.reserved
= 0;
388 ret
= vmbus_sendpacket(InputDevice
->Device
->channel
,
390 sizeof(struct pipe_prt_msg
) - sizeof(unsigned char) +
391 sizeof(struct synthhid_device_info_ack
),
394 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED
);
396 pr_err("unable to send synthhid device info ack - ret %d",
401 InputDevice
->device_wait_condition
= 1;
402 wake_up(&InputDevice
->DeviceInfoWaitEvent
);
407 kfree(InputDevice
->HidDesc
);
408 InputDevice
->HidDesc
= NULL
;
410 kfree(InputDevice
->ReportDesc
);
411 InputDevice
->ReportDesc
= NULL
;
413 InputDevice
->DeviceInfoStatus
= -1;
414 InputDevice
->device_wait_condition
= 1;
415 wake_up(&InputDevice
->DeviceInfoWaitEvent
);
418 static void MousevscOnReceiveInputReport(struct mousevsc_dev
*InputDevice
, struct synthhid_input_report
*InputReport
)
420 struct mousevsc_drv_obj
*inputDriver
;
422 if (!InputDevice
->bInitializeComplete
) {
423 pr_info("Initialization incomplete...ignoring InputReport msg");
427 inputDriver
= (struct mousevsc_drv_obj
*)InputDevice
->Device
->drv
;
429 inputreport_callback(InputDevice
->Device
,
431 InputReport
->header
.size
);
434 static void MousevscOnReceive(struct hv_device
*Device
, struct vmpacket_descriptor
*Packet
)
436 struct pipe_prt_msg
*pipeMsg
;
437 struct synthhid_msg
*hidMsg
;
438 struct mousevsc_dev
*inputDevice
;
440 inputDevice
= MustGetInputDevice(Device
);
442 pr_err("unable to get input device...device being destroyed?");
446 pipeMsg
= (struct pipe_prt_msg
*)((unsigned long)Packet
+ (Packet
->offset8
<< 3));
448 if (pipeMsg
->type
!= PipeMessageData
) {
449 pr_err("unknown pipe msg type - type %d len %d",
450 pipeMsg
->type
, pipeMsg
->size
);
451 PutInputDevice(Device
);
455 hidMsg
= (struct synthhid_msg
*)&pipeMsg
->data
[0];
457 switch (hidMsg
->header
.type
) {
458 case SynthHidProtocolResponse
:
459 memcpy(&inputDevice
->ProtocolResp
, pipeMsg
,
460 pipeMsg
->size
+ sizeof(struct pipe_prt_msg
) -
461 sizeof(unsigned char));
462 inputDevice
->protocol_wait_condition
= 1;
463 wake_up(&inputDevice
->ProtocolWaitEvent
);
466 case SynthHidInitialDeviceInfo
:
467 WARN_ON(pipeMsg
->size
>= sizeof(struct hv_input_dev_info
));
470 * Parse out the device info into device attr,
471 * hid desc and report desc
473 MousevscOnReceiveDeviceInfo(inputDevice
,
474 (struct synthhid_device_info
*)&pipeMsg
->data
[0]);
476 case SynthHidInputReport
:
477 MousevscOnReceiveInputReport(inputDevice
,
478 (struct synthhid_input_report
*)&pipeMsg
->data
[0]);
482 pr_err("unsupported hid msg type - type %d len %d",
483 hidMsg
->header
.type
, hidMsg
->header
.size
);
487 PutInputDevice(Device
);
490 static void MousevscOnChannelCallback(void *Context
)
492 const int packetSize
= 0x100;
494 struct hv_device
*device
= (struct hv_device
*)Context
;
495 struct mousevsc_dev
*inputDevice
;
499 unsigned char packet
[packetSize
];
500 struct vmpacket_descriptor
*desc
;
501 unsigned char *buffer
= packet
;
502 int bufferlen
= packetSize
;
504 inputDevice
= MustGetInputDevice(device
);
507 pr_err("unable to get input device...device being destroyed?");
512 ret
= vmbus_recvpacket_raw(device
->channel
, buffer
, bufferlen
, &bytesRecvd
, &requestId
);
515 if (bytesRecvd
> 0) {
516 desc
= (struct vmpacket_descriptor
*)buffer
;
518 switch (desc
->type
) {
520 MousevscOnSendCompletion(device
,
524 case VM_PKT_DATA_INBAND
:
525 MousevscOnReceive(device
, desc
);
529 pr_err("unhandled packet type %d, tid %llx len %d\n",
537 if (bufferlen
> packetSize
) {
541 bufferlen
= packetSize
;
545 * pr_debug("nothing else to read...");
548 if (bufferlen
> packetSize
) {
552 bufferlen
= packetSize
;
556 } else if (ret
== -2) {
557 /* Handle large packet */
558 bufferlen
= bytesRecvd
;
559 buffer
= kzalloc(bytesRecvd
, GFP_KERNEL
);
561 if (buffer
== NULL
) {
563 bufferlen
= packetSize
;
565 /* Try again next time around */
566 pr_err("unable to allocate buffer of size %d!",
573 PutInputDevice(device
);
578 static int MousevscConnectToVsp(struct hv_device
*Device
)
581 struct mousevsc_dev
*inputDevice
;
582 struct mousevsc_prt_msg
*request
;
583 struct mousevsc_prt_msg
*response
;
585 inputDevice
= GetInputDevice(Device
);
588 pr_err("unable to get input device...device being destroyed?");
592 init_waitqueue_head(&inputDevice
->ProtocolWaitEvent
);
593 init_waitqueue_head(&inputDevice
->DeviceInfoWaitEvent
);
595 request
= &inputDevice
->ProtocolReq
;
598 * Now, initiate the vsc/vsp initialization protocol on the open channel
600 memset(request
, 0, sizeof(struct mousevsc_prt_msg
));
602 request
->type
= PipeMessageData
;
603 request
->size
= sizeof(struct synthhid_protocol_request
);
605 request
->request
.header
.type
= SynthHidProtocolRequest
;
606 request
->request
.header
.size
= sizeof(unsigned long);
607 request
->request
.version_requested
.version
= SYNTHHID_INPUT_VERSION
;
609 pr_info("synthhid protocol request...");
611 ret
= vmbus_sendpacket(Device
->channel
, request
,
612 sizeof(struct pipe_prt_msg
) -
613 sizeof(unsigned char) +
614 sizeof(struct synthhid_protocol_request
),
615 (unsigned long)request
,
617 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED
);
619 pr_err("unable to send synthhid protocol request.");
623 inputDevice
->protocol_wait_condition
= 0;
624 wait_event_timeout(inputDevice
->ProtocolWaitEvent
, inputDevice
->protocol_wait_condition
, msecs_to_jiffies(1000));
625 if (inputDevice
->protocol_wait_condition
== 0) {
630 response
= &inputDevice
->ProtocolResp
;
632 if (!response
->response
.approved
) {
633 pr_err("synthhid protocol request failed (version %d)",
634 SYNTHHID_INPUT_VERSION
);
639 inputDevice
->device_wait_condition
= 0;
640 wait_event_timeout(inputDevice
->DeviceInfoWaitEvent
, inputDevice
->device_wait_condition
, msecs_to_jiffies(1000));
641 if (inputDevice
->device_wait_condition
== 0) {
647 * We should have gotten the device attr, hid desc and report
650 if (!inputDevice
->DeviceInfoStatus
)
651 pr_info("**** input channel up and running!! ****");
656 PutInputDevice(Device
);
661 static int MousevscOnDeviceAdd(struct hv_device
*Device
, void *AdditionalInfo
)
664 struct mousevsc_dev
*inputDevice
;
665 struct mousevsc_drv_obj
*inputDriver
;
666 struct hv_input_dev_info dev_info
;
668 inputDevice
= AllocInputDevice(Device
);
675 inputDevice
->bInitializeComplete
= false;
677 /* Open the channel */
678 ret
= vmbus_open(Device
->channel
,
679 INPUTVSC_SEND_RING_BUFFER_SIZE
,
680 INPUTVSC_RECV_RING_BUFFER_SIZE
,
683 MousevscOnChannelCallback
,
688 pr_err("unable to open channel: %d", ret
);
689 FreeInputDevice(inputDevice
);
693 pr_info("InputVsc channel open: %d", ret
);
695 ret
= MousevscConnectToVsp(Device
);
698 pr_err("unable to connect channel: %d", ret
);
700 vmbus_close(Device
->channel
);
701 FreeInputDevice(inputDevice
);
705 inputDriver
= (struct mousevsc_drv_obj
*)inputDevice
->Device
->drv
;
707 dev_info
.vendor
= inputDevice
->hid_dev_info
.vendor
;
708 dev_info
.product
= inputDevice
->hid_dev_info
.product
;
709 dev_info
.version
= inputDevice
->hid_dev_info
.version
;
710 strcpy(dev_info
.name
, "Microsoft Vmbus HID-compliant Mouse");
712 /* Send the device info back up */
713 deviceinfo_callback(Device
, &dev_info
);
715 /* Send the report desc back up */
716 /* workaround SA-167 */
717 if (inputDevice
->ReportDesc
[14] == 0x25)
718 inputDevice
->ReportDesc
[14] = 0x29;
720 reportdesc_callback(Device
, inputDevice
->ReportDesc
,
721 inputDevice
->ReportDescSize
);
723 inputDevice
->bInitializeComplete
= true;
729 static int MousevscOnDeviceRemove(struct hv_device
*Device
)
731 struct mousevsc_dev
*inputDevice
;
734 pr_info("disabling input device (%p)...",
737 inputDevice
= ReleaseInputDevice(Device
);
741 * At this point, all outbound traffic should be disable. We only
742 * allow inbound traffic (responses) to proceed
744 * so that outstanding requests can be completed.
746 while (inputDevice
->NumOutstandingRequests
) {
747 pr_info("waiting for %d requests to complete...", inputDevice
->NumOutstandingRequests
);
752 pr_info("removing input device (%p)...", Device
->ext
);
754 inputDevice
= FinalReleaseInputDevice(Device
);
756 pr_info("input device (%p) safe to remove", inputDevice
);
758 /* Close the channel */
759 vmbus_close(Device
->channel
);
761 FreeInputDevice(inputDevice
);
766 static void MousevscOnCleanup(struct hv_driver
*drv
)
773 struct input_device_context
{
774 struct hv_device
*device_ctx
;
775 struct hid_device
*hid_device
;
776 struct hv_input_dev_info device_info
;
781 static struct mousevsc_drv_obj g_mousevsc_drv
;
783 static void deviceinfo_callback(struct hv_device
*dev
, struct hv_input_dev_info
*info
)
785 struct input_device_context
*input_device_ctx
=
786 dev_get_drvdata(&dev
->device
);
788 memcpy(&input_device_ctx
->device_info
, info
,
789 sizeof(struct hv_input_dev_info
));
791 DPRINT_INFO(INPUTVSC_DRV
, "%s", __func__
);
794 static void inputreport_callback(struct hv_device
*dev
, void *packet
, u32 len
)
798 struct input_device_context
*input_dev_ctx
=
799 dev_get_drvdata(&dev
->device
);
801 ret
= hid_input_report(input_dev_ctx
->hid_device
,
802 HID_INPUT_REPORT
, packet
, len
, 1);
804 DPRINT_DBG(INPUTVSC_DRV
, "hid_input_report (ret %d)", ret
);
807 static int mousevsc_hid_open(struct hid_device
*hid
)
812 static void mousevsc_hid_close(struct hid_device
*hid
)
816 static int mousevsc_probe(struct device
*device
)
820 struct hv_driver
*drv
=
821 drv_to_hv_drv(device
->driver
);
822 struct mousevsc_drv_obj
*mousevsc_drv_obj
= drv
->priv
;
824 struct hv_device
*device_obj
= device_to_hv_device(device
);
825 struct input_device_context
*input_dev_ctx
;
827 input_dev_ctx
= kmalloc(sizeof(struct input_device_context
),
830 dev_set_drvdata(device
, input_dev_ctx
);
832 /* Call to the vsc driver to add the device */
833 ret
= mousevsc_drv_obj
->Base
.dev_add(device_obj
, NULL
);
836 DPRINT_ERR(INPUTVSC_DRV
, "unable to add input vsc device");
844 static int mousevsc_remove(struct device
*device
)
848 struct hv_driver
*drv
=
849 drv_to_hv_drv(device
->driver
);
850 struct mousevsc_drv_obj
*mousevsc_drv_obj
= drv
->priv
;
852 struct hv_device
*device_obj
= device_to_hv_device(device
);
853 struct input_device_context
*input_dev_ctx
;
855 input_dev_ctx
= kmalloc(sizeof(struct input_device_context
),
858 dev_set_drvdata(device
, input_dev_ctx
);
860 if (input_dev_ctx
->connected
) {
861 hidinput_disconnect(input_dev_ctx
->hid_device
);
862 input_dev_ctx
->connected
= 0;
865 if (!mousevsc_drv_obj
->Base
.dev_rm
)
869 * Call to the vsc driver to let it know that the device
872 ret
= mousevsc_drv_obj
->Base
.dev_rm(device_obj
);
875 DPRINT_ERR(INPUTVSC_DRV
,
876 "unable to remove vsc device (ret %d)", ret
);
879 kfree(input_dev_ctx
);
884 static void reportdesc_callback(struct hv_device
*dev
, void *packet
, u32 len
)
886 struct input_device_context
*input_device_ctx
=
887 dev_get_drvdata(&dev
->device
);
888 struct hid_device
*hid_dev
;
890 /* hid_debug = -1; */
891 hid_dev
= kmalloc(sizeof(struct hid_device
), GFP_KERNEL
);
893 if (hid_parse_report(hid_dev
, packet
, len
)) {
894 DPRINT_INFO(INPUTVSC_DRV
, "Unable to call hd_parse_report");
899 DPRINT_INFO(INPUTVSC_DRV
, "hid_device created");
901 hid_dev
->ll_driver
->open
= mousevsc_hid_open
;
902 hid_dev
->ll_driver
->close
= mousevsc_hid_close
;
904 hid_dev
->bus
= BUS_VIRTUAL
;
905 hid_dev
->vendor
= input_device_ctx
->device_info
.vendor
;
906 hid_dev
->product
= input_device_ctx
->device_info
.product
;
907 hid_dev
->version
= input_device_ctx
->device_info
.version
;
908 hid_dev
->dev
= dev
->device
;
910 sprintf(hid_dev
->name
, "%s",
911 input_device_ctx
->device_info
.name
);
914 * HJ Do we want to call it with a 0
916 if (!hidinput_connect(hid_dev
, 0)) {
917 hid_dev
->claimed
|= HID_CLAIMED_INPUT
;
919 input_device_ctx
->connected
= 1;
921 DPRINT_INFO(INPUTVSC_DRV
,
922 "HID device claimed by input\n");
925 if (!hid_dev
->claimed
) {
926 DPRINT_ERR(INPUTVSC_DRV
,
927 "HID device not claimed by "
928 "input or hiddev\n");
931 input_device_ctx
->hid_device
= hid_dev
;
937 static int mousevsc_drv_exit_cb(struct device
*dev
, void *data
)
939 struct device
**curr
= (struct device
**)data
;
945 static void mousevsc_drv_exit(void)
947 struct mousevsc_drv_obj
*mousevsc_drv_obj
= &g_mousevsc_drv
;
948 struct hv_driver
*drv
= &g_mousevsc_drv
.Base
;
951 struct device
*current_dev
= NULL
;
957 ret
= driver_for_each_device(&drv
->driver
, NULL
,
958 (void *)¤t_dev
,
959 mousevsc_drv_exit_cb
);
961 printk(KERN_ERR
"Can't find mouse device!\n");
963 if (current_dev
== NULL
)
966 /* Initiate removal from the top-down */
967 device_unregister(current_dev
);
970 if (mousevsc_drv_obj
->Base
.cleanup
)
971 mousevsc_drv_obj
->Base
.cleanup(&mousevsc_drv_obj
->Base
);
973 vmbus_child_driver_unregister(&drv
->driver
);
978 static int mouse_vsc_initialize(struct hv_driver
*Driver
)
980 struct mousevsc_drv_obj
*inputDriver
=
981 (struct mousevsc_drv_obj
*)Driver
;
984 Driver
->name
= driver_name
;
985 memcpy(&Driver
->dev_type
, &mouse_guid
,
986 sizeof(struct hv_guid
));
988 /* Setup the dispatch table */
989 inputDriver
->Base
.dev_add
= MousevscOnDeviceAdd
;
990 inputDriver
->Base
.dev_rm
= MousevscOnDeviceRemove
;
991 inputDriver
->Base
.cleanup
= MousevscOnCleanup
;
997 static int __init
mousevsc_init(void)
999 struct mousevsc_drv_obj
*input_drv_obj
= &g_mousevsc_drv
;
1000 struct hv_driver
*drv
= &g_mousevsc_drv
.Base
;
1002 DPRINT_INFO(INPUTVSC_DRV
, "Hyper-V Mouse driver initializing.");
1004 /* Callback to client driver to complete the initialization */
1005 mouse_vsc_initialize(&input_drv_obj
->Base
);
1007 drv
->driver
.name
= input_drv_obj
->Base
.name
;
1008 drv
->priv
= input_drv_obj
;
1010 drv
->driver
.probe
= mousevsc_probe
;
1011 drv
->driver
.remove
= mousevsc_remove
;
1013 /* The driver belongs to vmbus */
1014 vmbus_child_driver_register(&drv
->driver
);
1019 static void __exit
mousevsc_exit(void)
1021 mousevsc_drv_exit();
1025 * We don't want to automatically load this driver just yet, it's quite
1026 * broken. It's safe if you want to load it yourself manually, but
1027 * don't inflict it on unsuspecting users, that's just mean.
1032 * We use a PCI table to determine if we should autoload this driver This is
1033 * needed by distro tools to determine if the hyperv drivers should be
1034 * installed and/or configured. We don't do anything else with the table, but
1035 * it needs to be present.
1037 const static struct pci_device_id microsoft_hv_pci_table
[] = {
1038 { PCI_DEVICE(0x1414, 0x5353) }, /* VGA compatible controller */
1041 MODULE_DEVICE_TABLE(pci
, microsoft_hv_pci_table
);
1044 MODULE_LICENSE("GPL");
1045 MODULE_VERSION(HV_DRV_VERSION
);
1046 module_init(mousevsc_init
);
1047 module_exit(mousevsc_exit
);