/* Tiger 320 chip chagne 2004/9/13 */ /* Update Jun.03, 2005 by Gary Lin > Use Lookup-Table to support all PIO/PISO cards. > Add Debug-Mode supports. > Arrange the source code to supports TC/BC/MSC. */ #include "Pio.H" #define MAX_BOARD_NUMBER 16 #define PCI_CONFIG_VENDEV 0 #define PCI_CONFIG_BAR0 4 #define PCI_CONFIG_SUBVENDEV 11 #define PCI_CONFIG_INTERRUPT 15 typedef struct { DWORD VendorDevice; // Vendor-Device ID, Tiger320/100 DWORD SubVenDev; // SubVendor, SubDevice ID BYTE SubAux; // SubAux BYTE SVDMask; // Mask for Sub-VendorDevice ID (First Byte) DWORD CompatibleID; // Compatible ID char name[20]; // Device Name } CARD_ID; // Order by SVDMask: more mask off (0x1F), more below (last one) const CARD_ID piso[]={ // VenDevID, Sub-VenDev, Aux, SVDMask,CompatibleID, Name {TIGER320, 0x0B890003, 0xFF, 0xFF, 0x0B890003, "PISO-PS400" }, {TIGER320, 0x0B890002, 0xFF, 0xFF, 0x0B890002, "PISO-PS200" }, {TIGER100, 0x00810004, 0xFF, 0xFF, 0x00810004, "PISO-PS300" }, {TIGER320, 0x41810000, 0xFF, 0xBF, 0x00810004, "PISO-PS300" }, /*========================================================*/ {TIGER320, 0x18000000, 0xFF, 0xFF, 0x18000000, "PISO-P16R16U"}, /*========================================================*/ {TIGER100, 0x800001, 0x50, 0xFF, 0x00800150, "PIO-D168A" }, {TIGER320, 0x98800001, 0x50, 0xBF, 0x00800150, "PIO-D168" }, {TIGER100, 0x800001, 0x00, 0xFF, 0x00800100, "PIO-D144" }, {TIGER320, 0x1C800001, 0x00, 0xBF, 0x00800100, "PIO-D144" }, {TIGER100, 0x800001, 0x10, 0xFF, 0x00800110, "PIO-D96" }, {TIGER320, 0x18800001, 0x10, 0xBF, 0x00800110, "PIO-D96" }, {TIGER100, 0x800001, 0x20, 0xFF, 0x00800120, "PIO-D64" }, {TIGER320, 0x00800001, 0x20, 0xBF, 0x00800120, "PIO-D64" }, {TIGER100, 0x800001, 0x40, 0xFF, 0x00800140, "PIO-D24/D56"}, {TIGER320, 0x80800001, 0x40, 0xBF, 0x00800140, "PIO-D24/D56"}, {TIGER100, 0x800001, 0x30, 0xFF, 0x00800130, "PIO-D48" }, {TIGER320, 0x00800001, 0x30, 0xBF, 0x00800130, "PIO-D48" }, {TIGER100, 0x800003, 0xFF, 0xFF, 0x008003FF, "PIO-821" }, {TIGER320, 0x40FF0003, 0xFF, 0xBF, 0x008003FF, "PIO-821" }, {TIGER100, 0x800004, 0xFF, 0xFF, 0x008004FF, "PIO-DA4816" }, {TIGER320, 0x41800000, 0xFF, 0xBF, 0x008004FF, "PIO-DA4816" }, /*========================================================*/ {TIGER100, 0x800008, 0x00, 0xFF, 0x00800800, "PISO-C64" }, {TIGER320, 0x02800000, 0x00, 0xBF, 0x00800800, "PISO-C64" }, {TIGER100, 0x800008, 0x10, 0xFF, 0x00800810, "PISO-P64" }, {TIGER320, 0x02800000, 0x10, 0xBF, 0x00800810, "PISO-P64" }, {TIGER320, 0x62800000, 0x90, 0xBF, 0x00800810, "PISO-P64" }, {TIGER100, 0x800008, 0x50, 0xFF, 0x00800850, "PISO-A64" }, {TIGER320, 0x82800000, 0x50, 0xBF, 0x00800850, "PISO-A64" }, {TIGER100, 0x800008, 0x20, 0xFF, 0x00800820, "PISO-P32C32"}, {TIGER320, 0x02800000, 0x20, 0xBF, 0x00800820, "PISO-P32C32"}, {TIGER100, 0x800008, 0x70, 0xFF, 0x00800870, "PISO-P32A32"}, {TIGER320, 0x82800000, 0x70, 0xBF, 0x00800870, "PISO-P32A32"}, // for PISO-P8R8, PISO-P8SSR8AC, PISO-P8SSR8DC {TIGER100, 0x800008, 0x30, 0xFF, 0x00800830, "PISO-P8R8/SSR"}, {TIGER320, 0x42000000, 0x30, 0xBF, 0x00800830, "PISO-P8R8/SSR"}, {TIGER320, 0x4A800000, 0x30, 0xBF, 0x00800830, "PISO-P8R8/SSR"}, {TIGER100, 0x800008, 0x40, 0xFF, 0x00800840, "PISO-730" }, {TIGER320, 0xC2FF0000, 0x40, 0xBF, 0x00800840, "PISO-730" }, {TIGER320, 0xCA800000, 0x40, 0xFF, 0x00800840, "PISO-730" }, {TIGER100, 0x800008, 0x80, 0xFF, 0x00800880, "PISO-730A" }, {TIGER320, 0x62FF0000, 0x80, 0xBF, 0x00800880, "PISO-730A" }, {TIGER100, 0x80000A, 0xFF, 0xFF, 0x00800AFF, "PISO-813" }, {TIGER320, 0x02800002, 0xFF, 0xBF, 0x00800AFF, "PISO-813" }, {TIGER100, 0x80000B, 0xFF, 0xFF, 0x00800BFF, "PISO-DA2" }, {TIGER320, 0x42800003, 0xFF, 0xBF, 0x00800BFF, "PISO-DA2" }, /*========================================================*/ {TIGER320, 0x1D610000, 0xFF, 0xFF, 0x1D610000, "VXC-112A" }, {TIGER100, 0x00610000, 0xFF, 0xFF, 0x00610000, "VXC-142" }, {TIGER320, 0x610000, 0xFF, 0x9F, 0x00610000, "VXC-142" }, {TIGER320, 0x61610002, 0xFF, 0x9F, 0x01610002, "VXC-142i" }, {TIGER100, 0x00610005, 0xFF, 0xFF, 0x00610005, "VXC-182i" }, {TIGER320, 0x61610001, 0xFF, 0x9F, 0x00610005, "VXC-182i" }, {TIGER320, 0x61600001, 0xFF, 0x9F, 0x00610005, "VXC-182i" }, /*========================================================*/ // PISO-725, bit15 ~13 = Aux6,1,7 = Interrupt Status {TIGER100, 0x80000C, 0xFF, 0xFF, 0x008008FF, "PISO-725" }, {TIGER320, 0x03800000, 0xFF, 0x1F, 0x008008FF, "PISO-725" } }; WORD TotalRecords=sizeof(piso)/sizeof(CARD_ID); WORD wTotalBoards=0; WORD wGetAddress=0; char Pio_Debug = 0; // 1 for debug print, 0 for NOT debug /* [0][1] --> system resource allocated wConfigSpace[][0]= wBase wConfigSpace[][1]= wIrq [2][3][4] --> subID to identify PIO/PISO cards wConfigSpace[][2]= wSubVendorID wConfigSpace[][3]= wSubDeviceID wConfigSpace[][4]= wSubAuxID [5][6] --> SlotID to identify the slot position of this PIO/PISO card wConfigSpace[][5]= wSlotBus wConfigSpace[][6]= wSlotDevice */ WORD wConfigSpace[MAX_BOARD_NUMBER][7]; WORD SearchCards(WORD wSubVendor, WORD wSubDevice, WORD wSubAux); //WORD PIO_DA_DaInit(WORD wBaseAddr); void PIODA_DA(WORD wBaseAddr,int iVal); void PIODA_DA(WORD wBaseAddr,int iVal) { int iChannel_no; outportb(wBaseAddr,0x11); //Enable for(iChannel_no = 0;iChannel_no<16;iChannel_no++) { iVal=iVal+(iChannel_no%4)*0x4000; /* iChannel_no : 0 - 15 */ outportb(wBaseAddr+0xf0,iVal); /* iVal : 0x0000 - 0x3fff */ outportb(wBaseAddr+0xf4,(iVal>>8)); outportb(wBaseAddr+0xe0+4*(iChannel_no/4),0xff); } } /* -------------------------------------------------------------------- */ // Returns the Compatible ID if found. // Returns 0 if the card is not in the list, it is an unknow device. DWORD GetCompatibleID(DWORD dwVenDev, DWORD dwSubVenDev, BYTE SubAux) { int i; DWORD dwMask; for (i=0; i> 16); return CfgData; } /* -------------------------------------------------------------------- */ float PIO_FloatSub2(float fA, float fB) { return(fA-fB); } short PIO_ShortSub2(short nA, short nB) { return(nA-nB); } WORD PIO_GetDriverVersion(WORD *wDriverVersion) { *wDriverVersion=0x221; return( NoError ); } /* -------------------------------------------------------------------- */ WORD PIO_DriverInit(WORD *wBoards, DWORD wSubVendorID, WORD wSubDeviceID, BYTE wSubAuxID) { WORD wReturnCode; wReturnCode=SearchCards((WORD)wSubVendorID, wSubDeviceID, wSubAuxID); *wBoards=wTotalBoards; return( wReturnCode ); } /* -------------------------------------------------------------------- */ WORD PIO_DriverClose(void) { return( NoError ); } /* -------------------------------------------------------------------- */ WORD PIO_GetConfigAddressSpace( WORD wBoardNo, WORD *wBaseAddr, WORD *wIrq, WORD *wSubVendor, WORD *wSubDevice, WORD *wSubAux, WORD *wSlotBus, WORD *wSlotDevice) { /* if (wGetAddress==0) { if (SearchCards()!=0) return(FindBoardError); } */ if ( wBoardNo>=wTotalBoards ) return ExceedBoardNumber; /* [0][1] --> system resource allocated */ *wBaseAddr = wConfigSpace[wBoardNo][0]; *wIrq = wConfigSpace[wBoardNo][1]; /* [2][3][4] --> subID to identify PIO/PISO cards */ *wSubVendor = wConfigSpace[wBoardNo][2]; *wSubDevice = wConfigSpace[wBoardNo][3]; *wSubAux = wConfigSpace[wBoardNo][4]; /* [5][6] --> SlotID to identify the slot position of this PIO/PISO card */ *wSlotBus = wConfigSpace[wBoardNo][5]; *wSlotDevice= wConfigSpace[wBoardNo][6]; return(NoError); } WORD SearchCards(WORD SubVendorID, WORD SubDeviceID, WORD SubAuxID) { UCHAR Bus, Device, Function; WORD GotVendorID, GotDeviceID; WORD GotSubVendorID, GotSubDeviceID; BYTE GotSubAuxID; DWORD GotVenDev, GotSubVenDev; DWORD dwFindingID, dwCompatibleID; WORD wBaseAddr, mask_val; WORD wIrqNo; wTotalBoards =0; // initial board number is 0 dwFindingID =0; // dwFindingID : // 0xFFFFFF = Search all cards // 0 = Search an unknown device // others = Search an specified card ID if ( SubVendorID == 0xFF && SubDeviceID == 0xFF && SubAuxID == 0xFF ) { dwFindingID = 0xFFFFFF; // Search All Cards } else { dwFindingID = ((DWORD)SubVendorID << 16) | SubDeviceID; dwFindingID &= 0xBFFFFFFF; dwFindingID = GetCompatibleID(0, dwFindingID, (BYTE)(0xFF & SubAuxID)); //printf("Test = %xd\n",dwFindingID); } //printf("We are finding 0x%lx\n", dwFindingID); if ( Pio_Debug ) { printf("\nDebug List..."); printf("\nVendor:Device SubVen:Device BAR0 Irq SAux Mark"); } for(Bus=0; Bus<32; Bus++) // for 32 bus { Function=0; for(Device=0; Device<32; Device++) // for 32 device { // ****************************** // Get the Vendor and Device ID Pci_WriteConfigAddress(Bus, Device, Function, PCI_CONFIG_VENDEV); Pci_ReadConfigData(&GotVendorID, &GotDeviceID); GotVenDev = ((DWORD)GotVendorID << 16) | GotDeviceID; // ****************************** // Get the Sub-Vendor and Sub-Device ID Pci_WriteConfigAddress(Bus, Device, Function, PCI_CONFIG_SUBVENDEV); Pci_ReadConfigData(&GotSubVendorID, &GotSubDeviceID); //GotSubVendorID &= 0xBFFF; // mask for Tiger320 GotSubVenDev = ((DWORD)GotSubVendorID << 16) | GotSubDeviceID; // ****************************** Pci_WriteConfigAddress(Bus, Device, Function, PCI_CONFIG_BAR0); Pci_ReadConfigData(&wBaseAddr, NULL); wBaseAddr &= 0xfffe; // ****************************** // Get the interrupt channel Pci_WriteConfigAddress(Bus, Device, Function, PCI_CONFIG_INTERRUPT); Pci_ReadConfigData(&wIrqNo, NULL); wIrqNo &= 0xff; if ( GotVendorID == 0xFFFF || GotDeviceID == 0xFFFF ) continue; if ( Pio_Debug ) { //printf("\nVendor:Device SubVen:Device BAR0 Irq SAux Mark"); printf("\n0x%04x:%04x 0x%04x:%04x %04x %02x", GotVendorID, GotDeviceID, GotSubVendorID, GotSubDeviceID, wBaseAddr, wIrqNo); } // We are finding Tiger320 and Tiger100 if ( (GotVenDev != TIGER320) && (GotVenDev != TIGER100) ) continue; /* if ((GotSubVendorID==0x80) && (GotSubDeviceID==0x04)) mask_val=0xc0; // PIO-DA family else if ((GotSubVendorID==0x61) && (GotSubDeviceID==0x05)) mask_val=0x70; // VXC-182I family else mask_val=0xf0; // other family */ mask_val = 0xF0; //_outp((WORD)(wBaseAddr+2),0); // Set Aux Control to input GotSubAuxID= inpw((WORD)(wBaseAddr+0x07)); GotSubAuxID= GotSubAuxID & mask_val; if ( Pio_Debug ) { printf(" %02x", GotSubAuxID) ; } if ( dwFindingID != 0xFFFFFF ) { // Search special cards if ( dwFindingID != 0 ) { // Search PIO/PISO Cards dwCompatibleID = GetCompatibleID(GotVenDev, GotSubVenDev, GotSubAuxID); if ( dwCompatibleID != dwFindingID ) continue; // skip this one //printf("%lx\n",dwCompatibleID); if (dwCompatibleID==0x008004FF) { PIODA_DA(wBaseAddr,8192); // D/A Initial Value = 0 for PIO-DA } } else { // Search an unknown device if (SubVendorID != GotSubVendorID || SubDeviceID != GotSubDeviceID) continue; // skip this one } } if ( Pio_Debug ) { printf(" ** ") ; } // Now, we got the specified card. // Or, we got the Tiger320/Tiger100 series card. wConfigSpace[wTotalBoards][0]=wBaseAddr; // wBase wConfigSpace[wTotalBoards][1]=wIrqNo; // wIrq wConfigSpace[wTotalBoards][2]=GotSubVendorID; // sub_VENDOR_ID wConfigSpace[wTotalBoards][3]=GotSubDeviceID; // sub_DEVICE_ID wConfigSpace[wTotalBoards][4]=GotSubAuxID; // sub_AUX_ID wConfigSpace[wTotalBoards][5]=Bus; // SlotBusID wConfigSpace[wTotalBoards][6]=Device; // SlotDeviceID wTotalBoards++; // increment board number wGetAddress=1; //if GetCompatibleID(DWORD dwVenDev, DWORD dwSubVenDev, BYTE SubAux)== 0x008004FF if (wTotalBoards >MAX_BOARD_NUMBER) return ExceedBoardNumber; } // end of each device //printf("Test\n"); //printf("SubVe %xd\n",GotSubVendorID); // printf("SubDev %xd\n",GotSubDeviceID); // printf("SubAux %xd\n",GotSubAuxID); // printf("BASE %xd\n",wBaseAddr); // if (GetCompatibleID(GotSubVendorID, GotSubDeviceID, GotSubAuxID)==0x4FF) // { //printf("123\n"); // } } // end of each bus if( wTotalBoards==0 ) return( FindBoardError ); return( NoError ); } /* -------------------------------------------------------------------- */ WORD ShowPioPiso(DWORD wSubVendorID, WORD wSubDeviceID, WORD wSubAux) { int i; DWORD dwSVD = (wSubVendorID << 16) + wSubDeviceID; DWORD dwFindingID = GetCompatibleID(0, dwSVD, (BYTE)wSubAux); if ( dwFindingID == 0 ) { printf("Unknown Device\n"); return 1; } // printf(" SearchID = %lx" , SearchID); for (i=0 ; i< TotalRecords ; i++ ) { if (dwFindingID == piso[i].CompatibleID) { printf("%s\n",piso[i].name); break; } } return 0; } // 1 or '1' : Enable Debug Print // else disable it! void PIO_SetDebugMode(UCHAR bMode) { if ( bMode == 1 || bMode == '1') Pio_Debug = 1; else Pio_Debug = 0; } /*************** for Microsoft C Compiler ****************/ #ifdef _MSC_VER void clrscr(void) { union REGS r; r.h.ah=6; r.h.al=0; r.h.ch=0; r.h.cl=0; r.h.dh=24; r.h.dl=79; r.h.bh=7; int86(0x10,&r,&r); } void gotoxy(int x,int y) { union REGS r; r.h.ah=2; r.h.dl=x-1; r.h.dh=y-1; r.h.bh=0; int86(0x10,&r,&r); } void delay1(int d) { long lDelay; do { d--; lDelay=1000; do { lDelay--; } while(lDelay>0); } while(d>0); } #endif /*************** for Microsoft C Compiler ****************/