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>
19 #include <linux/reboot.h>
25 #define sclp_console_major 4 /* TTYAUX_MAJOR */
26 #define sclp_console_minor 64
27 #define sclp_console_name "ttyS"
29 /* Lock to guard over changes to global variables */
30 static spinlock_t sclp_con_lock;
31 /* List of free pages that can be used for console output buffering */
32 static struct list_head sclp_con_pages;
33 /* List of full struct sclp_buffer structures ready for output */
34 static struct list_head sclp_con_outqueue;
35 /* Counter how many buffers are emitted (max 1) and how many */
36 /* are on the output queue. */
37 static int sclp_con_buffer_count;
38 /* Pointer to current console buffer */
39 static struct sclp_buffer *sclp_conbuf;
40 /* Timer for delayed output of console messages */
41 static struct timer_list sclp_con_timer;
43 /* Output format for console messages */
44 static unsigned short sclp_con_columns;
45 static unsigned short sclp_con_width_htab;
48 sclp_conbuf_callback(struct sclp_buffer *buffer, int rc)
54 page = sclp_unmake_buffer(buffer);
55 spin_lock_irqsave(&sclp_con_lock, flags);
56 /* Remove buffer from outqueue */
57 list_del(&buffer->list);
58 sclp_con_buffer_count--;
59 list_add_tail((struct list_head *) page, &sclp_con_pages);
60 /* Check if there is a pending buffer on the out queue. */
62 if (!list_empty(&sclp_con_outqueue))
63 buffer = list_entry(sclp_con_outqueue.next,
64 struct sclp_buffer, list);
65 spin_unlock_irqrestore(&sclp_con_lock, flags);
66 } while (buffer && sclp_emit_buffer(buffer, sclp_conbuf_callback));
70 sclp_conbuf_emit(void)
72 struct sclp_buffer* buffer;
77 spin_lock_irqsave(&sclp_con_lock, flags);
81 spin_unlock_irqrestore(&sclp_con_lock, flags);
84 list_add_tail(&buffer->list, &sclp_con_outqueue);
85 count = sclp_con_buffer_count++;
86 spin_unlock_irqrestore(&sclp_con_lock, flags);
89 rc = sclp_emit_buffer(buffer, sclp_conbuf_callback);
91 sclp_conbuf_callback(buffer, rc);
95 * When this routine is called from the timer then we flush the
96 * temporary write buffer without further waiting on a final new line.
99 sclp_console_timeout(unsigned long data)
105 * Writes the given message to S390 system console
108 sclp_console_write(struct console *console, const char *message,
117 spin_lock_irqsave(&sclp_con_lock, flags);
119 * process escape characters, write message into buffer,
120 * send buffer to SCLP
123 /* make sure we have a console output buffer */
124 if (sclp_conbuf == NULL) {
125 while (list_empty(&sclp_con_pages)) {
126 spin_unlock_irqrestore(&sclp_con_lock, flags);
128 spin_lock_irqsave(&sclp_con_lock, flags);
130 page = sclp_con_pages.next;
131 list_del((struct list_head *) page);
132 sclp_conbuf = sclp_make_buffer(page, sclp_con_columns,
133 sclp_con_width_htab);
135 /* try to write the string to the current output buffer */
136 written = sclp_write(sclp_conbuf, (const unsigned char *)
138 if (written == count)
141 * Not all characters could be written to the current
142 * output buffer. Emit the buffer, create a new buffer
143 * and then output the rest of the string.
145 spin_unlock_irqrestore(&sclp_con_lock, flags);
147 spin_lock_irqsave(&sclp_con_lock, flags);
151 /* Setup timer to output current console buffer after 1/10 second */
152 if (sclp_conbuf != NULL && sclp_chars_in_buffer(sclp_conbuf) != 0 &&
153 !timer_pending(&sclp_con_timer)) {
154 init_timer(&sclp_con_timer);
155 sclp_con_timer.function = sclp_console_timeout;
156 sclp_con_timer.data = 0UL;
157 sclp_con_timer.expires = jiffies + HZ/10;
158 add_timer(&sclp_con_timer);
160 spin_unlock_irqrestore(&sclp_con_lock, flags);
163 static struct tty_driver *
164 sclp_console_device(struct console *c, int *index)
167 return sclp_tty_driver;
171 * This routine is called from panic when the kernel
172 * is going to give up. We have to make sure that all buffers
173 * will be flushed to the SCLP.
176 sclp_console_flush(void)
181 spin_lock_irqsave(&sclp_con_lock, flags);
182 if (timer_pending(&sclp_con_timer))
183 del_timer(&sclp_con_timer);
184 while (sclp_con_buffer_count > 0) {
185 spin_unlock_irqrestore(&sclp_con_lock, flags);
187 spin_lock_irqsave(&sclp_con_lock, flags);
189 spin_unlock_irqrestore(&sclp_con_lock, flags);
193 sclp_console_notify(struct notifier_block *self,
194 unsigned long event, void *data)
196 sclp_console_flush();
200 static struct notifier_block on_panic_nb = {
201 .notifier_call = sclp_console_notify,
205 static struct notifier_block on_reboot_nb = {
206 .notifier_call = sclp_console_notify,
211 * used to register the SCLP console to the kernel and to
212 * give printk necessary information
214 static struct console sclp_console =
216 .name = sclp_console_name,
217 .write = sclp_console_write,
218 .device = sclp_console_device,
219 .flags = CON_PRINTBUFFER,
220 .index = 0 /* ttyS0 */
224 * called by console_init() in drivers/char/tty_io.c at boot-time.
227 sclp_console_init(void)
233 if (!CONSOLE_IS_SCLP)
238 /* Allocate pages for output buffering */
239 INIT_LIST_HEAD(&sclp_con_pages);
240 for (i = 0; i < MAX_CONSOLE_PAGES; i++) {
241 page = alloc_bootmem_low_pages(PAGE_SIZE);
242 list_add_tail((struct list_head *) page, &sclp_con_pages);
244 INIT_LIST_HEAD(&sclp_con_outqueue);
245 spin_lock_init(&sclp_con_lock);
246 sclp_con_buffer_count = 0;
248 init_timer(&sclp_con_timer);
250 /* Set output format */
253 * save 4 characters for the CPU number
254 * written at start of each line by VM/CP
256 sclp_con_columns = 76;
258 sclp_con_columns = 80;
259 sclp_con_width_htab = 8;
261 /* enable printk-access to this driver */
262 atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
263 register_reboot_notifier(&on_reboot_nb);
264 register_console(&sclp_console);
268 console_initcall(sclp_console_init);