aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/Kconfig16
-rw-r--r--drivers/char/Makefile2
-rw-r--r--drivers/char/bsr.c84
-rw-r--r--drivers/char/hvc_console.c13
-rw-r--r--drivers/char/hvc_console.h2
-rw-r--r--drivers/char/hvc_iseries.c4
-rw-r--r--drivers/char/hvc_iucv.c850
-rw-r--r--drivers/char/hvc_udbg.c96
-rw-r--r--drivers/char/hvc_vio.c4
-rw-r--r--drivers/char/hvcs.c2
-rw-r--r--drivers/char/hvsi.c2
-rw-r--r--drivers/char/nvram.c264
-rw-r--r--drivers/char/tty_audit.c76
-rw-r--r--drivers/char/tty_io.c1
14 files changed, 1220 insertions, 196 deletions
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 43d6ba83a191..c602b547cc6e 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -622,6 +622,16 @@ config HVC_BEAT
622 help 622 help
623 Toshiba's Cell Reference Set Beat Console device driver 623 Toshiba's Cell Reference Set Beat Console device driver
624 624
625config HVC_IUCV
626 bool "z/VM IUCV Hypervisor console support (VM only)"
627 depends on S390
628 select HVC_DRIVER
629 select IUCV
630 default y
631 help
632 This driver provides a Hypervisor console (HVC) back-end to access
633 a Linux (console) terminal via a z/VM IUCV communication path.
634
625config HVC_XEN 635config HVC_XEN
626 bool "Xen Hypervisor Console support" 636 bool "Xen Hypervisor Console support"
627 depends on XEN 637 depends on XEN
@@ -631,6 +641,12 @@ config HVC_XEN
631 help 641 help
632 Xen virtual console device driver 642 Xen virtual console device driver
633 643
644config HVC_UDBG
645 bool "udbg based fake hypervisor console"
646 depends on PPC && EXPERIMENTAL
647 select HVC_DRIVER
648 default n
649
634config VIRTIO_CONSOLE 650config VIRTIO_CONSOLE
635 tristate "Virtio console" 651 tristate "Virtio console"
636 depends on VIRTIO 652 depends on VIRTIO
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 438f71317c5c..9caf5b5ad1c0 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -50,6 +50,8 @@ obj-$(CONFIG_HVC_BEAT) += hvc_beat.o
50obj-$(CONFIG_HVC_DRIVER) += hvc_console.o 50obj-$(CONFIG_HVC_DRIVER) += hvc_console.o
51obj-$(CONFIG_HVC_IRQ) += hvc_irq.o 51obj-$(CONFIG_HVC_IRQ) += hvc_irq.o
52obj-$(CONFIG_HVC_XEN) += hvc_xen.o 52obj-$(CONFIG_HVC_XEN) += hvc_xen.o
53obj-$(CONFIG_HVC_IUCV) += hvc_iucv.o
54obj-$(CONFIG_HVC_UDBG) += hvc_udbg.o
53obj-$(CONFIG_VIRTIO_CONSOLE) += virtio_console.o 55obj-$(CONFIG_VIRTIO_CONSOLE) += virtio_console.o
54obj-$(CONFIG_RAW_DRIVER) += raw.o 56obj-$(CONFIG_RAW_DRIVER) += raw.o
55obj-$(CONFIG_SGI_SNSC) += snsc.o snsc_event.o 57obj-$(CONFIG_SGI_SNSC) += snsc.o snsc_event.o
diff --git a/drivers/char/bsr.c b/drivers/char/bsr.c
index 456f54db73e2..977dfb1096a0 100644
--- a/drivers/char/bsr.c
+++ b/drivers/char/bsr.c
@@ -60,6 +60,8 @@ struct bsr_dev {
60 unsigned bsr_num; /* bsr id number for its type */ 60 unsigned bsr_num; /* bsr id number for its type */
61 int bsr_minor; 61 int bsr_minor;
62 62
63 struct list_head bsr_list;
64
63 dev_t bsr_dev; 65 dev_t bsr_dev;
64 struct cdev bsr_cdev; 66 struct cdev bsr_cdev;
65 struct device *bsr_device; 67 struct device *bsr_device;
@@ -67,8 +69,8 @@ struct bsr_dev {
67 69
68}; 70};
69 71
70static unsigned num_bsr_devs; 72static unsigned total_bsr_devs;
71static struct bsr_dev *bsr_devs; 73static struct list_head bsr_devs = LIST_HEAD_INIT(bsr_devs);
72static struct class *bsr_class; 74static struct class *bsr_class;
73static int bsr_major; 75static int bsr_major;
74 76
@@ -146,24 +148,25 @@ const static struct file_operations bsr_fops = {
146 148
147static void bsr_cleanup_devs(void) 149static void bsr_cleanup_devs(void)
148{ 150{
149 int i; 151 struct bsr_dev *cur, *n;
150 for (i=0 ; i < num_bsr_devs; i++) { 152
151 struct bsr_dev *cur = bsr_devs + i; 153 list_for_each_entry_safe(cur, n, &bsr_devs, bsr_list) {
152 if (cur->bsr_device) { 154 if (cur->bsr_device) {
153 cdev_del(&cur->bsr_cdev); 155 cdev_del(&cur->bsr_cdev);
154 device_del(cur->bsr_device); 156 device_del(cur->bsr_device);
155 } 157 }
158 list_del(&cur->bsr_list);
159 kfree(cur);
156 } 160 }
157
158 kfree(bsr_devs);
159} 161}
160 162
161static int bsr_create_devs(struct device_node *bn) 163static int bsr_add_node(struct device_node *bn)
162{ 164{
163 int bsr_stride_len, bsr_bytes_len; 165 int bsr_stride_len, bsr_bytes_len, num_bsr_devs;
164 const u32 *bsr_stride; 166 const u32 *bsr_stride;
165 const u32 *bsr_bytes; 167 const u32 *bsr_bytes;
166 unsigned i; 168 unsigned i;
169 int ret = -ENODEV;
167 170
168 bsr_stride = of_get_property(bn, "ibm,lock-stride", &bsr_stride_len); 171 bsr_stride = of_get_property(bn, "ibm,lock-stride", &bsr_stride_len);
169 bsr_bytes = of_get_property(bn, "ibm,#lock-bytes", &bsr_bytes_len); 172 bsr_bytes = of_get_property(bn, "ibm,#lock-bytes", &bsr_bytes_len);
@@ -171,35 +174,36 @@ static int bsr_create_devs(struct device_node *bn)
171 if (!bsr_stride || !bsr_bytes || 174 if (!bsr_stride || !bsr_bytes ||
172 (bsr_stride_len != bsr_bytes_len)) { 175 (bsr_stride_len != bsr_bytes_len)) {
173 printk(KERN_ERR "bsr of-node has missing/incorrect property\n"); 176 printk(KERN_ERR "bsr of-node has missing/incorrect property\n");
174 return -ENODEV; 177 return ret;
175 } 178 }
176 179
177 num_bsr_devs = bsr_bytes_len / sizeof(u32); 180 num_bsr_devs = bsr_bytes_len / sizeof(u32);
178 181
179 /* only a warning, its informational since we'll fail and exit */
180 WARN_ON(num_bsr_devs > BSR_MAX_DEVS);
181
182 bsr_devs = kzalloc(sizeof(struct bsr_dev) * num_bsr_devs, GFP_KERNEL);
183 if (!bsr_devs)
184 return -ENOMEM;
185
186 for (i = 0 ; i < num_bsr_devs; i++) { 182 for (i = 0 ; i < num_bsr_devs; i++) {
187 struct bsr_dev *cur = bsr_devs + i; 183 struct bsr_dev *cur = kzalloc(sizeof(struct bsr_dev),
184 GFP_KERNEL);
188 struct resource res; 185 struct resource res;
189 int result; 186 int result;
190 187
188 if (!cur) {
189 printk(KERN_ERR "Unable to alloc bsr dev\n");
190 ret = -ENOMEM;
191 goto out_err;
192 }
193
191 result = of_address_to_resource(bn, i, &res); 194 result = of_address_to_resource(bn, i, &res);
192 if (result < 0) { 195 if (result < 0) {
193 printk(KERN_ERR "bsr of-node has invalid reg property\n"); 196 printk(KERN_ERR "bsr of-node has invalid reg property, skipping\n");
194 goto out_err; 197 kfree(cur);
198 continue;
195 } 199 }
196 200
197 cur->bsr_minor = i; 201 cur->bsr_minor = i + total_bsr_devs;
198 cur->bsr_addr = res.start; 202 cur->bsr_addr = res.start;
199 cur->bsr_len = res.end - res.start + 1; 203 cur->bsr_len = res.end - res.start + 1;
200 cur->bsr_bytes = bsr_bytes[i]; 204 cur->bsr_bytes = bsr_bytes[i];
201 cur->bsr_stride = bsr_stride[i]; 205 cur->bsr_stride = bsr_stride[i];
202 cur->bsr_dev = MKDEV(bsr_major, i); 206 cur->bsr_dev = MKDEV(bsr_major, i + total_bsr_devs);
203 207
204 switch(cur->bsr_bytes) { 208 switch(cur->bsr_bytes) {
205 case 8: 209 case 8:
@@ -220,14 +224,15 @@ static int bsr_create_devs(struct device_node *bn)
220 } 224 }
221 225
222 cur->bsr_num = bsr_types[cur->bsr_type]; 226 cur->bsr_num = bsr_types[cur->bsr_type];
223 bsr_types[cur->bsr_type] = cur->bsr_num + 1;
224 snprintf(cur->bsr_name, 32, "bsr%d_%d", 227 snprintf(cur->bsr_name, 32, "bsr%d_%d",
225 cur->bsr_bytes, cur->bsr_num); 228 cur->bsr_bytes, cur->bsr_num);
226 229
227 cdev_init(&cur->bsr_cdev, &bsr_fops); 230 cdev_init(&cur->bsr_cdev, &bsr_fops);
228 result = cdev_add(&cur->bsr_cdev, cur->bsr_dev, 1); 231 result = cdev_add(&cur->bsr_cdev, cur->bsr_dev, 1);
229 if (result) 232 if (result) {
233 kfree(cur);
230 goto out_err; 234 goto out_err;
235 }
231 236
232 cur->bsr_device = device_create(bsr_class, NULL, cur->bsr_dev, 237 cur->bsr_device = device_create(bsr_class, NULL, cur->bsr_dev,
233 cur, cur->bsr_name); 238 cur, cur->bsr_name);
@@ -235,16 +240,37 @@ static int bsr_create_devs(struct device_node *bn)
235 printk(KERN_ERR "device_create failed for %s\n", 240 printk(KERN_ERR "device_create failed for %s\n",
236 cur->bsr_name); 241 cur->bsr_name);
237 cdev_del(&cur->bsr_cdev); 242 cdev_del(&cur->bsr_cdev);
243 kfree(cur);
238 goto out_err; 244 goto out_err;
239 } 245 }
246
247 bsr_types[cur->bsr_type] = cur->bsr_num + 1;
248 list_add_tail(&cur->bsr_list, &bsr_devs);
240 } 249 }
241 250
251 total_bsr_devs += num_bsr_devs;
252
242 return 0; 253 return 0;
243 254
244 out_err: 255 out_err:
245 256
246 bsr_cleanup_devs(); 257 bsr_cleanup_devs();
247 return -ENODEV; 258 return ret;
259}
260
261static int bsr_create_devs(struct device_node *bn)
262{
263 int ret;
264
265 while (bn) {
266 ret = bsr_add_node(bn);
267 if (ret) {
268 of_node_put(bn);
269 return ret;
270 }
271 bn = of_find_compatible_node(bn, NULL, "ibm,bsr");
272 }
273 return 0;
248} 274}
249 275
250static int __init bsr_init(void) 276static int __init bsr_init(void)
@@ -254,7 +280,7 @@ static int __init bsr_init(void)
254 int ret = -ENODEV; 280 int ret = -ENODEV;
255 int result; 281 int result;
256 282
257 np = of_find_compatible_node(NULL, "ibm,bsr", "ibm,bsr"); 283 np = of_find_compatible_node(NULL, NULL, "ibm,bsr");
258 if (!np) 284 if (!np)
259 goto out_err; 285 goto out_err;
260 286
@@ -272,10 +298,10 @@ static int __init bsr_init(void)
272 goto out_err_2; 298 goto out_err_2;
273 } 299 }
274 300
275 if ((ret = bsr_create_devs(np)) < 0) 301 if ((ret = bsr_create_devs(np)) < 0) {
302 np = NULL;
276 goto out_err_3; 303 goto out_err_3;
277 304 }
278 of_node_put(np);
279 305
280 return 0; 306 return 0;
281 307
diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c
index 5b819b12675a..fb57f67bb427 100644
--- a/drivers/char/hvc_console.c
+++ b/drivers/char/hvc_console.c
@@ -642,8 +642,11 @@ int hvc_poll(struct hvc_struct *hp)
642 /* Handle the SysRq Hack */ 642 /* Handle the SysRq Hack */
643 /* XXX should support a sequence */ 643 /* XXX should support a sequence */
644 if (buf[i] == '\x0f') { /* ^O */ 644 if (buf[i] == '\x0f') { /* ^O */
645 sysrq_pressed = 1; 645 /* if ^O is pressed again, reset
646 continue; 646 * sysrq_pressed and flip ^O char */
647 sysrq_pressed = !sysrq_pressed;
648 if (sysrq_pressed)
649 continue;
647 } else if (sysrq_pressed) { 650 } else if (sysrq_pressed) {
648 handle_sysrq(buf[i], tty); 651 handle_sysrq(buf[i], tty);
649 sysrq_pressed = 0; 652 sysrq_pressed = 0;
@@ -689,10 +692,8 @@ EXPORT_SYMBOL_GPL(hvc_poll);
689 */ 692 */
690void hvc_resize(struct hvc_struct *hp, struct winsize ws) 693void hvc_resize(struct hvc_struct *hp, struct winsize ws)
691{ 694{
692 if ((hp->ws.ws_row != ws.ws_row) || (hp->ws.ws_col != ws.ws_col)) { 695 hp->ws = ws;
693 hp->ws = ws; 696 schedule_work(&hp->tty_resize);
694 schedule_work(&hp->tty_resize);
695 }
696} 697}
697 698
698/* 699/*
diff --git a/drivers/char/hvc_console.h b/drivers/char/hvc_console.h
index 8297dbc2e6ec..3c85d78c975c 100644
--- a/drivers/char/hvc_console.h
+++ b/drivers/char/hvc_console.h
@@ -48,7 +48,7 @@ struct hvc_struct {
48 spinlock_t lock; 48 spinlock_t lock;
49 int index; 49 int index;
50 struct tty_struct *tty; 50 struct tty_struct *tty;
51 unsigned int count; 51 int count;
52 int do_wakeup; 52 int do_wakeup;
53 char *outbuf; 53 char *outbuf;
54 int outbuf_size; 54 int outbuf_size;
diff --git a/drivers/char/hvc_iseries.c b/drivers/char/hvc_iseries.c
index b74a2f8ab908..449727b6166d 100644
--- a/drivers/char/hvc_iseries.c
+++ b/drivers/char/hvc_iseries.c
@@ -575,8 +575,10 @@ static int __init hvc_find_vtys(void)
575 * of console adapters. 575 * of console adapters.
576 */ 576 */
577 if ((num_found >= MAX_NR_HVC_CONSOLES) || 577 if ((num_found >= MAX_NR_HVC_CONSOLES) ||
578 (num_found >= VTTY_PORTS)) 578 (num_found >= VTTY_PORTS)) {
579 of_node_put(vty);
579 break; 580 break;
581 }
580 582
581 vtermno = of_get_property(vty, "reg", NULL); 583 vtermno = of_get_property(vty, "reg", NULL);
582 if (!vtermno) 584 if (!vtermno)
diff --git a/drivers/char/hvc_iucv.c b/drivers/char/hvc_iucv.c
new file mode 100644
index 000000000000..5ea7d7713fca
--- /dev/null
+++ b/drivers/char/hvc_iucv.c
@@ -0,0 +1,850 @@
1/*
2 * hvc_iucv.c - z/VM IUCV back-end for the Hypervisor Console (HVC)
3 *
4 * This back-end for HVC provides terminal access via
5 * z/VM IUCV communication paths.
6 *
7 * Copyright IBM Corp. 2008.
8 *
9 * Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
10 */
11#define KMSG_COMPONENT "hvc_iucv"
12
13#include <linux/types.h>
14#include <asm/ebcdic.h>
15#include <linux/mempool.h>
16#include <linux/module.h>
17#include <linux/tty.h>
18#include <net/iucv/iucv.h>
19
20#include "hvc_console.h"
21
22
23/* HVC backend for z/VM IUCV */
24#define HVC_IUCV_MAGIC 0xc9e4c3e5
25#define MAX_HVC_IUCV_LINES HVC_ALLOC_TTY_ADAPTERS
26#define MEMPOOL_MIN_NR (PAGE_SIZE / sizeof(struct iucv_tty_buffer)/4)
27
28/* IUCV TTY message */
29#define MSG_VERSION 0x02 /* Message version */
30#define MSG_TYPE_ERROR 0x01 /* Error message */
31#define MSG_TYPE_TERMENV 0x02 /* Terminal environment variable */
32#define MSG_TYPE_TERMIOS 0x04 /* Terminal IO struct update */
33#define MSG_TYPE_WINSIZE 0x08 /* Terminal window size update */
34#define MSG_TYPE_DATA 0x10 /* Terminal data */
35
36#define MSG_SIZE(s) ((s) + offsetof(struct iucv_tty_msg, data))
37struct iucv_tty_msg {
38 u8 version; /* Message version */
39 u8 type; /* Message type */
40#define MSG_MAX_DATALEN (~(u16)0)
41 u16 datalen; /* Payload length */
42 u8 data[]; /* Payload buffer */
43} __attribute__((packed));
44
45enum iucv_state_t {
46 IUCV_DISCONN = 0,
47 IUCV_CONNECTED = 1,
48 IUCV_SEVERED = 2,
49};
50
51enum tty_state_t {
52 TTY_CLOSED = 0,
53 TTY_OPENED = 1,
54};
55
56struct hvc_iucv_private {
57 struct hvc_struct *hvc; /* HVC console struct reference */
58 u8 srv_name[8]; /* IUCV service name (ebcdic) */
59 enum iucv_state_t iucv_state; /* IUCV connection status */
60 enum tty_state_t tty_state; /* TTY status */
61 struct iucv_path *path; /* IUCV path pointer */
62 spinlock_t lock; /* hvc_iucv_private lock */
63 struct list_head tty_outqueue; /* outgoing IUCV messages */
64 struct list_head tty_inqueue; /* incoming IUCV messages */
65};
66
67struct iucv_tty_buffer {
68 struct list_head list; /* list pointer */
69 struct iucv_message msg; /* store an incoming IUCV message */
70 size_t offset; /* data buffer offset */
71 struct iucv_tty_msg *mbuf; /* buffer to store input/output data */
72};
73
74/* IUCV callback handler */
75static int hvc_iucv_path_pending(struct iucv_path *, u8[8], u8[16]);
76static void hvc_iucv_path_severed(struct iucv_path *, u8[16]);
77static void hvc_iucv_msg_pending(struct iucv_path *, struct iucv_message *);
78static void hvc_iucv_msg_complete(struct iucv_path *, struct iucv_message *);
79
80
81/* Kernel module parameters */
82static unsigned long hvc_iucv_devices;
83
84/* Array of allocated hvc iucv tty lines... */
85static struct hvc_iucv_private *hvc_iucv_table[MAX_HVC_IUCV_LINES];
86
87/* Kmem cache and mempool for iucv_tty_buffer elements */
88static struct kmem_cache *hvc_iucv_buffer_cache;
89static mempool_t *hvc_iucv_mempool;
90
91/* IUCV handler callback functions */
92static struct iucv_handler hvc_iucv_handler = {
93 .path_pending = hvc_iucv_path_pending,
94 .path_severed = hvc_iucv_path_severed,
95 .message_complete = hvc_iucv_msg_complete,
96 .message_pending = hvc_iucv_msg_pending,
97};
98
99
100/**
101 * hvc_iucv_get_private() - Return a struct hvc_iucv_private instance.
102 * @num: The HVC virtual terminal number (vtermno)
103 *
104 * This function returns the struct hvc_iucv_private instance that corresponds
105 * to the HVC virtual terminal number specified as parameter @num.
106 */
107struct hvc_iucv_private *hvc_iucv_get_private(uint32_t num)
108{
109 if ((num < HVC_IUCV_MAGIC) || (num - HVC_IUCV_MAGIC > hvc_iucv_devices))
110 return NULL;
111 return hvc_iucv_table[num - HVC_IUCV_MAGIC];
112}
113
114/**
115 * alloc_tty_buffer() - Returns a new struct iucv_tty_buffer element.
116 * @size: Size of the internal buffer used to store data.
117 * @flags: Memory allocation flags passed to mempool.
118 *
119 * This function allocates a new struct iucv_tty_buffer element and, optionally,
120 * allocates an internal data buffer with the specified size @size.
121 * Note: The total message size arises from the internal buffer size and the
122 * members of the iucv_tty_msg structure.
123 *
124 * The function returns NULL if memory allocation has failed.
125 */
126static struct iucv_tty_buffer *alloc_tty_buffer(size_t size, gfp_t flags)
127{
128 struct iucv_tty_buffer *bufp;
129
130 bufp = mempool_alloc(hvc_iucv_mempool, flags);
131 if (!bufp)
132 return NULL;
133 memset(bufp, 0, sizeof(struct iucv_tty_buffer));
134
135 if (size > 0) {
136 bufp->msg.length = MSG_SIZE(size);
137 bufp->mbuf = kmalloc(bufp->msg.length, flags);
138 if (!bufp->mbuf) {
139 mempool_free(bufp, hvc_iucv_mempool);
140 return NULL;
141 }
142 bufp->mbuf->version = MSG_VERSION;
143 bufp->mbuf->type = MSG_TYPE_DATA;
144 bufp->mbuf->datalen = (u16) size;
145 }
146 return bufp;
147}
148
149/**
150 * destroy_tty_buffer() - destroy struct iucv_tty_buffer element.
151 * @bufp: Pointer to a struct iucv_tty_buffer element, SHALL NOT be NULL.
152 *
153 * The destroy_tty_buffer() function frees the internal data buffer and returns
154 * the struct iucv_tty_buffer element back to the mempool for freeing.
155 */
156static void destroy_tty_buffer(struct iucv_tty_buffer *bufp)
157{
158 kfree(bufp->mbuf);
159 mempool_free(bufp, hvc_iucv_mempool);
160}
161
162/**
163 * destroy_tty_buffer_list() - call destroy_tty_buffer() for each list element.
164 * @list: List head pointer to a list containing struct iucv_tty_buffer
165 * elements.
166 *
167 * Calls destroy_tty_buffer() for each struct iucv_tty_buffer element in the
168 * list @list.
169 */
170static void destroy_tty_buffer_list(struct list_head *list)
171{
172 struct iucv_tty_buffer *ent, *next;
173
174 list_for_each_entry_safe(ent, next, list, list) {
175 list_del(&ent->list);
176 destroy_tty_buffer(ent);
177 }
178}
179
180/**
181 * hvc_iucv_write() - Receive IUCV message write data to HVC console buffer.
182 * @priv: Pointer to hvc_iucv_private structure.
183 * @buf: HVC console buffer for writing received terminal data.
184 * @count: HVC console buffer size.
185 * @has_more_data: Pointer to an int variable.
186 *
187 * The function picks up pending messages from the input queue and receives
188 * the message data that is then written to the specified buffer @buf.
189 * If the buffer size @count is less than the data message size, then the
190 * message is kept on the input queue and @has_more_data is set to 1.
191 * If the message data has been entirely written, the message is removed from
192 * the input queue.
193 *
194 * The function returns the number of bytes written to the terminal, zero if
195 * there are no pending data messages available or if there is no established
196 * IUCV path.
197 * If the IUCV path has been severed, then -EPIPE is returned to cause a
198 * hang up (that is issued by the HVC console layer).
199 */
200static int hvc_iucv_write(struct hvc_iucv_private *priv,
201 char *buf, int count, int *has_more_data)
202{
203 struct iucv_tty_buffer *rb;
204 int written;
205 int rc;
206
207 /* Immediately return if there is no IUCV connection */
208 if (priv->iucv_state == IUCV_DISCONN)
209 return 0;
210
211 /* If the IUCV path has been severed, return -EPIPE to inform the
212 * hvc console layer to hang up the tty device. */
213 if (priv->iucv_state == IUCV_SEVERED)
214 return -EPIPE;
215
216 /* check if there are pending messages */
217 if (list_empty(&priv->tty_inqueue))
218 return 0;
219
220 /* receive a iucv message and flip data to the tty (ldisc) */
221 rb = list_first_entry(&priv->tty_inqueue, struct iucv_tty_buffer, list);
222
223 written = 0;
224 if (!rb->mbuf) { /* message not yet received ... */
225 /* allocate mem to store msg data; if no memory is available
226 * then leave the buffer on the list and re-try later */
227 rb->mbuf = kmalloc(rb->msg.length, GFP_ATOMIC);
228 if (!rb->mbuf)
229 return -ENOMEM;
230
231 rc = __iucv_message_receive(priv->path, &rb->msg, 0,
232 rb->mbuf, rb->msg.length, NULL);
233 switch (rc) {
234 case 0: /* Successful */
235 break;
236 case 2: /* No message found */
237 case 9: /* Message purged */
238 break;
239 default:
240 written = -EIO;
241 }
242 /* remove buffer if an error has occured or received data
243 * is not correct */
244 if (rc || (rb->mbuf->version != MSG_VERSION) ||
245 (rb->msg.length != MSG_SIZE(rb->mbuf->datalen)))
246 goto out_remove_buffer;
247 }
248
249 switch (rb->mbuf->type) {
250 case MSG_TYPE_DATA:
251 written = min_t(int, rb->mbuf->datalen - rb->offset, count);
252 memcpy(buf, rb->mbuf->data + rb->offset, written);
253 if (written < (rb->mbuf->datalen - rb->offset)) {
254 rb->offset += written;
255 *has_more_data = 1;
256 goto out_written;
257 }
258 break;
259
260 case MSG_TYPE_WINSIZE:
261 if (rb->mbuf->datalen != sizeof(struct winsize))
262 break;
263 hvc_resize(priv->hvc, *((struct winsize *)rb->mbuf->data));
264 break;
265
266 case MSG_TYPE_ERROR: /* ignored ... */
267 case MSG_TYPE_TERMENV: /* ignored ... */
268 case MSG_TYPE_TERMIOS: /* ignored ... */
269 break;
270 }
271
272out_remove_buffer:
273 list_del(&rb->list);
274 destroy_tty_buffer(rb);
275 *has_more_data = !list_empty(&priv->tty_inqueue);
276
277out_written:
278 return written;
279}
280
281/**
282 * hvc_iucv_get_chars() - HVC get_chars operation.
283 * @vtermno: HVC virtual terminal number.
284 * @buf: Pointer to a buffer to store data
285 * @count: Size of buffer available for writing
286 *
287 * The hvc_console thread calls this method to read characters from
288 * the terminal backend. If an IUCV communication path has been established,
289 * pending IUCV messages are received and data is copied into buffer @buf
290 * up to @count bytes.
291 *
292 * Locking: The routine gets called under an irqsave() spinlock; and
293 * the routine locks the struct hvc_iucv_private->lock to call
294 * helper functions.
295 */
296static int hvc_iucv_get_chars(uint32_t vtermno, char *buf, int count)
297{
298 struct hvc_iucv_private *priv = hvc_iucv_get_private(vtermno);
299 int written;
300 int has_more_data;
301
302 if (count <= 0)
303 return 0;
304
305 if (!priv)
306 return -ENODEV;
307
308 spin_lock(&priv->lock);
309 has_more_data = 0;
310 written = hvc_iucv_write(priv, buf, count, &has_more_data);
311 spin_unlock(&priv->lock);
312
313 /* if there are still messages on the queue... schedule another run */
314 if (has_more_data)
315 hvc_kick();
316
317 return written;
318}
319
320/**
321 * hvc_iucv_send() - Send an IUCV message containing terminal data.
322 * @priv: Pointer to struct hvc_iucv_private instance.
323 * @buf: Buffer containing data to send.
324 * @size: Size of buffer and amount of data to send.
325 *
326 * If an IUCV communication path is established, the function copies the buffer
327 * data to a newly allocated struct iucv_tty_buffer element, sends the data and
328 * puts the element to the outqueue.
329 *
330 * If there is no IUCV communication path established, the function returns 0.
331 * If an existing IUCV communicaton path has been severed, the function returns
332 * -EPIPE (can be passed to HVC layer to cause a tty hangup).
333 */
334static int hvc_iucv_send(struct hvc_iucv_private *priv, const char *buf,
335 int count)
336{
337 struct iucv_tty_buffer *sb;
338 int rc;
339 u16 len;
340
341 if (priv->iucv_state == IUCV_SEVERED)
342 return -EPIPE;
343
344 if (priv->iucv_state == IUCV_DISCONN)
345 return 0;
346
347 len = min_t(u16, MSG_MAX_DATALEN, count);
348
349 /* allocate internal buffer to store msg data and also compute total
350 * message length */
351 sb = alloc_tty_buffer(len, GFP_ATOMIC);
352 if (!sb)
353 return -ENOMEM;
354
355 sb->mbuf->datalen = len;
356 memcpy(sb->mbuf->data, buf, len);
357
358 list_add_tail(&sb->list, &priv->tty_outqueue);
359
360 rc = __iucv_message_send(priv->path, &sb->msg, 0, 0,
361 (void *) sb->mbuf, sb->msg.length);
362 if (rc) {
363 list_del(&sb->list);
364 destroy_tty_buffer(sb);
365 len = 0;
366 }
367
368 return len;
369}
370
371/**
372 * hvc_iucv_put_chars() - HVC put_chars operation.
373 * @vtermno: HVC virtual terminal number.
374 * @buf: Pointer to an buffer to read data from
375 * @count: Size of buffer available for reading
376 *
377 * The hvc_console thread calls this method to write characters from
378 * to the terminal backend.
379 * The function calls hvc_iucv_send() under the lock of the
380 * struct hvc_iucv_private instance that corresponds to the tty @vtermno.
381 *
382 * Locking: The method gets called under an irqsave() spinlock; and
383 * locks struct hvc_iucv_private->lock.
384 */
385static int hvc_iucv_put_chars(uint32_t vtermno, const char *buf, int count)
386{
387 struct hvc_iucv_private *priv = hvc_iucv_get_private(vtermno);
388 int sent;
389
390 if (count <= 0)
391 return 0;
392
393 if (!priv)
394 return -ENODEV;
395
396 spin_lock(&priv->lock);
397 sent = hvc_iucv_send(priv, buf, count);
398 spin_unlock(&priv->lock);
399
400 return sent;
401}
402
403/**
404 * hvc_iucv_notifier_add() - HVC notifier for opening a TTY for the first time.
405 * @hp: Pointer to the HVC device (struct hvc_struct)
406 * @id: Additional data (originally passed to hvc_alloc): the index of an struct
407 * hvc_iucv_private instance.
408 *
409 * The function sets the tty state to TTY_OPEN for the struct hvc_iucv_private
410 * instance that is derived from @id. Always returns 0.
411 *
412 * Locking: struct hvc_iucv_private->lock, spin_lock_bh
413 */
414static int hvc_iucv_notifier_add(struct hvc_struct *hp, int id)
415{
416 struct hvc_iucv_private *priv;
417
418 priv = hvc_iucv_get_private(id);
419 if (!priv)
420 return 0;
421
422 spin_lock_bh(&priv->lock);
423 priv->tty_state = TTY_OPENED;
424 spin_unlock_bh(&priv->lock);
425
426 return 0;
427}
428
429/**
430 * hvc_iucv_cleanup() - Clean up function if the tty portion is finally closed.
431 * @priv: Pointer to the struct hvc_iucv_private instance.
432 *
433 * The functions severs the established IUCV communication path (if any), and
434 * destroy struct iucv_tty_buffer elements from the in- and outqueue. Finally,
435 * the functions resets the states to TTY_CLOSED and IUCV_DISCONN.
436 */
437static void hvc_iucv_cleanup(struct hvc_iucv_private *priv)
438{
439 destroy_tty_buffer_list(&priv->tty_outqueue);
440 destroy_tty_buffer_list(&priv->tty_inqueue);
441
442 priv->tty_state = TTY_CLOSED;
443 priv->iucv_state = IUCV_DISCONN;
444}
445
446/**
447 * hvc_iucv_notifier_hangup() - HVC notifier for tty hangups.
448 * @hp: Pointer to the HVC device (struct hvc_struct)
449 * @id: Additional data (originally passed to hvc_alloc): the index of an struct
450 * hvc_iucv_private instance.
451 *
452 * This routine notifies the HVC backend that a tty hangup (carrier loss,
453 * virtual or otherwise) has occured.
454 *
455 * The HVC backend for z/VM IUCV ignores virtual hangups (vhangup()), to keep
456 * an existing IUCV communication path established.
457 * (Background: vhangup() is called from user space (by getty or login) to
458 * disable writing to the tty by other applications).
459 *
460 * If the tty has been opened (e.g. getty) and an established IUCV path has been
461 * severed (we caused the tty hangup in that case), then the functions invokes
462 * hvc_iucv_cleanup() to clean up.
463 *
464 * Locking: struct hvc_iucv_private->lock
465 */
466static void hvc_iucv_notifier_hangup(struct hvc_struct *hp, int id)
467{
468 struct hvc_iucv_private *priv;
469
470 priv = hvc_iucv_get_private(id);
471 if (!priv)
472 return;
473
474 spin_lock_bh(&priv->lock);
475 /* NOTE: If the hangup was scheduled by ourself (from the iucv
476 * path_servered callback [IUCV_SEVERED]), then we have to
477 * finally clean up the tty backend structure and set state to
478 * TTY_CLOSED.
479 *
480 * If the tty was hung up otherwise (e.g. vhangup()), then we
481 * ignore this hangup and keep an established IUCV path open...
482 * (...the reason is that we are not able to connect back to the
483 * client if we disconnect on hang up) */
484 priv->tty_state = TTY_CLOSED;
485
486 if (priv->iucv_state == IUCV_SEVERED)
487 hvc_iucv_cleanup(priv);
488 spin_unlock_bh(&priv->lock);
489}
490
491/**
492 * hvc_iucv_notifier_del() - HVC notifier for closing a TTY for the last time.
493 * @hp: Pointer to the HVC device (struct hvc_struct)
494 * @id: Additional data (originally passed to hvc_alloc):
495 * the index of an struct hvc_iucv_private instance.
496 *
497 * This routine notifies the HVC backend that the last tty device file
498 * descriptor has been closed.
499 * The function calls hvc_iucv_cleanup() to clean up the struct hvc_iucv_private
500 * instance.
501 *
502 * Locking: struct hvc_iucv_private->lock
503 */
504static void hvc_iucv_notifier_del(struct hvc_struct *hp, int id)
505{
506 struct hvc_iucv_private *priv;
507 struct iucv_path *path;
508
509 priv = hvc_iucv_get_private(id);
510 if (!priv)
511 return;
512
513 spin_lock_bh(&priv->lock);
514 path = priv->path; /* save reference to IUCV path */
515 priv->path = NULL;
516 hvc_iucv_cleanup(priv);
517 spin_unlock_bh(&priv->lock);
518
519 /* sever IUCV path outside of priv->lock due to lock ordering of:
520 * priv->lock <--> iucv_table_lock */
521 if (path) {
522 iucv_path_sever(path, NULL);
523 iucv_path_free(path);
524 }
525}
526
527/**
528 * hvc_iucv_path_pending() - IUCV handler to process a connection request.
529 * @path: Pending path (struct iucv_path)
530 * @ipvmid: Originator z/VM system identifier
531 * @ipuser: User specified data for this path
532 * (AF_IUCV: port/service name and originator port)
533 *
534 * The function uses the @ipuser data to check to determine if the pending
535 * path belongs to a terminal managed by this HVC backend.
536 * If the check is successful, then an additional check is done to ensure
537 * that a terminal cannot be accessed multiple times (only one connection
538 * to a terminal is allowed). In that particular case, the pending path is
539 * severed. If it is the first connection, the pending path is accepted and
540 * associated to the struct hvc_iucv_private. The iucv state is updated to
541 * reflect that a communication path has been established.
542 *
543 * Returns 0 if the path belongs to a terminal managed by the this HVC backend;
544 * otherwise returns -ENODEV in order to dispatch this path to other handlers.
545 *
546 * Locking: struct hvc_iucv_private->lock
547 */
548static int hvc_iucv_path_pending(struct iucv_path *path,
549 u8 ipvmid[8], u8 ipuser[16])
550{
551 struct hvc_iucv_private *priv;
552 u8 nuser_data[16];
553 int i, rc;
554
555 priv = NULL;
556 for (i = 0; i < hvc_iucv_devices; i++)
557 if (hvc_iucv_table[i] &&
558 (0 == memcmp(hvc_iucv_table[i]->srv_name, ipuser, 8))) {
559 priv = hvc_iucv_table[i];
560 break;
561 }
562
563 if (!priv)
564 return -ENODEV;
565
566 spin_lock(&priv->lock);
567
568 /* If the terminal is already connected or being severed, then sever
569 * this path to enforce that there is only ONE established communication
570 * path per terminal. */
571 if (priv->iucv_state != IUCV_DISCONN) {
572 iucv_path_sever(path, ipuser);
573 iucv_path_free(path);
574 goto out_path_handled;
575 }
576
577 /* accept path */
578 memcpy(nuser_data, ipuser + 8, 8); /* remote service (for af_iucv) */
579 memcpy(nuser_data + 8, ipuser, 8); /* local service (for af_iucv) */
580 path->msglim = 0xffff; /* IUCV MSGLIMIT */
581 path->flags &= ~IUCV_IPRMDATA; /* TODO: use IUCV_IPRMDATA */
582 rc = iucv_path_accept(path, &hvc_iucv_handler, nuser_data, priv);
583 if (rc) {
584 iucv_path_sever(path, ipuser);
585 iucv_path_free(path);
586 goto out_path_handled;
587 }
588 priv->path = path;
589 priv->iucv_state = IUCV_CONNECTED;
590
591out_path_handled:
592 spin_unlock(&priv->lock);
593 return 0;
594}
595
596/**
597 * hvc_iucv_path_severed() - IUCV handler to process a path sever.
598 * @path: Pending path (struct iucv_path)
599 * @ipuser: User specified data for this path
600 * (AF_IUCV: port/service name and originator port)
601 *
602 * The function also severs the path (as required by the IUCV protocol) and
603 * sets the iucv state to IUCV_SEVERED for the associated struct
604 * hvc_iucv_private instance. Later, the IUCV_SEVERED state triggers a tty
605 * hangup (hvc_iucv_get_chars() / hvc_iucv_write()).
606 *
607 * If tty portion of the HVC is closed then clean up the outqueue in addition.
608 *
609 * Locking: struct hvc_iucv_private->lock
610 */
611static void hvc_iucv_path_severed(struct iucv_path *path, u8 ipuser[16])
612{
613 struct hvc_iucv_private *priv = path->private;
614
615 spin_lock(&priv->lock);
616 priv->iucv_state = IUCV_SEVERED;
617
618 /* NOTE: If the tty has not yet been opened by a getty program
619 * (e.g. to see console messages), then cleanup the
620 * hvc_iucv_private structure to allow re-connects.
621 *
622 * If the tty has been opened, the get_chars() callback returns
623 * -EPIPE to signal the hvc console layer to hang up the tty. */
624 priv->path = NULL;
625 if (priv->tty_state == TTY_CLOSED)
626 hvc_iucv_cleanup(priv);
627 spin_unlock(&priv->lock);
628
629 /* finally sever path (outside of priv->lock due to lock ordering) */
630 iucv_path_sever(path, ipuser);
631 iucv_path_free(path);
632}
633
634/**
635 * hvc_iucv_msg_pending() - IUCV handler to process an incoming IUCV message.
636 * @path: Pending path (struct iucv_path)
637 * @msg: Pointer to the IUCV message
638 *
639 * The function stores an incoming message on the input queue for later
640 * processing (by hvc_iucv_get_chars() / hvc_iucv_write()).
641 * However, if the tty has not yet been opened, the message is rejected.
642 *
643 * Locking: struct hvc_iucv_private->lock
644 */
645static void hvc_iucv_msg_pending(struct iucv_path *path,
646 struct iucv_message *msg)
647{
648 struct hvc_iucv_private *priv = path->private;
649 struct iucv_tty_buffer *rb;
650
651 spin_lock(&priv->lock);
652
653 /* reject messages if tty has not yet been opened */
654 if (priv->tty_state == TTY_CLOSED) {
655 iucv_message_reject(path, msg);
656 goto unlock_return;
657 }
658
659 /* allocate buffer an empty buffer element */
660 rb = alloc_tty_buffer(0, GFP_ATOMIC);
661 if (!rb) {
662 iucv_message_reject(path, msg);
663 goto unlock_return; /* -ENOMEM */
664 }
665 rb->msg = *msg;
666
667 list_add_tail(&rb->list, &priv->tty_inqueue);
668
669 hvc_kick(); /* wakup hvc console thread */
670
671unlock_return:
672 spin_unlock(&priv->lock);
673}
674
675/**
676 * hvc_iucv_msg_complete() - IUCV handler to process message completion
677 * @path: Pending path (struct iucv_path)
678 * @msg: Pointer to the IUCV message
679 *
680 * The function is called upon completion of message delivery and the
681 * message is removed from the outqueue. Additional delivery information
682 * can be found in msg->audit: rejected messages (0x040000 (IPADRJCT)) and
683 * purged messages (0x010000 (IPADPGNR)).
684 *
685 * Locking: struct hvc_iucv_private->lock
686 */
687static void hvc_iucv_msg_complete(struct iucv_path *path,
688 struct iucv_message *msg)
689{
690 struct hvc_iucv_private *priv = path->private;
691 struct iucv_tty_buffer *ent, *next;
692 LIST_HEAD(list_remove);
693
694 spin_lock(&priv->lock);
695 list_for_each_entry_safe(ent, next, &priv->tty_outqueue, list)
696 if (ent->msg.id == msg->id) {
697 list_move(&ent->list, &list_remove);
698 break;
699 }
700 spin_unlock(&priv->lock);
701 destroy_tty_buffer_list(&list_remove);
702}
703
704
705/* HVC operations */
706static struct hv_ops hvc_iucv_ops = {
707 .get_chars = hvc_iucv_get_chars,
708 .put_chars = hvc_iucv_put_chars,
709 .notifier_add = hvc_iucv_notifier_add,
710 .notifier_del = hvc_iucv_notifier_del,
711 .notifier_hangup = hvc_iucv_notifier_hangup,
712};
713
714/**
715 * hvc_iucv_alloc() - Allocates a new struct hvc_iucv_private instance
716 * @id: hvc_iucv_table index
717 *
718 * This function allocates a new hvc_iucv_private struct and put the
719 * instance into hvc_iucv_table at index @id.
720 * Returns 0 on success; otherwise non-zero.
721 */
722static int __init hvc_iucv_alloc(int id)
723{
724 struct hvc_iucv_private *priv;
725 char name[9];
726 int rc;
727
728 priv = kzalloc(sizeof(struct hvc_iucv_private), GFP_KERNEL);
729 if (!priv)
730 return -ENOMEM;
731
732 spin_lock_init(&priv->lock);
733 INIT_LIST_HEAD(&priv->tty_outqueue);
734 INIT_LIST_HEAD(&priv->tty_inqueue);
735
736 /* Finally allocate hvc */
737 priv->hvc = hvc_alloc(HVC_IUCV_MAGIC + id,
738 HVC_IUCV_MAGIC + id, &hvc_iucv_ops, PAGE_SIZE);
739 if (IS_ERR(priv->hvc)) {
740 rc = PTR_ERR(priv->hvc);
741 kfree(priv);
742 return rc;
743 }
744
745 /* setup iucv related information */
746 snprintf(name, 9, "ihvc%-4d", id);
747 memcpy(priv->srv_name, name, 8);
748 ASCEBC(priv->srv_name, 8);
749
750 hvc_iucv_table[id] = priv;
751 return 0;
752}
753
754/**
755 * hvc_iucv_init() - Initialization of HVC backend for z/VM IUCV
756 */
757static int __init hvc_iucv_init(void)
758{
759 int rc, i;
760
761 if (!MACHINE_IS_VM) {
762 pr_warning("The z/VM IUCV Hypervisor console cannot be "
763 "used without z/VM.\n");
764 return -ENODEV;
765 }
766
767 if (!hvc_iucv_devices)
768 return -ENODEV;
769
770 if (hvc_iucv_devices > MAX_HVC_IUCV_LINES)
771 return -EINVAL;
772
773 hvc_iucv_buffer_cache = kmem_cache_create(KMSG_COMPONENT,
774 sizeof(struct iucv_tty_buffer),
775 0, 0, NULL);
776 if (!hvc_iucv_buffer_cache) {
777 pr_err("Not enough memory for driver initialization "
778 "(rs=%d).\n", 1);
779 return -ENOMEM;
780 }
781
782 hvc_iucv_mempool = mempool_create_slab_pool(MEMPOOL_MIN_NR,
783 hvc_iucv_buffer_cache);
784 if (!hvc_iucv_mempool) {
785 pr_err("Not enough memory for driver initialization "
786 "(rs=%d).\n", 2);
787 kmem_cache_destroy(hvc_iucv_buffer_cache);
788 return -ENOMEM;
789 }
790
791 /* allocate hvc_iucv_private structs */
792 for (i = 0; i < hvc_iucv_devices; i++) {
793 rc = hvc_iucv_alloc(i);
794 if (rc) {
795 pr_err("Could not create new z/VM IUCV HVC backend "
796 "rc=%d.\n", rc);
797 goto out_error_hvc;
798 }
799 }
800
801 /* register IUCV callback handler */
802 rc = iucv_register(&hvc_iucv_handler, 0);
803 if (rc) {
804 pr_err("Could not register iucv handler (rc=%d).\n", rc);
805 goto out_error_iucv;
806 }
807
808 return 0;
809
810out_error_iucv:
811 iucv_unregister(&hvc_iucv_handler, 0);
812out_error_hvc:
813 for (i = 0; i < hvc_iucv_devices; i++)
814 if (hvc_iucv_table[i]) {
815 if (hvc_iucv_table[i]->hvc)
816 hvc_remove(hvc_iucv_table[i]->hvc);
817 kfree(hvc_iucv_table[i]);
818 }
819 mempool_destroy(hvc_iucv_mempool);
820 kmem_cache_destroy(hvc_iucv_buffer_cache);
821 return rc;
822}
823
824/**
825 * hvc_iucv_console_init() - Early console initialization
826 */
827static int __init hvc_iucv_console_init(void)
828{
829 if (!MACHINE_IS_VM || !hvc_iucv_devices)
830 return -ENODEV;
831 return hvc_instantiate(HVC_IUCV_MAGIC, 0, &hvc_iucv_ops);
832}
833
834/**
835 * hvc_iucv_config() - Parsing of hvc_iucv= kernel command line parameter
836 * @val: Parameter value (numeric)
837 */
838static int __init hvc_iucv_config(char *val)
839{
840 return strict_strtoul(val, 10, &hvc_iucv_devices);
841}
842
843
844module_init(hvc_iucv_init);
845console_initcall(hvc_iucv_console_init);
846__setup("hvc_iucv=", hvc_iucv_config);
847
848MODULE_LICENSE("GPL");
849MODULE_DESCRIPTION("HVC back-end for z/VM IUCV.");
850MODULE_AUTHOR("Hendrik Brueckner <brueckner@linux.vnet.ibm.com>");
diff --git a/drivers/char/hvc_udbg.c b/drivers/char/hvc_udbg.c
new file mode 100644
index 000000000000..bd63ba878a56
--- /dev/null
+++ b/drivers/char/hvc_udbg.c
@@ -0,0 +1,96 @@
1/*
2 * udbg interface to hvc_console.c
3 *
4 * (C) Copyright David Gibson, IBM Corporation 2008.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <linux/console.h>
22#include <linux/delay.h>
23#include <linux/err.h>
24#include <linux/init.h>
25#include <linux/moduleparam.h>
26#include <linux/types.h>
27#include <linux/irq.h>
28
29#include <asm/udbg.h>
30
31#include "hvc_console.h"
32
33struct hvc_struct *hvc_udbg_dev;
34
35static int hvc_udbg_put(uint32_t vtermno, const char *buf, int count)
36{
37 int i;
38
39 for (i = 0; i < count; i++)
40 udbg_putc(buf[i]);
41
42 return i;
43}
44
45static int hvc_udbg_get(uint32_t vtermno, char *buf, int count)
46{
47 int i, c;
48
49 if (!udbg_getc_poll)
50 return 0;
51
52 for (i = 0; i < count; i++) {
53 if ((c = udbg_getc_poll()) == -1)
54 break;
55 buf[i] = c;
56 }
57
58 return i;
59}
60
61static struct hv_ops hvc_udbg_ops = {
62 .get_chars = hvc_udbg_get,
63 .put_chars = hvc_udbg_put,
64};
65
66static int __init hvc_udbg_init(void)
67{
68 struct hvc_struct *hp;
69
70 BUG_ON(hvc_udbg_dev);
71
72 hp = hvc_alloc(0, NO_IRQ, &hvc_udbg_ops, 16);
73 if (IS_ERR(hp))
74 return PTR_ERR(hp);
75
76 hvc_udbg_dev = hp;
77
78 return 0;
79}
80module_init(hvc_udbg_init);
81
82static void __exit hvc_udbg_exit(void)
83{
84 if (hvc_udbg_dev)
85 hvc_remove(hvc_udbg_dev);
86}
87module_exit(hvc_udbg_exit);
88
89static int __init hvc_udbg_console_init(void)
90{
91 hvc_instantiate(0, 0, &hvc_udbg_ops);
92 add_preferred_console("hvc", 0, NULL);
93
94 return 0;
95}
96console_initcall(hvc_udbg_console_init);
diff --git a/drivers/char/hvc_vio.c b/drivers/char/hvc_vio.c
index 019e0b58593d..bd62dc86b47d 100644
--- a/drivers/char/hvc_vio.c
+++ b/drivers/char/hvc_vio.c
@@ -153,8 +153,10 @@ static int hvc_find_vtys(void)
153 /* We have statically defined space for only a certain number 153 /* We have statically defined space for only a certain number
154 * of console adapters. 154 * of console adapters.
155 */ 155 */
156 if (num_found >= MAX_NR_HVC_CONSOLES) 156 if (num_found >= MAX_NR_HVC_CONSOLES) {
157 of_node_put(vty);
157 break; 158 break;
159 }
158 160
159 vtermno = of_get_property(vty, "reg", NULL); 161 vtermno = of_get_property(vty, "reg", NULL);
160 if (!vtermno) 162 if (!vtermno)
diff --git a/drivers/char/hvcs.c b/drivers/char/hvcs.c
index 473d9b14439a..6e6eb445d374 100644
--- a/drivers/char/hvcs.c
+++ b/drivers/char/hvcs.c
@@ -269,7 +269,7 @@ struct hvcs_struct {
269 unsigned int index; 269 unsigned int index;
270 270
271 struct tty_struct *tty; 271 struct tty_struct *tty;
272 unsigned int open_count; 272 int open_count;
273 273
274 /* 274 /*
275 * Used to tell the driver kernel_thread what operations need to take 275 * Used to tell the driver kernel_thread what operations need to take
diff --git a/drivers/char/hvsi.c b/drivers/char/hvsi.c
index 59c6f9ab94e4..af055287271a 100644
--- a/drivers/char/hvsi.c
+++ b/drivers/char/hvsi.c
@@ -75,7 +75,7 @@ struct hvsi_struct {
75 spinlock_t lock; 75 spinlock_t lock;
76 int index; 76 int index;
77 struct tty_struct *tty; 77 struct tty_struct *tty;
78 unsigned int count; 78 int count;
79 uint8_t throttle_buf[128]; 79 uint8_t throttle_buf[128];
80 uint8_t outbuf[N_OUTBUF]; /* to implement write_room and chars_in_buffer */ 80 uint8_t outbuf[N_OUTBUF]; /* to implement write_room and chars_in_buffer */
81 /* inbuf is for packet reassembly. leave a little room for leftovers. */ 81 /* inbuf is for packet reassembly. leave a little room for leftovers. */
diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
index 8054ee839b3c..88cee4099be9 100644
--- a/drivers/char/nvram.c
+++ b/drivers/char/nvram.c
@@ -32,9 +32,10 @@
32 * added changelog 32 * added changelog
33 * 1.2 Erik Gilling: Cobalt Networks support 33 * 1.2 Erik Gilling: Cobalt Networks support
34 * Tim Hockin: general cleanup, Cobalt support 34 * Tim Hockin: general cleanup, Cobalt support
35 * 1.3 Wim Van Sebroeck: convert PRINT_PROC to seq_file
35 */ 36 */
36 37
37#define NVRAM_VERSION "1.2" 38#define NVRAM_VERSION "1.3"
38 39
39#include <linux/module.h> 40#include <linux/module.h>
40#include <linux/smp_lock.h> 41#include <linux/smp_lock.h>
@@ -46,7 +47,7 @@
46/* select machine configuration */ 47/* select machine configuration */
47#if defined(CONFIG_ATARI) 48#if defined(CONFIG_ATARI)
48# define MACH ATARI 49# define MACH ATARI
49#elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) /* and others?? */ 50#elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) /* and ?? */
50# define MACH PC 51# define MACH PC
51#else 52#else
52# error Cannot build nvram driver for this machine configuration. 53# error Cannot build nvram driver for this machine configuration.
@@ -106,10 +107,11 @@
106#include <linux/mc146818rtc.h> 107#include <linux/mc146818rtc.h>
107#include <linux/init.h> 108#include <linux/init.h>
108#include <linux/proc_fs.h> 109#include <linux/proc_fs.h>
110#include <linux/seq_file.h>
109#include <linux/spinlock.h> 111#include <linux/spinlock.h>
112#include <linux/io.h>
113#include <linux/uaccess.h>
110 114
111#include <asm/io.h>
112#include <asm/uaccess.h>
113#include <asm/system.h> 115#include <asm/system.h>
114 116
115static DEFINE_SPINLOCK(nvram_state_lock); 117static DEFINE_SPINLOCK(nvram_state_lock);
@@ -122,8 +124,8 @@ static int mach_check_checksum(void);
122static void mach_set_checksum(void); 124static void mach_set_checksum(void);
123 125
124#ifdef CONFIG_PROC_FS 126#ifdef CONFIG_PROC_FS
125static int mach_proc_infos(unsigned char *contents, char *buffer, int *len, 127static void mach_proc_infos(unsigned char *contents, struct seq_file *seq,
126 off_t *begin, off_t offset, int size); 128 void *offset);
127#endif 129#endif
128 130
129/* 131/*
@@ -133,18 +135,17 @@ static int mach_proc_infos(unsigned char *contents, char *buffer, int *len,
133 * 135 *
134 * It is worth noting that these functions all access bytes of general 136 * It is worth noting that these functions all access bytes of general
135 * purpose memory in the NVRAM - that is to say, they all add the 137 * purpose memory in the NVRAM - that is to say, they all add the
136 * NVRAM_FIRST_BYTE offset. Pass them offsets into NVRAM as if you did not 138 * NVRAM_FIRST_BYTE offset. Pass them offsets into NVRAM as if you did not
137 * know about the RTC cruft. 139 * know about the RTC cruft.
138 */ 140 */
139 141
140unsigned char 142unsigned char __nvram_read_byte(int i)
141__nvram_read_byte(int i)
142{ 143{
143 return CMOS_READ(NVRAM_FIRST_BYTE + i); 144 return CMOS_READ(NVRAM_FIRST_BYTE + i);
144} 145}
146EXPORT_SYMBOL(__nvram_read_byte);
145 147
146unsigned char 148unsigned char nvram_read_byte(int i)
147nvram_read_byte(int i)
148{ 149{
149 unsigned long flags; 150 unsigned long flags;
150 unsigned char c; 151 unsigned char c;
@@ -154,16 +155,16 @@ nvram_read_byte(int i)
154 spin_unlock_irqrestore(&rtc_lock, flags); 155 spin_unlock_irqrestore(&rtc_lock, flags);
155 return c; 156 return c;
156} 157}
158EXPORT_SYMBOL(nvram_read_byte);
157 159
158/* This races nicely with trying to read with checksum checking (nvram_read) */ 160/* This races nicely with trying to read with checksum checking (nvram_read) */
159void 161void __nvram_write_byte(unsigned char c, int i)
160__nvram_write_byte(unsigned char c, int i)
161{ 162{
162 CMOS_WRITE(c, NVRAM_FIRST_BYTE + i); 163 CMOS_WRITE(c, NVRAM_FIRST_BYTE + i);
163} 164}
165EXPORT_SYMBOL(__nvram_write_byte);
164 166
165void 167void nvram_write_byte(unsigned char c, int i)
166nvram_write_byte(unsigned char c, int i)
167{ 168{
168 unsigned long flags; 169 unsigned long flags;
169 170
@@ -171,15 +172,15 @@ nvram_write_byte(unsigned char c, int i)
171 __nvram_write_byte(c, i); 172 __nvram_write_byte(c, i);
172 spin_unlock_irqrestore(&rtc_lock, flags); 173 spin_unlock_irqrestore(&rtc_lock, flags);
173} 174}
175EXPORT_SYMBOL(nvram_write_byte);
174 176
175int 177int __nvram_check_checksum(void)
176__nvram_check_checksum(void)
177{ 178{
178 return mach_check_checksum(); 179 return mach_check_checksum();
179} 180}
181EXPORT_SYMBOL(__nvram_check_checksum);
180 182
181int 183int nvram_check_checksum(void)
182nvram_check_checksum(void)
183{ 184{
184 unsigned long flags; 185 unsigned long flags;
185 int rv; 186 int rv;
@@ -189,16 +190,15 @@ nvram_check_checksum(void)
189 spin_unlock_irqrestore(&rtc_lock, flags); 190 spin_unlock_irqrestore(&rtc_lock, flags);
190 return rv; 191 return rv;
191} 192}
193EXPORT_SYMBOL(nvram_check_checksum);
192 194
193static void 195static void __nvram_set_checksum(void)
194__nvram_set_checksum(void)
195{ 196{
196 mach_set_checksum(); 197 mach_set_checksum();
197} 198}
198 199
199#if 0 200#if 0
200void 201void nvram_set_checksum(void)
201nvram_set_checksum(void)
202{ 202{
203 unsigned long flags; 203 unsigned long flags;
204 204
@@ -212,7 +212,7 @@ nvram_set_checksum(void)
212 * The are the file operation function for user access to /dev/nvram 212 * The are the file operation function for user access to /dev/nvram
213 */ 213 */
214 214
215static loff_t nvram_llseek(struct file *file,loff_t offset, int origin ) 215static loff_t nvram_llseek(struct file *file, loff_t offset, int origin)
216{ 216{
217 lock_kernel(); 217 lock_kernel();
218 switch (origin) { 218 switch (origin) {
@@ -230,8 +230,8 @@ static loff_t nvram_llseek(struct file *file,loff_t offset, int origin )
230 return (offset >= 0) ? (file->f_pos = offset) : -EINVAL; 230 return (offset >= 0) ? (file->f_pos = offset) : -EINVAL;
231} 231}
232 232
233static ssize_t 233static ssize_t nvram_read(struct file *file, char __user *buf,
234nvram_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) 234 size_t count, loff_t *ppos)
235{ 235{
236 unsigned char contents[NVRAM_BYTES]; 236 unsigned char contents[NVRAM_BYTES];
237 unsigned i = *ppos; 237 unsigned i = *ppos;
@@ -254,13 +254,13 @@ nvram_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
254 254
255 return tmp - contents; 255 return tmp - contents;
256 256
257 checksum_err: 257checksum_err:
258 spin_unlock_irq(&rtc_lock); 258 spin_unlock_irq(&rtc_lock);
259 return -EIO; 259 return -EIO;
260} 260}
261 261
262static ssize_t 262static ssize_t nvram_write(struct file *file, const char __user *buf,
263nvram_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) 263 size_t count, loff_t *ppos)
264{ 264{
265 unsigned char contents[NVRAM_BYTES]; 265 unsigned char contents[NVRAM_BYTES];
266 unsigned i = *ppos; 266 unsigned i = *ppos;
@@ -287,14 +287,13 @@ nvram_write(struct file *file, const char __user *buf, size_t count, loff_t *ppo
287 287
288 return tmp - contents; 288 return tmp - contents;
289 289
290 checksum_err: 290checksum_err:
291 spin_unlock_irq(&rtc_lock); 291 spin_unlock_irq(&rtc_lock);
292 return -EIO; 292 return -EIO;
293} 293}
294 294
295static int 295static int nvram_ioctl(struct inode *inode, struct file *file,
296nvram_ioctl(struct inode *inode, struct file *file, 296 unsigned int cmd, unsigned long arg)
297 unsigned int cmd, unsigned long arg)
298{ 297{
299 int i; 298 int i;
300 299
@@ -315,7 +314,7 @@ nvram_ioctl(struct inode *inode, struct file *file,
315 return 0; 314 return 0;
316 315
317 case NVRAM_SETCKS: 316 case NVRAM_SETCKS:
318 /* just set checksum, contents unchanged (maybe useful after 317 /* just set checksum, contents unchanged (maybe useful after
319 * checksum garbaged somehow...) */ 318 * checksum garbaged somehow...) */
320 if (!capable(CAP_SYS_ADMIN)) 319 if (!capable(CAP_SYS_ADMIN))
321 return -EACCES; 320 return -EACCES;
@@ -330,8 +329,7 @@ nvram_ioctl(struct inode *inode, struct file *file,
330 } 329 }
331} 330}
332 331
333static int 332static int nvram_open(struct inode *inode, struct file *file)
334nvram_open(struct inode *inode, struct file *file)
335{ 333{
336 lock_kernel(); 334 lock_kernel();
337 spin_lock(&nvram_state_lock); 335 spin_lock(&nvram_state_lock);
@@ -356,8 +354,7 @@ nvram_open(struct inode *inode, struct file *file)
356 return 0; 354 return 0;
357} 355}
358 356
359static int 357static int nvram_release(struct inode *inode, struct file *file)
360nvram_release(struct inode *inode, struct file *file)
361{ 358{
362 spin_lock(&nvram_state_lock); 359 spin_lock(&nvram_state_lock);
363 360
@@ -375,48 +372,47 @@ nvram_release(struct inode *inode, struct file *file)
375} 372}
376 373
377#ifndef CONFIG_PROC_FS 374#ifndef CONFIG_PROC_FS
378static int 375static int nvram_add_proc_fs(void)
379nvram_read_proc(char *buffer, char **start, off_t offset,
380 int size, int *eof, void *data)
381{ 376{
382 return 0; 377 return 0;
383} 378}
379
384#else 380#else
385 381
386static int 382static int nvram_proc_read(struct seq_file *seq, void *offset)
387nvram_read_proc(char *buffer, char **start, off_t offset,
388 int size, int *eof, void *data)
389{ 383{
390 unsigned char contents[NVRAM_BYTES]; 384 unsigned char contents[NVRAM_BYTES];
391 int i, len = 0; 385 int i = 0;
392 off_t begin = 0;
393 386
394 spin_lock_irq(&rtc_lock); 387 spin_lock_irq(&rtc_lock);
395 for (i = 0; i < NVRAM_BYTES; ++i) 388 for (i = 0; i < NVRAM_BYTES; ++i)
396 contents[i] = __nvram_read_byte(i); 389 contents[i] = __nvram_read_byte(i);
397 spin_unlock_irq(&rtc_lock); 390 spin_unlock_irq(&rtc_lock);
398 391
399 *eof = mach_proc_infos(contents, buffer, &len, &begin, offset, size); 392 mach_proc_infos(contents, seq, offset);
400 393
401 if (offset >= begin + len) 394 return 0;
402 return 0; 395}
403 *start = buffer + (offset - begin);
404 return (size < begin + len - offset) ? size : begin + len - offset;
405 396
397static int nvram_proc_open(struct inode *inode, struct file *file)
398{
399 return single_open(file, nvram_proc_read, NULL);
406} 400}
407 401
408/* This macro frees the machine specific function from bounds checking and 402static const struct file_operations nvram_proc_fops = {
409 * this like that... */ 403 .owner = THIS_MODULE,
410#define PRINT_PROC(fmt,args...) \ 404 .open = nvram_proc_open,
411 do { \ 405 .read = seq_read,
412 *len += sprintf(buffer+*len, fmt, ##args); \ 406 .llseek = seq_lseek,
413 if (*begin + *len > offset + size) \ 407 .release = single_release,
414 return 0; \ 408};
415 if (*begin + *len < offset) { \ 409
416 *begin += *len; \ 410static int nvram_add_proc_fs(void)
417 *len = 0; \ 411{
418 } \ 412 if (!proc_create("driver/nvram", 0, NULL, &nvram_proc_fops))
419 } while(0) 413 return -ENOMEM;
414 return 0;
415}
420 416
421#endif /* CONFIG_PROC_FS */ 417#endif /* CONFIG_PROC_FS */
422 418
@@ -436,8 +432,7 @@ static struct miscdevice nvram_dev = {
436 &nvram_fops 432 &nvram_fops
437}; 433};
438 434
439static int __init 435static int __init nvram_init(void)
440nvram_init(void)
441{ 436{
442 int ret; 437 int ret;
443 438
@@ -451,23 +446,21 @@ nvram_init(void)
451 NVRAM_MINOR); 446 NVRAM_MINOR);
452 goto out; 447 goto out;
453 } 448 }
454 if (!create_proc_read_entry("driver/nvram", 0, NULL, nvram_read_proc, 449 ret = nvram_add_proc_fs();
455 NULL)) { 450 if (ret) {
456 printk(KERN_ERR "nvram: can't create /proc/driver/nvram\n"); 451 printk(KERN_ERR "nvram: can't create /proc/driver/nvram\n");
457 ret = -ENOMEM;
458 goto outmisc; 452 goto outmisc;
459 } 453 }
460 ret = 0; 454 ret = 0;
461 printk(KERN_INFO "Non-volatile memory driver v" NVRAM_VERSION "\n"); 455 printk(KERN_INFO "Non-volatile memory driver v" NVRAM_VERSION "\n");
462 out: 456out:
463 return ret; 457 return ret;
464 outmisc: 458outmisc:
465 misc_deregister(&nvram_dev); 459 misc_deregister(&nvram_dev);
466 goto out; 460 goto out;
467} 461}
468 462
469static void __exit 463static void __exit nvram_cleanup_module(void)
470nvram_cleanup_module(void)
471{ 464{
472 remove_proc_entry("driver/nvram", NULL); 465 remove_proc_entry("driver/nvram", NULL);
473 misc_deregister(&nvram_dev); 466 misc_deregister(&nvram_dev);
@@ -482,8 +475,7 @@ module_exit(nvram_cleanup_module);
482 475
483#if MACH == PC 476#if MACH == PC
484 477
485static int 478static int pc_check_checksum(void)
486pc_check_checksum(void)
487{ 479{
488 int i; 480 int i;
489 unsigned short sum = 0; 481 unsigned short sum = 0;
@@ -493,11 +485,10 @@ pc_check_checksum(void)
493 sum += __nvram_read_byte(i); 485 sum += __nvram_read_byte(i);
494 expect = __nvram_read_byte(PC_CKS_LOC)<<8 | 486 expect = __nvram_read_byte(PC_CKS_LOC)<<8 |
495 __nvram_read_byte(PC_CKS_LOC+1); 487 __nvram_read_byte(PC_CKS_LOC+1);
496 return ((sum & 0xffff) == expect); 488 return (sum & 0xffff) == expect;
497} 489}
498 490
499static void 491static void pc_set_checksum(void)
500pc_set_checksum(void)
501{ 492{
502 int i; 493 int i;
503 unsigned short sum = 0; 494 unsigned short sum = 0;
@@ -522,9 +513,8 @@ static char *gfx_types[] = {
522 "monochrome", 513 "monochrome",
523}; 514};
524 515
525static int 516static void pc_proc_infos(unsigned char *nvram, struct seq_file *seq,
526pc_proc_infos(unsigned char *nvram, char *buffer, int *len, 517 void *offset)
527 off_t *begin, off_t offset, int size)
528{ 518{
529 int checksum; 519 int checksum;
530 int type; 520 int type;
@@ -533,56 +523,57 @@ pc_proc_infos(unsigned char *nvram, char *buffer, int *len,
533 checksum = __nvram_check_checksum(); 523 checksum = __nvram_check_checksum();
534 spin_unlock_irq(&rtc_lock); 524 spin_unlock_irq(&rtc_lock);
535 525
536 PRINT_PROC("Checksum status: %svalid\n", checksum ? "" : "not "); 526 seq_printf(seq, "Checksum status: %svalid\n", checksum ? "" : "not ");
537 527
538 PRINT_PROC("# floppies : %d\n", 528 seq_printf(seq, "# floppies : %d\n",
539 (nvram[6] & 1) ? (nvram[6] >> 6) + 1 : 0); 529 (nvram[6] & 1) ? (nvram[6] >> 6) + 1 : 0);
540 PRINT_PROC("Floppy 0 type : "); 530 seq_printf(seq, "Floppy 0 type : ");
541 type = nvram[2] >> 4; 531 type = nvram[2] >> 4;
542 if (type < ARRAY_SIZE(floppy_types)) 532 if (type < ARRAY_SIZE(floppy_types))
543 PRINT_PROC("%s\n", floppy_types[type]); 533 seq_printf(seq, "%s\n", floppy_types[type]);
544 else 534 else
545 PRINT_PROC("%d (unknown)\n", type); 535 seq_printf(seq, "%d (unknown)\n", type);
546 PRINT_PROC("Floppy 1 type : "); 536 seq_printf(seq, "Floppy 1 type : ");
547 type = nvram[2] & 0x0f; 537 type = nvram[2] & 0x0f;
548 if (type < ARRAY_SIZE(floppy_types)) 538 if (type < ARRAY_SIZE(floppy_types))
549 PRINT_PROC("%s\n", floppy_types[type]); 539 seq_printf(seq, "%s\n", floppy_types[type]);
550 else 540 else
551 PRINT_PROC("%d (unknown)\n", type); 541 seq_printf(seq, "%d (unknown)\n", type);
552 542
553 PRINT_PROC("HD 0 type : "); 543 seq_printf(seq, "HD 0 type : ");
554 type = nvram[4] >> 4; 544 type = nvram[4] >> 4;
555 if (type) 545 if (type)
556 PRINT_PROC("%02x\n", type == 0x0f ? nvram[11] : type); 546 seq_printf(seq, "%02x\n", type == 0x0f ? nvram[11] : type);
557 else 547 else
558 PRINT_PROC("none\n"); 548 seq_printf(seq, "none\n");
559 549
560 PRINT_PROC("HD 1 type : "); 550 seq_printf(seq, "HD 1 type : ");
561 type = nvram[4] & 0x0f; 551 type = nvram[4] & 0x0f;
562 if (type) 552 if (type)
563 PRINT_PROC("%02x\n", type == 0x0f ? nvram[12] : type); 553 seq_printf(seq, "%02x\n", type == 0x0f ? nvram[12] : type);
564 else 554 else
565 PRINT_PROC("none\n"); 555 seq_printf(seq, "none\n");
566 556
567 PRINT_PROC("HD type 48 data: %d/%d/%d C/H/S, precomp %d, lz %d\n", 557 seq_printf(seq, "HD type 48 data: %d/%d/%d C/H/S, precomp %d, lz %d\n",
568 nvram[18] | (nvram[19] << 8), 558 nvram[18] | (nvram[19] << 8),
569 nvram[20], nvram[25], 559 nvram[20], nvram[25],
570 nvram[21] | (nvram[22] << 8), nvram[23] | (nvram[24] << 8)); 560 nvram[21] | (nvram[22] << 8), nvram[23] | (nvram[24] << 8));
571 PRINT_PROC("HD type 49 data: %d/%d/%d C/H/S, precomp %d, lz %d\n", 561 seq_printf(seq, "HD type 49 data: %d/%d/%d C/H/S, precomp %d, lz %d\n",
572 nvram[39] | (nvram[40] << 8), 562 nvram[39] | (nvram[40] << 8),
573 nvram[41], nvram[46], 563 nvram[41], nvram[46],
574 nvram[42] | (nvram[43] << 8), nvram[44] | (nvram[45] << 8)); 564 nvram[42] | (nvram[43] << 8), nvram[44] | (nvram[45] << 8));
575 565
576 PRINT_PROC("DOS base memory: %d kB\n", nvram[7] | (nvram[8] << 8)); 566 seq_printf(seq, "DOS base memory: %d kB\n", nvram[7] | (nvram[8] << 8));
577 PRINT_PROC("Extended memory: %d kB (configured), %d kB (tested)\n", 567 seq_printf(seq, "Extended memory: %d kB (configured), %d kB (tested)\n",
578 nvram[9] | (nvram[10] << 8), nvram[34] | (nvram[35] << 8)); 568 nvram[9] | (nvram[10] << 8), nvram[34] | (nvram[35] << 8));
579 569
580 PRINT_PROC("Gfx adapter : %s\n", gfx_types[(nvram[6] >> 4) & 3]); 570 seq_printf(seq, "Gfx adapter : %s\n",
571 gfx_types[(nvram[6] >> 4) & 3]);
581 572
582 PRINT_PROC("FPU : %sinstalled\n", 573 seq_printf(seq, "FPU : %sinstalled\n",
583 (nvram[6] & 2) ? "" : "not "); 574 (nvram[6] & 2) ? "" : "not ");
584 575
585 return 1; 576 return;
586} 577}
587#endif 578#endif
588 579
@@ -590,20 +581,18 @@ pc_proc_infos(unsigned char *nvram, char *buffer, int *len,
590 581
591#if MACH == ATARI 582#if MACH == ATARI
592 583
593static int 584static int atari_check_checksum(void)
594atari_check_checksum(void)
595{ 585{
596 int i; 586 int i;
597 unsigned char sum = 0; 587 unsigned char sum = 0;
598 588
599 for (i = ATARI_CKS_RANGE_START; i <= ATARI_CKS_RANGE_END; ++i) 589 for (i = ATARI_CKS_RANGE_START; i <= ATARI_CKS_RANGE_END; ++i)
600 sum += __nvram_read_byte(i); 590 sum += __nvram_read_byte(i);
601 return (__nvram_read_byte(ATARI_CKS_LOC) == (~sum & 0xff) && 591 return (__nvram_read_byte(ATARI_CKS_LOC) == (~sum & 0xff)) &&
602 __nvram_read_byte(ATARI_CKS_LOC + 1) == (sum & 0xff)); 592 (__nvram_read_byte(ATARI_CKS_LOC + 1) == (sum & 0xff));
603} 593}
604 594
605static void 595static void atari_set_checksum(void)
606atari_set_checksum(void)
607{ 596{
608 int i; 597 int i;
609 unsigned char sum = 0; 598 unsigned char sum = 0;
@@ -654,82 +643,75 @@ static char *colors[] = {
654 "2", "4", "16", "256", "65536", "??", "??", "??" 643 "2", "4", "16", "256", "65536", "??", "??", "??"
655}; 644};
656 645
657static int 646static void atari_proc_infos(unsigned char *nvram, struct seq_file *seq,
658atari_proc_infos(unsigned char *nvram, char *buffer, int *len, 647 void *offset)
659 off_t *begin, off_t offset, int size)
660{ 648{
661 int checksum = nvram_check_checksum(); 649 int checksum = nvram_check_checksum();
662 int i; 650 int i;
663 unsigned vmode; 651 unsigned vmode;
664 652
665 PRINT_PROC("Checksum status : %svalid\n", checksum ? "" : "not "); 653 seq_printf(seq, "Checksum status : %svalid\n", checksum ? "" : "not ");
666 654
667 PRINT_PROC("Boot preference : "); 655 seq_printf(seq, "Boot preference : ");
668 for (i = ARRAY_SIZE(boot_prefs) - 1; i >= 0; --i) { 656 for (i = ARRAY_SIZE(boot_prefs) - 1; i >= 0; --i) {
669 if (nvram[1] == boot_prefs[i].val) { 657 if (nvram[1] == boot_prefs[i].val) {
670 PRINT_PROC("%s\n", boot_prefs[i].name); 658 seq_printf(seq, "%s\n", boot_prefs[i].name);
671 break; 659 break;
672 } 660 }
673 } 661 }
674 if (i < 0) 662 if (i < 0)
675 PRINT_PROC("0x%02x (undefined)\n", nvram[1]); 663 seq_printf(seq, "0x%02x (undefined)\n", nvram[1]);
676 664
677 PRINT_PROC("SCSI arbitration : %s\n", 665 seq_printf(seq, "SCSI arbitration : %s\n",
678 (nvram[16] & 0x80) ? "on" : "off"); 666 (nvram[16] & 0x80) ? "on" : "off");
679 PRINT_PROC("SCSI host ID : "); 667 seq_printf(seq, "SCSI host ID : ");
680 if (nvram[16] & 0x80) 668 if (nvram[16] & 0x80)
681 PRINT_PROC("%d\n", nvram[16] & 7); 669 seq_printf(seq, "%d\n", nvram[16] & 7);
682 else 670 else
683 PRINT_PROC("n/a\n"); 671 seq_printf(seq, "n/a\n");
684 672
685 /* the following entries are defined only for the Falcon */ 673 /* the following entries are defined only for the Falcon */
686 if ((atari_mch_cookie >> 16) != ATARI_MCH_FALCON) 674 if ((atari_mch_cookie >> 16) != ATARI_MCH_FALCON)
687 return 1; 675 return;
688 676
689 PRINT_PROC("OS language : "); 677 seq_printf(seq, "OS language : ");
690 if (nvram[6] < ARRAY_SIZE(languages)) 678 if (nvram[6] < ARRAY_SIZE(languages))
691 PRINT_PROC("%s\n", languages[nvram[6]]); 679 seq_printf(seq, "%s\n", languages[nvram[6]]);
692 else 680 else
693 PRINT_PROC("%u (undefined)\n", nvram[6]); 681 seq_printf(seq, "%u (undefined)\n", nvram[6]);
694 PRINT_PROC("Keyboard language: "); 682 seq_printf(seq, "Keyboard language: ");
695 if (nvram[7] < ARRAY_SIZE(languages)) 683 if (nvram[7] < ARRAY_SIZE(languages))
696 PRINT_PROC("%s\n", languages[nvram[7]]); 684 seq_printf(seq, "%s\n", languages[nvram[7]]);
697 else 685 else
698 PRINT_PROC("%u (undefined)\n", nvram[7]); 686 seq_printf(seq, "%u (undefined)\n", nvram[7]);
699 PRINT_PROC("Date format : "); 687 seq_printf(seq, "Date format : ");
700 PRINT_PROC(dateformat[nvram[8] & 7], 688 seq_printf(seq, dateformat[nvram[8] & 7],
701 nvram[9] ? nvram[9] : '/', nvram[9] ? nvram[9] : '/'); 689 nvram[9] ? nvram[9] : '/', nvram[9] ? nvram[9] : '/');
702 PRINT_PROC(", %dh clock\n", nvram[8] & 16 ? 24 : 12); 690 seq_printf(seq, ", %dh clock\n", nvram[8] & 16 ? 24 : 12);
703 PRINT_PROC("Boot delay : "); 691 seq_printf(seq, "Boot delay : ");
704 if (nvram[10] == 0) 692 if (nvram[10] == 0)
705 PRINT_PROC("default"); 693 seq_printf(seq, "default");
706 else 694 else
707 PRINT_PROC("%ds%s\n", nvram[10], 695 seq_printf(seq, "%ds%s\n", nvram[10],
708 nvram[10] < 8 ? ", no memory test" : ""); 696 nvram[10] < 8 ? ", no memory test" : "");
709 697
710 vmode = (nvram[14] << 8) || nvram[15]; 698 vmode = (nvram[14] << 8) || nvram[15];
711 PRINT_PROC("Video mode : %s colors, %d columns, %s %s monitor\n", 699 seq_printf(seq,
700 "Video mode : %s colors, %d columns, %s %s monitor\n",
712 colors[vmode & 7], 701 colors[vmode & 7],
713 vmode & 8 ? 80 : 40, 702 vmode & 8 ? 80 : 40,
714 vmode & 16 ? "VGA" : "TV", vmode & 32 ? "PAL" : "NTSC"); 703 vmode & 16 ? "VGA" : "TV", vmode & 32 ? "PAL" : "NTSC");
715 PRINT_PROC(" %soverscan, compat. mode %s%s\n", 704 seq_printf(seq, " %soverscan, compat. mode %s%s\n",
716 vmode & 64 ? "" : "no ", 705 vmode & 64 ? "" : "no ",
717 vmode & 128 ? "on" : "off", 706 vmode & 128 ? "on" : "off",
718 vmode & 256 ? 707 vmode & 256 ?
719 (vmode & 16 ? ", line doubling" : ", half screen") : ""); 708 (vmode & 16 ? ", line doubling" : ", half screen") : "");
720 709
721 return 1; 710 return;
722} 711}
723#endif 712#endif
724 713
725#endif /* MACH == ATARI */ 714#endif /* MACH == ATARI */
726 715
727MODULE_LICENSE("GPL"); 716MODULE_LICENSE("GPL");
728
729EXPORT_SYMBOL(__nvram_read_byte);
730EXPORT_SYMBOL(nvram_read_byte);
731EXPORT_SYMBOL(__nvram_write_byte);
732EXPORT_SYMBOL(nvram_write_byte);
733EXPORT_SYMBOL(__nvram_check_checksum);
734EXPORT_SYMBOL(nvram_check_checksum);
735MODULE_ALIAS_MISCDEV(NVRAM_MINOR); 717MODULE_ALIAS_MISCDEV(NVRAM_MINOR);
diff --git a/drivers/char/tty_audit.c b/drivers/char/tty_audit.c
index 5787249934c8..34ab6d798f81 100644
--- a/drivers/char/tty_audit.c
+++ b/drivers/char/tty_audit.c
@@ -67,6 +67,29 @@ static void tty_audit_buf_put(struct tty_audit_buf *buf)
67 tty_audit_buf_free(buf); 67 tty_audit_buf_free(buf);
68} 68}
69 69
70static void tty_audit_log(const char *description, struct task_struct *tsk,
71 uid_t loginuid, unsigned sessionid, int major,
72 int minor, unsigned char *data, size_t size)
73{
74 struct audit_buffer *ab;
75
76 ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_TTY);
77 if (ab) {
78 char name[sizeof(tsk->comm)];
79 uid_t uid = task_uid(tsk);
80
81 audit_log_format(ab, "%s pid=%u uid=%u auid=%u ses=%u "
82 "major=%d minor=%d comm=", description,
83 tsk->pid, uid, loginuid, sessionid,
84 major, minor);
85 get_task_comm(name, tsk);
86 audit_log_untrustedstring(ab, name);
87 audit_log_format(ab, " data=");
88 audit_log_n_hex(ab, data, size);
89 audit_log_end(ab);
90 }
91}
92
70/** 93/**
71 * tty_audit_buf_push - Push buffered data out 94 * tty_audit_buf_push - Push buffered data out
72 * 95 *
@@ -77,25 +100,12 @@ static void tty_audit_buf_push(struct task_struct *tsk, uid_t loginuid,
77 unsigned int sessionid, 100 unsigned int sessionid,
78 struct tty_audit_buf *buf) 101 struct tty_audit_buf *buf)
79{ 102{
80 struct audit_buffer *ab;
81
82 if (buf->valid == 0) 103 if (buf->valid == 0)
83 return; 104 return;
84 if (audit_enabled == 0) 105 if (audit_enabled == 0)
85 return; 106 return;
86 ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_TTY); 107 tty_audit_log("tty", tsk, loginuid, sessionid, buf->major, buf->minor,
87 if (ab) { 108 buf->data, buf->valid);
88 char name[sizeof(tsk->comm)];
89
90 audit_log_format(ab, "tty pid=%u uid=%u auid=%u ses=%u "
91 "major=%d minor=%d comm=", tsk->pid, tsk->uid,
92 loginuid, sessionid, buf->major, buf->minor);
93 get_task_comm(name, tsk);
94 audit_log_untrustedstring(ab, name);
95 audit_log_format(ab, " data=");
96 audit_log_n_hex(ab, buf->data, buf->valid);
97 audit_log_end(ab);
98 }
99 buf->valid = 0; 109 buf->valid = 0;
100} 110}
101 111
@@ -150,6 +160,42 @@ void tty_audit_fork(struct signal_struct *sig)
150} 160}
151 161
152/** 162/**
163 * tty_audit_tiocsti - Log TIOCSTI
164 */
165void tty_audit_tiocsti(struct tty_struct *tty, char ch)
166{
167 struct tty_audit_buf *buf;
168 int major, minor, should_audit;
169
170 spin_lock_irq(&current->sighand->siglock);
171 should_audit = current->signal->audit_tty;
172 buf = current->signal->tty_audit_buf;
173 if (buf)
174 atomic_inc(&buf->count);
175 spin_unlock_irq(&current->sighand->siglock);
176
177 major = tty->driver->major;
178 minor = tty->driver->minor_start + tty->index;
179 if (buf) {
180 mutex_lock(&buf->mutex);
181 if (buf->major == major && buf->minor == minor)
182 tty_audit_buf_push_current(buf);
183 mutex_unlock(&buf->mutex);
184 tty_audit_buf_put(buf);
185 }
186
187 if (should_audit && audit_enabled) {
188 uid_t auid;
189 unsigned int sessionid;
190
191 auid = audit_get_loginuid(current);
192 sessionid = audit_get_sessionid(current);
193 tty_audit_log("ioctl=TIOCSTI", current, auid, sessionid, major,
194 minor, &ch, 1);
195 }
196}
197
198/**
153 * tty_audit_push_task - Flush task's pending audit data 199 * tty_audit_push_task - Flush task's pending audit data
154 */ 200 */
155void tty_audit_push_task(struct task_struct *tsk, uid_t loginuid, u32 sessionid) 201void tty_audit_push_task(struct task_struct *tsk, uid_t loginuid, u32 sessionid)
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 1412a8d1e58d..db15f9ba7c0b 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -2018,6 +2018,7 @@ static int tiocsti(struct tty_struct *tty, char __user *p)
2018 return -EPERM; 2018 return -EPERM;
2019 if (get_user(ch, p)) 2019 if (get_user(ch, p))
2020 return -EFAULT; 2020 return -EFAULT;
2021 tty_audit_tiocsti(tty, ch);
2021 ld = tty_ldisc_ref_wait(tty); 2022 ld = tty_ldisc_ref_wait(tty);
2022 ld->ops->receive_buf(tty, &ch, &mbz, 1); 2023 ld->ops->receive_buf(tty, &ch, &mbz, 1);
2023 tty_ldisc_deref(ld); 2024 tty_ldisc_deref(ld);