summaryrefslogblamecommitdiffstats
path: root/private/ntos/ndis/digi/pcimac/idd_io.c
blob: 4f2c64744141b20e3e410e9b3b1d65248f70972d (plain) (tree)
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































































































































































































































































































































































































































































































































































































































































































                                                                                                                    
 /*
 * IDD_IO.C - do inp/outp ops for idd modules
 */

#include	<ndis.h>
#include	<mytypes.h>
#include	<mydefs.h>
#include	<disp.h>
#include	<util.h>
#include	<opcodes.h>
#include	<idd.h>
#include	<res.h>

typedef union
{
	UCHAR	uc[4];
	ULONG	ul;
}ULONG_UNION;

typedef union
{
	UCHAR	uc[2];
	USHORT	us;
}USHORT_UNION;

/* output to a port */
VOID
IdpOutp(
	IDD *idd,
	USHORT port,
	UCHAR val)
{
	NdisRawWritePortUchar((ULONG)idd->vhw.vbase_io + port, val);
}

/* input from a port */
UCHAR
IdpInp(
	IDD *idd,
	USHORT port)
{
    UCHAR   val;

    NdisRawReadPortUchar((ULONG)idd->vhw.vbase_io + port, &val);

    return(val);
}

/* output to a port */
VOID
AdpOutp(
	IDD *idd,
	USHORT port,
	UCHAR val
	)
{
   //
   //   Determine if this is a multi-channel BRI adapter.  If so, then
   //   we need to select the correct ADP to reference.
   //
   //   IMPORTANT NOTE:  I can get away with this because we process IDD's
   //                    on a per adapter basis.  If this ever changes,
   //                    then it may be necessary to change what is done
   //                    here.
   //
   switch( idd->btype )
   {
      case IDD_BT_DATAFIRE4ST:
         //
         //   select the correct BRI channel to access.
         //
	      NdisRawWritePortUchar( (ULONG)idd->vhw.vbase_io + ADP_REG_ADAPTER_CTRL,
                                idd->bline );
         break;
   }

	NdisRawWritePortUchar((ULONG)idd->vhw.vbase_io + port, val);
}  // end AdpOutp

/* input from a port */
UCHAR
AdpInp(
	IDD *idd,
	USHORT port
	)
{
    UCHAR   val;

   //
   //   Determine if this is a multi-channel BRI adapter.  If so, then
   //   we need to select the correct ADP to reference.
   //
   //   IMPORTANT NOTE:  I can get away with this because we process IDD's
   //                    on a per adapter basis.  If this ever changes,
   //                    then it may be necessary to change what is done
   //                    here.
   //
   switch( idd->btype )
   {
      case IDD_BT_DATAFIRE4ST:
         //
         //   select the correct BRI channel to access.
         //
	      NdisRawWritePortUchar( (ULONG)idd->vhw.vbase_io + ADP_REG_ADAPTER_CTRL,
                                idd->bline );
         break;
   }

    NdisRawReadPortUchar((ULONG)idd->vhw.vbase_io + port, &val);

    return(val);
}  // end AdpInp

VOID AdpWriteControlBit( IDD *idd,
	                      UCHAR Bit,
	                      UCHAR Value )
/*++

Routine Description:

   Sets bits indicated to specified values.

Arguments:

   Bit - BitMask of which bits are to be set.

   Value - BitMask to be applied to for Bit.

Return Value:

   None.

--*/
{
	UCHAR	OldData, NewData;

   // Read old value.
   OldData = idd->InFromPort( idd, ADP_REG_CTRL );

   // Set new value
   NewData = (OldData & Bit) | Value;

//	Data &= ~Bit;
//	Data |= (Value ? Bit : 0);

   idd->OutToPort(idd, ADP_REG_CTRL, NewData);
}

UCHAR
AdpReadReceiveStatus(
	IDD *idd
	)
{
	return(AdpGetUByte(idd, ADP_STS_WINDOW));
}

//
// this function should be updated to use NdisRawWritePortBufferUshort
// when the datarat is capable of handling it!!!!
//
VOID
AdpPutBuffer (
	IDD *idd,
	ULONG Destination,
	PUCHAR Source,
	USHORT Length
	)
{
	USHORT	WordLength = Length >> 1;
	PUCHAR	OddData = (PUCHAR)(Source + (Length - 1));

    D_LOG(D_ENTRY, ("AdpPutBuffer: idd: 0x%lx, Destination: 0x%lx, Source: 0x%lx, Length: %d\n", \
	                 idd, Destination, Source, Length));

	AdpSetAddress(idd, Destination);

	//
	// if WordLength has gone to zero with the shift this macro is just a nop
	//
	NdisRawWritePortBufferUshort((ULONG)(idd->vhw.vbase_io + ADP_REG_DATA_INC),
	                        (PUSHORT)Source,
							WordLength);

	//
	// if the length is odd write the last odd byte to adapter
	//
	if (Length & 0x0001)
		NdisRawWritePortUchar((ULONG)idd->vhw.vbase_io + ADP_REG_DATA_INC, *OddData);

#if 0
	NdisRawWritePortBufferUchar( (ULONG)idd->vhw.vbase_io + ADP_REG_DATA_INC,
                                Source,
                                Length );
#endif
}

//
// this function should be updated to use NdisRawReadPortBufferUshort
// when the datarat is capable of handling it!!!!
//
VOID
AdpGetBuffer (
	IDD *idd,
	PUCHAR Destination,
	ULONG Source,
	USHORT Length
	)
{
	USHORT	WordLength = Length >> 1;
	PUCHAR	OddData = (PUCHAR)(Destination + (Length - 1));

    D_LOG(D_ENTRY, ("AdpGetBuffer: idd: 0x%lx, Destination: 0x%lx, Source: 0x%lx, Length: %d\n", \
	                 idd, Destination, Source, Length));

	AdpSetAddress(idd, Source);

	//
	// if WordLength has gone to zero with the shift this macro is just a nop
	//
	NdisRawReadPortBufferUshort((ULONG)(idd->vhw.vbase_io + ADP_REG_DATA_INC),
	                        (PUSHORT)Destination,
							WordLength);

	//
	// if the length is odd read the last odd byte from adapter
	//
	if (Length & 0x0001)
		NdisRawReadPortUchar((ULONG)idd->vhw.vbase_io + ADP_REG_DATA_INC, OddData);

//	NdisRawReadPortBufferUchar((ULONG)idd->vhw.vbase_io + ADP_REG_DATA_INC,
//	                        Buffer,
//							Length);
}

VOID
AdpPutUByte(
	IDD *idd,
	ULONG Address,
	UCHAR Value
	)
{
	AdpSetAddress(idd, Address);
	idd->OutToPort(idd, ADP_REG_DATA_INC, Value);
}

VOID
AdpPutUShort(
	IDD *idd,
	ULONG Address,
	USHORT Value
	)
{
	USHORT_UNION us;

	us.us = Value;
	AdpSetAddress(idd, Address);
	idd->OutToPort(idd, ADP_REG_DATA_INC, us.uc[1]);
	idd->OutToPort(idd, ADP_REG_DATA_INC, us.uc[0]);
}

VOID
AdpPutULong(
	IDD *idd,
	ULONG Address,
	ULONG Value
	)
{
	ULONG_UNION ul;

	ul.ul = Value;
	AdpSetAddress(idd, Address);
	idd->OutToPort(idd, ADP_REG_DATA_INC, ul.uc[3]);
	idd->OutToPort(idd, ADP_REG_DATA_INC, ul.uc[2]);
	idd->OutToPort(idd, ADP_REG_DATA_INC, ul.uc[1]);
	idd->OutToPort(idd, ADP_REG_DATA_INC, ul.uc[0]);
}

UCHAR
AdpGetUByte(
	IDD *idd,
	ULONG Address
	)
{
	UCHAR Value;

	AdpSetAddress(idd, Address);

	Value = idd->InFromPort(idd, ADP_REG_DATA_INC);

	return(Value);
}

USHORT
AdpGetUShort(
	IDD *idd,
	ULONG Address
	)
{
	USHORT_UNION us;

	AdpSetAddress(idd, Address);
	us.uc[1] = idd->InFromPort(idd, ADP_REG_DATA_INC);
	us.uc[0] = idd->InFromPort(idd, ADP_REG_DATA_INC);

	return(us.us);
}

ULONG
AdpGetULong(
	IDD *idd,
	ULONG Address
	)
{
	ULONG_UNION ul;

	AdpSetAddress(idd, Address);
	ul.uc[3] = idd->InFromPort(idd, ADP_REG_DATA_INC);
	ul.uc[2] = idd->InFromPort(idd, ADP_REG_DATA_INC);
	ul.uc[1] = idd->InFromPort(idd, ADP_REG_DATA_INC);
	ul.uc[0] = idd->InFromPort(idd, ADP_REG_DATA_INC);

	return(ul.ul);
}

VOID
AdpWriteCommandStatus(
	IDD *idd,
	UCHAR Value
	)
{
	//
	// setup the address
	//
	AdpSetAddress(idd, ADP_CMD_WINDOW + 1);

	//
	// put out the value
	//
	idd->OutToPort(idd, ADP_REG_DATA_INC, Value);
}

UCHAR
AdpReadCommandStatus(
	IDD *idd
	)
{
	UCHAR	Status;

	//
	// setup the address
	//
	AdpSetAddress(idd, ADP_CMD_WINDOW + 1);

	//
	// get status
	//
	Status = idd->InFromPort(idd, ADP_REG_DATA_INC);

	return(Status);
}

VOID
AdpSetAddress(
	IDD *idd,
	ULONG Address
	)
{
	ULONG_UNION	ul;

   //
   // Look at the heartbeat on the adapter and determine if it is
   // still beating.
   //
   ul.ul = 0x504;
	idd->OutToPort(idd, ADP_REG_ADDR_LO, ul.uc[0]);
	idd->OutToPort(idd, ADP_REG_ADDR_MID, ul.uc[1]);
	idd->OutToPort(idd, ADP_REG_ADDR_HI, ul.uc[2]);

	ul.uc[3] = idd->InFromPort(idd, ADP_REG_DATA_INC);
	ul.uc[2] = idd->InFromPort(idd, ADP_REG_DATA_INC);
	ul.uc[1] = idd->InFromPort(idd, ADP_REG_DATA_INC);
	ul.uc[0] = idd->InFromPort(idd, ADP_REG_DATA_INC);

   D_LOG( D_NEVER, ("Heartbeat: 0x%lx\n", ul.ul) );

    D_LOG(D_NEVER, ("AdpSetAddress: idd: 0x%lx, Address: 0x%lx\n", \
	                 idd, Address));
	//
	// setup address
	//
	ul.ul = Address;
	idd->OutToPort(idd, ADP_REG_ADDR_LO, ul.uc[0]);
	idd->OutToPort(idd, ADP_REG_ADDR_MID, ul.uc[1]);
	idd->OutToPort(idd, ADP_REG_ADDR_HI, ul.uc[2]);
}

UCHAR
IdpGetUByteIO(
	IDD* idd,
	USHORT port
	)
{
	UCHAR Value;

	Value = idd->InFromPort(idd, port);

	return(Value);
}

VOID
IdpGetBuffer(
	IDD* idd,
	ULONG Bank,
	ULONG Page,
	ULONG Address,
	USHORT Length,
	PUCHAR Buffer
	)
{
	//
	// address from offset 0 on the bank and page described
	//
	PUCHAR	VirtualAddress = idd->vhw.vmem + Address;

	DbgPrint("IdpGetBuffer: idd: 0x%x, Bank: 0x%x, Page: 0x%x, Address: 0x%x, VirtAddres: 0x%x, Length: 0x%x\n",
	                       idd, Bank, Page, Address, VirtualAddress, Length);
	

	if (Length > IDP_RAM_PAGE_SIZE)
		Length = IDP_RAM_PAGE_SIZE;

	//
	// set the bank to the desired bank
	//
	idd->SetBank(idd, (UCHAR)Bank, 1);

	//
	// set the page to the desired page
	//
	idd->ChangePage(idd, (UCHAR)Page);

	//
	// get the stuff
	//
	NdisMoveFromMappedMemory((PVOID)Buffer, (PVOID)VirtualAddress, Length);
}

VOID
IdpPutUByteIO(
	IDD* idd,
	USHORT Port,
	UCHAR Value
	)
{
		
}

VOID
IdpPutBuffer(
	IDD* idd,
	ULONG Bank,
	ULONG Page,
	ULONG Address,
	USHORT Length,
	PUCHAR Buffer
	)
{
		
}

/*
 * IDD_MC.C - IDD board specific functions for MCIMAC
 */

/* set active bank, control reset state */
VOID
IdpMcSetBank(IDD *idd, UCHAR bank, UCHAR run)
{
	static UCHAR	reset_map[] = { 4, 5, 7 };
	static UCHAR	run_map[] = { 0, 1, 3 };

	idd->OutToPort(idd, 1, (UCHAR)(run ? run_map[bank] : reset_map[bank]));
}

/* set active page, control memory mapping */
VOID
IdpMcSetPage(IDD *idd, UCHAR page)
{
	if ( page == IDD_PAGE_NONE )
		idd->OutToPort(idd, 2, 0);
	else
		idd->OutToPort(idd, 2, (UCHAR)(0x80 | page));
}

/* set base memory window, redundent! - already stored by POS */
VOID
IdpMcSetBasemem(IDD *idd, ULONG basemem)
{

}


/*
 * IDD_PC.C - IDD board specific functions for ARIZONA
 */

/* set active bank, control reset state */
VOID
AdpSetBank(IDD *idd, UCHAR bank, UCHAR run)
{

}

/* set active page, control memory mapping */
VOID
AdpSetPage(IDD *idd, UCHAR page)
{

}

/* set base memory window, redundent! - already stored by POS */
VOID
AdpSetBasemem(IDD *idd, ULONG basemem)
{

}

/*
 * IDD_PC.C - IDD board specific functions for PCIMAC
 */

/* set active bank, control reset state */
VOID
IdpPcSetBank(IDD *idd, UCHAR bank, UCHAR run)
{
	//
	// reset map means that the reset bit is held in the bank select register
	//
	static UCHAR	reset_map[] = { 4, 5, 7 };

	//
	// run map means that the reset bit is not set in the bank select register
	//
	static UCHAR	run_map[] = { 0, 1, 3 };

	idd->OutToPort(idd, 4, (UCHAR)(run ? run_map[bank] : reset_map[bank]));
}

/* set active page, control memory mapping */
VOID
IdpPcSetPage(IDD *idd, UCHAR page)
{
	if ( page == IDD_PAGE_NONE )
		idd->OutToPort(idd, 5, 0);
	else
		idd->OutToPort(idd, 5, (UCHAR)(0x80 | page));
}

/* set base memory window, over-writes IRQ to 0! */
VOID
IdpPcSetBasemem(IDD *idd, ULONG basemem)
{
	idd->OutToPort(idd, 6, (UCHAR)(basemem >> 8));
	idd->OutToPort(idd, 7, (UCHAR)(basemem >> 16));
}


/*
 * IDD_PC4.C - IDD board specific functions for PCIMAC\4
 */

/*
 * set active bank, control reset state
 *
 * this routine makes use of the local data attached to the i/o resource.
 * as local dta is a long, it is used as an image of registers 3,4,x,x
 */
VOID
IdpPc4SetBank(IDD *idd, UCHAR bank, UCHAR run)
{
	static UCHAR	reset_map[] = { 4, 5, 7 };
	static UCHAR	run_map[] = { 0, 1, 3 };
	ULONG			lreg;
	UCHAR			*reg = (UCHAR*)&lreg;
	UCHAR			val = run ? run_map[bank] : reset_map[bank];

    D_LOG(D_ENTRY, ("idd__pc4_set_bank: entry, idd: 0x%lx, bank: 0x%x, run: 0x%x\n", idd, bank, run));

	/* lock i/o resource, get local data - which is register image */
	res_own(idd->res_io, idd);
	res_get_data(idd->res_io, &lreg);

	/* the easy way is to switch on bline & write bline specific code */
	switch ( idd->bline )
	{
		case 0 :
			reg[0] = (reg[0] & 0xF0) | val;
			idd->OutToPort(idd, 3, reg[0]);
			break;

		case 1 :
			reg[0] = (val << 4) | (reg[0] & 0x0F);
			idd->OutToPort(idd, 3, reg[0]);
			break;

		case 2 :
			reg[1] = (reg[1] & 0xF0) | val;
			idd->OutToPort(idd, 4, reg[1]);
			break;

		case 3 :
			reg[1] = (val << 4) | (reg[1] & 0x0F);
			idd->OutToPort(idd, 4, reg[1]);
			break;
	}

	/* return local data, release resource */
	res_set_data(idd->res_io, lreg);
	res_unown(idd->res_io, idd);

    D_LOG(D_EXIT, ("idd__pc4_set_bank: exit\n"));
}

/* set active page, control memory mapping */
VOID
IdpPc4SetPage(IDD *idd, UCHAR page)
{
	if ( page == IDD_PAGE_NONE )
		idd->OutToPort(idd, 5, 0);
	else
		idd->OutToPort(idd, 5, (UCHAR)(0x80 | page | (UCHAR)(idd->bline << 5)));
}

/* set base memory window, over-writes IRQ to 0! */
VOID
IdpPc4SetBasemem(IDD *idd, ULONG basemem)
{
	idd->OutToPort(idd, 6, (UCHAR)(basemem >> 8));
	idd->OutToPort(idd, 7, (UCHAR)(basemem >> 16));
}


/*
 * IDD_MEM.C - some memory handling routines
 */


/* fill a memory block using word moves */
VOID
IdpMemset(UCHAR*dst, USHORT val, INT size)
{
    D_LOG(D_ENTRY, ("idd__memwset: entry, dst: 0x%lx, val: 0x%x, size: 0x%x\n", dst, val, size));

//    for ( size /= sizeof(USHORT) ; size ; size--, dst++ )
//		NdisMoveToMappedMemory((PVOID)dst, (PVOID)&val, sizeof(USHORT));
		NdisZeroMappedMemory((PVOID)dst, size);
}

/* copy a memory block using word moves */
VOID
IdpMemcpy(UCHAR *dst, UCHAR *src, INT size)
{
    D_LOG(D_ENTRY, ("idd__memwcpy: entry, dst: 0x%lx, src: 0x%lx, size: 0x%x\n", dst, src, size));

//	for ( size /= sizeof(USHORT) ; size ; size--, dst++, src++ )
//		NdisMoveToMappedMemory((PVOID)dst, (PVOID)src, sizeof(USHORT));

		NdisMoveToMappedMemory((PVOID)dst, (PVOID)src, size);
}