diff options
Diffstat (limited to 'drivers/char')
-rw-r--r-- | drivers/char/Kconfig | 10 | ||||
-rw-r--r-- | drivers/char/Makefile | 1 | ||||
-rw-r--r-- | drivers/char/hvc_iucv.c | 850 | ||||
-rw-r--r-- | drivers/char/nvram.c | 264 | ||||
-rw-r--r-- | drivers/char/sysrq.c | 18 | ||||
-rw-r--r-- | drivers/char/tty_audit.c | 76 | ||||
-rw-r--r-- | drivers/char/tty_io.c | 1 |
7 files changed, 1063 insertions, 157 deletions
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index f57907a2c7a1..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 | ||
625 | config 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 | |||
625 | config HVC_XEN | 635 | config HVC_XEN |
626 | bool "Xen Hypervisor Console support" | 636 | bool "Xen Hypervisor Console support" |
627 | depends on XEN | 637 | depends on XEN |
diff --git a/drivers/char/Makefile b/drivers/char/Makefile index 52e15524af39..9caf5b5ad1c0 100644 --- a/drivers/char/Makefile +++ b/drivers/char/Makefile | |||
@@ -50,6 +50,7 @@ obj-$(CONFIG_HVC_BEAT) += hvc_beat.o | |||
50 | obj-$(CONFIG_HVC_DRIVER) += hvc_console.o | 50 | obj-$(CONFIG_HVC_DRIVER) += hvc_console.o |
51 | obj-$(CONFIG_HVC_IRQ) += hvc_irq.o | 51 | obj-$(CONFIG_HVC_IRQ) += hvc_irq.o |
52 | obj-$(CONFIG_HVC_XEN) += hvc_xen.o | 52 | obj-$(CONFIG_HVC_XEN) += hvc_xen.o |
53 | obj-$(CONFIG_HVC_IUCV) += hvc_iucv.o | ||
53 | obj-$(CONFIG_HVC_UDBG) += hvc_udbg.o | 54 | obj-$(CONFIG_HVC_UDBG) += hvc_udbg.o |
54 | obj-$(CONFIG_VIRTIO_CONSOLE) += virtio_console.o | 55 | obj-$(CONFIG_VIRTIO_CONSOLE) += virtio_console.o |
55 | obj-$(CONFIG_RAW_DRIVER) += raw.o | 56 | obj-$(CONFIG_RAW_DRIVER) += raw.o |
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)) | ||
37 | struct 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 | |||
45 | enum iucv_state_t { | ||
46 | IUCV_DISCONN = 0, | ||
47 | IUCV_CONNECTED = 1, | ||
48 | IUCV_SEVERED = 2, | ||
49 | }; | ||
50 | |||
51 | enum tty_state_t { | ||
52 | TTY_CLOSED = 0, | ||
53 | TTY_OPENED = 1, | ||
54 | }; | ||
55 | |||
56 | struct 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 | |||
67 | struct 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 */ | ||
75 | static int hvc_iucv_path_pending(struct iucv_path *, u8[8], u8[16]); | ||
76 | static void hvc_iucv_path_severed(struct iucv_path *, u8[16]); | ||
77 | static void hvc_iucv_msg_pending(struct iucv_path *, struct iucv_message *); | ||
78 | static void hvc_iucv_msg_complete(struct iucv_path *, struct iucv_message *); | ||
79 | |||
80 | |||
81 | /* Kernel module parameters */ | ||
82 | static unsigned long hvc_iucv_devices; | ||
83 | |||
84 | /* Array of allocated hvc iucv tty lines... */ | ||
85 | static struct hvc_iucv_private *hvc_iucv_table[MAX_HVC_IUCV_LINES]; | ||
86 | |||
87 | /* Kmem cache and mempool for iucv_tty_buffer elements */ | ||
88 | static struct kmem_cache *hvc_iucv_buffer_cache; | ||
89 | static mempool_t *hvc_iucv_mempool; | ||
90 | |||
91 | /* IUCV handler callback functions */ | ||
92 | static 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 | */ | ||
107 | struct 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 | */ | ||
126 | static 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 | */ | ||
156 | static 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 | */ | ||
170 | static 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 | */ | ||
200 | static 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 | |||
272 | out_remove_buffer: | ||
273 | list_del(&rb->list); | ||
274 | destroy_tty_buffer(rb); | ||
275 | *has_more_data = !list_empty(&priv->tty_inqueue); | ||
276 | |||
277 | out_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 | */ | ||
296 | static 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 | */ | ||
334 | static 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 | */ | ||
385 | static 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 | */ | ||
414 | static 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 | */ | ||
437 | static 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 | */ | ||
466 | static 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 | */ | ||
504 | static 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 | */ | ||
548 | static 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 | |||
591 | out_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 | */ | ||
611 | static 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 | */ | ||
645 | static 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 | |||
671 | unlock_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 | */ | ||
687 | static 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 */ | ||
706 | static 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 | */ | ||
722 | static 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 | */ | ||
757 | static 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 | |||
810 | out_error_iucv: | ||
811 | iucv_unregister(&hvc_iucv_handler, 0); | ||
812 | out_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 | */ | ||
827 | static 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 | */ | ||
838 | static int __init hvc_iucv_config(char *val) | ||
839 | { | ||
840 | return strict_strtoul(val, 10, &hvc_iucv_devices); | ||
841 | } | ||
842 | |||
843 | |||
844 | module_init(hvc_iucv_init); | ||
845 | console_initcall(hvc_iucv_console_init); | ||
846 | __setup("hvc_iucv=", hvc_iucv_config); | ||
847 | |||
848 | MODULE_LICENSE("GPL"); | ||
849 | MODULE_DESCRIPTION("HVC back-end for z/VM IUCV."); | ||
850 | MODULE_AUTHOR("Hendrik Brueckner <brueckner@linux.vnet.ibm.com>"); | ||
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 | ||
115 | static DEFINE_SPINLOCK(nvram_state_lock); | 117 | static DEFINE_SPINLOCK(nvram_state_lock); |
@@ -122,8 +124,8 @@ static int mach_check_checksum(void); | |||
122 | static void mach_set_checksum(void); | 124 | static void mach_set_checksum(void); |
123 | 125 | ||
124 | #ifdef CONFIG_PROC_FS | 126 | #ifdef CONFIG_PROC_FS |
125 | static int mach_proc_infos(unsigned char *contents, char *buffer, int *len, | 127 | static 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 | ||
140 | unsigned char | 142 | unsigned 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 | } |
146 | EXPORT_SYMBOL(__nvram_read_byte); | ||
145 | 147 | ||
146 | unsigned char | 148 | unsigned char nvram_read_byte(int i) |
147 | nvram_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 | } |
158 | EXPORT_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) */ |
159 | void | 161 | void __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 | } |
165 | EXPORT_SYMBOL(__nvram_write_byte); | ||
164 | 166 | ||
165 | void | 167 | void nvram_write_byte(unsigned char c, int i) |
166 | nvram_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 | } |
175 | EXPORT_SYMBOL(nvram_write_byte); | ||
174 | 176 | ||
175 | int | 177 | int __nvram_check_checksum(void) |
176 | __nvram_check_checksum(void) | ||
177 | { | 178 | { |
178 | return mach_check_checksum(); | 179 | return mach_check_checksum(); |
179 | } | 180 | } |
181 | EXPORT_SYMBOL(__nvram_check_checksum); | ||
180 | 182 | ||
181 | int | 183 | int nvram_check_checksum(void) |
182 | nvram_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 | } |
193 | EXPORT_SYMBOL(nvram_check_checksum); | ||
192 | 194 | ||
193 | static void | 195 | static 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 |
200 | void | 201 | void nvram_set_checksum(void) |
201 | nvram_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 | ||
215 | static loff_t nvram_llseek(struct file *file,loff_t offset, int origin ) | 215 | static 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 | ||
233 | static ssize_t | 233 | static ssize_t nvram_read(struct file *file, char __user *buf, |
234 | nvram_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: | 257 | checksum_err: |
258 | spin_unlock_irq(&rtc_lock); | 258 | spin_unlock_irq(&rtc_lock); |
259 | return -EIO; | 259 | return -EIO; |
260 | } | 260 | } |
261 | 261 | ||
262 | static ssize_t | 262 | static ssize_t nvram_write(struct file *file, const char __user *buf, |
263 | nvram_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: | 290 | checksum_err: |
291 | spin_unlock_irq(&rtc_lock); | 291 | spin_unlock_irq(&rtc_lock); |
292 | return -EIO; | 292 | return -EIO; |
293 | } | 293 | } |
294 | 294 | ||
295 | static int | 295 | static int nvram_ioctl(struct inode *inode, struct file *file, |
296 | nvram_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 | ||
333 | static int | 332 | static int nvram_open(struct inode *inode, struct file *file) |
334 | nvram_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 | ||
359 | static int | 357 | static int nvram_release(struct inode *inode, struct file *file) |
360 | nvram_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 |
378 | static int | 375 | static int nvram_add_proc_fs(void) |
379 | nvram_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 | ||
386 | static int | 382 | static int nvram_proc_read(struct seq_file *seq, void *offset) |
387 | nvram_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 | ||
397 | static 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 | 402 | static 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; \ | 410 | static 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 | ||
439 | static int __init | 435 | static int __init nvram_init(void) |
440 | nvram_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: | 456 | out: |
463 | return ret; | 457 | return ret; |
464 | outmisc: | 458 | outmisc: |
465 | misc_deregister(&nvram_dev); | 459 | misc_deregister(&nvram_dev); |
466 | goto out; | 460 | goto out; |
467 | } | 461 | } |
468 | 462 | ||
469 | static void __exit | 463 | static void __exit nvram_cleanup_module(void) |
470 | nvram_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 | ||
485 | static int | 478 | static int pc_check_checksum(void) |
486 | pc_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 | ||
499 | static void | 491 | static void pc_set_checksum(void) |
500 | pc_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 | ||
525 | static int | 516 | static void pc_proc_infos(unsigned char *nvram, struct seq_file *seq, |
526 | pc_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 | ||
593 | static int | 584 | static int atari_check_checksum(void) |
594 | atari_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 | ||
605 | static void | 595 | static void atari_set_checksum(void) |
606 | atari_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 | ||
657 | static int | 646 | static void atari_proc_infos(unsigned char *nvram, struct seq_file *seq, |
658 | atari_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 | ||
727 | MODULE_LICENSE("GPL"); | 716 | MODULE_LICENSE("GPL"); |
728 | |||
729 | EXPORT_SYMBOL(__nvram_read_byte); | ||
730 | EXPORT_SYMBOL(nvram_read_byte); | ||
731 | EXPORT_SYMBOL(__nvram_write_byte); | ||
732 | EXPORT_SYMBOL(nvram_write_byte); | ||
733 | EXPORT_SYMBOL(__nvram_check_checksum); | ||
734 | EXPORT_SYMBOL(nvram_check_checksum); | ||
735 | MODULE_ALIAS_MISCDEV(NVRAM_MINOR); | 717 | MODULE_ALIAS_MISCDEV(NVRAM_MINOR); |
diff --git a/drivers/char/sysrq.c b/drivers/char/sysrq.c index ce0d9da52a8a..94966edfb44d 100644 --- a/drivers/char/sysrq.c +++ b/drivers/char/sysrq.c | |||
@@ -274,6 +274,22 @@ static struct sysrq_key_op sysrq_showstate_blocked_op = { | |||
274 | .enable_mask = SYSRQ_ENABLE_DUMP, | 274 | .enable_mask = SYSRQ_ENABLE_DUMP, |
275 | }; | 275 | }; |
276 | 276 | ||
277 | #ifdef CONFIG_TRACING | ||
278 | #include <linux/ftrace.h> | ||
279 | |||
280 | static void sysrq_ftrace_dump(int key, struct tty_struct *tty) | ||
281 | { | ||
282 | ftrace_dump(); | ||
283 | } | ||
284 | static struct sysrq_key_op sysrq_ftrace_dump_op = { | ||
285 | .handler = sysrq_ftrace_dump, | ||
286 | .help_msg = "dumpZ-ftrace-buffer", | ||
287 | .action_msg = "Dump ftrace buffer", | ||
288 | .enable_mask = SYSRQ_ENABLE_DUMP, | ||
289 | }; | ||
290 | #else | ||
291 | #define sysrq_ftrace_dump_op (*(struct sysrq_key_op *)0) | ||
292 | #endif | ||
277 | 293 | ||
278 | static void sysrq_handle_showmem(int key, struct tty_struct *tty) | 294 | static void sysrq_handle_showmem(int key, struct tty_struct *tty) |
279 | { | 295 | { |
@@ -406,7 +422,7 @@ static struct sysrq_key_op *sysrq_key_table[36] = { | |||
406 | NULL, /* x */ | 422 | NULL, /* x */ |
407 | /* y: May be registered on sparc64 for global register dump */ | 423 | /* y: May be registered on sparc64 for global register dump */ |
408 | NULL, /* y */ | 424 | NULL, /* y */ |
409 | NULL /* z */ | 425 | &sysrq_ftrace_dump_op, /* z */ |
410 | }; | 426 | }; |
411 | 427 | ||
412 | /* key2index calculation, -1 on invalid index */ | 428 | /* key2index calculation, -1 on invalid index */ |
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 | ||
70 | static 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 | */ | ||
165 | void 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(¤t->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(¤t->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 | */ |
155 | void tty_audit_push_task(struct task_struct *tsk, uid_t loginuid, u32 sessionid) | 201 | void 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); |