xref: /openbmc/linux/arch/sparc/prom/console_32.c (revision b2441318)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2708d4f09SSam Ravnborg /*
3708d4f09SSam Ravnborg  * console.c: Routines that deal with sending and receiving IO
4708d4f09SSam Ravnborg  *            to/from the current console device using the PROM.
5708d4f09SSam Ravnborg  *
6708d4f09SSam Ravnborg  * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
7708d4f09SSam Ravnborg  * Copyright (C) 1998 Pete Zaitcev <zaitcev@yahoo.com>
8708d4f09SSam Ravnborg  */
9708d4f09SSam Ravnborg 
10708d4f09SSam Ravnborg #include <linux/types.h>
11708d4f09SSam Ravnborg #include <linux/kernel.h>
12708d4f09SSam Ravnborg #include <linux/sched.h>
13708d4f09SSam Ravnborg #include <asm/openprom.h>
14708d4f09SSam Ravnborg #include <asm/oplib.h>
15708d4f09SSam Ravnborg #include <linux/string.h>
16708d4f09SSam Ravnborg 
17708d4f09SSam Ravnborg extern void restore_current(void);
18708d4f09SSam Ravnborg 
19708d4f09SSam Ravnborg /* Non blocking put character to console device, returns -1 if
20708d4f09SSam Ravnborg  * unsuccessful.
21708d4f09SSam Ravnborg  */
prom_nbputchar(const char * buf)22e62cac1fSDavid S. Miller static int prom_nbputchar(const char *buf)
23708d4f09SSam Ravnborg {
24708d4f09SSam Ravnborg 	unsigned long flags;
25708d4f09SSam Ravnborg 	int i = -1;
26708d4f09SSam Ravnborg 
27708d4f09SSam Ravnborg 	spin_lock_irqsave(&prom_lock, flags);
28708d4f09SSam Ravnborg 	switch(prom_vers) {
29708d4f09SSam Ravnborg 	case PROM_V0:
3015433768SJulian Calaby 		if ((*(romvec->pv_nbputchar))(*buf))
3115433768SJulian Calaby 			i = 1;
32708d4f09SSam Ravnborg 		break;
33708d4f09SSam Ravnborg 	case PROM_V2:
34708d4f09SSam Ravnborg 	case PROM_V3:
35e62cac1fSDavid S. Miller 		if ((*(romvec->pv_v2devops).v2_dev_write)(*romvec->pv_v2bootargs.fd_stdout,
36e62cac1fSDavid S. Miller 							  buf, 0x1) == 1)
3715433768SJulian Calaby 			i = 1;
38708d4f09SSam Ravnborg 		break;
39708d4f09SSam Ravnborg 	default:
40708d4f09SSam Ravnborg 		break;
416cb79b3fSJoe Perches 	}
42708d4f09SSam Ravnborg 	restore_current();
43708d4f09SSam Ravnborg 	spin_unlock_irqrestore(&prom_lock, flags);
44708d4f09SSam Ravnborg 	return i; /* Ugh, we could spin forever on unsupported proms ;( */
45708d4f09SSam Ravnborg }
46708d4f09SSam Ravnborg 
prom_console_write_buf(const char * buf,int len)47595a251cSDavid S. Miller void prom_console_write_buf(const char *buf, int len)
48708d4f09SSam Ravnborg {
49595a251cSDavid S. Miller 	while (len) {
50595a251cSDavid S. Miller 		int n = prom_nbputchar(buf);
5115433768SJulian Calaby 		if (n < 0)
52595a251cSDavid S. Miller 			continue;
53595a251cSDavid S. Miller 		len--;
54595a251cSDavid S. Miller 		buf++;
55e62cac1fSDavid S. Miller 	}
56708d4f09SSam Ravnborg }
57595a251cSDavid S. Miller 
58