^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) * console.c: Routines that deal with sending and receiving IO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * to/from the current console device using the PROM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 1998 Pete Zaitcev <zaitcev@yahoo.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/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/openprom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <asm/oplib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) extern void restore_current(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /* Non blocking put character to console device, returns -1 if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * unsuccessful.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static int prom_nbputchar(const char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) int i = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) spin_lock_irqsave(&prom_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) switch(prom_vers) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) case PROM_V0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) if ((*(romvec->pv_nbputchar))(*buf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) i = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) case PROM_V2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) case PROM_V3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) if ((*(romvec->pv_v2devops).v2_dev_write)(*romvec->pv_v2bootargs.fd_stdout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) buf, 0x1) == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) i = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) restore_current();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) spin_unlock_irqrestore(&prom_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) return i; /* Ugh, we could spin forever on unsupported proms ;( */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) void prom_console_write_buf(const char *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) while (len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) int n = prom_nbputchar(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) if (n < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) len--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) buf++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)