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/config.h>
12 #include <linux/kmod.h>
13 #include <linux/console.h>
14 #include <linux/init.h>
15 #include <linux/timer.h>
16 #include <linux/jiffies.h>
17 #include <linux/bootmem.h>
18 #include <linux/err.h>
24 #define SCLP_CON_PRINT_HEADER "sclp console driver: "
26 #define sclp_console_major 4 /* TTYAUX_MAJOR */
27 #define sclp_console_minor 64
28 #define sclp_console_name "ttyS"
30 /* Lock to guard over changes to global variables */
31 static spinlock_t sclp_con_lock
;
32 /* List of free pages that can be used for console output buffering */
33 static struct list_head sclp_con_pages
;
34 /* List of full struct sclp_buffer structures ready for output */
35 static struct list_head sclp_con_outqueue
;
36 /* Counter how many buffers are emitted (max 1) and how many */
37 /* are on the output queue. */
38 static int sclp_con_buffer_count
;
39 /* Pointer to current console buffer */
40 static struct sclp_buffer
*sclp_conbuf
;
41 /* Timer for delayed output of console messages */
42 static struct timer_list sclp_con_timer
;
44 /* Output format for console messages */
45 static unsigned short sclp_con_columns
;
46 static unsigned short sclp_con_width_htab
;
49 sclp_conbuf_callback(struct sclp_buffer
*buffer
, int rc
)
55 page
= sclp_unmake_buffer(buffer
);
56 spin_lock_irqsave(&sclp_con_lock
, flags
);
57 /* Remove buffer from outqueue */
58 list_del(&buffer
->list
);
59 sclp_con_buffer_count
--;
60 list_add_tail((struct list_head
*) page
, &sclp_con_pages
);
61 /* Check if there is a pending buffer on the out queue. */
63 if (!list_empty(&sclp_con_outqueue
))
64 buffer
= list_entry(sclp_con_outqueue
.next
,
65 struct sclp_buffer
, list
);
66 spin_unlock_irqrestore(&sclp_con_lock
, flags
);
67 } while (buffer
&& sclp_emit_buffer(buffer
, sclp_conbuf_callback
));
71 sclp_conbuf_emit(void)
73 struct sclp_buffer
* buffer
;
78 spin_lock_irqsave(&sclp_con_lock
, flags
);
82 spin_unlock_irqrestore(&sclp_con_lock
, flags
);
85 list_add_tail(&buffer
->list
, &sclp_con_outqueue
);
86 count
= sclp_con_buffer_count
++;
87 spin_unlock_irqrestore(&sclp_con_lock
, flags
);
90 rc
= sclp_emit_buffer(buffer
, sclp_conbuf_callback
);
92 sclp_conbuf_callback(buffer
, rc
);
96 * When this routine is called from the timer then we flush the
97 * temporary write buffer without further waiting on a final new line.
100 sclp_console_timeout(unsigned long data
)
106 * Writes the given message to S390 system console
109 sclp_console_write(struct console
*console
, const char *message
,
118 spin_lock_irqsave(&sclp_con_lock
, flags
);
120 * process escape characters, write message into buffer,
121 * send buffer to SCLP
124 /* make sure we have a console output buffer */
125 if (sclp_conbuf
== NULL
) {
126 while (list_empty(&sclp_con_pages
)) {
127 spin_unlock_irqrestore(&sclp_con_lock
, flags
);
129 spin_lock_irqsave(&sclp_con_lock
, flags
);
131 page
= sclp_con_pages
.next
;
132 list_del((struct list_head
*) page
);
133 sclp_conbuf
= sclp_make_buffer(page
, sclp_con_columns
,
134 sclp_con_width_htab
);
136 /* try to write the string to the current output buffer */
137 written
= sclp_write(sclp_conbuf
, (const unsigned char *)
139 if (written
== count
)
142 * Not all characters could be written to the current
143 * output buffer. Emit the buffer, create a new buffer
144 * and then output the rest of the string.
146 spin_unlock_irqrestore(&sclp_con_lock
, flags
);
148 spin_lock_irqsave(&sclp_con_lock
, flags
);
152 /* Setup timer to output current console buffer after 1/10 second */
153 if (sclp_conbuf
!= NULL
&& sclp_chars_in_buffer(sclp_conbuf
) != 0 &&
154 !timer_pending(&sclp_con_timer
)) {
155 init_timer(&sclp_con_timer
);
156 sclp_con_timer
.function
= sclp_console_timeout
;
157 sclp_con_timer
.data
= 0UL;
158 sclp_con_timer
.expires
= jiffies
+ HZ
/10;
159 add_timer(&sclp_con_timer
);
161 spin_unlock_irqrestore(&sclp_con_lock
, flags
);
164 static struct tty_driver
*
165 sclp_console_device(struct console
*c
, int *index
)
168 return sclp_tty_driver
;
172 * This routine is called from panic when the kernel
173 * is going to give up. We have to make sure that all buffers
174 * will be flushed to the SCLP.
177 sclp_console_unblank(void)
182 spin_lock_irqsave(&sclp_con_lock
, flags
);
183 if (timer_pending(&sclp_con_timer
))
184 del_timer(&sclp_con_timer
);
185 while (sclp_con_buffer_count
> 0) {
186 spin_unlock_irqrestore(&sclp_con_lock
, flags
);
188 spin_lock_irqsave(&sclp_con_lock
, flags
);
190 spin_unlock_irqrestore(&sclp_con_lock
, flags
);
194 * used to register the SCLP console to the kernel and to
195 * give printk necessary information
197 static struct console sclp_console
=
199 .name
= sclp_console_name
,
200 .write
= sclp_console_write
,
201 .device
= sclp_console_device
,
202 .unblank
= sclp_console_unblank
,
203 .flags
= CON_PRINTBUFFER
,
204 .index
= 0 /* ttyS0 */
208 * called by console_init() in drivers/char/tty_io.c at boot-time.
211 sclp_console_init(void)
217 if (!CONSOLE_IS_SCLP
)
222 /* Allocate pages for output buffering */
223 INIT_LIST_HEAD(&sclp_con_pages
);
224 for (i
= 0; i
< MAX_CONSOLE_PAGES
; i
++) {
225 page
= alloc_bootmem_low_pages(PAGE_SIZE
);
228 list_add_tail((struct list_head
*) page
, &sclp_con_pages
);
230 INIT_LIST_HEAD(&sclp_con_outqueue
);
231 spin_lock_init(&sclp_con_lock
);
232 sclp_con_buffer_count
= 0;
234 init_timer(&sclp_con_timer
);
236 /* Set output format */
239 * save 4 characters for the CPU number
240 * written at start of each line by VM/CP
242 sclp_con_columns
= 76;
244 sclp_con_columns
= 80;
245 sclp_con_width_htab
= 8;
247 /* enable printk-access to this driver */
248 register_console(&sclp_console
);
252 console_initcall(sclp_console_init
);