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;
91 struct synthhid_msg_hdr Header;
92 char Data[1]; /* Enclosed message */
95 union synthhid_version {
107 struct synthhid_protocol_request {
108 struct synthhid_msg_hdr Header;
109 union synthhid_version VersionRequested;
112 struct synthhid_protocol_response {
113 struct synthhid_msg_hdr Header;
114 union synthhid_version VersionRequested;
115 unsigned char Approved;
118 struct synthhid_device_info {
119 struct synthhid_msg_hdr Header;
120 struct hv_input_dev_info HidDeviceAttributes;
121 unsigned char HidDescriptorInformation[1];
124 struct synthhid_device_info_ack {
125 struct synthhid_msg_hdr Header;
126 unsigned char Reserved;
129 struct synthhid_input_report {
130 struct synthhid_msg_hdr Header;
131 char ReportBuffer[1];
136 #define INPUTVSC_SEND_RING_BUFFER_SIZE 10*PAGE_SIZE
137 #define INPUTVSC_RECV_RING_BUFFER_SIZE 10*PAGE_SIZE
139 #define NBITS(x) (((x)/BITS_PER_LONG)+1)
141 enum pipe_prot_msg_type {
142 PipeMessageInvalid = 0,
148 struct pipe_prt_msg {
149 enum pipe_prot_msg_type PacketType;
157 struct mousevsc_prt_msg {
158 enum pipe_prot_msg_type PacketType;
161 struct synthhid_protocol_request Request;
162 struct synthhid_protocol_response Response;
163 struct synthhid_device_info_ack Ack;
168 * Represents an mousevsc device
170 struct mousevsc_dev {
171 struct hv_device *Device;
172 /* 0 indicates the device is being destroyed */
174 int NumOutstandingRequests;
175 unsigned char bInitializeComplete;
176 struct mousevsc_prt_msg ProtocolReq;
177 struct mousevsc_prt_msg ProtocolResp;
178 /* Synchronize the request/response if needed */
179 wait_queue_head_t ProtocolWaitEvent;
180 wait_queue_head_t DeviceInfoWaitEvent;
181 int protocol_wait_condition;
182 int device_wait_condition;
183 int DeviceInfoStatus;
185 struct hid_descriptor *HidDesc;
186 unsigned char *ReportDesc;
188 struct hv_input_dev_info DeviceAttr;
195 static const char *gDriverName = "mousevsc";
197 /* {CFA8B69E-5B4A-4cc0-B98B-8BA1A1F3F95A} */
198 static const struct hv_guid gMousevscDeviceType = {
199 .data = {0x9E, 0xB6, 0xA8, 0xCF, 0x4A, 0x5B, 0xc0, 0x4c,
200 0xB9, 0x8B, 0x8B, 0xA1, 0xA1, 0xF3, 0xF9, 0x5A}
203 static void MousevscOnReceive(struct hv_device *Device,
204 struct vmpacket_descriptor *Packet);
206 static void deviceinfo_callback(struct hv_device *dev, struct hv_input_dev_info *info);
207 static void inputreport_callback(struct hv_device *dev, void *packet, u32 len);
208 static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len);
210 static struct mousevsc_dev *AllocInputDevice(struct hv_device *Device)
212 struct mousevsc_dev *inputDevice;
214 inputDevice = kzalloc(sizeof(struct mousevsc_dev), GFP_KERNEL);
220 * Set to 2 to allow both inbound and outbound traffics
221 * (ie GetInputDevice() and MustGetInputDevice()) to proceed.
223 atomic_cmpxchg(&inputDevice->RefCount, 0, 2);
225 inputDevice->Device = Device;
226 Device->ext = inputDevice;
231 static void FreeInputDevice(struct mousevsc_dev *Device)
233 WARN_ON(atomic_read(&Device->RefCount) == 0);
238 * Get the inputdevice object if exists and its refcount > 1
240 static struct mousevsc_dev *GetInputDevice(struct hv_device *Device)
242 struct mousevsc_dev *inputDevice;
244 inputDevice = (struct mousevsc_dev *)Device->ext;
248 * This sure isn't a valid thing to print for debugging, no matter
249 * what the intention is...
251 * printk(KERN_ERR "-------------------------> REFCOUNT = %d",
252 * inputDevice->RefCount);
255 if (inputDevice && atomic_read(&inputDevice->RefCount) > 1)
256 atomic_inc(&inputDevice->RefCount);
264 * Get the inputdevice object iff exists and its refcount > 0
266 static struct mousevsc_dev *MustGetInputDevice(struct hv_device *Device)
268 struct mousevsc_dev *inputDevice;
270 inputDevice = (struct mousevsc_dev *)Device->ext;
272 if (inputDevice && atomic_read(&inputDevice->RefCount))
273 atomic_inc(&inputDevice->RefCount);
280 static void PutInputDevice(struct hv_device *Device)
282 struct mousevsc_dev *inputDevice;
284 inputDevice = (struct mousevsc_dev *)Device->ext;
286 atomic_dec(&inputDevice->RefCount);
290 * Drop ref count to 1 to effectively disable GetInputDevice()
292 static struct mousevsc_dev *ReleaseInputDevice(struct hv_device *Device)
294 struct mousevsc_dev *inputDevice;
296 inputDevice = (struct mousevsc_dev *)Device->ext;
298 /* Busy wait until the ref drop to 2, then set it to 1 */
299 while (atomic_cmpxchg(&inputDevice->RefCount, 2, 1) != 2)
306 * Drop ref count to 0. No one can use InputDevice object.
308 static struct mousevsc_dev *FinalReleaseInputDevice(struct hv_device *Device)
310 struct mousevsc_dev *inputDevice;
312 inputDevice = (struct mousevsc_dev *)Device->ext;
314 /* Busy wait until the ref drop to 1, then set it to 0 */
315 while (atomic_cmpxchg(&inputDevice->RefCount, 1, 0) != 1)
322 static void MousevscOnSendCompletion(struct hv_device *Device, struct vmpacket_descriptor *Packet)
324 struct mousevsc_dev *inputDevice;
327 inputDevice = MustGetInputDevice(Device);
329 pr_err("unable to get input device...device being destroyed?");
333 request = (void *)(unsigned long *)Packet->trans_id;
335 if (request == &inputDevice->ProtocolReq) {
337 /* Shouldn't we be doing something here? */
340 PutInputDevice(Device);
343 static void MousevscOnReceiveDeviceInfo(struct mousevsc_dev *InputDevice, struct synthhid_device_info *DeviceInfo)
346 struct hid_descriptor *desc;
347 struct mousevsc_prt_msg ack;
349 /* Assume success for now */
350 InputDevice->DeviceInfoStatus = 0;
352 /* Save the device attr */
353 memcpy(&InputDevice->DeviceAttr, &DeviceInfo->HidDeviceAttributes, sizeof(struct hv_input_dev_info));
355 /* Save the hid desc */
356 desc = (struct hid_descriptor *)DeviceInfo->HidDescriptorInformation;
357 WARN_ON(desc->bLength > 0);
359 InputDevice->HidDesc = kzalloc(desc->bLength, GFP_KERNEL);
361 if (!InputDevice->HidDesc) {
362 pr_err("unable to allocate hid descriptor - size %d", desc->bLength);
366 memcpy(InputDevice->HidDesc, desc, desc->bLength);
368 /* Save the report desc */
369 InputDevice->ReportDescSize = desc->desc[0].wDescriptorLength;
370 InputDevice->ReportDesc = kzalloc(InputDevice->ReportDescSize,
373 if (!InputDevice->ReportDesc) {
374 pr_err("unable to allocate report descriptor - size %d",
375 InputDevice->ReportDescSize);
379 memcpy(InputDevice->ReportDesc,
380 ((unsigned char *)desc) + desc->bLength,
381 desc->desc[0].wDescriptorLength);
384 memset(&ack, sizeof(struct mousevsc_prt_msg), 0);
386 ack.PacketType = PipeMessageData;
387 ack.DataSize = sizeof(struct synthhid_device_info_ack);
389 ack.u.Ack.Header.type = SynthHidInitialDeviceInfoAck;
390 ack.u.Ack.Header.size = 1;
391 ack.u.Ack.Reserved = 0;
393 ret = vmbus_sendpacket(InputDevice->Device->channel,
395 sizeof(struct pipe_prt_msg) - sizeof(unsigned char) +
396 sizeof(struct synthhid_device_info_ack),
399 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
401 pr_err("unable to send synthhid device info ack - ret %d",
406 InputDevice->device_wait_condition = 1;
407 wake_up(&InputDevice->DeviceInfoWaitEvent);
412 if (InputDevice->HidDesc) {
413 kfree(InputDevice->HidDesc);
414 InputDevice->HidDesc = NULL;
417 if (InputDevice->ReportDesc) {
418 kfree(InputDevice->ReportDesc);
419 InputDevice->ReportDesc = NULL;
422 InputDevice->DeviceInfoStatus = -1;
423 InputDevice->device_wait_condition = 1;
424 wake_up(&InputDevice->DeviceInfoWaitEvent);
427 static void MousevscOnReceiveInputReport(struct mousevsc_dev *InputDevice, struct synthhid_input_report *InputReport)
429 struct mousevsc_drv_obj *inputDriver;
431 if (!InputDevice->bInitializeComplete) {
432 pr_info("Initialization incomplete...ignoring InputReport msg");
436 inputDriver = (struct mousevsc_drv_obj *)InputDevice->Device->drv;
438 inputreport_callback(InputDevice->Device,
439 InputReport->ReportBuffer,
440 InputReport->Header.size);
443 static void MousevscOnReceive(struct hv_device *Device, struct vmpacket_descriptor *Packet)
445 struct pipe_prt_msg *pipeMsg;
446 struct synthhid_msg *hidMsg;
447 struct mousevsc_dev *inputDevice;
449 inputDevice = MustGetInputDevice(Device);
451 pr_err("unable to get input device...device being destroyed?");
455 pipeMsg = (struct pipe_prt_msg *)((unsigned long)Packet + (Packet->offset8 << 3));
457 if (pipeMsg->PacketType != PipeMessageData) {
458 pr_err("unknown pipe msg type - type %d len %d",
459 pipeMsg->PacketType, pipeMsg->DataSize);
460 PutInputDevice(Device);
464 hidMsg = (struct synthhid_msg *)&pipeMsg->Data[0];
466 switch (hidMsg->Header.type) {
467 case SynthHidProtocolResponse:
468 memcpy(&inputDevice->ProtocolResp, pipeMsg, pipeMsg->DataSize+sizeof(struct pipe_prt_msg) - sizeof(unsigned char));
469 inputDevice->protocol_wait_condition = 1;
470 wake_up(&inputDevice->ProtocolWaitEvent);
473 case SynthHidInitialDeviceInfo:
474 WARN_ON(pipeMsg->DataSize >= sizeof(struct hv_input_dev_info));
477 * Parse out the device info into device attr,
478 * hid desc and report desc
480 MousevscOnReceiveDeviceInfo(inputDevice,
481 (struct synthhid_device_info *)&pipeMsg->Data[0]);
483 case SynthHidInputReport:
484 MousevscOnReceiveInputReport(inputDevice,
485 (struct synthhid_input_report *)&pipeMsg->Data[0]);
489 pr_err("unsupported hid msg type - type %d len %d",
490 hidMsg->Header.type, hidMsg->Header.size);
494 PutInputDevice(Device);
497 static void MousevscOnChannelCallback(void *Context)
499 const int packetSize = 0x100;
501 struct hv_device *device = (struct hv_device *)Context;
502 struct mousevsc_dev *inputDevice;
506 unsigned char packet[packetSize];
507 struct vmpacket_descriptor *desc;
508 unsigned char *buffer = packet;
509 int bufferlen = packetSize;
511 inputDevice = MustGetInputDevice(device);
514 pr_err("unable to get input device...device being destroyed?");
519 ret = vmbus_recvpacket_raw(device->channel, buffer, bufferlen, &bytesRecvd, &requestId);
522 if (bytesRecvd > 0) {
523 desc = (struct vmpacket_descriptor *)buffer;
525 switch (desc->type) {
527 MousevscOnSendCompletion(device,
531 case VM_PKT_DATA_INBAND:
532 MousevscOnReceive(device, desc);
536 pr_err("unhandled packet type %d, tid %llx len %d\n",
544 if (bufferlen > packetSize) {
548 bufferlen = packetSize;
552 * pr_debug("nothing else to read...");
555 if (bufferlen > packetSize) {
559 bufferlen = packetSize;
563 } else if (ret == -2) {
564 /* Handle large packet */
565 bufferlen = bytesRecvd;
566 buffer = kzalloc(bytesRecvd, GFP_KERNEL);
568 if (buffer == NULL) {
570 bufferlen = packetSize;
572 /* Try again next time around */
573 pr_err("unable to allocate buffer of size %d!",
580 PutInputDevice(device);
585 static int MousevscConnectToVsp(struct hv_device *Device)
588 struct mousevsc_dev *inputDevice;
589 struct mousevsc_prt_msg *request;
590 struct mousevsc_prt_msg *response;
592 inputDevice = GetInputDevice(Device);
595 pr_err("unable to get input device...device being destroyed?");
599 init_waitqueue_head(&inputDevice->ProtocolWaitEvent);
600 init_waitqueue_head(&inputDevice->DeviceInfoWaitEvent);
602 request = &inputDevice->ProtocolReq;
605 * Now, initiate the vsc/vsp initialization protocol on the open channel
607 memset(request, sizeof(struct mousevsc_prt_msg), 0);
609 request->PacketType = PipeMessageData;
610 request->DataSize = sizeof(struct synthhid_protocol_request);
612 request->u.Request.Header.type = SynthHidProtocolRequest;
613 request->u.Request.Header.size = sizeof(unsigned long);
614 request->u.Request.VersionRequested.AsDWord =
615 SYNTHHID_INPUT_VERSION_DWORD;
617 pr_info("synthhid protocol request...");
619 ret = vmbus_sendpacket(Device->channel, request,
620 sizeof(struct pipe_prt_msg) -
621 sizeof(unsigned char) +
622 sizeof(struct synthhid_protocol_request),
623 (unsigned long)request,
625 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
627 pr_err("unable to send synthhid protocol request.");
631 inputDevice->protocol_wait_condition = 0;
632 wait_event_timeout(inputDevice->ProtocolWaitEvent, inputDevice->protocol_wait_condition, msecs_to_jiffies(1000));
633 if (inputDevice->protocol_wait_condition == 0) {
638 response = &inputDevice->ProtocolResp;
640 if (!response->u.Response.Approved) {
641 pr_err("synthhid protocol request failed (version %d)",
642 SYNTHHID_INPUT_VERSION_DWORD);
647 inputDevice->device_wait_condition = 0;
648 wait_event_timeout(inputDevice->DeviceInfoWaitEvent, inputDevice->device_wait_condition, msecs_to_jiffies(1000));
649 if (inputDevice->device_wait_condition == 0) {
655 * We should have gotten the device attr, hid desc and report
658 if (!inputDevice->DeviceInfoStatus)
659 pr_info("**** input channel up and running!! ****");
664 PutInputDevice(Device);
669 static int MousevscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo)
672 struct mousevsc_dev *inputDevice;
673 struct mousevsc_drv_obj *inputDriver;
674 struct hv_input_dev_info deviceInfo;
676 inputDevice = AllocInputDevice(Device);
683 inputDevice->bInitializeComplete = false;
685 /* Open the channel */
686 ret = vmbus_open(Device->channel,
687 INPUTVSC_SEND_RING_BUFFER_SIZE,
688 INPUTVSC_RECV_RING_BUFFER_SIZE,
691 MousevscOnChannelCallback,
696 pr_err("unable to open channel: %d", ret);
700 pr_info("InputVsc channel open: %d", ret);
702 ret = MousevscConnectToVsp(Device);
705 pr_err("unable to connect channel: %d", ret);
707 vmbus_close(Device->channel);
711 inputDriver = (struct mousevsc_drv_obj *)inputDevice->Device->drv;
713 deviceInfo.vendor = inputDevice->DeviceAttr.vendor;
714 deviceInfo.product = inputDevice->DeviceAttr.product;
715 deviceInfo.version = inputDevice->DeviceAttr.version;
716 strcpy(deviceInfo.name, "Microsoft Vmbus HID-compliant Mouse");
718 /* Send the device info back up */
719 deviceinfo_callback(Device, &deviceInfo);
721 /* Send the report desc back up */
722 /* workaround SA-167 */
723 if (inputDevice->ReportDesc[14] == 0x25)
724 inputDevice->ReportDesc[14] = 0x29;
726 reportdesc_callback(Device, inputDevice->ReportDesc,
727 inputDevice->ReportDescSize);
729 inputDevice->bInitializeComplete = true;
735 static int MousevscOnDeviceRemove(struct hv_device *Device)
737 struct mousevsc_dev *inputDevice;
740 pr_info("disabling input device (%p)...",
743 inputDevice = ReleaseInputDevice(Device);
747 * At this point, all outbound traffic should be disable. We only
748 * allow inbound traffic (responses) to proceed
750 * so that outstanding requests can be completed.
752 while (inputDevice->NumOutstandingRequests) {
753 pr_info("waiting for %d requests to complete...", inputDevice->NumOutstandingRequests);
758 pr_info("removing input device (%p)...", Device->ext);
760 inputDevice = FinalReleaseInputDevice(Device);
762 pr_info("input device (%p) safe to remove", inputDevice);
764 /* Close the channel */
765 vmbus_close(Device->channel);
767 FreeInputDevice(inputDevice);
772 static void MousevscOnCleanup(struct hv_driver *drv)
779 struct input_device_context {
780 struct vm_device *device_ctx;
781 struct hid_device *hid_device;
782 struct hv_input_dev_info device_info;
786 struct mousevsc_driver_context {
787 struct driver_context drv_ctx;
788 struct mousevsc_drv_obj drv_obj;
791 static struct mousevsc_driver_context g_mousevsc_drv;
793 static void deviceinfo_callback(struct hv_device *dev, struct hv_input_dev_info *info)
795 struct vm_device *device_ctx = to_vm_device(dev);
796 struct input_device_context *input_device_ctx =
797 dev_get_drvdata(&device_ctx->device);
799 memcpy(&input_device_ctx->device_info, info,
800 sizeof(struct hv_input_dev_info));
802 DPRINT_INFO(INPUTVSC_DRV, "%s", __func__);
805 static void inputreport_callback(struct hv_device *dev, void *packet, u32 len)
809 struct vm_device *device_ctx = to_vm_device(dev);
810 struct input_device_context *input_dev_ctx =
811 dev_get_drvdata(&device_ctx->device);
813 ret = hid_input_report(input_dev_ctx->hid_device,
814 HID_INPUT_REPORT, packet, len, 1);
816 DPRINT_DBG(INPUTVSC_DRV, "hid_input_report (ret %d)", ret);
819 static int mousevsc_hid_open(struct hid_device *hid)
824 static void mousevsc_hid_close(struct hid_device *hid)
828 static int mousevsc_probe(struct device *device)
832 struct driver_context *driver_ctx =
833 driver_to_driver_context(device->driver);
834 struct mousevsc_driver_context *mousevsc_drv_ctx =
835 (struct mousevsc_driver_context *)driver_ctx;
836 struct mousevsc_drv_obj *mousevsc_drv_obj = &mousevsc_drv_ctx->drv_obj;
838 struct vm_device *device_ctx = device_to_vm_device(device);
839 struct hv_device *device_obj = &device_ctx->device_obj;
840 struct input_device_context *input_dev_ctx;
842 input_dev_ctx = kmalloc(sizeof(struct input_device_context),
845 dev_set_drvdata(device, input_dev_ctx);
847 /* Call to the vsc driver to add the device */
848 ret = mousevsc_drv_obj->Base.dev_add(device_obj, NULL);
851 DPRINT_ERR(INPUTVSC_DRV, "unable to add input vsc device");
859 static int mousevsc_remove(struct device *device)
863 struct driver_context *driver_ctx =
864 driver_to_driver_context(device->driver);
865 struct mousevsc_driver_context *mousevsc_drv_ctx =
866 (struct mousevsc_driver_context *)driver_ctx;
867 struct mousevsc_drv_obj *mousevsc_drv_obj = &mousevsc_drv_ctx->drv_obj;
869 struct vm_device *device_ctx = device_to_vm_device(device);
870 struct hv_device *device_obj = &device_ctx->device_obj;
871 struct input_device_context *input_dev_ctx;
873 input_dev_ctx = kmalloc(sizeof(struct input_device_context),
876 dev_set_drvdata(device, input_dev_ctx);
878 if (input_dev_ctx->connected) {
879 hidinput_disconnect(input_dev_ctx->hid_device);
880 input_dev_ctx->connected = 0;
883 if (!mousevsc_drv_obj->Base.dev_rm)
887 * Call to the vsc driver to let it know that the device
890 ret = mousevsc_drv_obj->Base.dev_rm(device_obj);
893 DPRINT_ERR(INPUTVSC_DRV,
894 "unable to remove vsc device (ret %d)", ret);
897 kfree(input_dev_ctx);
902 static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len)
904 struct vm_device *device_ctx = to_vm_device(dev);
905 struct input_device_context *input_device_ctx =
906 dev_get_drvdata(&device_ctx->device);
907 struct hid_device *hid_dev;
909 /* hid_debug = -1; */
910 hid_dev = kmalloc(sizeof(struct hid_device), GFP_KERNEL);
912 if (hid_parse_report(hid_dev, packet, len)) {
913 DPRINT_INFO(INPUTVSC_DRV, "Unable to call hd_parse_report");
918 DPRINT_INFO(INPUTVSC_DRV, "hid_device created");
920 hid_dev->ll_driver->open = mousevsc_hid_open;
921 hid_dev->ll_driver->close = mousevsc_hid_close;
923 hid_dev->bus = BUS_VIRTUAL;
924 hid_dev->vendor = input_device_ctx->device_info.vendor;
925 hid_dev->product = input_device_ctx->device_info.product;
926 hid_dev->version = input_device_ctx->device_info.version;
927 hid_dev->dev = device_ctx->device;
929 sprintf(hid_dev->name, "%s",
930 input_device_ctx->device_info.name);
933 * HJ Do we want to call it with a 0
935 if (!hidinput_connect(hid_dev, 0)) {
936 hid_dev->claimed |= HID_CLAIMED_INPUT;
938 input_device_ctx->connected = 1;
940 DPRINT_INFO(INPUTVSC_DRV,
941 "HID device claimed by input\n");
944 if (!hid_dev->claimed) {
945 DPRINT_ERR(INPUTVSC_DRV,
946 "HID device not claimed by "
947 "input or hiddev\n");
950 input_device_ctx->hid_device = hid_dev;
956 static int mousevsc_drv_exit_cb(struct device *dev, void *data)
958 struct device **curr = (struct device **)data;
964 static void mousevsc_drv_exit(void)
966 struct mousevsc_drv_obj *mousevsc_drv_obj = &g_mousevsc_drv.drv_obj;
967 struct driver_context *drv_ctx = &g_mousevsc_drv.drv_ctx;
970 struct device *current_dev = NULL;
976 ret = driver_for_each_device(&drv_ctx->driver, NULL,
977 (void *)¤t_dev,
978 mousevsc_drv_exit_cb);
980 printk(KERN_ERR "Can't find mouse device!\n");
982 if (current_dev == NULL)
985 /* Initiate removal from the top-down */
986 device_unregister(current_dev);
989 if (mousevsc_drv_obj->Base.cleanup)
990 mousevsc_drv_obj->Base.cleanup(&mousevsc_drv_obj->Base);
992 vmbus_child_driver_unregister(drv_ctx);
997 static int mouse_vsc_initialize(struct hv_driver *Driver)
999 struct mousevsc_drv_obj *inputDriver =
1000 (struct mousevsc_drv_obj *)Driver;
1003 Driver->name = gDriverName;
1004 memcpy(&Driver->dev_type, &gMousevscDeviceType,
1005 sizeof(struct hv_guid));
1007 /* Setup the dispatch table */
1008 inputDriver->Base.dev_add = MousevscOnDeviceAdd;
1009 inputDriver->Base.dev_rm = MousevscOnDeviceRemove;
1010 inputDriver->Base.cleanup = MousevscOnCleanup;
1016 static int __init mousevsc_init(void)
1018 struct mousevsc_drv_obj *input_drv_obj = &g_mousevsc_drv.drv_obj;
1019 struct driver_context *drv_ctx = &g_mousevsc_drv.drv_ctx;
1021 DPRINT_INFO(INPUTVSC_DRV, "Hyper-V Mouse driver initializing.");
1023 /* Callback to client driver to complete the initialization */
1024 mouse_vsc_initialize(&input_drv_obj->Base);
1026 drv_ctx->driver.name = input_drv_obj->Base.name;
1027 memcpy(&drv_ctx->class_id, &input_drv_obj->Base.dev_type,
1028 sizeof(struct hv_guid));
1030 drv_ctx->probe = mousevsc_probe;
1031 drv_ctx->remove = mousevsc_remove;
1033 /* The driver belongs to vmbus */
1034 vmbus_child_driver_register(drv_ctx);
1039 static void __exit mousevsc_exit(void)
1041 mousevsc_drv_exit();
1045 * We don't want to automatically load this driver just yet, it's quite
1046 * broken. It's safe if you want to load it yourself manually, but
1047 * don't inflict it on unsuspecting users, that's just mean.
1052 * We use a PCI table to determine if we should autoload this driver This is
1053 * needed by distro tools to determine if the hyperv drivers should be
1054 * installed and/or configured. We don't do anything else with the table, but
1055 * it needs to be present.
1057 const static struct pci_device_id microsoft_hv_pci_table[] = {
1058 { PCI_DEVICE(0x1414, 0x5353) }, /* VGA compatible controller */
1061 MODULE_DEVICE_TABLE(pci, microsoft_hv_pci_table);
1064 MODULE_LICENSE("GPL");
1065 MODULE_VERSION(HV_DRV_VERSION);
1066 module_init(mousevsc_init);
1067 module_exit(mousevsc_exit);