16 #include <linux/module.h>
17 #include <linux/device.h>
19 #include <linux/input.h>
20 #include <linux/hid.h>
21 #include <linux/hiddev.h>
34 #define SYNTHHID_MAX_INPUT_REPORT_SIZE 16
43 #define SYNTHHID_INPUT_VERSION_MAJOR 2
44 #define SYNTHHID_INPUT_VERSION_MINOR 0
45 #define SYNTHHID_INPUT_VERSION (SYNTHHID_INPUT_VERSION_MINOR | \
46 (SYNTHHID_INPUT_VERSION_MAJOR << 16))
115 #define INPUTVSC_SEND_RING_BUFFER_SIZE (10*PAGE_SIZE)
116 #define INPUTVSC_RECV_RING_BUFFER_SIZE (10*PAGE_SIZE)
173 hv_set_drvdata(device, input_dev);
188 static void mousevsc_on_receive_device_info(
struct mousevsc_dev *input_device,
224 ((
unsigned char *)desc) + desc->
bLength,
225 desc->
desc[0].wDescriptorLength);
234 ack.ack.header.size = 1;
235 ack.ack.reserved = 0;
243 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
254 static void mousevsc_on_receive(
struct hv_device *
device,
255 struct vmpacket_descriptor *
packet)
259 struct mousevsc_dev *input_dev = hv_get_drvdata(device);
262 pipe_msg = (
struct pipe_prt_msg *)((
unsigned long)packet +
263 (packet->offset8 << 3));
270 switch (hid_msg->
header.type) {
278 -
sizeof(
unsigned char))
286 sizeof(
unsigned char));
297 mousevsc_on_receive_device_info(input_dev,
307 input_report->
header.size, 1);
310 pr_err(
"unsupported hid msg type - type %d len %d",
317 static void mousevsc_on_channel_callback(
void *
context)
319 const int packet_size = 0x100;
321 struct hv_device *device =
context;
324 struct vmpacket_descriptor *desc;
326 int bufferlen = packet_size;
334 bufferlen, &bytes_recvd, &req_id);
338 if (bytes_recvd <= 0) {
342 desc = (
struct vmpacket_descriptor *)buffer;
344 switch (desc->type) {
348 case VM_PKT_DATA_INBAND:
349 mousevsc_on_receive(device, desc);
353 pr_err(
"unhandled packet type %d, tid %llx len %d\n",
354 desc->type, req_id, bytes_recvd);
363 bufferlen = bytes_recvd;
375 static int mousevsc_connect_to_vsp(
struct hv_device *device)
379 struct mousevsc_dev *input_dev = hv_get_drvdata(device);
389 request->
request.header.size =
sizeof(
unsigned int);
394 sizeof(
unsigned char) +
396 (
unsigned long)request,
398 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
411 pr_err(
"synthhid protocol request failed (version %d)\n",
433 static int mousevsc_hid_parse(
struct hid_device *hid)
435 struct hv_device *
dev = hid_get_drvdata(hid);
442 static int mousevsc_hid_open(
struct hid_device *hid)
447 static int mousevsc_hid_start(
struct hid_device *hid)
452 static void mousevsc_hid_close(
struct hid_device *hid)
456 static void mousevsc_hid_stop(
struct hid_device *hid)
461 .parse = mousevsc_hid_parse,
462 .open = mousevsc_hid_open,
463 .close = mousevsc_hid_close,
464 .start = mousevsc_hid_start,
465 .stop = mousevsc_hid_stop,
470 static int mousevsc_probe(
struct hv_device *device,
477 input_dev = mousevsc_alloc_device(device);
487 mousevsc_on_channel_callback,
494 ret = mousevsc_connect_to_vsp(device);
504 if (IS_ERR(hid_dev)) {
505 ret = PTR_ERR(hid_dev);
509 hid_dev->
ll_driver = &mousevsc_ll_driver;
510 hid_dev->
driver = &mousevsc_hid_driver;
517 sprintf(hid_dev->
name,
"%s",
"Microsoft Vmbus HID-compliant Mouse");
519 hid_set_drvdata(hid_dev, device);
526 ret = hid_parse(hid_dev);
528 hid_err(hid_dev,
"parse failed\n");
535 hid_err(hid_dev,
"hw start failed\n");
551 mousevsc_free_device(input_dev);
557 static int mousevsc_remove(
struct hv_device *
dev)
564 mousevsc_free_device(input_dev);
571 { VMBUS_DEVICE(0x9E, 0xB6, 0xA8, 0xCF, 0x4A, 0x5B, 0xc0, 0x4c,
572 0xB9, 0x8B, 0x8B, 0xA1, 0xA1, 0xF3, 0xF9, 0x5A) },
578 static struct hv_driver mousevsc_drv = {
579 .name = KBUILD_MODNAME,
580 .id_table = id_table,
581 .probe = mousevsc_probe,
582 .remove = mousevsc_remove,
585 static int __init mousevsc_init(
void)
587 return vmbus_driver_register(&mousevsc_drv);
590 static void __exit mousevsc_exit(
void)