Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * SCLP line mode console driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright IBM Corp. 1999, 2009
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Author(s): Martin Peschke <mpeschke@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *	      Martin Schwidefsky <schwidefsky@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/kmod.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/termios.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "sclp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "sclp_rw.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "sclp_tty.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define sclp_console_major 4		/* TTYAUX_MAJOR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define sclp_console_minor 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define sclp_console_name  "ttyS"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) /* Lock to guard over changes to global variables */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static spinlock_t sclp_con_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) /* List of free pages that can be used for console output buffering */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static struct list_head sclp_con_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) /* List of full struct sclp_buffer structures ready for output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static struct list_head sclp_con_outqueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) /* Pointer to current console buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static struct sclp_buffer *sclp_conbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) /* Timer for delayed output of console messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static struct timer_list sclp_con_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) /* Suspend mode flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static int sclp_con_suspended;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) /* Flag that output queue is currently running */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static int sclp_con_queue_running;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) /* Output format for console messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static unsigned short sclp_con_columns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static unsigned short sclp_con_width_htab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) sclp_conbuf_callback(struct sclp_buffer *buffer, int rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	void *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		page = sclp_unmake_buffer(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		spin_lock_irqsave(&sclp_con_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		/* Remove buffer from outqueue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		list_del(&buffer->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		list_add_tail((struct list_head *) page, &sclp_con_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		/* Check if there is a pending buffer on the out queue. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		buffer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		if (!list_empty(&sclp_con_outqueue))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			buffer = list_first_entry(&sclp_con_outqueue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 						  struct sclp_buffer, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		if (!buffer || sclp_con_suspended) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 			sclp_con_queue_running = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			spin_unlock_irqrestore(&sclp_con_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		spin_unlock_irqrestore(&sclp_con_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	} while (sclp_emit_buffer(buffer, sclp_conbuf_callback));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * Finalize and emit first pending buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) static void sclp_conbuf_emit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	struct sclp_buffer* buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	spin_lock_irqsave(&sclp_con_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	if (sclp_conbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		list_add_tail(&sclp_conbuf->list, &sclp_con_outqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	sclp_conbuf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (sclp_con_queue_running || sclp_con_suspended)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (list_empty(&sclp_con_outqueue))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	buffer = list_first_entry(&sclp_con_outqueue, struct sclp_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 				  list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	sclp_con_queue_running = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	spin_unlock_irqrestore(&sclp_con_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	rc = sclp_emit_buffer(buffer, sclp_conbuf_callback);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		sclp_conbuf_callback(buffer, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	spin_unlock_irqrestore(&sclp_con_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  * Wait until out queue is empty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static void sclp_console_sync_queue(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	spin_lock_irqsave(&sclp_con_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	if (timer_pending(&sclp_con_timer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		del_timer(&sclp_con_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	while (sclp_con_queue_running) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		spin_unlock_irqrestore(&sclp_con_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		sclp_sync_wait();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		spin_lock_irqsave(&sclp_con_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	spin_unlock_irqrestore(&sclp_con_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  * When this routine is called from the timer then we flush the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  * temporary write buffer without further waiting on a final new line.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) sclp_console_timeout(struct timer_list *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	sclp_conbuf_emit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  * Drop oldest console buffer if sclp_con_drop is set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) sclp_console_drop_buffer(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	struct list_head *list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	struct sclp_buffer *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	void *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (!sclp_console_drop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	list = sclp_con_outqueue.next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	if (sclp_con_queue_running)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		/* The first element is in I/O */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		list = list->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (list == &sclp_con_outqueue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	list_del(list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	buffer = list_entry(list, struct sclp_buffer, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	page = sclp_unmake_buffer(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	list_add_tail((struct list_head *) page, &sclp_con_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  * Writes the given message to S390 system console
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) sclp_console_write(struct console *console, const char *message,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		   unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	void *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	int written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (count == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	spin_lock_irqsave(&sclp_con_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	 * process escape characters, write message into buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	 * send buffer to SCLP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		/* make sure we have a console output buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		if (sclp_conbuf == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			if (list_empty(&sclp_con_pages))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 				sclp_console_full++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			while (list_empty(&sclp_con_pages)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 				if (sclp_con_suspended)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 					goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 				if (sclp_console_drop_buffer())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 				spin_unlock_irqrestore(&sclp_con_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 				sclp_sync_wait();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 				spin_lock_irqsave(&sclp_con_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			page = sclp_con_pages.next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			list_del((struct list_head *) page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			sclp_conbuf = sclp_make_buffer(page, sclp_con_columns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 						       sclp_con_width_htab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		/* try to write the string to the current output buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		written = sclp_write(sclp_conbuf, (const unsigned char *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 				     message, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		if (written == count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		 * Not all characters could be written to the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		 * output buffer. Emit the buffer, create a new buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		 * and then output the rest of the string.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		spin_unlock_irqrestore(&sclp_con_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		sclp_conbuf_emit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		spin_lock_irqsave(&sclp_con_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		message += written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		count -= written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	} while (count > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	/* Setup timer to output current console buffer after 1/10 second */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (sclp_conbuf != NULL && sclp_chars_in_buffer(sclp_conbuf) != 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	    !timer_pending(&sclp_con_timer)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		mod_timer(&sclp_con_timer, jiffies + HZ / 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	spin_unlock_irqrestore(&sclp_con_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static struct tty_driver *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) sclp_console_device(struct console *c, int *index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	*index = c->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	return sclp_tty_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)  * Make sure that all buffers will be flushed to the SCLP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) sclp_console_flush(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	sclp_conbuf_emit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	sclp_console_sync_queue();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  * Resume console: If there are cached messages, emit them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static void sclp_console_resume(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	spin_lock_irqsave(&sclp_con_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	sclp_con_suspended = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	spin_unlock_irqrestore(&sclp_con_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	sclp_conbuf_emit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)  * Suspend console: Set suspend flag and flush console
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static void sclp_console_suspend(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	spin_lock_irqsave(&sclp_con_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	sclp_con_suspended = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	spin_unlock_irqrestore(&sclp_con_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	sclp_console_flush();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static int sclp_console_notify(struct notifier_block *self,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			       unsigned long event, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	sclp_console_flush();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	return NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static struct notifier_block on_panic_nb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	.notifier_call = sclp_console_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	.priority = SCLP_PANIC_PRIO_CLIENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static struct notifier_block on_reboot_nb = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	.notifier_call = sclp_console_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	.priority = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)  * used to register the SCLP console to the kernel and to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)  * give printk necessary information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) static struct console sclp_console =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	.name = sclp_console_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	.write = sclp_console_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	.device = sclp_console_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	.flags = CON_PRINTBUFFER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	.index = 0 /* ttyS0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)  * This function is called for SCLP suspend and resume events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) void sclp_console_pm_event(enum sclp_pm_event sclp_pm_event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	switch (sclp_pm_event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	case SCLP_PM_EVENT_FREEZE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		sclp_console_suspend();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	case SCLP_PM_EVENT_RESTORE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	case SCLP_PM_EVENT_THAW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		sclp_console_resume();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)  * called by console_init() in drivers/char/tty_io.c at boot-time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) static int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) sclp_console_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	void *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	/* SCLP consoles are handled together */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	if (!(CONSOLE_IS_SCLP || CONSOLE_IS_VT220))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	rc = sclp_rw_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	/* Allocate pages for output buffering */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	INIT_LIST_HEAD(&sclp_con_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	for (i = 0; i < sclp_console_pages; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		page = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		list_add_tail(page, &sclp_con_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	INIT_LIST_HEAD(&sclp_con_outqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	spin_lock_init(&sclp_con_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	sclp_conbuf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	timer_setup(&sclp_con_timer, sclp_console_timeout, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	/* Set output format */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	if (MACHINE_IS_VM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		 * save 4 characters for the CPU number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		 * written at start of each line by VM/CP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		sclp_con_columns = 76;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		sclp_con_columns = 80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	sclp_con_width_htab = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	/* enable printk-access to this driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	register_reboot_notifier(&on_reboot_nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	register_console(&sclp_console);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) console_initcall(sclp_console_init);