Commit | Line | Data |
---|---|---|
740e4029 | 1 | /* dh.c 4.48 82/08/13 */ |
a18f326f | 2 | |
66b4fb09 | 3 | #include "dh.h" |
0916e0d1 | 4 | #if NDH > 0 |
a18f326f | 5 | /* |
d4638843 | 6 | * DH-11/DM-11 driver |
a18f326f | 7 | */ |
e2c4935e | 8 | #include "bk.h" |
a18f326f BJ |
9 | #include "../h/param.h" |
10 | #include "../h/conf.h" | |
11 | #include "../h/dir.h" | |
12 | #include "../h/user.h" | |
155d9ff0 | 13 | #include "../h/proc.h" |
a18f326f BJ |
14 | #include "../h/tty.h" |
15 | #include "../h/map.h" | |
16 | #include "../h/pte.h" | |
3f3a34c3 | 17 | #include "../h/buf.h" |
7e286c72 | 18 | #include "../h/vm.h" |
b09915c5 BJ |
19 | #include "../h/ubareg.h" |
20 | #include "../h/ubavar.h" | |
038bbe6b | 21 | #include "../h/bk.h" |
a5cc519e | 22 | #include "../h/clist.h" |
7e00c42b | 23 | #include "../h/file.h" |
740e4029 | 24 | #include "../h/uio.h" |
a18f326f | 25 | |
7e00c42b | 26 | /* |
d4638843 BJ |
27 | * Definition of the driver for the auto-configuration program. |
28 | * There is one definition for the dh and one for the dm. | |
7e00c42b | 29 | */ |
71236e46 | 30 | int dhprobe(), dhattach(), dhrint(), dhxint(); |
b09915c5 | 31 | struct uba_device *dhinfo[NDH]; |
3f3a34c3 | 32 | u_short dhstd[] = { 0 }; |
3f3a34c3 | 33 | struct uba_driver dhdriver = |
71236e46 | 34 | { dhprobe, 0, dhattach, 0, dhstd, "dh", dhinfo }; |
3f3a34c3 | 35 | |
71236e46 | 36 | int dmprobe(), dmattach(), dmintr(); |
b09915c5 | 37 | struct uba_device *dminfo[NDH]; |
d4638843 BJ |
38 | u_short dmstd[] = { 0 }; |
39 | struct uba_driver dmdriver = | |
71236e46 | 40 | { dmprobe, 0, dmattach, 0, dmstd, "dm", dminfo }; |
a18f326f | 41 | |
d4638843 BJ |
42 | struct dhdevice |
43 | { | |
44 | union { | |
45 | short dhcsr; /* control-status register */ | |
46 | char dhcsrl; /* low byte for line select */ | |
47 | } un; | |
48 | short dhrcr; /* receive character register */ | |
49 | short dhlpr; /* line parameter register */ | |
50 | u_short dhcar; /* current address register */ | |
51 | short dhbcr; /* byte count register */ | |
52 | u_short dhbar; /* buffer active register */ | |
53 | short dhbreak; /* break control register */ | |
54 | short dhsilo; /* silo status register */ | |
55 | }; | |
a18f326f | 56 | |
df07bd9e SL |
57 | #ifndef PORTSELECTOR |
58 | #define ISPEED B300 | |
59 | #define IFLAGS (EVENP|ODDP|ECHO) | |
60 | #else | |
61 | #define ISPEED B4800 | |
62 | #define IFLAGS (EVENP|ODDP) | |
63 | #endif | |
64 | ||
88d5b764 BJ |
65 | /* Bits in dhcsr */ |
66 | #define DH_TI 0100000 /* transmit interrupt */ | |
67 | #define DH_SI 0040000 /* storage interrupt */ | |
68 | #define DH_TIE 0020000 /* transmit interrupt enable */ | |
69 | #define DH_SIE 0010000 /* storage interrupt enable */ | |
70 | #define DH_MC 0004000 /* master clear */ | |
71 | #define DH_NXM 0002000 /* non-existant memory */ | |
72 | #define DH_MM 0001000 /* maintenance mode */ | |
73 | #define DH_CNI 0000400 /* clear non-existant memory interrupt */ | |
74 | #define DH_RI 0000200 /* receiver interrupt */ | |
75 | #define DH_RIE 0000100 /* receiver interrupt enable */ | |
76 | ||
d4638843 BJ |
77 | /* Bits in dhlpr */ |
78 | #define BITS6 01 | |
79 | #define BITS7 02 | |
80 | #define BITS8 03 | |
81 | #define TWOSB 04 | |
82 | #define PENABLE 020 | |
83 | /* DEC manuals incorrectly say this bit causes generation of even parity. */ | |
84 | #define OPAR 040 | |
85 | #define HDUPLX 040000 | |
86 | ||
88d5b764 BJ |
87 | #define DH_IE (DH_TIE|DH_SIE|DH_RIE) |
88 | ||
89 | /* Bits in dhrcr */ | |
d4638843 BJ |
90 | #define DH_PE 0010000 /* parity error */ |
91 | #define DH_FE 0020000 /* framing error */ | |
92 | #define DH_DO 0040000 /* data overrun */ | |
93 | ||
94 | struct dmdevice | |
95 | { | |
96 | short dmcsr; /* control status register */ | |
97 | short dmlstat; /* line status register */ | |
98 | short dmpad1[2]; | |
99 | }; | |
100 | ||
101 | /* bits in dm csr */ | |
102 | #define DM_RF 0100000 /* ring flag */ | |
103 | #define DM_CF 0040000 /* carrier flag */ | |
104 | #define DM_CTS 0020000 /* clear to send */ | |
105 | #define DM_SRF 0010000 /* secondary receive flag */ | |
106 | #define DM_CS 0004000 /* clear scan */ | |
107 | #define DM_CM 0002000 /* clear multiplexor */ | |
108 | #define DM_MM 0001000 /* maintenance mode */ | |
109 | #define DM_STP 0000400 /* step */ | |
110 | #define DM_DONE 0000200 /* scanner is done */ | |
111 | #define DM_IE 0000100 /* interrupt enable */ | |
112 | #define DM_SE 0000040 /* scan enable */ | |
113 | #define DM_BUSY 0000020 /* scan busy */ | |
114 | ||
115 | /* bits in dm lsr */ | |
116 | #define DML_RNG 0000200 /* ring */ | |
117 | #define DML_CAR 0000100 /* carrier detect */ | |
118 | #define DML_CTS 0000040 /* clear to send */ | |
119 | #define DML_SR 0000020 /* secondary receive */ | |
120 | #define DML_ST 0000010 /* secondary transmit */ | |
121 | #define DML_RTS 0000004 /* request to send */ | |
122 | #define DML_DTR 0000002 /* data terminal ready */ | |
123 | #define DML_LE 0000001 /* line enable */ | |
124 | ||
1d6c2d43 | 125 | #define DML_ON (DML_DTR|DML_RTS|DML_LE) |
d4638843 | 126 | #define DML_OFF (DML_LE) |
a18f326f | 127 | |
a18f326f | 128 | /* |
d4638843 | 129 | * Local variables for the driver |
a18f326f | 130 | */ |
0916e0d1 BJ |
131 | short dhsar[NDH]; /* software copy of last bar */ |
132 | short dhsoftCAR[NDH]; | |
a18f326f | 133 | |
0916e0d1 BJ |
134 | struct tty dh11[NDH*16]; |
135 | int ndh11 = NDH*16; | |
d4638843 BJ |
136 | int dhact; /* mask of active dh's */ |
137 | int dhstart(), ttrstrt(); | |
a18f326f | 138 | |
d4638843 BJ |
139 | /* |
140 | * The clist space is mapped by the driver onto each UNIBUS. | |
141 | * The UBACVT macro converts a clist space address for unibus uban | |
142 | * into an i/o space address for the DMA routine. | |
143 | */ | |
144 | int dh_ubinfo[MAXNUBA]; /* info about allocated unibus map */ | |
145 | int cbase[MAXNUBA]; /* base address in unibus map */ | |
146 | #define UBACVT(x, uban) (cbase[uban] + ((x)-(char *)cfree)) | |
a18f326f | 147 | |
88d5b764 BJ |
148 | /* |
149 | * Routine for configuration to force a dh to interrupt. | |
150 | * Set to transmit at 9600 baud, and cause a transmitter interrupt. | |
151 | */ | |
7e00c42b | 152 | /*ARGSUSED*/ |
71236e46 | 153 | dhprobe(reg) |
3f3a34c3 BJ |
154 | caddr_t reg; |
155 | { | |
7e00c42b | 156 | register int br, cvec; /* these are ``value-result'' */ |
d4638843 | 157 | register struct dhdevice *dhaddr = (struct dhdevice *)reg; |
5aa9d5ea | 158 | |
71236e46 BJ |
159 | #ifdef lint |
160 | br = 0; cvec = br; br = cvec; | |
fde2e6c9 | 161 | if (ndh11 == 0) ndh11 = 1; |
89b8a44c | 162 | dhrint(0); dhxint(0); |
71236e46 | 163 | #endif |
52ab9b2b | 164 | #ifndef notdef |
7e286c72 | 165 | dhaddr->un.dhcsr = DH_RIE|DH_MM|DH_RI; |
5e7ab705 | 166 | DELAY(1000); |
fde2e6c9 | 167 | dhaddr->un.dhcsr &= ~DH_RI; |
7e286c72 BJ |
168 | dhaddr->un.dhcsr = 0; |
169 | #else | |
88d5b764 BJ |
170 | dhaddr->un.dhcsr = DH_TIE; |
171 | DELAY(5); | |
172 | dhaddr->dhlpr = (B9600 << 10) | (B9600 << 6) | BITS7|PENABLE; | |
5aa9d5ea | 173 | dhaddr->dhbcr = -1; |
5aa9d5ea | 174 | dhaddr->dhcar = 0; |
88d5b764 BJ |
175 | dhaddr->dhbar = 1; |
176 | DELAY(100000); /* wait 1/10'th of a sec for interrupt */ | |
5aa9d5ea | 177 | dhaddr->un.dhcsr = 0; |
88d5b764 BJ |
178 | if (cvec && cvec != 0x200) |
179 | cvec -= 4; /* transmit -> receive */ | |
4afc81c0 | 180 | #endif |
9c0adba0 | 181 | return (sizeof (struct dhdevice)); |
3f3a34c3 BJ |
182 | } |
183 | ||
88d5b764 | 184 | /* |
71236e46 | 185 | * Routine called to attach a dh. |
88d5b764 | 186 | */ |
71236e46 | 187 | dhattach(ui) |
b09915c5 | 188 | struct uba_device *ui; |
3f3a34c3 BJ |
189 | { |
190 | ||
7e286c72 | 191 | dhsoftCAR[ui->ui_unit] = ui->ui_flags; |
3f3a34c3 BJ |
192 | } |
193 | ||
d4638843 BJ |
194 | /* |
195 | * Configuration routine to cause a dm to interrupt. | |
196 | */ | |
71236e46 BJ |
197 | dmprobe(reg) |
198 | caddr_t reg; | |
d4638843 BJ |
199 | { |
200 | register int br, vec; /* value-result */ | |
71236e46 | 201 | register struct dmdevice *dmaddr = (struct dmdevice *)reg; |
d4638843 | 202 | |
71236e46 | 203 | #ifdef lint |
a0eab615 | 204 | br = 0; vec = br; br = vec; |
155d9ff0 | 205 | dmintr(0); |
71236e46 | 206 | #endif |
d4638843 BJ |
207 | dmaddr->dmcsr = DM_DONE|DM_IE; |
208 | DELAY(20); | |
209 | dmaddr->dmcsr = 0; | |
71236e46 | 210 | return (1); |
d4638843 BJ |
211 | } |
212 | ||
71236e46 BJ |
213 | /*ARGSUSED*/ |
214 | dmattach(ui) | |
b09915c5 | 215 | struct uba_device *ui; |
d4638843 BJ |
216 | { |
217 | ||
218 | /* no local state to set up */ | |
219 | } | |
220 | ||
a18f326f | 221 | /* |
7e00c42b BJ |
222 | * Open a DH11 line, mapping the clist onto the uba if this |
223 | * is the first dh on this uba. Turn on this dh if this is | |
224 | * the first use of it. Also do a dmopen to wait for carrier. | |
a18f326f BJ |
225 | */ |
226 | /*ARGSUSED*/ | |
227 | dhopen(dev, flag) | |
3f3a34c3 | 228 | dev_t dev; |
a18f326f BJ |
229 | { |
230 | register struct tty *tp; | |
3f3a34c3 | 231 | register int unit, dh; |
d4638843 | 232 | register struct dhdevice *addr; |
b09915c5 | 233 | register struct uba_device *ui; |
a18f326f BJ |
234 | int s; |
235 | ||
3f3a34c3 BJ |
236 | unit = minor(dev); |
237 | dh = unit >> 4; | |
0916e0d1 | 238 | if (unit >= NDH*16 || (ui = dhinfo[dh])== 0 || ui->ui_alive == 0) { |
a18f326f BJ |
239 | u.u_error = ENXIO; |
240 | return; | |
241 | } | |
3f3a34c3 | 242 | tp = &dh11[unit]; |
941944c9 | 243 | if (tp->t_state&TS_XCLUDE && u.u_uid!=0) { |
7e00c42b BJ |
244 | u.u_error = EBUSY; |
245 | return; | |
246 | } | |
d4638843 | 247 | addr = (struct dhdevice *)ui->ui_addr; |
a18f326f BJ |
248 | tp->t_addr = (caddr_t)addr; |
249 | tp->t_oproc = dhstart; | |
941944c9 | 250 | tp->t_state |= TS_WOPEN; |
7e00c42b BJ |
251 | /* |
252 | * While setting up state for this uba and this dh, | |
253 | * block uba resets which can clear the state. | |
254 | */ | |
255 | s = spl5(); | |
5aa9d5ea | 256 | if (dh_ubinfo[ui->ui_ubanum] == 0) { |
d319892b | 257 | /* 512+ is a kludge to try to get around a hardware problem */ |
3f3a34c3 | 258 | dh_ubinfo[ui->ui_ubanum] = |
5aa9d5ea | 259 | uballoc(ui->ui_ubanum, (caddr_t)cfree, |
4c05b581 | 260 | 512+nclist*sizeof(struct cblock), 0); |
88d5b764 BJ |
261 | cbase[ui->ui_ubanum] = dh_ubinfo[ui->ui_ubanum]&0x3ffff; |
262 | } | |
263 | if ((dhact&(1<<dh)) == 0) { | |
264 | addr->un.dhcsr |= DH_IE; | |
88d5b764 | 265 | dhact |= (1<<dh); |
7e00c42b | 266 | addr->dhsilo = 16; |
a18f326f BJ |
267 | } |
268 | splx(s); | |
7e00c42b BJ |
269 | /* |
270 | * If this is first open, initialze tty state to default. | |
271 | */ | |
941944c9 | 272 | if ((tp->t_state&TS_ISOPEN) == 0) { |
a18f326f | 273 | ttychars(tp); |
df07bd9e | 274 | #ifndef PORTSELECTOR |
87f51a66 | 275 | if (tp->t_ispeed == 0) { |
df07bd9e SL |
276 | #endif |
277 | tp->t_ispeed = ISPEED; | |
278 | tp->t_ospeed = ISPEED; | |
279 | tp->t_flags = IFLAGS; | |
280 | #ifndef PORTSELECTOR | |
87f51a66 | 281 | } |
df07bd9e | 282 | #endif |
3f3a34c3 | 283 | dhparam(unit); |
a18f326f | 284 | } |
7e00c42b BJ |
285 | /* |
286 | * Wait for carrier, then process line discipline specific open. | |
287 | */ | |
a18f326f | 288 | dmopen(dev); |
3f3a34c3 | 289 | (*linesw[tp->t_line].l_open)(dev, tp); |
a18f326f BJ |
290 | } |
291 | ||
292 | /* | |
7e00c42b | 293 | * Close a DH11 line, turning off the DM11. |
a18f326f BJ |
294 | */ |
295 | /*ARGSUSED*/ | |
296 | dhclose(dev, flag) | |
3f3a34c3 BJ |
297 | dev_t dev; |
298 | int flag; | |
a18f326f BJ |
299 | { |
300 | register struct tty *tp; | |
3f3a34c3 | 301 | register unit; |
a18f326f | 302 | |
3f3a34c3 BJ |
303 | unit = minor(dev); |
304 | tp = &dh11[unit]; | |
a18f326f | 305 | (*linesw[tp->t_line].l_close)(tp); |
d4638843 | 306 | ((struct dhdevice *)(tp->t_addr))->dhbreak &= ~(1<<(unit&017)); |
941944c9 | 307 | if (tp->t_state&TS_HUPCLS || (tp->t_state&TS_ISOPEN)==0) |
d4638843 | 308 | dmctl(unit, DML_OFF, DMSET); |
a18f326f BJ |
309 | ttyclose(tp); |
310 | } | |
311 | ||
740e4029 | 312 | dhread(dev, uio) |
3f3a34c3 | 313 | dev_t dev; |
740e4029 | 314 | struct uio *uio; |
a18f326f | 315 | { |
3f3a34c3 | 316 | register struct tty *tp; |
a18f326f | 317 | |
3f3a34c3 | 318 | tp = &dh11[minor(dev)]; |
740e4029 | 319 | return ((*linesw[tp->t_line].l_read)(tp, uio)); |
a18f326f BJ |
320 | } |
321 | ||
a18f326f | 322 | dhwrite(dev) |
3f3a34c3 | 323 | dev_t dev; |
a18f326f | 324 | { |
3f3a34c3 | 325 | register struct tty *tp; |
a18f326f | 326 | |
3f3a34c3 | 327 | tp = &dh11[minor(dev)]; |
a18f326f BJ |
328 | (*linesw[tp->t_line].l_write)(tp); |
329 | } | |
330 | ||
331 | /* | |
332 | * DH11 receiver interrupt. | |
333 | */ | |
3f3a34c3 BJ |
334 | dhrint(dh) |
335 | int dh; | |
a18f326f BJ |
336 | { |
337 | register struct tty *tp; | |
3f3a34c3 | 338 | register c; |
d4638843 | 339 | register struct dhdevice *addr; |
0e239190 | 340 | register struct tty *tp0; |
b09915c5 | 341 | register struct uba_device *ui; |
b19fe459 | 342 | int overrun = 0; |
a18f326f | 343 | |
3f3a34c3 | 344 | ui = dhinfo[dh]; |
d4638843 BJ |
345 | if (ui == 0 || ui->ui_alive == 0) |
346 | return; | |
347 | addr = (struct dhdevice *)ui->ui_addr; | |
7e00c42b BJ |
348 | tp0 = &dh11[dh<<4]; |
349 | /* | |
350 | * Loop fetching characters from the silo for this | |
351 | * dh until there are no more in the silo. | |
352 | */ | |
353 | while ((c = addr->dhrcr) < 0) { | |
354 | tp = tp0 + ((c>>8)&0xf); | |
df07bd9e | 355 | #ifndef PORTSELECTOR |
941944c9 | 356 | if ((tp->t_state&TS_ISOPEN)==0) { |
df07bd9e SL |
357 | #else |
358 | if ((tp->t_state&(TS_ISOPEN|TS_WOPEN))==0) { | |
359 | #endif | |
a18f326f BJ |
360 | wakeup((caddr_t)tp); |
361 | continue; | |
362 | } | |
7e00c42b | 363 | if (c & DH_PE) |
a18f326f BJ |
364 | if ((tp->t_flags&(EVENP|ODDP))==EVENP |
365 | || (tp->t_flags&(EVENP|ODDP))==ODDP ) | |
366 | continue; | |
b19fe459 BJ |
367 | if ((c & DH_DO) && overrun == 0) { |
368 | printf("dh%d: silo overflow\n", dh); | |
369 | overrun = 1; | |
370 | } | |
7e00c42b BJ |
371 | if (c & DH_FE) |
372 | /* | |
373 | * At framing error (break) generate | |
374 | * a null (in raw mode, for getty), or a | |
375 | * interrupt (in cooked/cbreak mode). | |
376 | */ | |
a18f326f | 377 | if (tp->t_flags&RAW) |
7e00c42b | 378 | c = 0; |
a18f326f | 379 | else |
1c17c385 | 380 | c = tun.t_intrc; |
e2c4935e | 381 | #if NBK > 0 |
5c6adb3e | 382 | if (tp->t_line == NETLDISC) { |
0e239190 | 383 | c &= 0177; |
87f51a66 | 384 | BKINPUT(c, tp); |
0e239190 | 385 | } else |
e2c4935e | 386 | #endif |
7e00c42b | 387 | (*linesw[tp->t_line].l_rint)(c, tp); |
a18f326f BJ |
388 | } |
389 | } | |
390 | ||
391 | /* | |
7e00c42b | 392 | * Ioctl for DH11. |
a18f326f BJ |
393 | */ |
394 | /*ARGSUSED*/ | |
942f05a9 SL |
395 | dhioctl(dev, cmd, data, flag) |
396 | caddr_t data; | |
a18f326f BJ |
397 | { |
398 | register struct tty *tp; | |
3f3a34c3 | 399 | register unit = minor(dev); |
a18f326f | 400 | |
3f3a34c3 | 401 | tp = &dh11[unit]; |
942f05a9 | 402 | cmd = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag); |
7e00c42b | 403 | if (cmd == 0) |
038bbe6b | 404 | return; |
942f05a9 SL |
405 | if (ttioctl(tp, cmd, data, flag)) { |
406 | if (cmd == TIOCSETP || cmd == TIOCSETN) | |
3f3a34c3 | 407 | dhparam(unit); |
87f51a66 | 408 | } else switch(cmd) { |
942f05a9 | 409 | |
87f51a66 | 410 | case TIOCSBRK: |
d4638843 | 411 | ((struct dhdevice *)(tp->t_addr))->dhbreak |= 1<<(unit&017); |
87f51a66 | 412 | break; |
942f05a9 | 413 | |
87f51a66 | 414 | case TIOCCBRK: |
d4638843 | 415 | ((struct dhdevice *)(tp->t_addr))->dhbreak &= ~(1<<(unit&017)); |
87f51a66 | 416 | break; |
942f05a9 | 417 | |
87f51a66 | 418 | case TIOCSDTR: |
d4638843 | 419 | dmctl(unit, DML_DTR|DML_RTS, DMBIS); |
87f51a66 | 420 | break; |
942f05a9 | 421 | |
87f51a66 | 422 | case TIOCCDTR: |
d4638843 | 423 | dmctl(unit, DML_DTR|DML_RTS, DMBIC); |
87f51a66 | 424 | break; |
942f05a9 | 425 | |
87f51a66 | 426 | default: |
a18f326f | 427 | u.u_error = ENOTTY; |
87f51a66 | 428 | } |
a18f326f BJ |
429 | } |
430 | ||
431 | /* | |
432 | * Set parameters from open or stty into the DH hardware | |
433 | * registers. | |
434 | */ | |
3f3a34c3 BJ |
435 | dhparam(unit) |
436 | register int unit; | |
a18f326f BJ |
437 | { |
438 | register struct tty *tp; | |
d4638843 | 439 | register struct dhdevice *addr; |
3f3a34c3 | 440 | register int lpar; |
0072a3c2 | 441 | int s; |
a18f326f | 442 | |
3f3a34c3 | 443 | tp = &dh11[unit]; |
d4638843 | 444 | addr = (struct dhdevice *)tp->t_addr; |
7e00c42b BJ |
445 | /* |
446 | * Block interrupts so parameters will be set | |
447 | * before the line interrupts. | |
448 | */ | |
0072a3c2 | 449 | s = spl5(); |
7e00c42b | 450 | addr->un.dhcsrl = (unit&0xf) | DH_IE; |
a18f326f | 451 | if ((tp->t_ispeed)==0) { |
941944c9 | 452 | tp->t_state |= TS_HUPCLS; |
d4638843 | 453 | dmctl(unit, DML_OFF, DMSET); |
a18f326f BJ |
454 | return; |
455 | } | |
3f3a34c3 | 456 | lpar = ((tp->t_ospeed)<<10) | ((tp->t_ispeed)<<6); |
7e00c42b | 457 | if ((tp->t_ispeed) == B134) |
3f3a34c3 | 458 | lpar |= BITS6|PENABLE|HDUPLX; |
131b2e17 | 459 | else if ((tp->t_flags&RAW) || (tp->t_local&LLITOUT)) |
3f3a34c3 | 460 | lpar |= BITS8; |
a18f326f | 461 | else |
3f3a34c3 | 462 | lpar |= BITS7|PENABLE; |
a18f326f | 463 | if ((tp->t_flags&EVENP) == 0) |
3f3a34c3 | 464 | lpar |= OPAR; |
7e00c42b | 465 | if ((tp->t_ospeed) == B110) |
3f3a34c3 BJ |
466 | lpar |= TWOSB; |
467 | addr->dhlpr = lpar; | |
0072a3c2 | 468 | splx(s); |
a18f326f BJ |
469 | } |
470 | ||
471 | /* | |
472 | * DH11 transmitter interrupt. | |
473 | * Restart each line which used to be active but has | |
474 | * terminated transmission since the last interrupt. | |
475 | */ | |
3f3a34c3 BJ |
476 | dhxint(dh) |
477 | int dh; | |
a18f326f BJ |
478 | { |
479 | register struct tty *tp; | |
d4638843 | 480 | register struct dhdevice *addr; |
a18f326f | 481 | short ttybit, bar, *sbar; |
b09915c5 | 482 | register struct uba_device *ui; |
7e00c42b | 483 | register int unit; |
71236e46 | 484 | u_short cntr; |
a18f326f | 485 | |
3f3a34c3 | 486 | ui = dhinfo[dh]; |
d4638843 | 487 | addr = (struct dhdevice *)ui->ui_addr; |
88d5b764 BJ |
488 | if (addr->un.dhcsr & DH_NXM) { |
489 | addr->un.dhcsr |= DH_CNI; | |
b19fe459 | 490 | printf("dh%d: NXM\n", dh); |
b4ec79ea | 491 | } |
3f3a34c3 | 492 | sbar = &dhsar[dh]; |
a18f326f | 493 | bar = *sbar & ~addr->dhbar; |
3f3a34c3 | 494 | unit = dh * 16; ttybit = 1; |
7e00c42b BJ |
495 | addr->un.dhcsr &= (short)~DH_TI; |
496 | for (; bar; unit++, ttybit <<= 1) { | |
497 | if (bar & ttybit) { | |
a18f326f BJ |
498 | *sbar &= ~ttybit; |
499 | bar &= ~ttybit; | |
3f3a34c3 | 500 | tp = &dh11[unit]; |
941944c9 BJ |
501 | tp->t_state &= ~TS_BUSY; |
502 | if (tp->t_state&TS_FLUSH) | |
503 | tp->t_state &= ~TS_FLUSH; | |
038bbe6b | 504 | else { |
88d5b764 | 505 | addr->un.dhcsrl = (unit&017)|DH_IE; |
7e00c42b BJ |
506 | /* |
507 | * Do arithmetic in a short to make up | |
508 | * for lost 16&17 bits. | |
509 | */ | |
71236e46 | 510 | cntr = addr->dhcar - |
7e00c42b | 511 | UBACVT(tp->t_outq.c_cf, ui->ui_ubanum); |
a0eab615 | 512 | ndflush(&tp->t_outq, (int)cntr); |
a18f326f | 513 | } |
038bbe6b BJ |
514 | if (tp->t_line) |
515 | (*linesw[tp->t_line].l_start)(tp); | |
516 | else | |
517 | dhstart(tp); | |
a18f326f BJ |
518 | } |
519 | } | |
520 | } | |
521 | ||
522 | /* | |
523 | * Start (restart) transmission on the given DH11 line. | |
524 | */ | |
525 | dhstart(tp) | |
3f3a34c3 | 526 | register struct tty *tp; |
a18f326f | 527 | { |
d4638843 | 528 | register struct dhdevice *addr; |
7e00c42b | 529 | register int car, dh, unit, nch; |
3f3a34c3 | 530 | int s; |
a18f326f | 531 | |
3f3a34c3 BJ |
532 | unit = minor(tp->t_dev); |
533 | dh = unit >> 4; | |
7e00c42b | 534 | unit &= 0xf; |
d4638843 | 535 | addr = (struct dhdevice *)tp->t_addr; |
7e00c42b BJ |
536 | |
537 | /* | |
538 | * Must hold interrupts in following code to prevent | |
539 | * state of the tp from changing. | |
540 | */ | |
541 | s = spl5(); | |
542 | /* | |
543 | * If it's currently active, or delaying, no need to do anything. | |
544 | */ | |
941944c9 | 545 | if (tp->t_state&(TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) |
a18f326f | 546 | goto out; |
7e00c42b BJ |
547 | /* |
548 | * If there are sleepers, and output has drained below low | |
549 | * water mark, wake up the sleepers. | |
550 | */ | |
941944c9 BJ |
551 | if (tp->t_outq.c_cc<=TTLOWAT(tp)) { |
552 | if (tp->t_state&TS_ASLEEP) { | |
553 | tp->t_state &= ~TS_ASLEEP; | |
554 | wakeup((caddr_t)&tp->t_outq); | |
555 | } | |
556 | if (tp->t_wsel) { | |
557 | selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL); | |
558 | tp->t_wsel = 0; | |
559 | tp->t_state &= ~TS_WCOLL; | |
560 | } | |
a18f326f | 561 | } |
7e00c42b BJ |
562 | /* |
563 | * Now restart transmission unless the output queue is | |
564 | * empty. | |
565 | */ | |
a18f326f BJ |
566 | if (tp->t_outq.c_cc == 0) |
567 | goto out; | |
6e3ea160 | 568 | if (tp->t_flags&RAW || tp->t_local&LLITOUT) |
a18f326f | 569 | nch = ndqb(&tp->t_outq, 0); |
3f3a34c3 | 570 | else { |
a18f326f | 571 | nch = ndqb(&tp->t_outq, 0200); |
7e00c42b BJ |
572 | /* |
573 | * If first thing on queue is a delay process it. | |
574 | */ | |
a18f326f BJ |
575 | if (nch == 0) { |
576 | nch = getc(&tp->t_outq); | |
7e00c42b | 577 | timeout(ttrstrt, (caddr_t)tp, (nch&0x7f)+6); |
941944c9 | 578 | tp->t_state |= TS_TIMEOUT; |
a18f326f BJ |
579 | goto out; |
580 | } | |
581 | } | |
7e00c42b BJ |
582 | /* |
583 | * If characters to transmit, restart transmission. | |
584 | */ | |
a18f326f | 585 | if (nch) { |
7e00c42b BJ |
586 | car = UBACVT(tp->t_outq.c_cf, dhinfo[dh]->ui_ubanum); |
587 | addr->un.dhcsrl = unit|((car>>12)&0x30)|DH_IE; | |
a1b41f3d BJ |
588 | /* |
589 | * The following nonsense with short word | |
590 | * is to make sure the dhbar |= word below | |
591 | * is done with an interlocking bisw2 instruction. | |
592 | */ | |
593 | { short word = 1 << unit; | |
594 | dhsar[dh] |= word; | |
7e00c42b | 595 | addr->dhcar = car; |
a18f326f | 596 | addr->dhbcr = -nch; |
a1b41f3d BJ |
597 | addr->dhbar |= word; |
598 | } | |
941944c9 | 599 | tp->t_state |= TS_BUSY; |
a18f326f | 600 | } |
3f3a34c3 | 601 | out: |
a18f326f BJ |
602 | splx(s); |
603 | } | |
604 | ||
a18f326f | 605 | /* |
7e00c42b | 606 | * Stop output on a line, e.g. for ^S/^Q or output flush. |
a18f326f BJ |
607 | */ |
608 | /*ARGSUSED*/ | |
609 | dhstop(tp, flag) | |
7e00c42b | 610 | register struct tty *tp; |
a18f326f | 611 | { |
d4638843 | 612 | register struct dhdevice *addr; |
3f3a34c3 | 613 | register int unit, s; |
a18f326f | 614 | |
d4638843 | 615 | addr = (struct dhdevice *)tp->t_addr; |
7e00c42b BJ |
616 | /* |
617 | * Block input/output interrupts while messing with state. | |
618 | */ | |
619 | s = spl5(); | |
941944c9 | 620 | if (tp->t_state & TS_BUSY) { |
7e00c42b BJ |
621 | /* |
622 | * Device is transmitting; stop output | |
623 | * by selecting the line and setting the byte | |
624 | * count to -1. We will clean up later | |
625 | * by examining the address where the dh stopped. | |
626 | */ | |
3f3a34c3 | 627 | unit = minor(tp->t_dev); |
88d5b764 | 628 | addr->un.dhcsrl = (unit&017) | DH_IE; |
941944c9 BJ |
629 | if ((tp->t_state&TS_TTSTOP)==0) |
630 | tp->t_state |= TS_FLUSH; | |
038bbe6b BJ |
631 | addr->dhbcr = -1; |
632 | } | |
a18f326f BJ |
633 | splx(s); |
634 | } | |
635 | ||
5c30d566 BJ |
636 | /* |
637 | * Reset state of driver if UBA reset was necessary. | |
638 | * Reset the csrl and lpr registers on open lines, and | |
639 | * restart transmitters. | |
640 | */ | |
3f3a34c3 | 641 | dhreset(uban) |
7e00c42b | 642 | int uban; |
5c30d566 | 643 | { |
3f3a34c3 | 644 | register int dh, unit; |
5c30d566 | 645 | register struct tty *tp; |
b09915c5 | 646 | register struct uba_device *ui; |
5aa9d5ea | 647 | int i; |
5c30d566 | 648 | |
5aa9d5ea RE |
649 | if (dh_ubinfo[uban] == 0) |
650 | return; | |
5aa9d5ea RE |
651 | ubarelse(uban, &dh_ubinfo[uban]); |
652 | dh_ubinfo[uban] = uballoc(uban, (caddr_t)cfree, | |
4c05b581 | 653 | 512+nclist*sizeof (struct cblock), 0); |
5aa9d5ea | 654 | cbase[uban] = dh_ubinfo[uban]&0x3ffff; |
3f3a34c3 | 655 | dh = 0; |
0916e0d1 | 656 | for (dh = 0; dh < NDH; dh++) { |
5aa9d5ea RE |
657 | ui = dhinfo[dh]; |
658 | if (ui == 0 || ui->ui_alive == 0 || ui->ui_ubanum != uban) | |
659 | continue; | |
b19fe459 | 660 | printf(" dh%d", dh); |
d4638843 | 661 | ((struct dhdevice *)ui->ui_addr)->un.dhcsr |= DH_IE; |
d4638843 | 662 | ((struct dhdevice *)ui->ui_addr)->dhsilo = 16; |
5aa9d5ea RE |
663 | unit = dh * 16; |
664 | for (i = 0; i < 16; i++) { | |
665 | tp = &dh11[unit]; | |
941944c9 | 666 | if (tp->t_state & (TS_ISOPEN|TS_WOPEN)) { |
5aa9d5ea | 667 | dhparam(unit); |
d4638843 | 668 | dmctl(unit, DML_ON, DMSET); |
941944c9 | 669 | tp->t_state &= ~TS_BUSY; |
5aa9d5ea RE |
670 | dhstart(tp); |
671 | } | |
672 | unit++; | |
0072a3c2 BJ |
673 | } |
674 | } | |
675 | dhtimer(); | |
5c30d566 | 676 | } |
3f3a34c3 | 677 | |
7e00c42b BJ |
678 | /* |
679 | * At software clock interrupt time or after a UNIBUS reset | |
680 | * empty all the dh silos. | |
681 | */ | |
88d5b764 BJ |
682 | dhtimer() |
683 | { | |
684 | register int dh; | |
685 | ||
0916e0d1 | 686 | for (dh = 0; dh < NDH; dh++) |
88d5b764 BJ |
687 | dhrint(dh); |
688 | } | |
689 | ||
7e00c42b | 690 | /* |
d4638843 | 691 | * Turn on the line associated with dh dev. |
7e00c42b BJ |
692 | */ |
693 | dmopen(dev) | |
694 | dev_t dev; | |
695 | { | |
696 | register struct tty *tp; | |
697 | register struct dmdevice *addr; | |
b09915c5 | 698 | register struct uba_device *ui; |
7e00c42b BJ |
699 | register int unit; |
700 | register int dm; | |
1d6c2d43 | 701 | int s; |
7e00c42b BJ |
702 | |
703 | unit = minor(dev); | |
d4638843 | 704 | dm = unit >> 4; |
7e00c42b | 705 | tp = &dh11[unit]; |
7e286c72 | 706 | unit &= 0xf; |
0916e0d1 | 707 | if (dm >= NDH || (ui = dminfo[dm]) == 0 || ui->ui_alive == 0 || |
7e286c72 | 708 | (dhsoftCAR[dm]&(1<<unit))) { |
941944c9 | 709 | tp->t_state |= TS_CARR_ON; |
7e00c42b BJ |
710 | return; |
711 | } | |
712 | addr = (struct dmdevice *)ui->ui_addr; | |
1d6c2d43 | 713 | s = spl5(); |
d4638843 BJ |
714 | addr->dmcsr &= ~DM_SE; |
715 | while (addr->dmcsr & DM_BUSY) | |
7e00c42b | 716 | ; |
7e286c72 | 717 | addr->dmcsr = unit; |
d4638843 BJ |
718 | addr->dmlstat = DML_ON; |
719 | if (addr->dmlstat&DML_CAR) | |
941944c9 | 720 | tp->t_state |= TS_CARR_ON; |
1d6c2d43 | 721 | addr->dmcsr = DM_IE|DM_SE; |
941944c9 | 722 | while ((tp->t_state&TS_CARR_ON)==0) |
7e00c42b | 723 | sleep((caddr_t)&tp->t_rawq, TTIPRI); |
1d6c2d43 | 724 | splx(s); |
7e00c42b BJ |
725 | } |
726 | ||
727 | /* | |
728 | * Dump control bits into the DM registers. | |
729 | */ | |
730 | dmctl(dev, bits, how) | |
731 | dev_t dev; | |
732 | int bits, how; | |
733 | { | |
b09915c5 | 734 | register struct uba_device *ui; |
7e00c42b BJ |
735 | register struct dmdevice *addr; |
736 | register int unit, s; | |
737 | int dm; | |
738 | ||
739 | unit = minor(dev); | |
740 | dm = unit >> 4; | |
741 | if ((ui = dminfo[dm]) == 0 || ui->ui_alive == 0) | |
742 | return; | |
743 | addr = (struct dmdevice *)ui->ui_addr; | |
744 | s = spl5(); | |
d4638843 BJ |
745 | addr->dmcsr &= ~DM_SE; |
746 | while (addr->dmcsr & DM_BUSY) | |
7e00c42b BJ |
747 | ; |
748 | addr->dmcsr = unit & 0xf; | |
749 | switch(how) { | |
750 | case DMSET: | |
751 | addr->dmlstat = bits; | |
752 | break; | |
753 | case DMBIS: | |
754 | addr->dmlstat |= bits; | |
755 | break; | |
756 | case DMBIC: | |
757 | addr->dmlstat &= ~bits; | |
758 | break; | |
759 | } | |
1d6c2d43 | 760 | addr->dmcsr = DM_IE|DM_SE; |
7e00c42b BJ |
761 | splx(s); |
762 | } | |
763 | ||
764 | /* | |
765 | * DM11 interrupt; deal with carrier transitions. | |
766 | */ | |
767 | dmintr(dm) | |
768 | register int dm; | |
769 | { | |
b09915c5 | 770 | register struct uba_device *ui; |
7e00c42b BJ |
771 | register struct tty *tp; |
772 | register struct dmdevice *addr; | |
773 | ||
774 | ui = dminfo[dm]; | |
d4638843 BJ |
775 | if (ui == 0) |
776 | return; | |
7e00c42b | 777 | addr = (struct dmdevice *)ui->ui_addr; |
658d2f56 BJ |
778 | if (addr->dmcsr&DM_DONE) { |
779 | if (addr->dmcsr&DM_CF) { | |
780 | tp = &dh11[(dm<<4)+(addr->dmcsr&0xf)]; | |
781 | wakeup((caddr_t)&tp->t_rawq); | |
941944c9 | 782 | if ((tp->t_state&TS_WOPEN)==0 && |
658d2f56 BJ |
783 | (tp->t_local&LMDMBUF)) { |
784 | if (addr->dmlstat & DML_CAR) { | |
941944c9 | 785 | tp->t_state &= ~TS_TTSTOP; |
658d2f56 | 786 | ttstart(tp); |
941944c9 BJ |
787 | } else if ((tp->t_state&TS_TTSTOP) == 0) { |
788 | tp->t_state |= TS_TTSTOP; | |
658d2f56 BJ |
789 | dhstop(tp, 0); |
790 | } | |
791 | } else if ((addr->dmlstat&DML_CAR)==0) { | |
941944c9 | 792 | if ((tp->t_state&TS_WOPEN)==0 && |
658d2f56 BJ |
793 | (tp->t_local&LNOHANG)==0) { |
794 | gsignal(tp->t_pgrp, SIGHUP); | |
795 | gsignal(tp->t_pgrp, SIGCONT); | |
796 | addr->dmlstat = 0; | |
797 | flushtty(tp, FREAD|FWRITE); | |
798 | } | |
941944c9 | 799 | tp->t_state &= ~TS_CARR_ON; |
658d2f56 | 800 | } else |
941944c9 | 801 | tp->t_state |= TS_CARR_ON; |
658d2f56 BJ |
802 | } |
803 | addr->dmcsr = DM_IE|DM_SE; | |
7e00c42b BJ |
804 | } |
805 | } | |
4569bb70 | 806 | #endif |