3 The contents of this file are subject to the AROS Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
4 http://www.aros.org/license.html
6 Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
7 ANY KIND, either express or implied. See the License for the specific language governing rights and
8 limitations under the License.
10 The Original Code is (C) Copyright 2004-2011 Ross Vumbaca.
12 The Initial Developer of the Original Code is Ross Vumbaca.
20 #include <exec/memory.h>
23 #include <proto/expansion.h>
25 #include <proto/exec.h>
26 #include <proto/dos.h>
28 #include <devices/timer.h>
30 #include "library_card.h"
34 #include "DriverData.h"
37 struct Library
* SysBase
;
38 struct Library
* DOSBase
;
39 struct DriverBase
* AHIsubBase
;
41 struct Library
* ExpansionBase
= NULL
;
42 struct ExpansionIFace
* IExpansion
= NULL
;
43 struct UtilityIFace
* IUtility
= NULL
;
44 struct AHIsubIFace
* IAHIsub
= NULL
;
45 struct MMUIFace
* IMMU
= NULL
;
46 struct PCIIFace
* IPCI
= NULL
;
48 #define CARD_STRING "SB128"
51 /******************************************************************************
52 ** Custom driver init *********************************************************
53 ******************************************************************************/
56 DriverInit( struct DriverBase
* ahisubbase
)
58 struct CardBase
* CardBase
= (struct CardBase
*) ahisubbase
;
59 struct PCIDevice
*dev
;
68 PCI_ANY_ID
, PCI_ANY_ID
71 CardBase
->cards_found
= 0;
72 CardBase
->driverdatas
= 0;
73 AHIsubBase
= ahisubbase
;
75 DOSBase
= IExec
->OpenLibrary( DOSNAME
, 37 );
79 Req( "Unable to open 'dos.library' version 37.\n" );
83 if ((IDOS
= (struct DOSIFace
*) IExec
->GetInterface((struct Library
*) DOSBase
, "main", 1, NULL
)) == NULL
)
85 Req("Couldn't open IDOS interface!\n");
89 ExpansionBase
= IExec
->OpenLibrary( "expansion.library", 50 );
90 if( ExpansionBase
== NULL
)
92 Req( "Unable to open 'expansion.library' version 50.\n" );
95 if ((IExpansion
= (struct ExpansionIFace
*) IExec
->GetInterface((struct Library
*) ExpansionBase
, "main", 1, NULL
)) == NULL
)
97 Req("Couldn't open IExpansion interface!\n");
101 if ((IPCI
= (struct PCIIFace
*) IExec
->GetInterface((struct Library
*) ExpansionBase
, "pci", 1, NULL
)) == NULL
)
103 Req("Couldn't open IPCI interface!\n");
107 if ((IAHIsub
= (struct AHIsubIFace
*) IExec
->GetInterface((struct Library
*) AHIsubBase
, "main", 1, NULL
)) == NULL
)
109 Req("Couldn't open IAHIsub interface!\n");
113 if ((IUtility
= (struct UtilityIFace
*) IExec
->GetInterface((struct Library
*) UtilityBase
, "main", 1, NULL
)) == NULL
)
115 Req("Couldn't open IUtility interface!\n");
119 if ((IMMU
= (struct MMUIFace
*) IExec
->GetInterface((struct Library
*) SysBase
, "mmu", 1, NULL
)) == NULL
)
121 Req("Couldn't open IMMU interface!\n");
127 /* replymp = (struct MsgPort *) IExec->CreatePort(NULL, 0);
130 IExec->DebugPrintF("SB128: Couldn't create ReplyPort!\n");
134 /*TimerIO = (struct timerequest *)IExec->CreateIORequest(replymp, sizeof(struct timerequest));
138 IExec->DebugPrintF("Out of memory.\n");
142 if (IExec->OpenDevice("timer.device", UNIT_MICROHZ, (struct IORequest *)TimerIO, 0) != 0)
144 IExec->DebugPrintF("Unable to open 'timer.device'.\n");
148 TimerBase = (struct Device *)TimerIO->tr_node.io_Device;*/
150 IExec
->InitSemaphore( &CardBase
->semaphore
);
153 /*** Count cards ***********************************************************/
157 if ( (dev
= IPCI
->FindDeviceTags( FDT_CandidateList
, cards
,
158 TAG_DONE
) ) != NULL
)
160 ++CardBase
->cards_found
;
161 IExec
->DebugPrintF("%s found! :-)\n", CARD_STRING
);
164 /* Fail if no hardware is present (prevents the audio modes from being added to
165 the database if the driver cannot be used). */
167 if( CardBase
->cards_found
== 0 )
169 IExec
->DebugPrintF("No %s found! :-(\n", CARD_STRING
);
170 Req( "No card present.\n" );
174 /*** CAMD ******************************************************************/
176 IExec
->InitSemaphore( &CardBase
->camd
.Semaphore
);
177 CardBase
->camd
.Semaphore
.ss_Link
.ln_Pri
= 0;
179 CardBase
->camd
.Semaphore
.ss_Link
.ln_Name
= Card_CAMD_SEMAPHORE
;
180 IExec
->AddSemaphore( &CardBase
->camd
.Semaphore
);
182 CardBase
->camd
.Cards
= CardBase
->cards_found
;
183 CardBase
->camd
.Version
= VERSION
;
184 CardBase
->camd
.Revision
= REVISION
;
187 CardBase
->camd
.OpenPortFunc
.h_Entry
= OpenCAMDPort
;
188 CardBase
->camd
.OpenPortFunc
.h_SubEntry
= NULL
;
189 CardBase
->camd
.OpenPortFunc
.h_Data
= NULL
;
191 CardBase
->camd
.ClosePortFunc
.h_Entry
= (HOOKFUNC
) CloseCAMDPort
;
192 CardBase
->camd
.ClosePortFunc
.h_SubEntry
= NULL
;
193 CardBase
->camd
.ClosePortFunc
.h_Data
= NULL
;
195 CardBase
->camd
.ActivateXmitFunc
.h_Entry
= (HOOKFUNC
) ActivateCAMDXmit
;
196 CardBase
->camd
.ActivateXmitFunc
.h_SubEntry
= NULL
;
197 CardBase
->camd
.ActivateXmitFunc
.h_Data
= NULL
;
201 /*** Allocate and init all cards *******************************************/
203 CardBase
->driverdatas
= IExec
->AllocVec( sizeof( *CardBase
->driverdatas
) *
204 CardBase
->cards_found
,
207 if( CardBase
->driverdatas
== NULL
)
209 Req( "Out of memory." );
215 if( ( dev
= IPCI
->FindDeviceTags( FDT_CandidateList
, cards
,
216 TAG_DONE
) ) != NULL
)
218 CardBase
->driverdatas
[ card_no
] = AllocDriverData( dev
, AHIsubBase
);
226 /******************************************************************************
227 ** Custom driver clean-up *****************************************************
228 ******************************************************************************/
231 DriverCleanup( struct DriverBase
* AHIsubBase
)
233 struct CardBase
* CardBase
= (struct CardBase
*) AHIsubBase
;
236 if( CardBase
->camd
.Semaphore
.ss_Link
.ln_Name
!= NULL
)
238 IExec
->ObtainSemaphore( &CardBase
->camd
.Semaphore
);
239 IExec
->RemSemaphore( &CardBase
->camd
.Semaphore
);
240 IExec
->ReleaseSemaphore( &CardBase
->camd
.Semaphore
);
244 for( i
= 0; i
< CardBase
->cards_found
; ++i
)
246 if (CardBase
->driverdatas
)
248 CardBase
->driverdatas
[ i
]->pci_dev
->OutLong(CardBase
->driverdatas
[ i
]->iobase
+ SB128_SCON
, 0);
249 FreeDriverData( CardBase
->driverdatas
[ i
], AHIsubBase
);
253 if (CardBase
->driverdatas
)
254 IExec
->FreeVec( CardBase
->driverdatas
);
258 IExec->CloseDevice((struct IORequest *)TimerIO);
259 IExec->DeleteIORequest((struct IORequest *)TimerIO);
263 IExec->DeletePort(replymp);*/
266 IExec
->DropInterface( (struct Interface
*) IMMU
);
269 IExec
->DropInterface( (struct Interface
*) IUtility
);
272 IExec
->DropInterface( (struct Interface
*) IExpansion
);
275 IExec
->DropInterface( (struct Interface
*) IPCI
);
278 IExec
->DropInterface( (struct Interface
*) IAHIsub
);
281 IExec
->DropInterface( (struct Interface
*) IDOS
);
284 IExec
->CloseLibrary( (struct Library
*) ExpansionBase
);
287 IExec
->CloseLibrary( (struct Library
*) UtilityBase
);
290 IExec
->CloseLibrary( (struct Library
*) DOSBase
);