Linux Audio

Check our new training course

Embedded Linux Audio

Check our new training course
with Creative Commons CC-BY-SA
lecture materials

Bootlin logo

Elixir Cross Referencer

Loading...
  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
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884

/*
 *
 * Copyright (C) Eicon Technology Corporation, 2000.
 *
 * Eicon File Revision :    1.15  
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY OF ANY KIND WHATSOEVER INCLUDING ANY 
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */


#include "eicon.h"
#include "sys.h"
#include "idi.h"
#include "constant.h"
#include "divas.h"
#include "pc.h"
#include "pr_pc.h"

#include "uxio.h"

#define DIVAS_LOAD_CMD		0x02
#define DIVAS_START_CMD		0x03
#define DIVAS_IRQ_RESET		0xC18
#define DIVAS_IRQ_RESET_VAL	0xFE

#define TEST_INT_DIVAS		0x11
#define TEST_INT_DIVAS_BRI	0x12
#define TEST_INT_DIVAS_Q	0x13

#define DIVAS_RESET	0x81
#define DIVAS_LED1	0x04
#define DIVAS_LED2	0x08
#define DIVAS_LED3	0x20
#define DIVAS_LED4	0x40

#define DIVAS_SIGNATURE 0x4447

#define MP_PROTOCOL_ADDR 0xA0011000

#define PLX_IOBASE	0
#define	DIVAS_IOBASE	1

typedef struct {
		dword cmd;
		dword addr;
		dword len;
		dword err;
		dword live;
		dword reserved[(0x1020>>2)-6];
		dword signature;
		byte  data[1];
} diva_server_boot_t;

int		DivasCardNext;
card_t	DivasCards[MAX_CARDS];

dia_config_t *DivasConfig(card_t *, dia_config_t *);

static
DESCRIPTOR DIDD_Table[32];

void    DIVA_DIDD_Read( DESCRIPTOR *table, int tablelength )
{
        memset(table, 0, tablelength);

        if (tablelength > sizeof(DIDD_Table))
          tablelength = sizeof(DIDD_Table);

        if(tablelength % sizeof(DESCRIPTOR)) {
          tablelength /= sizeof(DESCRIPTOR);
          tablelength *= sizeof(DESCRIPTOR);
        }

        if (tablelength > 0)
          memcpy((void *)table, (void *)DIDD_Table, tablelength);

	return;
}

void 	DIVA_DIDD_Write(DESCRIPTOR *table, int tablelength)
{
        if (tablelength > sizeof(DIDD_Table))
          tablelength = sizeof(DIDD_Table);

	memcpy((void *)DIDD_Table, (void *)table, tablelength);

	return;
}

static
void    init_idi_tab(void)
{
    DESCRIPTOR d[32];

    memset(d, 0, sizeof(d));

    d[0].type = IDI_DIMAINT;  /* identify the DIMAINT entry */
    d[0].channels = 0; /* zero channels associated with dimaint*/
    d[0].features = 0; /* no features associated with dimaint */
    d[0].request = (IDI_CALL) DivasPrintf;
    
    DIVA_DIDD_Write(d, sizeof(d));

    return;
}

/*
 * I/O routines for memory mapped cards
 */

byte mem_in(ADAPTER *a, void *adr)
{
	card_t			*card = a->io;
	unsigned char	*b, *m;
	byte			value;

	m = b = UxCardMemAttach(card->hw, DIVAS_SHARED_MEMORY);

	m += (unsigned int) adr;

	value = UxCardMemIn(card->hw, m);

	UxCardMemDetach(card->hw, b);

	return value;
}

word mem_inw(ADAPTER *a, void *adr)
{
	card_t			*card = a->io;
	unsigned char	*b, *m;
	word			value;

	m = b = UxCardMemAttach(card->hw, DIVAS_SHARED_MEMORY);

	m += (unsigned int) adr;

	value = UxCardMemInW(card->hw, m);

	UxCardMemDetach(card->hw, b);

	return value;
}

void mem_in_buffer(ADAPTER *a, void *adr, void *P, word length)
{
	card_t			*card = a->io;
	unsigned char	*b, *m;

	m = b = UxCardMemAttach(card->hw, DIVAS_SHARED_MEMORY);

	m += (unsigned int) adr;

	UxCardMemInBuffer(card->hw, m, P, length);

	UxCardMemDetach(card->hw, b);

	return;
}

void mem_look_ahead(ADAPTER *a, PBUFFER *RBuffer, ENTITY *e)
{
	card_t			*card = a->io;
	unsigned char	*b, *m;

	m = b = UxCardMemAttach(card->hw, DIVAS_SHARED_MEMORY);

	m += (dword) &RBuffer->length;
	card->RBuffer.length = UxCardMemInW(card->hw, m);

	m = b;
	m += (dword) &RBuffer->P;
	UxCardMemInBuffer(card->hw, m, card->RBuffer.P, card->RBuffer.length);

	e->RBuffer = (DBUFFER *) &card->RBuffer;

	UxCardMemDetach(card->hw, b);

	return;
}

void mem_out(ADAPTER *a, void *adr, byte data)
{
	card_t			*card = a->io;
	unsigned char	*b, *m;

	m = b = UxCardMemAttach(card->hw, DIVAS_SHARED_MEMORY);

	m += (unsigned int) adr;

	UxCardMemOut(card->hw, m, data);

	UxCardMemDetach(card->hw, b);

	return;
}

void mem_outw(ADAPTER *a, void *adr, word data)
{
	card_t			*card = a->io;
	unsigned char	*b, *m;

	m = b = UxCardMemAttach(card->hw, DIVAS_SHARED_MEMORY);

	m += (unsigned int) adr;

	UxCardMemOutW(card->hw, m, data);

	UxCardMemDetach(card->hw, b);

	return;
}

void mem_out_buffer(ADAPTER *a, void *adr, void *P, word length)
{
	card_t			*card = a->io;
	unsigned char	*b, *m;

	m = b = UxCardMemAttach(card->hw, DIVAS_SHARED_MEMORY);

	m += (unsigned int) adr;

	UxCardMemOutBuffer(card->hw, m, P, length);

	UxCardMemDetach(card->hw, b);

	return;
}

void mem_inc(ADAPTER *a, void *adr)
{
	word			value;
	card_t			*card = a->io;
	unsigned char	*b, *m;

	m = b = UxCardMemAttach(card->hw, DIVAS_SHARED_MEMORY);

	m += (unsigned int) adr;

	value = UxCardMemInW(card->hw, m);
	value++;
	UxCardMemOutW(card->hw, m, value);

	UxCardMemDetach(card->hw, b);

	return;
}

/*
 * I/O routines for I/O mapped cards
 */

byte io_in(ADAPTER *a, void *adr)
{
	card_t		    *card = a->io;
	byte		    value;
	byte	*DivasIOBase = NULL;

	DivasIOBase = UxCardMemAttach(card->hw, DIVAS_IOBASE);

	value = UxCardIoIn(card->hw, DivasIOBase, adr);

	UxCardMemDetach(card->hw, DivasIOBase);

    return value;
}

word io_inw(ADAPTER *a, void *adr)
{
	card_t		*card = a->io;
	word		value;
	byte	*DivasIOBase = NULL;

	DivasIOBase = UxCardMemAttach(card->hw, DIVAS_IOBASE);

	value = UxCardIoInW(card->hw, DivasIOBase, adr);

	UxCardMemDetach(card->hw, DivasIOBase);

	return value;
}

void io_in_buffer(ADAPTER *a, void *adr, void *P, word length)
{
	card_t *card = a->io;
	byte *DivasIOBase = NULL;

	DivasIOBase = UxCardMemAttach(card->hw, DIVAS_IOBASE);

	UxCardIoInBuffer(card->hw, DivasIOBase, adr, P,length);

	UxCardMemDetach(card->hw, DivasIOBase);

    return;
}

void io_look_ahead(ADAPTER *a, PBUFFER *RBuffer, ENTITY *e)
{
	card_t *card = a->io;
	byte *DivasIOBase = NULL;

	DivasIOBase = UxCardMemAttach(card->hw, DIVAS_IOBASE);

	card->RBuffer.length = UxCardIoInW(card->hw, DivasIOBase, (byte *) RBuffer);

	UxCardIoInBuffer(card->hw, DivasIOBase, &RBuffer->P, card->RBuffer.P, card->RBuffer.length);

	UxCardMemDetach(card->hw, DivasIOBase);

	e->RBuffer = (DBUFFER *) &card->RBuffer;

    return;
}

void io_out(ADAPTER *a, void *adr, byte data)
{
	card_t		*card = a->io;
	byte	*DivasIOBase = NULL;

	DivasIOBase = UxCardMemAttach(card->hw, DIVAS_IOBASE);

	UxCardIoOut(card->hw, DivasIOBase, adr, data);

	UxCardMemDetach(card->hw, DivasIOBase);

    return;
}

void io_outw(ADAPTER *a, void *adr, word data)
{
	card_t		*card = a->io;
	byte	*DivasIOBase = NULL;

	DivasIOBase = UxCardMemAttach(card->hw, DIVAS_IOBASE);

	UxCardIoOutW(card->hw, DivasIOBase, adr, data);

	UxCardMemDetach(card->hw, DivasIOBase);

    return;
}

void io_out_buffer(ADAPTER *a, void *adr, void *P, word length)
{
	card_t		*card = a->io;
	byte *DivasIOBase = NULL;

	DivasIOBase = UxCardMemAttach(card->hw, DIVAS_IOBASE);

	UxCardIoOutBuffer(card->hw, DivasIOBase, adr, P, length);

	UxCardMemDetach(card->hw, DivasIOBase);

    return;
}

void io_inc(ADAPTER *a, void *adr)
{
	word		value;
	card_t		*card = a->io;
	byte *DivasIOBase;

	DivasIOBase = UxCardMemAttach(card->hw, DIVAS_IOBASE);

	value = UxCardIoInW(card->hw, DivasIOBase, adr);
	
	value++;

	UxCardIoOutW(card->hw, DivasIOBase, adr, value);

	UxCardMemDetach(card->hw, DivasIOBase);

    return;
}

static
void test_int(card_t *card)

{
	byte *shared, *DivasIOBase;

	switch (card->test_int_pend)
	{
		case TEST_INT_DIVAS:
			DPRINTF(("divas: test interrupt pending"));
			shared = UxCardMemAttach(card->hw, DIVAS_SHARED_MEMORY);

			if (UxCardMemIn(card->hw, &shared[0x3FE]))
			{
				UxCardMemOut(card->hw, 
								&(((struct pr_ram *)shared)->RcOutput), 0);
				UxCardMemDetach(card->hw, shared);
            	(*card->reset_int)(card);
				shared = UxCardMemAttach(card->hw, DIVAS_SHARED_MEMORY);
				UxCardMemOut(card->hw, &shared[0x3FE], 0);
				DPRINTF(("divas: test interrupt cleared"));
			}

			UxCardMemDetach(card->hw, shared);

			card->test_int_pend = 0;
			break;

		case TEST_INT_DIVAS_BRI:
			DPRINTF(("divas: BRI test interrupt pending"));
			(*card->reset_int)(card);
			DivasIOBase = UxCardMemAttach(card->hw, DIVAS_IOBASE);
			UxCardIoOutW(card->hw, DivasIOBase, (void *) 0x3FE, 0);
			UxCardMemDetach(card->hw, DivasIOBase);
			DPRINTF(("divas: test interrupt cleared"));
			card->test_int_pend = 0;
			break;

		case TEST_INT_DIVAS_Q:
			DPRINTF(("divas: 4BRI test interrupt pending"));
			(*card->reset_int)(card);
			card->test_int_pend = 0;
			break;

		default:
			DPRINTF(("divas: unknown test interrupt pending"));
			return;
	}
	return;
}

void card_isr (void *dev_id)
{
	card_t *card = (card_t *) dev_id;
	ADAPTER *a = &card->a;
	int ipl;

	if (card->test_int_pend)
	{
		ipl = UxCardLock(card->hw);
		card->int_pend=0;
		test_int(card);
		UxCardUnlock(card->hw,ipl);
		return;
	}
	
	if(card->card_isr)
	{
		(*(card->card_isr))(card);
	}
	else
	{
		ipl = UxCardLock(card->hw);
	
		if ((card->test_int)(a))
		{
			(card->reset_int)(card);
		}
		
		UxCardUnlock(card->hw,ipl);
		
	}

}

int DivasCardNew(dia_card_t *card_info)
{
	card_t *card;
	static boolean_t first_call = TRUE;
	boolean_t NeedISRandReset = FALSE;

	DPRINTF(("divas: new card "));

	if (first_call)
	{
		first_call = FALSE;
		init_idi_tab();
	}

	DivasConfigGet(card_info);
	
	if (DivasCardNext == DIM(DivasCards))
	{
		KDPRINTF((KERN_WARNING "Divas: no space available for new card"));
		return -1;
	}

	card = &DivasCards[DivasCardNext];

	card->state = DIA_UNKNOWN;

	card->cfg = *card_info;

	card->a.io = card;

	if (UxCardHandleGet(&card->hw, card_info))
	{
		KDPRINTF((KERN_WARNING "Divas: cannot get OS specific handle for card"));
		return -1;
	}

	if (card_info->card_type == DIA_CARD_TYPE_DIVA_SERVER_B)
	{
		DivasBriPatch(card);
		card_info->io_base = card->cfg.io_base;
	}

	switch (card_info->card_type)
	{
		case DIA_CARD_TYPE_DIVA_SERVER:
			if (DivasPriInit(card, card_info))
			{
				return -1;
			}
			NeedISRandReset = TRUE;
			break;

		case DIA_CARD_TYPE_DIVA_SERVER_B:
			if (DivasBriInit(card, card_info))
			{
				return -1;
			}
			NeedISRandReset = TRUE;
			break;

 		case DIA_CARD_TYPE_DIVA_SERVER_Q:
			if (Divas4BriInit(card, card_info))
			{
				return -1;
			}

			if (card_info->name[6] == '0')
			{
				NeedISRandReset = TRUE;
			}
			else // Need to set paramater for ISR anyway
			{
				card->hw->user_isr_arg = card;
				card->hw->user_isr = card_isr;
			}
			break;   

		default:
			KDPRINTF((KERN_WARNING "Divas: unsupported card type (%d)", card_info->card_type));
			return -1;
	}

	if (NeedISRandReset)
	{
		if (UxIsrInstall(card->hw, card_isr, card))
		{
			KDPRINTF((KERN_WARNING "Divas: Install ISR failed (IRQ %d)", card->cfg.irq));
			UxCardHandleFree(card->hw);
			return -1;
		}

		if (card_info->card_type != DIA_CARD_TYPE_DIVA_SERVER_Q)
		{
			if ((*card->card_reset)(card))
			{
				KDPRINTF((KERN_WARNING "Divas: Adapter reset failed"));
				return -1;
			}
			card->state = DIA_RESET;
		}

		NeedISRandReset = FALSE;
	}

	DivasCardNext++;

	return 0;
}

void	*get_card(int card_id)
{
	int i;

	for (i=0; i < DivasCardNext; i++)
	{
		if (DivasCards[i].cfg.card_id == card_id)
		{
			return(&DivasCards[i]);
		}
	}

	DPRINTF(("divas: get_card() : no such card id (%d)", card_id));

	return NULL;
}

int DivasCardConfig(dia_config_t *config)
{
	card_t *card;
	int status;

	DPRINTF(("divas: configuring card"));

	card = get_card(config->card_id);
	if (!card)
	{
		return -1;
	}

	config = DivasConfig(card, config);

	status = (*card->card_config)(card, config);

	if (!status)
	{
		card->state = DIA_CONFIGURED;
	}
	return status;
}

int DivasCardLoad(dia_load_t *load)
{
	card_t *card;
	int	status;

	card = get_card(load->card_id);
	if (!card)
	{
		return -1;
	}

	if (card->state == DIA_RUNNING)
	{
		(*card->card_reset)(card);
	}

	status = (*card->card_load)(card, load);
	if (!status)
	{
		card->state = DIA_LOADED;
	}
	return status;
}

static int idi_register(card_t *card, byte channels)
{
    DESCRIPTOR d[32];
    int length, num_entities;

	DPRINTF(("divas: registering card with IDI"));

	num_entities = (channels > 2) ? MAX_PENTITIES : MAX_ENTITIES;
	card->e_tbl = UxAlloc(sizeof(E_INFO) * num_entities);

	if (!card->e_tbl)
	{
		KDPRINTF((KERN_WARNING "Divas: IDI register failed - no memory available"));
		return -1;
	}

	memset(card->e_tbl, 0, sizeof(E_INFO) * num_entities);
	card->e_max = num_entities;

    DIVA_DIDD_Read(d, sizeof(d));

        for(length=0; length < DIM(d); length++)
          if (d[length].type == 0) break;

	if (length >= DIM(d))
	{
		KDPRINTF((KERN_WARNING "Divas: IDI register failed - table full"));
		return -1;
	}

	switch (card->cfg.card_type)
	{
		case DIA_CARD_TYPE_DIVA_SERVER:
		d[length].type = IDI_ADAPTER_PR;
		/* d[length].serial = card->serial_no; */
		break;

		case DIA_CARD_TYPE_DIVA_SERVER_B:
		d[length].type = IDI_ADAPTER_MAESTRA;
		/* d[length].serial = card->serial_no; */
		break;

		// 4BRI is treated as 4 BRI adapters
		case DIA_CARD_TYPE_DIVA_SERVER_Q:
		d[length].type = IDI_ADAPTER_MAESTRA;
		/* d[length].serial = card->cfg.serial; */
	}

	d[length].features = 0;
	d[length].features |= DI_FAX3|DI_MODEM|DI_POST|DI_V110|DI_V120;

	if ( card->hw->features & PROTCAP_MANIF )
	{
		d[length].features |= DI_MANAGE ;
	}
	if ( card->hw->features & PROTCAP_V_42 )
	{
		d[length].features |= DI_V_42 ;
	}
	if ( card->hw->features & PROTCAP_EXTD_FAX )
	{
		d[length].features |= DI_EXTD_FAX ;
	}

	d[length].channels = channels;
	d[length].request = DivasIdiRequest[card - DivasCards];

	length++;

	DIVA_DIDD_Write(d, sizeof(d));

    return 0;
}

int DivasCardStart(int card_id)
{
	card_t *card;
	byte channels;
	int status;

	DPRINTF(("divas: starting card"));

	card = get_card(card_id);
	if (!card)
	{
		return -1;
	}

	status = (*card->card_start)(card, &channels);
	if (status)
	{
		return status;
	}

	/* 4BRI == 4 x BRI so call idi_register 4 times each with 2 channels */
	if (card->cfg.card_type == DIA_CARD_TYPE_DIVA_SERVER_Q)
	{
		int i;
		card_t *FourBRISlave;

		for (i=3; i >= 0; i--)
		{
			FourBRISlave = get_card(card_id - i); /* 0, 1, 2, 3 */
			if (FourBRISlave)
			{
				idi_register(FourBRISlave, 2);
				FourBRISlave->state = DIA_RUNNING;
			}
		}
		card->serial_no = card->cfg.serial;

		DPRINTF(("divas: card id %d (4BRI), serial no. 0x%x ready with %d channels", 
				card_id - 3, card->serial_no, (int) channels));
	}
	else
	{
		status = idi_register(card, channels);
		if (!status)
		{
			card->state = DIA_RUNNING;
			DPRINTF(("divas: card id %d, serial no. 0x%x ready with %d channels", 
						card_id, card->serial_no, (int) channels));
		}
	}

	return status;
}

int DivasGetMem(mem_block_t *mem_block)
{
	card_t *card;
	word	card_id = mem_block->card_id;

	card = get_card(card_id);
	if (!card)
	{
		return 0;
	}

	return (*card->card_mem_get)(card, mem_block);
}


/*
 * Deleyed Procedure Call for handling interrupts from card
 */

void	DivaDoCardDpc(card_t *card)
{
	ADAPTER	*a;

	a = &card->a;

	if(UxInterlockedIncrement(card->hw, &card->dpc_reentered) > 1)
	{
		return;
	}

	do{
		if((*(card->test_int))(a))
		{
			(*(card->dpc))(a);
			(*(card->clear_int))(a);
		}
			(*(card->out))(a);
	}while(UxInterlockedDecrement(card->hw, &card->dpc_reentered));
			
}

void	DivasDoDpc(void *pData)
{
	card_t	*card = DivasCards;
	int 	i = DivasCardNext;
	
	while(i--)
	{
		DivaDoCardDpc(card++);
	}
}

void	DivasDoRequestDpc(void *pData)
{
	DivasDoDpc(pData);
}

/*
 * DivasGetNum
 * Returns the number of active adapters
 */

int DivasGetNum(void)
{
	return(DivasCardNext);
}

/*
 * DivasGetList
 * Returns a list of active adapters
 */
int DivasGetList(dia_card_list_t *card_list)
{
	int i;

	memset(card_list, 0, sizeof(dia_card_list_t));

	for(i = 0; i < DivasCardNext; i++)
	{
		card_list->card_type = DivasCards[i].cfg.card_type;
		card_list->card_slot = DivasCards[i].cfg.slot;
		card_list->state     = DivasCards[i].state;
		card_list++;
	}

	return 0;

}

/*
 * control logging for specified card
 */

void	DivasLog(dia_log_t *log)
{
	card_t *card;

	card = get_card(log->card_id);
	if (!card)
	{
		return;
	}

	card->log_types = log->log_types;

	return;
}