Annotation of sys/arch/hp300/stand/common/dcm.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: dcm.c,v 1.5 2006/08/17 06:31:10 miod Exp $ */
2: /* $NetBSD: dcm.c,v 1.2 1997/04/14 05:58:32 scottr Exp $ */
3:
4: /*
5: * Copyright (c) 1988 University of Utah.
6: * Copyright (c) 1990, 1993
7: * The Regents of the University of California. All rights reserved.
8: *
9: * This code is derived from software contributed to Berkeley by
10: * the Systems Programming Group of the University of Utah Computer
11: * Science Department.
12: *
13: * Redistribution and use in source and binary forms, with or without
14: * modification, are permitted provided that the following conditions
15: * are met:
16: * 1. Redistributions of source code must retain the above copyright
17: * notice, this list of conditions and the following disclaimer.
18: * 2. Redistributions in binary form must reproduce the above copyright
19: * notice, this list of conditions and the following disclaimer in the
20: * documentation and/or other materials provided with the distribution.
21: * 3. Neither the name of the University nor the names of its contributors
22: * may be used to endorse or promote products derived from this software
23: * without specific prior written permission.
24: *
25: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35: * SUCH DAMAGE.
36: *
37: * @(#)dcm.c 8.1 (Berkeley) 6/10/93
38: */
39:
40: #ifdef DCMCONSOLE
41: #include <sys/param.h>
42:
43: #include <hp300/dev/dcmreg.h>
44:
45: #include "samachdep.h"
46: #include "consdefs.h"
47: #include "device.h"
48:
49: struct dcmdevice *dcmcnaddr = NULL;
50:
51: #define DCMCONUNIT 1 /* XXX */
52:
53: void
54: dcmprobe(struct consdev *cp)
55: {
56: extern struct hp_hw sc_table[];
57: struct hp_hw *hw;
58: struct dcmdevice *dcm;
59:
60: for (hw = sc_table; hw < &sc_table[MAXCTLRS]; hw++)
61: if (HW_ISDEV(hw, D_COMMDCM) && !badaddr((caddr_t)hw->hw_kva))
62: break;
63: if (!HW_ISDEV(hw, D_COMMDCM))
64: return;
65: dcmcnaddr = (struct dcmdevice *) hw->hw_kva;
66:
67: dcm = dcmcnaddr;
68: switch (dcm->dcm_rsid) {
69: case DCMID:
70: cp->cn_pri = CN_NORMAL;
71: break;
72: case DCMID|DCMCON:
73: cp->cn_pri = CN_REMOTE;
74: break;
75: default:
76: break;
77: }
78: }
79:
80: void
81: dcminit(struct consdev *cp)
82: {
83: struct dcmdevice *dcm = dcmcnaddr;
84: int port = DCMCONUNIT;
85:
86: dcm->dcm_ic = IC_ID;
87: while (dcm->dcm_thead[port].ptr != dcm->dcm_ttail[port].ptr)
88: ;
89: dcm->dcm_data[port].dcm_baud = BR_9600;
90: dcm->dcm_data[port].dcm_conf = LC_8BITS | LC_1STOP;
91: SEM_LOCK(dcm);
92: dcm->dcm_cmdtab[port].dcm_data |= CT_CON;
93: dcm->dcm_cr |= (1 << port);
94: SEM_UNLOCK(dcm);
95: DELAY(15000);
96: }
97:
98: /* ARGSUSED */
99: int
100: dcmgetchar(dev_t dev)
101: {
102: #ifndef SMALL
103: struct dcmdevice *dcm = dcmcnaddr;
104: struct dcmrfifo *fifo;
105: struct dcmpreg *pp;
106: unsigned head;
107: int c, stat, port;
108:
109: port = DCMCONUNIT;
110: pp = dcm_preg(dcm, port);
111: head = pp->r_head & RX_MASK;
112: if (head == (pp->r_tail & RX_MASK))
113: return(0);
114: fifo = &dcm->dcm_rfifos[3-port][head>>1];
115: c = fifo->data_char;
116: stat = fifo->data_stat;
117: pp->r_head = (head + 2) & RX_MASK;
118: SEM_LOCK(dcm);
119: stat = dcm->dcm_iir;
120: SEM_UNLOCK(dcm);
121: return(c);
122: #else
123: return(0);
124: #endif
125: }
126:
127: /* ARGSUSED */
128: void
129: dcmputchar(dev_t dev, int c)
130: {
131: struct dcmdevice *dcm = dcmcnaddr;
132: struct dcmpreg *pp;
133: int timo;
134: unsigned tail;
135: int port, stat;
136:
137: port = DCMCONUNIT;
138: pp = dcm_preg(dcm, port);
139: tail = pp->t_tail & TX_MASK;
140: timo = 50000;
141: while (tail != (pp->t_head & TX_MASK) && --timo)
142: ;
143: dcm->dcm_tfifos[3-port][tail].data_char = c;
144: pp->t_tail = tail = (tail + 1) & TX_MASK;
145: SEM_LOCK(dcm);
146: dcm->dcm_cmdtab[port].dcm_data |= CT_TX;
147: dcm->dcm_cr |= (1 << port);
148: SEM_UNLOCK(dcm);
149: timo = 1000000;
150: while (tail != (pp->t_head & TX_MASK) && --timo)
151: ;
152: SEM_LOCK(dcm);
153: stat = dcm->dcm_iir;
154: SEM_UNLOCK(dcm);
155: }
156: #endif
CVSweb