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 input_dev_info {
40 unsigned short VendorID;
41 unsigned short ProductID;
42 unsigned short VersionNumber;
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 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 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}
208 static int MousevscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo);
210 static int MousevscOnDeviceRemove(struct hv_device *Device);
212 static void MousevscOnCleanup(struct hv_driver *Device);
214 static void MousevscOnChannelCallback(void *Context);
216 static int MousevscConnectToVsp(struct hv_device *Device);
218 static void MousevscOnReceive(struct hv_device *Device,
219 struct vmpacket_descriptor *Packet);
221 static void deviceinfo_callback(struct hv_device *dev, struct input_dev_info *info);
222 static void inputreport_callback(struct hv_device *dev, void *packet, u32 len);
223 static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len);
225 static struct mousevsc_dev *AllocInputDevice(struct hv_device *Device)
227 struct mousevsc_dev *inputDevice;
229 inputDevice = kzalloc(sizeof(struct mousevsc_dev), GFP_KERNEL);
235 * Set to 2 to allow both inbound and outbound traffics
236 * (ie GetInputDevice() and MustGetInputDevice()) to proceed.
238 atomic_cmpxchg(&inputDevice->RefCount, 0, 2);
240 inputDevice->Device = Device;
241 Device->ext = inputDevice;
246 static void FreeInputDevice(struct mousevsc_dev *Device)
248 WARN_ON(atomic_read(&Device->RefCount) == 0);
253 * Get the inputdevice object if exists and its refcount > 1
255 static struct mousevsc_dev *GetInputDevice(struct hv_device *Device)
257 struct mousevsc_dev *inputDevice;
259 inputDevice = (struct mousevsc_dev *)Device->ext;
263 * This sure isn't a valid thing to print for debugging, no matter
264 * what the intention is...
266 * printk(KERN_ERR "-------------------------> REFCOUNT = %d",
267 * inputDevice->RefCount);
270 if (inputDevice && atomic_read(&inputDevice->RefCount) > 1)
271 atomic_inc(&inputDevice->RefCount);
279 * Get the inputdevice object iff exists and its refcount > 0
281 static struct mousevsc_dev *MustGetInputDevice(struct hv_device *Device)
283 struct mousevsc_dev *inputDevice;
285 inputDevice = (struct mousevsc_dev *)Device->ext;
287 if (inputDevice && atomic_read(&inputDevice->RefCount))
288 atomic_inc(&inputDevice->RefCount);
295 static void PutInputDevice(struct hv_device *Device)
297 struct mousevsc_dev *inputDevice;
299 inputDevice = (struct mousevsc_dev *)Device->ext;
301 atomic_dec(&inputDevice->RefCount);
305 * Drop ref count to 1 to effectively disable GetInputDevice()
307 static struct mousevsc_dev *ReleaseInputDevice(struct hv_device *Device)
309 struct mousevsc_dev *inputDevice;
311 inputDevice = (struct mousevsc_dev *)Device->ext;
313 /* Busy wait until the ref drop to 2, then set it to 1 */
314 while (atomic_cmpxchg(&inputDevice->RefCount, 2, 1) != 2)
321 * Drop ref count to 0. No one can use InputDevice object.
323 static struct mousevsc_dev *FinalReleaseInputDevice(struct hv_device *Device)
325 struct mousevsc_dev *inputDevice;
327 inputDevice = (struct mousevsc_dev *)Device->ext;
329 /* Busy wait until the ref drop to 1, then set it to 0 */
330 while (atomic_cmpxchg(&inputDevice->RefCount, 1, 0) != 1)
337 static int mouse_vsc_initialize(struct hv_driver *Driver)
339 struct mousevsc_drv_obj *inputDriver =
340 (struct mousevsc_drv_obj *)Driver;
343 Driver->name = gDriverName;
344 memcpy(&Driver->dev_type, &gMousevscDeviceType,
345 sizeof(struct hv_guid));
347 /* Setup the dispatch table */
348 inputDriver->Base.dev_add = MousevscOnDeviceAdd;
349 inputDriver->Base.dev_rm = MousevscOnDeviceRemove;
350 inputDriver->Base.cleanup = MousevscOnCleanup;
358 * MousevscOnDeviceAdd()
361 * Callback when the device belonging to this driver is added
365 MousevscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo)
368 struct mousevsc_dev *inputDevice;
369 struct mousevsc_drv_obj *inputDriver;
370 struct input_dev_info deviceInfo;
372 inputDevice = AllocInputDevice(Device);
379 inputDevice->bInitializeComplete = false;
381 /* Open the channel */
382 ret = vmbus_open(Device->channel,
383 INPUTVSC_SEND_RING_BUFFER_SIZE,
384 INPUTVSC_RECV_RING_BUFFER_SIZE,
387 MousevscOnChannelCallback,
392 pr_err("unable to open channel: %d", ret);
396 pr_info("InputVsc channel open: %d", ret);
398 ret = MousevscConnectToVsp(Device);
401 pr_err("unable to connect channel: %d", ret);
403 vmbus_close(Device->channel);
407 inputDriver = (struct mousevsc_drv_obj *)inputDevice->Device->drv;
409 deviceInfo.VendorID = inputDevice->DeviceAttr.VendorID;
410 deviceInfo.ProductID = inputDevice->DeviceAttr.ProductID;
411 deviceInfo.VersionNumber = inputDevice->DeviceAttr.VersionNumber;
412 strcpy(deviceInfo.Name, "Microsoft Vmbus HID-compliant Mouse");
414 /* Send the device info back up */
415 deviceinfo_callback(Device, &deviceInfo);
417 /* Send the report desc back up */
418 /* workaround SA-167 */
419 if (inputDevice->ReportDesc[14] == 0x25)
420 inputDevice->ReportDesc[14] = 0x29;
422 reportdesc_callback(Device, inputDevice->ReportDesc,
423 inputDevice->ReportDescSize);
425 inputDevice->bInitializeComplete = true;
432 MousevscConnectToVsp(struct hv_device *Device)
435 struct mousevsc_dev *inputDevice;
436 struct mousevsc_prt_msg *request;
437 struct mousevsc_prt_msg *response;
439 inputDevice = GetInputDevice(Device);
442 pr_err("unable to get input device...device being destroyed?");
446 init_waitqueue_head(&inputDevice->ProtocolWaitEvent);
447 init_waitqueue_head(&inputDevice->DeviceInfoWaitEvent);
449 request = &inputDevice->ProtocolReq;
452 * Now, initiate the vsc/vsp initialization protocol on the open channel
454 memset(request, sizeof(struct mousevsc_prt_msg), 0);
456 request->PacketType = PipeMessageData;
457 request->DataSize = sizeof(struct synthhid_protocol_request);
459 request->u.Request.Header.Type = SynthHidProtocolRequest;
460 request->u.Request.Header.Size = sizeof(unsigned long);
461 request->u.Request.VersionRequested.AsDWord =
462 SYNTHHID_INPUT_VERSION_DWORD;
464 pr_info("synthhid protocol request...");
466 ret = vmbus_sendpacket(Device->channel, request,
467 sizeof(struct pipe_prt_msg) -
468 sizeof(unsigned char) +
469 sizeof(struct synthhid_protocol_request),
470 (unsigned long)request,
472 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
474 pr_err("unable to send synthhid protocol request.");
478 inputDevice->protocol_wait_condition = 0;
479 wait_event_timeout(inputDevice->ProtocolWaitEvent, inputDevice->protocol_wait_condition, msecs_to_jiffies(1000));
480 if (inputDevice->protocol_wait_condition == 0) {
485 response = &inputDevice->ProtocolResp;
487 if (!response->u.Response.Approved) {
488 pr_err("synthhid protocol request failed (version %d)",
489 SYNTHHID_INPUT_VERSION_DWORD);
494 inputDevice->device_wait_condition = 0;
495 wait_event_timeout(inputDevice->DeviceInfoWaitEvent, inputDevice->device_wait_condition, msecs_to_jiffies(1000));
496 if (inputDevice->device_wait_condition == 0) {
502 * We should have gotten the device attr, hid desc and report
505 if (!inputDevice->DeviceInfoStatus)
506 pr_info("**** input channel up and running!! ****");
511 PutInputDevice(Device);
520 * MousevscOnDeviceRemove()
523 * Callback when the our device is being removed
527 MousevscOnDeviceRemove(struct hv_device *Device)
529 struct mousevsc_dev *inputDevice;
532 pr_info("disabling input device (%p)...",
535 inputDevice = ReleaseInputDevice(Device);
539 * At this point, all outbound traffic should be disable. We only
540 * allow inbound traffic (responses) to proceed
542 * so that outstanding requests can be completed.
544 while (inputDevice->NumOutstandingRequests) {
545 pr_info("waiting for %d requests to complete...", inputDevice->NumOutstandingRequests);
550 pr_info("removing input device (%p)...", Device->ext);
552 inputDevice = FinalReleaseInputDevice(Device);
554 pr_info("input device (%p) safe to remove", inputDevice);
556 /* Close the channel */
557 vmbus_close(Device->channel);
559 FreeInputDevice(inputDevice);
568 * MousevscOnCleanup()
571 * Perform any cleanup when the driver is removed
573 static void MousevscOnCleanup(struct hv_driver *drv)
579 MousevscOnSendCompletion(struct hv_device *Device,
580 struct vmpacket_descriptor *Packet)
582 struct mousevsc_dev *inputDevice;
585 inputDevice = MustGetInputDevice(Device);
587 pr_err("unable to get input device...device being destroyed?");
591 request = (void *)(unsigned long *)Packet->trans_id;
593 if (request == &inputDevice->ProtocolReq) {
595 /* Shouldn't we be doing something here? */
598 PutInputDevice(Device);
602 MousevscOnReceiveDeviceInfo(
603 struct mousevsc_dev *InputDevice,
604 struct synthhid_device_info *DeviceInfo)
607 struct hid_descriptor *desc;
608 struct mousevsc_prt_msg ack;
610 /* Assume success for now */
611 InputDevice->DeviceInfoStatus = 0;
613 /* Save the device attr */
614 memcpy(&InputDevice->DeviceAttr, &DeviceInfo->HidDeviceAttributes, sizeof(struct input_dev_info));
616 /* Save the hid desc */
617 desc = (struct hid_descriptor *)DeviceInfo->HidDescriptorInformation;
618 WARN_ON(desc->bLength > 0);
620 InputDevice->HidDesc = kzalloc(desc->bLength, GFP_KERNEL);
622 if (!InputDevice->HidDesc) {
623 pr_err("unable to allocate hid descriptor - size %d", desc->bLength);
627 memcpy(InputDevice->HidDesc, desc, desc->bLength);
629 /* Save the report desc */
630 InputDevice->ReportDescSize = desc->desc[0].wDescriptorLength;
631 InputDevice->ReportDesc = kzalloc(InputDevice->ReportDescSize,
634 if (!InputDevice->ReportDesc) {
635 pr_err("unable to allocate report descriptor - size %d",
636 InputDevice->ReportDescSize);
640 memcpy(InputDevice->ReportDesc,
641 ((unsigned char *)desc) + desc->bLength,
642 desc->desc[0].wDescriptorLength);
645 memset(&ack, sizeof(struct mousevsc_prt_msg), 0);
647 ack.PacketType = PipeMessageData;
648 ack.DataSize = sizeof(struct synthhid_device_info_ack);
650 ack.u.Ack.Header.Type = SynthHidInitialDeviceInfoAck;
651 ack.u.Ack.Header.Size = 1;
652 ack.u.Ack.Reserved = 0;
654 ret = vmbus_sendpacket(InputDevice->Device->channel,
656 sizeof(struct pipe_prt_msg) - sizeof(unsigned char) +
657 sizeof(struct synthhid_device_info_ack),
660 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
662 pr_err("unable to send synthhid device info ack - ret %d",
667 InputDevice->device_wait_condition = 1;
668 wake_up(&InputDevice->DeviceInfoWaitEvent);
673 if (InputDevice->HidDesc) {
674 kfree(InputDevice->HidDesc);
675 InputDevice->HidDesc = NULL;
678 if (InputDevice->ReportDesc) {
679 kfree(InputDevice->ReportDesc);
680 InputDevice->ReportDesc = NULL;
683 InputDevice->DeviceInfoStatus = -1;
684 InputDevice->device_wait_condition = 1;
685 wake_up(&InputDevice->DeviceInfoWaitEvent);
690 MousevscOnReceiveInputReport(
691 struct mousevsc_dev *InputDevice,
692 struct synthhid_input_report *InputReport)
694 struct mousevsc_drv_obj *inputDriver;
696 if (!InputDevice->bInitializeComplete) {
697 pr_info("Initialization incomplete...ignoring InputReport msg");
701 inputDriver = (struct mousevsc_drv_obj *)InputDevice->Device->drv;
703 inputreport_callback(InputDevice->Device,
704 InputReport->ReportBuffer,
705 InputReport->Header.Size);
709 MousevscOnReceive(struct hv_device *Device, struct vmpacket_descriptor *Packet)
711 struct pipe_prt_msg *pipeMsg;
712 struct synthhid_msg *hidMsg;
713 struct mousevsc_dev *inputDevice;
715 inputDevice = MustGetInputDevice(Device);
717 pr_err("unable to get input device...device being destroyed?");
721 pipeMsg = (struct pipe_prt_msg *)((unsigned long)Packet + (Packet->offset8 << 3));
723 if (pipeMsg->PacketType != PipeMessageData) {
724 pr_err("unknown pipe msg type - type %d len %d",
725 pipeMsg->PacketType, pipeMsg->DataSize);
726 PutInputDevice(Device);
730 hidMsg = (struct synthhid_msg *)&pipeMsg->Data[0];
732 switch (hidMsg->Header.Type) {
733 case SynthHidProtocolResponse:
734 memcpy(&inputDevice->ProtocolResp, pipeMsg, pipeMsg->DataSize+sizeof(struct pipe_prt_msg) - sizeof(unsigned char));
735 inputDevice->protocol_wait_condition = 1;
736 wake_up(&inputDevice->ProtocolWaitEvent);
739 case SynthHidInitialDeviceInfo:
740 WARN_ON(pipeMsg->DataSize >= sizeof(struct input_dev_info));
743 * Parse out the device info into device attr,
744 * hid desc and report desc
746 MousevscOnReceiveDeviceInfo(inputDevice,
747 (struct synthhid_device_info *)&pipeMsg->Data[0]);
749 case SynthHidInputReport:
750 MousevscOnReceiveInputReport(inputDevice,
751 (struct synthhid_input_report *)&pipeMsg->Data[0]);
755 pr_err("unsupported hid msg type - type %d len %d",
756 hidMsg->Header.Type, hidMsg->Header.Size);
760 PutInputDevice(Device);
763 void MousevscOnChannelCallback(void *Context)
765 const int packetSize = 0x100;
767 struct hv_device *device = (struct hv_device *)Context;
768 struct mousevsc_dev *inputDevice;
772 unsigned char packet[packetSize];
773 struct vmpacket_descriptor *desc;
774 unsigned char *buffer = packet;
775 int bufferlen = packetSize;
777 inputDevice = MustGetInputDevice(device);
780 pr_err("unable to get input device...device being destroyed?");
785 ret = vmbus_recvpacket_raw(device->channel, buffer, bufferlen, &bytesRecvd, &requestId);
788 if (bytesRecvd > 0) {
789 desc = (struct vmpacket_descriptor *)buffer;
791 switch (desc->type) {
793 MousevscOnSendCompletion(device,
797 case VM_PKT_DATA_INBAND:
798 MousevscOnReceive(device, desc);
802 pr_err("unhandled packet type %d, tid %llx len %d\n",
810 if (bufferlen > packetSize) {
814 bufferlen = packetSize;
818 * pr_debug("nothing else to read...");
821 if (bufferlen > packetSize) {
825 bufferlen = packetSize;
829 } else if (ret == -2) {
830 /* Handle large packet */
831 bufferlen = bytesRecvd;
832 buffer = kzalloc(bytesRecvd, GFP_KERNEL);
834 if (buffer == NULL) {
836 bufferlen = packetSize;
838 /* Try again next time around */
839 pr_err("unable to allocate buffer of size %d!",
846 PutInputDevice(device);
854 struct input_device_context {
855 struct vm_device *device_ctx;
856 struct hid_device *hid_device;
857 struct input_dev_info device_info;
861 struct mousevsc_driver_context {
862 struct driver_context drv_ctx;
863 struct mousevsc_drv_obj drv_obj;
866 static struct mousevsc_driver_context g_mousevsc_drv;
868 static void deviceinfo_callback(struct hv_device *dev,
869 struct input_dev_info *info)
871 struct vm_device *device_ctx = to_vm_device(dev);
872 struct input_device_context *input_device_ctx =
873 dev_get_drvdata(&device_ctx->device);
875 memcpy(&input_device_ctx->device_info, info,
876 sizeof(struct input_dev_info));
878 DPRINT_INFO(INPUTVSC_DRV, "%s", __func__);
881 static void inputreport_callback(struct hv_device *dev, void *packet, u32 len)
885 struct vm_device *device_ctx = to_vm_device(dev);
886 struct input_device_context *input_dev_ctx =
887 dev_get_drvdata(&device_ctx->device);
889 ret = hid_input_report(input_dev_ctx->hid_device,
890 HID_INPUT_REPORT, packet, len, 1);
892 DPRINT_DBG(INPUTVSC_DRV, "hid_input_report (ret %d)", ret);
895 int mousevsc_hid_open(struct hid_device *hid)
900 void mousevsc_hid_close(struct hid_device *hid)
904 int mousevsc_probe(struct device *device)
908 struct driver_context *driver_ctx =
909 driver_to_driver_context(device->driver);
910 struct mousevsc_driver_context *mousevsc_drv_ctx =
911 (struct mousevsc_driver_context *)driver_ctx;
912 struct mousevsc_drv_obj *mousevsc_drv_obj = &mousevsc_drv_ctx->drv_obj;
914 struct vm_device *device_ctx = device_to_vm_device(device);
915 struct hv_device *device_obj = &device_ctx->device_obj;
916 struct input_device_context *input_dev_ctx;
918 input_dev_ctx = kmalloc(sizeof(struct input_device_context),
921 dev_set_drvdata(device, input_dev_ctx);
923 /* Call to the vsc driver to add the device */
924 ret = mousevsc_drv_obj->Base.dev_add(device_obj, NULL);
927 DPRINT_ERR(INPUTVSC_DRV, "unable to add input vsc device");
936 int mousevsc_remove(struct device *device)
940 struct driver_context *driver_ctx =
941 driver_to_driver_context(device->driver);
942 struct mousevsc_driver_context *mousevsc_drv_ctx =
943 (struct mousevsc_driver_context *)driver_ctx;
944 struct mousevsc_drv_obj *mousevsc_drv_obj = &mousevsc_drv_ctx->drv_obj;
946 struct vm_device *device_ctx = device_to_vm_device(device);
947 struct hv_device *device_obj = &device_ctx->device_obj;
948 struct input_device_context *input_dev_ctx;
950 input_dev_ctx = kmalloc(sizeof(struct input_device_context),
953 dev_set_drvdata(device, input_dev_ctx);
955 if (input_dev_ctx->connected) {
956 hidinput_disconnect(input_dev_ctx->hid_device);
957 input_dev_ctx->connected = 0;
960 if (!mousevsc_drv_obj->Base.dev_rm)
964 * Call to the vsc driver to let it know that the device
967 ret = mousevsc_drv_obj->Base.dev_rm(device_obj);
970 DPRINT_ERR(INPUTVSC_DRV,
971 "unable to remove vsc device (ret %d)", ret);
974 kfree(input_dev_ctx);
979 static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len)
981 struct vm_device *device_ctx = to_vm_device(dev);
982 struct input_device_context *input_device_ctx =
983 dev_get_drvdata(&device_ctx->device);
984 struct hid_device *hid_dev;
986 /* hid_debug = -1; */
987 hid_dev = kmalloc(sizeof(struct hid_device), GFP_KERNEL);
989 if (hid_parse_report(hid_dev, packet, len)) {
990 DPRINT_INFO(INPUTVSC_DRV, "Unable to call hd_parse_report");
995 DPRINT_INFO(INPUTVSC_DRV, "hid_device created");
997 hid_dev->ll_driver->open = mousevsc_hid_open;
998 hid_dev->ll_driver->close = mousevsc_hid_close;
1000 hid_dev->bus = 0x06; /* BUS_VIRTUAL */
1001 hid_dev->vendor = input_device_ctx->device_info.VendorID;
1002 hid_dev->product = input_device_ctx->device_info.ProductID;
1003 hid_dev->version = input_device_ctx->device_info.VersionNumber;
1004 hid_dev->dev = device_ctx->device;
1006 sprintf(hid_dev->name, "%s",
1007 input_device_ctx->device_info.Name);
1010 * HJ Do we want to call it with a 0
1012 if (!hidinput_connect(hid_dev, 0)) {
1013 hid_dev->claimed |= HID_CLAIMED_INPUT;
1015 input_device_ctx->connected = 1;
1017 DPRINT_INFO(INPUTVSC_DRV,
1018 "HID device claimed by input\n");
1021 if (!hid_dev->claimed) {
1022 DPRINT_ERR(INPUTVSC_DRV,
1023 "HID device not claimed by "
1024 "input or hiddev\n");
1027 input_device_ctx->hid_device = hid_dev;
1033 int mousevsc_drv_exit_cb(struct device *dev, void *data)
1035 struct device **curr = (struct device **)data;
1041 void mousevsc_drv_exit(void)
1043 struct mousevsc_drv_obj *mousevsc_drv_obj = &g_mousevsc_drv.drv_obj;
1044 struct driver_context *drv_ctx = &g_mousevsc_drv.drv_ctx;
1047 struct device *current_dev = NULL;
1052 /* Get the device */
1053 ret = driver_for_each_device(&drv_ctx->driver, NULL,
1054 (void *)¤t_dev,
1055 mousevsc_drv_exit_cb);
1057 printk(KERN_ERR "Can't find mouse device!\n");
1059 if (current_dev == NULL)
1062 /* Initiate removal from the top-down */
1063 device_unregister(current_dev);
1066 if (mousevsc_drv_obj->Base.cleanup)
1067 mousevsc_drv_obj->Base.cleanup(&mousevsc_drv_obj->Base);
1069 vmbus_child_driver_unregister(drv_ctx);
1074 static int __init mousevsc_init(void)
1076 struct mousevsc_drv_obj *input_drv_obj = &g_mousevsc_drv.drv_obj;
1077 struct driver_context *drv_ctx = &g_mousevsc_drv.drv_ctx;
1079 DPRINT_INFO(INPUTVSC_DRV, "Hyper-V Mouse driver initializing.");
1081 /* Callback to client driver to complete the initialization */
1082 mouse_vsc_initialize(&input_drv_obj->Base);
1084 drv_ctx->driver.name = input_drv_obj->Base.name;
1085 memcpy(&drv_ctx->class_id, &input_drv_obj->Base.dev_type,
1086 sizeof(struct hv_guid));
1088 drv_ctx->probe = mousevsc_probe;
1089 drv_ctx->remove = mousevsc_remove;
1091 /* The driver belongs to vmbus */
1092 vmbus_child_driver_register(drv_ctx);
1097 static void __exit mousevsc_exit(void)
1099 mousevsc_drv_exit();
1103 * We don't want to automatically load this driver just yet, it's quite
1104 * broken. It's safe if you want to load it yourself manually, but
1105 * don't inflict it on unsuspecting users, that's just mean.
1110 * We use a PCI table to determine if we should autoload this driver This is
1111 * needed by distro tools to determine if the hyperv drivers should be
1112 * installed and/or configured. We don't do anything else with the table, but
1113 * it needs to be present.
1115 const static struct pci_device_id microsoft_hv_pci_table[] = {
1116 { PCI_DEVICE(0x1414, 0x5353) }, /* VGA compatible controller */
1119 MODULE_DEVICE_TABLE(pci, microsoft_hv_pci_table);
1122 MODULE_LICENSE("GPL");
1123 MODULE_VERSION(HV_DRV_VERSION);
1124 module_init(mousevsc_init);
1125 module_exit(mousevsc_exit);