/
openxt-kbdfront.c
780 lines (640 loc) · 22.9 KB
/
openxt-kbdfront.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
/*
* OpenXT para-virtual input device
*
* Copyright (C) 2005 Anthony Liguori <aliguori@us.ibm.com>
* Copyright (C) 2006-2008 Red Hat, Inc., Markus Armbruster <armbru@redhat.com>
* Copyright (C) 2015 Assured Information Security, Inc. Kyle J. Temkin <temkink@ainfosec.com>
*
* Based on linux/drivers/input/misc/xen-kbdfront.c
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive for
* more details.
*/
#include <linux/input/mt.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/module.h>
#include <linux/input.h>
#include <linux/slab.h>
#include <asm/xen/hypervisor.h>
#include <xen/xen.h>
#include <xen/events.h>
#include <xen/page.h>
#include <xen/grant_table.h>
#include <xen/interface/grant_table.h>
#include <xen/interface/io/fbif.h>
#include <xen/interface/io/kbdif.h>
#include <xen/xenbus.h>
#include <xen/platform_pci.h>
#include "openxt_kbdif.h"
/**
* Default ABS_X/ABS_Y max: the default maximum value that the absolute input devices
* should accept. This effectively sets the maximum width and height transmitted
* via the shared ring.
*/
static int default_max_x = 32768;
module_param(default_max_x, int, S_IRUGO);
static int default_max_y = 32768;
module_param(default_max_y, int, S_IRUGO);
/**
* Data structure describing the OXT-KBD device state.
*/
struct openxt_kbd_info {
//The raw keyboard-- used to send key events.
struct input_dev *keyboard;
struct input_dev *relative_pointer;
//The input device used to deliver any absolute events.
struct input_dev *absolute_pointer;
// Information about the current connection to the backend domain,
// including the grant reference and event channel IRQ.
int gref;
int irq;
struct xenkbd_page *page;
struct xenbus_device *xbdev;
char phys[32];
};
//Forward declarations.
static int oxtkbd_remove(struct xenbus_device *);
static int oxtkbd_connect_backend(struct xenbus_device *, struct openxt_kbd_info *);
static void oxtkbd_disconnect_backend(struct openxt_kbd_info *);
/**
* Handler for relative motion events.
*
* @param info The device information structure for the relevant PV input
* device.
* @param event The relative motion event to be handled.
*/
static void __handle_relative_motion(struct openxt_kbd_info *info,
union oxtkbd_in_event *event)
{
//Pass the relative movement on to evdev.
input_report_rel(info->relative_pointer, REL_X, event->motion.rel_x);
input_report_rel(info->relative_pointer, REL_Y, event->motion.rel_y);
//If the event has a Z-axis motion (a scroll wheel event),
//send that as well.
if (event->motion.rel_z)
input_report_rel(info->relative_pointer, REL_WHEEL, -event->motion.rel_z);
input_sync(info->relative_pointer);
}
/**
* Handler for pure absolute (e.g. touchpad) movements.
*
* @param info The device information structure for the relevant PV input
* device.
* @param event The absolute motion event to be handled.
*/
static void __handle_absolute_motion(struct openxt_kbd_info *info,
union oxtkbd_in_event *event)
{
//Send the new absolute coordinate...
input_report_abs(info->absolute_pointer, ABS_X, event->pos.abs_x);
input_report_abs(info->absolute_pointer, ABS_Y, event->pos.abs_y);
//... and if we have a scroll wheel event, send that too.
if (event->pos.rel_z)
input_report_rel(info->absolute_pointer, REL_WHEEL, -event->pos.rel_z);
input_sync(info->absolute_pointer);
}
/**
* Handler for multitouch touch events.
*
* @param info The device information structure for the relevant PV input
* device.
* @param event The touch event to be handled.
*/
static void __handle_touch_down(struct openxt_kbd_info *info,
union oxtkbd_in_event *event)
{
//Send an indication that the given finger has been pressed...
input_mt_slot(info->absolute_pointer, event->touch_move.id);
input_mt_report_slot_state(info->absolute_pointer, MT_TOOL_FINGER, 1);
}
/**
* Handler for multitouch touch events.
*
* @param info The device information structure for the relevant PV input
* device.
* @param event The touch event to be handled.
*/
static void __handle_touch_movement(struct openxt_kbd_info *info,
union oxtkbd_in_event *event, int report_slot, int send_abs_event)
{
//Send the slot number, which determines which "finger" is providing
//the touch event.
if (report_slot)
input_mt_slot(info->absolute_pointer, event->touch_move.id);
//... the multi-touch coordinates...
input_report_abs(info->absolute_pointer, ABS_MT_POSITION_X, event->touch_move.abs_x);
input_report_abs(info->absolute_pointer, ABS_MT_POSITION_Y, event->touch_move.abs_y);
//... and absolute touch points, if desired.
//Note that we only send the absolute touch events for slot zero-- the other "fingers"
//only send multi-touch events!
if (send_abs_event && (event->touch_move.id == 0)) {
input_report_abs(info->absolute_pointer, ABS_X, event->touch_move.abs_x);
input_report_abs(info->absolute_pointer, ABS_Y, event->touch_move.abs_y);
}
}
/**
* Handler for multitouch touch events.
*
* @param info The device information structure for the relevant PV input
* device.
* @param event The touch event to be handled.
*/
static void __handle_touch_up(struct openxt_kbd_info *info,
union oxtkbd_in_event *event)
{
//Send an indication that the given finger has been pressed...
input_mt_slot(info->absolute_pointer, event->touch_move.id);
input_mt_report_slot_state(info->absolute_pointer, MT_TOOL_FINGER, 0);
}
/**
* Handle touch framing events.
*
* @param info The device information structure for the relevant PV input
* device.
* @param event The touch event to be handled.
*/
static void __handle_touch_framing(struct openxt_kbd_info *info,
union oxtkbd_in_event *event)
{
input_mt_sync_frame(info->absolute_pointer);
input_sync(info->absolute_pointer);;
}
/**
* Handler for keypress events, including mouse button "keys".
*
* @param info The device information structure for the relevant PV input
* device.
* @param event The keypress event to be handled.
*/
static void __handle_key_or_button_press(struct openxt_kbd_info *info,
union oxtkbd_in_event *event)
{
struct input_dev *dev = NULL;
//If this event is corresponds to a keyboard event,
//send it via the keyboard device.
if (test_bit(event->key.keycode, info->keyboard->keybit))
dev = info->keyboard;
//If it corresponds to a mouse event, send it via the mouse
//device. TODO: Possibly differentiate between ABS and REL presses?
if (test_bit(event->key.keycode, info->relative_pointer->keybit))
dev = info->relative_pointer;
//If we found a device to send the key via, send it!
if (dev) {
input_report_key(dev, event->key.keycode, event->key.pressed);
input_sync(dev);
}
else {
pr_warning("unhandled keycode 0x%x\n", event->key.keycode);
}
}
/**
* Main handler for OpenXT PV input.
*/
static irqreturn_t input_handler(int rq, void *dev_id)
{
__u32 cons, prod;
//Get a reference to the device's information structure...
struct openxt_kbd_info *info = dev_id;
//... and get a reference to the shared page used for communications.
struct xenkbd_page *page = info->page;
//If we have the latest data from the ringbuffer, we're done!
prod = page->in_prod;
if (prod == page->in_cons)
return IRQ_HANDLED;
//Ensure that we always see the latest data.
rmb();
//For each outstanding event in the ringbuffer...
for (cons = page->in_cons; cons != prod; cons++) {
union oxtkbd_in_event *event;
//Get a reference to the current event.
event = &OXT_KBD_IN_RING_REF(page, cons);
switch (event->type) {
case OXT_KBD_TYPE_MOTION:
__handle_relative_motion(info, event);
break;
case OXT_KBD_TYPE_KEY:
__handle_key_or_button_press(info, event);
break;
case OXT_KBD_TYPE_POS:
__handle_absolute_motion(info, event);
break;
case OXT_KBD_TYPE_TOUCH_DOWN:
__handle_touch_down(info, event);
__handle_touch_movement(info, event, false, false);
break;
case OXT_KBD_TYPE_TOUCH_UP:
__handle_touch_up(info, event);
break;
case OXT_KBD_TYPE_TOUCH_MOVE:
__handle_touch_movement(info, event, true, false);
break;
case OXT_KBD_TYPE_TOUCH_FRAME:
__handle_touch_framing(info, event);
break;
}
}
//Free the relevant space in the ringbuffer...
mb();
page->in_cons = cons;
//... and signal to the other side that we're ready
//for more data.
notify_remote_via_irq(info->irq);
return IRQ_HANDLED;
}
/**
* Registers a new Xen Virtual Keyboard Device.
*
* @param info The information structure for the combined input device
* for which this device should belong to.
* @param name The new device's name, as reported to the user.
*/
static struct input_dev * __allocate_keyboard_device(struct openxt_kbd_info *info,
char * name)
{
int i, ret;
//Allocate a new input device.
struct input_dev *kbd = input_allocate_device();
if (!kbd)
return NULL;
//Initailize its basic device information...
kbd->name = name;
kbd->phys = info->phys;
kbd->id.bustype = BUS_PCI;
kbd->id.vendor = 0x5853;
kbd->id.product = 0xffff;
//Register all of the keys we'll want the keyboard device to handle.
__set_bit(EV_KEY, kbd->evbit);
for (i = KEY_ESC; i < KEY_UNKNOWN; i++)
__set_bit(i, kbd->keybit);
for (i = KEY_OK; i < KEY_MAX; i++)
__set_bit(i, kbd->keybit);
//And finally, register the device with the input subsystem.
ret = input_register_device(kbd);
if (ret) {
input_free_device(kbd);
return NULL;
}
return kbd;
}
/**
* Creates a new Xen Virtrual Pointer Device.
*
* @param info The information structure for the combined input device
* for which this device should belong to.
* @param name The new device's name, as reported to the user.
*/
static struct input_dev * __allocate_pointer_device(struct openxt_kbd_info *info,
char * name, int is_absolute, int is_multitouch)
{
int i, ret;
struct input_dev *ptr = input_allocate_device();
//If we weren't able to allocate a new input device, fail out!
if (!ptr)
return NULL;
//Otherwise, set up some of the device's defaults.
ptr->name = name;
ptr->phys = info->phys;
ptr->id.bustype = BUS_PCI;
ptr->id.vendor = 0x5853;
ptr->id.product = 0xfffe;
//If we're creating an absolute device, register it as a provider
//of absolute events.
if (is_absolute) {
__set_bit(EV_ABS, ptr->evbit);
input_set_abs_params(ptr, ABS_X, 0, default_max_x, 0, 0);
input_set_abs_params(ptr, ABS_Y, 0, default_max_y, 0, 0);
if (is_multitouch) {
input_set_abs_params(ptr, ABS_MT_POSITION_X, 0, default_max_x, 0, 0);
input_set_abs_params(ptr, ABS_MT_POSITION_Y, 0, default_max_y, 0, 0);
//Accept touches, as well.
input_set_capability(ptr, EV_KEY, BTN_TOUCH);
//And allow up to ten fingers of touch.
input_mt_init_slots(ptr, 10, INPUT_MT_DIRECT);
}
}
//Otherwise, register it as providing relative ones.
else {
input_set_capability(ptr, EV_REL, REL_X);
input_set_capability(ptr, EV_REL, REL_Y);
}
//Enable scroll events on non-multitouch displays.
if (!is_multitouch)
input_set_capability(ptr, EV_REL, REL_WHEEL);
//Mark this device as providing the typical mouse keys.
if (!is_multitouch) {
__set_bit(EV_KEY, ptr->evbit);
for (i = BTN_LEFT; i <= BTN_TASK; i++)
__set_bit(i, ptr->keybit);
}
//Finally, register the new input device with evdev.
ret = input_register_device(ptr);
if (ret) {
input_free_device(ptr);
return NULL;
}
return ptr;
}
/**
* Creates a new OpenXT combined input device, if possible.
*
* @param dev The XenBus device to which the new combined input device will belong.
* @param id Information regarding the relevant xenbus device.
*
* @return 0 on success, or an error code on failure.
*/
static int oxtkbd_probe(struct xenbus_device *dev, const struct xenbus_device_id *id)
{
int ret;
struct openxt_kbd_info *info;
//Create a new information structure for our new combined input device.
//This will represent the device "object", and store all of the device's
//state.
info = kzalloc(sizeof(*info), GFP_KERNEL);
if (!info) {
xenbus_dev_fatal(dev, -ENOMEM, "allocating info structure");
return -ENOMEM;
}
//Associate the new information structure with the core XenBus device.
dev_set_drvdata(&dev->dev, info);
//Initialize the information structure.
info->xbdev = dev;
info->irq = -1;
info->gref = -1;
snprintf(info->phys, sizeof(info->phys), "xenbus/%s", dev->nodename);
//To communicate with the backend, we'll use a small "shared page"
//as a ring buffer. We'll allocate that page now, and share it with
//the when it tries to connect.
info->page = (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
if (!info->page)
goto error_nomem;
//Allocate a new keyboard device, which will handle all keypresses and
//button presses.
info->keyboard = __allocate_keyboard_device(info, "Xen Virtual Keyboard");
if (!info->keyboard)
goto error_nomem;
//Allocate a new relative pointer, for our relative events...
info->relative_pointer = __allocate_pointer_device(info, "Xen Relative Pointer", false, false);
if (!info->relative_pointer)
goto error_nomem;
//...and an absolute pointer for our absolute ones.
info->absolute_pointer = __allocate_pointer_device(info, "Xen Absolute Pointer", true, true);
if (!info->absolute_pointer)
goto error_nomem;
//Finally, connect to the backend.
ret = oxtkbd_connect_backend(dev, info);
if (ret < 0)
goto error;
//Indicate success.
return 0;
error_nomem:
ret = -ENOMEM;
xenbus_dev_fatal(dev, ret, "allocating device memory");
error:
oxtkbd_remove(dev);
return ret;
}
/**
* Resumes use of the input device after sleep/S3.
*
* @param dev The device to be resumed.
*/
static int oxtkbd_resume(struct xenbus_device *dev)
{
//Get a reference to the connection's information structure.
struct openxt_kbd_info *info = dev_get_drvdata(&dev->dev);
//Upon resume, we'll want to tear down our existing connection
//and reconnect.
oxtkbd_disconnect_backend(info);
//Ensure that no events survive past S3.
memset(info->page, 0, PAGE_SIZE);
return oxtkbd_connect_backend(dev, info);
}
/**
* Removes the provided OpenXT input connection from the system.
*
* @param dev There device to be removed.
*/
static int oxtkbd_remove(struct xenbus_device *dev)
{
//Get a reference to the connection's information structure.
struct openxt_kbd_info *info = dev_get_drvdata(&dev->dev);
//Disconnect ourself from the backend...
oxtkbd_disconnect_backend(info);
//...tear down each of our actual input devices...
if (info->keyboard)
input_unregister_device(info->keyboard);
if (info->relative_pointer)
input_unregister_device(info->relative_pointer);
if (info->absolute_pointer) {
input_mt_destroy_slots(info->absolute_pointer);
input_unregister_device(info->absolute_pointer);
}
//... free our shared page...
free_page((unsigned long)info->page);
//... finally free our information structure.
kfree(info);
return 0;
}
/**
* Connect the OpenXT input device to the corresponding backend.
*
* @param dev The device to be connected.
* @param info The information structure that corresponds to the given device.
*
* @return int Zero on success, or an error code on failure.
*/
static int oxtkbd_connect_backend(struct xenbus_device *dev,
struct openxt_kbd_info *info)
{
int ret, evtchn;
struct xenbus_transaction xbt;
//To communicate with the backend, we'll share a single page of memory
//We'll start this process by granting out our "shared page".
ret = gnttab_grant_foreign_access(dev->otherend_id, virt_to_mfn(info->page), 0);
if (ret < 0)
return ret;
info->gref = ret;
//Next, we'll need to create an event channel we can use to signal that data
//has changed in our shared page.
ret = xenbus_alloc_evtchn(dev, &evtchn);
if (ret)
goto error_grant;
//Bind our input handler to our event channel-- ensuring we're recieve any
//"new data" notifications.
ret = bind_evtchn_to_irqhandler(evtchn, input_handler, 0, dev->devicetype, info);
if (ret < 0) {
xenbus_dev_fatal(dev, ret, "bind_evtchn_to_irqhandler");
goto error_evtchan;
}
info->irq = ret;
again:
//Now that we've set up our shared assets, we'll need to communicate them
//to the backend. First, we'll start a xenbus transaction, so we can dump
//all of our data into the XenStore simultaneously.
ret = xenbus_transaction_start(&xbt);
if (ret) {
xenbus_dev_fatal(dev, ret, "starting transaction");
goto error_irqh;
}
//Provide a direct reference to the page. This allows backends that want
//to use foreign mappings (i.e. legacy backends) to map in the shared page
//without touching grants.
ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu", virt_to_mfn(info->page));
if (ret)
goto error_xenbus;
//And provide our grant reference. This is the preferred way of getting the
//shared page.
ret = xenbus_printf(xbt, dev->nodename, "page-gref", "%u", info->gref);
if (ret)
goto error_xenbus;
//Provide the number for our event channel, so the backend can signal
//new informatino to us.
ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u", evtchn);
if (ret)
goto error_xenbus;
//Attempt to apply all of our changes at once.
ret = xenbus_transaction_end(xbt, 0);
//If our transaction failed...
if (ret) {
//... it may have been because the XenStore was busy. If this is the case,
//repeat out transaction until we succeed, or hit an error.
if (ret == -EAGAIN)
goto again;
//Otherwise, we couldn't connect. Bail out!
xenbus_dev_fatal(dev, ret, "completing transaction");
goto error_irqh;
}
//Finally, switch our state to "intialized", hopefully cueing the backend
//to connect.
xenbus_switch_state(dev, XenbusStateInitialised);
return 0;
error_xenbus:
xenbus_transaction_end(xbt, 1);
xenbus_dev_fatal(dev, ret, "writing xenstore");
error_irqh:
unbind_from_irqhandler(info->irq, info);
info->irq = -1;
error_evtchan:
xenbus_free_evtchn(dev, evtchn);
error_grant:
gnttab_end_foreign_access(info->gref, 0, 0UL);
info->gref = -1;
return ret;
}
/**
* Handles a backend disconnect.
*
* @param info The information structure for the device to be disconnected.
*/
static void oxtkbd_disconnect_backend(struct openxt_kbd_info *info)
{
//If we had an input IRQ registered, tear it down.
if (info->irq >= 0)
unbind_from_irqhandler(info->irq, info);
info->irq = -1;
//... and if we have a shared page for our ring, tear it down.
if (info->gref >= 0)
gnttab_end_foreign_access(info->gref, 0, 0UL);
info->gref = -1;
}
/**
* Handle a change to the keyboard device's backend.
* This effectively moves us through the XenBus negotiation FSM.
*/
static void oxtkbd_backend_changed(struct xenbus_device *dev,
enum xenbus_state backend_state)
{
int val;
struct openxt_kbd_info *info = dev_get_drvdata(&dev->dev);
switch (backend_state) {
case XenbusStateInitialising:
case XenbusStateInitialised:
case XenbusStateReconfiguring:
case XenbusStateReconfigured:
case XenbusStateUnknown:
break;
case XenbusStateInitWait:
InitWait:
xenbus_switch_state(dev, XenbusStateConnected);
break;
case XenbusStateConnected:
/*
* Work around xenbus race condition: If backend goes
* through InitWait to Connected fast enough, we can
* get Connected twice here.
*/
if (dev->state != XenbusStateConnected)
goto InitWait; /* no InitWait seen yet, fudge it */
//Once we connect, try to adjust the screen width and height
//to match the width and height stored in the XenStore.
if (xenbus_scanf(XBT_NIL, info->xbdev->otherend,
"width", "%d", &val) > 0) {
input_set_abs_params(info->absolute_pointer, ABS_X, 0, val, 0, 0);
input_set_abs_params(info->absolute_pointer, ABS_MT_POSITION_X, 0, val, 0, 0);
}
if (xenbus_scanf(XBT_NIL, info->xbdev->otherend,
"height", "%d", &val) > 0) {
input_set_abs_params(info->absolute_pointer, ABS_Y, 0, val, 0, 0);
input_set_abs_params(info->absolute_pointer, ABS_MT_POSITION_Y, 0, val, 0, 0);
}
break;
case XenbusStateClosed:
if (dev->state == XenbusStateClosed)
break;
/* Missed the backend's CLOSING state -- fallthrough */
case XenbusStateClosing:
xenbus_frontend_closed(dev);
break;
}
}
/**
* For now, we'll provide a backwards-compatible alternative to
* xen_kbdfront that can support additional frontend capabilities.
* This may change in the future.
*/
static const struct xenbus_device_id oxtkbd_ids[] = {
{ "vkbd" },
{ "" }
};
/**
* Specify each of the XenBus handlers for our new input driver.
*/
static struct xenbus_driver oxtkbd_driver = {
.ids = oxtkbd_ids,
.probe = oxtkbd_probe,
.remove = oxtkbd_remove,
.resume = oxtkbd_resume,
.otherend_changed = oxtkbd_backend_changed,
};
/**
* Initializes the OpenXT input module.
*/
static int __init oxtkbd_init(void)
{
//If we're not on Xen, we definitely don't apply.
if (!xen_domain())
return -ENODEV;
//For now, there's no sense in running this from dom0,
//as it has direct access to the keyboard. This may change,
//depending on disaggregation specifics.
if (xen_initial_domain())
return -ENODEV;
//If we can't use the XenBus, fail out.
if (!xen_has_pv_devices())
return -ENODEV;
//Otheriwse, register our driver!
return xenbus_register_frontend(&oxtkbd_driver);
}
/**
* Tears down the OpenXT input module.
*/
static void __exit oxtkbd_cleanup(void)
{
xenbus_unregister_driver(&oxtkbd_driver);
}
module_init(oxtkbd_init);
module_exit(oxtkbd_cleanup);
MODULE_DESCRIPTION("OpenXT Paravirtual Input Device");
MODULE_LICENSE("GPL");