Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / AHI / Drivers / EMU10kx / emu10kx-init.c
blobaa48ab41ccdac9f7f14402ec5b27eae04759a33a
1 /*
2 emu10kx.audio - AHI driver for SoundBlaster Live! series
3 Copyright (C) 2002-2005 Martin Blom <martin@blom.org>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include <config.h>
22 #include <exec/memory.h>
23 #include <proto/exec.h>
24 #include <clib/alib_protos.h>
27 #include "library.h"
28 #include "version.h"
29 #include "emu10kx-misc.h"
30 #include "pci_wrapper.h"
32 /* We use global library bases instead of storing them in DriverBase, since
33 I don't want to modify the original sources more than necessary. */
35 struct DriverBase* AHIsubBase = NULL;
36 struct ExecBase* SysBase = NULL;
37 struct DosLibrary* DOSBase = NULL;
39 #ifdef __AMIGAOS4__
40 struct DOSIFace* IDOS = NULL;
41 struct ExecIFace* IExec = NULL;
42 struct MMUIFace* IMMU = NULL;
43 #endif
45 #ifdef __AROS__
46 #include <proto/stdc.h>
48 struct StdCBase *StdCBase = NULL;
49 #endif
52 #include "8010.h"
57 /******************************************************************************
58 ** Custom driver init *********************************************************
59 ******************************************************************************/
61 BOOL
62 DriverInit( struct DriverBase* ahisubbase )
64 struct EMU10kxBase* EMU10kxBase = (struct EMU10kxBase*) ahisubbase;
65 APTR dev;
66 int card_no;
68 /*** Libraries etc. ********************************************************/
70 AHIsubBase = ahisubbase;
72 DOSBase = (struct DosLibrary*) OpenLibrary( DOSNAME, 37 );
74 if( DOSBase == NULL )
76 Req( "Unable to open 'dos.library' version 37.\n" );
77 return FALSE;
80 #ifdef __AMIGAOS4__
81 if ((IDOS = (struct DOSIFace *) GetInterface((struct Library *) DOSBase, "main", 1, NULL)) == NULL)
83 Req("Couldn't open IDOS interface!\n");
84 return FALSE;
87 /* if ((IAHIsub = (struct AHIsubIFace *) GetInterface((struct Library *) AHIsubBase, "main", 1, NULL)) == NULL) */
88 /* { */
89 /* Req("Couldn't open IAHIsub interface!\n"); */
90 /* return FALSE; */
91 /* } */
93 if ((IMMU = (struct MMUIFace *) GetInterface((struct Library *) SysBase, "mmu", 1, NULL)) == NULL)
95 Req("Couldn't open IMMU interface!\n");
96 return FALSE;
99 /* if ((IUtility = (struct UtilityIFace *) GetInterface((struct Library *) UtilityBase, "main", 1, NULL)) == NULL) */
100 /* { */
101 /* Req("Couldn't open IUtility interface!\n"); */
102 /* return FALSE; */
103 /* } */
104 #endif
106 #ifdef __AROS__
107 StdCBase = (struct StdCBase *) OpenLibrary( "stdc.library", 0 );
109 if( StdCBase == NULL )
111 Req( "Unable to open 'stdc.library'.\n" );
112 return FALSE;
114 #endif
116 if (!ahi_pci_init(ahisubbase))
118 return FALSE;
121 InitSemaphore( &EMU10kxBase->semaphore );
124 /*** Count cards ***********************************************************/
126 EMU10kxBase->cards_found = 0;
127 dev = NULL;
129 // Search for Live! cards
130 while( ( dev = ahi_pci_find_device( PCI_VENDOR_ID_CREATIVE,
131 PCI_DEVICE_ID_CREATIVE_EMU10K1,
132 dev ) ) != NULL )
134 ++EMU10kxBase->cards_found;
137 // Search for Audigy cards
138 while( ( dev = ahi_pci_find_device( PCI_VENDOR_ID_CREATIVE,
139 PCI_DEVICE_ID_CREATIVE_AUDIGY,
140 dev ) ) != NULL )
142 ++EMU10kxBase->cards_found;
145 // Fail if no hardware (prevents the audio modes form being added to
146 // the database if the driver cannot be used).
148 if( EMU10kxBase->cards_found == 0 )
150 return FALSE;
153 /*** CAMD ******************************************************************/
155 InitSemaphore( &EMU10kxBase->camd.Semaphore );
156 EMU10kxBase->camd.Semaphore.ss_Link.ln_Pri = 0;
157 EMU10kxBase->camd.Semaphore.ss_Link.ln_Name = EMU10KX_CAMD_SEMAPHORE;
159 EMU10kxBase->camd.Cards = EMU10kxBase->cards_found;
160 EMU10kxBase->camd.Version = VERSION;
161 EMU10kxBase->camd.Revision = REVISION;
163 #ifdef __AMIGAOS4__
164 EMU10kxBase->camd.OpenPortFunc.h_Entry = OpenCAMDPort;
165 EMU10kxBase->camd.OpenPortFunc.h_SubEntry = NULL;
166 EMU10kxBase->camd.OpenPortFunc.h_Data = NULL;
168 EMU10kxBase->camd.ClosePortFunc.h_Entry = (HOOKFUNC) CloseCAMDPort;
169 EMU10kxBase->camd.ClosePortFunc.h_SubEntry = NULL;
170 EMU10kxBase->camd.ClosePortFunc.h_Data = NULL;
172 EMU10kxBase->camd.ActivateXmitFunc.h_Entry = (HOOKFUNC) ActivateCAMDXmit;
173 EMU10kxBase->camd.ActivateXmitFunc.h_SubEntry = NULL;
174 EMU10kxBase->camd.ActivateXmitFunc.h_Data = NULL;
176 #else
178 EMU10kxBase->camd.OpenPortFunc.h_Entry = HookEntry;
179 EMU10kxBase->camd.OpenPortFunc.h_SubEntry = OpenCAMDPort;
180 EMU10kxBase->camd.OpenPortFunc.h_Data = NULL;
182 EMU10kxBase->camd.ClosePortFunc.h_Entry = HookEntry;
183 EMU10kxBase->camd.ClosePortFunc.h_SubEntry = (HOOKFUNC) CloseCAMDPort;
184 EMU10kxBase->camd.ClosePortFunc.h_Data = NULL;
186 EMU10kxBase->camd.ActivateXmitFunc.h_Entry = HookEntry;
187 EMU10kxBase->camd.ActivateXmitFunc.h_SubEntry = (HOOKFUNC) ActivateCAMDXmit;
188 EMU10kxBase->camd.ActivateXmitFunc.h_Data = NULL;
189 #endif
191 AddSemaphore( &EMU10kxBase->camd.Semaphore );
193 /*** AC97 Mixer ************************************************************/
195 InitSemaphore( &EMU10kxBase->ac97.Semaphore );
196 EMU10kxBase->ac97.Semaphore.ss_Link.ln_Pri = 0;
197 EMU10kxBase->ac97.Semaphore.ss_Link.ln_Name = EMU10KX_AC97_SEMAPHORE;
199 EMU10kxBase->ac97.Cards = EMU10kxBase->cards_found;
200 EMU10kxBase->ac97.Version = VERSION;
201 EMU10kxBase->ac97.Revision = REVISION;
203 #ifdef __AMIGAOS4__
204 EMU10kxBase->ac97.GetFunc.h_Entry = AC97GetFunc;
205 EMU10kxBase->ac97.GetFunc.h_SubEntry = NULL;
206 EMU10kxBase->ac97.GetFunc.h_Data = NULL;
208 EMU10kxBase->ac97.SetFunc.h_Entry = (HOOKFUNC) AC97SetFunc;
209 EMU10kxBase->ac97.SetFunc.h_SubEntry = NULL;
210 EMU10kxBase->ac97.SetFunc.h_Data = NULL;
212 #else
214 EMU10kxBase->ac97.GetFunc.h_Entry = HookEntry;
215 EMU10kxBase->ac97.GetFunc.h_SubEntry = AC97GetFunc;
216 EMU10kxBase->ac97.GetFunc.h_Data = NULL;
218 EMU10kxBase->ac97.SetFunc.h_Entry = HookEntry;
219 EMU10kxBase->ac97.SetFunc.h_SubEntry = (HOOKFUNC) AC97SetFunc;
220 EMU10kxBase->ac97.SetFunc.h_Data = NULL;
221 #endif
223 AddSemaphore( &EMU10kxBase->ac97.Semaphore );
225 /*** Allocate and init all cards *******************************************/
227 EMU10kxBase->driverdatas = AllocVec( sizeof( *EMU10kxBase->driverdatas ) *
228 EMU10kxBase->cards_found,
229 MEMF_PUBLIC );
231 if( EMU10kxBase->driverdatas == NULL )
233 Req( "Out of memory." );
234 return FALSE;
237 card_no = 0;
239 // Live! cards ...
240 while( ( dev = ahi_pci_find_device( PCI_VENDOR_ID_CREATIVE,
241 PCI_DEVICE_ID_CREATIVE_EMU10K1,
242 dev ) ) != NULL )
244 // AOS4: dev->Lock(PCI_LOCK_EXCLUSIVE); tbd
245 EMU10kxBase->driverdatas[ card_no ] = AllocDriverData( dev, AHIsubBase );
246 ++card_no;
249 // Audigy cards ...
250 while( ( dev = ahi_pci_find_device( PCI_VENDOR_ID_CREATIVE,
251 PCI_DEVICE_ID_CREATIVE_AUDIGY,
252 dev ) ) != NULL )
254 // AOS4: dev->Lock(PCI_LOCK_EXCLUSIVE); tbd
255 EMU10kxBase->driverdatas[ card_no ] = AllocDriverData( dev, AHIsubBase );
256 ++card_no;
259 return TRUE;
263 /******************************************************************************
264 ** Custom driver clean-up *****************************************************
265 ******************************************************************************/
267 VOID
268 DriverCleanup( struct DriverBase* AHIsubBase )
270 struct EMU10kxBase* EMU10kxBase = (struct EMU10kxBase*) AHIsubBase;
271 int i;
273 if( EMU10kxBase->camd.Semaphore.ss_Link.ln_Name != NULL )
275 ObtainSemaphore( &EMU10kxBase->camd.Semaphore );
276 RemSemaphore( &EMU10kxBase->camd.Semaphore );
277 ReleaseSemaphore( &EMU10kxBase->camd.Semaphore );
280 if( EMU10kxBase->ac97.Semaphore.ss_Link.ln_Name != NULL )
282 ObtainSemaphore( &EMU10kxBase->ac97.Semaphore );
283 RemSemaphore( &EMU10kxBase->ac97.Semaphore );
284 ReleaseSemaphore( &EMU10kxBase->ac97.Semaphore );
287 for( i = 0; i < EMU10kxBase->cards_found; ++i )
289 // Kill'em all
290 emu10k1_irq_disable( &EMU10kxBase->driverdatas[ i ]->card, ~0UL );
291 // INTE_MIDIRXENABLE | INTE_MIDITXENABLE);
293 FreeDriverData( EMU10kxBase->driverdatas[ i ], AHIsubBase );
296 FreeVec( EMU10kxBase->driverdatas );
298 #ifdef __AROS__
299 CloseLibrary( (struct Library*) StdCBase );
300 #endif
302 #ifdef __AMIGAOS4__
303 DropInterface((struct Interface *) IDOS);
304 DropInterface((struct Interface *) IMMU);
305 #endif
307 ahi_pci_exit();
309 CloseLibrary( (struct Library*) DOSBase );