1 /*        $NetBSD: cons.c,v 1.7 2011/02/08 20:20:14 rmind Exp $       */
2 
3 /*
4  * Copyright (c) 1988 University of Utah.
5  * Copyright (c) 1990, 1993
6  *        The Regents of the University of California.  All rights reserved.
7  *
8  * This code is derived from software contributed to Berkeley by
9  * the Systems Programming Group of the University of Utah Computer
10  * Science Department.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  * from: Utah Hdr: cons.c 1.7 92/02/28
37  *
38  *        @(#)cons.c          8.1 (Berkeley) 6/10/93
39  */
40 
41 #include <sys/param.h>
42 #include <dev/cons.h>
43 
44 #include <hp300/stand/common/consdefs.h>
45 #include <hp300/stand/common/samachdep.h>
46 
47 struct consdev constab[] = {
48 #ifdef ITECONSOLE
49           { iteprobe,         iteinit,  itegetchar,         iteputchar },
50 #endif
51 #ifdef DCACONSOLE
52           { dcaprobe,         dcainit,  dcagetchar,         dcaputchar },
53 #endif
54 #ifdef APCICONSOLE
55           { apciprobe,        apciinit, apcigetchar,        apciputchar },
56 #endif
57 #ifdef DCMCONSOLE
58           { dcmprobe,         dcminit,  dcmgetchar,         dcmputchar },
59 #endif
60           { 0 },
61 };
62 
63 int       curcons_scode;      /* select code of device currently being probed */
64 int       cons_scode;         /* final select code of console device */
65 
66 struct consdev *cn_tab;
67 int noconsole;
68 
69 void
cninit(void)70 cninit(void)
71 {
72           struct consdev *cp;
73 
74           cn_tab = NULL;
75           noconsole = 1;
76           cons_scode = 256;   /* larger than last valid select code */
77           for (cp = constab; cp->cn_probe; cp++) {
78                     (*cp->cn_probe)(cp);
79                     if (cp->cn_pri > CN_DEAD &&
80                         (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri)) {
81                               cn_tab = cp;
82                               cons_scode = curcons_scode;
83                     }
84           }
85           if (cn_tab) {
86                     (*cn_tab->cn_init)(cn_tab);
87                     noconsole = 0;
88 #if 0
89                     printf("console: ");
90                     switch (cons_scode) {
91                     case -2:
92                               printf("apci\n");
93                               break;
94                     case -1:
95                               printf("internal grf\n");
96                               break;
97                     default:
98                               printf("scode %d\n", cons_scode);
99                     }
100 #endif
101           }
102 }
103 
104 int
cngetc(void)105 cngetc(void)
106 {
107 
108           /* Note: the dev_t arguments are not used! */
109           if (cn_tab)
110                     return (*cn_tab->cn_getc)(0);
111           return 0;
112 }
113 
114 int
cnputc(int c)115 cnputc(int c)
116 {
117 
118           /* Note: the dev_t arguments are not used! */
119           if (userom)
120                     romputchar(c);
121           else if (cn_tab)
122                     (*cn_tab->cn_putc)(0, c);
123 
124           return 0;
125 }
126