These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / staging / unisys / visorinput / visorinput.c
1 /* visorinput.c
2  *
3  * Copyright (C) 2011 - 2015 UNISYS CORPORATION
4  * All rights reserved.
5  *
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.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13  * NON INFRINGEMENT.  See the GNU General Public License for more
14  * details.
15  */
16
17 /*
18  * This driver lives in a generic guest Linux partition, and registers to
19  * receive keyboard and mouse channels from the visorbus driver.  It reads
20  * inputs from such channels, and delivers it to the Linux OS in the
21  * standard way the Linux expects for input drivers.
22  */
23
24 #include <linux/buffer_head.h>
25 #include <linux/fb.h>
26 #include <linux/fs.h>
27 #include <linux/input.h>
28 #include <linux/uaccess.h>
29 #include <linux/kernel.h>
30 #include <linux/uuid.h>
31
32 #include "version.h"
33 #include "visorbus.h"
34 #include "channel.h"
35 #include "ultrainputreport.h"
36
37 /* Keyboard channel {c73416d0-b0b8-44af-b304-9d2ae99f1b3d} */
38 #define SPAR_KEYBOARD_CHANNEL_PROTOCOL_UUID                             \
39         UUID_LE(0xc73416d0, 0xb0b8, 0x44af,                             \
40                 0xb3, 0x4, 0x9d, 0x2a, 0xe9, 0x9f, 0x1b, 0x3d)
41 #define SPAR_KEYBOARD_CHANNEL_PROTOCOL_UUID_STR "c73416d0-b0b8-44af-b304-9d2ae99f1b3d"
42
43 /* Mouse channel {addf07d4-94a9-46e2-81c3-61abcdbdbd87} */
44 #define SPAR_MOUSE_CHANNEL_PROTOCOL_UUID  \
45         UUID_LE(0xaddf07d4, 0x94a9, 0x46e2, \
46                 0x81, 0xc3, 0x61, 0xab, 0xcd, 0xbd, 0xbd, 0x87)
47 #define SPAR_MOUSE_CHANNEL_PROTOCOL_UUID_STR \
48         "addf07d4-94a9-46e2-81c3-61abcdbdbd87"
49
50 #define PIXELS_ACROSS_DEFAULT   800
51 #define PIXELS_DOWN_DEFAULT     600
52 #define KEYCODE_TABLE_BYTES     256
53
54 enum visorinput_device_type {
55         visorinput_keyboard,
56         visorinput_mouse,
57 };
58
59 /*
60  * This is the private data that we store for each device.
61  * A pointer to this struct is maintained via
62  * dev_get_drvdata() / dev_set_drvdata() for each struct device.
63  */
64 struct visorinput_devdata {
65         struct visor_device *dev;
66         struct rw_semaphore lock_visor_dev; /* lock for dev */
67         struct input_dev *visorinput_dev;
68         bool paused;
69         unsigned int keycode_table_bytes; /* size of following array */
70         /* for keyboard devices: visorkbd_keycode[] + visorkbd_ext_keycode[] */
71         unsigned char keycode_table[0];
72 };
73
74 static const uuid_le spar_keyboard_channel_protocol_uuid =
75         SPAR_KEYBOARD_CHANNEL_PROTOCOL_UUID;
76 static const uuid_le spar_mouse_channel_protocol_uuid =
77         SPAR_MOUSE_CHANNEL_PROTOCOL_UUID;
78
79 /*
80  * Borrowed from drivers/input/keyboard/atakbd.c
81  * This maps 1-byte scancodes to keycodes.
82  */
83 static const unsigned char visorkbd_keycode[KEYCODE_TABLE_BYTES] = {
84         /* American layout */
85         [0] = KEY_GRAVE,
86         [1] = KEY_ESC,
87         [2] = KEY_1,
88         [3] = KEY_2,
89         [4] = KEY_3,
90         [5] = KEY_4,
91         [6] = KEY_5,
92         [7] = KEY_6,
93         [8] = KEY_7,
94         [9] = KEY_8,
95         [10] = KEY_9,
96         [11] = KEY_0,
97         [12] = KEY_MINUS,
98         [13] = KEY_EQUAL,
99         [14] = KEY_BACKSPACE,
100         [15] = KEY_TAB,
101         [16] = KEY_Q,
102         [17] = KEY_W,
103         [18] = KEY_E,
104         [19] = KEY_R,
105         [20] = KEY_T,
106         [21] = KEY_Y,
107         [22] = KEY_U,
108         [23] = KEY_I,
109         [24] = KEY_O,
110         [25] = KEY_P,
111         [26] = KEY_LEFTBRACE,
112         [27] = KEY_RIGHTBRACE,
113         [28] = KEY_ENTER,
114         [29] = KEY_LEFTCTRL,
115         [30] = KEY_A,
116         [31] = KEY_S,
117         [32] = KEY_D,
118         [33] = KEY_F,
119         [34] = KEY_G,
120         [35] = KEY_H,
121         [36] = KEY_J,
122         [37] = KEY_K,
123         [38] = KEY_L,
124         [39] = KEY_SEMICOLON,
125         [40] = KEY_APOSTROPHE,
126         [41] = KEY_GRAVE,       /* FIXME, '#' */
127         [42] = KEY_LEFTSHIFT,
128         [43] = KEY_BACKSLASH,   /* FIXME, '~' */
129         [44] = KEY_Z,
130         [45] = KEY_X,
131         [46] = KEY_C,
132         [47] = KEY_V,
133         [48] = KEY_B,
134         [49] = KEY_N,
135         [50] = KEY_M,
136         [51] = KEY_COMMA,
137         [52] = KEY_DOT,
138         [53] = KEY_SLASH,
139         [54] = KEY_RIGHTSHIFT,
140         [55] = KEY_KPASTERISK,
141         [56] = KEY_LEFTALT,
142         [57] = KEY_SPACE,
143         [58] = KEY_CAPSLOCK,
144         [59] = KEY_F1,
145         [60] = KEY_F2,
146         [61] = KEY_F3,
147         [62] = KEY_F4,
148         [63] = KEY_F5,
149         [64] = KEY_F6,
150         [65] = KEY_F7,
151         [66] = KEY_F8,
152         [67] = KEY_F9,
153         [68] = KEY_F10,
154         [69] = KEY_NUMLOCK,
155         [70] = KEY_SCROLLLOCK,
156         [71] = KEY_KP7,
157         [72] = KEY_KP8,
158         [73] = KEY_KP9,
159         [74] = KEY_KPMINUS,
160         [75] = KEY_KP4,
161         [76] = KEY_KP5,
162         [77] = KEY_KP6,
163         [78] = KEY_KPPLUS,
164         [79] = KEY_KP1,
165         [80] = KEY_KP2,
166         [81] = KEY_KP3,
167         [82] = KEY_KP0,
168         [83] = KEY_KPDOT,
169         [86] = KEY_102ND, /* enables UK backslash+pipe key,
170                            * and FR lessthan+greaterthan key
171                            */
172         [87] = KEY_F11,
173         [88] = KEY_F12,
174         [90] = KEY_KPLEFTPAREN,
175         [91] = KEY_KPRIGHTPAREN,
176         [92] = KEY_KPASTERISK,  /* FIXME */
177         [93] = KEY_KPASTERISK,
178         [94] = KEY_KPPLUS,
179         [95] = KEY_HELP,
180         [96] = KEY_KPENTER,
181         [97] = KEY_RIGHTCTRL,
182         [98] = KEY_KPSLASH,
183         [99] = KEY_KPLEFTPAREN,
184         [100] = KEY_KPRIGHTPAREN,
185         [101] = KEY_KPSLASH,
186         [102] = KEY_HOME,
187         [103] = KEY_UP,
188         [104] = KEY_PAGEUP,
189         [105] = KEY_LEFT,
190         [106] = KEY_RIGHT,
191         [107] = KEY_END,
192         [108] = KEY_DOWN,
193         [109] = KEY_PAGEDOWN,
194         [110] = KEY_INSERT,
195         [111] = KEY_DELETE,
196         [112] = KEY_MACRO,
197         [113] = KEY_MUTE
198 };
199
200 /*
201  * This maps the <xx> in extended scancodes of the form "0xE0 <xx>" into
202  * keycodes.
203  */
204 static const unsigned char visorkbd_ext_keycode[KEYCODE_TABLE_BYTES] = {
205         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,             /* 0x00 */
206         0, 0, 0, 0, 0, 0, 0, 0,                                     /* 0x10 */
207         0, 0, 0, 0, KEY_KPENTER, KEY_RIGHTCTRL, 0, 0,               /* 0x18 */
208         0, 0, 0, 0, 0, 0, 0, 0,                                     /* 0x20 */
209         KEY_RIGHTALT, 0, 0, 0, 0, 0, 0, 0,                          /* 0x28 */
210         0, 0, 0, 0, 0, 0, 0, 0,                                     /* 0x30 */
211         KEY_RIGHTALT /* AltGr */, 0, 0, 0, 0, 0, 0, 0,              /* 0x38 */
212         0, 0, 0, 0, 0, 0, 0, KEY_HOME,                              /* 0x40 */
213         KEY_UP, KEY_PAGEUP, 0, KEY_LEFT, 0, KEY_RIGHT, 0, KEY_END,  /* 0x48 */
214         KEY_DOWN, KEY_PAGEDOWN, KEY_INSERT, KEY_DELETE, 0, 0, 0, 0, /* 0x50 */
215         0, 0, 0, 0, 0, 0, 0, 0,                                     /* 0x58 */
216         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,             /* 0x60 */
217         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,             /* 0x70 */
218 };
219
220 static int visorinput_open(struct input_dev *visorinput_dev)
221 {
222         struct visorinput_devdata *devdata = input_get_drvdata(visorinput_dev);
223
224         if (!devdata) {
225                 pr_err("%s input_get_drvdata(%p) returned NULL\n",
226                        __func__, visorinput_dev);
227                 return -EINVAL;
228         }
229         dev_dbg(&visorinput_dev->dev, "%s opened\n", __func__);
230         visorbus_enable_channel_interrupts(devdata->dev);
231         return 0;
232 }
233
234 static void visorinput_close(struct input_dev *visorinput_dev)
235 {
236         struct visorinput_devdata *devdata = input_get_drvdata(visorinput_dev);
237
238         if (!devdata) {
239                 pr_err("%s input_get_drvdata(%p) returned NULL\n",
240                        __func__, visorinput_dev);
241                 return;
242         }
243         dev_dbg(&visorinput_dev->dev, "%s closed\n", __func__);
244         visorbus_disable_channel_interrupts(devdata->dev);
245 }
246
247 /*
248  * register_client_keyboard() initializes and returns a Linux input node that
249  * we can use to deliver keyboard inputs to Linux.  We of course do this when
250  * we see keyboard inputs coming in on a keyboard channel.
251  */
252 static struct input_dev *
253 register_client_keyboard(void *devdata,  /* opaque on purpose */
254                          unsigned char *keycode_table)
255
256 {
257         int i, error;
258         struct input_dev *visorinput_dev;
259
260         visorinput_dev = input_allocate_device();
261         if (!visorinput_dev)
262                 return NULL;
263
264         visorinput_dev->name = "visor Keyboard";
265         visorinput_dev->phys = "visorkbd:input0";
266         visorinput_dev->id.bustype = BUS_VIRTUAL;
267         visorinput_dev->id.vendor = 0x0001;
268         visorinput_dev->id.product = 0x0001;
269         visorinput_dev->id.version = 0x0100;
270
271         visorinput_dev->evbit[0] = BIT_MASK(EV_KEY) |
272                                    BIT_MASK(EV_REP) |
273                                    BIT_MASK(EV_LED);
274         visorinput_dev->ledbit[0] = BIT_MASK(LED_CAPSL) |
275                                     BIT_MASK(LED_SCROLLL) |
276                                     BIT_MASK(LED_NUML);
277         visorinput_dev->keycode = keycode_table;
278         visorinput_dev->keycodesize = 1; /* sizeof(unsigned char) */
279         visorinput_dev->keycodemax = KEYCODE_TABLE_BYTES;
280
281         for (i = 1; i < visorinput_dev->keycodemax; i++)
282                 set_bit(keycode_table[i], visorinput_dev->keybit);
283         for (i = 1; i < visorinput_dev->keycodemax; i++)
284                 set_bit(keycode_table[i + KEYCODE_TABLE_BYTES],
285                         visorinput_dev->keybit);
286
287         visorinput_dev->open = visorinput_open;
288         visorinput_dev->close = visorinput_close;
289         input_set_drvdata(visorinput_dev, devdata); /* pre input_register! */
290
291         error = input_register_device(visorinput_dev);
292         if (error) {
293                 input_free_device(visorinput_dev);
294                 return NULL;
295         }
296         return visorinput_dev;
297 }
298
299 static struct input_dev *
300 register_client_mouse(void *devdata /* opaque on purpose */)
301 {
302         int error;
303         struct input_dev *visorinput_dev = NULL;
304         int xres, yres;
305         struct fb_info *fb0;
306
307         visorinput_dev = input_allocate_device();
308         if (!visorinput_dev)
309                 return NULL;
310
311         visorinput_dev->name = "visor Mouse";
312         visorinput_dev->phys = "visormou:input0";
313         visorinput_dev->id.bustype = BUS_VIRTUAL;
314         visorinput_dev->id.vendor = 0x0001;
315         visorinput_dev->id.product = 0x0002;
316         visorinput_dev->id.version = 0x0100;
317
318         visorinput_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
319         set_bit(BTN_LEFT, visorinput_dev->keybit);
320         set_bit(BTN_RIGHT, visorinput_dev->keybit);
321         set_bit(BTN_MIDDLE, visorinput_dev->keybit);
322
323         if (registered_fb[0]) {
324                 fb0 = registered_fb[0];
325                 xres = fb0->var.xres_virtual;
326                 yres = fb0->var.yres_virtual;
327         } else {
328                 xres = PIXELS_ACROSS_DEFAULT;
329                 yres = PIXELS_DOWN_DEFAULT;
330         }
331         input_set_abs_params(visorinput_dev, ABS_X, 0, xres, 0, 0);
332         input_set_abs_params(visorinput_dev, ABS_Y, 0, yres, 0, 0);
333
334         visorinput_dev->open = visorinput_open;
335         visorinput_dev->close = visorinput_close;
336         input_set_drvdata(visorinput_dev, devdata); /* pre input_register! */
337
338         error = input_register_device(visorinput_dev);
339         if (error) {
340                 input_free_device(visorinput_dev);
341                 return NULL;
342         }
343
344         input_set_capability(visorinput_dev, EV_REL, REL_WHEEL);
345
346         return visorinput_dev;
347 }
348
349 static struct visorinput_devdata *
350 devdata_create(struct visor_device *dev, enum visorinput_device_type devtype)
351 {
352         struct visorinput_devdata *devdata = NULL;
353         unsigned int extra_bytes = 0;
354
355         if (devtype == visorinput_keyboard)
356                 /* allocate room for devdata->keycode_table, filled in below */
357                 extra_bytes = KEYCODE_TABLE_BYTES * 2;
358         devdata = kzalloc(sizeof(*devdata) + extra_bytes, GFP_KERNEL);
359         if (!devdata)
360                 return NULL;
361         devdata->dev = dev;
362
363         /*
364          * This is an input device in a client guest partition,
365          * so we need to create whatever input nodes are necessary to
366          * deliver our inputs to the guest OS.
367          */
368         switch (devtype) {
369         case visorinput_keyboard:
370                 devdata->keycode_table_bytes = extra_bytes;
371                 memcpy(devdata->keycode_table, visorkbd_keycode,
372                        KEYCODE_TABLE_BYTES);
373                 memcpy(devdata->keycode_table + KEYCODE_TABLE_BYTES,
374                        visorkbd_ext_keycode, KEYCODE_TABLE_BYTES);
375                 devdata->visorinput_dev = register_client_keyboard
376                         (devdata, devdata->keycode_table);
377                 if (!devdata->visorinput_dev)
378                         goto cleanups_register;
379                 break;
380         case visorinput_mouse:
381                 devdata->visorinput_dev = register_client_mouse(devdata);
382                 if (!devdata->visorinput_dev)
383                         goto cleanups_register;
384                 break;
385         }
386
387         init_rwsem(&devdata->lock_visor_dev);
388
389         return devdata;
390
391 cleanups_register:
392         kfree(devdata);
393         return NULL;
394 }
395
396 static int
397 visorinput_probe(struct visor_device *dev)
398 {
399         struct visorinput_devdata *devdata = NULL;
400         uuid_le guid;
401         enum visorinput_device_type devtype;
402
403         guid = visorchannel_get_uuid(dev->visorchannel);
404         if (uuid_le_cmp(guid, spar_mouse_channel_protocol_uuid) == 0)
405                 devtype = visorinput_mouse;
406         else if (uuid_le_cmp(guid, spar_keyboard_channel_protocol_uuid) == 0)
407                 devtype = visorinput_keyboard;
408         else
409                 return -ENODEV;
410         devdata = devdata_create(dev, devtype);
411         if (!devdata)
412                 return -ENOMEM;
413         dev_set_drvdata(&dev->device, devdata);
414         return 0;
415 }
416
417 static void
418 unregister_client_input(struct input_dev *visorinput_dev)
419 {
420         if (visorinput_dev)
421                 input_unregister_device(visorinput_dev);
422 }
423
424 static void
425 visorinput_remove(struct visor_device *dev)
426 {
427         struct visorinput_devdata *devdata = dev_get_drvdata(&dev->device);
428
429         if (!devdata)
430                 return;
431
432         visorbus_disable_channel_interrupts(dev);
433
434         /*
435          * due to above, at this time no thread of execution will be
436          * in visorinput_channel_interrupt()
437          */
438
439         down_write(&devdata->lock_visor_dev);
440         dev_set_drvdata(&dev->device, NULL);
441         unregister_client_input(devdata->visorinput_dev);
442         up_write(&devdata->lock_visor_dev);
443         kfree(devdata);
444 }
445
446 /*
447  * Make it so the current locking state of the locking key indicated by
448  * <keycode> is as indicated by <desired_state> (1=locked, 0=unlocked).
449  */
450 static void
451 handle_locking_key(struct input_dev *visorinput_dev,
452                    int keycode, int desired_state)
453 {
454         int led;
455
456         switch (keycode) {
457         case KEY_CAPSLOCK:
458                 led = LED_CAPSL;
459                 break;
460         case KEY_SCROLLLOCK:
461                 led = LED_SCROLLL;
462                 break;
463         case KEY_NUMLOCK:
464                 led = LED_NUML;
465                 break;
466         default:
467                 led = -1;
468                 break;
469         }
470         if (led >= 0) {
471                 int old_state = (test_bit(led, visorinput_dev->led) != 0);
472
473                 if (old_state != desired_state) {
474                         input_report_key(visorinput_dev, keycode, 1);
475                         input_sync(visorinput_dev);
476                         input_report_key(visorinput_dev, keycode, 0);
477                         input_sync(visorinput_dev);
478                         __change_bit(led, visorinput_dev->led);
479                 }
480         }
481 }
482
483 /*
484  * <scancode> is either a 1-byte scancode, or an extended 16-bit scancode
485  * with 0xE0 in the low byte and the extended scancode value in the next
486  * higher byte.
487  */
488 static int
489 scancode_to_keycode(int scancode)
490 {
491         int keycode;
492
493         if (scancode > 0xff)
494                 keycode = visorkbd_ext_keycode[(scancode >> 8) & 0xff];
495         else
496                 keycode = visorkbd_keycode[scancode];
497         return keycode;
498 }
499
500 static int
501 calc_button(int x)
502 {
503         switch (x) {
504         case 1:
505                 return BTN_LEFT;
506         case 2:
507                 return BTN_MIDDLE;
508         case 3:
509                 return BTN_RIGHT;
510         default:
511                 return -1;
512         }
513 }
514
515 /*
516  * This is used only when this driver is active as an input driver in the
517  * client guest partition.  It is called periodically so we can obtain inputs
518  * from the channel, and deliver them to the guest OS.
519  */
520 static void
521 visorinput_channel_interrupt(struct visor_device *dev)
522 {
523         struct ultra_inputreport r;
524         int scancode, keycode;
525         struct input_dev *visorinput_dev;
526         int xmotion, ymotion, zmotion, button;
527         int i;
528
529         struct visorinput_devdata *devdata = dev_get_drvdata(&dev->device);
530
531         if (!devdata)
532                 return;
533
534         down_write(&devdata->lock_visor_dev);
535         if (devdata->paused) /* don't touch device/channel when paused */
536                 goto out_locked;
537
538         visorinput_dev = devdata->visorinput_dev;
539         if (!visorinput_dev)
540                 goto out_locked;
541
542         while (visorchannel_signalremove(dev->visorchannel, 0, &r)) {
543                 scancode = r.activity.arg1;
544                 keycode = scancode_to_keycode(scancode);
545                 switch (r.activity.action) {
546                 case inputaction_key_down:
547                         input_report_key(visorinput_dev, keycode, 1);
548                         input_sync(visorinput_dev);
549                         break;
550                 case inputaction_key_up:
551                         input_report_key(visorinput_dev, keycode, 0);
552                         input_sync(visorinput_dev);
553                         break;
554                 case inputaction_key_down_up:
555                         input_report_key(visorinput_dev, keycode, 1);
556                         input_sync(visorinput_dev);
557                         input_report_key(visorinput_dev, keycode, 0);
558                         input_sync(visorinput_dev);
559                         break;
560                 case inputaction_set_locking_key_state:
561                         handle_locking_key(visorinput_dev, keycode,
562                                            r.activity.arg2);
563                         break;
564                 case inputaction_xy_motion:
565                         xmotion = r.activity.arg1;
566                         ymotion = r.activity.arg2;
567                         input_report_abs(visorinput_dev, ABS_X, xmotion);
568                         input_report_abs(visorinput_dev, ABS_Y, ymotion);
569                         input_sync(visorinput_dev);
570                         break;
571                 case inputaction_mouse_button_down:
572                         button = calc_button(r.activity.arg1);
573                         if (button < 0)
574                                 break;
575                         input_report_key(visorinput_dev, button, 1);
576                         input_sync(visorinput_dev);
577                         break;
578                 case inputaction_mouse_button_up:
579                         button = calc_button(r.activity.arg1);
580                         if (button < 0)
581                                 break;
582                         input_report_key(visorinput_dev, button, 0);
583                         input_sync(visorinput_dev);
584                         break;
585                 case inputaction_mouse_button_click:
586                         button = calc_button(r.activity.arg1);
587                         if (button < 0)
588                                 break;
589                         input_report_key(visorinput_dev, button, 1);
590
591                         input_sync(visorinput_dev);
592                         input_report_key(visorinput_dev, button, 0);
593                         input_sync(visorinput_dev);
594                         break;
595                 case inputaction_mouse_button_dclick:
596                         button = calc_button(r.activity.arg1);
597                         if (button < 0)
598                                 break;
599                         for (i = 0; i < 2; i++) {
600                                 input_report_key(visorinput_dev, button, 1);
601                                 input_sync(visorinput_dev);
602                                 input_report_key(visorinput_dev, button, 0);
603                                 input_sync(visorinput_dev);
604                         }
605                         break;
606                 case inputaction_wheel_rotate_away:
607                         zmotion = r.activity.arg1;
608                         input_report_rel(visorinput_dev, REL_WHEEL, 1);
609                         input_sync(visorinput_dev);
610                         break;
611                 case inputaction_wheel_rotate_toward:
612                         zmotion = r.activity.arg1;
613                         input_report_rel(visorinput_dev, REL_WHEEL, -1);
614                         input_sync(visorinput_dev);
615                         break;
616                 }
617         }
618 out_locked:
619         up_write(&devdata->lock_visor_dev);
620 }
621
622 static int
623 visorinput_pause(struct visor_device *dev,
624                  visorbus_state_complete_func complete_func)
625 {
626         int rc;
627         struct visorinput_devdata *devdata = dev_get_drvdata(&dev->device);
628
629         if (!devdata) {
630                 rc = -ENODEV;
631                 goto out;
632         }
633
634         down_write(&devdata->lock_visor_dev);
635         if (devdata->paused) {
636                 rc = -EBUSY;
637                 goto out_locked;
638         }
639         devdata->paused = true;
640         complete_func(dev, 0);
641         rc = 0;
642 out_locked:
643         up_write(&devdata->lock_visor_dev);
644 out:
645         return rc;
646 }
647
648 static int
649 visorinput_resume(struct visor_device *dev,
650                   visorbus_state_complete_func complete_func)
651 {
652         int rc;
653         struct visorinput_devdata *devdata = dev_get_drvdata(&dev->device);
654
655         if (!devdata) {
656                 rc = -ENODEV;
657                 goto out;
658         }
659         down_write(&devdata->lock_visor_dev);
660         if (!devdata->paused) {
661                 rc = -EBUSY;
662                 goto out_locked;
663         }
664         devdata->paused = false;
665         complete_func(dev, 0);
666         rc = 0;
667 out_locked:
668         up_write(&devdata->lock_visor_dev);
669 out:
670         return rc;
671 }
672
673 /* GUIDS for all channel types supported by this driver. */
674 static struct visor_channeltype_descriptor visorinput_channel_types[] = {
675         { SPAR_KEYBOARD_CHANNEL_PROTOCOL_UUID, "keyboard"},
676         { SPAR_MOUSE_CHANNEL_PROTOCOL_UUID, "mouse"},
677         { NULL_UUID_LE, NULL }
678 };
679
680 static struct visor_driver visorinput_driver = {
681         .name = "visorinput",
682         .vertag = NULL,
683         .owner = THIS_MODULE,
684         .channel_types = visorinput_channel_types,
685         .probe = visorinput_probe,
686         .remove = visorinput_remove,
687         .channel_interrupt = visorinput_channel_interrupt,
688         .pause = visorinput_pause,
689         .resume = visorinput_resume,
690 };
691
692 static int
693 visorinput_init(void)
694 {
695         return visorbus_register_visor_driver(&visorinput_driver);
696 }
697
698 static void
699 visorinput_cleanup(void)
700 {
701         visorbus_unregister_visor_driver(&visorinput_driver);
702 }
703
704 module_init(visorinput_init);
705 module_exit(visorinput_cleanup);
706
707 MODULE_DEVICE_TABLE(visorbus, visorinput_channel_types);
708
709 MODULE_AUTHOR("Unisys");
710 MODULE_LICENSE("GPL");
711 MODULE_DESCRIPTION("s-Par human input driver for guest Linux");
712 MODULE_VERSION(VERSION);
713
714 MODULE_ALIAS("visorbus:" SPAR_MOUSE_CHANNEL_PROTOCOL_UUID_STR);
715 MODULE_ALIAS("visorbus:" SPAR_KEYBOARD_CHANNEL_PROTOCOL_UUID_STR);