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.
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>
30 #include "pci_wrapper.h"
32 struct DosLibrary
* DOSBase
;
33 struct DriverBase
* AHIsubBase
;
34 struct Library
* ExpansionBase
= NULL
;
36 struct Library
*StdCBase
= NULL
;
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 ******************************************************************************/
56 DriverInit( struct DriverBase
* ahisubbase
)
58 struct SB128Base
* SB128Base
= (struct SB128Base
*) ahisubbase
;
59 struct PCIDevice
*dev
;
61 struct List foundCards
;
64 D(bug("[SB128]: %s()\n", __PRETTY_FUNCTION__
));
66 SB128Base
->cards_found
= 0;
67 SB128Base
->driverdatas
= 0;
68 AHIsubBase
= ahisubbase
;
72 DOSBase
= (struct DosLibrary
*)OpenLibrary( DOSNAME
, 37 );
76 Req( "Unable to open 'dos.library' version 37.\n" );
80 ExpansionBase
= OpenLibrary( "expansion.library", 1 );
81 if( ExpansionBase
== NULL
)
83 Req( "Unable to open 'expansion.library' version 1.\n" );
88 StdCBase
= OpenLibrary( "stdc.library", 0 );
91 Req( "Unable to open 'stdc.library'.\n" );
96 if (!ahi_pci_init(ahisubbase
))
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;
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
);
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" );
155 /*** CAMD ******************************************************************/
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
;
182 /*** Allocate and init all cards *******************************************/
184 SB128Base
->driverdatas
= AllocVec( sizeof( *SB128Base
->driverdatas
) *
185 SB128Base
->cards_found
,
188 if( SB128Base
->driverdatas
== NULL
)
190 Req( "Out of memory." );
196 struct Node
*scratchNode
;
197 ForeachNodeSafe(&foundCards
, devTmp
, scratchNode
)
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
);
209 D(bug("[SB128] %s: Done.\n", __PRETTY_FUNCTION__
));
215 /******************************************************************************
216 ** Custom driver clean-up *****************************************************
217 ******************************************************************************/
220 DriverCleanup( struct DriverBase
* AHIsubBase
)
222 struct SB128Base
* SB128Base
= (struct SB128Base
*) AHIsubBase
;
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
);
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
);
247 CloseDevice((struct IORequest *)TimerIO);
248 DeleteIORequest((struct IORequest *)TimerIO);
252 DeletePort(replymp);*/
258 CloseLibrary( StdCBase
);
262 CloseLibrary( (struct Library
*) ExpansionBase
);
265 CloseLibrary( (struct Library
*) UtilityBase
);
268 CloseLibrary( (struct Library
*) DOSBase
);