grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / devs / AHI / Drivers / SB128 / driver-init.c
blob0328412ff7d2bde4dbc40df73d17bf117d3fd2ad
1 /*
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.
14 All Rights Reserved.
18 #include <aros/debug.h>
20 #include <exec/memory.h>
22 #include <proto/exec.h>
23 #include <proto/dos.h>
24 #include <clib/alib_protos.h>
26 #include "library.h"
27 #include "misc.h"
28 #include "regs.h"
30 #include "pci_wrapper.h"
32 struct DosLibrary* DOSBase;
33 struct DriverBase* AHIsubBase;
34 struct Library* ExpansionBase = NULL;
35 #ifdef __AROS__
36 struct Library *StdCBase = NULL;
37 #endif
39 struct VendorDevice
41 UWORD vendor;
42 UWORD device;
45 #define CARD_STRING "SB128"
46 #define MAX_DEVICE_VENDORS 512
48 struct VendorDevice *vendor_device_list = NULL;
49 static int vendor_device_list_size = 0;
51 /******************************************************************************
52 ** Custom driver init *********************************************************
53 ******************************************************************************/
55 BOOL
56 DriverInit( struct DriverBase* ahisubbase )
58 struct SB128Base* SB128Base = (struct SB128Base*) ahisubbase;
59 struct PCIDevice *dev;
60 int card_no, i;
61 struct List foundCards;
62 struct Node *devTmp;
64 D(bug("[SB128]: %s()\n", __PRETTY_FUNCTION__));
66 SB128Base->cards_found = 0;
67 SB128Base->driverdatas = 0;
68 AHIsubBase = ahisubbase;
70 NewList(&foundCards);
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 ExpansionBase = OpenLibrary( "expansion.library", 1 );
81 if( ExpansionBase == NULL )
83 Req( "Unable to open 'expansion.library' version 1.\n" );
84 return FALSE;
87 #ifdef __AROS__
88 StdCBase = OpenLibrary( "stdc.library", 0 );
89 if( StdCBase == NULL)
91 Req( "Unable to open 'stdc.library'.\n" );
92 return FALSE;
94 #endif
96 if (!ahi_pci_init(ahisubbase))
98 return FALSE;
101 InitSemaphore( &SB128Base->semaphore );
103 /*** Count cards ***********************************************************/
105 vendor_device_list = (struct VendorDevice *) AllocVec(sizeof(struct VendorDevice) * MAX_DEVICE_VENDORS, MEMF_PUBLIC | MEMF_CLEAR);
107 vendor_device_list[0].vendor = 0x1274;
108 vendor_device_list[0].device = 0x5000;
109 vendor_device_list_size++;
111 vendor_device_list[1].vendor = 0x1274;
112 vendor_device_list[1].device = 0x1371;
113 vendor_device_list_size++;
115 vendor_device_list[2].vendor = 0x1274;
116 vendor_device_list[2].device = 0x5880;
117 vendor_device_list_size++;
119 vendor_device_list[3].vendor = 0x1102;
120 vendor_device_list[3].device = 0x8938;
121 vendor_device_list_size++;
123 D(bug("vendor_device_list_size = %ld\n", vendor_device_list_size));
125 SB128Base->cards_found = 0;
126 dev = NULL;
128 for (i = 0; i < vendor_device_list_size; i++)
130 dev = ahi_pci_find_device(vendor_device_list[i].vendor, vendor_device_list[i].device, dev);
132 if (dev != NULL)
134 D(bug("[SB128] %s: Found SB128 #%d [%4x:%4x] pci obj @ 0x%p\n", __PRETTY_FUNCTION__, i, vendor_device_list[i].vendor, vendor_device_list[i].device, dev));
135 ++SB128Base->cards_found;
137 devTmp = AllocVec(sizeof(struct Node), MEMF_CLEAR);
138 devTmp->ln_Name = (APTR)dev;
139 AddTail(&foundCards, devTmp);
143 // Fail if no hardware is present (prevents the audio modes from being added to
144 // the database if the driver cannot be used).
146 if(SB128Base->cards_found == 0 )
148 D(bug("[SB128] %s: No SB128 found! :-(\n", __PRETTY_FUNCTION__));
149 #if defined(VERBOSE_REQ)
150 Req( "No card present.\n" );
151 #endif
152 return FALSE;
155 /*** CAMD ******************************************************************/
156 #if 0
157 InitSemaphore( &SB128Base->camd.Semaphore );
158 SB128Base->camd.Semaphore.ss_Link.ln_Pri = 0;
160 SB128Base->camd.Semaphore.ss_Link.ln_Name = Card_CAMD_SEMAPHORE;
161 AddSemaphore( &SB128Base->camd.Semaphore );
163 SB128Base->camd.Cards = SB128Base->cards_found;
164 SB128Base->camd.Version = VERSION;
165 SB128Base->camd.Revision = REVISION;
168 SB128Base->camd.OpenPortFunc.h_Entry = OpenCAMDPort;
169 SB128Base->camd.OpenPortFunc.h_SubEntry = NULL;
170 SB128Base->camd.OpenPortFunc.h_Data = NULL;
172 SB128Base->camd.ClosePortFunc.h_Entry = (HOOKFUNC) CloseCAMDPort;
173 SB128Base->camd.ClosePortFunc.h_SubEntry = NULL;
174 SB128Base->camd.ClosePortFunc.h_Data = NULL;
176 SB128Base->camd.ActivateXmitFunc.h_Entry = (HOOKFUNC) ActivateCAMDXmit;
177 SB128Base->camd.ActivateXmitFunc.h_SubEntry = NULL;
178 SB128Base->camd.ActivateXmitFunc.h_Data = NULL;
179 #endif
182 /*** Allocate and init all cards *******************************************/
184 SB128Base->driverdatas = AllocVec( sizeof( *SB128Base->driverdatas ) *
185 SB128Base->cards_found,
186 MEMF_PUBLIC );
188 if( SB128Base->driverdatas == NULL )
190 Req( "Out of memory." );
191 return FALSE;
194 card_no = 0;
196 struct Node *scratchNode;
197 ForeachNodeSafe(&foundCards, devTmp, scratchNode)
199 Remove(devTmp);
201 dev = (struct PCIDevice *)devTmp->ln_Name;
202 D(bug("[SB128] %s: Preparing card #%d pci obj @ 0x%p\n", __PRETTY_FUNCTION__, card_no, dev));
203 SB128Base->driverdatas[ card_no ] = AllocDriverData( dev, AHIsubBase );
205 FreeVec(devTmp);
206 ++card_no;
209 D(bug("[SB128] %s: Done.\n", __PRETTY_FUNCTION__));
211 return TRUE;
215 /******************************************************************************
216 ** Custom driver clean-up *****************************************************
217 ******************************************************************************/
219 VOID
220 DriverCleanup( struct DriverBase* AHIsubBase )
222 struct SB128Base* SB128Base = (struct SB128Base*) AHIsubBase;
223 int i;
224 #if 0
225 if( SB128Base->camd.Semaphore.ss_Link.ln_Name != NULL )
227 ObtainSemaphore( &SB128Base->camd.Semaphore );
228 RemSemaphore( &SB128Base->camd.Semaphore );
229 ReleaseSemaphore( &SB128Base->camd.Semaphore );
231 #endif
233 for( i = 0; i < SB128Base->cards_found; ++i )
235 if (SB128Base->driverdatas)
237 pci_outl( 0, SB128_SCON, SB128Base->driverdatas[i] );
238 FreeDriverData( SB128Base->driverdatas[ i ], AHIsubBase );
242 if (SB128Base->driverdatas)
243 FreeVec( SB128Base->driverdatas );
245 /*if (TimerIO)
247 CloseDevice((struct IORequest *)TimerIO);
248 DeleteIORequest((struct IORequest *)TimerIO);
251 /*if (replymp)
252 DeletePort(replymp);*/
254 ahi_pci_exit();
256 #ifdef __AROS__
257 if (StdCBase)
258 CloseLibrary( StdCBase );
259 #endif
261 if (ExpansionBase)
262 CloseLibrary( (struct Library*) ExpansionBase );
264 if (UtilityBase)
265 CloseLibrary( (struct Library*) UtilityBase );
267 if (DOSBase)
268 CloseLibrary( (struct Library*) DOSBase );