ia64/linux-2.6.18-xen.hg

view drivers/xen/fbfront/xenkbd.c @ 470:5baef0e18e36

xenbus: prevent warnings on unhandled enumeration values

XenbusStateReconfiguring/XenbusStateReconfigured were introduced by
c/s 437, but aren't handled in many switch statements. This c/s also
introduced a possibly un-referenced label, which also gets eliminated
here.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Mar 05 17:28:41 2008 +0000 (2008-03-05)
parents 57dfe0098000
children ba72914de93a
line source
1 /*
2 * linux/drivers/input/keyboard/xenkbd.c -- Xen para-virtual input device
3 *
4 * Copyright (C) 2005 Anthony Liguori <aliguori@us.ibm.com>
5 * Copyright (C) 2006 Red Hat, Inc., Markus Armbruster <armbru@redhat.com>
6 *
7 * Based on linux/drivers/input/mouse/sermouse.c
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of this archive for
11 * more details.
12 */
14 /*
15 * TODO:
16 *
17 * Switch to grant tables together with xenfb.c.
18 */
20 #include <linux/kernel.h>
21 #include <linux/errno.h>
22 #include <linux/module.h>
23 #include <linux/input.h>
24 #include <asm/hypervisor.h>
25 #include <xen/evtchn.h>
26 #include <xen/interface/io/fbif.h>
27 #include <xen/interface/io/kbdif.h>
28 #include <xen/xenbus.h>
30 struct xenkbd_info
31 {
32 struct input_dev *kbd;
33 struct input_dev *ptr;
34 struct xenkbd_page *page;
35 int irq;
36 struct xenbus_device *xbdev;
37 char phys[32];
38 };
40 static int xenkbd_remove(struct xenbus_device *);
41 static int xenkbd_connect_backend(struct xenbus_device *, struct xenkbd_info *);
42 static void xenkbd_disconnect_backend(struct xenkbd_info *);
44 /*
45 * Note: if you need to send out events, see xenfb_do_update() for how
46 * to do that.
47 */
49 static irqreturn_t input_handler(int rq, void *dev_id, struct pt_regs *regs)
50 {
51 struct xenkbd_info *info = dev_id;
52 struct xenkbd_page *page = info->page;
53 __u32 cons, prod;
55 prod = page->in_prod;
56 if (prod == page->in_cons)
57 return IRQ_HANDLED;
58 rmb(); /* ensure we see ring contents up to prod */
59 for (cons = page->in_cons; cons != prod; cons++) {
60 union xenkbd_in_event *event;
61 struct input_dev *dev;
62 event = &XENKBD_IN_RING_REF(page, cons);
64 dev = info->ptr;
65 switch (event->type) {
66 case XENKBD_TYPE_MOTION:
67 if (event->motion.rel_z)
68 input_report_rel(dev, REL_WHEEL,
69 -event->motion.rel_z);
70 input_report_rel(dev, REL_X, event->motion.rel_x);
71 input_report_rel(dev, REL_Y, event->motion.rel_y);
72 break;
73 case XENKBD_TYPE_KEY:
74 dev = NULL;
75 if (test_bit(event->key.keycode, info->kbd->keybit))
76 dev = info->kbd;
77 if (test_bit(event->key.keycode, info->ptr->keybit))
78 dev = info->ptr;
79 if (dev)
80 input_report_key(dev, event->key.keycode,
81 event->key.pressed);
82 else
83 printk("xenkbd: unhandled keycode 0x%x\n",
84 event->key.keycode);
85 break;
86 case XENKBD_TYPE_POS:
87 if (event->pos.rel_z)
88 input_report_rel(dev, REL_WHEEL,
89 -event->pos.rel_z);
90 input_report_abs(dev, ABS_X, event->pos.abs_x);
91 input_report_abs(dev, ABS_Y, event->pos.abs_y);
92 break;
93 }
94 if (dev)
95 input_sync(dev);
96 }
97 mb(); /* ensure we got ring contents */
98 page->in_cons = cons;
99 notify_remote_via_irq(info->irq);
101 return IRQ_HANDLED;
102 }
104 int __devinit xenkbd_probe(struct xenbus_device *dev,
105 const struct xenbus_device_id *id)
106 {
107 int ret, i;
108 struct xenkbd_info *info;
109 struct input_dev *kbd, *ptr;
111 info = kzalloc(sizeof(*info), GFP_KERNEL);
112 if (!info) {
113 xenbus_dev_fatal(dev, -ENOMEM, "allocating info structure");
114 return -ENOMEM;
115 }
116 dev->dev.driver_data = info;
117 info->xbdev = dev;
118 snprintf(info->phys, sizeof(info->phys), "xenbus/%s", dev->nodename);
120 info->page = (void *)__get_free_page(GFP_KERNEL);
121 if (!info->page)
122 goto error_nomem;
123 info->page->in_cons = info->page->in_prod = 0;
124 info->page->out_cons = info->page->out_prod = 0;
126 /* keyboard */
127 kbd = input_allocate_device();
128 if (!kbd)
129 goto error_nomem;
130 kbd->name = "Xen Virtual Keyboard";
131 kbd->phys = info->phys;
132 kbd->id.bustype = BUS_PCI;
133 kbd->id.vendor = 0x5853;
134 kbd->id.product = 0xffff;
135 kbd->evbit[0] = BIT(EV_KEY);
136 for (i = KEY_ESC; i < KEY_UNKNOWN; i++)
137 set_bit(i, kbd->keybit);
138 for (i = KEY_OK; i < KEY_MAX; i++)
139 set_bit(i, kbd->keybit);
141 ret = input_register_device(kbd);
142 if (ret) {
143 input_free_device(kbd);
144 xenbus_dev_fatal(dev, ret, "input_register_device(kbd)");
145 goto error;
146 }
147 info->kbd = kbd;
149 /* pointing device */
150 ptr = input_allocate_device();
151 if (!ptr)
152 goto error_nomem;
153 ptr->name = "Xen Virtual Pointer";
154 ptr->phys = info->phys;
155 ptr->id.bustype = BUS_PCI;
156 ptr->id.vendor = 0x5853;
157 ptr->id.product = 0xfffe;
158 ptr->evbit[0] = BIT(EV_KEY) | BIT(EV_REL) | BIT(EV_ABS);
159 for (i = BTN_LEFT; i <= BTN_TASK; i++)
160 set_bit(i, ptr->keybit);
161 ptr->relbit[0] = BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL);
162 input_set_abs_params(ptr, ABS_X, 0, XENFB_WIDTH, 0, 0);
163 input_set_abs_params(ptr, ABS_Y, 0, XENFB_HEIGHT, 0, 0);
165 ret = input_register_device(ptr);
166 if (ret) {
167 input_free_device(ptr);
168 xenbus_dev_fatal(dev, ret, "input_register_device(ptr)");
169 goto error;
170 }
171 info->ptr = ptr;
173 ret = xenkbd_connect_backend(dev, info);
174 if (ret < 0)
175 goto error;
177 return 0;
179 error_nomem:
180 ret = -ENOMEM;
181 xenbus_dev_fatal(dev, ret, "allocating device memory");
182 error:
183 xenkbd_remove(dev);
184 return ret;
185 }
187 static int xenkbd_resume(struct xenbus_device *dev)
188 {
189 struct xenkbd_info *info = dev->dev.driver_data;
191 xenkbd_disconnect_backend(info);
192 info->page->in_cons = info->page->in_prod = 0;
193 info->page->out_cons = info->page->out_prod = 0;
194 return xenkbd_connect_backend(dev, info);
195 }
197 static int xenkbd_remove(struct xenbus_device *dev)
198 {
199 struct xenkbd_info *info = dev->dev.driver_data;
201 xenkbd_disconnect_backend(info);
202 input_unregister_device(info->kbd);
203 input_unregister_device(info->ptr);
204 free_page((unsigned long)info->page);
205 kfree(info);
206 return 0;
207 }
209 static int xenkbd_connect_backend(struct xenbus_device *dev,
210 struct xenkbd_info *info)
211 {
212 int ret;
213 struct xenbus_transaction xbt;
215 ret = bind_listening_port_to_irqhandler(
216 dev->otherend_id, input_handler, 0, "xenkbd", info);
217 if (ret < 0) {
218 xenbus_dev_fatal(dev, ret,
219 "bind_listening_port_to_irqhandler");
220 return ret;
221 }
222 info->irq = ret;
224 again:
225 ret = xenbus_transaction_start(&xbt);
226 if (ret) {
227 xenbus_dev_fatal(dev, ret, "starting transaction");
228 return ret;
229 }
230 ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
231 virt_to_mfn(info->page));
232 if (ret)
233 goto error_xenbus;
234 ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u",
235 irq_to_evtchn_port(info->irq));
236 if (ret)
237 goto error_xenbus;
238 ret = xenbus_transaction_end(xbt, 0);
239 if (ret) {
240 if (ret == -EAGAIN)
241 goto again;
242 xenbus_dev_fatal(dev, ret, "completing transaction");
243 return ret;
244 }
246 xenbus_switch_state(dev, XenbusStateInitialised);
247 return 0;
249 error_xenbus:
250 xenbus_transaction_end(xbt, 1);
251 xenbus_dev_fatal(dev, ret, "writing xenstore");
252 return ret;
253 }
255 static void xenkbd_disconnect_backend(struct xenkbd_info *info)
256 {
257 if (info->irq >= 0)
258 unbind_from_irqhandler(info->irq, info);
259 info->irq = -1;
260 }
262 static void xenkbd_backend_changed(struct xenbus_device *dev,
263 enum xenbus_state backend_state)
264 {
265 struct xenkbd_info *info = dev->dev.driver_data;
266 int ret, val;
268 switch (backend_state) {
269 case XenbusStateInitialising:
270 case XenbusStateInitialised:
271 case XenbusStateReconfiguring:
272 case XenbusStateReconfigured:
273 case XenbusStateUnknown:
274 case XenbusStateClosed:
275 break;
277 case XenbusStateInitWait:
278 InitWait:
279 ret = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
280 "feature-abs-pointer", "%d", &val);
281 if (ret < 0)
282 val = 0;
283 if (val) {
284 ret = xenbus_printf(XBT_NIL, info->xbdev->nodename,
285 "request-abs-pointer", "1");
286 if (ret)
287 ; /* FIXME */
288 }
289 xenbus_switch_state(dev, XenbusStateConnected);
290 break;
292 case XenbusStateConnected:
293 /*
294 * Work around xenbus race condition: If backend goes
295 * through InitWait to Connected fast enough, we can
296 * get Connected twice here.
297 */
298 if (dev->state != XenbusStateConnected)
299 goto InitWait; /* no InitWait seen yet, fudge it */
300 break;
302 case XenbusStateClosing:
303 xenbus_frontend_closed(dev);
304 break;
305 }
306 }
308 static struct xenbus_device_id xenkbd_ids[] = {
309 { "vkbd" },
310 { "" }
311 };
312 MODULE_ALIAS("xen:vkbd");
314 static struct xenbus_driver xenkbd = {
315 .name = "vkbd",
316 .owner = THIS_MODULE,
317 .ids = xenkbd_ids,
318 .probe = xenkbd_probe,
319 .remove = xenkbd_remove,
320 .resume = xenkbd_resume,
321 .otherend_changed = xenkbd_backend_changed,
322 };
324 static int __init xenkbd_init(void)
325 {
326 if (!is_running_on_xen())
327 return -ENODEV;
329 /* Nothing to do if running in dom0. */
330 if (is_initial_xendomain())
331 return -ENODEV;
333 return xenbus_register_frontend(&xenkbd);
334 }
336 static void __exit xenkbd_cleanup(void)
337 {
338 return xenbus_unregister_driver(&xenkbd);
339 }
341 module_init(xenkbd_init);
342 module_exit(xenkbd_cleanup);
344 MODULE_LICENSE("GPL");