1/* $OpenBSD: promcons.c,v 1.1 2023/03/11 20:56:01 miod Exp $ */ 2/* $NetBSD: prom.c,v 1.2 1996/11/25 16:18:16 cgd Exp $ */ 3 4/* 5 * Mach Operating System 6 * Copyright (c) 1992 Carnegie Mellon University 7 * All Rights Reserved. 8 * 9 * Permission to use, copy, modify and distribute this software and its 10 * documentation is hereby granted, provided that both the copyright 11 * notice and this permission notice appear in all copies of the 12 * software, derivative works or modified versions, and any portions 13 * thereof, and that both notices appear in supporting documentation. 14 * 15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 17 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 18 * 19 * Carnegie Mellon requests users of this software to return to 20 * 21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 22 * School of Computer Science 23 * Carnegie Mellon University 24 * Pittsburgh PA 15213-3890 25 * 26 * any improvements or extensions that they make and grant Carnegie Mellon 27 * the rights to redistribute these changes. 28 */ 29 30#include <sys/types.h> 31#include <machine/rpb.h> 32#include <machine/prom.h> 33#include <dev/cons.h> 34 35#include "libsa.h" 36 37void 38prom_cnprobe(struct consdev *cn) 39{ 40 char buf[4]; 41 int console; 42 43 /* Look for console tty. */ 44 prom_getenv(PROM_E_TTY_DEV, buf, 4); 45 console = buf[0] - '0'; 46 47 cn->cn_pri = CN_MIDPRI; 48 cn->cn_dev = makedev(0, console); 49} 50 51void 52prom_cninit(struct consdev *cn) 53{ 54} 55 56int 57prom_cngetc(dev_t dev) 58{ 59 static int stash = 0; 60 int unit = dev & ~0x80; 61 int poll = (dev & 0x80) != 0; 62 int c; 63 prom_return_t ret; 64 65 if (stash != 0) { 66 c = stash; 67 if (!poll) 68 stash = 0; 69 return c; 70 } 71 72 for (;;) { 73 ret.bits = prom_dispatch(PROM_R_GETC, unit, 0, 0, 0); 74 if (ret.u.status == 0 || ret.u.status == 1) { 75 c = ret.u.retval; 76 if (poll) 77 stash = c; 78 return c; 79 } 80 if (poll) 81 return 0; 82 } 83} 84 85void 86prom_cnputc(dev_t dev, int c) 87{ 88 int unit = dev & ~0x80; 89 prom_return_t ret; 90 char cbuf = c; 91 92 do { 93 ret.bits = prom_dispatch(PROM_R_PUTS, unit, 94 (u_int64_t)&cbuf, 1, 0); 95 } while ((ret.u.retval & 1) == 0); 96} 97