Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / AHI / Drivers / Envy24 / driver-init.c
blob3e62a03e828891cf23dc3b44bbda028dac2d7563
1 /*
2 Copyright © 2004-2014, Davy Wentzler. All rights reserved.
3 Copyright © 2010-2014, The AROS Development Team. All rights reserved.
4 $Id$
5 */
7 #include <exec/memory.h>
9 #if !defined(__AROS__)
10 #undef __USE_INLINE__
11 #include <proto/expansion.h>
12 #endif
14 #include <proto/exec.h>
15 #include <proto/dos.h>
16 #include <clib/alib_protos.h>
18 #include "library.h"
19 #include "misc.h"
20 #include "regs.h"
22 #include "pci_wrapper.h"
24 struct DriverBase* AHIsubBase;
26 struct DosLibrary* DOSBase;
27 struct Library* ExpansionBase = NULL;
29 struct VendorDevice
31 UWORD vendor;
32 UWORD device;
35 #define VENDOR_ID 0x1412
36 #define DEVICE_ID 0x1712
37 #define CARD_STRING "Envy24"
38 #define MAX_DEVICE_VENDORS 512
40 struct VendorDevice *vendor_device_list = NULL;
41 static int vendor_device_list_size = 0;
43 /******************************************************************************
44 ** Custom driver init *********************************************************
45 ******************************************************************************/
47 BOOL
48 DriverInit( struct DriverBase* ahisubbase )
50 struct CardBase *CardBase = (struct CardBase*) ahisubbase;
51 struct PCIDevice *dev;
52 int card_no, i;
53 struct List foundCards;
54 struct Node *devTmp;
56 DebugPrintF("[Envy24]: %s()\n", __PRETTY_FUNCTION__);
58 CardBase->driverdatas = 0;
59 CardBase->cards_found = 0;
60 AHIsubBase = ahisubbase;
62 NewList(&foundCards);
64 DOSBase = (struct DosLibrary *)OpenLibrary( DOSNAME, 37 );
66 if( DOSBase == NULL )
68 Req( "Envy24: Unable to open 'dos.library' version 37.\n" );
69 return FALSE;
72 ExpansionBase = OpenLibrary( "expansion.library", 1 );
73 if( ExpansionBase == NULL )
75 Req( "Envy24: Unable to open 'expansion.library' version 1.\n" );
76 return FALSE;
79 if (!ahi_pci_init(ahisubbase))
81 return FALSE;
84 InitSemaphore( &CardBase->semaphore );
86 /*** Count cards ***********************************************************/
88 vendor_device_list = (struct VendorDevice *) AllocVec(sizeof(struct VendorDevice) * MAX_DEVICE_VENDORS, MEMF_PUBLIC | MEMF_CLEAR);
90 vendor_device_list[0].vendor = VENDOR_ID;
91 vendor_device_list[0].device = DEVICE_ID;
92 vendor_device_list_size++;
94 DebugPrintF("vendor_device_list_size = %ld\n", vendor_device_list_size);
96 CardBase->cards_found = 0;
97 dev = NULL;
99 for (i = 0; i < vendor_device_list_size; i++)
101 dev = ahi_pci_find_device(vendor_device_list[i].vendor, vendor_device_list[i].device, dev);
103 if (dev != NULL)
105 DebugPrintF("[Envy24] %s: Found Envy24 #%d [%4x:%4x] pci obj @ 0x%p\n", __PRETTY_FUNCTION__, i, vendor_device_list[i].vendor, vendor_device_list[i].device, dev);
106 ++CardBase->cards_found;
108 devTmp = AllocVec(sizeof(struct Node), MEMF_CLEAR);
109 devTmp->ln_Name = (APTR)dev;
110 AddTail(&foundCards, devTmp);
114 // Fail if no hardware is present (prevents the audio modes from being added to
115 // the database if the driver cannot be used).
117 if(CardBase->cards_found == 0 )
119 DebugPrintF("No Envy24 found! :-(\n");
120 #if defined(VERBOSE_REQ)
121 Req( "No card present.\n" );
122 #endif
123 return FALSE;
126 /*** Allocate and init all cards *******************************************/
128 CardBase->driverdatas = AllocVec( sizeof( *CardBase->driverdatas ) *
129 CardBase->cards_found,
130 MEMF_PUBLIC | MEMF_CLEAR);
132 if( CardBase->driverdatas == NULL )
134 Req( "Out of memory." );
135 return FALSE;
138 card_no = 0;
140 struct Node *scratchNode;
141 ForeachNodeSafe(&foundCards, devTmp, scratchNode)
143 Remove(devTmp);
145 dev = (struct PCIDevice *)devTmp->ln_Name;
146 DebugPrintF("[Envy24] %s: Preparing card #%d pci obj @ 0x%p\n", __PRETTY_FUNCTION__, card_no, dev);
147 CardBase->driverdatas[ card_no ] = AllocDriverData( dev, AHIsubBase );
149 FreeVec(devTmp);
150 ++card_no;
153 DebugPrintF("[Envy24] %s: Done.\n", __PRETTY_FUNCTION__);
155 return TRUE;
159 /******************************************************************************
160 ** Custom driver clean-up *****************************************************
161 ******************************************************************************/
163 VOID
164 DriverCleanup( struct DriverBase* AHIsubBase )
166 struct CardBase* CardBase = (struct CardBase*) AHIsubBase;
167 int i;
169 DebugPrintF("[Envy24]: %s()\n", __PRETTY_FUNCTION__);
171 for( i = 0; i < CardBase->cards_found; ++i )
173 FreeDriverData( CardBase->driverdatas[ i ], AHIsubBase );
176 FreeVec( CardBase->driverdatas );
178 ahi_pci_exit();
180 if (ExpansionBase)
181 CloseLibrary( (struct Library*) ExpansionBase);
183 if (UtilityBase)
184 CloseLibrary( (struct Library*) UtilityBase);
186 if (DOSBase)
187 CloseLibrary( (struct Library*) DOSBase);