ReactOS  0.4.13-dev-99-g7e18b6d
main.cpp
Go to the documentation of this file.
1 /*
2  ReactOS Operating System
3  Sound Blaster KS Driver
4 
5  AUTHORS:
6  Andrew Greenwood
7 
8  NOTES:
9  WaveTable is not supported.
10 */
11 
12 #include <sb16.h>
13 
14 /* How many miniports do we support? */
15 #define MAX_MINIPORTS 1
16 
17 
18 typedef struct
19 {
25 } Resources;
26 
27 
28 DWORD
31 {
32  /* ASSERT(Port); */
33 
34 #if 0
35  PPORTCLSVERSION portcls_version;
36  PDRMPORT drm_port;
37  PPORTEVENTS port_events;
38  DWORD version;
39 
40 /*
41  TODO: This stuff needs IID impls
42 
43  Port->QueryInterface( IID_IPortClsVersion, (PVOID*) &portcls_version);
44  Port->QueryInterface( IID_IDrmPort, (PVOID*) &drm_port);
45  Port->QueryInterface( IID_IPortEvents, (PVOID*) &port_events);
46 */
47 
48  if ( portcls_version )
49  {
50  version = portcls_version->GetVersion();
51  portcls_version->Release();
52  }
53 
54  /* If we don't support portcls' GetVersion, we can try other methods */
55  else if ( drm_port )
56  {
58  // ASSERT(IoIsWdmVersionAvailable(0x01, 0x05));
59  }
60 
61  /* If portcls GetVersion and DRMPort not supported, it'll be Win98 */
62  else if ( port_events )
63  {
65  }
66 
67  /* IPortEvents was added in Win 98 SE so if not supported, it's not 98 SE */
68  else
69  {
71  }
72 
73  return version;
74 #else
75  return kVersionWin98;
76 #endif
77 }
78 
79 
83  OUT PBOOLEAN HasUart,
84  OUT PBOOLEAN HasFmSynth,
85  OUT PBOOLEAN HasWaveTable)
86 {
88 
89  BOOLEAN DetectedWaveTable = FALSE;
90  BOOLEAN DetectedUart = FALSE;
91  BOOLEAN DetectedFmSynth = FALSE;
92 
93  ULONG IoCount = ResourceList->NumberOfPorts();
94  ULONG IrqCount = ResourceList->NumberOfInterrupts();
95  ULONG DmaCount = ResourceList->NumberOfDmas();
96 
97  switch ( IoCount )
98  {
99  case 1 : /* No FM / UART */
100  {
101  if ( ( ResourceList->FindTranslatedPort(0)->u.Port.Length < 16 ) ||
102  ( IrqCount < 1 ) ||
103  ( DmaCount < 1 ) )
104  {
106  }
107 
108  break;
109  }
110 
111  case 2 :
112  {
113  if ( ( ResourceList->FindTranslatedPort(0)->u.Port.Length < 16 ) ||
114  ( IrqCount < 1 ) ||
115  ( DmaCount < 1 ) )
116  {
118  }
119 
120  else
121  {
122  /* The length of the port indicates the function provided */
123 
124  switch ( ResourceList->FindTranslatedPort(1)->u.Port.Length )
125  {
126  case 2 :
127  {
128  DetectedUart = TRUE;
129  break;
130  }
131  case 4:
132  {
133  DetectedFmSynth = TRUE;
134  break;
135  }
136  default :
137  {
139  }
140  }
141  }
142 
143  break;
144  }
145 
146  case 3 :
147  {
148  if ( ( ResourceList->FindTranslatedPort(0)->u.Port.Length < 16 ) ||
149  ( ResourceList->FindTranslatedPort(1)->u.Port.Length != 2 ) ||
150  ( ResourceList->FindTranslatedPort(2)->u.Port.Length != 4 ) ||
151  ( IrqCount < 1 ) ||
152  ( DmaCount < 1 ) )
153  {
155  }
156  else
157  {
158  DetectedUart = TRUE;
159  DetectedFmSynth = TRUE;
160  }
161 
162  break;
163  }
164 
165  default :
166  {
168  break;
169  }
170  }
171 
172  if ( HasUart )
173  *HasUart = DetectedUart;
174  if ( HasFmSynth )
175  *HasFmSynth = DetectedFmSynth;
176  if ( HasWaveTable )
177  *HasWaveTable = DetectedWaveTable;
178 
179  return status;
180 }
181 
182 
183 NTSTATUS
187 {
189  BOOLEAN HasUart, HasFmSynth, HasWaveTable;
190 
192  Resources->Wave = NULL;
193  Resources->Uart = NULL;
196 
197  status = DetectFeatures(ResourceList, &HasUart, &HasFmSynth, &HasWaveTable);
198 
199  if ( ! NT_SUCCESS(status) )
200  {
201  return status;
202  }
203 
204  /* Wave I/O resources */
205 
207  NULL,
208  PagedPool,
209  ResourceList,
210  ResourceList->NumberOfDmas() +
211  ResourceList->NumberOfInterrupts() + 1);
212 
213  if ( NT_SUCCESS(status) )
214  {
215  ULONG i;
216 
217  /* Base port address */
219 
220  /* DMA channels */
221  if ( NT_SUCCESS(status) )
222  {
223  for ( i = 0; i < ResourceList->NumberOfDmas(); i ++ )
224  {
226 
227  if ( ! NT_SUCCESS(status) )
228  break;
229  }
230  }
231 
232  /* IRQs */
233  if ( NT_SUCCESS(status) )
234  {
235  for ( i = 0; i < ResourceList->NumberOfInterrupts(); i ++ )
236  {
238 
239  if ( ! NT_SUCCESS(status) )
240  break;
241  }
242  }
243  }
244 
245  /* UART resources */
246 
247  if ( NT_SUCCESS(status) && HasUart )
248  {
249  /* TODO */
250  }
251 
252  /* FM Synth resources */
253 
254  if ( NT_SUCCESS(status) && HasFmSynth )
255  {
256  /* TODO */
257  }
258 
259  /* Adapter resources */
260 
261  if ( NT_SUCCESS(status) )
262  {
264  NULL,
265  PagedPool,
266  ResourceList,
267  3);
268 
269  if ( NT_SUCCESS(status) )
270  {
272  }
273 
274  if ( NT_SUCCESS(status) )
275  {
277  }
278 
279  if ( NT_SUCCESS(status) && HasUart )
280  {
281  /* TODO */
282  }
283  }
284 
285  /* Cleanup - TODO: Make this cleanup UART, FM etc. */
286 
287  if ( ! NT_SUCCESS(status) )
288  {
289  if ( (*Resources).Wave != NULL )
290  {
291  (*Resources->Wave).Release();
292  (*Resources).Wave = NULL;
293  }
294 
295  if ( (*Resources).Adapter != NULL )
296  {
297  (*Resources->Adapter).Release();
298  (*Resources).Adapter = NULL;
299  }
300  }
301 
302  return status;
303 }
304 
305 
306 NTSTATUS
309  IN PIRP Irp,
311 {
313 
314  Resources DeviceResources;
315 
316  PUNKNOWN UnknownTopology = NULL;
317  PUNKNOWN UnknownWave = NULL;
318  PUNKNOWN UnknownWaveTable = NULL;
319  PUNKNOWN UnknownFmSynth = NULL;
320 
321 // PADAPTERCOMMON AdapterCommon = NULL;
322  PUNKNOWN UnknownCommon = NULL;
323 
324  status = AssignResources(ResourceList, &DeviceResources);
325 
326  if ( NT_SUCCESS(status) )
327  {
328  }
329 
330  return status;
331 }
332 
333 extern "C"
334 NTSTATUS
338 {
341  StartDevice,
343  0);
344 }
345 
346 extern "C"
347 NTSTATUS
350  IN PUNICODE_STRING RegistryPathName)
351 {
353 
355  RegistryPathName,
357 
358  /* TODO: Add our own IRP handlers here */
359 
360  return status;
361 }
362 
IPortEvents * PPORTEVENTS
Definition: portcls.h:2065
CPPORT Port[4]
Definition: headless.c:34
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
PRESOURCELIST Adapter
Definition: main.cpp:24
IPortTopology * PPORTTOPOLOGY
Definition: portcls.h:1403
_In_ BOOLEAN Release
Definition: classpnp.h:929
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS AssignResources(IN PRESOURCELIST ResourceList, OUT Resources *Resources)
Definition: main.cpp:184
_Must_inspect_result_ _Out_ PULONG IoCount
Definition: ndis.h:6108
const MUI_LANGUAGE_RESOURCE ResourceList[]
Definition: muilanguages.h:414
DWORD DetectPlatform(PPORTTOPOLOGY Port)
Definition: main.cpp:29
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define AddInterruptFromParent(p, n)
Definition: portcls.h:465
unsigned char BOOLEAN
NTSTATUS NTAPI PcAddAdapterDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject, IN PCPFNSTARTDEVICE StartDevice, IN ULONG MaxObjects, IN ULONG DeviceExtensionSize)
Definition: adapter.cpp:76
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR version[]
Definition: asmname.c:64
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
PRESOURCELIST Wave
Definition: main.cpp:20
NTSTATUS DetectFeatures(IN PRESOURCELIST ResourceList, OUT PBOOLEAN HasUart, OUT PBOOLEAN HasFmSynth, OUT PBOOLEAN HasWaveTable)
Definition: main.cpp:81
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
IDrmPort * PDRMPORT
Definition: portcls.h:2120
unsigned long DWORD
Definition: ntddk_ex.h:95
NTSTATUS StartDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PRESOURCELIST ResourceList)
Definition: main.cpp:307
char * PBOOLEAN
Definition: retypes.h:11
NTSTATUS NTAPI PcInitializeAdapterDriver(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPathName, IN PDRIVER_ADD_DEVICE AddDevice)
Definition: adapter.cpp:32
PRESOURCELIST WaveTable
Definition: main.cpp:21
#define MAX_MINIPORTS
Definition: main.cpp:15
IResourceList * PRESOURCELIST
Definition: portcls.h:442
PRESOURCELIST Uart
Definition: main.cpp:23
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PRESOURCELIST FmSynth
Definition: main.cpp:22
DRIVER_ADD_DEVICE * PDRIVER_ADD_DEVICE
Definition: iotypes.h:2107
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPathName)
Definition: main.cpp:348
#define AddPortFromParent(p, n)
Definition: portcls.h:453
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
#define AddDmaFromParent(p, n)
Definition: portcls.h:489
NTSTATUS AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
Definition: main.cpp:335
#define STATUS_DEVICE_CONFIGURATION_ERROR
Definition: ntstatus.h:605
return STATUS_SUCCESS
Definition: btrfs.c:2725
static SERVICE_STATUS status
Definition: service.c:31
PORTCLASSAPI NTSTATUS NTAPI PcNewResourceSublist(OUT PRESOURCELIST *OutResourceList, IN PUNKNOWN OuterUnknown OPTIONAL, IN POOL_TYPE PoolType, IN PRESOURCELIST ParentList, IN ULONG MaximumEntries)
Definition: resource.cpp:410
Definition: ps.c:97
IPortClsVersion * PPORTCLSVERSION
Definition: portcls.h:2209