1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
/* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */
/* All Rights Reserved */
/* Copyright (c) 1988, 1989 Intel Corp. */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Set features for each architecture. List of features:
* ADDR_32: Address is 32 bits
* COUNT_24: Count is 24 bits
* DMA_4CSCD: DMA channel 4 is used for cascade of channels 0-3)
* DMA_INTR: DMA interrupt is available (always with DMA_BUF_CHAIN)
* DMA_BUF_CHAIN: DMA buffer chaining is available (always with DMA_INTR)
* MEM_TO_MEM: Memory to memory transfers available
* NO_PROG_WIDTH: Channel data width is NOT programmable
* SCATER_GATHER Scatter-gather DMA is available (code not implemented)
* ISA_MODE Standard ISA modes available
* EISA_EXT_MODE: EISA extension modes available
*/
/*
* Address is 24 bits (default) with no carry between lo word and hi byte
* Count is 16 bits (default)
*/
#define DMA_4CSCD
#define NO_PROG_WIDTH
#define ISA_MODE
#include <sys/types.h>
#include <sys/cpuvar.h>
#include <sys/disp.h>
#include <sys/sunddi.h>
#include <sys/cmn_err.h>
#include <sys/dma_engine.h>
#include <sys/dma_i8237A.h>
#if defined(DEBUG)
#include <sys/promif.h>
static int i8237debug = 0;
#define dprintf(x) if (i8237debug) (void)prom_printf x
#else
#define dprintf(x)
#endif /* defined(DEBUG) */
extern int EISA_chaining;
/*
* data structures for maintaining the DMACs
*/
static kmutex_t dma_engine_lock;
static struct d37A_chan_reg_addr chan_addr[] = { D37A_BASE_REGS_VALUES };
static ushort_t d37A_chnl_path[] = {
DMAE_PATH_8, /* first 4 DMA channels default to 8-bit xfers */
DMAE_PATH_8,
DMAE_PATH_8,
DMAE_PATH_8,
0,
DMAE_PATH_16, /* last 3 DMA channels default to 16-bit xfers */
DMAE_PATH_16,
DMAE_PATH_16};
static ushort_t d37A_chnl_mode[] = {
DMAE_TRANS_SNGL, DMAE_TRANS_SNGL, DMAE_TRANS_SNGL, DMAE_TRANS_SNGL,
#ifdef DMA_4CSCD
DMAE_TRANS_CSCD,
#else /* !DMA_4CSCD */
DMAE_TRANS_SNGL,
#endif /* !DMA_4CSCD */
DMAE_TRANS_SNGL, DMAE_TRANS_SNGL, DMAE_TRANS_SNGL};
#ifdef DMA_BUF_CHAIN
static ddi_dma_cookie_t *d37A_next_cookie[] =
{0, 0, 0, 0, 0, 0, 0, 0};
#endif /* DMA_BUF_CHAIN */
#ifdef DMA_INTR
static uint_t d37A_intr(caddr_t);
#endif
static int d37A_set_mode(struct ddi_dmae_req *, int);
static int d37A_write_addr(ulong_t, int);
static ulong_t d37A_read_addr(int);
static int d37A_write_count(long, int);
static long d37A_read_count(int);
#ifdef DMA_BUF_CHAIN
static void dEISA_setchain(ddi_dma_cookie_t *cp, int chnl);
#endif
/*
* Routine: d37A_init()
* purpose: initializes the 8237A.
* caller: dma_init()
* calls: d37A macros, d37A_init()
*/
/*ARGSUSED*/
int
d37A_init(dev_info_t *dip)
{
#ifdef DMA_INTR
ddi_iblock_cookie_t iblk_cookie = 0;
int error;
if ((error = ddi_add_intr(dip, (uint_t)0, &iblk_cookie,
(ddi_idevice_cookie_t *)0, d37A_intr, (caddr_t)NULL)) !=
DDI_SUCCESS) {
if (error != DDI_INTR_NOTFOUND)
cmn_err(CE_WARN, "!d37A_init: cannot add dma intr\n");
EISA_chaining = 0;
}
mutex_init(&dma_engine_lock, NULL, MUTEX_DRIVER, (void *)iblk_cookie);
#else /* !DMA_INTR */
mutex_init(&dma_engine_lock, NULL, MUTEX_DRIVER, NULL);
#endif /* !DMA_INTR */
return (DDI_SUCCESS);
}
/*
* Routine: d37A_valid()
* purpose: validates the channel to be acquired.
* caller: i_dmae_acquire()
* calls:
*/
int
d37A_dma_valid(int chnl)
{
#ifdef DMA_4CSCD
if (chnl == 4)
return (0);
#endif /* DMA_4CSCD */
return (1);
}
/*
* Routine: d37A_release()
* purpose: resets the 8237A mode.
* caller: i_dmae_free()
* calls:
*/
void
d37A_dma_release(int chnl)
{
#ifdef DMA_4CSCD
if (chnl == 4)
return;
#endif /* DMA_4CSCD */
d37A_chnl_mode[chnl] = DMAE_TRANS_SNGL;
}
/*
* routine: d37A_dma_disable()
* purpose: Prevent the DMAC from responding to external hardware
* requests for DMA service on the given channel
* caller: dma_disable()
* calls: d37A macros
*/
void
d37A_dma_disable(int chnl)
{
dprintf(("d37A_dma_disable: chnl=%d mask_reg=0x%x\n",
chnl, chan_addr[chnl].mask_reg));
outb(chan_addr[chnl].mask_reg, (chnl & 3) | DMA_SETMSK);
}
/*
* routine: d37A_dma_enable()
* purpose: Enable to DMAC to respond to hardware requests for DMA
* service on the specified channel.
* caller: dma_enable()
* calls: d37A macros
*/
void
d37A_dma_enable(int chnl)
{
dprintf(("d37A_dma_enable: chnl=%d mask_reg=0x%x val=0x%x\n",
chnl, chan_addr[chnl].mask_reg, chnl & 3));
/* mutex_enter(&dma_engine_lock); */
outb(chan_addr[chnl].mask_reg, chnl & 3);
/* mutex_exit(&dma_engine_lock); */
}
/*
* routine: d37A_get_best_mode()
* purpose: stub routine - determine optimum transfer method
* caller: dma_get_best_mode().
* calls:
*/
/* ARGSUSED */
uchar_t
d37A_get_best_mode(struct ddi_dmae_req *dmaereqp)
{
return (DMAE_CYCLES_2);
}
#ifdef DMA_INTR
/*
* routine: d37A_intr()
* purpose: stub routine
* caller:
* calls: dma_intr().
*/
/*ARGSUSED*/
static uint_t
d37A_intr(caddr_t arg)
{
int chnl, istate, nstate;
uint_t mask;
if ((istate = (inb(EISA_DMAIS) & 0xef)) != 0) {
/* channel 4 can't interrupt */
chnl = 0;
nstate = istate;
mutex_enter(&dma_engine_lock);
do {
if (istate & 1) {
dEISA_setchain(d37A_next_cookie[chnl], chnl);
#ifdef DEBUG
if (chnl < 4)
mask = inb(DMAC1_ALLMASK) >> (chnl);
else
mask = inb(DMAC2_ALLMASK) >> (chnl - 4);
if (mask & 1)
prom_printf("eisa: dma buffer chaining failure chnl %d!\n", chnl);
#endif /* DEBUG */
}
chnl++;
istate >>= 1;
} while (istate);
chnl = 0;
do {
if ((nstate & 1) && d37A_next_cookie[chnl])
d37A_next_cookie[chnl] = _dmae_nxcookie(chnl);
chnl++;
nstate >>= 1;
} while (nstate);
mutex_exit(&dma_engine_lock);
return (DDI_INTR_CLAIMED);
}
return (DDI_INTR_UNCLAIMED);
}
#endif /* DMA_INTR */
#ifdef DMA_BUF_CHAIN
/*
* routine: dEISA_setchain()
* purpose: Set next buffer address/count from chain
* caller: d37A_intr()
* calls: d37A macros
*/
static void
dEISA_setchain(ddi_dma_cookie_t *cp, int chnl)
{
if (cp) {
dprintf(("dEISA_setchain: chnl=%d next_addr=%x count=%lx\n",
chnl, cp->dmac_address, cp->dmac_size));
(void) d37A_write_addr(cp->dmac_address, chnl);
(void) d37A_write_count(cp->dmac_size, chnl);
outb(chan_addr[chnl].scm_reg, chnl | EISA_ENCM | EISA_CMOK);
} else {
/*
* clear chain enable bit
*/
outb(chan_addr[chnl].scm_reg, chnl);
dprintf(("dEISA_setchain: chnl=%d end\n", chnl));
}
}
#endif /* DMA_BUF_CHAIN */
/*
* routine: d37A_prog_chan()
* purpose: program the Mode registers and the Base registers of a
* DMA channel for a subsequent hardware-initiated transfer.
* caller: dma_prog_chan()
* calls: d37A_write_addr(), d37A_write_count(), d37A macros.
*/
int
d37A_prog_chan(struct ddi_dmae_req *dmaereqp, ddi_dma_cookie_t *cp, int chnl)
{
if (d37A_chnl_mode[chnl] == DMAE_TRANS_CSCD) {
dprintf(("d37A_prog_chan err: chnl=%d in cascade mode\n",
chnl));
return (DDI_FAILURE);
}
#ifndef MEM_TO_MEM
if (dmaereqp && dmaereqp->der_dest == DMAE_DEST_MEM) {
dprintf(("d37A_prog_chan err: memory to memory mode not supported.\n"));
return (DDI_FAILURE);
}
#endif /* !MEM_TO_MEM */
dprintf(("d37A_prog_chan: chnl=%d dmaereq=%p\n",
chnl, (void *)dmaereqp));
if (dmaereqp) {
switch (chnl) {
case DMAE_CH0:
case DMAE_CH1:
case DMAE_CH2:
case DMAE_CH3:
#ifdef NO_PROG_WIDTH
if (dmaereqp->der_path &&
dmaereqp->der_path != DMAE_PATH_8) {
dprintf(("d37A_prog_chan err: chnl %d not programmed.\n", chnl));
return (DDI_FAILURE);
}
#endif /* NO_PROG_WIDTH */
break;
#ifndef DMA_4CSCD
case DMAE_CH4:
#endif /* !DMA_4CSCD */
case DMAE_CH5:
case DMAE_CH6:
case DMAE_CH7:
#ifdef NO_PROG_WIDTH
if (dmaereqp->der_path &&
dmaereqp->der_path != DMAE_PATH_16) {
dprintf(("d37A_prog_chan err: chnl %d not programmed.\n", chnl));
return (DDI_FAILURE);
}
#endif /* NO_PROG_WIDTH */
break;
default:
dprintf(("d37A_prog_chan err: chnl %d not programmed.\n", chnl));
return (DDI_FAILURE);
}
} else
chnl &= 3;
mutex_enter(&dma_engine_lock);
d37A_dma_disable(chnl);
if (dmaereqp)
(void) d37A_set_mode(dmaereqp, chnl);
if (cp) {
(void) d37A_write_addr(cp->dmac_address, chnl);
(void) d37A_write_count(cp->dmac_size, chnl);
#ifdef DMA_BUF_CHAIN
if (dmaereqp && dmaereqp->der_bufprocess == DMAE_BUF_CHAIN &&
(d37A_next_cookie[chnl] = _dmae_nxcookie(chnl))) {
/*
* i/o operation has more than 1 cookie
* so enable dma buffer chaining
*/
drv_usecwait(10);
outb(chan_addr[chnl].scm_reg, chnl | EISA_ENCM);
drv_usecwait(15);
dEISA_setchain(d37A_next_cookie[chnl], chnl);
d37A_next_cookie[chnl] = _dmae_nxcookie(chnl);
}
#endif /* DMA_BUF_CHAIN */
}
mutex_exit(&dma_engine_lock);
return (DDI_SUCCESS);
}
/*
* routine: d37A_dma_swsetup()
* purpose: program the Mode registers and the Base register for the
* specified channel.
* caller: dma_swsetup()
* calls: d37A_write_addr(), d37A_write_count(), d37A macros.
*/
int
d37A_dma_swsetup(struct ddi_dmae_req *dmaereqp, ddi_dma_cookie_t *cp, int chnl)
{
if (d37A_chnl_mode[chnl] == DMAE_TRANS_CSCD) {
dprintf(("d37A_dma_swsetup err: chnl %d not programmed\n",
chnl));
return (DDI_FAILURE);
}
dprintf(("d37A_dma_swsetup: chnl=%d dmaereq=%p.\n",
chnl, (void *)dmaereqp));
/* MUST BE IN BLOCK MODE FOR SOFTWARE INITIATED REQUESTS */
if (dmaereqp->der_trans != DMAE_TRANS_BLCK)
dmaereqp->der_trans = DMAE_TRANS_BLCK;
switch (chnl) {
case DMAE_CH0:
case DMAE_CH1:
case DMAE_CH2:
case DMAE_CH3:
#ifdef NO_PROG_WIDTH
if (dmaereqp->der_path && dmaereqp->der_path != DMAE_PATH_8) {
dprintf(("d37A_dma_swsetup err: chnl %d not programmed.\n", chnl));
return (DDI_FAILURE);
}
#endif /* NO_PROG_WIDTH */
break;
#ifndef DMA_4CSCD
case DMAE_CH4:
#endif /* !DMA_4CSCD */
case DMAE_CH5:
case DMAE_CH6:
case DMAE_CH7:
#ifdef NO_PROG_WIDTH
if (dmaereqp->der_path && dmaereqp->der_path != DMAE_PATH_16) {
dprintf(("d37A_dma_swsetup err: chnl %d not programmed.\n", chnl));
return (DDI_FAILURE);
}
#endif /* NO_PROG_WIDTH */
break;
default:
dprintf(("d37A_dma_swsetup err: chnl %d not set up.\n", chnl));
return (DDI_FAILURE);
};
mutex_enter(&dma_engine_lock);
d37A_dma_disable(chnl);
(void) d37A_set_mode(dmaereqp, chnl);
(void) d37A_write_addr(cp->dmac_address, chnl);
(void) d37A_write_count(cp->dmac_size, chnl);
#ifdef DMA_BUF_CHAIN
if (dmaereqp->der_bufprocess == DMAE_BUF_CHAIN &&
(d37A_next_cookie[chnl] = _dmae_nxcookie(chnl))) {
/*
* i/o operation has more than 1 cookie
* so enable dma buffer chaining
*/
outb(chan_addr[chnl].scm_reg, chnl | EISA_ENCM);
dEISA_setchain(d37A_next_cookie[chnl], chnl);
d37A_next_cookie[chnl] = _dmae_nxcookie(chnl);
}
#endif /* DMA_BUF_CHAIN */
mutex_exit(&dma_engine_lock);
return (DDI_SUCCESS);
}
/*
* routine: d37A_dma_swstart()
* purpose: SW start transfer setup on the indicated channel.
* caller: dma_swstart()
* calls: d37A_dma_enable(), d37A macros
*/
void
d37A_dma_swstart(int chnl)
{
dprintf(("d37A_dma_swstart: chnl=%d\n", chnl));
mutex_enter(&dma_engine_lock);
d37A_dma_enable(chnl);
outb(chan_addr[chnl].reqt_reg, DMA_SETMSK | chnl); /* set request bit */
mutex_exit(&dma_engine_lock);
}
/*
* routine: d37A_dma_stop()
* purpose: Stop any activity on the indicated channel.
* caller: dma_stop()
* calls: d37A macros
*/
void
d37A_dma_stop(int chnl)
{
dprintf(("d37A_dma_stop: chnl=%d\n", chnl));
mutex_enter(&dma_engine_lock);
d37A_dma_disable(chnl);
outb(chan_addr[chnl].reqt_reg, chnl & 3); /* reset request bit */
mutex_exit(&dma_engine_lock);
}
/*
* routine: d37A_get_chan_stat()
* purpose: retrieve the Current Address and Count registers for the
* specified channel.
* caller: dma_get_chan_stat()
* calls: d37A_read_addr(), d37A_read_count().
*/
void
d37A_get_chan_stat(int chnl, ulong_t *addressp, int *countp)
{
ulong_t taddr;
int tcount;
mutex_enter(&dma_engine_lock);
taddr = d37A_read_addr(chnl);
tcount = d37A_read_count(chnl);
mutex_exit(&dma_engine_lock);
if (addressp)
*addressp = taddr;
if (countp)
*countp = tcount;
dprintf(("d37A_get_chan_stat: chnl=%d address=%lx count=%x\n",
chnl, taddr, tcount));
}
/*
* routine: d37A_set_mode()
* purpose: program the Mode registers of the
* DMAC for a subsequent hardware-initiated transfer.
* caller: d37A_prog_chan(), d37A_dma_swsetup
* calls:
*/
static int
d37A_set_mode(struct ddi_dmae_req *dmaereqp, int chnl)
{
uchar_t mode = 0, emode = 0;
#ifdef ISA_MODE
#if defined(lint)
emode = emode;
#endif
mode = chnl & 3;
switch (dmaereqp->der_command) {
case DMAE_CMD_READ:
mode |= DMAMODE_READ;
break;
case DMAE_CMD_WRITE:
mode |= DMAMODE_WRITE;
break;
case DMAE_CMD_VRFY:
mode |= DMAMODE_VERF;
break;
case DMAE_CMD_TRAN:
mode |= 0x0C; /* for Adaptec 1st party DMA on chnl 0 */
break;
default:
return (DDI_FAILURE);
}
if (dmaereqp->der_bufprocess == DMAE_BUF_AUTO)
mode |= DMAMODE_AUTO;
if (dmaereqp->der_step == DMAE_STEP_DEC)
mode |= DMAMODE_DECR;
switch (dmaereqp->der_trans) {
case DMAE_TRANS_SNGL:
mode |= DMAMODE_SINGLE;
break;
case DMAE_TRANS_BLCK:
mode |= DMAMODE_BLOCK;
break;
case DMAE_TRANS_DMND:
break;
case DMAE_TRANS_CSCD:
mode |= DMAMODE_CASC;
break;
default:
return (DDI_FAILURE);
}
d37A_chnl_mode[chnl] = dmaereqp->der_trans;
dprintf(("d37A_set_mode: chnl=%d mode_reg=0x%x mode=0x%x\n",
chnl, chan_addr[chnl].mode_reg, mode));
outb(chan_addr[chnl].mode_reg, mode);
#endif /* ISA_MODE */
#ifdef EISA_EXT_MODE
emode = chnl & 3;
d37A_chnl_path[chnl] = dmaereqp->der_path;
switch (dmaereqp->der_path) {
case DMAE_PATH_8:
/* emode |= EISA_DMA_8; */
break;
case DMAE_PATH_16:
emode |= EISA_DMA_16;
break;
case DMAE_PATH_32:
emode |= EISA_DMA_32;
break;
case DMAE_PATH_16B:
emode |= EISA_DMA_16B;
break;
default:
switch (chnl) {
case DMAE_CH0:
case DMAE_CH1:
case DMAE_CH2:
case DMAE_CH3:
d37A_chnl_path[chnl] = DMAE_PATH_8;
/* emode |= EISA_DMA_8; */
break;
case DMAE_CH5:
case DMAE_CH6:
case DMAE_CH7:
d37A_chnl_path[chnl] = DMAE_PATH_16;
emode |= EISA_DMA_16;
break;
}
}
emode |= (dmaereqp->der_cycles & 3) << 4;
outb(chan_addr[chnl].emode_reg, emode);
dprintf(("d37A_set_mode: chnl=%d em_reg=0x%x emode=0x%x\n",
chnl, chan_addr[chnl].emode_reg, emode));
#endif /* EISA_EXT_MODE */
return (DDI_SUCCESS);
}
/*
* routine: d37A_write_addr()
* purpose: write the 24- or 32-bit physical address into the Base Address
* Register for the indicated channel.
* caller: d37A_prog_chan(), d37A_dma_swsetup().
* calls: d37A macros
*/
static int
d37A_write_addr(ulong_t paddress, int chnl)
{
uchar_t *adr_byte;
dprintf(("d37A_write_addr: chnl=%d address=%lx\n", chnl, paddress));
switch (d37A_chnl_path[chnl]) {
case DMAE_PATH_8:
case DMAE_PATH_16B:
case DMAE_PATH_32:
/*
* program DMA controller with byte address
*/
break;
case DMAE_PATH_16:
/*
* convert byte address to shifted word address
*/
paddress = (paddress & ~0x1ffff) | ((paddress & 0x1ffff) >> 1);
break;
default:
return (DDI_FAILURE);
}
kpreempt_disable(); /* don't preempt thread while using flip-flop */
outb(chan_addr[chnl].ff_reg, 0); /* set flipflop */
adr_byte = (uchar_t *)&paddress;
outb(chan_addr[chnl].addr_reg, adr_byte[0]);
outb(chan_addr[chnl].addr_reg, adr_byte[1]);
outb(chan_addr[chnl].page_reg, adr_byte[2]);
#ifdef ADDR_32
outb(chan_addr[chnl].hpage_reg, adr_byte[3]);
#endif /* ADDR_32 */
kpreempt_enable();
return (DDI_SUCCESS);
}
/*
* routine: d37A_read_addr()
* purpose: read the 24- or 32-bit physical address from the Current Address
* Register for the indicated channel.
* caller: d37A_get_chan_stat().
* calls: d37A macros
*/
static ulong_t
d37A_read_addr(int chnl)
{
ulong_t paddress = 0;
uchar_t *adr_byte;
kpreempt_disable(); /* don't preempt thread while using flip-flop */
adr_byte = (uchar_t *)&paddress;
outb(chan_addr[chnl].ff_reg, 0); /* set flipflop */
adr_byte[0] = inb(chan_addr[chnl].addr_reg);
adr_byte[1] = inb(chan_addr[chnl].addr_reg);
adr_byte[2] = inb(chan_addr[chnl].page_reg);
#ifdef ADDR_32
adr_byte[3] = inb(chan_addr[chnl].hpage_reg);
#endif /* ADDR_32 */
kpreempt_enable();
switch (d37A_chnl_path[chnl]) {
case DMAE_PATH_8:
case DMAE_PATH_16B:
case DMAE_PATH_32:
/*
* return with byte address
*/
break;
case DMAE_PATH_16:
/*
* convert shifted word address to byte address
*/
paddress = (paddress & ~0x1ffff) | ((paddress & 0x0ffff) << 1);
break;
default:
return ((ulong_t)DDI_FAILURE);
}
dprintf(("d37A_read_addr: chnl=%d address=%lx.\n", chnl, paddress));
return (paddress);
}
/*
* routine: d37A_write_count()
* purpose: write the 16- or 24-bit count into the Base Count Register for
* the indicated channel.
* caller: d37A_prog_chan(), d37A_dma_swsetup()
* calls: d37A macros
*/
static int
d37A_write_count(long count, int chnl)
{
uchar_t *count_byte;
dprintf(("d37A_write_count: chnl=%d count=0x%lx\n", chnl, count));
switch (d37A_chnl_path[chnl]) {
case DMAE_PATH_16:
/*
* Convert byte count to word count
*/
count >>= 1;
/* FALLTHROUGH */
case DMAE_PATH_8:
case DMAE_PATH_16B:
case DMAE_PATH_32:
--count;
break;
default:
return (DDI_FAILURE);
}
kpreempt_disable(); /* don't preempt thread while using flip-flop */
outb(chan_addr[chnl].ff_reg, 0); /* set flipflop */
count_byte = (uchar_t *)&count;
outb(chan_addr[chnl].cnt_reg, count_byte[0]);
outb(chan_addr[chnl].cnt_reg, count_byte[1]);
#ifdef COUNT_24
outb(chan_addr[chnl].hcnt_reg, count_byte[2]);
#endif /* COUNT_24 */
kpreempt_enable();
return (DDI_SUCCESS);
}
/*
* routine: d37A_read_count()
* purpose: read the 16- or 24-bit count from the Current Count Register for
* the indicated channel
* caller: d37A_get_chan_stat()
* calls: d37A macros
*/
static long
d37A_read_count(int chnl)
{
long count = 0;
uchar_t *count_byte;
kpreempt_disable(); /* don't preempt thread while using flip-flop */
count_byte = (uchar_t *)&count;
outb(chan_addr[chnl].ff_reg, 0); /* set flipflop */
count_byte[0] = inb(chan_addr[chnl].cnt_reg);
count_byte[1] = inb(chan_addr[chnl].cnt_reg);
#ifdef COUNT_24
count_byte[2] = inb(chan_addr[chnl].hcnt_reg);
#endif /* COUNT_24 */
#ifdef COUNT_24
if ((ulong_t)count == 0xffffff)
#else /* !COUNT_24 */
if ((ulong_t)count == 0xffff)
#endif /* !COUNT_24 */
count = -1;
kpreempt_enable();
switch (d37A_chnl_path[chnl]) {
case DMAE_PATH_8:
case DMAE_PATH_16B:
case DMAE_PATH_32:
++count;
break;
case DMAE_PATH_16:
/*
* Convert incremented word count to byte count
*/
count = (count + 1) << 1;
break;
}
dprintf(("d37A_read_count: chnl=%d count=0x%lx\n", chnl, count));
return (count);
}
|