2 Copyright © 2004-2014, Davy Wentzler. All rights reserved.
3 Copyright © 2010-2014, The AROS Development Team. All rights reserved.
7 #include <exec/memory.h>
11 #include <proto/expansion.h>
14 #include <proto/exec.h>
15 #include <proto/dos.h>
16 #include <clib/alib_protos.h>
22 #include "pci_wrapper.h"
24 struct DriverBase
* AHIsubBase
;
26 struct DosLibrary
* DOSBase
;
27 struct Library
* ExpansionBase
= NULL
;
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 ******************************************************************************/
48 DriverInit( struct DriverBase
* ahisubbase
)
50 struct CardBase
*CardBase
= (struct CardBase
*) ahisubbase
;
51 struct PCIDevice
*dev
;
53 struct List foundCards
;
56 DebugPrintF("[Envy24]: %s()\n", __PRETTY_FUNCTION__
);
58 CardBase
->driverdatas
= 0;
59 CardBase
->cards_found
= 0;
60 AHIsubBase
= ahisubbase
;
64 DOSBase
= (struct DosLibrary
*)OpenLibrary( DOSNAME
, 37 );
68 Req( "Envy24: Unable to open 'dos.library' version 37.\n" );
72 ExpansionBase
= OpenLibrary( "expansion.library", 1 );
73 if( ExpansionBase
== NULL
)
75 Req( "Envy24: Unable to open 'expansion.library' version 1.\n" );
79 if (!ahi_pci_init(ahisubbase
))
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;
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
);
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" );
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." );
140 struct Node
*scratchNode
;
141 ForeachNodeSafe(&foundCards
, devTmp
, scratchNode
)
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
);
153 DebugPrintF("[Envy24] %s: Done.\n", __PRETTY_FUNCTION__
);
159 /******************************************************************************
160 ** Custom driver clean-up *****************************************************
161 ******************************************************************************/
164 DriverCleanup( struct DriverBase
* AHIsubBase
)
166 struct CardBase
* CardBase
= (struct CardBase
*) AHIsubBase
;
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
);
181 CloseLibrary( (struct Library
*) ExpansionBase
);
184 CloseLibrary( (struct Library
*) UtilityBase
);
187 CloseLibrary( (struct Library
*) DOSBase
);