2011-02-27 16:43:10 +01:00
|
|
|
/*
|
2011-03-03 02:49:30 +01:00
|
|
|
* Copyright (c) 2009, Citrix Systems, Inc.
|
|
|
|
* Copyright (c) 2010, Microsoft Corporation.
|
|
|
|
* Copyright (c) 2011, Novell Inc.
|
2011-02-27 16:43:10 +01:00
|
|
|
*
|
2011-03-03 02:49:30 +01:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
2011-02-27 16:43:10 +01:00
|
|
|
*
|
2011-03-03 02:49:30 +01:00
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
2011-02-27 16:43:10 +01:00
|
|
|
*/
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
2011-04-01 18:50:54 +02:00
|
|
|
#include <linux/delay.h>
|
2011-02-27 16:43:10 +01:00
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/workqueue.h>
|
2011-03-03 02:42:50 +01:00
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/wait.h>
|
2011-02-27 16:43:10 +01:00
|
|
|
#include <linux/input.h>
|
|
|
|
#include <linux/hid.h>
|
|
|
|
#include <linux/hiddev.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/dmi.h>
|
2011-04-06 08:35:12 +02:00
|
|
|
#include <linux/delay.h>
|
2011-02-27 16:43:10 +01:00
|
|
|
|
|
|
|
#include "hv_api.h"
|
|
|
|
#include "logging.h"
|
|
|
|
#include "version_info.h"
|
|
|
|
#include "vmbus.h"
|
2011-03-03 02:42:50 +01:00
|
|
|
#include "vmbus_api.h"
|
|
|
|
#include "channel.h"
|
|
|
|
#include "vmbus_packet_format.h"
|
2011-03-03 02:53:58 +01:00
|
|
|
|
|
|
|
|
2011-03-03 02:57:51 +01:00
|
|
|
/*
|
|
|
|
* Data types
|
|
|
|
*/
|
2011-03-03 03:57:04 +01:00
|
|
|
struct hv_input_dev_info {
|
|
|
|
unsigned short vendor;
|
|
|
|
unsigned short product;
|
|
|
|
unsigned short version;
|
|
|
|
char name[128];
|
2011-03-03 02:57:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Represents the input vsc driver */
|
2011-03-03 03:38:31 +01:00
|
|
|
/* FIXME - can be removed entirely */
|
2011-03-03 02:57:51 +01:00
|
|
|
struct mousevsc_drv_obj {
|
2011-04-01 23:32:12 +02:00
|
|
|
struct hv_driver base;
|
2011-03-03 02:57:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-04-26 18:20:20 +02:00
|
|
|
static inline
|
|
|
|
struct mousevsc_drv_obj *drv_to_mousedrv(struct device_driver *d)
|
|
|
|
{
|
|
|
|
struct hv_driver *hvdrv = drv_to_hv_drv(d);
|
|
|
|
return container_of(hvdrv, struct mousevsc_drv_obj, base);
|
|
|
|
}
|
|
|
|
|
2011-03-03 02:53:58 +01:00
|
|
|
/* The maximum size of a synthetic input message. */
|
|
|
|
#define SYNTHHID_MAX_INPUT_REPORT_SIZE 16
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Current version
|
|
|
|
*
|
|
|
|
* History:
|
|
|
|
* Beta, RC < 2008/1/22 1,0
|
|
|
|
* RC > 2008/1/22 2,0
|
|
|
|
*/
|
2011-03-03 04:18:34 +01:00
|
|
|
#define SYNTHHID_INPUT_VERSION_MAJOR 2
|
|
|
|
#define SYNTHHID_INPUT_VERSION_MINOR 0
|
|
|
|
#define SYNTHHID_INPUT_VERSION (SYNTHHID_INPUT_VERSION_MINOR | \
|
|
|
|
(SYNTHHID_INPUT_VERSION_MAJOR << 16))
|
2011-03-03 02:53:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
#pragma pack(push,1)
|
|
|
|
/*
|
|
|
|
* Message types in the synthetic input protocol
|
|
|
|
*/
|
|
|
|
enum synthhid_msg_type {
|
|
|
|
SynthHidProtocolRequest,
|
|
|
|
SynthHidProtocolResponse,
|
|
|
|
SynthHidInitialDeviceInfo,
|
|
|
|
SynthHidInitialDeviceInfoAck,
|
|
|
|
SynthHidInputReport,
|
|
|
|
SynthHidMax
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Basic message structures.
|
|
|
|
*/
|
2011-03-03 03:21:01 +01:00
|
|
|
struct synthhid_msg_hdr {
|
2011-03-03 04:01:49 +01:00
|
|
|
enum synthhid_msg_type type;
|
|
|
|
u32 size;
|
2011-03-03 03:21:01 +01:00
|
|
|
};
|
2011-03-03 02:53:58 +01:00
|
|
|
|
2011-03-03 03:21:01 +01:00
|
|
|
struct synthhid_msg {
|
2011-03-03 04:04:09 +01:00
|
|
|
struct synthhid_msg_hdr header;
|
2011-03-03 04:11:49 +01:00
|
|
|
char data[1]; /* Enclosed message */
|
2011-03-03 03:21:01 +01:00
|
|
|
};
|
2011-03-03 02:53:58 +01:00
|
|
|
|
2011-03-03 03:21:01 +01:00
|
|
|
union synthhid_version {
|
2011-03-03 02:53:58 +01:00
|
|
|
struct {
|
2011-03-03 04:18:34 +01:00
|
|
|
u16 minor_version;
|
|
|
|
u16 major_version;
|
2011-03-03 02:53:58 +01:00
|
|
|
};
|
2011-03-03 04:18:34 +01:00
|
|
|
u32 version;
|
2011-03-03 03:21:01 +01:00
|
|
|
};
|
2011-03-03 02:53:58 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Protocol messages
|
|
|
|
*/
|
2011-03-03 03:21:01 +01:00
|
|
|
struct synthhid_protocol_request {
|
2011-03-03 04:04:09 +01:00
|
|
|
struct synthhid_msg_hdr header;
|
2011-03-03 04:18:34 +01:00
|
|
|
union synthhid_version version_requested;
|
2011-03-03 03:21:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct synthhid_protocol_response {
|
2011-03-03 04:04:09 +01:00
|
|
|
struct synthhid_msg_hdr header;
|
2011-03-03 04:18:34 +01:00
|
|
|
union synthhid_version version_requested;
|
2011-03-03 04:19:58 +01:00
|
|
|
unsigned char approved;
|
2011-03-03 03:21:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct synthhid_device_info {
|
2011-03-03 04:04:09 +01:00
|
|
|
struct synthhid_msg_hdr header;
|
2011-03-03 04:24:05 +01:00
|
|
|
struct hv_input_dev_info hid_dev_info;
|
2011-03-03 04:27:17 +01:00
|
|
|
struct hid_descriptor hid_descriptor;
|
2011-03-03 03:21:01 +01:00
|
|
|
};
|
2011-03-03 02:53:58 +01:00
|
|
|
|
2011-03-03 03:21:01 +01:00
|
|
|
struct synthhid_device_info_ack {
|
2011-03-03 04:04:09 +01:00
|
|
|
struct synthhid_msg_hdr header;
|
2011-03-03 04:29:42 +01:00
|
|
|
unsigned char reserved;
|
2011-03-03 03:21:01 +01:00
|
|
|
};
|
2011-03-03 02:53:58 +01:00
|
|
|
|
2011-03-03 03:21:01 +01:00
|
|
|
struct synthhid_input_report {
|
2011-03-03 04:04:09 +01:00
|
|
|
struct synthhid_msg_hdr header;
|
2011-03-03 04:31:39 +01:00
|
|
|
char buffer[1];
|
2011-03-03 03:21:01 +01:00
|
|
|
};
|
2011-03-03 02:53:58 +01:00
|
|
|
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
2011-03-03 02:57:51 +01:00
|
|
|
#define INPUTVSC_SEND_RING_BUFFER_SIZE 10*PAGE_SIZE
|
|
|
|
#define INPUTVSC_RECV_RING_BUFFER_SIZE 10*PAGE_SIZE
|
2011-02-27 16:43:10 +01:00
|
|
|
|
|
|
|
#define NBITS(x) (((x)/BITS_PER_LONG)+1)
|
|
|
|
|
2011-03-03 02:42:50 +01:00
|
|
|
enum pipe_prot_msg_type {
|
|
|
|
PipeMessageInvalid = 0,
|
|
|
|
PipeMessageData,
|
|
|
|
PipeMessageMaximum
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct pipe_prt_msg {
|
2011-03-03 04:36:15 +01:00
|
|
|
enum pipe_prot_msg_type type;
|
2011-03-03 04:38:29 +01:00
|
|
|
u32 size;
|
2011-03-03 04:39:48 +01:00
|
|
|
char data[1];
|
2011-03-03 02:42:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Data types
|
|
|
|
*/
|
|
|
|
struct mousevsc_prt_msg {
|
2011-03-03 04:36:15 +01:00
|
|
|
enum pipe_prot_msg_type type;
|
2011-03-03 04:38:29 +01:00
|
|
|
u32 size;
|
2011-03-03 02:42:50 +01:00
|
|
|
union {
|
2011-03-03 04:41:00 +01:00
|
|
|
struct synthhid_protocol_request request;
|
|
|
|
struct synthhid_protocol_response response;
|
|
|
|
struct synthhid_device_info_ack ack;
|
2011-03-03 04:33:17 +01:00
|
|
|
};
|
2011-03-03 02:42:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Represents an mousevsc device
|
|
|
|
*/
|
|
|
|
struct mousevsc_dev {
|
2011-04-01 23:32:13 +02:00
|
|
|
struct hv_device *device;
|
2011-03-03 02:42:50 +01:00
|
|
|
/* 0 indicates the device is being destroyed */
|
2011-04-01 23:32:13 +02:00
|
|
|
atomic_t ref_count;
|
|
|
|
int num_outstanding_req;
|
|
|
|
unsigned char init_complete;
|
|
|
|
struct mousevsc_prt_msg protocol_req;
|
|
|
|
struct mousevsc_prt_msg protocol_resp;
|
2011-03-03 02:42:50 +01:00
|
|
|
/* Synchronize the request/response if needed */
|
2011-04-01 23:32:13 +02:00
|
|
|
wait_queue_head_t protocol_wait_event;
|
|
|
|
wait_queue_head_t dev_info_wait_event;
|
2011-03-03 02:42:50 +01:00
|
|
|
int protocol_wait_condition;
|
|
|
|
int device_wait_condition;
|
2011-04-01 23:32:13 +02:00
|
|
|
int dev_info_status;
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:13 +02:00
|
|
|
struct hid_descriptor *hid_desc;
|
|
|
|
unsigned char *report_desc;
|
|
|
|
u32 report_desc_size;
|
2011-03-03 04:24:05 +01:00
|
|
|
struct hv_input_dev_info hid_dev_info;
|
2011-03-03 02:42:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-03-03 04:42:19 +01:00
|
|
|
static const char *driver_name = "mousevsc";
|
2011-03-03 02:42:50 +01:00
|
|
|
|
|
|
|
/* {CFA8B69E-5B4A-4cc0-B98B-8BA1A1F3F95A} */
|
2011-03-03 04:44:13 +01:00
|
|
|
static const struct hv_guid mouse_guid = {
|
2011-03-03 02:42:50 +01:00
|
|
|
.data = {0x9E, 0xB6, 0xA8, 0xCF, 0x4A, 0x5B, 0xc0, 0x4c,
|
|
|
|
0xB9, 0x8B, 0x8B, 0xA1, 0xA1, 0xF3, 0xF9, 0x5A}
|
|
|
|
};
|
|
|
|
|
2011-03-03 03:57:04 +01:00
|
|
|
static void deviceinfo_callback(struct hv_device *dev, struct hv_input_dev_info *info);
|
2011-03-03 03:38:31 +01:00
|
|
|
static void inputreport_callback(struct hv_device *dev, void *packet, u32 len);
|
|
|
|
static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len);
|
|
|
|
|
2011-04-01 23:32:11 +02:00
|
|
|
static struct mousevsc_dev *alloc_input_device(struct hv_device *device)
|
2011-03-03 02:42:50 +01:00
|
|
|
{
|
2011-04-01 23:32:14 +02:00
|
|
|
struct mousevsc_dev *input_dev;
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
input_dev = kzalloc(sizeof(struct mousevsc_dev), GFP_KERNEL);
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
if (!input_dev)
|
2011-03-03 02:42:50 +01:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set to 2 to allow both inbound and outbound traffics
|
2011-04-01 23:32:10 +02:00
|
|
|
* (ie get_input_device() and must_get_input_device()) to proceed.
|
2011-03-03 02:42:50 +01:00
|
|
|
*/
|
2011-04-01 23:32:14 +02:00
|
|
|
atomic_cmpxchg(&input_dev->ref_count, 0, 2);
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
input_dev->device = device;
|
|
|
|
device->ext = input_dev;
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
return input_dev;
|
2011-03-03 02:42:50 +01:00
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:11 +02:00
|
|
|
static void free_input_device(struct mousevsc_dev *device)
|
2011-03-03 02:42:50 +01:00
|
|
|
{
|
2011-04-01 23:32:13 +02:00
|
|
|
WARN_ON(atomic_read(&device->ref_count) == 0);
|
2011-04-01 23:32:11 +02:00
|
|
|
kfree(device);
|
2011-03-03 02:42:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the inputdevice object if exists and its refcount > 1
|
|
|
|
*/
|
2011-04-01 23:32:11 +02:00
|
|
|
static struct mousevsc_dev *get_input_device(struct hv_device *device)
|
2011-03-03 02:42:50 +01:00
|
|
|
{
|
2011-04-01 23:32:14 +02:00
|
|
|
struct mousevsc_dev *input_dev;
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
input_dev = (struct mousevsc_dev *)device->ext;
|
2011-03-03 02:42:50 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME
|
|
|
|
* This sure isn't a valid thing to print for debugging, no matter
|
|
|
|
* what the intention is...
|
|
|
|
*
|
|
|
|
* printk(KERN_ERR "-------------------------> REFCOUNT = %d",
|
2011-04-01 23:32:14 +02:00
|
|
|
* input_dev->ref_count);
|
2011-03-03 02:42:50 +01:00
|
|
|
*/
|
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
if (input_dev && atomic_read(&input_dev->ref_count) > 1)
|
|
|
|
atomic_inc(&input_dev->ref_count);
|
2011-03-03 02:42:50 +01:00
|
|
|
else
|
2011-04-01 23:32:14 +02:00
|
|
|
input_dev = NULL;
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
return input_dev;
|
2011-03-03 02:42:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the inputdevice object iff exists and its refcount > 0
|
|
|
|
*/
|
2011-04-01 23:32:11 +02:00
|
|
|
static struct mousevsc_dev *must_get_input_device(struct hv_device *device)
|
2011-03-03 02:42:50 +01:00
|
|
|
{
|
2011-04-01 23:32:14 +02:00
|
|
|
struct mousevsc_dev *input_dev;
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
input_dev = (struct mousevsc_dev *)device->ext;
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
if (input_dev && atomic_read(&input_dev->ref_count))
|
|
|
|
atomic_inc(&input_dev->ref_count);
|
2011-03-03 02:42:50 +01:00
|
|
|
else
|
2011-04-01 23:32:14 +02:00
|
|
|
input_dev = NULL;
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
return input_dev;
|
2011-03-03 02:42:50 +01:00
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:11 +02:00
|
|
|
static void put_input_device(struct hv_device *device)
|
2011-03-03 02:42:50 +01:00
|
|
|
{
|
2011-04-01 23:32:14 +02:00
|
|
|
struct mousevsc_dev *input_dev;
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
input_dev = (struct mousevsc_dev *)device->ext;
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
atomic_dec(&input_dev->ref_count);
|
2011-03-03 02:42:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-04-01 23:32:10 +02:00
|
|
|
* Drop ref count to 1 to effectively disable get_input_device()
|
2011-03-03 02:42:50 +01:00
|
|
|
*/
|
2011-04-01 23:32:11 +02:00
|
|
|
static struct mousevsc_dev *release_input_device(struct hv_device *device)
|
2011-03-03 02:42:50 +01:00
|
|
|
{
|
2011-04-01 23:32:14 +02:00
|
|
|
struct mousevsc_dev *input_dev;
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
input_dev = (struct mousevsc_dev *)device->ext;
|
2011-03-03 02:42:50 +01:00
|
|
|
|
|
|
|
/* Busy wait until the ref drop to 2, then set it to 1 */
|
2011-04-01 23:32:14 +02:00
|
|
|
while (atomic_cmpxchg(&input_dev->ref_count, 2, 1) != 2)
|
2011-03-03 02:42:50 +01:00
|
|
|
udelay(100);
|
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
return input_dev;
|
2011-03-03 02:42:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-04-01 23:32:11 +02:00
|
|
|
* Drop ref count to 0. No one can use input_device object.
|
2011-03-03 02:42:50 +01:00
|
|
|
*/
|
2011-04-01 23:32:11 +02:00
|
|
|
static struct mousevsc_dev *final_release_input_device(struct hv_device *device)
|
2011-03-03 02:42:50 +01:00
|
|
|
{
|
2011-04-01 23:32:14 +02:00
|
|
|
struct mousevsc_dev *input_dev;
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
input_dev = (struct mousevsc_dev *)device->ext;
|
2011-03-03 02:42:50 +01:00
|
|
|
|
|
|
|
/* Busy wait until the ref drop to 1, then set it to 0 */
|
2011-04-01 23:32:14 +02:00
|
|
|
while (atomic_cmpxchg(&input_dev->ref_count, 1, 0) != 1)
|
2011-03-03 02:42:50 +01:00
|
|
|
udelay(100);
|
|
|
|
|
2011-04-01 23:32:11 +02:00
|
|
|
device->ext = NULL;
|
2011-04-01 23:32:14 +02:00
|
|
|
return input_dev;
|
2011-03-03 02:42:50 +01:00
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:11 +02:00
|
|
|
static void mousevsc_on_send_completion(struct hv_device *device,
|
|
|
|
struct vmpacket_descriptor *packet)
|
2011-03-03 02:42:50 +01:00
|
|
|
{
|
2011-04-01 23:32:14 +02:00
|
|
|
struct mousevsc_dev *input_dev;
|
2011-03-03 02:42:50 +01:00
|
|
|
void *request;
|
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
input_dev = must_get_input_device(device);
|
|
|
|
if (!input_dev) {
|
2011-03-03 02:42:50 +01:00
|
|
|
pr_err("unable to get input device...device being destroyed?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:11 +02:00
|
|
|
request = (void *)(unsigned long)packet->trans_id;
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
if (request == &input_dev->protocol_req) {
|
2011-03-03 02:42:50 +01:00
|
|
|
/* FIXME */
|
|
|
|
/* Shouldn't we be doing something here? */
|
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:11 +02:00
|
|
|
put_input_device(device);
|
2011-03-03 02:42:50 +01:00
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:11 +02:00
|
|
|
static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
|
|
|
|
struct synthhid_device_info *device_info)
|
2011-03-03 02:42:50 +01:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct hid_descriptor *desc;
|
|
|
|
struct mousevsc_prt_msg ack;
|
|
|
|
|
|
|
|
/* Assume success for now */
|
2011-04-01 23:32:13 +02:00
|
|
|
input_device->dev_info_status = 0;
|
2011-03-03 02:42:50 +01:00
|
|
|
|
|
|
|
/* Save the device attr */
|
2011-04-01 23:32:11 +02:00
|
|
|
memcpy(&input_device->hid_dev_info, &device_info->hid_dev_info,
|
|
|
|
sizeof(struct hv_input_dev_info));
|
2011-03-03 02:42:50 +01:00
|
|
|
|
|
|
|
/* Save the hid desc */
|
2011-04-01 23:32:11 +02:00
|
|
|
desc = &device_info->hid_descriptor;
|
2011-03-03 02:42:50 +01:00
|
|
|
WARN_ON(desc->bLength > 0);
|
|
|
|
|
2011-04-01 23:32:13 +02:00
|
|
|
input_device->hid_desc = kzalloc(desc->bLength, GFP_KERNEL);
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:13 +02:00
|
|
|
if (!input_device->hid_desc) {
|
2011-03-03 02:42:50 +01:00
|
|
|
pr_err("unable to allocate hid descriptor - size %d", desc->bLength);
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:13 +02:00
|
|
|
memcpy(input_device->hid_desc, desc, desc->bLength);
|
2011-03-03 02:42:50 +01:00
|
|
|
|
|
|
|
/* Save the report desc */
|
2011-04-01 23:32:13 +02:00
|
|
|
input_device->report_desc_size = desc->desc[0].wDescriptorLength;
|
|
|
|
input_device->report_desc = kzalloc(input_device->report_desc_size,
|
2011-03-03 02:42:50 +01:00
|
|
|
GFP_KERNEL);
|
|
|
|
|
2011-04-01 23:32:13 +02:00
|
|
|
if (!input_device->report_desc) {
|
2011-03-03 02:42:50 +01:00
|
|
|
pr_err("unable to allocate report descriptor - size %d",
|
2011-04-01 23:32:13 +02:00
|
|
|
input_device->report_desc_size);
|
2011-03-03 02:42:50 +01:00
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:13 +02:00
|
|
|
memcpy(input_device->report_desc,
|
2011-03-03 02:42:50 +01:00
|
|
|
((unsigned char *)desc) + desc->bLength,
|
|
|
|
desc->desc[0].wDescriptorLength);
|
|
|
|
|
|
|
|
/* Send the ack */
|
2011-03-17 02:40:59 +01:00
|
|
|
memset(&ack, 0, sizeof(struct mousevsc_prt_msg));
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-03-03 04:36:15 +01:00
|
|
|
ack.type = PipeMessageData;
|
2011-03-03 04:38:29 +01:00
|
|
|
ack.size = sizeof(struct synthhid_device_info_ack);
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-03-03 04:41:00 +01:00
|
|
|
ack.ack.header.type = SynthHidInitialDeviceInfoAck;
|
|
|
|
ack.ack.header.size = 1;
|
|
|
|
ack.ack.reserved = 0;
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:13 +02:00
|
|
|
ret = vmbus_sendpacket(input_device->device->channel,
|
2011-03-03 02:42:50 +01:00
|
|
|
&ack,
|
2011-03-03 03:21:01 +01:00
|
|
|
sizeof(struct pipe_prt_msg) - sizeof(unsigned char) +
|
|
|
|
sizeof(struct synthhid_device_info_ack),
|
2011-03-03 02:42:50 +01:00
|
|
|
(unsigned long)&ack,
|
|
|
|
VM_PKT_DATA_INBAND,
|
|
|
|
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
|
|
|
|
if (ret != 0) {
|
2011-03-03 03:21:01 +01:00
|
|
|
pr_err("unable to send synthhid device info ack - ret %d",
|
2011-03-03 02:42:50 +01:00
|
|
|
ret);
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:11 +02:00
|
|
|
input_device->device_wait_condition = 1;
|
2011-04-01 23:32:13 +02:00
|
|
|
wake_up(&input_device->dev_info_wait_event);
|
2011-03-03 02:42:50 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
Cleanup:
|
2011-04-01 23:32:13 +02:00
|
|
|
kfree(input_device->hid_desc);
|
|
|
|
input_device->hid_desc = NULL;
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:13 +02:00
|
|
|
kfree(input_device->report_desc);
|
|
|
|
input_device->report_desc = NULL;
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:13 +02:00
|
|
|
input_device->dev_info_status = -1;
|
2011-04-01 23:32:11 +02:00
|
|
|
input_device->device_wait_condition = 1;
|
2011-04-01 23:32:13 +02:00
|
|
|
wake_up(&input_device->dev_info_wait_event);
|
2011-03-03 02:42:50 +01:00
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:11 +02:00
|
|
|
static void mousevsc_on_receive_input_report(struct mousevsc_dev *input_device,
|
|
|
|
struct synthhid_input_report *input_report)
|
2011-03-03 02:42:50 +01:00
|
|
|
{
|
2011-04-01 23:32:14 +02:00
|
|
|
struct mousevsc_drv_obj *input_drv;
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:13 +02:00
|
|
|
if (!input_device->init_complete) {
|
2011-04-01 23:32:11 +02:00
|
|
|
pr_info("Initialization incomplete...ignoring input_report msg");
|
2011-03-03 02:42:50 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-26 18:20:20 +02:00
|
|
|
input_drv = drv_to_mousedrv(input_device->device->device.driver);
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:13 +02:00
|
|
|
inputreport_callback(input_device->device,
|
2011-04-01 23:32:11 +02:00
|
|
|
input_report->buffer,
|
|
|
|
input_report->header.size);
|
2011-03-03 02:42:50 +01:00
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:11 +02:00
|
|
|
static void mousevsc_on_receive(struct hv_device *device,
|
|
|
|
struct vmpacket_descriptor *packet)
|
2011-03-03 02:42:50 +01:00
|
|
|
{
|
2011-04-01 23:32:14 +02:00
|
|
|
struct pipe_prt_msg *pipe_msg;
|
|
|
|
struct synthhid_msg *hid_msg;
|
|
|
|
struct mousevsc_dev *input_dev;
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
input_dev = must_get_input_device(device);
|
|
|
|
if (!input_dev) {
|
2011-03-03 02:42:50 +01:00
|
|
|
pr_err("unable to get input device...device being destroyed?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
pipe_msg = (struct pipe_prt_msg *)((unsigned long)packet +
|
2011-04-01 23:32:11 +02:00
|
|
|
(packet->offset8 << 3));
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
if (pipe_msg->type != PipeMessageData) {
|
2011-03-03 02:42:50 +01:00
|
|
|
pr_err("unknown pipe msg type - type %d len %d",
|
2011-04-01 23:32:14 +02:00
|
|
|
pipe_msg->type, pipe_msg->size);
|
2011-04-01 23:32:11 +02:00
|
|
|
put_input_device(device);
|
2011-03-03 02:42:50 +01:00
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
hid_msg = (struct synthhid_msg *)&pipe_msg->data[0];
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
switch (hid_msg->header.type) {
|
2011-03-03 02:42:50 +01:00
|
|
|
case SynthHidProtocolResponse:
|
2011-04-01 23:32:14 +02:00
|
|
|
memcpy(&input_dev->protocol_resp, pipe_msg,
|
|
|
|
pipe_msg->size + sizeof(struct pipe_prt_msg) -
|
2011-03-03 04:38:29 +01:00
|
|
|
sizeof(unsigned char));
|
2011-04-01 23:32:14 +02:00
|
|
|
input_dev->protocol_wait_condition = 1;
|
|
|
|
wake_up(&input_dev->protocol_wait_event);
|
2011-03-03 02:42:50 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SynthHidInitialDeviceInfo:
|
2011-04-01 23:32:14 +02:00
|
|
|
WARN_ON(pipe_msg->size >= sizeof(struct hv_input_dev_info));
|
2011-03-03 02:42:50 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse out the device info into device attr,
|
|
|
|
* hid desc and report desc
|
|
|
|
*/
|
2011-04-01 23:32:14 +02:00
|
|
|
mousevsc_on_receive_device_info(input_dev,
|
|
|
|
(struct synthhid_device_info *)&pipe_msg->data[0]);
|
2011-03-03 02:42:50 +01:00
|
|
|
break;
|
|
|
|
case SynthHidInputReport:
|
2011-04-01 23:32:14 +02:00
|
|
|
mousevsc_on_receive_input_report(input_dev,
|
|
|
|
(struct synthhid_input_report *)&pipe_msg->data[0]);
|
2011-03-03 02:42:50 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pr_err("unsupported hid msg type - type %d len %d",
|
2011-04-01 23:32:14 +02:00
|
|
|
hid_msg->header.type, hid_msg->header.size);
|
2011-03-03 02:42:50 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:11 +02:00
|
|
|
put_input_device(device);
|
2011-03-03 02:42:50 +01:00
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:11 +02:00
|
|
|
static void mousevsc_on_channel_callback(void *context)
|
2011-03-03 02:42:50 +01:00
|
|
|
{
|
|
|
|
const int packetSize = 0x100;
|
|
|
|
int ret = 0;
|
2011-04-01 23:32:11 +02:00
|
|
|
struct hv_device *device = (struct hv_device *)context;
|
2011-04-01 23:32:14 +02:00
|
|
|
struct mousevsc_dev *input_dev;
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
u32 bytes_recvd;
|
|
|
|
u64 req_id;
|
2011-03-03 02:42:50 +01:00
|
|
|
unsigned char packet[packetSize];
|
|
|
|
struct vmpacket_descriptor *desc;
|
|
|
|
unsigned char *buffer = packet;
|
|
|
|
int bufferlen = packetSize;
|
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
input_dev = must_get_input_device(device);
|
2011-03-03 02:42:50 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
if (!input_dev) {
|
2011-03-03 02:42:50 +01:00
|
|
|
pr_err("unable to get input device...device being destroyed?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
2011-04-01 23:32:14 +02:00
|
|
|
ret = vmbus_recvpacket_raw(device->channel, buffer,
|
|
|
|
bufferlen, &bytes_recvd, &req_id);
|
2011-03-03 02:42:50 +01:00
|
|
|
|
|
|
|
if (ret == 0) {
|
2011-04-01 23:32:14 +02:00
|
|
|
if (bytes_recvd > 0) {
|
2011-03-03 02:42:50 +01:00
|
|
|
desc = (struct vmpacket_descriptor *)buffer;
|
|
|
|
|
|
|
|
switch (desc->type) {
|
|
|
|
case VM_PKT_COMP:
|
2011-04-01 23:32:10 +02:00
|
|
|
mousevsc_on_send_completion(
|
|
|
|
device, desc);
|
2011-03-03 02:42:50 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VM_PKT_DATA_INBAND:
|
2011-04-01 23:32:10 +02:00
|
|
|
mousevsc_on_receive(
|
|
|
|
device, desc);
|
2011-03-03 02:42:50 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
pr_err("unhandled packet type %d, tid %llx len %d\n",
|
|
|
|
desc->type,
|
2011-04-01 23:32:14 +02:00
|
|
|
req_id,
|
|
|
|
bytes_recvd);
|
2011-03-03 02:42:50 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reset */
|
|
|
|
if (bufferlen > packetSize) {
|
|
|
|
kfree(buffer);
|
|
|
|
|
|
|
|
buffer = packet;
|
|
|
|
bufferlen = packetSize;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* pr_debug("nothing else to read...");
|
|
|
|
* reset
|
|
|
|
*/
|
|
|
|
if (bufferlen > packetSize) {
|
|
|
|
kfree(buffer);
|
|
|
|
|
|
|
|
buffer = packet;
|
|
|
|
bufferlen = packetSize;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (ret == -2) {
|
|
|
|
/* Handle large packet */
|
2011-04-01 23:32:14 +02:00
|
|
|
bufferlen = bytes_recvd;
|
|
|
|
buffer = kzalloc(bytes_recvd, GFP_KERNEL);
|
2011-03-03 02:42:50 +01:00
|
|
|
|
|
|
|
if (buffer == NULL) {
|
|
|
|
buffer = packet;
|
|
|
|
bufferlen = packetSize;
|
|
|
|
|
|
|
|
/* Try again next time around */
|
|
|
|
pr_err("unable to allocate buffer of size %d!",
|
2011-04-01 23:32:14 +02:00
|
|
|
bytes_recvd);
|
2011-03-03 02:42:50 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (1);
|
|
|
|
|
2011-04-01 23:32:10 +02:00
|
|
|
put_input_device(device);
|
2011-03-03 02:42:50 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2011-02-27 16:43:10 +01:00
|
|
|
|
2011-04-01 23:32:11 +02:00
|
|
|
static int mousevsc_connect_to_vsp(struct hv_device *device)
|
2011-03-03 03:50:15 +01:00
|
|
|
{
|
|
|
|
int ret = 0;
|
2011-04-01 23:32:14 +02:00
|
|
|
struct mousevsc_dev *input_dev;
|
2011-03-03 03:50:15 +01:00
|
|
|
struct mousevsc_prt_msg *request;
|
|
|
|
struct mousevsc_prt_msg *response;
|
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
input_dev = get_input_device(device);
|
2011-03-03 03:50:15 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
if (!input_dev) {
|
2011-03-03 03:50:15 +01:00
|
|
|
pr_err("unable to get input device...device being destroyed?");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
init_waitqueue_head(&input_dev->protocol_wait_event);
|
|
|
|
init_waitqueue_head(&input_dev->dev_info_wait_event);
|
2011-03-03 03:50:15 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
request = &input_dev->protocol_req;
|
2011-03-03 03:50:15 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now, initiate the vsc/vsp initialization protocol on the open channel
|
|
|
|
*/
|
2011-03-17 02:40:59 +01:00
|
|
|
memset(request, 0, sizeof(struct mousevsc_prt_msg));
|
2011-03-03 03:50:15 +01:00
|
|
|
|
2011-03-03 04:36:15 +01:00
|
|
|
request->type = PipeMessageData;
|
2011-03-03 04:38:29 +01:00
|
|
|
request->size = sizeof(struct synthhid_protocol_request);
|
2011-03-03 03:50:15 +01:00
|
|
|
|
2011-03-03 04:41:00 +01:00
|
|
|
request->request.header.type = SynthHidProtocolRequest;
|
|
|
|
request->request.header.size = sizeof(unsigned long);
|
|
|
|
request->request.version_requested.version = SYNTHHID_INPUT_VERSION;
|
2011-03-03 03:50:15 +01:00
|
|
|
|
|
|
|
pr_info("synthhid protocol request...");
|
|
|
|
|
2011-04-01 23:32:11 +02:00
|
|
|
ret = vmbus_sendpacket(device->channel, request,
|
2011-03-03 03:50:15 +01:00
|
|
|
sizeof(struct pipe_prt_msg) -
|
|
|
|
sizeof(unsigned char) +
|
|
|
|
sizeof(struct synthhid_protocol_request),
|
|
|
|
(unsigned long)request,
|
|
|
|
VM_PKT_DATA_INBAND,
|
|
|
|
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
|
|
|
|
if (ret != 0) {
|
|
|
|
pr_err("unable to send synthhid protocol request.");
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
input_dev->protocol_wait_condition = 0;
|
|
|
|
wait_event_timeout(input_dev->protocol_wait_event,
|
|
|
|
input_dev->protocol_wait_condition, msecs_to_jiffies(1000));
|
|
|
|
if (input_dev->protocol_wait_condition == 0) {
|
2011-03-03 03:50:15 +01:00
|
|
|
ret = -ETIMEDOUT;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
response = &input_dev->protocol_resp;
|
2011-03-03 03:50:15 +01:00
|
|
|
|
2011-03-03 04:41:00 +01:00
|
|
|
if (!response->response.approved) {
|
2011-03-03 03:50:15 +01:00
|
|
|
pr_err("synthhid protocol request failed (version %d)",
|
2011-03-03 04:18:34 +01:00
|
|
|
SYNTHHID_INPUT_VERSION);
|
2011-03-03 03:50:15 +01:00
|
|
|
ret = -1;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
input_dev->device_wait_condition = 0;
|
|
|
|
wait_event_timeout(input_dev->dev_info_wait_event,
|
|
|
|
input_dev->device_wait_condition, msecs_to_jiffies(1000));
|
|
|
|
if (input_dev->device_wait_condition == 0) {
|
2011-03-03 03:50:15 +01:00
|
|
|
ret = -ETIMEDOUT;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We should have gotten the device attr, hid desc and report
|
|
|
|
* desc at this point
|
|
|
|
*/
|
2011-04-01 23:32:14 +02:00
|
|
|
if (!input_dev->dev_info_status)
|
2011-03-03 03:50:15 +01:00
|
|
|
pr_info("**** input channel up and running!! ****");
|
|
|
|
else
|
|
|
|
ret = -1;
|
|
|
|
|
|
|
|
Cleanup:
|
2011-04-01 23:32:11 +02:00
|
|
|
put_input_device(device);
|
2011-03-03 03:50:15 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:11 +02:00
|
|
|
static int mousevsc_on_device_add(struct hv_device *device,
|
|
|
|
void *additional_info)
|
2011-03-03 03:50:15 +01:00
|
|
|
{
|
|
|
|
int ret = 0;
|
2011-04-01 23:32:14 +02:00
|
|
|
struct mousevsc_dev *input_dev;
|
|
|
|
struct mousevsc_drv_obj *input_drv;
|
2011-03-03 04:24:05 +01:00
|
|
|
struct hv_input_dev_info dev_info;
|
2011-03-03 03:50:15 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
input_dev = alloc_input_device(device);
|
2011-03-03 03:50:15 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
if (!input_dev) {
|
2011-03-03 03:50:15 +01:00
|
|
|
ret = -1;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
input_dev->init_complete = false;
|
2011-03-03 03:50:15 +01:00
|
|
|
|
|
|
|
/* Open the channel */
|
2011-04-01 23:32:11 +02:00
|
|
|
ret = vmbus_open(device->channel,
|
2011-03-03 03:50:15 +01:00
|
|
|
INPUTVSC_SEND_RING_BUFFER_SIZE,
|
|
|
|
INPUTVSC_RECV_RING_BUFFER_SIZE,
|
|
|
|
NULL,
|
|
|
|
0,
|
2011-04-01 23:32:10 +02:00
|
|
|
mousevsc_on_channel_callback,
|
2011-04-01 23:32:11 +02:00
|
|
|
device
|
2011-03-03 03:50:15 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
if (ret != 0) {
|
|
|
|
pr_err("unable to open channel: %d", ret);
|
2011-04-01 23:32:14 +02:00
|
|
|
free_input_device(input_dev);
|
2011-03-03 03:50:15 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pr_info("InputVsc channel open: %d", ret);
|
|
|
|
|
2011-04-01 23:32:11 +02:00
|
|
|
ret = mousevsc_connect_to_vsp(device);
|
2011-03-03 03:50:15 +01:00
|
|
|
|
|
|
|
if (ret != 0) {
|
|
|
|
pr_err("unable to connect channel: %d", ret);
|
|
|
|
|
2011-04-01 23:32:11 +02:00
|
|
|
vmbus_close(device->channel);
|
2011-04-01 23:32:14 +02:00
|
|
|
free_input_device(input_dev);
|
2011-03-03 03:50:15 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-04-26 18:20:20 +02:00
|
|
|
input_drv = drv_to_mousedrv(input_dev->device->device.driver);
|
2011-03-03 03:50:15 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
dev_info.vendor = input_dev->hid_dev_info.vendor;
|
|
|
|
dev_info.product = input_dev->hid_dev_info.product;
|
|
|
|
dev_info.version = input_dev->hid_dev_info.version;
|
2011-03-03 04:24:05 +01:00
|
|
|
strcpy(dev_info.name, "Microsoft Vmbus HID-compliant Mouse");
|
2011-03-03 03:50:15 +01:00
|
|
|
|
|
|
|
/* Send the device info back up */
|
2011-04-01 23:32:11 +02:00
|
|
|
deviceinfo_callback(device, &dev_info);
|
2011-03-03 03:50:15 +01:00
|
|
|
|
|
|
|
/* Send the report desc back up */
|
|
|
|
/* workaround SA-167 */
|
2011-04-01 23:32:14 +02:00
|
|
|
if (input_dev->report_desc[14] == 0x25)
|
|
|
|
input_dev->report_desc[14] = 0x29;
|
2011-03-03 03:50:15 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
reportdesc_callback(device, input_dev->report_desc,
|
|
|
|
input_dev->report_desc_size);
|
2011-03-03 03:50:15 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
input_dev->init_complete = true;
|
2011-03-03 03:50:15 +01:00
|
|
|
|
|
|
|
Cleanup:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:11 +02:00
|
|
|
static int mousevsc_on_device_remove(struct hv_device *device)
|
2011-03-03 03:50:15 +01:00
|
|
|
{
|
2011-04-01 23:32:14 +02:00
|
|
|
struct mousevsc_dev *input_dev;
|
2011-03-03 03:50:15 +01:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
pr_info("disabling input device (%p)...",
|
2011-04-01 23:32:11 +02:00
|
|
|
device->ext);
|
2011-03-03 03:50:15 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
input_dev = release_input_device(device);
|
2011-03-03 03:50:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point, all outbound traffic should be disable. We only
|
|
|
|
* allow inbound traffic (responses) to proceed
|
|
|
|
*
|
|
|
|
* so that outstanding requests can be completed.
|
|
|
|
*/
|
2011-04-01 23:32:14 +02:00
|
|
|
while (input_dev->num_outstanding_req) {
|
2011-04-01 23:32:13 +02:00
|
|
|
pr_info("waiting for %d requests to complete...",
|
2011-04-01 23:32:14 +02:00
|
|
|
input_dev->num_outstanding_req);
|
2011-03-03 03:50:15 +01:00
|
|
|
|
|
|
|
udelay(100);
|
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:11 +02:00
|
|
|
pr_info("removing input device (%p)...", device->ext);
|
2011-03-03 03:50:15 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
input_dev = final_release_input_device(device);
|
2011-03-03 03:50:15 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
pr_info("input device (%p) safe to remove", input_dev);
|
2011-03-03 03:50:15 +01:00
|
|
|
|
|
|
|
/* Close the channel */
|
2011-04-01 23:32:11 +02:00
|
|
|
vmbus_close(device->channel);
|
2011-03-03 03:50:15 +01:00
|
|
|
|
2011-04-01 23:32:14 +02:00
|
|
|
free_input_device(input_dev);
|
2011-03-03 03:50:15 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-27 16:43:10 +01:00
|
|
|
/*
|
|
|
|
* Data types
|
|
|
|
*/
|
|
|
|
struct input_device_context {
|
2011-03-07 22:35:48 +01:00
|
|
|
struct hv_device *device_ctx;
|
2011-02-27 16:43:10 +01:00
|
|
|
struct hid_device *hid_device;
|
2011-03-03 03:57:04 +01:00
|
|
|
struct hv_input_dev_info device_info;
|
2011-02-27 16:43:10 +01:00
|
|
|
int connected;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-05-10 16:55:18 +02:00
|
|
|
static struct mousevsc_drv_obj mousevsc_drv;
|
2011-02-27 16:43:10 +01:00
|
|
|
|
2011-03-03 03:57:04 +01:00
|
|
|
static void deviceinfo_callback(struct hv_device *dev, struct hv_input_dev_info *info)
|
2011-02-27 16:43:10 +01:00
|
|
|
{
|
|
|
|
struct input_device_context *input_device_ctx =
|
2011-03-07 22:35:48 +01:00
|
|
|
dev_get_drvdata(&dev->device);
|
2011-02-27 16:43:10 +01:00
|
|
|
|
|
|
|
memcpy(&input_device_ctx->device_info, info,
|
2011-03-03 03:57:04 +01:00
|
|
|
sizeof(struct hv_input_dev_info));
|
2011-02-27 16:43:10 +01:00
|
|
|
|
2011-03-03 03:38:31 +01:00
|
|
|
DPRINT_INFO(INPUTVSC_DRV, "%s", __func__);
|
2011-02-27 16:43:10 +01:00
|
|
|
}
|
|
|
|
|
2011-03-03 03:38:31 +01:00
|
|
|
static void inputreport_callback(struct hv_device *dev, void *packet, u32 len)
|
2011-02-27 16:43:10 +01:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
struct input_device_context *input_dev_ctx =
|
2011-03-07 22:35:48 +01:00
|
|
|
dev_get_drvdata(&dev->device);
|
2011-02-27 16:43:10 +01:00
|
|
|
|
|
|
|
ret = hid_input_report(input_dev_ctx->hid_device,
|
|
|
|
HID_INPUT_REPORT, packet, len, 1);
|
|
|
|
|
|
|
|
DPRINT_DBG(INPUTVSC_DRV, "hid_input_report (ret %d)", ret);
|
|
|
|
}
|
|
|
|
|
2011-03-03 03:50:15 +01:00
|
|
|
static int mousevsc_hid_open(struct hid_device *hid)
|
2011-02-27 16:43:10 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-03 03:50:15 +01:00
|
|
|
static void mousevsc_hid_close(struct hid_device *hid)
|
2011-02-27 16:43:10 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-04-29 22:45:10 +02:00
|
|
|
static int mousevsc_probe(struct hv_device *dev)
|
2011-02-27 16:43:10 +01:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
struct input_device_context *input_dev_ctx;
|
|
|
|
|
|
|
|
input_dev_ctx = kmalloc(sizeof(struct input_device_context),
|
|
|
|
GFP_KERNEL);
|
|
|
|
|
2011-04-29 22:45:10 +02:00
|
|
|
dev_set_drvdata(&dev->device, input_dev_ctx);
|
2011-02-27 16:43:10 +01:00
|
|
|
|
|
|
|
/* Call to the vsc driver to add the device */
|
2011-05-10 16:55:06 +02:00
|
|
|
ret = mousevsc_on_device_add(dev, NULL);
|
2011-02-27 16:43:10 +01:00
|
|
|
|
|
|
|
if (ret != 0) {
|
|
|
|
DPRINT_ERR(INPUTVSC_DRV, "unable to add input vsc device");
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-04-29 22:45:12 +02:00
|
|
|
static int mousevsc_remove(struct hv_device *dev)
|
2011-02-27 16:43:10 +01:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
struct input_device_context *input_dev_ctx;
|
|
|
|
|
|
|
|
input_dev_ctx = kmalloc(sizeof(struct input_device_context),
|
|
|
|
GFP_KERNEL);
|
|
|
|
|
2011-04-29 22:45:12 +02:00
|
|
|
dev_set_drvdata(&dev->device, input_dev_ctx);
|
2011-02-27 16:43:10 +01:00
|
|
|
|
|
|
|
if (input_dev_ctx->connected) {
|
|
|
|
hidinput_disconnect(input_dev_ctx->hid_device);
|
|
|
|
input_dev_ctx->connected = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call to the vsc driver to let it know that the device
|
|
|
|
* is being removed
|
|
|
|
*/
|
2011-05-10 16:55:07 +02:00
|
|
|
ret = mousevsc_on_device_remove(dev);
|
2011-02-27 16:43:10 +01:00
|
|
|
|
|
|
|
if (ret != 0) {
|
|
|
|
DPRINT_ERR(INPUTVSC_DRV,
|
|
|
|
"unable to remove vsc device (ret %d)", ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(input_dev_ctx);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-03 03:38:31 +01:00
|
|
|
static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len)
|
2011-02-27 16:43:10 +01:00
|
|
|
{
|
|
|
|
struct input_device_context *input_device_ctx =
|
2011-03-07 22:35:48 +01:00
|
|
|
dev_get_drvdata(&dev->device);
|
2011-02-27 16:43:10 +01:00
|
|
|
struct hid_device *hid_dev;
|
|
|
|
|
|
|
|
/* hid_debug = -1; */
|
|
|
|
hid_dev = kmalloc(sizeof(struct hid_device), GFP_KERNEL);
|
|
|
|
|
|
|
|
if (hid_parse_report(hid_dev, packet, len)) {
|
|
|
|
DPRINT_INFO(INPUTVSC_DRV, "Unable to call hd_parse_report");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hid_dev) {
|
|
|
|
DPRINT_INFO(INPUTVSC_DRV, "hid_device created");
|
|
|
|
|
|
|
|
hid_dev->ll_driver->open = mousevsc_hid_open;
|
|
|
|
hid_dev->ll_driver->close = mousevsc_hid_close;
|
|
|
|
|
2011-03-03 03:58:35 +01:00
|
|
|
hid_dev->bus = BUS_VIRTUAL;
|
2011-03-03 03:57:04 +01:00
|
|
|
hid_dev->vendor = input_device_ctx->device_info.vendor;
|
|
|
|
hid_dev->product = input_device_ctx->device_info.product;
|
|
|
|
hid_dev->version = input_device_ctx->device_info.version;
|
2011-03-07 22:35:48 +01:00
|
|
|
hid_dev->dev = dev->device;
|
2011-02-27 16:43:10 +01:00
|
|
|
|
|
|
|
sprintf(hid_dev->name, "%s",
|
2011-03-03 03:57:04 +01:00
|
|
|
input_device_ctx->device_info.name);
|
2011-02-27 16:43:10 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* HJ Do we want to call it with a 0
|
|
|
|
*/
|
|
|
|
if (!hidinput_connect(hid_dev, 0)) {
|
|
|
|
hid_dev->claimed |= HID_CLAIMED_INPUT;
|
|
|
|
|
|
|
|
input_device_ctx->connected = 1;
|
|
|
|
|
|
|
|
DPRINT_INFO(INPUTVSC_DRV,
|
|
|
|
"HID device claimed by input\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hid_dev->claimed) {
|
|
|
|
DPRINT_ERR(INPUTVSC_DRV,
|
|
|
|
"HID device not claimed by "
|
|
|
|
"input or hiddev\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
input_device_ctx->hid_device = hid_dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(hid_dev);
|
|
|
|
}
|
|
|
|
|
2011-03-03 03:50:15 +01:00
|
|
|
static int mousevsc_drv_exit_cb(struct device *dev, void *data)
|
2011-02-27 16:43:10 +01:00
|
|
|
{
|
|
|
|
struct device **curr = (struct device **)data;
|
|
|
|
*curr = dev;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-03-03 03:50:15 +01:00
|
|
|
static void mousevsc_drv_exit(void)
|
2011-02-27 16:43:10 +01:00
|
|
|
{
|
2011-05-10 16:55:18 +02:00
|
|
|
struct hv_driver *drv = &mousevsc_drv.base;
|
2011-02-27 16:43:10 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
struct device *current_dev = NULL;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
current_dev = NULL;
|
|
|
|
|
|
|
|
/* Get the device */
|
2011-03-07 22:32:31 +01:00
|
|
|
ret = driver_for_each_device(&drv->driver, NULL,
|
2011-03-03 02:19:05 +01:00
|
|
|
(void *)¤t_dev,
|
|
|
|
mousevsc_drv_exit_cb);
|
2011-02-27 16:43:10 +01:00
|
|
|
if (ret)
|
|
|
|
printk(KERN_ERR "Can't find mouse device!\n");
|
|
|
|
|
|
|
|
if (current_dev == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Initiate removal from the top-down */
|
|
|
|
device_unregister(current_dev);
|
|
|
|
}
|
|
|
|
|
2011-03-07 22:32:31 +01:00
|
|
|
vmbus_child_driver_unregister(&drv->driver);
|
2011-02-27 16:43:10 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-01 23:32:11 +02:00
|
|
|
static int mouse_vsc_initialize(struct hv_driver *driver)
|
2011-03-03 03:50:15 +01:00
|
|
|
{
|
2011-04-01 23:32:11 +02:00
|
|
|
driver->name = driver_name;
|
|
|
|
memcpy(&driver->dev_type, &mouse_guid,
|
2011-03-03 03:50:15 +01:00
|
|
|
sizeof(struct hv_guid));
|
|
|
|
|
2011-05-10 16:55:09 +02:00
|
|
|
return 0;
|
2011-03-03 03:50:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-27 16:43:10 +01:00
|
|
|
static int __init mousevsc_init(void)
|
|
|
|
{
|
2011-05-10 16:55:18 +02:00
|
|
|
struct mousevsc_drv_obj *input_drv_obj = &mousevsc_drv;
|
|
|
|
struct hv_driver *drv = &mousevsc_drv.base;
|
2011-02-27 16:43:10 +01:00
|
|
|
|
|
|
|
DPRINT_INFO(INPUTVSC_DRV, "Hyper-V Mouse driver initializing.");
|
|
|
|
|
2011-03-03 03:28:52 +01:00
|
|
|
/* Callback to client driver to complete the initialization */
|
2011-04-01 23:32:12 +02:00
|
|
|
mouse_vsc_initialize(&input_drv_obj->base);
|
2011-03-03 03:28:52 +01:00
|
|
|
|
2011-04-01 23:32:12 +02:00
|
|
|
drv->driver.name = input_drv_obj->base.name;
|
2011-03-03 03:28:52 +01:00
|
|
|
|
2011-04-29 22:45:10 +02:00
|
|
|
drv->probe = mousevsc_probe;
|
2011-04-29 22:45:12 +02:00
|
|
|
drv->remove = mousevsc_remove;
|
2011-03-03 03:28:52 +01:00
|
|
|
|
|
|
|
/* The driver belongs to vmbus */
|
2011-03-07 22:32:31 +01:00
|
|
|
vmbus_child_driver_register(&drv->driver);
|
2011-03-03 03:28:52 +01:00
|
|
|
|
|
|
|
return 0;
|
2011-02-27 16:43:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit mousevsc_exit(void)
|
|
|
|
{
|
|
|
|
mousevsc_drv_exit();
|
|
|
|
}
|
|
|
|
|
2011-03-03 02:15:14 +01:00
|
|
|
/*
|
|
|
|
* We don't want to automatically load this driver just yet, it's quite
|
|
|
|
* broken. It's safe if you want to load it yourself manually, but
|
|
|
|
* don't inflict it on unsuspecting users, that's just mean.
|
|
|
|
*/
|
|
|
|
#if 0
|
|
|
|
|
2011-02-27 16:43:10 +01:00
|
|
|
/*
|
|
|
|
* We use a PCI table to determine if we should autoload this driver This is
|
|
|
|
* needed by distro tools to determine if the hyperv drivers should be
|
|
|
|
* installed and/or configured. We don't do anything else with the table, but
|
|
|
|
* it needs to be present.
|
|
|
|
*/
|
|
|
|
const static struct pci_device_id microsoft_hv_pci_table[] = {
|
|
|
|
{ PCI_DEVICE(0x1414, 0x5353) }, /* VGA compatible controller */
|
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(pci, microsoft_hv_pci_table);
|
2011-03-03 02:15:14 +01:00
|
|
|
#endif
|
2011-02-27 16:43:10 +01:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_VERSION(HV_DRV_VERSION);
|
|
|
|
module_init(mousevsc_init);
|
|
|
|
module_exit(mousevsc_exit);
|
|
|
|
|