ACPI: thinkpad-acpi: allow use of CMOS NVRAM for brightness control
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / char / hvc_lguest.c
blobe7b889e404a7ec80d498a34f20302dc0ac03d3b8
1 /* Simple console for lguest.
3 * Copyright (C) 2006 Rusty Russell, IBM Corporation
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include <linux/err.h>
20 #include <linux/init.h>
21 #include <linux/lguest_bus.h>
22 #include "hvc_console.h"
24 static char inbuf[256];
25 static struct lguest_dma cons_input = { .used_len = 0,
26 .addr[0] = __pa(inbuf),
27 .len[0] = sizeof(inbuf),
28 .len[1] = 0 };
30 static int put_chars(u32 vtermno, const char *buf, int count)
32 struct lguest_dma dma;
34 /* FIXME: what if it's over a page boundary? */
35 dma.len[0] = count;
36 dma.len[1] = 0;
37 dma.addr[0] = __pa(buf);
39 lguest_send_dma(LGUEST_CONSOLE_DMA_KEY, &dma);
40 return count;
43 static int get_chars(u32 vtermno, char *buf, int count)
45 static int cons_offset;
47 if (!cons_input.used_len)
48 return 0;
50 if (cons_input.used_len - cons_offset < count)
51 count = cons_input.used_len - cons_offset;
53 memcpy(buf, inbuf + cons_offset, count);
54 cons_offset += count;
55 if (cons_offset == cons_input.used_len) {
56 cons_offset = 0;
57 cons_input.used_len = 0;
59 return count;
62 static struct hv_ops lguest_cons = {
63 .get_chars = get_chars,
64 .put_chars = put_chars,
67 static int __init cons_init(void)
69 if (strcmp(paravirt_ops.name, "lguest") != 0)
70 return 0;
72 return hvc_instantiate(0, 0, &lguest_cons);
74 console_initcall(cons_init);
76 static int lguestcons_probe(struct lguest_device *lgdev)
78 int err;
80 lgdev->private = hvc_alloc(0, lgdev_irq(lgdev), &lguest_cons, 256);
81 if (IS_ERR(lgdev->private))
82 return PTR_ERR(lgdev->private);
84 err = lguest_bind_dma(LGUEST_CONSOLE_DMA_KEY, &cons_input, 1,
85 lgdev_irq(lgdev));
86 if (err)
87 printk("lguest console: failed to bind buffer.\n");
88 return err;
91 static struct lguest_driver lguestcons_drv = {
92 .name = "lguestcons",
93 .owner = THIS_MODULE,
94 .device_type = LGUEST_DEVICE_T_CONSOLE,
95 .probe = lguestcons_probe,
98 static int __init hvc_lguest_init(void)
100 return register_lguest_driver(&lguestcons_drv);
102 module_init(hvc_lguest_init);