ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

main.cpp
Go to the documentation of this file.
00001 /*
00002     ReactOS Operating System
00003     Sound Blaster KS Driver
00004 
00005     AUTHORS:
00006         Andrew Greenwood
00007 
00008     NOTES:
00009         WaveTable is not supported.
00010 */
00011 
00012 #include <sb16.h>
00013 
00014 /* How many miniports do we support? */
00015 #define MAX_MINIPORTS 1
00016 
00017 
00018 typedef struct
00019 {
00020     PRESOURCELIST Wave;
00021     PRESOURCELIST WaveTable;
00022     PRESOURCELIST FmSynth;
00023     PRESOURCELIST Uart;
00024     PRESOURCELIST Adapter;
00025 } Resources;
00026 
00027 
00028 DWORD
00029 DetectPlatform(
00030     PPORTTOPOLOGY Port)
00031 {
00032     /* ASSERT(Port); */
00033 
00034 #if 0
00035     PPORTCLSVERSION portcls_version;
00036     PDRMPORT drm_port;
00037     PPORTEVENTS port_events;
00038     DWORD version;
00039 
00040 /*
00041     TODO: This stuff needs IID impls
00042 
00043     Port->QueryInterface( IID_IPortClsVersion, (PVOID*) &portcls_version);
00044     Port->QueryInterface( IID_IDrmPort, (PVOID*) &drm_port);
00045     Port->QueryInterface( IID_IPortEvents, (PVOID*) &port_events);
00046 */
00047 
00048     if ( portcls_version )
00049     {
00050         version = portcls_version->GetVersion();
00051         portcls_version->Release();
00052     }
00053 
00054     /* If we don't support portcls' GetVersion, we can try other methods */
00055     else if ( drm_port )
00056     {
00057         version = kVersionWinME;
00058         // ASSERT(IoIsWdmVersionAvailable(0x01, 0x05));
00059     }
00060 
00061     /* If portcls GetVersion and DRMPort not supported, it'll be Win98 */
00062     else if ( port_events )
00063     {
00064         version = kVersionWin98SE;
00065     }
00066 
00067     /* IPortEvents was added in Win 98 SE so if not supported, it's not 98 SE */
00068     else
00069     {
00070         version = kVersionWin98;
00071     }
00072 
00073     return version;
00074 #else
00075     return kVersionWin98;
00076 #endif
00077 }
00078 
00079 
00080 NTSTATUS
00081 DetectFeatures(
00082     IN  PRESOURCELIST ResourceList,
00083     OUT PBOOLEAN HasUart,
00084     OUT PBOOLEAN HasFmSynth,
00085     OUT PBOOLEAN HasWaveTable)
00086 {
00087     NTSTATUS status = STATUS_SUCCESS;
00088 
00089     BOOLEAN DetectedWaveTable = FALSE;
00090     BOOLEAN DetectedUart = FALSE;
00091     BOOLEAN DetectedFmSynth = FALSE;
00092 
00093     ULONG IoCount = ResourceList->NumberOfPorts();
00094     ULONG IrqCount = ResourceList->NumberOfInterrupts();
00095     ULONG DmaCount = ResourceList->NumberOfDmas();
00096 
00097     switch ( IoCount )
00098     {
00099         case 1 :    /* No FM / UART */
00100         {
00101             if ( ( ResourceList->FindTranslatedPort(0)->u.Port.Length < 16 ) ||
00102                  ( IrqCount < 1 ) ||
00103                  ( DmaCount < 1 ) )
00104             {
00105                 status = STATUS_DEVICE_CONFIGURATION_ERROR;
00106             }
00107 
00108             break;
00109         }
00110 
00111         case 2 :
00112         {
00113             if ( ( ResourceList->FindTranslatedPort(0)->u.Port.Length < 16 ) ||
00114                  ( IrqCount < 1 ) ||
00115                  ( DmaCount < 1 ) )
00116             {
00117                 status = STATUS_DEVICE_CONFIGURATION_ERROR;
00118             }
00119 
00120             else
00121             {
00122                 /* The length of the port indicates the function provided */
00123 
00124                 switch ( ResourceList->FindTranslatedPort(1)->u.Port.Length )
00125                 {
00126                     case 2 :
00127                     {
00128                         DetectedUart = TRUE;
00129                         break;
00130                     }
00131                     case 4:
00132                     {
00133                         DetectedFmSynth = TRUE;
00134                         break;
00135                     }
00136                     default :
00137                     {
00138                         status = STATUS_DEVICE_CONFIGURATION_ERROR;
00139                     }
00140                 }
00141             }
00142 
00143             break;
00144         }
00145 
00146         case 3 :
00147         {
00148             if ( ( ResourceList->FindTranslatedPort(0)->u.Port.Length < 16 ) ||
00149                  ( ResourceList->FindTranslatedPort(1)->u.Port.Length != 2 ) ||
00150                  ( ResourceList->FindTranslatedPort(2)->u.Port.Length != 4 ) ||
00151                  ( IrqCount < 1 ) ||
00152                  ( DmaCount < 1 ) )
00153             {
00154                 status = STATUS_DEVICE_CONFIGURATION_ERROR;
00155             }
00156             else
00157             {
00158                 DetectedUart = TRUE;
00159                 DetectedFmSynth = TRUE;
00160             }
00161 
00162             break;
00163         }
00164 
00165         default :
00166         {
00167             status = STATUS_DEVICE_CONFIGURATION_ERROR;
00168             break;
00169         }
00170     }
00171 
00172     if ( HasUart )
00173         *HasUart = DetectedUart;
00174     if ( HasFmSynth )
00175         *HasFmSynth = DetectedFmSynth;
00176     if ( HasWaveTable )
00177         *HasWaveTable = DetectedWaveTable;
00178 
00179     return status;
00180 }
00181 
00182 
00183 NTSTATUS
00184 AssignResources(
00185     IN  PRESOURCELIST ResourceList,
00186     OUT Resources* Resources)
00187 {
00188     NTSTATUS status;
00189     BOOLEAN HasUart, HasFmSynth, HasWaveTable;
00190 
00191     Resources->Adapter = NULL;
00192     Resources->Wave = NULL;
00193     Resources->Uart = NULL;
00194     Resources->FmSynth = NULL;
00195     Resources->WaveTable = NULL;
00196 
00197     status = DetectFeatures(ResourceList, &HasUart, &HasFmSynth, &HasWaveTable);
00198 
00199     if ( ! NT_SUCCESS(status) )
00200     {
00201         return status;
00202     }
00203 
00204     /* Wave I/O resources */
00205 
00206     status = PcNewResourceSublist(&Resources->Wave,
00207                                   NULL,
00208                                   PagedPool,
00209                                   ResourceList,
00210                                   ResourceList->NumberOfDmas() +
00211                                       ResourceList->NumberOfInterrupts() + 1);
00212 
00213     if ( NT_SUCCESS(status) )
00214     {
00215         ULONG i;
00216 
00217         /* Base port address */
00218         status = (*Resources->Wave).AddPortFromParent(ResourceList, 0);
00219 
00220         /* DMA channels */
00221         if ( NT_SUCCESS(status) )
00222         {
00223             for ( i = 0; i < ResourceList->NumberOfDmas(); i ++ )
00224             {
00225                 status = (*Resources->Wave).AddDmaFromParent(ResourceList, i);
00226 
00227                 if ( ! NT_SUCCESS(status) )
00228                     break;
00229             }
00230         }
00231 
00232         /* IRQs */
00233         if ( NT_SUCCESS(status) )
00234         {
00235             for ( i = 0; i < ResourceList->NumberOfInterrupts(); i ++ )
00236             {
00237                 status = (*Resources->Wave).AddInterruptFromParent(ResourceList, i);
00238 
00239                 if ( ! NT_SUCCESS(status) )
00240                     break;
00241             }
00242         }
00243     }
00244 
00245     /* UART resources */
00246 
00247     if ( NT_SUCCESS(status) && HasUart )
00248     {
00249         /* TODO */
00250     }
00251 
00252     /* FM Synth resources */
00253 
00254     if ( NT_SUCCESS(status) && HasFmSynth )
00255     {
00256         /* TODO */
00257     }
00258 
00259     /* Adapter resources */
00260 
00261     if ( NT_SUCCESS(status) )
00262     {
00263         status = PcNewResourceSublist(&Resources->Adapter,
00264                                       NULL,
00265                                       PagedPool,
00266                                       ResourceList,
00267                                       3);
00268 
00269         if ( NT_SUCCESS(status) )
00270         {
00271             status = (*Resources->Adapter).AddInterruptFromParent(ResourceList, 0);
00272         }
00273 
00274         if ( NT_SUCCESS(status) )
00275         {
00276             status = (*Resources->Adapter).AddPortFromParent(ResourceList, 0);
00277         }
00278 
00279         if ( NT_SUCCESS(status) && HasUart )
00280         {
00281             /* TODO */
00282         }
00283     }
00284 
00285     /* Cleanup - TODO: Make this cleanup UART, FM etc. */
00286 
00287     if ( ! NT_SUCCESS(status) )
00288     {
00289         if ( (*Resources).Wave != NULL )
00290         {
00291             (*Resources->Wave).Release();
00292             (*Resources).Wave = NULL;
00293         }
00294 
00295         if ( (*Resources).Adapter != NULL )
00296         {
00297             (*Resources->Adapter).Release();
00298             (*Resources).Adapter = NULL;
00299         }
00300     }
00301 
00302     return status;
00303 }
00304 
00305 
00306 NTSTATUS
00307 StartDevice(
00308     IN  PDEVICE_OBJECT DeviceObject,
00309     IN  PIRP Irp,
00310     IN  PRESOURCELIST ResourceList)
00311 {
00312     NTSTATUS status = STATUS_SUCCESS;
00313 
00314     Resources DeviceResources;
00315 
00316     PUNKNOWN UnknownTopology = NULL;
00317     PUNKNOWN UnknownWave = NULL;
00318     PUNKNOWN UnknownWaveTable = NULL;
00319     PUNKNOWN UnknownFmSynth = NULL;
00320 
00321 //    PADAPTERCOMMON AdapterCommon = NULL;
00322     PUNKNOWN UnknownCommon = NULL;
00323 
00324     status = AssignResources(ResourceList, &DeviceResources);
00325 
00326     if ( NT_SUCCESS(status) )
00327     {
00328     }
00329 
00330     return status;
00331 }
00332 
00333 extern "C"
00334 NTSTATUS
00335 AddDevice(
00336     IN  PDRIVER_OBJECT DriverObject,
00337     IN  PDEVICE_OBJECT PhysicalDeviceObject)
00338 {
00339     return PcAddAdapterDevice(DriverObject,
00340                               PhysicalDeviceObject,
00341                               StartDevice,
00342                               MAX_MINIPORTS,
00343                               0);
00344 }
00345 
00346 extern "C"
00347 NTSTATUS
00348 DriverEntry(
00349     IN  PDRIVER_OBJECT DriverObject,
00350     IN  PUNICODE_STRING RegistryPathName)
00351 {
00352     NTSTATUS status;
00353 
00354     status = PcInitializeAdapterDriver(DriverObject,
00355                                        RegistryPathName,
00356                                        (PDRIVER_ADD_DEVICE) AddDevice);
00357 
00358     /* TODO: Add our own IRP handlers here */
00359 
00360     return status;
00361 }
00362 

Generated on Sat May 26 2012 04:27:13 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.