2 * drivers/s390/char/sclp_con.c
3 * SCLP line mode console driver
6 * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
8 * Martin Schwidefsky <schwidefsky@de.ibm.com>
11 #include <linux/kmod.h>
12 #include <linux/console.h>
13 #include <linux/init.h>
14 #include <linux/timer.h>
15 #include <linux/jiffies.h>
16 #include <linux/bootmem.h>
17 #include <linux/termios.h>
18 #include <linux/err.h>
24 #define sclp_console_major 4 /* TTYAUX_MAJOR */
25 #define sclp_console_minor 64
26 #define sclp_console_name "ttyS"
28 /* Lock to guard over changes to global variables */
29 static spinlock_t sclp_con_lock;
30 /* List of free pages that can be used for console output buffering */
31 static struct list_head sclp_con_pages;
32 /* List of full struct sclp_buffer structures ready for output */
33 static struct list_head sclp_con_outqueue;
34 /* Counter how many buffers are emitted (max 1) and how many */
35 /* are on the output queue. */
36 static int sclp_con_buffer_count;
37 /* Pointer to current console buffer */
38 static struct sclp_buffer *sclp_conbuf;
39 /* Timer for delayed output of console messages */
40 static struct timer_list sclp_con_timer;
42 /* Output format for console messages */
43 static unsigned short sclp_con_columns;
44 static unsigned short sclp_con_width_htab;
47 sclp_conbuf_callback(struct sclp_buffer *buffer, int rc)
53 page = sclp_unmake_buffer(buffer);
54 spin_lock_irqsave(&sclp_con_lock, flags);
55 /* Remove buffer from outqueue */
56 list_del(&buffer->list);
57 sclp_con_buffer_count--;
58 list_add_tail((struct list_head *) page, &sclp_con_pages);
59 /* Check if there is a pending buffer on the out queue. */
61 if (!list_empty(&sclp_con_outqueue))
62 buffer = list_entry(sclp_con_outqueue.next,
63 struct sclp_buffer, list);
64 spin_unlock_irqrestore(&sclp_con_lock, flags);
65 } while (buffer && sclp_emit_buffer(buffer, sclp_conbuf_callback));
69 sclp_conbuf_emit(void)
71 struct sclp_buffer* buffer;
76 spin_lock_irqsave(&sclp_con_lock, flags);
80 spin_unlock_irqrestore(&sclp_con_lock, flags);
83 list_add_tail(&buffer->list, &sclp_con_outqueue);
84 count = sclp_con_buffer_count++;
85 spin_unlock_irqrestore(&sclp_con_lock, flags);
88 rc = sclp_emit_buffer(buffer, sclp_conbuf_callback);
90 sclp_conbuf_callback(buffer, rc);
94 * When this routine is called from the timer then we flush the
95 * temporary write buffer without further waiting on a final new line.
98 sclp_console_timeout(unsigned long data)
104 * Writes the given message to S390 system console
107 sclp_console_write(struct console *console, const char *message,
116 spin_lock_irqsave(&sclp_con_lock, flags);
118 * process escape characters, write message into buffer,
119 * send buffer to SCLP
122 /* make sure we have a console output buffer */
123 if (sclp_conbuf == NULL) {
124 while (list_empty(&sclp_con_pages)) {
125 spin_unlock_irqrestore(&sclp_con_lock, flags);
127 spin_lock_irqsave(&sclp_con_lock, flags);
129 page = sclp_con_pages.next;
130 list_del((struct list_head *) page);
131 sclp_conbuf = sclp_make_buffer(page, sclp_con_columns,
132 sclp_con_width_htab);
134 /* try to write the string to the current output buffer */
135 written = sclp_write(sclp_conbuf, (const unsigned char *)
137 if (written == count)
140 * Not all characters could be written to the current
141 * output buffer. Emit the buffer, create a new buffer
142 * and then output the rest of the string.
144 spin_unlock_irqrestore(&sclp_con_lock, flags);
146 spin_lock_irqsave(&sclp_con_lock, flags);
150 /* Setup timer to output current console buffer after 1/10 second */
151 if (sclp_conbuf != NULL && sclp_chars_in_buffer(sclp_conbuf) != 0 &&
152 !timer_pending(&sclp_con_timer)) {
153 init_timer(&sclp_con_timer);
154 sclp_con_timer.function = sclp_console_timeout;
155 sclp_con_timer.data = 0UL;
156 sclp_con_timer.expires = jiffies + HZ/10;
157 add_timer(&sclp_con_timer);
159 spin_unlock_irqrestore(&sclp_con_lock, flags);
162 static struct tty_driver *
163 sclp_console_device(struct console *c, int *index)
166 return sclp_tty_driver;
170 * This routine is called from panic when the kernel
171 * is going to give up. We have to make sure that all buffers
172 * will be flushed to the SCLP.
175 sclp_console_unblank(void)
180 spin_lock_irqsave(&sclp_con_lock, flags);
181 if (timer_pending(&sclp_con_timer))
182 del_timer(&sclp_con_timer);
183 while (sclp_con_buffer_count > 0) {
184 spin_unlock_irqrestore(&sclp_con_lock, flags);
186 spin_lock_irqsave(&sclp_con_lock, flags);
188 spin_unlock_irqrestore(&sclp_con_lock, flags);
192 * used to register the SCLP console to the kernel and to
193 * give printk necessary information
195 static struct console sclp_console =
197 .name = sclp_console_name,
198 .write = sclp_console_write,
199 .device = sclp_console_device,
200 .unblank = sclp_console_unblank,
201 .flags = CON_PRINTBUFFER,
202 .index = 0 /* ttyS0 */
206 * called by console_init() in drivers/char/tty_io.c at boot-time.
209 sclp_console_init(void)
215 if (!CONSOLE_IS_SCLP)
220 /* Allocate pages for output buffering */
221 INIT_LIST_HEAD(&sclp_con_pages);
222 for (i = 0; i < MAX_CONSOLE_PAGES; i++) {
223 page = alloc_bootmem_low_pages(PAGE_SIZE);
224 list_add_tail((struct list_head *) page, &sclp_con_pages);
226 INIT_LIST_HEAD(&sclp_con_outqueue);
227 spin_lock_init(&sclp_con_lock);
228 sclp_con_buffer_count = 0;
230 init_timer(&sclp_con_timer);
232 /* Set output format */
235 * save 4 characters for the CPU number
236 * written at start of each line by VM/CP
238 sclp_con_columns = 76;
240 sclp_con_columns = 80;
241 sclp_con_width_htab = 8;
243 /* enable printk-access to this driver */
244 register_console(&sclp_console);
248 console_initcall(sclp_console_init);