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/device.h>
18 #include <linux/workqueue.h>
19 #include <linux/sched.h>
20 #include <linux/wait.h>
21 #include <linux/input.h>
22 #include <linux/hid.h>
23 #include <linux/hiddev.h>
24 #include <linux/pci.h>
25 #include <linux/dmi.h>
29 #include "version_info.h"
31 #include "vmbus_api.h"
33 #include "vmbus_packet_format.h"
39 struct hv_input_dev_info
{
40 unsigned short vendor
;
41 unsigned short product
;
42 unsigned short version
;
46 /* Represents the input vsc driver */
47 /* FIXME - can be removed entirely */
48 struct mousevsc_drv_obj
{
49 struct hv_driver Base
;
53 /* The maximum size of a synthetic input message. */
54 #define SYNTHHID_MAX_INPUT_REPORT_SIZE 16
60 * Beta, RC < 2008/1/22 1,0
63 #define SYNTHHID_INPUT_VERSION_MAJOR 2
64 #define SYNTHHID_INPUT_VERSION_MINOR 0
65 #define SYNTHHID_INPUT_VERSION_DWORD (SYNTHHID_INPUT_VERSION_MINOR | \
66 (SYNTHHID_INPUT_VERSION_MAJOR << 16))
71 * Message types in the synthetic input protocol
73 enum synthhid_msg_type
{
74 SynthHidProtocolRequest
,
75 SynthHidProtocolResponse
,
76 SynthHidInitialDeviceInfo
,
77 SynthHidInitialDeviceInfoAck
,
83 * Basic message structures.
85 struct synthhid_msg_hdr
{
86 enum synthhid_msg_type Type
; /* Type of the enclosed message */
87 u32 Size
; /* Size of the enclosed message
88 * (size of the data payload)
93 struct synthhid_msg_hdr Header
;
94 char Data
[1]; /* Enclosed message */
97 union synthhid_version
{
109 struct synthhid_protocol_request
{
110 struct synthhid_msg_hdr Header
;
111 union synthhid_version VersionRequested
;
114 struct synthhid_protocol_response
{
115 struct synthhid_msg_hdr Header
;
116 union synthhid_version VersionRequested
;
117 unsigned char Approved
;
120 struct synthhid_device_info
{
121 struct synthhid_msg_hdr Header
;
122 struct hv_input_dev_info HidDeviceAttributes
;
123 unsigned char HidDescriptorInformation
[1];
126 struct synthhid_device_info_ack
{
127 struct synthhid_msg_hdr Header
;
128 unsigned char Reserved
;
131 struct synthhid_input_report
{
132 struct synthhid_msg_hdr Header
;
133 char ReportBuffer
[1];
138 #define INPUTVSC_SEND_RING_BUFFER_SIZE 10*PAGE_SIZE
139 #define INPUTVSC_RECV_RING_BUFFER_SIZE 10*PAGE_SIZE
141 #define NBITS(x) (((x)/BITS_PER_LONG)+1)
143 enum pipe_prot_msg_type
{
144 PipeMessageInvalid
= 0,
150 struct pipe_prt_msg
{
151 enum pipe_prot_msg_type PacketType
;
159 struct mousevsc_prt_msg
{
160 enum pipe_prot_msg_type PacketType
;
163 struct synthhid_protocol_request Request
;
164 struct synthhid_protocol_response Response
;
165 struct synthhid_device_info_ack Ack
;
170 * Represents an mousevsc device
172 struct mousevsc_dev
{
173 struct hv_device
*Device
;
174 /* 0 indicates the device is being destroyed */
176 int NumOutstandingRequests
;
177 unsigned char bInitializeComplete
;
178 struct mousevsc_prt_msg ProtocolReq
;
179 struct mousevsc_prt_msg ProtocolResp
;
180 /* Synchronize the request/response if needed */
181 wait_queue_head_t ProtocolWaitEvent
;
182 wait_queue_head_t DeviceInfoWaitEvent
;
183 int protocol_wait_condition
;
184 int device_wait_condition
;
185 int DeviceInfoStatus
;
187 struct hid_descriptor
*HidDesc
;
188 unsigned char *ReportDesc
;
190 struct hv_input_dev_info DeviceAttr
;
197 static const char *gDriverName
= "mousevsc";
199 /* {CFA8B69E-5B4A-4cc0-B98B-8BA1A1F3F95A} */
200 static const struct hv_guid gMousevscDeviceType
= {
201 .data
= {0x9E, 0xB6, 0xA8, 0xCF, 0x4A, 0x5B, 0xc0, 0x4c,
202 0xB9, 0x8B, 0x8B, 0xA1, 0xA1, 0xF3, 0xF9, 0x5A}
205 static void MousevscOnReceive(struct hv_device
*Device
,
206 struct vmpacket_descriptor
*Packet
);
208 static void deviceinfo_callback(struct hv_device
*dev
, struct hv_input_dev_info
*info
);
209 static void inputreport_callback(struct hv_device
*dev
, void *packet
, u32 len
);
210 static void reportdesc_callback(struct hv_device
*dev
, void *packet
, u32 len
);
212 static struct mousevsc_dev
*AllocInputDevice(struct hv_device
*Device
)
214 struct mousevsc_dev
*inputDevice
;
216 inputDevice
= kzalloc(sizeof(struct mousevsc_dev
), GFP_KERNEL
);
222 * Set to 2 to allow both inbound and outbound traffics
223 * (ie GetInputDevice() and MustGetInputDevice()) to proceed.
225 atomic_cmpxchg(&inputDevice
->RefCount
, 0, 2);
227 inputDevice
->Device
= Device
;
228 Device
->ext
= inputDevice
;
233 static void FreeInputDevice(struct mousevsc_dev
*Device
)
235 WARN_ON(atomic_read(&Device
->RefCount
) == 0);
240 * Get the inputdevice object if exists and its refcount > 1
242 static struct mousevsc_dev
*GetInputDevice(struct hv_device
*Device
)
244 struct mousevsc_dev
*inputDevice
;
246 inputDevice
= (struct mousevsc_dev
*)Device
->ext
;
250 * This sure isn't a valid thing to print for debugging, no matter
251 * what the intention is...
253 * printk(KERN_ERR "-------------------------> REFCOUNT = %d",
254 * inputDevice->RefCount);
257 if (inputDevice
&& atomic_read(&inputDevice
->RefCount
) > 1)
258 atomic_inc(&inputDevice
->RefCount
);
266 * Get the inputdevice object iff exists and its refcount > 0
268 static struct mousevsc_dev
*MustGetInputDevice(struct hv_device
*Device
)
270 struct mousevsc_dev
*inputDevice
;
272 inputDevice
= (struct mousevsc_dev
*)Device
->ext
;
274 if (inputDevice
&& atomic_read(&inputDevice
->RefCount
))
275 atomic_inc(&inputDevice
->RefCount
);
282 static void PutInputDevice(struct hv_device
*Device
)
284 struct mousevsc_dev
*inputDevice
;
286 inputDevice
= (struct mousevsc_dev
*)Device
->ext
;
288 atomic_dec(&inputDevice
->RefCount
);
292 * Drop ref count to 1 to effectively disable GetInputDevice()
294 static struct mousevsc_dev
*ReleaseInputDevice(struct hv_device
*Device
)
296 struct mousevsc_dev
*inputDevice
;
298 inputDevice
= (struct mousevsc_dev
*)Device
->ext
;
300 /* Busy wait until the ref drop to 2, then set it to 1 */
301 while (atomic_cmpxchg(&inputDevice
->RefCount
, 2, 1) != 2)
308 * Drop ref count to 0. No one can use InputDevice object.
310 static struct mousevsc_dev
*FinalReleaseInputDevice(struct hv_device
*Device
)
312 struct mousevsc_dev
*inputDevice
;
314 inputDevice
= (struct mousevsc_dev
*)Device
->ext
;
316 /* Busy wait until the ref drop to 1, then set it to 0 */
317 while (atomic_cmpxchg(&inputDevice
->RefCount
, 1, 0) != 1)
324 static void MousevscOnSendCompletion(struct hv_device
*Device
, struct vmpacket_descriptor
*Packet
)
326 struct mousevsc_dev
*inputDevice
;
329 inputDevice
= MustGetInputDevice(Device
);
331 pr_err("unable to get input device...device being destroyed?");
335 request
= (void *)(unsigned long *)Packet
->trans_id
;
337 if (request
== &inputDevice
->ProtocolReq
) {
339 /* Shouldn't we be doing something here? */
342 PutInputDevice(Device
);
345 static void MousevscOnReceiveDeviceInfo(struct mousevsc_dev
*InputDevice
, struct synthhid_device_info
*DeviceInfo
)
348 struct hid_descriptor
*desc
;
349 struct mousevsc_prt_msg ack
;
351 /* Assume success for now */
352 InputDevice
->DeviceInfoStatus
= 0;
354 /* Save the device attr */
355 memcpy(&InputDevice
->DeviceAttr
, &DeviceInfo
->HidDeviceAttributes
, sizeof(struct hv_input_dev_info
));
357 /* Save the hid desc */
358 desc
= (struct hid_descriptor
*)DeviceInfo
->HidDescriptorInformation
;
359 WARN_ON(desc
->bLength
> 0);
361 InputDevice
->HidDesc
= kzalloc(desc
->bLength
, GFP_KERNEL
);
363 if (!InputDevice
->HidDesc
) {
364 pr_err("unable to allocate hid descriptor - size %d", desc
->bLength
);
368 memcpy(InputDevice
->HidDesc
, desc
, desc
->bLength
);
370 /* Save the report desc */
371 InputDevice
->ReportDescSize
= desc
->desc
[0].wDescriptorLength
;
372 InputDevice
->ReportDesc
= kzalloc(InputDevice
->ReportDescSize
,
375 if (!InputDevice
->ReportDesc
) {
376 pr_err("unable to allocate report descriptor - size %d",
377 InputDevice
->ReportDescSize
);
381 memcpy(InputDevice
->ReportDesc
,
382 ((unsigned char *)desc
) + desc
->bLength
,
383 desc
->desc
[0].wDescriptorLength
);
386 memset(&ack
, sizeof(struct mousevsc_prt_msg
), 0);
388 ack
.PacketType
= PipeMessageData
;
389 ack
.DataSize
= sizeof(struct synthhid_device_info_ack
);
391 ack
.u
.Ack
.Header
.Type
= SynthHidInitialDeviceInfoAck
;
392 ack
.u
.Ack
.Header
.Size
= 1;
393 ack
.u
.Ack
.Reserved
= 0;
395 ret
= vmbus_sendpacket(InputDevice
->Device
->channel
,
397 sizeof(struct pipe_prt_msg
) - sizeof(unsigned char) +
398 sizeof(struct synthhid_device_info_ack
),
401 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED
);
403 pr_err("unable to send synthhid device info ack - ret %d",
408 InputDevice
->device_wait_condition
= 1;
409 wake_up(&InputDevice
->DeviceInfoWaitEvent
);
414 if (InputDevice
->HidDesc
) {
415 kfree(InputDevice
->HidDesc
);
416 InputDevice
->HidDesc
= NULL
;
419 if (InputDevice
->ReportDesc
) {
420 kfree(InputDevice
->ReportDesc
);
421 InputDevice
->ReportDesc
= NULL
;
424 InputDevice
->DeviceInfoStatus
= -1;
425 InputDevice
->device_wait_condition
= 1;
426 wake_up(&InputDevice
->DeviceInfoWaitEvent
);
429 static void MousevscOnReceiveInputReport(struct mousevsc_dev
*InputDevice
, struct synthhid_input_report
*InputReport
)
431 struct mousevsc_drv_obj
*inputDriver
;
433 if (!InputDevice
->bInitializeComplete
) {
434 pr_info("Initialization incomplete...ignoring InputReport msg");
438 inputDriver
= (struct mousevsc_drv_obj
*)InputDevice
->Device
->drv
;
440 inputreport_callback(InputDevice
->Device
,
441 InputReport
->ReportBuffer
,
442 InputReport
->Header
.Size
);
445 static void MousevscOnReceive(struct hv_device
*Device
, struct vmpacket_descriptor
*Packet
)
447 struct pipe_prt_msg
*pipeMsg
;
448 struct synthhid_msg
*hidMsg
;
449 struct mousevsc_dev
*inputDevice
;
451 inputDevice
= MustGetInputDevice(Device
);
453 pr_err("unable to get input device...device being destroyed?");
457 pipeMsg
= (struct pipe_prt_msg
*)((unsigned long)Packet
+ (Packet
->offset8
<< 3));
459 if (pipeMsg
->PacketType
!= PipeMessageData
) {
460 pr_err("unknown pipe msg type - type %d len %d",
461 pipeMsg
->PacketType
, pipeMsg
->DataSize
);
462 PutInputDevice(Device
);
466 hidMsg
= (struct synthhid_msg
*)&pipeMsg
->Data
[0];
468 switch (hidMsg
->Header
.Type
) {
469 case SynthHidProtocolResponse
:
470 memcpy(&inputDevice
->ProtocolResp
, pipeMsg
, pipeMsg
->DataSize
+sizeof(struct pipe_prt_msg
) - sizeof(unsigned char));
471 inputDevice
->protocol_wait_condition
= 1;
472 wake_up(&inputDevice
->ProtocolWaitEvent
);
475 case SynthHidInitialDeviceInfo
:
476 WARN_ON(pipeMsg
->DataSize
>= sizeof(struct hv_input_dev_info
));
479 * Parse out the device info into device attr,
480 * hid desc and report desc
482 MousevscOnReceiveDeviceInfo(inputDevice
,
483 (struct synthhid_device_info
*)&pipeMsg
->Data
[0]);
485 case SynthHidInputReport
:
486 MousevscOnReceiveInputReport(inputDevice
,
487 (struct synthhid_input_report
*)&pipeMsg
->Data
[0]);
491 pr_err("unsupported hid msg type - type %d len %d",
492 hidMsg
->Header
.Type
, hidMsg
->Header
.Size
);
496 PutInputDevice(Device
);
499 static void MousevscOnChannelCallback(void *Context
)
501 const int packetSize
= 0x100;
503 struct hv_device
*device
= (struct hv_device
*)Context
;
504 struct mousevsc_dev
*inputDevice
;
508 unsigned char packet
[packetSize
];
509 struct vmpacket_descriptor
*desc
;
510 unsigned char *buffer
= packet
;
511 int bufferlen
= packetSize
;
513 inputDevice
= MustGetInputDevice(device
);
516 pr_err("unable to get input device...device being destroyed?");
521 ret
= vmbus_recvpacket_raw(device
->channel
, buffer
, bufferlen
, &bytesRecvd
, &requestId
);
524 if (bytesRecvd
> 0) {
525 desc
= (struct vmpacket_descriptor
*)buffer
;
527 switch (desc
->type
) {
529 MousevscOnSendCompletion(device
,
533 case VM_PKT_DATA_INBAND
:
534 MousevscOnReceive(device
, desc
);
538 pr_err("unhandled packet type %d, tid %llx len %d\n",
546 if (bufferlen
> packetSize
) {
550 bufferlen
= packetSize
;
554 * pr_debug("nothing else to read...");
557 if (bufferlen
> packetSize
) {
561 bufferlen
= packetSize
;
565 } else if (ret
== -2) {
566 /* Handle large packet */
567 bufferlen
= bytesRecvd
;
568 buffer
= kzalloc(bytesRecvd
, GFP_KERNEL
);
570 if (buffer
== NULL
) {
572 bufferlen
= packetSize
;
574 /* Try again next time around */
575 pr_err("unable to allocate buffer of size %d!",
582 PutInputDevice(device
);
587 static int MousevscConnectToVsp(struct hv_device
*Device
)
590 struct mousevsc_dev
*inputDevice
;
591 struct mousevsc_prt_msg
*request
;
592 struct mousevsc_prt_msg
*response
;
594 inputDevice
= GetInputDevice(Device
);
597 pr_err("unable to get input device...device being destroyed?");
601 init_waitqueue_head(&inputDevice
->ProtocolWaitEvent
);
602 init_waitqueue_head(&inputDevice
->DeviceInfoWaitEvent
);
604 request
= &inputDevice
->ProtocolReq
;
607 * Now, initiate the vsc/vsp initialization protocol on the open channel
609 memset(request
, sizeof(struct mousevsc_prt_msg
), 0);
611 request
->PacketType
= PipeMessageData
;
612 request
->DataSize
= sizeof(struct synthhid_protocol_request
);
614 request
->u
.Request
.Header
.Type
= SynthHidProtocolRequest
;
615 request
->u
.Request
.Header
.Size
= sizeof(unsigned long);
616 request
->u
.Request
.VersionRequested
.AsDWord
=
617 SYNTHHID_INPUT_VERSION_DWORD
;
619 pr_info("synthhid protocol request...");
621 ret
= vmbus_sendpacket(Device
->channel
, request
,
622 sizeof(struct pipe_prt_msg
) -
623 sizeof(unsigned char) +
624 sizeof(struct synthhid_protocol_request
),
625 (unsigned long)request
,
627 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED
);
629 pr_err("unable to send synthhid protocol request.");
633 inputDevice
->protocol_wait_condition
= 0;
634 wait_event_timeout(inputDevice
->ProtocolWaitEvent
, inputDevice
->protocol_wait_condition
, msecs_to_jiffies(1000));
635 if (inputDevice
->protocol_wait_condition
== 0) {
640 response
= &inputDevice
->ProtocolResp
;
642 if (!response
->u
.Response
.Approved
) {
643 pr_err("synthhid protocol request failed (version %d)",
644 SYNTHHID_INPUT_VERSION_DWORD
);
649 inputDevice
->device_wait_condition
= 0;
650 wait_event_timeout(inputDevice
->DeviceInfoWaitEvent
, inputDevice
->device_wait_condition
, msecs_to_jiffies(1000));
651 if (inputDevice
->device_wait_condition
== 0) {
657 * We should have gotten the device attr, hid desc and report
660 if (!inputDevice
->DeviceInfoStatus
)
661 pr_info("**** input channel up and running!! ****");
666 PutInputDevice(Device
);
671 static int MousevscOnDeviceAdd(struct hv_device
*Device
, void *AdditionalInfo
)
674 struct mousevsc_dev
*inputDevice
;
675 struct mousevsc_drv_obj
*inputDriver
;
676 struct hv_input_dev_info deviceInfo
;
678 inputDevice
= AllocInputDevice(Device
);
685 inputDevice
->bInitializeComplete
= false;
687 /* Open the channel */
688 ret
= vmbus_open(Device
->channel
,
689 INPUTVSC_SEND_RING_BUFFER_SIZE
,
690 INPUTVSC_RECV_RING_BUFFER_SIZE
,
693 MousevscOnChannelCallback
,
698 pr_err("unable to open channel: %d", ret
);
702 pr_info("InputVsc channel open: %d", ret
);
704 ret
= MousevscConnectToVsp(Device
);
707 pr_err("unable to connect channel: %d", ret
);
709 vmbus_close(Device
->channel
);
713 inputDriver
= (struct mousevsc_drv_obj
*)inputDevice
->Device
->drv
;
715 deviceInfo
.vendor
= inputDevice
->DeviceAttr
.vendor
;
716 deviceInfo
.product
= inputDevice
->DeviceAttr
.product
;
717 deviceInfo
.version
= inputDevice
->DeviceAttr
.version
;
718 strcpy(deviceInfo
.name
, "Microsoft Vmbus HID-compliant Mouse");
720 /* Send the device info back up */
721 deviceinfo_callback(Device
, &deviceInfo
);
723 /* Send the report desc back up */
724 /* workaround SA-167 */
725 if (inputDevice
->ReportDesc
[14] == 0x25)
726 inputDevice
->ReportDesc
[14] = 0x29;
728 reportdesc_callback(Device
, inputDevice
->ReportDesc
,
729 inputDevice
->ReportDescSize
);
731 inputDevice
->bInitializeComplete
= true;
737 static int MousevscOnDeviceRemove(struct hv_device
*Device
)
739 struct mousevsc_dev
*inputDevice
;
742 pr_info("disabling input device (%p)...",
745 inputDevice
= ReleaseInputDevice(Device
);
749 * At this point, all outbound traffic should be disable. We only
750 * allow inbound traffic (responses) to proceed
752 * so that outstanding requests can be completed.
754 while (inputDevice
->NumOutstandingRequests
) {
755 pr_info("waiting for %d requests to complete...", inputDevice
->NumOutstandingRequests
);
760 pr_info("removing input device (%p)...", Device
->ext
);
762 inputDevice
= FinalReleaseInputDevice(Device
);
764 pr_info("input device (%p) safe to remove", inputDevice
);
766 /* Close the channel */
767 vmbus_close(Device
->channel
);
769 FreeInputDevice(inputDevice
);
774 static void MousevscOnCleanup(struct hv_driver
*drv
)
781 struct input_device_context
{
782 struct vm_device
*device_ctx
;
783 struct hid_device
*hid_device
;
784 struct hv_input_dev_info device_info
;
788 struct mousevsc_driver_context
{
789 struct driver_context drv_ctx
;
790 struct mousevsc_drv_obj drv_obj
;
793 static struct mousevsc_driver_context g_mousevsc_drv
;
795 static void deviceinfo_callback(struct hv_device
*dev
, struct hv_input_dev_info
*info
)
797 struct vm_device
*device_ctx
= to_vm_device(dev
);
798 struct input_device_context
*input_device_ctx
=
799 dev_get_drvdata(&device_ctx
->device
);
801 memcpy(&input_device_ctx
->device_info
, info
,
802 sizeof(struct hv_input_dev_info
));
804 DPRINT_INFO(INPUTVSC_DRV
, "%s", __func__
);
807 static void inputreport_callback(struct hv_device
*dev
, void *packet
, u32 len
)
811 struct vm_device
*device_ctx
= to_vm_device(dev
);
812 struct input_device_context
*input_dev_ctx
=
813 dev_get_drvdata(&device_ctx
->device
);
815 ret
= hid_input_report(input_dev_ctx
->hid_device
,
816 HID_INPUT_REPORT
, packet
, len
, 1);
818 DPRINT_DBG(INPUTVSC_DRV
, "hid_input_report (ret %d)", ret
);
821 static int mousevsc_hid_open(struct hid_device
*hid
)
826 static void mousevsc_hid_close(struct hid_device
*hid
)
830 static int mousevsc_probe(struct device
*device
)
834 struct driver_context
*driver_ctx
=
835 driver_to_driver_context(device
->driver
);
836 struct mousevsc_driver_context
*mousevsc_drv_ctx
=
837 (struct mousevsc_driver_context
*)driver_ctx
;
838 struct mousevsc_drv_obj
*mousevsc_drv_obj
= &mousevsc_drv_ctx
->drv_obj
;
840 struct vm_device
*device_ctx
= device_to_vm_device(device
);
841 struct hv_device
*device_obj
= &device_ctx
->device_obj
;
842 struct input_device_context
*input_dev_ctx
;
844 input_dev_ctx
= kmalloc(sizeof(struct input_device_context
),
847 dev_set_drvdata(device
, input_dev_ctx
);
849 /* Call to the vsc driver to add the device */
850 ret
= mousevsc_drv_obj
->Base
.dev_add(device_obj
, NULL
);
853 DPRINT_ERR(INPUTVSC_DRV
, "unable to add input vsc device");
861 static int mousevsc_remove(struct device
*device
)
865 struct driver_context
*driver_ctx
=
866 driver_to_driver_context(device
->driver
);
867 struct mousevsc_driver_context
*mousevsc_drv_ctx
=
868 (struct mousevsc_driver_context
*)driver_ctx
;
869 struct mousevsc_drv_obj
*mousevsc_drv_obj
= &mousevsc_drv_ctx
->drv_obj
;
871 struct vm_device
*device_ctx
= device_to_vm_device(device
);
872 struct hv_device
*device_obj
= &device_ctx
->device_obj
;
873 struct input_device_context
*input_dev_ctx
;
875 input_dev_ctx
= kmalloc(sizeof(struct input_device_context
),
878 dev_set_drvdata(device
, input_dev_ctx
);
880 if (input_dev_ctx
->connected
) {
881 hidinput_disconnect(input_dev_ctx
->hid_device
);
882 input_dev_ctx
->connected
= 0;
885 if (!mousevsc_drv_obj
->Base
.dev_rm
)
889 * Call to the vsc driver to let it know that the device
892 ret
= mousevsc_drv_obj
->Base
.dev_rm(device_obj
);
895 DPRINT_ERR(INPUTVSC_DRV
,
896 "unable to remove vsc device (ret %d)", ret
);
899 kfree(input_dev_ctx
);
904 static void reportdesc_callback(struct hv_device
*dev
, void *packet
, u32 len
)
906 struct vm_device
*device_ctx
= to_vm_device(dev
);
907 struct input_device_context
*input_device_ctx
=
908 dev_get_drvdata(&device_ctx
->device
);
909 struct hid_device
*hid_dev
;
911 /* hid_debug = -1; */
912 hid_dev
= kmalloc(sizeof(struct hid_device
), GFP_KERNEL
);
914 if (hid_parse_report(hid_dev
, packet
, len
)) {
915 DPRINT_INFO(INPUTVSC_DRV
, "Unable to call hd_parse_report");
920 DPRINT_INFO(INPUTVSC_DRV
, "hid_device created");
922 hid_dev
->ll_driver
->open
= mousevsc_hid_open
;
923 hid_dev
->ll_driver
->close
= mousevsc_hid_close
;
925 hid_dev
->bus
= BUS_VIRTUAL
;
926 hid_dev
->vendor
= input_device_ctx
->device_info
.vendor
;
927 hid_dev
->product
= input_device_ctx
->device_info
.product
;
928 hid_dev
->version
= input_device_ctx
->device_info
.version
;
929 hid_dev
->dev
= device_ctx
->device
;
931 sprintf(hid_dev
->name
, "%s",
932 input_device_ctx
->device_info
.name
);
935 * HJ Do we want to call it with a 0
937 if (!hidinput_connect(hid_dev
, 0)) {
938 hid_dev
->claimed
|= HID_CLAIMED_INPUT
;
940 input_device_ctx
->connected
= 1;
942 DPRINT_INFO(INPUTVSC_DRV
,
943 "HID device claimed by input\n");
946 if (!hid_dev
->claimed
) {
947 DPRINT_ERR(INPUTVSC_DRV
,
948 "HID device not claimed by "
949 "input or hiddev\n");
952 input_device_ctx
->hid_device
= hid_dev
;
958 static int mousevsc_drv_exit_cb(struct device
*dev
, void *data
)
960 struct device
**curr
= (struct device
**)data
;
966 static void mousevsc_drv_exit(void)
968 struct mousevsc_drv_obj
*mousevsc_drv_obj
= &g_mousevsc_drv
.drv_obj
;
969 struct driver_context
*drv_ctx
= &g_mousevsc_drv
.drv_ctx
;
972 struct device
*current_dev
= NULL
;
978 ret
= driver_for_each_device(&drv_ctx
->driver
, NULL
,
979 (void *)¤t_dev
,
980 mousevsc_drv_exit_cb
);
982 printk(KERN_ERR
"Can't find mouse device!\n");
984 if (current_dev
== NULL
)
987 /* Initiate removal from the top-down */
988 device_unregister(current_dev
);
991 if (mousevsc_drv_obj
->Base
.cleanup
)
992 mousevsc_drv_obj
->Base
.cleanup(&mousevsc_drv_obj
->Base
);
994 vmbus_child_driver_unregister(drv_ctx
);
999 static int mouse_vsc_initialize(struct hv_driver
*Driver
)
1001 struct mousevsc_drv_obj
*inputDriver
=
1002 (struct mousevsc_drv_obj
*)Driver
;
1005 Driver
->name
= gDriverName
;
1006 memcpy(&Driver
->dev_type
, &gMousevscDeviceType
,
1007 sizeof(struct hv_guid
));
1009 /* Setup the dispatch table */
1010 inputDriver
->Base
.dev_add
= MousevscOnDeviceAdd
;
1011 inputDriver
->Base
.dev_rm
= MousevscOnDeviceRemove
;
1012 inputDriver
->Base
.cleanup
= MousevscOnCleanup
;
1018 static int __init
mousevsc_init(void)
1020 struct mousevsc_drv_obj
*input_drv_obj
= &g_mousevsc_drv
.drv_obj
;
1021 struct driver_context
*drv_ctx
= &g_mousevsc_drv
.drv_ctx
;
1023 DPRINT_INFO(INPUTVSC_DRV
, "Hyper-V Mouse driver initializing.");
1025 /* Callback to client driver to complete the initialization */
1026 mouse_vsc_initialize(&input_drv_obj
->Base
);
1028 drv_ctx
->driver
.name
= input_drv_obj
->Base
.name
;
1029 memcpy(&drv_ctx
->class_id
, &input_drv_obj
->Base
.dev_type
,
1030 sizeof(struct hv_guid
));
1032 drv_ctx
->probe
= mousevsc_probe
;
1033 drv_ctx
->remove
= mousevsc_remove
;
1035 /* The driver belongs to vmbus */
1036 vmbus_child_driver_register(drv_ctx
);
1041 static void __exit
mousevsc_exit(void)
1043 mousevsc_drv_exit();
1047 * We don't want to automatically load this driver just yet, it's quite
1048 * broken. It's safe if you want to load it yourself manually, but
1049 * don't inflict it on unsuspecting users, that's just mean.
1054 * We use a PCI table to determine if we should autoload this driver This is
1055 * needed by distro tools to determine if the hyperv drivers should be
1056 * installed and/or configured. We don't do anything else with the table, but
1057 * it needs to be present.
1059 const static struct pci_device_id microsoft_hv_pci_table
[] = {
1060 { PCI_DEVICE(0x1414, 0x5353) }, /* VGA compatible controller */
1063 MODULE_DEVICE_TABLE(pci
, microsoft_hv_pci_table
);
1066 MODULE_LICENSE("GPL");
1067 MODULE_VERSION(HV_DRV_VERSION
);
1068 module_init(mousevsc_init
);
1069 module_exit(mousevsc_exit
);