Annotation of sys/arch/vax/boot/boot/ctu.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: ctu.c,v 1.4 2003/08/15 23:16:30 deraadt Exp $ */
2: /* $NetBSD: ctu.c,v 1.3 2000/05/20 13:30:03 ragge Exp $ */
3: /*
4: * Copyright (c) 1996 Ludd, University of Lule}, Sweden.
5: * All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. All advertising materials mentioning features or use of this software
16: * must display the following acknowledgement:
17: * This product includes software developed at Ludd, University of
18: * Lule}, Sweden and its contributors.
19: * 4. The name of the author may not be used to endorse or promote products
20: * derived from this software without specific prior written permission
21: *
22: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32: */
33:
34: /*
35: * Standalone device driver for 11/750 Console TU58.
36: * It can only handle reads, and doesn't calculate checksum.
37: */
38:
39: #include <sys/param.h>
40:
41: #include <lib/libsa/stand.h>
42:
43: #include <machine/mtpr.h>
44: #include <machine/rsp.h>
45:
46: #include "vaxstand.h"
47:
48: static short ctu_cksum(unsigned short *, int);
49:
50: enum tu_state {
51: SC_INIT,
52: SC_READY,
53: SC_SEND_CMD,
54: SC_GET_RESP,
55: };
56:
57: volatile struct tu_softc {
58: enum tu_state sc_state;
59: char sc_rsp[15]; /* Should be struct rsb; but don't work */
60: u_char *sc_xfptr; /* Current char to xfer */
61: int sc_nbytes; /* Number of bytes to xfer */
62: int sc_xbytes; /* Number of xfer'd bytes */
63: int sc_bbytes; /* Number of xfer'd bytes this block */
64: } tu_sc;
65:
66: void ctutintr(void);
67: void cturintr(void);
68:
69: int
70: ctuopen(struct open_file *f, int adapt, int ctlr, int unit, int part)
71: {
72:
73: tu_sc.sc_state = SC_INIT;
74:
75: mtpr(RSP_TYP_INIT, PR_CSTD);
76: cturintr();
77: tu_sc.sc_state = SC_READY;
78: return 0;
79:
80: }
81:
82: int
83: ctustrategy(void *f, int func, daddr_t dblk, size_t size, void *buf, size_t *rsize)
84: {
85: struct rsp *rsp = (struct rsp *)tu_sc.sc_rsp;
86:
87: tu_sc.sc_xfptr = buf;
88: tu_sc.sc_nbytes = size;
89: tu_sc.sc_xbytes = tu_sc.sc_bbytes = 0;
90:
91: rsp->rsp_typ = RSP_TYP_COMMAND;
92: rsp->rsp_sz = 012;
93: rsp->rsp_op = RSP_OP_READ;
94: rsp->rsp_mod = 0;
95: rsp->rsp_drv = 0;
96: rsp->rsp_sw = rsp->rsp_xx1 = rsp->rsp_xx2 = 0;
97: rsp->rsp_cnt = tu_sc.sc_nbytes;
98: rsp->rsp_blk = dblk;
99: rsp->rsp_sum = ctu_cksum((u_short *)rsp, 6);
100: tu_sc.sc_state = SC_SEND_CMD;
101: while (tu_sc.sc_state != SC_GET_RESP)
102: ctutintr();
103: while (tu_sc.sc_state != SC_READY)
104: cturintr();
105: *rsize = size;
106: return 0;
107: }
108:
109: void
110: cturintr(void)
111: {
112: int status;
113:
114: while ((mfpr(PR_CSRS) & 0x80) == 0)
115: ;
116:
117: status = mfpr(PR_CSRD);
118:
119: switch (tu_sc.sc_state) {
120:
121: case SC_INIT:
122: break;
123:
124: case SC_GET_RESP:
125: if (tu_sc.sc_xbytes == tu_sc.sc_nbytes) {
126: tu_sc.sc_bbytes++;
127: if (tu_sc.sc_bbytes == 146)
128: tu_sc.sc_state = SC_READY;
129: break;
130: }
131: tu_sc.sc_bbytes++;
132: if (tu_sc.sc_bbytes < 3) /* Data header */
133: break;
134: if (tu_sc.sc_bbytes == 132) { /* Finished */
135: tu_sc.sc_bbytes = 0;
136: break;
137: }
138: if (tu_sc.sc_bbytes == 131) /* First checksum */
139: break;
140: tu_sc.sc_xfptr[tu_sc.sc_xbytes++] = status;
141: break;
142: case SC_READY:
143: case SC_SEND_CMD:
144: break;
145: }
146:
147: }
148:
149: void
150: ctutintr(void)
151: {
152: int c;
153:
154: while ((mfpr(PR_CSTS) & 0x80) == 0)
155: ;
156:
157: c = tu_sc.sc_rsp[tu_sc.sc_xbytes++] & 0xff;
158: mtpr(c, PR_CSTD);
159: if (tu_sc.sc_xbytes > 13) {
160: tu_sc.sc_state = SC_GET_RESP;
161: tu_sc.sc_xbytes = 0;
162: }
163: }
164:
165: short
166: ctu_cksum(unsigned short *buf, int words)
167: {
168: int i, cksum;
169:
170: for (i = cksum = 0; i < words; i++)
171: cksum += buf[i];
172:
173: hej: if (cksum > 65535) {
174: cksum = (cksum & 65535) + (cksum >> 16);
175: goto hej;
176: }
177: return cksum;
178: }
CVSweb