gtmpsc.c revision 1.11.2.2 1 /* $NetBSD: gtmpsc.c,v 1.11.2.2 2006/12/30 20:48:35 yamt Exp $ */
2
3 /*
4 * Copyright (c) 2002 Allegro Networks, Inc., Wasabi Systems, Inc.
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 for the NetBSD Project by
18 * Allegro Networks, Inc., and Wasabi Systems, Inc.
19 * 4. The name of Allegro Networks, Inc. may not be used to endorse
20 * or promote products derived from this software without specific prior
21 * written permission.
22 * 5. The name of Wasabi Systems, Inc. may not be used to endorse
23 * or promote products derived from this software without specific prior
24 * written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY ALLEGRO NETWORKS, INC. AND
27 * WASABI SYSTEMS, INC. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
28 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
29 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 * IN NO EVENT SHALL EITHER ALLEGRO NETWORKS, INC. OR WASABI SYSTEMS, INC.
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*
41 * mpsc.c - MPSC serial driver, supports UART mode only
42 *
43 *
44 * creation Mon Apr 9 19:40:15 PDT 2001 cliff
45 */
46
47 #include <sys/cdefs.h>
48 __KERNEL_RCSID(0, "$NetBSD: gtmpsc.c,v 1.11.2.2 2006/12/30 20:48:35 yamt Exp $");
49
50 #include "opt_kgdb.h"
51
52 #include <sys/param.h>
53 #include <sys/conf.h>
54 #include <sys/device.h>
55 #include <sys/kauth.h>
56 #include <sys/proc.h>
57 #include <sys/systm.h>
58 #include <sys/tty.h>
59 #include <sys/callout.h>
60 #include <sys/fcntl.h>
61 #ifdef KGDB
62 #include <sys/kernel.h>
63 #include <sys/kgdb.h>
64 #endif
65
66 #include <uvm/uvm_extern.h>
67
68 #include <powerpc/atomic.h>
69 #include <dev/cons.h>
70 #include <machine/bus.h>
71 #include <machine/cpu.h> /* for DELAY */
72 #include <machine/stdarg.h>
73 #include "gtmpsc.h"
74
75
76 #include <dev/marvell/gtreg.h>
77 #include <dev/marvell/gtvar.h>
78 #include <dev/marvell/gtintrreg.h>
79 #include <dev/marvell/gtmpscreg.h>
80 #include <dev/marvell/gtsdmareg.h>
81 #include <dev/marvell/gtmpscvar.h>
82 #include <dev/marvell/gtbrgreg.h>
83
84 /*
85 * XXX these delays were derived empiracaly
86 */
87 #define GTMPSC_POLL_DELAY 1 /* 1 usec */
88 /*
89 * Wait 2 characters time for RESET_DELAY
90 */
91 #define GTMPSC_RESET_DELAY (2*8*1000000 / GT_MPSC_DEFAULT_BAUD_RATE)
92
93 #define BURSTLEN 128
94
95 /*
96 * stat values for gtmpsc_common_pollc
97 */
98 #define GTMPSC_STAT_NONE 0
99 #define GTMPSC_STAT_BREAK 1
100
101
102 #define PRINTF(x) gtmpsc_mem_printf x
103
104 #if defined(DEBUG)
105 unsigned int gtmpsc_debug = 0;
106 # define STATIC
107 # define DPRINTF(x) do { if (gtmpsc_debug) gtmpsc_mem_printf x ; } while (0)
108 #else
109 # define STATIC static
110 # define DPRINTF(x)
111 #endif
112
113 #define GTMPSCUNIT_MASK 0x7ffff
114 #define GTMPSCDIALOUT_MASK 0x80000
115
116 #define GTMPSCUNIT(x) (minor(x) & GTMPSCUNIT_MASK)
117 #define GTMPSCDIALOUT(x) (minor(x) & GTMPSCDIALOUT_MASK)
118
119 STATIC void gtmpscinit(struct gtmpsc_softc *);
120 STATIC int gtmpscmatch(struct device *, struct cfdata *, void *);
121 STATIC void gtmpscattach(struct device *, struct device *, void *);
122 STATIC int compute_cdv(unsigned int);
123 STATIC void gtmpsc_loadchannelregs(struct gtmpsc_softc *);
124 STATIC void gtmpscshutdown(struct gtmpsc_softc *);
125 STATIC void gtmpscstart(struct tty *);
126 STATIC int gtmpscparam(struct tty *, struct termios *);
127 STATIC int gtmpsc_probe(void);
128 STATIC int gtmpsc_intr(void *);
129 STATIC void gtmpsc_softintr(void *);
130
131 STATIC void gtmpsc_common_putn(struct gtmpsc_softc *);
132 STATIC void gtmpsc_common_putc(unsigned int, unsigned char);
133 STATIC int gtmpsc_common_getc(unsigned int);
134 STATIC int gtmpsc_common_pollc(unsigned int, char *, int *);
135 STATIC void gtmpsc_poll(void *);
136 #ifdef KGDB
137 STATIC void gtmpsc_kgdb_poll(void *);
138 #endif
139 STATIC void gtmpsc_mem_printf(const char *, ...);
140
141 STATIC void gtmpsc_txdesc_init(gtmpsc_poll_sdma_t *, gtmpsc_poll_sdma_t *);
142 STATIC void gtmpsc_rxdesc_init(gtmpsc_poll_sdma_t *, gtmpsc_poll_sdma_t *);
143 STATIC unsigned int gtmpsc_get_causes(void);
144 STATIC void gtmpsc_hackinit(struct gtmpsc_softc *, bus_space_tag_t,
145 bus_space_handle_t, int);
146 STATIC void gtmpscinit_stop(struct gtmpsc_softc *, int);
147 STATIC void gtmpscinit_start(struct gtmpsc_softc *, int);
148 #if 0
149 void gtmpsc_printf(const char *fmt, ...);
150 #endif
151 void gtmpsc_puts(char *);
152
153 void gtmpsccnprobe(struct consdev *);
154 void gtmpsccninit(struct consdev *);
155 int gtmpsccngetc(dev_t);
156 void gtmpsccnputc(dev_t, int);
157 void gtmpsccnpollc(dev_t, int);
158 void gtmpsccnhalt(dev_t);
159
160 STATIC void gtmpsc_txflush(gtmpsc_softc_t *);
161 STATIC void gtmpsc_iflush(gtmpsc_softc_t *);
162 STATIC void gtmpsc_shutdownhook(void *);
163
164 dev_type_open(gtmpscopen);
165 dev_type_close(gtmpscclose);
166 dev_type_read(gtmpscread);
167 dev_type_write(gtmpscwrite);
168 dev_type_ioctl(gtmpscioctl);
169 dev_type_stop(gtmpscstop);
170 dev_type_tty(gtmpsctty);
171 dev_type_poll(gtmpscpoll);
172
173 const struct cdevsw gtmpsc_cdevsw = {
174 gtmpscopen, gtmpscclose, gtmpscread, gtmpscwrite, gtmpscioctl,
175 gtmpscstop, gtmpsctty, gtmpscpoll, nommap, ttykqfilter, D_TTY
176 };
177
178 CFATTACH_DECL(gtmpsc, sizeof(struct gtmpsc_softc),
179 gtmpscmatch, gtmpscattach, NULL, NULL);
180
181 extern struct cfdriver gtmpsc_cd;
182
183 static struct consdev gtmpsc_consdev = {
184 0,
185 gtmpsccninit,
186 gtmpsccngetc,
187 gtmpsccnputc,
188 gtmpsccnpollc,
189 NULL, /* cn_bell */
190 gtmpsccnhalt,
191 NULL, /* cn_flush */
192 NODEV,
193 CN_NORMAL
194 };
195
196 STATIC void *gtmpsc_sdma_ih = NULL;
197
198 gtmpsc_softc_t *gtmpsc_scp[GTMPSC_NCHAN] = { 0 };
199
200 STATIC int gt_reva_gtmpsc_bug;
201 unsigned int sdma_imask; /* soft copy of SDMA IMASK reg */
202
203 #ifdef KGDB
204 #include <sys/kgdb.h>
205
206 static int gtmpsc_kgdb_addr;
207 static int gtmpsc_kgdb_attached;
208
209 int kgdb_break_immediate /* = 0 */ ;
210
211 STATIC int gtmpsc_kgdb_getc(void *);
212 STATIC void gtmpsc_kgdb_putc(void *, int);
213 #endif /* KGDB */
214
215 /*
216 * hacks for console initialization
217 * which happens prior to autoconfig "attach"
218 *
219 * XXX Assumes PAGE_SIZE is a constant!
220 */
221 STATIC unsigned int gtmpsccninit_done = 0;
222 STATIC gtmpsc_softc_t gtmpsc_fake_softc;
223 STATIC unsigned char gtmpsc_earlybuf[PAGE_SIZE]
224 __attribute__ ((aligned(PAGE_SIZE)));
225 STATIC unsigned char gtmpsc_fake_dmapage[PAGE_SIZE]
226 __attribute__ ((aligned(PAGE_SIZE)));
227
228
229 #define GTMPSC_PRINT_BUF_SIZE 4096
230 STATIC unsigned char gtmpsc_print_buf[GTMPSC_PRINT_BUF_SIZE] = { 0 };
231
232 unsigned int gtmpsc_poll_putc_cnt = 0;
233 unsigned int gtmpsc_poll_putn_cnt = 0;
234 unsigned int gtmpsc_poll_getc_cnt = 0;
235 unsigned int gtmpsc_poll_pollc_cnt = 0;
236 unsigned int gtmpsc_poll_putc_miss = 0;
237 unsigned int gtmpsc_poll_putn_miss = 0;
238 unsigned int gtmpsc_poll_getc_miss = 0;
239 unsigned int gtmpsc_poll_pollc_miss = 0;
240
241 #ifndef SDMA_COHERENT
242 /*
243 * inlines to flush, invalidate cache
244 * required if DMA cache coherency is broken
245 * note that pointer `p' args are assumed to be cache aligned
246 * and the size is assumed to be one CACHELINESIZE block
247 */
248
249 #define GTMPSC_CACHE_FLUSH(p) gtmpsc_cache_flush(p)
250 #define GTMPSC_CACHE_INVALIDATE(p) gtmpsc_cache_invalidate(p)
251
252 static inline void
253 gtmpsc_cache_flush(void *p)
254 {
255 __asm volatile ("eieio; dcbf 0,%0; lwz %0,0(%0); sync;"
256 : "+r"(p):);
257 }
258
259 static inline void
260 gtmpsc_cache_invalidate(void *p)
261 {
262 __asm volatile ("eieio; dcbi 0,%0; sync;" :: "r"(p));
263 }
264 #else
265
266 #define GTMPSC_CACHE_FLUSH(p)
267 #define GTMPSC_CACHE_INVALIDATE(p)
268
269 #endif /* SDMA_COHERENT */
270
271 #define GT_READ(sc,o) \
272 bus_space_read_4((sc)->gtmpsc_memt, (sc)->gtmpsc_memh, (o))
273 #define GT_WRITE(sc,o,v) \
274 bus_space_write_4((sc)->gtmpsc_memt, (sc)->gtmpsc_memh, (o), (v))
275
276
277 #define SDMA_IMASK_ENABLE(sc, bit) do { \
278 unsigned int __r; \
279 GT_WRITE(sc, SDMA_ICAUSE, ~(bit)); \
280 if (gt_reva_gtmpsc_bug) \
281 __r = sdma_imask; \
282 else \
283 __r = GT_READ(sc, SDMA_IMASK); \
284 __r |= (bit); \
285 sdma_imask = __r; \
286 GT_WRITE(sc, SDMA_IMASK, __r); \
287 } while (/*CONSTCOND*/ 0)
288
289 #define SDMA_IMASK_DISABLE(sc, bit) do { \
290 unsigned int __r; \
291 if (gt_reva_gtmpsc_bug) \
292 __r = sdma_imask; \
293 else \
294 __r = GT_READ(sc, SDMA_IMASK); \
295 __r &= ~(bit); \
296 sdma_imask = __r; \
297 GT_WRITE(sc, SDMA_IMASK, __r); \
298 } while (/*CONSTCOND*/ 0)
299
300 static inline unsigned int
301 desc_read(unsigned int *ip)
302 {
303 unsigned int rv;
304
305 __asm volatile ("lwzx %0,0,%1; eieio;"
306 : "=r"(rv) : "r"(ip));
307 return rv;
308 }
309
310 static inline void
311 desc_write(unsigned int *ip, unsigned int val)
312 {
313 __asm volatile ("stwx %0,0,%1; eieio;"
314 :: "r"(val), "r"(ip));
315 }
316
317
318 /*
319 * gtmpsc_txdesc_init - set up TX descriptor ring
320 */
321 STATIC void
322 gtmpsc_txdesc_init(gtmpsc_poll_sdma_t *vmps, gtmpsc_poll_sdma_t *pmps)
323 {
324 int n;
325 sdma_desc_t *dp;
326 gtmpsc_polltx_t *vtxp;
327 gtmpsc_polltx_t *ptxp;
328 gtmpsc_polltx_t *next_ptxp;
329 gtmpsc_polltx_t *first_ptxp;
330
331 first_ptxp = ptxp = &pmps->tx[0];
332 vtxp = &vmps->tx[0];
333 next_ptxp = ptxp + 1;
334 for (n = (GTMPSC_NTXDESC - 1); n--; ) {
335 dp = &vtxp->txdesc;
336 desc_write(&dp->sdma_csr, 0);
337 desc_write(&dp->sdma_cnt, 0);
338 desc_write(&dp->sdma_bufp, (u_int32_t)&ptxp->txbuf);
339 desc_write(&dp->sdma_next, (u_int32_t)&next_ptxp->txdesc);
340 GTMPSC_CACHE_FLUSH(dp);
341 vtxp++;
342 ptxp++;
343 next_ptxp++;
344 }
345 dp = &vtxp->txdesc;
346 desc_write(&dp->sdma_csr, 0);
347 desc_write(&dp->sdma_cnt, 0);
348 desc_write(&dp->sdma_bufp, (u_int32_t)&ptxp->txbuf);
349 desc_write(&dp->sdma_next, (u_int32_t)&first_ptxp->txdesc);
350 GTMPSC_CACHE_FLUSH(dp);
351 }
352
353 /*
354 * gtmpsc_rxdesc_init - set up RX descriptor ring
355 */
356 STATIC void
357 gtmpsc_rxdesc_init(gtmpsc_poll_sdma_t *vmps, gtmpsc_poll_sdma_t *pmps)
358 {
359 int n;
360 sdma_desc_t *dp;
361 gtmpsc_pollrx_t *vrxp;
362 gtmpsc_pollrx_t *prxp;
363 gtmpsc_pollrx_t *next_prxp;
364 gtmpsc_pollrx_t *first_prxp;
365 unsigned int csr;
366
367 csr = SDMA_CSR_RX_L|SDMA_CSR_RX_F|SDMA_CSR_RX_OWN|SDMA_CSR_RX_EI;
368 first_prxp = prxp = &pmps->rx[0];
369 vrxp = &vmps->rx[0];
370 next_prxp = prxp + 1;
371 for (n = (GTMPSC_NRXDESC - 1); n--; ) {
372 dp = &vrxp->rxdesc;
373 desc_write(&dp->sdma_csr, csr);
374 desc_write(&dp->sdma_cnt,
375 GTMPSC_RXBUFSZ << SDMA_RX_CNT_BUFSZ_SHIFT);
376 desc_write(&dp->sdma_bufp, (u_int32_t)&prxp->rxbuf);
377 desc_write(&dp->sdma_next, (u_int32_t)&next_prxp->rxdesc);
378 GTMPSC_CACHE_FLUSH(dp);
379 vrxp++;
380 prxp++;
381 next_prxp++;
382 }
383 dp = &vrxp->rxdesc;
384 desc_write(&dp->sdma_csr, SDMA_CSR_RX_OWN);
385 desc_write(&dp->sdma_cnt,
386 GTMPSC_RXBUFSZ << SDMA_RX_CNT_BUFSZ_SHIFT);
387 desc_write(&dp->sdma_bufp, (u_int32_t)&prxp->rxbuf);
388 desc_write(&dp->sdma_next, (u_int32_t)&first_prxp->rxdesc);
389 GTMPSC_CACHE_FLUSH(dp);
390 }
391
392 /*
393 * Compute the BRG countdown value (CDV in BRG_BCR)
394 */
395
396 STATIC int
397 compute_cdv(unsigned int baud)
398 {
399 unsigned int cdv;
400
401 if (baud == 0)
402 return 0;
403 cdv = (GT_MPSC_FREQUENCY / (baud * GTMPSC_CLOCK_DIVIDER) + 1) / 2 - 1;
404 if (cdv > BRG_BCR_CDV_MAX)
405 return -1;
406 return cdv;
407 }
408
409 STATIC void
410 gtmpsc_loadchannelregs(struct gtmpsc_softc *sc)
411 {
412 u_int brg_bcr;
413 u_int unit;
414
415 unit = sc->gtmpsc_unit;
416 brg_bcr = unit ? BRG_BCR1 : BRG_BCR0;
417
418 GT_WRITE(sc, brg_bcr, sc->gtmpsc_brg_bcr);
419 GT_WRITE(sc, GTMPSC_U_CHRN(unit, 3), sc->gtmpsc_chr3);
420 }
421
422 STATIC int
423 gtmpscmatch(struct device *parent, struct cfdata *self, void *aux)
424 {
425 struct gt_softc *gt = device_private(parent);
426 struct gt_attach_args *ga = aux;
427
428 return GT_MPSCOK(gt, ga, >mpsc_cd);
429 }
430
431 STATIC void
432 gtmpscattach(struct device *parent, struct device *self, void *aux)
433 {
434 struct gt_attach_args *ga = aux;
435 struct gt_softc *gt = device_private(parent);
436 struct gtmpsc_softc *sc = device_private(self);
437 gtmpsc_poll_sdma_t *vmps;
438 gtmpsc_poll_sdma_t *pmps;
439 struct tty *tp;
440 caddr_t kva;
441 int rsegs;
442 int err;
443 int s;
444 int is_console = 0;
445
446 DPRINTF(("mpscattach\n"));
447
448 GT_MPSCFOUND(gt, ga);
449
450 s = splhigh();
451
452 sc->gtmpsc_memt = ga->ga_memt;
453 sc->gtmpsc_memh = ga->ga_memh;
454 sc->gtmpsc_dmat = ga->ga_dmat;
455 sc->gtmpsc_unit = ga->ga_unit;
456
457 aprint_normal(": SDMA");
458 err = bus_dmamem_alloc(sc->gtmpsc_dmat, PAGE_SIZE, PAGE_SIZE, PAGE_SIZE,
459 sc->gtmpsc_dma_segs, 1, &rsegs, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW);
460 if (err) {
461 PRINTF(("mpscattach: bus_dmamem_alloc error 0x%x\n", err));
462 splx(s);
463 return;
464 }
465 #ifndef SDMA_COHERENT
466 err = bus_dmamem_map(sc->gtmpsc_dmat, sc->gtmpsc_dma_segs, 1, PAGE_SIZE,
467 &kva, BUS_DMA_NOWAIT);
468 #else
469 err = bus_dmamem_map(sc->gtmpsc_dmat, sc->gtmpsc_dma_segs, 1, PAGE_SIZE,
470 &kva, BUS_DMA_NOWAIT|BUS_DMA_NOCACHE);
471 #endif
472 if (err) {
473 PRINTF(("mpscattach: bus_dmamem_map error 0x%x\n", err));
474 splx(s);
475 return;
476 }
477
478 err = bus_dmamap_create(sc->gtmpsc_dmat, PAGE_SIZE, 1, PAGE_SIZE,
479 PAGE_SIZE, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW, &sc->gtmpsc_dma_map);
480 if (err) {
481 PRINTF(("mpscattach: bus_dmamap_create error 0x%x\n", err));
482 splx(s);
483 return;
484 }
485
486 err = bus_dmamap_load(sc->gtmpsc_dmat, sc->gtmpsc_dma_map, kva,
487 PAGE_SIZE, NULL, 0);
488 if (err) {
489 PRINTF(("mpscattach: bus_dmamap_load error 0x%x\n", err));
490 splx(s);
491 return;
492 }
493 memset(kva, 0, PAGE_SIZE); /* paranoid/superfluous */
494
495 vmps = (gtmpsc_poll_sdma_t *)kva; /* KVA */
496 pmps = (gtmpsc_poll_sdma_t *)sc->gtmpsc_dma_map->dm_segs[0].ds_addr; /* PA */
497 #if defined(DEBUG)
498 printf(" at %p/%p", vmps, pmps);
499 #endif
500 gtmpsc_txdesc_init(vmps, pmps);
501 gtmpsc_rxdesc_init(vmps, pmps);
502 sc->gtmpsc_poll_sdmapage = vmps;
503
504 if (gtmpsc_scp[sc->gtmpsc_unit] != NULL)
505 gtmpsc_txflush(gtmpsc_scp[sc->gtmpsc_unit]);
506
507 sc->gtmpsc_tty = tp = ttymalloc();
508 tp->t_oproc = gtmpscstart;
509 tp->t_param = gtmpscparam;
510 tty_attach(tp);
511
512 if (gtmpsc_sdma_ih == NULL) {
513 gtmpsc_sdma_ih = intr_establish(IRQ_SDMA, IST_LEVEL, IPL_SERIAL,
514 gtmpsc_intr, &sc);
515 if (gtmpsc_sdma_ih == NULL)
516 panic("mpscattach: cannot intr_establish IRQ_SDMA");
517 }
518
519 sc->sc_si = softintr_establish(IPL_SOFTSERIAL, gtmpsc_softintr, sc);
520 if (sc->sc_si == NULL)
521 panic("mpscattach: cannot softintr_establish IPL_SOFTSERIAL");
522
523 shutdownhook_establish(gtmpsc_shutdownhook, sc);
524
525 gtmpsc_scp[sc->gtmpsc_unit] = sc;
526 gtmpscinit(sc);
527
528 if (cn_tab == >mpsc_consdev &&
529 cn_tab->cn_dev == makedev(0, sc->gtmpsc_unit)) {
530 cn_tab->cn_dev = makedev(cdevsw_lookup_major(>mpsc_cdevsw),
531 device_unit(&sc->gtmpsc_dev));
532 is_console = 1;
533 }
534
535 aprint_normal(" irq %s%s\n",
536 intr_string(IRQ_SDMA),
537 (gt_reva_gtmpsc_bug) ? " [Rev A. bug]" : "");
538
539 if (is_console)
540 aprint_normal("%s: console\n", sc->gtmpsc_dev.dv_xname);
541
542 #ifdef DDB
543 if (is_console == 0)
544 SDMA_IMASK_ENABLE(sc, SDMA_INTR_RXBUF(sc->gtmpsc_unit));
545 #endif /* DDB */
546
547 splx(s);
548 #ifdef KGDB
549 /*
550 * Allow kgdb to "take over" this port. If this is
551 * the kgdb device, it has exclusive use.
552 */
553 if (sc->gtmpsc_unit == comkgdbport) {
554 if (comkgdbport == 0) { /* FIXME */
555 printf("%s(kgdb): cannot share with console\n",
556 sc->gtmpsc_dev.dv_xname);
557 return;
558 }
559
560 sc->gtmpsc_flags |= GTMPSCF_KGDB;
561 printf("%s: kgdb\n", sc->gtmpsc_dev.dv_xname);
562 gtmpsc_txflush(gtmpsc_scp[0]);
563 kgdb_attach(gtmpsc_kgdb_getc, gtmpsc_kgdb_putc, NULL);
564 kgdb_dev = 123; /* unneeded, only to satisfy some tests */
565 gtmpsc_kgdb_attached = 1;
566 SDMA_IMASK_ENABLE(sc, SDMA_INTR_RXBUF(sc->gtmpsc_unit));
567 kgdb_connect(1);
568 }
569 #endif /* KGDB */
570 }
571
572 STATIC void
573 gtmpscshutdown(struct gtmpsc_softc *sc)
574 {
575 struct tty *tp;
576 int s;
577
578 #ifdef KGDB
579 if (sc->gtmpsc_flags & GTMPSCF_KGDB != 0)
580 return;
581 #endif
582 tp = sc->gtmpsc_tty;
583 s = splserial();
584 /* Fake carrier off */
585 (void) (*tp->t_linesw->l_modem)(tp, 0);
586 SDMA_IMASK_DISABLE(sc, SDMA_INTR_RXBUF(sc->gtmpsc_unit));
587 splx(s);
588 }
589
590 int
591 gtmpscopen(dev_t dev, int flag, int mode, struct lwp *l)
592 {
593 struct gtmpsc_softc *sc;
594 int unit = GTMPSCUNIT(dev);
595 struct tty *tp;
596 int s;
597 int s2;
598 int error;
599
600 if (unit >= gtmpsc_cd.cd_ndevs)
601 return ENXIO;
602 sc = gtmpsc_cd.cd_devs[unit];
603 if (!sc)
604 return ENXIO;
605 #ifdef KGDB
606 /*
607 * If this is the kgdb port, no other use is permitted.
608 */
609 if (sc->gtmpsc_flags & GTMPSCF_KGDB != 0)
610 return (EBUSY);
611 #endif
612 tp = sc->gtmpsc_tty;
613 if (kauth_authorize_device_tty(l->l_cred, KAUTH_DEVICE_TTY_OPEN, tp))
614 return (EBUSY);
615
616 s = spltty();
617
618 if (!(tp->t_state & TS_ISOPEN)) {
619 struct termios t;
620
621 tp->t_dev = dev;
622 s2 = splserial();
623 SDMA_IMASK_ENABLE(sc, SDMA_INTR_RXBUF(unit));
624 splx(s2);
625 t.c_ispeed = 0;
626 #if 0
627 t.c_ospeed = TTYDEF_SPEED;
628 #else
629 t.c_ospeed = GT_MPSC_DEFAULT_BAUD_RATE;
630 #endif
631 t.c_cflag = TTYDEF_CFLAG;
632 /* Make sure gtmpscparam() will do something. */
633 tp->t_ospeed = 0;
634 (void) gtmpscparam(tp, &t);
635 tp->t_iflag = TTYDEF_IFLAG;
636 tp->t_oflag = TTYDEF_OFLAG;
637 tp->t_lflag = TTYDEF_LFLAG;
638 ttychars(tp);
639 ttsetwater(tp);
640 s2 = splserial();
641 /* Clear the input ring */
642 sc->gtmpsc_rxfifo_putix = 0;
643 sc->gtmpsc_rxfifo_getix = 0;
644 sc->gtmpsc_rxfifo_navail = GTMPSC_RXFIFOSZ;
645 gtmpsc_iflush(sc);
646 splx(s2);
647 }
648 splx(s);
649 error = ttyopen(tp, GTMPSCDIALOUT(dev), ISSET(flag, O_NONBLOCK));
650 if (error)
651 goto bad;
652
653 error = (*tp->t_linesw->l_open)(dev, tp);
654 if (error)
655 goto bad;
656
657 return (0);
658
659 bad:
660 if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
661 /*
662 * We failed to open the device, and nobody else had it opened.
663 * Clean up the state as appropriate.
664 */
665 gtmpscshutdown(sc);
666 }
667
668 return (error);
669 }
670
671 int
672 gtmpscclose(dev_t dev, int flag, int mode, struct lwp *l)
673 {
674 int unit = GTMPSCUNIT(dev);
675 struct gtmpsc_softc *sc = gtmpsc_cd.cd_devs[unit];
676 struct tty *tp = sc->gtmpsc_tty;
677 int s;
678
679 s = splserial();
680 if (!ISSET(tp->t_state, TS_ISOPEN)) {
681 splx(s);
682 return (0);
683 }
684
685 (*tp->t_linesw->l_close)(tp, flag);
686 ttyclose(tp);
687 if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
688 /*
689 * Although we got a last close, the device may still be in
690 * use; e.g. if this was the dialout node, and there are still
691 * processes waiting for carrier on the non-dialout node.
692 */
693 gtmpscshutdown(sc);
694 }
695
696 splx(s);
697 return (0);
698 }
699
700 int
701 gtmpscread(dev_t dev, struct uio *uio, int flag)
702 {
703 struct gtmpsc_softc *sc = gtmpsc_cd.cd_devs[GTMPSCUNIT(dev)];
704 struct tty *tp = sc->gtmpsc_tty;
705
706 return (*tp->t_linesw->l_read)(tp, uio, flag);
707 }
708
709 int
710 gtmpscwrite(dev_t dev, struct uio *uio, int flag)
711 {
712 struct gtmpsc_softc *sc = gtmpsc_cd.cd_devs[GTMPSCUNIT(dev)];
713 struct tty *tp = sc->gtmpsc_tty;
714
715 return (*tp->t_linesw->l_write)(tp, uio, flag);
716 }
717
718 int
719 gtmpscpoll(dev_t dev, int events, struct lwp *l)
720 {
721 struct gtmpsc_softc *sc = gtmpsc_cd.cd_devs[GTMPSCUNIT(dev)];
722 struct tty *tp = sc->gtmpsc_tty;
723
724 return ((*tp->t_linesw->l_poll)(tp, events, l));
725 }
726
727 int
728 gtmpscioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct lwp *l)
729 {
730 struct gtmpsc_softc *sc = gtmpsc_cd.cd_devs[GTMPSCUNIT(dev)];
731 struct tty *tp = sc->gtmpsc_tty;
732 int error;
733
734 if ((error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flag, l)) >= 0)
735 return error;
736 if ((error = ttioctl(tp, cmd, data, flag, l)) >= 0)
737 return error;
738 return ENOTTY;
739 }
740
741 struct tty *
742 gtmpsctty(dev_t dev)
743 {
744 struct gtmpsc_softc *sc = gtmpsc_cd.cd_devs[GTMPSCUNIT(dev)];
745
746 return sc->gtmpsc_tty;
747 }
748
749 void
750 gtmpscstop(struct tty *tp, int flag)
751 {
752 }
753
754 STATIC void
755 gtmpscstart(struct tty *tp)
756 {
757 struct gtmpsc_softc *sc;
758 unsigned char *tba;
759 unsigned int unit;
760 int s, s2, tbc;
761
762 unit = GTMPSCUNIT(tp->t_dev);
763 sc = gtmpsc_cd.cd_devs[unit];
764 if (sc == NULL)
765 return;
766
767 s = spltty();
768 if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))
769 goto out;
770 if (sc->sc_tx_stopped)
771 goto out;
772 if (tp->t_outq.c_cc <= tp->t_lowat) {
773 if ((tp->t_state & TS_ASLEEP) != 0) {
774 tp->t_state &= ~TS_ASLEEP;
775 wakeup(&tp->t_outq);
776 }
777 selwakeup(&tp->t_wsel);
778 if (tp->t_outq.c_cc == 0)
779 goto out;
780 }
781
782 /* Grab the first contiguous region of buffer space. */
783 tba = tp->t_outq.c_cf;
784 tbc = ndqb(&tp->t_outq, 0);
785
786 s2 = splserial();
787
788 sc->sc_tba = tba;
789 sc->sc_tbc = tbc;
790 sc->cnt_tx_from_ldisc += tbc;
791 SDMA_IMASK_ENABLE(sc, SDMA_INTR_TXBUF(unit));
792 tp->t_state |= TS_BUSY;
793 sc->sc_tx_busy = 1;
794 gtmpsc_common_putn(sc);
795
796 splx(s2);
797 out:
798 splx(s);
799 }
800
801 STATIC int
802 gtmpscparam(struct tty *tp, struct termios *t)
803 {
804 struct gtmpsc_softc *sc = gtmpsc_cd.cd_devs[GTMPSCUNIT(tp->t_dev)];
805 int ospeed = compute_cdv(t->c_ospeed);
806 int s;
807
808 /* Check requested parameters. */
809 if (ospeed < 0)
810 return (EINVAL);
811 if (t->c_ispeed && t->c_ispeed != t->c_ospeed)
812 return (EINVAL);
813
814 /*
815 * If there were no changes, don't do anything. This avoids dropping
816 * input and improves performance when all we did was frob things like
817 * VMIN and VTIME.
818 */
819 if (tp->t_ospeed == t->c_ospeed &&
820 tp->t_cflag == t->c_cflag)
821 return (0);
822
823 s = splserial();
824
825 sc->gtmpsc_brg_bcr = BRG_BCR_EN | GT_MPSC_CLOCK_SOURCE | ospeed;
826 sc->gtmpsc_chr3 = GTMPSC_MAXIDLE(t->c_ospeed);
827
828 /* And copy to tty. */
829 tp->t_ispeed = 0;
830 tp->t_ospeed = t->c_ospeed;
831 tp->t_cflag = t->c_cflag;
832
833 if (!sc->sc_heldchange) {
834 if (sc->sc_tx_busy) {
835 sc->sc_heldtbc = sc->sc_tbc;
836 sc->sc_tbc = 0;
837 sc->sc_heldchange = 1;
838 } else
839 gtmpsc_loadchannelregs(sc);
840 }
841
842 splx(s);
843
844 /* Fake carrier on */
845 (void) (*tp->t_linesw->l_modem)(tp, 1);
846
847 return 0;
848 }
849
850 STATIC int
851 gtmpsc_probe(void)
852 {
853 return 1; /* XXX */
854 }
855
856 STATIC unsigned int
857 gtmpsc_get_causes(void)
858 {
859 int i;
860 struct gtmpsc_softc *sc;
861 unsigned int cause = 0;
862 static unsigned int bits[4] = {
863 SDMA_INTR_RXBUF(0),
864 SDMA_INTR_TXBUF(0),
865 SDMA_INTR_RXBUF(1),
866 SDMA_INTR_TXBUF(1),
867 };
868 sdma_desc_t *desc_addr[4];
869 static unsigned int fake_once = SDMA_INTR_RXBUF(0)
870 | SDMA_INTR_RXBUF(1);
871
872 desc_addr[0] = 0;
873 desc_addr[1] = 0;
874 desc_addr[2] = 0;
875 desc_addr[3] = 0;
876 sc = gtmpsc_cd.cd_devs[0];
877 if (sc != 0) {
878 if (sdma_imask & SDMA_INTR_RXBUF(0)) {
879 desc_addr[0] =
880 &sc->gtmpsc_poll_sdmapage->rx[sc->gtmpsc_poll_rxix].rxdesc;
881 GTMPSC_CACHE_INVALIDATE(desc_addr[0]);
882 __asm volatile ("dcbt 0,%0" :: "r"(desc_addr[0]));
883 }
884 if (sdma_imask & SDMA_INTR_TXBUF(0)) {
885 desc_addr[1] =
886 &sc->gtmpsc_poll_sdmapage->tx[sc->gtmpsc_poll_txix].txdesc;
887 GTMPSC_CACHE_INVALIDATE(desc_addr[1]);
888 __asm volatile ("dcbt 0,%0" :: "r"(desc_addr[1]));
889 }
890 }
891 sc = gtmpsc_cd.cd_devs[1];
892 if (sc != 0) {
893 if (sdma_imask & SDMA_INTR_RXBUF(1)) {
894 desc_addr[2] =
895 &sc->gtmpsc_poll_sdmapage->rx[sc->gtmpsc_poll_rxix].rxdesc;
896 GTMPSC_CACHE_INVALIDATE(desc_addr[2]);
897 __asm volatile ("dcbt 0,%0" :: "r"(desc_addr[2]));
898 }
899 if (sdma_imask & SDMA_INTR_TXBUF(1)) {
900 desc_addr[3] =
901 &sc->gtmpsc_poll_sdmapage->tx[sc->gtmpsc_poll_txix].txdesc;
902 GTMPSC_CACHE_INVALIDATE(desc_addr[3]);
903 __asm volatile ("dcbt 0,%0" :: "r"(desc_addr[3]));
904 }
905 }
906
907 for (i = 0; i < 4; ++i)
908 if ((sdma_imask & bits[i]) && desc_addr[i] != 0 &&
909 (desc_addr[i]->sdma_csr & SDMA_CSR_TX_OWN) == 0)
910 cause |= bits[i];
911 if (fake_once & sdma_imask) {
912 cause |= fake_once & sdma_imask;
913 /* fake_once &= ~(cause & fake_once); */
914 }
915 return cause;
916 }
917
918 STATIC int
919 gtmpsc_intr(void *arg)
920 {
921 struct gtmpsc_softc *sc;
922 unsigned int unit;
923 int spurious = 1;
924 unsigned int r;
925 unsigned int cause=0;
926
927 if (gt_reva_gtmpsc_bug)
928 cause = gtmpsc_get_causes();
929
930 #ifdef KGDB
931 if (kgdb_break_immediate) {
932 unit = comkgdbport;
933 sc = gtmpsc_cd.cd_devs[unit];
934 if (sc == 0 || (sc->gtmpsc_flags & GTMPSCF_KGDB) == 0)
935 goto skip_kgdb;
936 if (gt_reva_gtmpsc_bug)
937 r = cause & sdma_imask;
938 else {
939 r = GT_READ(sc, SDMA_ICAUSE);
940 r &= GT_READ(sc, SDMA_IMASK);
941 }
942 r &= SDMA_INTR_RXBUF(unit);
943 if (r == 0)
944 goto skip_kgdb;
945 GT_WRITE(sc, SDMA_ICAUSE, ~r);
946 spurious = 0;
947 gtmpsc_kgdb_poll(sc);
948 }
949 skip_kgdb:
950 #endif
951 for (unit = 0; unit < GTMPSC_NCHAN; ++unit) {
952 sc = gtmpsc_cd.cd_devs[unit];
953 if (sc == 0)
954 continue;
955 if (gt_reva_gtmpsc_bug)
956 r = cause & sdma_imask;
957 else {
958 r = GT_READ(sc, SDMA_ICAUSE);
959 r &= GT_READ(sc, SDMA_IMASK);
960 }
961 r &= SDMA_U_INTR_MASK(unit);
962 if (r == 0)
963 continue;
964 GT_WRITE(sc, SDMA_ICAUSE, ~r);
965 spurious = 0;
966 if (r & SDMA_INTR_RXBUF(unit)) {
967 #ifdef KGDB
968 if (sc->gtmpsc_flags & GTMPSCF_KGDB)
969 gtmpsc_kgdb_poll(sc);
970 else
971 #endif
972 gtmpsc_poll(sc);
973 }
974 if (r & SDMA_INTR_TXBUF(unit)) {
975 /*
976 * If we've delayed a parameter change, do it now,
977 * and restart output.
978 */
979 if (sc->sc_heldchange) {
980 gtmpsc_loadchannelregs(sc);
981 sc->sc_heldchange = 0;
982 sc->sc_tbc = sc->sc_heldtbc;
983 sc->sc_heldtbc = 0;
984 }
985
986 /* Output the next chunk of the contiguous buffer,
987 if any. */
988 if (sc->sc_tbc > 0)
989 gtmpsc_common_putn(sc);
990 if (sc->sc_tbc == 0 && sc->sc_tx_busy) {
991 sc->sc_tx_busy = 0;
992 sc->sc_tx_done = 1;
993 softintr_schedule(sc->sc_si);
994 SDMA_IMASK_DISABLE(sc, SDMA_INTR_TXBUF(unit));
995 }
996 }
997 }
998 return 1;
999 /* return !spurious; */
1000 }
1001
1002 STATIC void
1003 gtmpsc_softintr(void *arg)
1004 {
1005 struct gtmpsc_softc *sc = arg;
1006 struct tty *tp;
1007 int (*rint)(int, struct tty *);
1008 int jobs;
1009 int s;
1010
1011 tp = sc->gtmpsc_tty;
1012 rint = tp->t_linesw->l_rint;
1013 do {
1014 jobs = 0;
1015 if (sc->gtmpsc_rxfifo_navail < GTMPSC_RXFIFOSZ) {
1016 s = spltty();
1017 rint(sc->gtmpsc_rxfifo[sc->gtmpsc_rxfifo_getix++],
1018 tp);
1019 if (sc->gtmpsc_rxfifo_getix >= GTMPSC_RXFIFOSZ)
1020 sc->gtmpsc_rxfifo_getix = 0;
1021 ++sc->cnt_rx_from_fifo;
1022 /* atomic_add() returns the previous value */
1023 jobs += atomic_add(&sc->gtmpsc_rxfifo_navail, 1) + 1
1024 < GTMPSC_RXFIFOSZ;
1025 splx(s);
1026 }
1027 if (sc->sc_tx_done) {
1028 ++jobs;
1029 sc->sc_tx_done = 0;
1030 s = spltty();
1031 tp->t_state &= ~TS_BUSY;
1032 if ((tp->t_state & TS_FLUSH) != 0)
1033 tp->t_state &= ~TS_FLUSH;
1034 else
1035 ndflush(&tp->t_outq, (int)(sc->sc_tba - tp->t_outq.c_cf));
1036 (*tp->t_linesw->l_start)(tp);
1037 splx(s);
1038 }
1039 } while (jobs);
1040 }
1041
1042 /*
1043 * Console support functions
1044 */
1045 void
1046 gtmpsccnprobe(struct consdev *cd)
1047 {
1048 int maj;
1049 /* {extern void return_to_dink(int); return_to_dink(gtbase);} */
1050
1051 if (!gtmpsc_probe())
1052 return;
1053
1054 maj = cdevsw_lookup_major(>mpsc_cdevsw);
1055 cd->cn_dev = makedev(maj, 0);
1056 cd->cn_pri = CN_INTERNAL;
1057 }
1058
1059 /*
1060 * gtmpsc_hackinit - hacks required to supprt GTMPSC console
1061 */
1062 STATIC void
1063 gtmpsc_hackinit(struct gtmpsc_softc *sc, bus_space_tag_t memt,
1064 bus_space_handle_t memh, int unit)
1065 {
1066 gtmpsc_poll_sdma_t *vmps;
1067 gtmpsc_poll_sdma_t *pmps;
1068
1069 DPRINTF(("hackinit\n"));
1070
1071 bzero(sc, sizeof(struct gtmpsc_softc));
1072 sc->gtmpsc_memt = memt;
1073 sc->gtmpsc_memh = memh;
1074 sc->gtmpsc_unit = unit;
1075 gtmpsc_scp[sc->gtmpsc_unit] = sc;
1076
1077 vmps = (gtmpsc_poll_sdma_t *)gtmpsc_fake_dmapage; /* KVA */
1078 pmps = (gtmpsc_poll_sdma_t *)gtmpsc_fake_dmapage; /* PA */
1079
1080 gtmpsc_txdesc_init(vmps, pmps);
1081 gtmpsc_rxdesc_init(vmps, pmps);
1082
1083 sc->gtmpsc_poll_sdmapage = vmps;
1084 }
1085
1086 /*
1087 * gtmpsc_txflush - wait for output to drain
1088 */
1089 STATIC void
1090 gtmpsc_txflush(gtmpsc_softc_t *sc)
1091 {
1092 unsigned int csr;
1093 unsigned int *csrp;
1094 gtmpsc_polltx_t *vtxp;
1095 int limit = 4000000; /* 4 seconds */
1096 int ix;
1097
1098 ix = sc->gtmpsc_poll_txix - 1;
1099 if (ix < 0)
1100 ix = GTMPSC_NTXDESC - 1;
1101
1102 vtxp = &sc->gtmpsc_poll_sdmapage->tx[ix];
1103 csrp = &vtxp->txdesc.sdma_csr;
1104 while (limit > 0) {
1105 GTMPSC_CACHE_INVALIDATE(csrp);
1106 csr = desc_read(csrp);
1107 if ((csr & SDMA_CSR_TX_OWN) == 0)
1108 break;
1109 DELAY(GTMPSC_POLL_DELAY);
1110 limit -= GTMPSC_POLL_DELAY;
1111 }
1112 }
1113
1114 STATIC void
1115 gtmpsc_iflush(gtmpsc_softc_t *sc)
1116 {
1117 int timo;
1118 char c;
1119 int stat;
1120
1121 for (timo = 50000; timo; timo--)
1122 if (gtmpsc_common_pollc(sc->gtmpsc_unit, &c, &stat) == 0)
1123 return;
1124 #ifdef DIAGNOSTIC
1125 printf("%s: gtmpsc_iflush timeout %02x\n", sc->gtmpsc_dev.dv_xname, c);
1126 #endif
1127 }
1128
1129 STATIC void
1130 gtmpscinit_stop(struct gtmpsc_softc *sc, int once)
1131 {
1132 unsigned int r;
1133 unsigned int unit = sc->gtmpsc_unit;
1134
1135 /*
1136 * XXX HACK FIXME
1137 * PMON output has not been flushed. give him a chance
1138 */
1139 #if 1
1140 if (! once)
1141 DELAY(100000); /* XXX */
1142 #endif
1143
1144 DPRINTF(("gtmpscinit_stop: unit 0x%x\n", unit));
1145 if (unit >= GTMPSC_NCHAN) {
1146 PRINTF(("mpscinit: undefined unit %d\n", sc->gtmpsc_unit));
1147 return;
1148 }
1149
1150 sc->gtmpsc_chr2 = 0; /* Default value of CHR2 */
1151
1152 /*
1153 * stop GTMPSC unit
1154 */
1155 r = sc->gtmpsc_chr2 | GTMPSC_CHR2_RXABORT|GTMPSC_CHR2_TXABORT;
1156 GT_WRITE(sc, GTMPSC_U_CHRN(unit, 2), r);
1157
1158 DELAY(GTMPSC_RESET_DELAY);
1159
1160 /*
1161 * abort SDMA TX, RX for GTMPSC unit
1162 */
1163 GT_WRITE(sc, SDMA_U_SDCM(unit), SDMA_SDCM_AR|SDMA_SDCM_AT);
1164
1165 if (once == 0) {
1166 /*
1167 * Determine if this is the buggy GT-64260A case.
1168 * If this is, then most of GTMPSC and SDMA registers
1169 * are unreadable.
1170 * (They always yield -1).
1171 */
1172 GT_WRITE(sc, SDMA_IMASK, 0);
1173 r = GT_READ(sc, SDMA_IMASK);
1174 gt_reva_gtmpsc_bug = r == ~0;
1175 sdma_imask = 0;
1176 }
1177
1178 /*
1179 * If Rx is disabled, we don't need to wait around for
1180 * abort completion.
1181 */
1182 if ((GT_READ(sc, GTMPSC_U_MMCR_LO(unit)) & GTMPSC_MMCR_LO_ER) == 0)
1183 return;
1184
1185 /*
1186 * poll for GTMPSC RX abort completion
1187 */
1188 if (gt_reva_gtmpsc_bug) {
1189 /* Sync up with the device first */
1190 r = GT_READ(sc, GTMPSC_U_CHRN(unit, 2));
1191 DELAY(GTMPSC_RESET_DELAY);
1192 } else
1193 for (;;) {
1194 r = GT_READ(sc, GTMPSC_U_CHRN(unit, 2));
1195 if (! (r & GTMPSC_CHR2_RXABORT))
1196 break;
1197 }
1198
1199 /*
1200 * poll for SDMA RX abort completion
1201 */
1202 for (;;) {
1203 r = GT_READ(sc, SDMA_U_SDCM(unit));
1204 if (! (r & (SDMA_SDCM_AR|SDMA_SDCM_AT)))
1205 break;
1206 DELAY(50);
1207 }
1208
1209 }
1210
1211 STATIC void
1212 gtmpscinit_start(struct gtmpsc_softc *sc, int once)
1213 {
1214 unsigned int r;
1215 unsigned int unit = sc->gtmpsc_unit;
1216
1217 /*
1218 * initialize softc's "current" transfer indicies & counts
1219 */
1220 sc->gtmpsc_cx = 0;
1221 sc->gtmpsc_nc = 0;
1222 sc->gtmpsc_poll_txix = 0;
1223 sc->gtmpsc_poll_rxix = 0;
1224
1225 /*
1226 * initialize softc's RX softintr FIFO
1227 */
1228 sc->gtmpsc_rxfifo_putix = 0;
1229 sc->gtmpsc_rxfifo_getix = 0;
1230 sc->gtmpsc_rxfifo_navail = GTMPSC_RXFIFOSZ;
1231 memset(&sc->gtmpsc_rxfifo[0], 0, GTMPSC_RXFIFOSZ);
1232
1233 /*
1234 * set SDMA unit port TX descriptor pointers
1235 * "next" pointer of last descriptor is start of ring
1236 */
1237 r = desc_read(
1238 &sc->gtmpsc_poll_sdmapage->tx[GTMPSC_NTXDESC-1].txdesc.sdma_next);
1239 GT_WRITE(sc, SDMA_U_SCTDP(unit), r); /* current */
1240 (void)GT_READ(sc, SDMA_U_SCTDP(unit));
1241 GT_WRITE(sc, SDMA_U_SFTDP(unit), r); /* first */
1242 (void)GT_READ(sc, SDMA_U_SFTDP(unit));
1243 /*
1244 * set SDMA unit port RX descriptor pointer
1245 * "next" pointer of last descriptor is start of ring
1246 */
1247 r = desc_read(
1248 &sc->gtmpsc_poll_sdmapage->rx[GTMPSC_NRXDESC-1].rxdesc.sdma_next);
1249 GT_WRITE(sc, SDMA_U_SCRDP(unit), r); /* current */
1250
1251 /*
1252 * initialize SDMA unit Configuration Register
1253 */
1254 r = SDMA_SDC_BSZ_8x64|SDMA_SDC_SFM|SDMA_SDC_RFT;
1255 GT_WRITE(sc, SDMA_U_SDC(unit), r);
1256
1257 /*
1258 * enable SDMA receive
1259 */
1260 GT_WRITE(sc, SDMA_U_SDCM(unit), SDMA_SDCM_ERD);
1261
1262 if (once == 0) {
1263 /*
1264 * GTMPSC Routing:
1265 * MR0 --> Serial Port 0
1266 * MR1 --> Serial Port 1
1267 */
1268 GT_WRITE(sc, GTMPSC_MRR, GTMPSC_MRR_RES);
1269
1270 /*
1271 * RX and TX Clock Routing:
1272 * CRR0 --> BRG0
1273 * CRR1 --> BRG1
1274 */
1275 r = GTMPSC_CRR_BRG0 | (GTMPSC_CRR_BRG1 << GTMPSC_CRR1_SHIFT);
1276 GT_WRITE(sc, GTMPSC_RCRR, r);
1277 GT_WRITE(sc, GTMPSC_TCRR, r);
1278 }
1279 sc->gtmpsc_brg_bcr = BRG_BCR_EN | GT_MPSC_CLOCK_SOURCE |
1280 compute_cdv(GT_MPSC_DEFAULT_BAUD_RATE);
1281 sc->gtmpsc_chr3 = GTMPSC_MAXIDLE(GT_MPSC_DEFAULT_BAUD_RATE);
1282 gtmpsc_loadchannelregs(sc);
1283
1284 /*
1285 * set MPSC Protocol configuration register for GTMPSC unit
1286 */
1287 GT_WRITE(sc, GTMPSC_U_MPCR(unit), GTMPSC_MPCR_CL_8);
1288
1289 /*
1290 * set MPSC LO and HI port config registers for GTMPSC unit
1291 */
1292 r = GTMPSC_MMCR_LO_MODE_UART
1293 |GTMPSC_MMCR_LO_ET
1294 |GTMPSC_MMCR_LO_ER
1295 |GTMPSC_MMCR_LO_NLM;
1296 GT_WRITE(sc, GTMPSC_U_MMCR_LO(unit), r);
1297
1298 r =
1299 GTMPSC_MMCR_HI_TCDV_DEFAULT
1300 |GTMPSC_MMCR_HI_RDW
1301 |GTMPSC_MMCR_HI_RCDV_DEFAULT;
1302 GT_WRITE(sc, GTMPSC_U_MMCR_HI(unit), r);
1303
1304 /*
1305 * tell MPSC receive the Enter Hunt
1306 */
1307 r = sc->gtmpsc_chr2 | GTMPSC_CHR2_EH;
1308 GT_WRITE(sc, GTMPSC_U_CHRN(unit, 2), r);
1309
1310 /*
1311 * clear any pending SDMA interrupts for this unit
1312 */
1313 r = GT_READ(sc, SDMA_ICAUSE);
1314 r &= ~SDMA_U_INTR_MASK(unit);
1315 GT_WRITE(sc, SDMA_ICAUSE, r); /* ??? */
1316
1317 DPRINTF(("gtmpscinit: OK\n"));
1318 }
1319
1320 /*
1321 * gtmpscinit - prepare MPSC for operation
1322 *
1323 * assumes we are called at ipl >= IPL_SERIAL
1324 */
1325 STATIC void
1326 gtmpscinit(struct gtmpsc_softc *sc)
1327 {
1328 static int once = 0;
1329
1330 gtmpscinit_stop(sc, once);
1331 gtmpscinit_start(sc, once);
1332 once = 1;
1333 }
1334
1335 /*
1336 * gtmpsccninit - initialize the driver and the mpsc device
1337 */
1338 void
1339 gtmpsccninit(struct consdev *cd)
1340 {
1341 }
1342
1343 int
1344 gtmpsccngetc(dev_t dev)
1345 {
1346 unsigned int unit = 0;
1347 int c;
1348
1349 unit = GTMPSCUNIT(dev);
1350 if (major(dev) != 0) {
1351 struct gtmpsc_softc *sc = device_lookup(>mpsc_cd, unit);
1352 if (sc == NULL)
1353 return 0;
1354 unit = sc->gtmpsc_unit;
1355 }
1356 if (unit >= GTMPSC_NCHAN)
1357 return 0;
1358 c = gtmpsc_common_getc(unit);
1359
1360 return c;
1361 }
1362
1363 void
1364 gtmpsccnputc(dev_t dev, int c)
1365 {
1366 unsigned int unit = 0;
1367 char ch = c;
1368 static int ix = 0;
1369
1370 if (gtmpsccninit_done == 0) {
1371 if ((minor(dev) == 0) && (ix < sizeof(gtmpsc_earlybuf)))
1372 gtmpsc_earlybuf[ix++] = (unsigned char)c;
1373 return;
1374 }
1375
1376 unit = GTMPSCUNIT(dev);
1377 if (major(dev) != 0) {
1378 struct gtmpsc_softc *sc = device_lookup(>mpsc_cd, unit);
1379 if (sc == NULL)
1380 return;
1381 unit = sc->gtmpsc_unit;
1382 }
1383
1384 if (unit >= GTMPSC_NCHAN)
1385 return;
1386
1387 gtmpsc_common_putc(unit, ch);
1388 }
1389
1390 void
1391 gtmpsccnpollc(dev_t dev, int on)
1392 {
1393 }
1394
1395 int
1396 gtmpsccnattach(bus_space_tag_t memt, bus_space_handle_t memh, int unit,
1397 int speed, tcflag_t tcflag)
1398 {
1399 struct gtmpsc_softc *sc = >mpsc_fake_softc;
1400 unsigned char *cp;
1401 unsigned char c;
1402 unsigned int i;
1403
1404 if (gtmpsccninit_done)
1405 return 0;
1406
1407 DPRINTF(("gtmpsccnattach\n"));
1408 gtmpsc_hackinit(sc, memt, memh, unit);
1409 DPRINTF(("gtmpscinit\n"));
1410 gtmpscinit(sc);
1411 gtmpsccninit_done = 1;
1412 cp = gtmpsc_earlybuf;
1413 strcpy(gtmpsc_earlybuf, "\r\nMPSC Lives!\r\n");
1414 for (i=0; i < sizeof(gtmpsc_earlybuf); i++) {
1415 c = *cp++;
1416 if (c == 0)
1417 break;
1418 gtmpsc_common_putc(unit, c);
1419 }
1420 DPRINTF(("switching cn_tab\n"));
1421 gtmpsc_consdev.cn_dev = makedev(0, unit);
1422 cn_tab = >mpsc_consdev;
1423 DPRINTF(("switched cn_tab!\n"));
1424 return 0;
1425 }
1426
1427 /*
1428 * gtmpsc_common_pollc - non-blocking console read
1429 *
1430 * if there is an RX char, return it in *cp
1431 * set *statp if Break detected
1432 *
1433 * assumes we are called at ipl >= IPL_SERIAL
1434 *
1435 * return 1 if there is RX data
1436 * otherwise return 0
1437 */
1438 STATIC int
1439 gtmpsc_common_pollc(unsigned int unit, char *cp, int *statp)
1440 {
1441 struct gtmpsc_softc *sc = gtmpsc_scp[unit];
1442 gtmpsc_pollrx_t *vrxp;
1443 unsigned int ix;
1444 unsigned int cx;
1445 unsigned int nc;
1446
1447 *statp = GTMPSC_STAT_NONE;
1448 ix = sc->gtmpsc_poll_rxix;
1449 nc = sc->gtmpsc_nc;
1450 cx = sc->gtmpsc_cx;
1451 if (nc == 0) {
1452 unsigned int *csrp;
1453 unsigned int csr;
1454
1455 vrxp = &sc->gtmpsc_poll_sdmapage->rx[ix];
1456 csrp = &vrxp->rxdesc.sdma_csr;
1457 cx = 0;
1458
1459 GTMPSC_CACHE_INVALIDATE(csrp);
1460 csr = desc_read(csrp);
1461 if (csr & SDMA_CSR_RX_OWN)
1462 return 0;
1463 if (csr & SDMA_CSR_RX_BR)
1464 *statp = GTMPSC_STAT_BREAK;
1465 if (csr & SDMA_CSR_RX_ES)
1466 PRINTF(("mpsc 0 RX error, rxdesc csr 0x%x\n", csr));
1467
1468 nc = desc_read(&vrxp->rxdesc.sdma_cnt);
1469 nc &= SDMA_RX_CNT_BCNT_MASK;
1470 csr = SDMA_CSR_RX_L|SDMA_CSR_RX_F|SDMA_CSR_RX_OWN
1471 |SDMA_CSR_RX_EI;
1472 if (nc == 0) {
1473 if ((++ix) >= GTMPSC_NRXDESC)
1474 ix = 0;
1475 sc->gtmpsc_poll_rxix = ix;
1476 desc_write(csrp, csr);
1477 GTMPSC_CACHE_FLUSH(csrp);
1478 return 0;
1479 }
1480 bcopy(vrxp->rxbuf, sc->gtmpsc_rxbuf, nc);
1481 desc_write(csrp, csr);
1482 GTMPSC_CACHE_FLUSH(csrp);
1483 }
1484 gtmpsc_poll_pollc_cnt++;
1485 nc--;
1486 *cp = sc->gtmpsc_rxbuf[cx++];
1487 if (nc == 0) {
1488 if ((++ix) >= GTMPSC_NRXDESC)
1489 ix = 0;
1490 sc->gtmpsc_poll_rxix = ix;
1491 }
1492 sc->gtmpsc_cx = cx;
1493 sc->gtmpsc_nc = nc;
1494 return 1;
1495 }
1496
1497 /*
1498 * gtmpsc_common_getc - polled console read
1499 *
1500 * We copy data from the DMA buffers into a buffer in the softc
1501 * to reduce descriptor ownership turnaround time
1502 * MPSC can crater if it wraps descriptor rings,
1503 * which is asynchronous and throttled only by line speed.
1504 *
1505 * This code assumes the buffer PA==KVA
1506 * and assumes we are called at ipl >= IPL_SERIAL
1507 */
1508 STATIC int
1509 gtmpsc_common_getc(unsigned int unit)
1510 {
1511 struct gtmpsc_softc *sc = gtmpsc_scp[unit];
1512 gtmpsc_pollrx_t *vrxp;
1513 unsigned int ix;
1514 unsigned int cx;
1515 unsigned int nc;
1516 unsigned int wdog_interval;
1517 int c;
1518
1519 ix = sc->gtmpsc_poll_rxix;
1520 nc = sc->gtmpsc_nc;
1521 cx = sc->gtmpsc_cx;
1522 wdog_interval = 0;
1523 while (nc == 0) {
1524 unsigned int *csrp;
1525 unsigned int csr;
1526 unsigned int r;
1527
1528 vrxp = &sc->gtmpsc_poll_sdmapage->rx[ix];
1529 csrp = &vrxp->rxdesc.sdma_csr;
1530 cx = 0;
1531
1532 GTMPSC_CACHE_INVALIDATE(csrp);
1533 csr = desc_read(csrp);
1534 if (csr & SDMA_CSR_RX_OWN) {
1535 r = sc->gtmpsc_chr2 | GTMPSC_CHR2_CRD;
1536 GT_WRITE(sc, GTMPSC_U_CHRN(unit, 2), r);
1537 do {
1538 if (wdog_interval++ % 32)
1539 gt_watchdog_service();
1540 gtmpsc_poll_getc_miss++;
1541 GTMPSC_CACHE_INVALIDATE(csrp);
1542 DELAY(50);
1543 csr = desc_read(csrp);
1544 } while (csr & SDMA_CSR_RX_OWN);
1545 } else
1546 if (wdog_interval++ % 32)
1547 gt_watchdog_service();
1548 if (csr & SDMA_CSR_RX_ES)
1549 PRINTF(("mpsc 0 RX error, rxdesc csr 0x%x\n", csr));
1550
1551 nc = desc_read(&vrxp->rxdesc.sdma_cnt);
1552 nc &= SDMA_RX_CNT_BCNT_MASK;
1553 if (nc) {
1554 bcopy(vrxp->rxbuf, sc->gtmpsc_rxbuf, nc);
1555 } else {
1556 if ((++ix) >= GTMPSC_NRXDESC)
1557 ix = 0;
1558 sc->gtmpsc_poll_rxix = ix;
1559 }
1560 csr = SDMA_CSR_RX_L|SDMA_CSR_RX_F|SDMA_CSR_RX_OWN
1561 |SDMA_CSR_RX_EI;
1562 desc_write(csrp, csr);
1563 GTMPSC_CACHE_FLUSH(csrp);
1564 #ifdef KGDB
1565 if (unit == comkgdbport && gt_reva_gtmpsc_bug)
1566 GT_WRITE(sc, SDMA_ICAUSE, ~SDMA_INTR_RXBUF(unit));
1567 #endif
1568 }
1569 gtmpsc_poll_getc_cnt++;
1570 nc--;
1571 c = (int)sc->gtmpsc_rxbuf[cx++];
1572 if (nc == 0) {
1573 if ((++ix) >= GTMPSC_NRXDESC)
1574 ix = 0;
1575 sc->gtmpsc_poll_rxix = ix;
1576 }
1577 sc->gtmpsc_cx = cx;
1578 sc->gtmpsc_nc = nc;
1579 gt_watchdog_service();
1580 return c;
1581 }
1582
1583 /*
1584 * gtmpsc_common_putn - write a buffer into the hardware
1585 *
1586 * assumes we are called at ipl >= IPL_SERIAL
1587 */
1588 STATIC void
1589 gtmpsc_common_putn(struct gtmpsc_softc *sc)
1590
1591 {
1592 int unit = sc->gtmpsc_unit;
1593 int n;
1594 int kick;
1595 gtmpsc_polltx_t *vtxp;
1596 unsigned int *csrp;
1597 unsigned int csr;
1598 unsigned int ix;
1599 unsigned int sdcm;
1600
1601 kick = 0;
1602 for (ix = sc->gtmpsc_poll_txix; sc->sc_tbc;) {
1603 vtxp = &sc->gtmpsc_poll_sdmapage->tx[ix];
1604 csrp = &vtxp->txdesc.sdma_csr;
1605 GTMPSC_CACHE_INVALIDATE(csrp);
1606 csr = desc_read(csrp);
1607 if ((csr & SDMA_CSR_TX_OWN) != 0)
1608 break;
1609 n = sc->sc_tbc;
1610 if (n > GTMPSC_TXBUFSZ)
1611 n = GTMPSC_TXBUFSZ;
1612 bcopy(sc->sc_tba, vtxp->txbuf, n);
1613 csr = SDMA_CSR_TX_L | SDMA_CSR_TX_F
1614 | SDMA_CSR_TX_EI | SDMA_CSR_TX_OWN;
1615 desc_write(&vtxp->txdesc.sdma_cnt,
1616 (n << SDMA_TX_CNT_BCNT_SHIFT) | n);
1617 desc_write(csrp, csr);
1618 GTMPSC_CACHE_FLUSH(csrp);
1619 sc->sc_tbc -= n;
1620 sc->sc_tba += n;
1621 gtmpsc_poll_putn_cnt += n;
1622 sc->cnt_tx_to_sdma += n;
1623 kick = 1;
1624
1625 if (++ix >= GTMPSC_NTXDESC)
1626 ix = 0;
1627 }
1628 if (kick) {
1629 sc->gtmpsc_poll_txix = ix;
1630
1631 /*
1632 * now kick some SDMA
1633 */
1634 sdcm = GT_READ(sc, SDMA_U_SDCM(unit));
1635
1636 if ((sdcm & SDMA_SDCM_TXD) == 0) {
1637 GT_WRITE(sc, SDMA_U_SDCM(unit), SDMA_SDCM_TXD);
1638 }
1639 }
1640 }
1641
1642 /*
1643 * gtmpsc_common_putc - polled console putc
1644 *
1645 * assumes we are called at ipl >= IPL_SERIAL
1646 */
1647 STATIC void
1648 gtmpsc_common_putc(unsigned int unit, unsigned char c)
1649 {
1650 struct gtmpsc_softc *sc = gtmpsc_scp[unit];
1651 gtmpsc_polltx_t *vtxp;
1652 unsigned int *csrp;
1653 unsigned int csr;
1654 unsigned int ix;
1655 unsigned int nix;
1656 unsigned int wdog_interval = 0;
1657
1658 DPRINTF(("gtmpsc_common_putc(%d, '%c'): cur=%#x, first=%#x", unit, c,
1659 GT_READ(sc, SDMA_U_SCTDP(unit)), /* current */
1660 GT_READ(sc, SDMA_U_SFTDP(unit)))); /* first */
1661 ix = sc->gtmpsc_poll_txix;
1662 nix = ix + 1;
1663 if (nix >= GTMPSC_NTXDESC)
1664 nix = 0;
1665 sc->gtmpsc_poll_txix = nix;
1666 vtxp = &sc->gtmpsc_poll_sdmapage->tx[ix];
1667 csrp = &vtxp->txdesc.sdma_csr;
1668
1669
1670 for (;;) {
1671 GTMPSC_CACHE_INVALIDATE(csrp);
1672 csr = desc_read(csrp);
1673 if ((csr & SDMA_CSR_TX_OWN) == 0)
1674 break;
1675 gtmpsc_poll_putc_miss++;
1676 DELAY(40);
1677 DPRINTF(("."));
1678 if (wdog_interval++ % 32)
1679 gt_watchdog_service();
1680 }
1681 if (csr & SDMA_CSR_TX_ES)
1682 PRINTF(("mpsc %d TX error, txdesc csr 0x%x\n", unit, csr));
1683
1684 gtmpsc_poll_putc_cnt++;
1685 vtxp->txbuf[0] = c;
1686 csr = SDMA_CSR_TX_L | SDMA_CSR_TX_F | SDMA_CSR_TX_EI | SDMA_CSR_TX_OWN;
1687 desc_write(&vtxp->txdesc.sdma_cnt, (1 << SDMA_TX_CNT_BCNT_SHIFT) | 1);
1688 desc_write(csrp, csr);
1689 GTMPSC_CACHE_FLUSH(csrp);
1690
1691 /*
1692 * now kick some SDMA
1693 */
1694 GT_WRITE(sc, SDMA_U_SDCM(unit), SDMA_SDCM_TXD);
1695 gt_watchdog_service();
1696 }
1697
1698
1699 STATIC void
1700 gtmpsc_poll(void *arg)
1701 {
1702 struct gtmpsc_softc *sc = (struct gtmpsc_softc *)arg;
1703 int kick;
1704 char ch;
1705 int stat;
1706 static struct timeval msg_time = {0,0};
1707 static struct timeval cur_time;
1708 static int fifo_full = 0;
1709
1710 kick = 0;
1711 while (gtmpsc_common_pollc(sc->gtmpsc_unit, &ch, &stat)) {
1712 #ifdef DDB
1713 if (stat)
1714 break;
1715 #endif
1716 ++sc->cnt_rx_from_sdma;
1717 if (sc->gtmpsc_rxfifo_navail != 0) {
1718 sc->gtmpsc_rxfifo[sc->gtmpsc_rxfifo_putix++] = ch;
1719 if (sc->gtmpsc_rxfifo_putix == GTMPSC_RXFIFOSZ)
1720 sc->gtmpsc_rxfifo_putix = 0;
1721 atomic_add(&sc->gtmpsc_rxfifo_navail, -1);
1722 ++sc->cnt_rx_to_fifo;
1723 fifo_full = 0;
1724 kick = 1;
1725 } else {
1726 if (fifo_full == 0) {
1727 fifo_full = 1;
1728 microtime(&cur_time);
1729 if (cur_time.tv_sec - msg_time.tv_sec >= 5) {
1730 /* Only do this once in 5 sec */
1731 msg_time = cur_time;
1732 printf("mpsc%d: input FIFO full, "
1733 "dropping incoming characters\n",
1734 sc->gtmpsc_unit);
1735 }
1736 }
1737 }
1738 }
1739 #ifdef DDB
1740 if (stat) {
1741 if (cn_tab == >mpsc_consdev) {
1742 Debugger();
1743 }
1744 }
1745 #endif
1746 if (kick)
1747 softintr_schedule(sc->sc_si);
1748 }
1749
1750 #ifdef KGDB
1751 /* ARGSUSED */
1752 STATIC int
1753 gtmpsc_kgdb_getc(arg)
1754 void *arg;
1755 {
1756
1757 return (gtmpsc_common_getc(comkgdbport));
1758 }
1759
1760 /* ARGSUSED */
1761 STATIC void
1762 gtmpsc_kgdb_putc(arg, c)
1763 void *arg;
1764 int c;
1765 {
1766
1767 return (gtmpsc_common_putc(comkgdbport, c));
1768 }
1769
1770 STATIC void
1771 gtmpsc_kgdb_poll(void *arg)
1772 {
1773 struct gtmpsc_softc *sc = (struct gtmpsc_softc *)arg;
1774 int s;
1775 char c;
1776 int brk;
1777
1778 s = splserial();
1779 if (kgdb_recover == 0) { /* gdb is not currently talking to its agent */
1780 while (gtmpsc_common_pollc(sc->gtmpsc_unit, &c, &brk)) {
1781 if (c == CTRL('c'))
1782 brk = GTMPSC_STAT_BREAK;
1783 if (brk == GTMPSC_STAT_BREAK)
1784 break;
1785 }
1786 if (brk == GTMPSC_STAT_BREAK) {
1787 if (kgdb_break_immediate)
1788 breakpoint();
1789 else {
1790 printf("connecting to kgdb\n");
1791 kgdb_connect(1);
1792 }
1793 }
1794 }
1795 splx(s);
1796 }
1797
1798 #endif /* KGDB */
1799
1800 #if 0
1801 void
1802 gtmpsc_printf(const char *fmt, ...)
1803 {
1804 struct consdev *ocd;
1805 int s;
1806 va_list ap;
1807
1808 s = splserial();
1809 ocd = cn_tab;
1810 cn_tab = &constab[0];
1811 va_start(ap, fmt);
1812 printf(fmt, ap);
1813 va_end(ap);
1814 cn_tab = ocd;
1815 splx(s);
1816 }
1817 #endif
1818
1819 void
1820 gtmpsc_mem_printf(const char *fmt, ...)
1821 {
1822 va_list ap;
1823 static unsigned char *p = gtmpsc_print_buf;
1824
1825 if (p >= >mpsc_print_buf[GTMPSC_PRINT_BUF_SIZE - 128]) {
1826 bzero(gtmpsc_print_buf, GTMPSC_PRINT_BUF_SIZE);
1827 p = gtmpsc_print_buf;
1828 }
1829 va_start(ap, fmt);
1830 p += vsprintf(p, fmt, ap);
1831 va_end(ap);
1832 }
1833
1834 void
1835 gtmpsc_shutdownhook(void *arg)
1836 {
1837 gtmpsc_softc_t *sc = (gtmpsc_softc_t *)arg;
1838
1839 gtmpsc_txflush(sc);
1840 }
1841
1842 void
1843 gtmpsccnhalt(dev_t dev)
1844 {
1845 unsigned int unit;
1846 u_int32_t r;
1847
1848 for (unit = 0; unit < GTMPSC_NCHAN; unit++) {
1849 gtmpsc_softc_t *sc = gtmpsc_scp[unit];
1850 if (sc == NULL)
1851 continue;
1852
1853 /*
1854 * flush TX buffers
1855 */
1856 gtmpsc_txflush(sc);
1857
1858 /*
1859 * stop MPSC unit RX
1860 */
1861 r = GT_READ(sc, GTMPSC_U_CHRN(unit, 2));
1862 r &= ~GTMPSC_CHR2_EH;
1863 r |= GTMPSC_CHR2_RXABORT;
1864 GT_WRITE(sc, GTMPSC_U_CHRN(unit, 2), r);
1865
1866 DELAY(GTMPSC_RESET_DELAY);
1867
1868 /*
1869 * abort SDMA RX for MPSC unit
1870 */
1871 GT_WRITE(sc, SDMA_U_SDCM(unit), SDMA_SDCM_AR);
1872 }
1873 }
1874
1875 void
1876 gtmpsc_puts(char *str)
1877 {
1878 char c;
1879
1880 if (str == NULL)
1881 return;
1882 while ((c = *str++) != 0)
1883 gtmpsccnputc(0, c);
1884 }
1885