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.
19 #include <aros/debug.h>
20 #define DebugPrintF bug
22 #include <exec/memory.h>
24 #include <proto/exec.h>
25 #include <proto/dos.h>
32 #include "pci_wrapper.h"
34 struct DosLibrary
* DOSBase
;
35 struct DriverBase
* AHIsubBase
;
36 struct Library
* ExpansionBase
= NULL
;
44 #define CARD_STRING "SB128"
45 #define MAX_DEVICE_VENDORS 512
47 struct VendorDevice
*vendor_device_list
= NULL
;
48 static int vendor_device_list_size
= 0;
50 /******************************************************************************
51 ** Custom driver init *********************************************************
52 ******************************************************************************/
55 DriverInit( struct DriverBase
* ahisubbase
)
57 struct SB128Base
* SB128Base
= (struct SB128Base
*) ahisubbase
;
58 struct PCIDevice
*dev
;
60 struct List foundCards
;
63 bug("[SB128]: %s()\n", __PRETTY_FUNCTION__
);
65 SB128Base
->cards_found
= 0;
66 SB128Base
->driverdatas
= 0;
67 AHIsubBase
= ahisubbase
;
71 DOSBase
= OpenLibrary( DOSNAME
, 37 );
75 Req( "Unable to open 'dos.library' version 37.\n" );
79 ExpansionBase
= OpenLibrary( "expansion.library", 1 );
80 if( ExpansionBase
== NULL
)
82 Req( "Unable to open 'expansion.library' version 1.\n" );
86 if (!ahi_pci_init(ahisubbase
))
91 InitSemaphore( &SB128Base
->semaphore
);
93 /*** Count cards ***********************************************************/
95 vendor_device_list
= (struct VendorDevice
*) AllocVec(sizeof(struct VendorDevice
) * MAX_DEVICE_VENDORS
, MEMF_PUBLIC
| MEMF_CLEAR
);
97 vendor_device_list
[0].vendor
= 0x1274;
98 vendor_device_list
[0].device
= 0x5000;
99 vendor_device_list_size
++;
101 vendor_device_list
[1].vendor
= 0x1274;
102 vendor_device_list
[1].device
= 0x1371;
103 vendor_device_list_size
++;
105 vendor_device_list
[2].vendor
= 0x1274;
106 vendor_device_list
[2].device
= 0x5880;
107 vendor_device_list_size
++;
109 vendor_device_list
[3].vendor
= 0x1102;
110 vendor_device_list
[3].device
= 0x8938;
111 vendor_device_list_size
++;
113 bug("vendor_device_list_size = %ld\n", vendor_device_list_size
);
115 SB128Base
->cards_found
= 0;
118 for (i
= 0; i
< vendor_device_list_size
; i
++)
120 dev
= ahi_pci_find_device(vendor_device_list
[i
].vendor
, vendor_device_list
[i
].device
, dev
);
124 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
);
125 ++SB128Base
->cards_found
;
127 devTmp
= AllocVec(sizeof(struct Node
), MEMF_CLEAR
);
128 devTmp
->ln_Name
= dev
;
129 AddTail(&foundCards
, devTmp
);
133 // Fail if no hardware is present (prevents the audio modes from being added to
134 // the database if the driver cannot be used).
136 if(SB128Base
->cards_found
== 0 )
138 DebugPrintF("No SB128 found! :-(\n");
139 #if defined(VERBOSE_REQ)
140 Req( "No card present.\n" );
145 /*** CAMD ******************************************************************/
147 InitSemaphore( &SB128Base
->camd
.Semaphore
);
148 SB128Base
->camd
.Semaphore
.ss_Link
.ln_Pri
= 0;
150 SB128Base
->camd
.Semaphore
.ss_Link
.ln_Name
= Card_CAMD_SEMAPHORE
;
151 AddSemaphore( &SB128Base
->camd
.Semaphore
);
153 SB128Base
->camd
.Cards
= SB128Base
->cards_found
;
154 SB128Base
->camd
.Version
= VERSION
;
155 SB128Base
->camd
.Revision
= REVISION
;
158 SB128Base
->camd
.OpenPortFunc
.h_Entry
= OpenCAMDPort
;
159 SB128Base
->camd
.OpenPortFunc
.h_SubEntry
= NULL
;
160 SB128Base
->camd
.OpenPortFunc
.h_Data
= NULL
;
162 SB128Base
->camd
.ClosePortFunc
.h_Entry
= (HOOKFUNC
) CloseCAMDPort
;
163 SB128Base
->camd
.ClosePortFunc
.h_SubEntry
= NULL
;
164 SB128Base
->camd
.ClosePortFunc
.h_Data
= NULL
;
166 SB128Base
->camd
.ActivateXmitFunc
.h_Entry
= (HOOKFUNC
) ActivateCAMDXmit
;
167 SB128Base
->camd
.ActivateXmitFunc
.h_SubEntry
= NULL
;
168 SB128Base
->camd
.ActivateXmitFunc
.h_Data
= NULL
;
172 /*** Allocate and init all cards *******************************************/
174 SB128Base
->driverdatas
= AllocVec( sizeof( *SB128Base
->driverdatas
) *
175 SB128Base
->cards_found
,
178 if( SB128Base
->driverdatas
== NULL
)
180 Req( "Out of memory." );
186 struct Node
*scratchNode
;
187 ForeachNodeSafe(&foundCards
, devTmp
, scratchNode
)
191 dev
= devTmp
->ln_Name
;
192 bug("[SB128] %s: Prepairing card #%d pci obj @ 0x%p\n", __PRETTY_FUNCTION__
, card_no
, dev
);
193 SB128Base
->driverdatas
[ card_no
] = AllocDriverData( dev
, AHIsubBase
);
199 bug("[SB128] %s: Done.\n", __PRETTY_FUNCTION__
);
206 /******************************************************************************
207 ** Custom driver clean-up *****************************************************
208 ******************************************************************************/
211 DriverCleanup( struct DriverBase
* AHIsubBase
)
213 struct SB128Base
* SB128Base
= (struct SB128Base
*) AHIsubBase
;
216 if( SB128Base
->camd
.Semaphore
.ss_Link
.ln_Name
!= NULL
)
218 ObtainSemaphore( &SB128Base
->camd
.Semaphore
);
219 RemSemaphore( &SB128Base
->camd
.Semaphore
);
220 ReleaseSemaphore( &SB128Base
->camd
.Semaphore
);
224 for( i
= 0; i
< SB128Base
->cards_found
; ++i
)
226 if (SB128Base
->driverdatas
)
228 pci_outl( 0, SB128_SCON
, SB128Base
->driverdatas
[i
] );
229 FreeDriverData( SB128Base
->driverdatas
[ i
], AHIsubBase
);
233 if (SB128Base
->driverdatas
)
234 FreeVec( SB128Base
->driverdatas
);
238 CloseDevice((struct IORequest *)TimerIO);
239 DeleteIORequest((struct IORequest *)TimerIO);
243 DeletePort(replymp);*/
248 CloseLibrary( (struct Library
*) ExpansionBase
);
251 CloseLibrary( (struct Library
*) UtilityBase
);
254 CloseLibrary( (struct Library
*) DOSBase
);