Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * console.c: Routines that deal with sending and receiving IO
0004  *            to/from the current console device using the PROM.
0005  *
0006  * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
0007  * Copyright (C) 1998 Pete Zaitcev <zaitcev@yahoo.com>
0008  */
0009 
0010 #include <linux/types.h>
0011 #include <linux/kernel.h>
0012 #include <linux/sched.h>
0013 #include <asm/openprom.h>
0014 #include <asm/oplib.h>
0015 #include <linux/string.h>
0016 
0017 extern void restore_current(void);
0018 
0019 /* Non blocking put character to console device, returns -1 if
0020  * unsuccessful.
0021  */
0022 static int prom_nbputchar(const char *buf)
0023 {
0024     unsigned long flags;
0025     int i = -1;
0026 
0027     spin_lock_irqsave(&prom_lock, flags);
0028     switch(prom_vers) {
0029     case PROM_V0:
0030         if ((*(romvec->pv_nbputchar))(*buf))
0031             i = 1;
0032         break;
0033     case PROM_V2:
0034     case PROM_V3:
0035         if ((*(romvec->pv_v2devops).v2_dev_write)(*romvec->pv_v2bootargs.fd_stdout,
0036                               buf, 0x1) == 1)
0037             i = 1;
0038         break;
0039     default:
0040         break;
0041     }
0042     restore_current();
0043     spin_unlock_irqrestore(&prom_lock, flags);
0044     return i; /* Ugh, we could spin forever on unsupported proms ;( */
0045 }
0046 
0047 void prom_console_write_buf(const char *buf, int len)
0048 {
0049     while (len) {
0050         int n = prom_nbputchar(buf);
0051         if (n < 0)
0052             continue;
0053         len--;
0054         buf++;
0055     }
0056 }
0057