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 (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
;
91 struct synthhid_msg_hdr header
;
92 char data
[1]; /* Enclosed message */
95 union synthhid_version
{
106 struct synthhid_protocol_request
{
107 struct synthhid_msg_hdr header
;
108 union synthhid_version version_requested
;
111 struct synthhid_protocol_response
{
112 struct synthhid_msg_hdr header
;
113 union synthhid_version version_requested
;
114 unsigned char approved
;
117 struct synthhid_device_info
{
118 struct synthhid_msg_hdr header
;
119 struct hv_input_dev_info HidDeviceAttributes
;
120 unsigned char HidDescriptorInformation
[1];
123 struct synthhid_device_info_ack
{
124 struct synthhid_msg_hdr header
;
125 unsigned char Reserved
;
128 struct synthhid_input_report
{
129 struct synthhid_msg_hdr header
;
130 char ReportBuffer
[1];
135 #define INPUTVSC_SEND_RING_BUFFER_SIZE 10*PAGE_SIZE
136 #define INPUTVSC_RECV_RING_BUFFER_SIZE 10*PAGE_SIZE
138 #define NBITS(x) (((x)/BITS_PER_LONG)+1)
140 enum pipe_prot_msg_type
{
141 PipeMessageInvalid
= 0,
147 struct pipe_prt_msg
{
148 enum pipe_prot_msg_type PacketType
;
156 struct mousevsc_prt_msg
{
157 enum pipe_prot_msg_type PacketType
;
160 struct synthhid_protocol_request Request
;
161 struct synthhid_protocol_response Response
;
162 struct synthhid_device_info_ack Ack
;
167 * Represents an mousevsc device
169 struct mousevsc_dev
{
170 struct hv_device
*Device
;
171 /* 0 indicates the device is being destroyed */
173 int NumOutstandingRequests
;
174 unsigned char bInitializeComplete
;
175 struct mousevsc_prt_msg ProtocolReq
;
176 struct mousevsc_prt_msg ProtocolResp
;
177 /* Synchronize the request/response if needed */
178 wait_queue_head_t ProtocolWaitEvent
;
179 wait_queue_head_t DeviceInfoWaitEvent
;
180 int protocol_wait_condition
;
181 int device_wait_condition
;
182 int DeviceInfoStatus
;
184 struct hid_descriptor
*HidDesc
;
185 unsigned char *ReportDesc
;
187 struct hv_input_dev_info DeviceAttr
;
194 static const char *gDriverName
= "mousevsc";
196 /* {CFA8B69E-5B4A-4cc0-B98B-8BA1A1F3F95A} */
197 static const struct hv_guid gMousevscDeviceType
= {
198 .data
= {0x9E, 0xB6, 0xA8, 0xCF, 0x4A, 0x5B, 0xc0, 0x4c,
199 0xB9, 0x8B, 0x8B, 0xA1, 0xA1, 0xF3, 0xF9, 0x5A}
202 static void MousevscOnReceive(struct hv_device
*Device
,
203 struct vmpacket_descriptor
*Packet
);
205 static void deviceinfo_callback(struct hv_device
*dev
, struct hv_input_dev_info
*info
);
206 static void inputreport_callback(struct hv_device
*dev
, void *packet
, u32 len
);
207 static void reportdesc_callback(struct hv_device
*dev
, void *packet
, u32 len
);
209 static struct mousevsc_dev
*AllocInputDevice(struct hv_device
*Device
)
211 struct mousevsc_dev
*inputDevice
;
213 inputDevice
= kzalloc(sizeof(struct mousevsc_dev
), GFP_KERNEL
);
219 * Set to 2 to allow both inbound and outbound traffics
220 * (ie GetInputDevice() and MustGetInputDevice()) to proceed.
222 atomic_cmpxchg(&inputDevice
->RefCount
, 0, 2);
224 inputDevice
->Device
= Device
;
225 Device
->ext
= inputDevice
;
230 static void FreeInputDevice(struct mousevsc_dev
*Device
)
232 WARN_ON(atomic_read(&Device
->RefCount
) == 0);
237 * Get the inputdevice object if exists and its refcount > 1
239 static struct mousevsc_dev
*GetInputDevice(struct hv_device
*Device
)
241 struct mousevsc_dev
*inputDevice
;
243 inputDevice
= (struct mousevsc_dev
*)Device
->ext
;
247 * This sure isn't a valid thing to print for debugging, no matter
248 * what the intention is...
250 * printk(KERN_ERR "-------------------------> REFCOUNT = %d",
251 * inputDevice->RefCount);
254 if (inputDevice
&& atomic_read(&inputDevice
->RefCount
) > 1)
255 atomic_inc(&inputDevice
->RefCount
);
263 * Get the inputdevice object iff exists and its refcount > 0
265 static struct mousevsc_dev
*MustGetInputDevice(struct hv_device
*Device
)
267 struct mousevsc_dev
*inputDevice
;
269 inputDevice
= (struct mousevsc_dev
*)Device
->ext
;
271 if (inputDevice
&& atomic_read(&inputDevice
->RefCount
))
272 atomic_inc(&inputDevice
->RefCount
);
279 static void PutInputDevice(struct hv_device
*Device
)
281 struct mousevsc_dev
*inputDevice
;
283 inputDevice
= (struct mousevsc_dev
*)Device
->ext
;
285 atomic_dec(&inputDevice
->RefCount
);
289 * Drop ref count to 1 to effectively disable GetInputDevice()
291 static struct mousevsc_dev
*ReleaseInputDevice(struct hv_device
*Device
)
293 struct mousevsc_dev
*inputDevice
;
295 inputDevice
= (struct mousevsc_dev
*)Device
->ext
;
297 /* Busy wait until the ref drop to 2, then set it to 1 */
298 while (atomic_cmpxchg(&inputDevice
->RefCount
, 2, 1) != 2)
305 * Drop ref count to 0. No one can use InputDevice object.
307 static struct mousevsc_dev
*FinalReleaseInputDevice(struct hv_device
*Device
)
309 struct mousevsc_dev
*inputDevice
;
311 inputDevice
= (struct mousevsc_dev
*)Device
->ext
;
313 /* Busy wait until the ref drop to 1, then set it to 0 */
314 while (atomic_cmpxchg(&inputDevice
->RefCount
, 1, 0) != 1)
321 static void MousevscOnSendCompletion(struct hv_device
*Device
, struct vmpacket_descriptor
*Packet
)
323 struct mousevsc_dev
*inputDevice
;
326 inputDevice
= MustGetInputDevice(Device
);
328 pr_err("unable to get input device...device being destroyed?");
332 request
= (void *)(unsigned long)Packet
->trans_id
;
334 if (request
== &inputDevice
->ProtocolReq
) {
336 /* Shouldn't we be doing something here? */
339 PutInputDevice(Device
);
342 static void MousevscOnReceiveDeviceInfo(struct mousevsc_dev
*InputDevice
, struct synthhid_device_info
*DeviceInfo
)
345 struct hid_descriptor
*desc
;
346 struct mousevsc_prt_msg ack
;
348 /* Assume success for now */
349 InputDevice
->DeviceInfoStatus
= 0;
351 /* Save the device attr */
352 memcpy(&InputDevice
->DeviceAttr
, &DeviceInfo
->HidDeviceAttributes
, sizeof(struct hv_input_dev_info
));
354 /* Save the hid desc */
355 desc
= (struct hid_descriptor
*)DeviceInfo
->HidDescriptorInformation
;
356 WARN_ON(desc
->bLength
> 0);
358 InputDevice
->HidDesc
= kzalloc(desc
->bLength
, GFP_KERNEL
);
360 if (!InputDevice
->HidDesc
) {
361 pr_err("unable to allocate hid descriptor - size %d", desc
->bLength
);
365 memcpy(InputDevice
->HidDesc
, desc
, desc
->bLength
);
367 /* Save the report desc */
368 InputDevice
->ReportDescSize
= desc
->desc
[0].wDescriptorLength
;
369 InputDevice
->ReportDesc
= kzalloc(InputDevice
->ReportDescSize
,
372 if (!InputDevice
->ReportDesc
) {
373 pr_err("unable to allocate report descriptor - size %d",
374 InputDevice
->ReportDescSize
);
378 memcpy(InputDevice
->ReportDesc
,
379 ((unsigned char *)desc
) + desc
->bLength
,
380 desc
->desc
[0].wDescriptorLength
);
383 memset(&ack
, sizeof(struct mousevsc_prt_msg
), 0);
385 ack
.PacketType
= PipeMessageData
;
386 ack
.DataSize
= sizeof(struct synthhid_device_info_ack
);
388 ack
.u
.Ack
.header
.type
= SynthHidInitialDeviceInfoAck
;
389 ack
.u
.Ack
.header
.size
= 1;
390 ack
.u
.Ack
.Reserved
= 0;
392 ret
= vmbus_sendpacket(InputDevice
->Device
->channel
,
394 sizeof(struct pipe_prt_msg
) - sizeof(unsigned char) +
395 sizeof(struct synthhid_device_info_ack
),
398 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED
);
400 pr_err("unable to send synthhid device info ack - ret %d",
405 InputDevice
->device_wait_condition
= 1;
406 wake_up(&InputDevice
->DeviceInfoWaitEvent
);
411 if (InputDevice
->HidDesc
) {
412 kfree(InputDevice
->HidDesc
);
413 InputDevice
->HidDesc
= NULL
;
416 if (InputDevice
->ReportDesc
) {
417 kfree(InputDevice
->ReportDesc
);
418 InputDevice
->ReportDesc
= NULL
;
421 InputDevice
->DeviceInfoStatus
= -1;
422 InputDevice
->device_wait_condition
= 1;
423 wake_up(&InputDevice
->DeviceInfoWaitEvent
);
426 static void MousevscOnReceiveInputReport(struct mousevsc_dev
*InputDevice
, struct synthhid_input_report
*InputReport
)
428 struct mousevsc_drv_obj
*inputDriver
;
430 if (!InputDevice
->bInitializeComplete
) {
431 pr_info("Initialization incomplete...ignoring InputReport msg");
435 inputDriver
= (struct mousevsc_drv_obj
*)InputDevice
->Device
->drv
;
437 inputreport_callback(InputDevice
->Device
,
438 InputReport
->ReportBuffer
,
439 InputReport
->header
.size
);
442 static void MousevscOnReceive(struct hv_device
*Device
, struct vmpacket_descriptor
*Packet
)
444 struct pipe_prt_msg
*pipeMsg
;
445 struct synthhid_msg
*hidMsg
;
446 struct mousevsc_dev
*inputDevice
;
448 inputDevice
= MustGetInputDevice(Device
);
450 pr_err("unable to get input device...device being destroyed?");
454 pipeMsg
= (struct pipe_prt_msg
*)((unsigned long)Packet
+ (Packet
->offset8
<< 3));
456 if (pipeMsg
->PacketType
!= PipeMessageData
) {
457 pr_err("unknown pipe msg type - type %d len %d",
458 pipeMsg
->PacketType
, pipeMsg
->DataSize
);
459 PutInputDevice(Device
);
463 hidMsg
= (struct synthhid_msg
*)&pipeMsg
->Data
[0];
465 switch (hidMsg
->header
.type
) {
466 case SynthHidProtocolResponse
:
467 memcpy(&inputDevice
->ProtocolResp
, pipeMsg
, pipeMsg
->DataSize
+sizeof(struct pipe_prt_msg
) - sizeof(unsigned char));
468 inputDevice
->protocol_wait_condition
= 1;
469 wake_up(&inputDevice
->ProtocolWaitEvent
);
472 case SynthHidInitialDeviceInfo
:
473 WARN_ON(pipeMsg
->DataSize
>= sizeof(struct hv_input_dev_info
));
476 * Parse out the device info into device attr,
477 * hid desc and report desc
479 MousevscOnReceiveDeviceInfo(inputDevice
,
480 (struct synthhid_device_info
*)&pipeMsg
->Data
[0]);
482 case SynthHidInputReport
:
483 MousevscOnReceiveInputReport(inputDevice
,
484 (struct synthhid_input_report
*)&pipeMsg
->Data
[0]);
488 pr_err("unsupported hid msg type - type %d len %d",
489 hidMsg
->header
.type
, hidMsg
->header
.size
);
493 PutInputDevice(Device
);
496 static void MousevscOnChannelCallback(void *Context
)
498 const int packetSize
= 0x100;
500 struct hv_device
*device
= (struct hv_device
*)Context
;
501 struct mousevsc_dev
*inputDevice
;
505 unsigned char packet
[packetSize
];
506 struct vmpacket_descriptor
*desc
;
507 unsigned char *buffer
= packet
;
508 int bufferlen
= packetSize
;
510 inputDevice
= MustGetInputDevice(device
);
513 pr_err("unable to get input device...device being destroyed?");
518 ret
= vmbus_recvpacket_raw(device
->channel
, buffer
, bufferlen
, &bytesRecvd
, &requestId
);
521 if (bytesRecvd
> 0) {
522 desc
= (struct vmpacket_descriptor
*)buffer
;
524 switch (desc
->type
) {
526 MousevscOnSendCompletion(device
,
530 case VM_PKT_DATA_INBAND
:
531 MousevscOnReceive(device
, desc
);
535 pr_err("unhandled packet type %d, tid %llx len %d\n",
543 if (bufferlen
> packetSize
) {
547 bufferlen
= packetSize
;
551 * pr_debug("nothing else to read...");
554 if (bufferlen
> packetSize
) {
558 bufferlen
= packetSize
;
562 } else if (ret
== -2) {
563 /* Handle large packet */
564 bufferlen
= bytesRecvd
;
565 buffer
= kzalloc(bytesRecvd
, GFP_KERNEL
);
567 if (buffer
== NULL
) {
569 bufferlen
= packetSize
;
571 /* Try again next time around */
572 pr_err("unable to allocate buffer of size %d!",
579 PutInputDevice(device
);
584 static int MousevscConnectToVsp(struct hv_device
*Device
)
587 struct mousevsc_dev
*inputDevice
;
588 struct mousevsc_prt_msg
*request
;
589 struct mousevsc_prt_msg
*response
;
591 inputDevice
= GetInputDevice(Device
);
594 pr_err("unable to get input device...device being destroyed?");
598 init_waitqueue_head(&inputDevice
->ProtocolWaitEvent
);
599 init_waitqueue_head(&inputDevice
->DeviceInfoWaitEvent
);
601 request
= &inputDevice
->ProtocolReq
;
604 * Now, initiate the vsc/vsp initialization protocol on the open channel
606 memset(request
, sizeof(struct mousevsc_prt_msg
), 0);
608 request
->PacketType
= PipeMessageData
;
609 request
->DataSize
= sizeof(struct synthhid_protocol_request
);
611 request
->u
.Request
.header
.type
= SynthHidProtocolRequest
;
612 request
->u
.Request
.header
.size
= sizeof(unsigned long);
613 request
->u
.Request
.version_requested
.version
= SYNTHHID_INPUT_VERSION
;
615 pr_info("synthhid protocol request...");
617 ret
= vmbus_sendpacket(Device
->channel
, request
,
618 sizeof(struct pipe_prt_msg
) -
619 sizeof(unsigned char) +
620 sizeof(struct synthhid_protocol_request
),
621 (unsigned long)request
,
623 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED
);
625 pr_err("unable to send synthhid protocol request.");
629 inputDevice
->protocol_wait_condition
= 0;
630 wait_event_timeout(inputDevice
->ProtocolWaitEvent
, inputDevice
->protocol_wait_condition
, msecs_to_jiffies(1000));
631 if (inputDevice
->protocol_wait_condition
== 0) {
636 response
= &inputDevice
->ProtocolResp
;
638 if (!response
->u
.Response
.approved
) {
639 pr_err("synthhid protocol request failed (version %d)",
640 SYNTHHID_INPUT_VERSION
);
645 inputDevice
->device_wait_condition
= 0;
646 wait_event_timeout(inputDevice
->DeviceInfoWaitEvent
, inputDevice
->device_wait_condition
, msecs_to_jiffies(1000));
647 if (inputDevice
->device_wait_condition
== 0) {
653 * We should have gotten the device attr, hid desc and report
656 if (!inputDevice
->DeviceInfoStatus
)
657 pr_info("**** input channel up and running!! ****");
662 PutInputDevice(Device
);
667 static int MousevscOnDeviceAdd(struct hv_device
*Device
, void *AdditionalInfo
)
670 struct mousevsc_dev
*inputDevice
;
671 struct mousevsc_drv_obj
*inputDriver
;
672 struct hv_input_dev_info deviceInfo
;
674 inputDevice
= AllocInputDevice(Device
);
681 inputDevice
->bInitializeComplete
= false;
683 /* Open the channel */
684 ret
= vmbus_open(Device
->channel
,
685 INPUTVSC_SEND_RING_BUFFER_SIZE
,
686 INPUTVSC_RECV_RING_BUFFER_SIZE
,
689 MousevscOnChannelCallback
,
694 pr_err("unable to open channel: %d", ret
);
698 pr_info("InputVsc channel open: %d", ret
);
700 ret
= MousevscConnectToVsp(Device
);
703 pr_err("unable to connect channel: %d", ret
);
705 vmbus_close(Device
->channel
);
709 inputDriver
= (struct mousevsc_drv_obj
*)inputDevice
->Device
->drv
;
711 deviceInfo
.vendor
= inputDevice
->DeviceAttr
.vendor
;
712 deviceInfo
.product
= inputDevice
->DeviceAttr
.product
;
713 deviceInfo
.version
= inputDevice
->DeviceAttr
.version
;
714 strcpy(deviceInfo
.name
, "Microsoft Vmbus HID-compliant Mouse");
716 /* Send the device info back up */
717 deviceinfo_callback(Device
, &deviceInfo
);
719 /* Send the report desc back up */
720 /* workaround SA-167 */
721 if (inputDevice
->ReportDesc
[14] == 0x25)
722 inputDevice
->ReportDesc
[14] = 0x29;
724 reportdesc_callback(Device
, inputDevice
->ReportDesc
,
725 inputDevice
->ReportDescSize
);
727 inputDevice
->bInitializeComplete
= true;
733 static int MousevscOnDeviceRemove(struct hv_device
*Device
)
735 struct mousevsc_dev
*inputDevice
;
738 pr_info("disabling input device (%p)...",
741 inputDevice
= ReleaseInputDevice(Device
);
745 * At this point, all outbound traffic should be disable. We only
746 * allow inbound traffic (responses) to proceed
748 * so that outstanding requests can be completed.
750 while (inputDevice
->NumOutstandingRequests
) {
751 pr_info("waiting for %d requests to complete...", inputDevice
->NumOutstandingRequests
);
756 pr_info("removing input device (%p)...", Device
->ext
);
758 inputDevice
= FinalReleaseInputDevice(Device
);
760 pr_info("input device (%p) safe to remove", inputDevice
);
762 /* Close the channel */
763 vmbus_close(Device
->channel
);
765 FreeInputDevice(inputDevice
);
770 static void MousevscOnCleanup(struct hv_driver
*drv
)
777 struct input_device_context
{
778 struct vm_device
*device_ctx
;
779 struct hid_device
*hid_device
;
780 struct hv_input_dev_info device_info
;
784 struct mousevsc_driver_context
{
785 struct driver_context drv_ctx
;
786 struct mousevsc_drv_obj drv_obj
;
789 static struct mousevsc_driver_context g_mousevsc_drv
;
791 static void deviceinfo_callback(struct hv_device
*dev
, struct hv_input_dev_info
*info
)
793 struct vm_device
*device_ctx
= to_vm_device(dev
);
794 struct input_device_context
*input_device_ctx
=
795 dev_get_drvdata(&device_ctx
->device
);
797 memcpy(&input_device_ctx
->device_info
, info
,
798 sizeof(struct hv_input_dev_info
));
800 DPRINT_INFO(INPUTVSC_DRV
, "%s", __func__
);
803 static void inputreport_callback(struct hv_device
*dev
, void *packet
, u32 len
)
807 struct vm_device
*device_ctx
= to_vm_device(dev
);
808 struct input_device_context
*input_dev_ctx
=
809 dev_get_drvdata(&device_ctx
->device
);
811 ret
= hid_input_report(input_dev_ctx
->hid_device
,
812 HID_INPUT_REPORT
, packet
, len
, 1);
814 DPRINT_DBG(INPUTVSC_DRV
, "hid_input_report (ret %d)", ret
);
817 static int mousevsc_hid_open(struct hid_device
*hid
)
822 static void mousevsc_hid_close(struct hid_device
*hid
)
826 static int mousevsc_probe(struct device
*device
)
830 struct driver_context
*driver_ctx
=
831 driver_to_driver_context(device
->driver
);
832 struct mousevsc_driver_context
*mousevsc_drv_ctx
=
833 (struct mousevsc_driver_context
*)driver_ctx
;
834 struct mousevsc_drv_obj
*mousevsc_drv_obj
= &mousevsc_drv_ctx
->drv_obj
;
836 struct vm_device
*device_ctx
= device_to_vm_device(device
);
837 struct hv_device
*device_obj
= &device_ctx
->device_obj
;
838 struct input_device_context
*input_dev_ctx
;
840 input_dev_ctx
= kmalloc(sizeof(struct input_device_context
),
843 dev_set_drvdata(device
, input_dev_ctx
);
845 /* Call to the vsc driver to add the device */
846 ret
= mousevsc_drv_obj
->Base
.dev_add(device_obj
, NULL
);
849 DPRINT_ERR(INPUTVSC_DRV
, "unable to add input vsc device");
857 static int mousevsc_remove(struct device
*device
)
861 struct driver_context
*driver_ctx
=
862 driver_to_driver_context(device
->driver
);
863 struct mousevsc_driver_context
*mousevsc_drv_ctx
=
864 (struct mousevsc_driver_context
*)driver_ctx
;
865 struct mousevsc_drv_obj
*mousevsc_drv_obj
= &mousevsc_drv_ctx
->drv_obj
;
867 struct vm_device
*device_ctx
= device_to_vm_device(device
);
868 struct hv_device
*device_obj
= &device_ctx
->device_obj
;
869 struct input_device_context
*input_dev_ctx
;
871 input_dev_ctx
= kmalloc(sizeof(struct input_device_context
),
874 dev_set_drvdata(device
, input_dev_ctx
);
876 if (input_dev_ctx
->connected
) {
877 hidinput_disconnect(input_dev_ctx
->hid_device
);
878 input_dev_ctx
->connected
= 0;
881 if (!mousevsc_drv_obj
->Base
.dev_rm
)
885 * Call to the vsc driver to let it know that the device
888 ret
= mousevsc_drv_obj
->Base
.dev_rm(device_obj
);
891 DPRINT_ERR(INPUTVSC_DRV
,
892 "unable to remove vsc device (ret %d)", ret
);
895 kfree(input_dev_ctx
);
900 static void reportdesc_callback(struct hv_device
*dev
, void *packet
, u32 len
)
902 struct vm_device
*device_ctx
= to_vm_device(dev
);
903 struct input_device_context
*input_device_ctx
=
904 dev_get_drvdata(&device_ctx
->device
);
905 struct hid_device
*hid_dev
;
907 /* hid_debug = -1; */
908 hid_dev
= kmalloc(sizeof(struct hid_device
), GFP_KERNEL
);
910 if (hid_parse_report(hid_dev
, packet
, len
)) {
911 DPRINT_INFO(INPUTVSC_DRV
, "Unable to call hd_parse_report");
916 DPRINT_INFO(INPUTVSC_DRV
, "hid_device created");
918 hid_dev
->ll_driver
->open
= mousevsc_hid_open
;
919 hid_dev
->ll_driver
->close
= mousevsc_hid_close
;
921 hid_dev
->bus
= BUS_VIRTUAL
;
922 hid_dev
->vendor
= input_device_ctx
->device_info
.vendor
;
923 hid_dev
->product
= input_device_ctx
->device_info
.product
;
924 hid_dev
->version
= input_device_ctx
->device_info
.version
;
925 hid_dev
->dev
= device_ctx
->device
;
927 sprintf(hid_dev
->name
, "%s",
928 input_device_ctx
->device_info
.name
);
931 * HJ Do we want to call it with a 0
933 if (!hidinput_connect(hid_dev
, 0)) {
934 hid_dev
->claimed
|= HID_CLAIMED_INPUT
;
936 input_device_ctx
->connected
= 1;
938 DPRINT_INFO(INPUTVSC_DRV
,
939 "HID device claimed by input\n");
942 if (!hid_dev
->claimed
) {
943 DPRINT_ERR(INPUTVSC_DRV
,
944 "HID device not claimed by "
945 "input or hiddev\n");
948 input_device_ctx
->hid_device
= hid_dev
;
954 static int mousevsc_drv_exit_cb(struct device
*dev
, void *data
)
956 struct device
**curr
= (struct device
**)data
;
962 static void mousevsc_drv_exit(void)
964 struct mousevsc_drv_obj
*mousevsc_drv_obj
= &g_mousevsc_drv
.drv_obj
;
965 struct driver_context
*drv_ctx
= &g_mousevsc_drv
.drv_ctx
;
968 struct device
*current_dev
= NULL
;
974 ret
= driver_for_each_device(&drv_ctx
->driver
, NULL
,
975 (void *)¤t_dev
,
976 mousevsc_drv_exit_cb
);
978 printk(KERN_ERR
"Can't find mouse device!\n");
980 if (current_dev
== NULL
)
983 /* Initiate removal from the top-down */
984 device_unregister(current_dev
);
987 if (mousevsc_drv_obj
->Base
.cleanup
)
988 mousevsc_drv_obj
->Base
.cleanup(&mousevsc_drv_obj
->Base
);
990 vmbus_child_driver_unregister(drv_ctx
);
995 static int mouse_vsc_initialize(struct hv_driver
*Driver
)
997 struct mousevsc_drv_obj
*inputDriver
=
998 (struct mousevsc_drv_obj
*)Driver
;
1001 Driver
->name
= gDriverName
;
1002 memcpy(&Driver
->dev_type
, &gMousevscDeviceType
,
1003 sizeof(struct hv_guid
));
1005 /* Setup the dispatch table */
1006 inputDriver
->Base
.dev_add
= MousevscOnDeviceAdd
;
1007 inputDriver
->Base
.dev_rm
= MousevscOnDeviceRemove
;
1008 inputDriver
->Base
.cleanup
= MousevscOnCleanup
;
1014 static int __init
mousevsc_init(void)
1016 struct mousevsc_drv_obj
*input_drv_obj
= &g_mousevsc_drv
.drv_obj
;
1017 struct driver_context
*drv_ctx
= &g_mousevsc_drv
.drv_ctx
;
1019 DPRINT_INFO(INPUTVSC_DRV
, "Hyper-V Mouse driver initializing.");
1021 /* Callback to client driver to complete the initialization */
1022 mouse_vsc_initialize(&input_drv_obj
->Base
);
1024 drv_ctx
->driver
.name
= input_drv_obj
->Base
.name
;
1025 memcpy(&drv_ctx
->class_id
, &input_drv_obj
->Base
.dev_type
,
1026 sizeof(struct hv_guid
));
1028 drv_ctx
->probe
= mousevsc_probe
;
1029 drv_ctx
->remove
= mousevsc_remove
;
1031 /* The driver belongs to vmbus */
1032 vmbus_child_driver_register(drv_ctx
);
1037 static void __exit
mousevsc_exit(void)
1039 mousevsc_drv_exit();
1043 * We don't want to automatically load this driver just yet, it's quite
1044 * broken. It's safe if you want to load it yourself manually, but
1045 * don't inflict it on unsuspecting users, that's just mean.
1050 * We use a PCI table to determine if we should autoload this driver This is
1051 * needed by distro tools to determine if the hyperv drivers should be
1052 * installed and/or configured. We don't do anything else with the table, but
1053 * it needs to be present.
1055 const static struct pci_device_id microsoft_hv_pci_table
[] = {
1056 { PCI_DEVICE(0x1414, 0x5353) }, /* VGA compatible controller */
1059 MODULE_DEVICE_TABLE(pci
, microsoft_hv_pci_table
);
1062 MODULE_LICENSE("GPL");
1063 MODULE_VERSION(HV_DRV_VERSION
);
1064 module_init(mousevsc_init
);
1065 module_exit(mousevsc_exit
);