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 hid_dev_info;
120 struct hid_descriptor hid_descriptor;
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;
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 type;
156 struct mousevsc_prt_msg {
157 enum pipe_prot_msg_type type;
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 hid_dev_info;
191 static const char *driver_name = "mousevsc";
193 /* {CFA8B69E-5B4A-4cc0-B98B-8BA1A1F3F95A} */
194 static const struct hv_guid mouse_guid = {
195 .data = {0x9E, 0xB6, 0xA8, 0xCF, 0x4A, 0x5B, 0xc0, 0x4c,
196 0xB9, 0x8B, 0x8B, 0xA1, 0xA1, 0xF3, 0xF9, 0x5A}
199 static void MousevscOnReceive(struct hv_device *Device,
200 struct vmpacket_descriptor *Packet);
202 static void deviceinfo_callback(struct hv_device *dev, struct hv_input_dev_info *info);
203 static void inputreport_callback(struct hv_device *dev, void *packet, u32 len);
204 static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len);
206 static struct mousevsc_dev *AllocInputDevice(struct hv_device *Device)
208 struct mousevsc_dev *inputDevice;
210 inputDevice = kzalloc(sizeof(struct mousevsc_dev), GFP_KERNEL);
216 * Set to 2 to allow both inbound and outbound traffics
217 * (ie GetInputDevice() and MustGetInputDevice()) to proceed.
219 atomic_cmpxchg(&inputDevice->RefCount, 0, 2);
221 inputDevice->Device = Device;
222 Device->ext = inputDevice;
227 static void FreeInputDevice(struct mousevsc_dev *Device)
229 WARN_ON(atomic_read(&Device->RefCount) == 0);
234 * Get the inputdevice object if exists and its refcount > 1
236 static struct mousevsc_dev *GetInputDevice(struct hv_device *Device)
238 struct mousevsc_dev *inputDevice;
240 inputDevice = (struct mousevsc_dev *)Device->ext;
244 * This sure isn't a valid thing to print for debugging, no matter
245 * what the intention is...
247 * printk(KERN_ERR "-------------------------> REFCOUNT = %d",
248 * inputDevice->RefCount);
251 if (inputDevice && atomic_read(&inputDevice->RefCount) > 1)
252 atomic_inc(&inputDevice->RefCount);
260 * Get the inputdevice object iff exists and its refcount > 0
262 static struct mousevsc_dev *MustGetInputDevice(struct hv_device *Device)
264 struct mousevsc_dev *inputDevice;
266 inputDevice = (struct mousevsc_dev *)Device->ext;
268 if (inputDevice && atomic_read(&inputDevice->RefCount))
269 atomic_inc(&inputDevice->RefCount);
276 static void PutInputDevice(struct hv_device *Device)
278 struct mousevsc_dev *inputDevice;
280 inputDevice = (struct mousevsc_dev *)Device->ext;
282 atomic_dec(&inputDevice->RefCount);
286 * Drop ref count to 1 to effectively disable GetInputDevice()
288 static struct mousevsc_dev *ReleaseInputDevice(struct hv_device *Device)
290 struct mousevsc_dev *inputDevice;
292 inputDevice = (struct mousevsc_dev *)Device->ext;
294 /* Busy wait until the ref drop to 2, then set it to 1 */
295 while (atomic_cmpxchg(&inputDevice->RefCount, 2, 1) != 2)
302 * Drop ref count to 0. No one can use InputDevice object.
304 static struct mousevsc_dev *FinalReleaseInputDevice(struct hv_device *Device)
306 struct mousevsc_dev *inputDevice;
308 inputDevice = (struct mousevsc_dev *)Device->ext;
310 /* Busy wait until the ref drop to 1, then set it to 0 */
311 while (atomic_cmpxchg(&inputDevice->RefCount, 1, 0) != 1)
318 static void MousevscOnSendCompletion(struct hv_device *Device, struct vmpacket_descriptor *Packet)
320 struct mousevsc_dev *inputDevice;
323 inputDevice = MustGetInputDevice(Device);
325 pr_err("unable to get input device...device being destroyed?");
329 request = (void *)(unsigned long)Packet->trans_id;
331 if (request == &inputDevice->ProtocolReq) {
333 /* Shouldn't we be doing something here? */
336 PutInputDevice(Device);
339 static void MousevscOnReceiveDeviceInfo(struct mousevsc_dev *InputDevice, struct synthhid_device_info *DeviceInfo)
342 struct hid_descriptor *desc;
343 struct mousevsc_prt_msg ack;
345 /* Assume success for now */
346 InputDevice->DeviceInfoStatus = 0;
348 /* Save the device attr */
349 memcpy(&InputDevice->hid_dev_info, &DeviceInfo->hid_dev_info, sizeof(struct hv_input_dev_info));
351 /* Save the hid desc */
352 desc = &DeviceInfo->hid_descriptor;
353 WARN_ON(desc->bLength > 0);
355 InputDevice->HidDesc = kzalloc(desc->bLength, GFP_KERNEL);
357 if (!InputDevice->HidDesc) {
358 pr_err("unable to allocate hid descriptor - size %d", desc->bLength);
362 memcpy(InputDevice->HidDesc, desc, desc->bLength);
364 /* Save the report desc */
365 InputDevice->ReportDescSize = desc->desc[0].wDescriptorLength;
366 InputDevice->ReportDesc = kzalloc(InputDevice->ReportDescSize,
369 if (!InputDevice->ReportDesc) {
370 pr_err("unable to allocate report descriptor - size %d",
371 InputDevice->ReportDescSize);
375 memcpy(InputDevice->ReportDesc,
376 ((unsigned char *)desc) + desc->bLength,
377 desc->desc[0].wDescriptorLength);
380 memset(&ack, sizeof(struct mousevsc_prt_msg), 0);
382 ack.type = PipeMessageData;
383 ack.size = sizeof(struct synthhid_device_info_ack);
385 ack.ack.header.type = SynthHidInitialDeviceInfoAck;
386 ack.ack.header.size = 1;
387 ack.ack.reserved = 0;
389 ret = vmbus_sendpacket(InputDevice->Device->channel,
391 sizeof(struct pipe_prt_msg) - sizeof(unsigned char) +
392 sizeof(struct synthhid_device_info_ack),
395 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
397 pr_err("unable to send synthhid device info ack - ret %d",
402 InputDevice->device_wait_condition = 1;
403 wake_up(&InputDevice->DeviceInfoWaitEvent);
408 if (InputDevice->HidDesc) {
409 kfree(InputDevice->HidDesc);
410 InputDevice->HidDesc = NULL;
413 if (InputDevice->ReportDesc) {
414 kfree(InputDevice->ReportDesc);
415 InputDevice->ReportDesc = NULL;
418 InputDevice->DeviceInfoStatus = -1;
419 InputDevice->device_wait_condition = 1;
420 wake_up(&InputDevice->DeviceInfoWaitEvent);
423 static void MousevscOnReceiveInputReport(struct mousevsc_dev *InputDevice, struct synthhid_input_report *InputReport)
425 struct mousevsc_drv_obj *inputDriver;
427 if (!InputDevice->bInitializeComplete) {
428 pr_info("Initialization incomplete...ignoring InputReport msg");
432 inputDriver = (struct mousevsc_drv_obj *)InputDevice->Device->drv;
434 inputreport_callback(InputDevice->Device,
436 InputReport->header.size);
439 static void MousevscOnReceive(struct hv_device *Device, struct vmpacket_descriptor *Packet)
441 struct pipe_prt_msg *pipeMsg;
442 struct synthhid_msg *hidMsg;
443 struct mousevsc_dev *inputDevice;
445 inputDevice = MustGetInputDevice(Device);
447 pr_err("unable to get input device...device being destroyed?");
451 pipeMsg = (struct pipe_prt_msg *)((unsigned long)Packet + (Packet->offset8 << 3));
453 if (pipeMsg->type != PipeMessageData) {
454 pr_err("unknown pipe msg type - type %d len %d",
455 pipeMsg->type, pipeMsg->size);
456 PutInputDevice(Device);
460 hidMsg = (struct synthhid_msg *)&pipeMsg->data[0];
462 switch (hidMsg->header.type) {
463 case SynthHidProtocolResponse:
464 memcpy(&inputDevice->ProtocolResp, pipeMsg,
465 pipeMsg->size + sizeof(struct pipe_prt_msg) -
466 sizeof(unsigned char));
467 inputDevice->protocol_wait_condition = 1;
468 wake_up(&inputDevice->ProtocolWaitEvent);
471 case SynthHidInitialDeviceInfo:
472 WARN_ON(pipeMsg->size >= sizeof(struct hv_input_dev_info));
475 * Parse out the device info into device attr,
476 * hid desc and report desc
478 MousevscOnReceiveDeviceInfo(inputDevice,
479 (struct synthhid_device_info *)&pipeMsg->data[0]);
481 case SynthHidInputReport:
482 MousevscOnReceiveInputReport(inputDevice,
483 (struct synthhid_input_report *)&pipeMsg->data[0]);
487 pr_err("unsupported hid msg type - type %d len %d",
488 hidMsg->header.type, hidMsg->header.size);
492 PutInputDevice(Device);
495 static void MousevscOnChannelCallback(void *Context)
497 const int packetSize = 0x100;
499 struct hv_device *device = (struct hv_device *)Context;
500 struct mousevsc_dev *inputDevice;
504 unsigned char packet[packetSize];
505 struct vmpacket_descriptor *desc;
506 unsigned char *buffer = packet;
507 int bufferlen = packetSize;
509 inputDevice = MustGetInputDevice(device);
512 pr_err("unable to get input device...device being destroyed?");
517 ret = vmbus_recvpacket_raw(device->channel, buffer, bufferlen, &bytesRecvd, &requestId);
520 if (bytesRecvd > 0) {
521 desc = (struct vmpacket_descriptor *)buffer;
523 switch (desc->type) {
525 MousevscOnSendCompletion(device,
529 case VM_PKT_DATA_INBAND:
530 MousevscOnReceive(device, desc);
534 pr_err("unhandled packet type %d, tid %llx len %d\n",
542 if (bufferlen > packetSize) {
546 bufferlen = packetSize;
550 * pr_debug("nothing else to read...");
553 if (bufferlen > packetSize) {
557 bufferlen = packetSize;
561 } else if (ret == -2) {
562 /* Handle large packet */
563 bufferlen = bytesRecvd;
564 buffer = kzalloc(bytesRecvd, GFP_KERNEL);
566 if (buffer == NULL) {
568 bufferlen = packetSize;
570 /* Try again next time around */
571 pr_err("unable to allocate buffer of size %d!",
578 PutInputDevice(device);
583 static int MousevscConnectToVsp(struct hv_device *Device)
586 struct mousevsc_dev *inputDevice;
587 struct mousevsc_prt_msg *request;
588 struct mousevsc_prt_msg *response;
590 inputDevice = GetInputDevice(Device);
593 pr_err("unable to get input device...device being destroyed?");
597 init_waitqueue_head(&inputDevice->ProtocolWaitEvent);
598 init_waitqueue_head(&inputDevice->DeviceInfoWaitEvent);
600 request = &inputDevice->ProtocolReq;
603 * Now, initiate the vsc/vsp initialization protocol on the open channel
605 memset(request, sizeof(struct mousevsc_prt_msg), 0);
607 request->type = PipeMessageData;
608 request->size = sizeof(struct synthhid_protocol_request);
610 request->request.header.type = SynthHidProtocolRequest;
611 request->request.header.size = sizeof(unsigned long);
612 request->request.version_requested.version = SYNTHHID_INPUT_VERSION;
614 pr_info("synthhid protocol request...");
616 ret = vmbus_sendpacket(Device->channel, request,
617 sizeof(struct pipe_prt_msg) -
618 sizeof(unsigned char) +
619 sizeof(struct synthhid_protocol_request),
620 (unsigned long)request,
622 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
624 pr_err("unable to send synthhid protocol request.");
628 inputDevice->protocol_wait_condition = 0;
629 wait_event_timeout(inputDevice->ProtocolWaitEvent, inputDevice->protocol_wait_condition, msecs_to_jiffies(1000));
630 if (inputDevice->protocol_wait_condition == 0) {
635 response = &inputDevice->ProtocolResp;
637 if (!response->response.approved) {
638 pr_err("synthhid protocol request failed (version %d)",
639 SYNTHHID_INPUT_VERSION);
644 inputDevice->device_wait_condition = 0;
645 wait_event_timeout(inputDevice->DeviceInfoWaitEvent, inputDevice->device_wait_condition, msecs_to_jiffies(1000));
646 if (inputDevice->device_wait_condition == 0) {
652 * We should have gotten the device attr, hid desc and report
655 if (!inputDevice->DeviceInfoStatus)
656 pr_info("**** input channel up and running!! ****");
661 PutInputDevice(Device);
666 static int MousevscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo)
669 struct mousevsc_dev *inputDevice;
670 struct mousevsc_drv_obj *inputDriver;
671 struct hv_input_dev_info dev_info;
673 inputDevice = AllocInputDevice(Device);
680 inputDevice->bInitializeComplete = false;
682 /* Open the channel */
683 ret = vmbus_open(Device->channel,
684 INPUTVSC_SEND_RING_BUFFER_SIZE,
685 INPUTVSC_RECV_RING_BUFFER_SIZE,
688 MousevscOnChannelCallback,
693 pr_err("unable to open channel: %d", ret);
697 pr_info("InputVsc channel open: %d", ret);
699 ret = MousevscConnectToVsp(Device);
702 pr_err("unable to connect channel: %d", ret);
704 vmbus_close(Device->channel);
708 inputDriver = (struct mousevsc_drv_obj *)inputDevice->Device->drv;
710 dev_info.vendor = inputDevice->hid_dev_info.vendor;
711 dev_info.product = inputDevice->hid_dev_info.product;
712 dev_info.version = inputDevice->hid_dev_info.version;
713 strcpy(dev_info.name, "Microsoft Vmbus HID-compliant Mouse");
715 /* Send the device info back up */
716 deviceinfo_callback(Device, &dev_info);
718 /* Send the report desc back up */
719 /* workaround SA-167 */
720 if (inputDevice->ReportDesc[14] == 0x25)
721 inputDevice->ReportDesc[14] = 0x29;
723 reportdesc_callback(Device, inputDevice->ReportDesc,
724 inputDevice->ReportDescSize);
726 inputDevice->bInitializeComplete = true;
732 static int MousevscOnDeviceRemove(struct hv_device *Device)
734 struct mousevsc_dev *inputDevice;
737 pr_info("disabling input device (%p)...",
740 inputDevice = ReleaseInputDevice(Device);
744 * At this point, all outbound traffic should be disable. We only
745 * allow inbound traffic (responses) to proceed
747 * so that outstanding requests can be completed.
749 while (inputDevice->NumOutstandingRequests) {
750 pr_info("waiting for %d requests to complete...", inputDevice->NumOutstandingRequests);
755 pr_info("removing input device (%p)...", Device->ext);
757 inputDevice = FinalReleaseInputDevice(Device);
759 pr_info("input device (%p) safe to remove", inputDevice);
761 /* Close the channel */
762 vmbus_close(Device->channel);
764 FreeInputDevice(inputDevice);
769 static void MousevscOnCleanup(struct hv_driver *drv)
776 struct input_device_context {
777 struct vm_device *device_ctx;
778 struct hid_device *hid_device;
779 struct hv_input_dev_info device_info;
783 struct mousevsc_driver_context {
784 struct driver_context drv_ctx;
785 struct mousevsc_drv_obj drv_obj;
788 static struct mousevsc_driver_context g_mousevsc_drv;
790 static void deviceinfo_callback(struct hv_device *dev, struct hv_input_dev_info *info)
792 struct vm_device *device_ctx = to_vm_device(dev);
793 struct input_device_context *input_device_ctx =
794 dev_get_drvdata(&device_ctx->device);
796 memcpy(&input_device_ctx->device_info, info,
797 sizeof(struct hv_input_dev_info));
799 DPRINT_INFO(INPUTVSC_DRV, "%s", __func__);
802 static void inputreport_callback(struct hv_device *dev, void *packet, u32 len)
806 struct vm_device *device_ctx = to_vm_device(dev);
807 struct input_device_context *input_dev_ctx =
808 dev_get_drvdata(&device_ctx->device);
810 ret = hid_input_report(input_dev_ctx->hid_device,
811 HID_INPUT_REPORT, packet, len, 1);
813 DPRINT_DBG(INPUTVSC_DRV, "hid_input_report (ret %d)", ret);
816 static int mousevsc_hid_open(struct hid_device *hid)
821 static void mousevsc_hid_close(struct hid_device *hid)
825 static int mousevsc_probe(struct device *device)
829 struct driver_context *driver_ctx =
830 driver_to_driver_context(device->driver);
831 struct mousevsc_driver_context *mousevsc_drv_ctx =
832 (struct mousevsc_driver_context *)driver_ctx;
833 struct mousevsc_drv_obj *mousevsc_drv_obj = &mousevsc_drv_ctx->drv_obj;
835 struct vm_device *device_ctx = device_to_vm_device(device);
836 struct hv_device *device_obj = &device_ctx->device_obj;
837 struct input_device_context *input_dev_ctx;
839 input_dev_ctx = kmalloc(sizeof(struct input_device_context),
842 dev_set_drvdata(device, input_dev_ctx);
844 /* Call to the vsc driver to add the device */
845 ret = mousevsc_drv_obj->Base.dev_add(device_obj, NULL);
848 DPRINT_ERR(INPUTVSC_DRV, "unable to add input vsc device");
856 static int mousevsc_remove(struct device *device)
860 struct driver_context *driver_ctx =
861 driver_to_driver_context(device->driver);
862 struct mousevsc_driver_context *mousevsc_drv_ctx =
863 (struct mousevsc_driver_context *)driver_ctx;
864 struct mousevsc_drv_obj *mousevsc_drv_obj = &mousevsc_drv_ctx->drv_obj;
866 struct vm_device *device_ctx = device_to_vm_device(device);
867 struct hv_device *device_obj = &device_ctx->device_obj;
868 struct input_device_context *input_dev_ctx;
870 input_dev_ctx = kmalloc(sizeof(struct input_device_context),
873 dev_set_drvdata(device, input_dev_ctx);
875 if (input_dev_ctx->connected) {
876 hidinput_disconnect(input_dev_ctx->hid_device);
877 input_dev_ctx->connected = 0;
880 if (!mousevsc_drv_obj->Base.dev_rm)
884 * Call to the vsc driver to let it know that the device
887 ret = mousevsc_drv_obj->Base.dev_rm(device_obj);
890 DPRINT_ERR(INPUTVSC_DRV,
891 "unable to remove vsc device (ret %d)", ret);
894 kfree(input_dev_ctx);
899 static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len)
901 struct vm_device *device_ctx = to_vm_device(dev);
902 struct input_device_context *input_device_ctx =
903 dev_get_drvdata(&device_ctx->device);
904 struct hid_device *hid_dev;
906 /* hid_debug = -1; */
907 hid_dev = kmalloc(sizeof(struct hid_device), GFP_KERNEL);
909 if (hid_parse_report(hid_dev, packet, len)) {
910 DPRINT_INFO(INPUTVSC_DRV, "Unable to call hd_parse_report");
915 DPRINT_INFO(INPUTVSC_DRV, "hid_device created");
917 hid_dev->ll_driver->open = mousevsc_hid_open;
918 hid_dev->ll_driver->close = mousevsc_hid_close;
920 hid_dev->bus = BUS_VIRTUAL;
921 hid_dev->vendor = input_device_ctx->device_info.vendor;
922 hid_dev->product = input_device_ctx->device_info.product;
923 hid_dev->version = input_device_ctx->device_info.version;
924 hid_dev->dev = device_ctx->device;
926 sprintf(hid_dev->name, "%s",
927 input_device_ctx->device_info.name);
930 * HJ Do we want to call it with a 0
932 if (!hidinput_connect(hid_dev, 0)) {
933 hid_dev->claimed |= HID_CLAIMED_INPUT;
935 input_device_ctx->connected = 1;
937 DPRINT_INFO(INPUTVSC_DRV,
938 "HID device claimed by input\n");
941 if (!hid_dev->claimed) {
942 DPRINT_ERR(INPUTVSC_DRV,
943 "HID device not claimed by "
944 "input or hiddev\n");
947 input_device_ctx->hid_device = hid_dev;
953 static int mousevsc_drv_exit_cb(struct device *dev, void *data)
955 struct device **curr = (struct device **)data;
961 static void mousevsc_drv_exit(void)
963 struct mousevsc_drv_obj *mousevsc_drv_obj = &g_mousevsc_drv.drv_obj;
964 struct driver_context *drv_ctx = &g_mousevsc_drv.drv_ctx;
967 struct device *current_dev = NULL;
973 ret = driver_for_each_device(&drv_ctx->driver, NULL,
974 (void *)¤t_dev,
975 mousevsc_drv_exit_cb);
977 printk(KERN_ERR "Can't find mouse device!\n");
979 if (current_dev == NULL)
982 /* Initiate removal from the top-down */
983 device_unregister(current_dev);
986 if (mousevsc_drv_obj->Base.cleanup)
987 mousevsc_drv_obj->Base.cleanup(&mousevsc_drv_obj->Base);
989 vmbus_child_driver_unregister(drv_ctx);
994 static int mouse_vsc_initialize(struct hv_driver *Driver)
996 struct mousevsc_drv_obj *inputDriver =
997 (struct mousevsc_drv_obj *)Driver;
1000 Driver->name = driver_name;
1001 memcpy(&Driver->dev_type, &mouse_guid,
1002 sizeof(struct hv_guid));
1004 /* Setup the dispatch table */
1005 inputDriver->Base.dev_add = MousevscOnDeviceAdd;
1006 inputDriver->Base.dev_rm = MousevscOnDeviceRemove;
1007 inputDriver->Base.cleanup = MousevscOnCleanup;
1013 static int __init mousevsc_init(void)
1015 struct mousevsc_drv_obj *input_drv_obj = &g_mousevsc_drv.drv_obj;
1016 struct driver_context *drv_ctx = &g_mousevsc_drv.drv_ctx;
1018 DPRINT_INFO(INPUTVSC_DRV, "Hyper-V Mouse driver initializing.");
1020 /* Callback to client driver to complete the initialization */
1021 mouse_vsc_initialize(&input_drv_obj->Base);
1023 drv_ctx->driver.name = input_drv_obj->Base.name;
1024 memcpy(&drv_ctx->class_id, &input_drv_obj->Base.dev_type,
1025 sizeof(struct hv_guid));
1027 drv_ctx->probe = mousevsc_probe;
1028 drv_ctx->remove = mousevsc_remove;
1030 /* The driver belongs to vmbus */
1031 vmbus_child_driver_register(drv_ctx);
1036 static void __exit mousevsc_exit(void)
1038 mousevsc_drv_exit();
1042 * We don't want to automatically load this driver just yet, it's quite
1043 * broken. It's safe if you want to load it yourself manually, but
1044 * don't inflict it on unsuspecting users, that's just mean.
1049 * We use a PCI table to determine if we should autoload this driver This is
1050 * needed by distro tools to determine if the hyperv drivers should be
1051 * installed and/or configured. We don't do anything else with the table, but
1052 * it needs to be present.
1054 const static struct pci_device_id microsoft_hv_pci_table[] = {
1055 { PCI_DEVICE(0x1414, 0x5353) }, /* VGA compatible controller */
1058 MODULE_DEVICE_TABLE(pci, microsoft_hv_pci_table);
1061 MODULE_LICENSE("GPL");
1062 MODULE_VERSION(HV_DRV_VERSION);
1063 module_init(mousevsc_init);
1064 module_exit(mousevsc_exit);