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 <exec/memory.h>
20 #include <proto/exec.h>
21 #include <proto/dos.h>
23 #include <devices/timer.h>
26 #include <aros/debug.h>
27 #define DebugPrintF bug
34 #include "pci_wrapper.h"
36 struct DosLibrary
* DOSBase
;
37 struct DriverBase
* AHIsubBase
;
38 struct Library
* ExpansionBase
= NULL
;
46 #define CARD_STRING "SB128"
47 #define MAX_DEVICE_VENDORS 512
49 struct VendorDevice
*vendor_device_list
= NULL
;
50 static int vendor_device_list_size
= 0;
52 /******************************************************************************
53 ** Custom driver init *********************************************************
54 ******************************************************************************/
57 DriverInit( struct DriverBase
* ahisubbase
)
59 struct SB128Base
* SB128Base
= (struct SB128Base
*) ahisubbase
;
60 struct PCIDevice
*dev
;
62 struct List foundCards
;
65 bug("[SB128]: %s()\n", __PRETTY_FUNCTION__
);
67 SB128Base
->cards_found
= 0;
68 SB128Base
->driverdatas
= 0;
69 AHIsubBase
= ahisubbase
;
71 DOSBase
= OpenLibrary( DOSNAME
, 37 );
75 Req( "Unable to open 'dos.library' version 37.\n" );
79 ExpansionBase
= OpenLibrary( "expansion.library", 50 );
80 if( ExpansionBase
== NULL
)
82 Req( "Unable to open 'expansion.library' version 50.\n" );
86 if (!ahi_pci_init(ahisubbase
))
93 /* replymp = (struct MsgPort *) CreatePort(NULL, 0);
96 DebugPrintF("SB128: Couldn't create ReplyPort!\n");
100 /*TimerIO = (struct timerequest *)CreateIORequest(replymp, sizeof(struct timerequest));
104 DebugPrintF("Out of memory.\n");
108 if (OpenDevice("timer.device", UNIT_MICROHZ, (struct IORequest *)TimerIO, 0) != 0)
110 DebugPrintF("Unable to open 'timer.device'.\n");
114 TimerBase = (struct Device *)TimerIO->tr_node.io_Device;*/
116 InitSemaphore( &SB128Base
->semaphore
);
118 /*** Count cards ***********************************************************/
120 vendor_device_list
= (struct VendorDevice
*) AllocVec(sizeof(struct VendorDevice
) * MAX_DEVICE_VENDORS
, MEMF_PUBLIC
| MEMF_CLEAR
);
122 vendor_device_list
[0].vendor
= 0x1274;
123 vendor_device_list
[0].device
= 0x5000;
124 vendor_device_list_size
++;
126 vendor_device_list
[0].vendor
= 0x1274;
127 vendor_device_list
[0].device
= 0x1371;
128 vendor_device_list_size
++;
130 vendor_device_list
[0].vendor
= 0x1274;
131 vendor_device_list
[0].device
= 0x5880;
132 vendor_device_list_size
++;
134 vendor_device_list
[0].vendor
= 0x1102;
135 vendor_device_list
[0].device
= 0x8938;
136 vendor_device_list_size
++;
138 bug("vendor_device_list_size = %ld\n", vendor_device_list_size
);
140 SB128Base
->cards_found
= 0;
143 for (i
= 0; i
< vendor_device_list_size
; i
++)
145 dev
= ahi_pci_find_device(vendor_device_list
[i
].vendor
, vendor_device_list
[i
].device
, dev
);
149 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
);
150 ++SB128Base
->cards_found
;
152 devTmp
= AllocVec(sizeof(struct Node
), MEMF_CLEAR
);
153 devTmp
->ln_Name
= dev
;
154 AddTail(&foundCards
, devTmp
);
158 // Fail if no hardware is present (prevents the audio modes from being added to
159 // the database if the driver cannot be used).
161 if(SB128Base
->cards_found
== 0 )
163 DebugPrintF("No SB128 found! :-(\n");
164 Req( "No card present.\n" );
168 /*** CAMD ******************************************************************/
170 InitSemaphore( &SB128Base
->camd
.Semaphore
);
171 SB128Base
->camd
.Semaphore
.ss_Link
.ln_Pri
= 0;
173 SB128Base
->camd
.Semaphore
.ss_Link
.ln_Name
= Card_CAMD_SEMAPHORE
;
174 AddSemaphore( &SB128Base
->camd
.Semaphore
);
176 SB128Base
->camd
.Cards
= SB128Base
->cards_found
;
177 SB128Base
->camd
.Version
= VERSION
;
178 SB128Base
->camd
.Revision
= REVISION
;
181 SB128Base
->camd
.OpenPortFunc
.h_Entry
= OpenCAMDPort
;
182 SB128Base
->camd
.OpenPortFunc
.h_SubEntry
= NULL
;
183 SB128Base
->camd
.OpenPortFunc
.h_Data
= NULL
;
185 SB128Base
->camd
.ClosePortFunc
.h_Entry
= (HOOKFUNC
) CloseCAMDPort
;
186 SB128Base
->camd
.ClosePortFunc
.h_SubEntry
= NULL
;
187 SB128Base
->camd
.ClosePortFunc
.h_Data
= NULL
;
189 SB128Base
->camd
.ActivateXmitFunc
.h_Entry
= (HOOKFUNC
) ActivateCAMDXmit
;
190 SB128Base
->camd
.ActivateXmitFunc
.h_SubEntry
= NULL
;
191 SB128Base
->camd
.ActivateXmitFunc
.h_Data
= NULL
;
195 /*** Allocate and init all cards *******************************************/
197 SB128Base
->driverdatas
= AllocVec( sizeof( *SB128Base
->driverdatas
) *
198 SB128Base
->cards_found
,
201 if( SB128Base
->driverdatas
== NULL
)
203 Req( "Out of memory." );
209 struct Node
*scratchNode
;
210 ForeachNodeSafe(&foundCards
, devTmp
, scratchNode
)
214 dev
= devTmp
->ln_Name
;
215 bug("[SB128] %s: Prepairing card #%d pci obj @ 0x%p\n", __PRETTY_FUNCTION__
, card_no
, dev
);
216 SB128Base
->driverdatas
[ card_no
] = AllocDriverData( dev
, AHIsubBase
);
222 bug("[SB128] %s: Done.\n", __PRETTY_FUNCTION__
);
229 /******************************************************************************
230 ** Custom driver clean-up *****************************************************
231 ******************************************************************************/
234 DriverCleanup( struct DriverBase
* AHIsubBase
)
236 struct SB128Base
* SB128Base
= (struct SB128Base
*) AHIsubBase
;
239 if( SB128Base
->camd
.Semaphore
.ss_Link
.ln_Name
!= NULL
)
241 ObtainSemaphore( &SB128Base
->camd
.Semaphore
);
242 RemSemaphore( &SB128Base
->camd
.Semaphore
);
243 ReleaseSemaphore( &SB128Base
->camd
.Semaphore
);
247 for( i
= 0; i
< SB128Base
->cards_found
; ++i
)
249 if (SB128Base
->driverdatas
)
251 pci_outl( 0, SB128_SCON
, SB128Base
->driverdatas
[i
] );
252 FreeDriverData( SB128Base
->driverdatas
[ i
], AHIsubBase
);
256 if (SB128Base
->driverdatas
)
257 FreeVec( SB128Base
->driverdatas
);
261 CloseDevice((struct IORequest *)TimerIO);
262 DeleteIORequest((struct IORequest *)TimerIO);
266 DeletePort(replymp);*/
271 CloseLibrary( (struct Library
*) ExpansionBase
);
274 CloseLibrary( (struct Library
*) UtilityBase
);
277 CloseLibrary( (struct Library
*) DOSBase
);