ext4: verify extent header depth
[cascardo/linux.git] / 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,
127         [42] = KEY_LEFTSHIFT,
128         [43] = KEY_BACKSLASH,
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,
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                 dev_err(&visorinput_dev->dev,
226                         "%s input_get_drvdata(%p) returned NULL\n",
227                         __func__, visorinput_dev);
228                 return -EINVAL;
229         }
230         dev_dbg(&visorinput_dev->dev, "%s opened\n", __func__);
231         visorbus_enable_channel_interrupts(devdata->dev);
232         return 0;
233 }
234
235 static void visorinput_close(struct input_dev *visorinput_dev)
236 {
237         struct visorinput_devdata *devdata = input_get_drvdata(visorinput_dev);
238
239         if (!devdata) {
240                 dev_err(&visorinput_dev->dev,
241                         "%s input_get_drvdata(%p) returned NULL\n",
242                         __func__, visorinput_dev);
243                 return;
244         }
245         dev_dbg(&visorinput_dev->dev, "%s closed\n", __func__);
246         visorbus_disable_channel_interrupts(devdata->dev);
247 }
248
249 /*
250  * register_client_keyboard() initializes and returns a Linux input node that
251  * we can use to deliver keyboard inputs to Linux.  We of course do this when
252  * we see keyboard inputs coming in on a keyboard channel.
253  */
254 static struct input_dev *
255 register_client_keyboard(void *devdata,  /* opaque on purpose */
256                          unsigned char *keycode_table)
257
258 {
259         int i, error;
260         struct input_dev *visorinput_dev;
261
262         visorinput_dev = input_allocate_device();
263         if (!visorinput_dev)
264                 return NULL;
265
266         visorinput_dev->name = "visor Keyboard";
267         visorinput_dev->phys = "visorkbd:input0";
268         visorinput_dev->id.bustype = BUS_VIRTUAL;
269         visorinput_dev->id.vendor = 0x0001;
270         visorinput_dev->id.product = 0x0001;
271         visorinput_dev->id.version = 0x0100;
272
273         visorinput_dev->evbit[0] = BIT_MASK(EV_KEY) |
274                                    BIT_MASK(EV_REP) |
275                                    BIT_MASK(EV_LED);
276         visorinput_dev->ledbit[0] = BIT_MASK(LED_CAPSL) |
277                                     BIT_MASK(LED_SCROLLL) |
278                                     BIT_MASK(LED_NUML);
279         visorinput_dev->keycode = keycode_table;
280         visorinput_dev->keycodesize = 1; /* sizeof(unsigned char) */
281         visorinput_dev->keycodemax = KEYCODE_TABLE_BYTES;
282
283         for (i = 1; i < visorinput_dev->keycodemax; i++)
284                 set_bit(keycode_table[i], visorinput_dev->keybit);
285         for (i = 1; i < visorinput_dev->keycodemax; i++)
286                 set_bit(keycode_table[i + KEYCODE_TABLE_BYTES],
287                         visorinput_dev->keybit);
288
289         visorinput_dev->open = visorinput_open;
290         visorinput_dev->close = visorinput_close;
291         input_set_drvdata(visorinput_dev, devdata); /* pre input_register! */
292
293         error = input_register_device(visorinput_dev);
294         if (error) {
295                 input_free_device(visorinput_dev);
296                 return NULL;
297         }
298         return visorinput_dev;
299 }
300
301 static struct input_dev *
302 register_client_mouse(void *devdata /* opaque on purpose */)
303 {
304         int error;
305         struct input_dev *visorinput_dev = NULL;
306         int xres, yres;
307         struct fb_info *fb0;
308
309         visorinput_dev = input_allocate_device();
310         if (!visorinput_dev)
311                 return NULL;
312
313         visorinput_dev->name = "visor Mouse";
314         visorinput_dev->phys = "visormou:input0";
315         visorinput_dev->id.bustype = BUS_VIRTUAL;
316         visorinput_dev->id.vendor = 0x0001;
317         visorinput_dev->id.product = 0x0002;
318         visorinput_dev->id.version = 0x0100;
319
320         visorinput_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
321         set_bit(BTN_LEFT, visorinput_dev->keybit);
322         set_bit(BTN_RIGHT, visorinput_dev->keybit);
323         set_bit(BTN_MIDDLE, visorinput_dev->keybit);
324
325         if (registered_fb[0]) {
326                 fb0 = registered_fb[0];
327                 xres = fb0->var.xres_virtual;
328                 yres = fb0->var.yres_virtual;
329         } else {
330                 xres = PIXELS_ACROSS_DEFAULT;
331                 yres = PIXELS_DOWN_DEFAULT;
332         }
333         input_set_abs_params(visorinput_dev, ABS_X, 0, xres, 0, 0);
334         input_set_abs_params(visorinput_dev, ABS_Y, 0, yres, 0, 0);
335
336         visorinput_dev->open = visorinput_open;
337         visorinput_dev->close = visorinput_close;
338         input_set_drvdata(visorinput_dev, devdata); /* pre input_register! */
339
340         error = input_register_device(visorinput_dev);
341         if (error) {
342                 input_free_device(visorinput_dev);
343                 return NULL;
344         }
345
346         input_set_capability(visorinput_dev, EV_REL, REL_WHEEL);
347
348         return visorinput_dev;
349 }
350
351 static struct visorinput_devdata *
352 devdata_create(struct visor_device *dev, enum visorinput_device_type devtype)
353 {
354         struct visorinput_devdata *devdata = NULL;
355         unsigned int extra_bytes = 0;
356
357         if (devtype == visorinput_keyboard)
358                 /* allocate room for devdata->keycode_table, filled in below */
359                 extra_bytes = KEYCODE_TABLE_BYTES * 2;
360         devdata = kzalloc(sizeof(*devdata) + extra_bytes, GFP_KERNEL);
361         if (!devdata)
362                 return NULL;
363         devdata->dev = dev;
364
365         /*
366          * This is an input device in a client guest partition,
367          * so we need to create whatever input nodes are necessary to
368          * deliver our inputs to the guest OS.
369          */
370         switch (devtype) {
371         case visorinput_keyboard:
372                 devdata->keycode_table_bytes = extra_bytes;
373                 memcpy(devdata->keycode_table, visorkbd_keycode,
374                        KEYCODE_TABLE_BYTES);
375                 memcpy(devdata->keycode_table + KEYCODE_TABLE_BYTES,
376                        visorkbd_ext_keycode, KEYCODE_TABLE_BYTES);
377                 devdata->visorinput_dev = register_client_keyboard
378                         (devdata, devdata->keycode_table);
379                 if (!devdata->visorinput_dev)
380                         goto cleanups_register;
381                 break;
382         case visorinput_mouse:
383                 devdata->visorinput_dev = register_client_mouse(devdata);
384                 if (!devdata->visorinput_dev)
385                         goto cleanups_register;
386                 break;
387         }
388
389         init_rwsem(&devdata->lock_visor_dev);
390
391         return devdata;
392
393 cleanups_register:
394         kfree(devdata);
395         return NULL;
396 }
397
398 static int
399 visorinput_probe(struct visor_device *dev)
400 {
401         struct visorinput_devdata *devdata = NULL;
402         uuid_le guid;
403         enum visorinput_device_type devtype;
404
405         guid = visorchannel_get_uuid(dev->visorchannel);
406         if (uuid_le_cmp(guid, spar_mouse_channel_protocol_uuid) == 0)
407                 devtype = visorinput_mouse;
408         else if (uuid_le_cmp(guid, spar_keyboard_channel_protocol_uuid) == 0)
409                 devtype = visorinput_keyboard;
410         else
411                 return -ENODEV;
412         devdata = devdata_create(dev, devtype);
413         if (!devdata)
414                 return -ENOMEM;
415         dev_set_drvdata(&dev->device, devdata);
416         return 0;
417 }
418
419 static void
420 unregister_client_input(struct input_dev *visorinput_dev)
421 {
422         if (visorinput_dev)
423                 input_unregister_device(visorinput_dev);
424 }
425
426 static void
427 visorinput_remove(struct visor_device *dev)
428 {
429         struct visorinput_devdata *devdata = dev_get_drvdata(&dev->device);
430
431         if (!devdata)
432                 return;
433
434         visorbus_disable_channel_interrupts(dev);
435
436         /*
437          * due to above, at this time no thread of execution will be
438          * in visorinput_channel_interrupt()
439          */
440
441         down_write(&devdata->lock_visor_dev);
442         dev_set_drvdata(&dev->device, NULL);
443         unregister_client_input(devdata->visorinput_dev);
444         up_write(&devdata->lock_visor_dev);
445         kfree(devdata);
446 }
447
448 /*
449  * Make it so the current locking state of the locking key indicated by
450  * <keycode> is as indicated by <desired_state> (1=locked, 0=unlocked).
451  */
452 static void
453 handle_locking_key(struct input_dev *visorinput_dev,
454                    int keycode, int desired_state)
455 {
456         int led;
457
458         switch (keycode) {
459         case KEY_CAPSLOCK:
460                 led = LED_CAPSL;
461                 break;
462         case KEY_SCROLLLOCK:
463                 led = LED_SCROLLL;
464                 break;
465         case KEY_NUMLOCK:
466                 led = LED_NUML;
467                 break;
468         default:
469                 led = -1;
470                 return;
471         }
472         if (test_bit(led, visorinput_dev->led) != desired_state) {
473                 input_report_key(visorinput_dev, keycode, 1);
474                 input_sync(visorinput_dev);
475                 input_report_key(visorinput_dev, keycode, 0);
476                 input_sync(visorinput_dev);
477                 __change_bit(led, visorinput_dev->led);
478         }
479 }
480
481 /*
482  * <scancode> is either a 1-byte scancode, or an extended 16-bit scancode
483  * with 0xE0 in the low byte and the extended scancode value in the next
484  * higher byte.
485  */
486 static int
487 scancode_to_keycode(int scancode)
488 {
489         int keycode;
490
491         if (scancode > 0xff)
492                 keycode = visorkbd_ext_keycode[(scancode >> 8) & 0xff];
493         else
494                 keycode = visorkbd_keycode[scancode];
495         return keycode;
496 }
497
498 static int
499 calc_button(int x)
500 {
501         switch (x) {
502         case 1:
503                 return BTN_LEFT;
504         case 2:
505                 return BTN_MIDDLE;
506         case 3:
507                 return BTN_RIGHT;
508         default:
509                 return -1;
510         }
511 }
512
513 /*
514  * This is used only when this driver is active as an input driver in the
515  * client guest partition.  It is called periodically so we can obtain inputs
516  * from the channel, and deliver them to the guest OS.
517  */
518 static void
519 visorinput_channel_interrupt(struct visor_device *dev)
520 {
521         struct ultra_inputreport r;
522         int scancode, keycode;
523         struct input_dev *visorinput_dev;
524         int xmotion, ymotion, button;
525         int i;
526
527         struct visorinput_devdata *devdata = dev_get_drvdata(&dev->device);
528
529         if (!devdata)
530                 return;
531
532         down_write(&devdata->lock_visor_dev);
533         if (devdata->paused) /* don't touch device/channel when paused */
534                 goto out_locked;
535
536         visorinput_dev = devdata->visorinput_dev;
537         if (!visorinput_dev)
538                 goto out_locked;
539
540         while (visorchannel_signalremove(dev->visorchannel, 0, &r)) {
541                 scancode = r.activity.arg1;
542                 keycode = scancode_to_keycode(scancode);
543                 switch (r.activity.action) {
544                 case inputaction_key_down:
545                         input_report_key(visorinput_dev, keycode, 1);
546                         input_sync(visorinput_dev);
547                         break;
548                 case inputaction_key_up:
549                         input_report_key(visorinput_dev, keycode, 0);
550                         input_sync(visorinput_dev);
551                         break;
552                 case inputaction_key_down_up:
553                         input_report_key(visorinput_dev, keycode, 1);
554                         input_sync(visorinput_dev);
555                         input_report_key(visorinput_dev, keycode, 0);
556                         input_sync(visorinput_dev);
557                         break;
558                 case inputaction_set_locking_key_state:
559                         handle_locking_key(visorinput_dev, keycode,
560                                            r.activity.arg2);
561                         break;
562                 case inputaction_xy_motion:
563                         xmotion = r.activity.arg1;
564                         ymotion = r.activity.arg2;
565                         input_report_abs(visorinput_dev, ABS_X, xmotion);
566                         input_report_abs(visorinput_dev, ABS_Y, ymotion);
567                         input_sync(visorinput_dev);
568                         break;
569                 case inputaction_mouse_button_down:
570                         button = calc_button(r.activity.arg1);
571                         if (button < 0)
572                                 break;
573                         input_report_key(visorinput_dev, button, 1);
574                         input_sync(visorinput_dev);
575                         break;
576                 case inputaction_mouse_button_up:
577                         button = calc_button(r.activity.arg1);
578                         if (button < 0)
579                                 break;
580                         input_report_key(visorinput_dev, button, 0);
581                         input_sync(visorinput_dev);
582                         break;
583                 case inputaction_mouse_button_click:
584                         button = calc_button(r.activity.arg1);
585                         if (button < 0)
586                                 break;
587                         input_report_key(visorinput_dev, button, 1);
588
589                         input_sync(visorinput_dev);
590                         input_report_key(visorinput_dev, button, 0);
591                         input_sync(visorinput_dev);
592                         break;
593                 case inputaction_mouse_button_dclick:
594                         button = calc_button(r.activity.arg1);
595                         if (button < 0)
596                                 break;
597                         for (i = 0; i < 2; i++) {
598                                 input_report_key(visorinput_dev, button, 1);
599                                 input_sync(visorinput_dev);
600                                 input_report_key(visorinput_dev, button, 0);
601                                 input_sync(visorinput_dev);
602                         }
603                         break;
604                 case inputaction_wheel_rotate_away:
605                         input_report_rel(visorinput_dev, REL_WHEEL, 1);
606                         input_sync(visorinput_dev);
607                         break;
608                 case inputaction_wheel_rotate_toward:
609                         input_report_rel(visorinput_dev, REL_WHEEL, -1);
610                         input_sync(visorinput_dev);
611                         break;
612                 }
613         }
614 out_locked:
615         up_write(&devdata->lock_visor_dev);
616 }
617
618 static int
619 visorinput_pause(struct visor_device *dev,
620                  visorbus_state_complete_func complete_func)
621 {
622         int rc;
623         struct visorinput_devdata *devdata = dev_get_drvdata(&dev->device);
624
625         if (!devdata) {
626                 rc = -ENODEV;
627                 goto out;
628         }
629
630         down_write(&devdata->lock_visor_dev);
631         if (devdata->paused) {
632                 rc = -EBUSY;
633                 goto out_locked;
634         }
635         devdata->paused = true;
636         complete_func(dev, 0);
637         rc = 0;
638 out_locked:
639         up_write(&devdata->lock_visor_dev);
640 out:
641         return rc;
642 }
643
644 static int
645 visorinput_resume(struct visor_device *dev,
646                   visorbus_state_complete_func complete_func)
647 {
648         int rc;
649         struct visorinput_devdata *devdata = dev_get_drvdata(&dev->device);
650
651         if (!devdata) {
652                 rc = -ENODEV;
653                 goto out;
654         }
655         down_write(&devdata->lock_visor_dev);
656         if (!devdata->paused) {
657                 rc = -EBUSY;
658                 goto out_locked;
659         }
660         devdata->paused = false;
661         complete_func(dev, 0);
662         rc = 0;
663 out_locked:
664         up_write(&devdata->lock_visor_dev);
665 out:
666         return rc;
667 }
668
669 /* GUIDS for all channel types supported by this driver. */
670 static struct visor_channeltype_descriptor visorinput_channel_types[] = {
671         { SPAR_KEYBOARD_CHANNEL_PROTOCOL_UUID, "keyboard"},
672         { SPAR_MOUSE_CHANNEL_PROTOCOL_UUID, "mouse"},
673         { NULL_UUID_LE, NULL }
674 };
675
676 static struct visor_driver visorinput_driver = {
677         .name = "visorinput",
678         .vertag = NULL,
679         .owner = THIS_MODULE,
680         .channel_types = visorinput_channel_types,
681         .probe = visorinput_probe,
682         .remove = visorinput_remove,
683         .channel_interrupt = visorinput_channel_interrupt,
684         .pause = visorinput_pause,
685         .resume = visorinput_resume,
686 };
687
688 static int
689 visorinput_init(void)
690 {
691         return visorbus_register_visor_driver(&visorinput_driver);
692 }
693
694 static void
695 visorinput_cleanup(void)
696 {
697         visorbus_unregister_visor_driver(&visorinput_driver);
698 }
699
700 module_init(visorinput_init);
701 module_exit(visorinput_cleanup);
702
703 MODULE_DEVICE_TABLE(visorbus, visorinput_channel_types);
704
705 MODULE_AUTHOR("Unisys");
706 MODULE_LICENSE("GPL");
707 MODULE_DESCRIPTION("s-Par human input driver for guest Linux");
708 MODULE_VERSION(VERSION);
709
710 MODULE_ALIAS("visorbus:" SPAR_MOUSE_CHANNEL_PROTOCOL_UUID_STR);
711 MODULE_ALIAS("visorbus:" SPAR_KEYBOARD_CHANNEL_PROTOCOL_UUID_STR);