ReactOS  0.4.14-dev-297-g23e575c
adapter.cpp File Reference
#include "adapter.hpp"
Include dependency graph for adapter.cpp:

Go to the source code of this file.

Macros

#define PUT_GUIDS_HERE
 

Functions

static NTSTATUS InstallSubdevice (PDEVICE_OBJECT DeviceObject, PIRP Irp, PWCHAR Name, REFGUID PortClassId, REFGUID MiniportClassId, PFNCREATEINSTANCE MiniportCreate, PUNKNOWN UnknownAdapter, PRESOURCELIST ResourceList, REFGUID PortInterfaceId, PUNKNOWN *OutPortUnknown)
 
static NTSTATUS ProcessResources (PRESOURCELIST ResourceList, PRESOURCELIST *UartResourceList)
 
NTSTATUS NTAPI StartDevice (PDEVICE_OBJECT DeviceObject, PIRP Irp, PRESOURCELIST ResourceList)
 
NTSTATUS NTAPI AddDevice (PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject)
 
static bool CopyResourceDescriptor (PIO_RESOURCE_DESCRIPTOR pInResDescriptor, PIO_RESOURCE_DESCRIPTOR pOutResDescriptor)
 
NTSTATUS NTAPI AdapterDispatchPnp (PDEVICE_OBJECT pDeviceObject, PIRP pIrp)
 
NTSTATUS NTAPI DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPathName)
 
int __cdecl _purecall (void)
 

Macro Definition Documentation

◆ PUT_GUIDS_HERE

#define PUT_GUIDS_HERE

Definition at line 28 of file adapter.cpp.

Function Documentation

◆ _purecall()

int __cdecl _purecall ( void  )

Definition at line 429 of file adapter.cpp.

430 {
431  return 0;
432 }

◆ AdapterDispatchPnp()

NTSTATUS NTAPI AdapterDispatchPnp ( PDEVICE_OBJECT  pDeviceObject,
PIRP  pIrp 
)

Definition at line 312 of file adapter.cpp.

313 {
314  PAGED_CODE();
316  ASSERT(pIrp);
317  DBGPRINT(("AdapterDispatchPnp()"));
318 
319  NTSTATUS ntStatus = STATUS_SUCCESS;
320  ULONG resourceListSize;
321  PIO_RESOURCE_REQUIREMENTS_LIST resourceList, list;
322  PIO_RESOURCE_DESCRIPTOR descriptor;
324 
326  DBGPRINT(("[AdapterDispatchPnp] - IRP_MN_FILTER_RESOURCE_REQUIREMENTS"));
327 
328  list = (PIO_RESOURCE_REQUIREMENTS_LIST)pIrp->IoStatus.Information;
329 
330  // IO_RESOURCE_REQUIREMENTS_LIST has 1 IO_RESOURCE_LIST, IO_RESOURCE_LIST has 1 IO_RESOURCE_DESCRIPTOR and we want 2 more
331  resourceListSize = sizeof(IO_RESOURCE_REQUIREMENTS_LIST) + sizeof(IO_RESOURCE_DESCRIPTOR)*(list->List[0].Count+2) ;
332  resourceList = (PIO_RESOURCE_REQUIREMENTS_LIST)ExAllocatePoolWithTag(PagedPool, resourceListSize, 'LRDV');
333 
334  if (!resourceList) {
336  return ntStatus;
337  }
338 
339 
340  RtlZeroMemory(resourceList, resourceListSize);
341 
342  // initialize the list header
343  resourceList->AlternativeLists = 1; // number of IO_RESOURCE_LISTs
344  resourceList->ListSize = resourceListSize;
345 
346  resourceList->List[0].Version = 1;
347  resourceList->List[0].Revision = 1;
348  resourceList->List[0].Count = 0;
349 
350  // copy the resources which have already been assigned
351  for (unsigned int i=0;i<list->List[0].Count;i++) {
352  if (CopyResourceDescriptor(&list->List[0].Descriptors[i], &resourceList->List[0].Descriptors[resourceList->List[0].Count])) {
353  resourceList->List[0].Count++;
354  }
355  }
356  ExFreePool(list);
357 
358  // an additional port for mpu401
359  resourceList->List[0].Count++;
360  descriptor = &resourceList->List[0].Descriptors[resourceList->List[0].Count-1];
361  descriptor->Option = IO_RESOURCE_PREFERRED;
362  descriptor->Type = CmResourceTypePort;
364  descriptor->Flags = CM_RESOURCE_PORT_IO;
365  descriptor->u.Port.MinimumAddress.LowPart = 0x300;
366  descriptor->u.Port.MinimumAddress.HighPart = 0;
367  descriptor->u.Port.MaximumAddress.LowPart = 0x330;
368  descriptor->u.Port.MaximumAddress.HighPart = 0;
369  descriptor->u.Port.Length = 2;
370  descriptor->u.Port.Alignment = 0x10;
371 
372  // mpu401 port should be optional. yes, this is severely braindamaged.
373  resourceList->List[0].Count++;
374  descriptor = &resourceList->List[0].Descriptors[resourceList->List[0].Count-1];
375  descriptor->Option = IO_RESOURCE_ALTERNATIVE;
376  descriptor->Type = CmResourceTypePort;
378  descriptor->Flags = CM_RESOURCE_PORT_IO;
379  descriptor->u.Port.MinimumAddress.LowPart = 0x0;
380  descriptor->u.Port.MinimumAddress.HighPart = 0;
381  descriptor->u.Port.MaximumAddress.LowPart = 0xFFFF;
382  descriptor->u.Port.MaximumAddress.HighPart = 0;
383  descriptor->u.Port.Length = 1;
384  descriptor->u.Port.Alignment = 0x10;
385 
386  DBGPRINT(("number of resource list descriptors: %d", resourceList->List[0].Count));
387 
388  pIrp->IoStatus.Information = (ULONG_PTR)resourceList;
389 
390  // set the return status
391  pIrp->IoStatus.Status = ntStatus;
392  }
393 
394  // Pass the IRPs on to PortCls
395  ntStatus = PcDispatchIrp(pDeviceObject, pIrp);
396 
397  return ntStatus;
398 }
_In_ PNDIS_STRING _In_ PNDIS_STRING _Out_ PDEVICE_OBJECT * pDeviceObject
Definition: ndis.h:4679
#define DBGPRINT(...)
Definition: pdo.c:21
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define IRP_MN_FILTER_RESOURCE_REQUIREMENTS
LONG NTSTATUS
Definition: precomp.h:26
#define CmResourceTypePort
Definition: hwresource.cpp:123
#define PAGED_CODE()
Definition: video.h:57
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 IO_RESOURCE_ALTERNATIVE
struct _IO_RESOURCE_DESCRIPTOR::@1986::@1987 Port
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
IO_RESOURCE_LIST List[1]
Definition: iotypes.h:2393
IO_RESOURCE_DESCRIPTOR Descriptors[1]
Definition: iotypes.h:2383
Definition: _list.h:228
struct _IO_RESOURCE_DESCRIPTOR IO_RESOURCE_DESCRIPTOR
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define CM_RESOURCE_PORT_IO
Definition: cmtypes.h:109
struct _IO_RESOURCE_REQUIREMENTS_LIST * PIO_RESOURCE_REQUIREMENTS_LIST
static bool CopyResourceDescriptor(PIO_RESOURCE_DESCRIPTOR pInResDescriptor, PIO_RESOURCE_DESCRIPTOR pOutResDescriptor)
Definition: adapter.cpp:269
#define list
Definition: rosglue.h:35
union _IO_RESOURCE_DESCRIPTOR::@1986 u
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ULONG_PTR
Definition: config.h:101
NTSTATUS NTAPI PcDispatchIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.cpp:433
#define IO_RESOURCE_PREFERRED
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by DriverEntry().

◆ AddDevice()

NTSTATUS NTAPI AddDevice ( PDRIVER_OBJECT  DriverObject,
PDEVICE_OBJECT  PhysicalDeviceObject 
)

Definition at line 259 of file adapter.cpp.

260 {
261  PAGED_CODE();
262  DBGPRINT(("AddDevice()"));
263 
265 }
#define DBGPRINT(...)
Definition: pdo.c:21
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1114
#define PAGED_CODE()
Definition: video.h:57
NTSTATUS NTAPI PcAddAdapterDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject, IN PCPFNSTARTDEVICE StartDevice, IN ULONG MaxObjects, IN ULONG DeviceExtensionSize)
Definition: adapter.cpp:76
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
const ULONG MAX_MINIPORTS
Definition: adapter.hpp:38
NTSTATUS NTAPI StartDevice(PDEVICE_OBJECT DeviceObject, PIRP Irp, PRESOURCELIST ResourceList)
Definition: adapter.cpp:115

Referenced by DriverEntry(), and PcInitializeAdapterDriver().

◆ CopyResourceDescriptor()

static bool CopyResourceDescriptor ( PIO_RESOURCE_DESCRIPTOR  pInResDescriptor,
PIO_RESOURCE_DESCRIPTOR  pOutResDescriptor 
)
static

Definition at line 269 of file adapter.cpp.

270 {
271  PAGED_CODE();
272  ASSERT(pInResDescriptor);
273  ASSERT(pOutResDescriptor);
274  DBGPRINT(("CopyResourceDescriptor()"));
275 
276 #if 0
277  RtlCopyMemory(pOutResDescriptor, pInResDescriptor, sizeof(IO_RESOURCE_DESCRIPTOR));
278 #else
279  pOutResDescriptor->Type = pInResDescriptor->Type;
280  pOutResDescriptor->ShareDisposition = pInResDescriptor->ShareDisposition;
281  pOutResDescriptor->Flags = pInResDescriptor->Flags;
282  pOutResDescriptor->Option = pInResDescriptor->Option;
283 
284  switch (pInResDescriptor->Type) {
285  case CmResourceTypePort:
287 /* // filter crap
288  if ((pInResDescriptor->u.Port.Length == 0) ||
289  ( (pInResDescriptor->u.Port.MinimumAddress.HighPart == pInResDescriptor->u.Port.MaximumAddress.HighPart) && (pInResDescriptor->u.Port.MinimumAddress.LowPart == pInResDescriptor->u.Port.MaximumAddress.LowPart) ) ) {
290  return FALSE;
291  }
292 */ pOutResDescriptor->u.Port.MinimumAddress = pInResDescriptor->u.Port.MinimumAddress;
293  pOutResDescriptor->u.Port.MaximumAddress = pInResDescriptor->u.Port.MaximumAddress;
294  pOutResDescriptor->u.Port.Length = pInResDescriptor->u.Port.Length;
295  pOutResDescriptor->u.Port.Alignment = pInResDescriptor->u.Port.Alignment;
296  DBGPRINT((" Port: min %08x.%08x max %08x.%08x, Length: %x, Option: %x", pOutResDescriptor->u.Port.MinimumAddress.HighPart, pOutResDescriptor->u.Port.MinimumAddress.LowPart,
297  pOutResDescriptor->u.Port.MaximumAddress.HighPart, pOutResDescriptor->u.Port.MaximumAddress.LowPart,
298  pOutResDescriptor->u.Port.Length, pOutResDescriptor->Option));
299  break;
301  pOutResDescriptor->u.Interrupt.MinimumVector = pInResDescriptor->u.Interrupt.MinimumVector;
302  pOutResDescriptor->u.Interrupt.MaximumVector = pInResDescriptor->u.Interrupt.MaximumVector;
303  DBGPRINT((" IRQ: min %x max %x, Option: %d", pOutResDescriptor->u.Interrupt.MinimumVector, pOutResDescriptor->u.Interrupt.MaximumVector, pOutResDescriptor->Option));
304  break;
305  default:
306  return FALSE;
307  }
308  return TRUE;
309 #endif
310 }
#define DBGPRINT(...)
Definition: pdo.c:21
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define CmResourceTypePort
Definition: hwresource.cpp:123
#define PAGED_CODE()
Definition: video.h:57
struct _IO_RESOURCE_DESCRIPTOR::@1986::@1989 Interrupt
struct _IO_RESOURCE_DESCRIPTOR::@1986::@1987 Port
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define CmResourceTypeInterrupt
Definition: hwresource.cpp:124
union _IO_RESOURCE_DESCRIPTOR::@1986 u
#define CmResourceTypeNonArbitrated
Definition: hwresource.cpp:129

Referenced by AdapterDispatchPnp().

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( PDRIVER_OBJECT  DriverObject,
PUNICODE_STRING  RegistryPathName 
)

Definition at line 403 of file adapter.cpp.

404 {
405  PAGED_CODE();
406  DBGPRINT(("DriverEntry()"));
407 
408  NTSTATUS ntStatus;
409 
410  //bind the adapter driver to the portclass driver
411  ntStatus = PcInitializeAdapterDriver(DriverObject, RegistryPathName, AddDevice);
412 #ifdef UART
413  if(NT_SUCCESS(ntStatus)) {
415  }
416 #endif
417 #ifdef WAVERT
418  if (!IoIsWdmVersionAvailable(6,0)) {
419  ntStatus = STATUS_UNSUCCESSFUL;
420  }
421 #endif
422 
423  return ntStatus;
424 }
#define DBGPRINT(...)
Definition: pdo.c:21
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
#define PAGED_CODE()
Definition: video.h:57
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
NTSTATUS NTAPI PcInitializeAdapterDriver(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPathName, IN PDRIVER_ADD_DEVICE AddDevice)
Definition: adapter.cpp:32
NTSTATUS NTAPI AdapterDispatchPnp(PDEVICE_OBJECT pDeviceObject, PIRP pIrp)
Definition: adapter.cpp:312
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2181
NTSTATUS NTAPI AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject)
Definition: adapter.cpp:259
BOOLEAN NTAPI IoIsWdmVersionAvailable(IN UCHAR MajorVersion, IN UCHAR MinorVersion)
Definition: util.c:126

◆ InstallSubdevice()

static NTSTATUS InstallSubdevice ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PWCHAR  Name,
REFGUID  PortClassId,
REFGUID  MiniportClassId,
PFNCREATEINSTANCE  MiniportCreate,
PUNKNOWN  UnknownAdapter,
PRESOURCELIST  ResourceList,
REFGUID  PortInterfaceId,
PUNKNOWN OutPortUnknown 
)
static

Definition at line 38 of file adapter.cpp.

39 {
40  PAGED_CODE();
41  DBGPRINT(("InstallSubdevice()"));
42 
43  NTSTATUS ntStatus;
44  PPORT Port;
45  PMINIPORT MiniPort;
46 
47  ntStatus = PcNewPort(&Port, PortClassId);
48  if (NT_SUCCESS(ntStatus)) {
49  if (MiniportCreate) {
50  ntStatus = MiniportCreate((PUNKNOWN*)&MiniPort, MiniportClassId, NULL, NonPagedPool);
51  } else {
52  ntStatus = PcNewMiniport(&MiniPort, MiniportClassId);
53  }
54  }
55 
56  if (!NT_SUCCESS(ntStatus)) {
57  Port->Release();
58  return ntStatus;
59  }
60 
61  ntStatus = Port->Init(DeviceObject, Irp, MiniPort, UnknownAdapter, ResourceList);
62  if (NT_SUCCESS(ntStatus)) {
64 
65  if (OutPortUnknown && NT_SUCCESS (ntStatus)) {
66  ntStatus = Port->QueryInterface(IID_IUnknown, (PVOID *)OutPortUnknown);
67  }
68  }
69 
70  if (MiniPort) {
71  MiniPort->Release();
72  }
73 
74  if (Port) {
75  Port->Release();
76  }
77 
78  return ntStatus;
79 }
CPPORT Port[4]
Definition: headless.c:34
#define DBGPRINT(...)
Definition: pdo.c:21
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
const MUI_LANGUAGE_RESOURCE ResourceList[]
Definition: muilanguages.h:414
#define PAGED_CODE()
Definition: video.h:57
NTSTATUS NTAPI PcNewMiniport(OUT PMINIPORT *OutMiniport, IN REFCLSID ClassId)
Definition: miniport.cpp:48
IPort * PPORT
Definition: portcls.h:1093
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
const GUID IID_IUnknown
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
NTSTATUS NTAPI PcNewPort(OUT PPORT *OutPort, IN REFCLSID ClassId)
Definition: port.cpp:20
NTSTATUS NTAPI PcRegisterSubdevice(IN PDEVICE_OBJECT DeviceObject, IN PWCHAR Name, IN PUNKNOWN Unknown)
Definition: adapter.cpp:210

Referenced by StartDevice().

◆ ProcessResources()

static NTSTATUS ProcessResources ( PRESOURCELIST  ResourceList,
PRESOURCELIST UartResourceList 
)
static

Definition at line 83 of file adapter.cpp.

84 {
85  PAGED_CODE();
87  ASSERT(UartResourceList);
88  DBGPRINT(("ProcessResources()"));
89  DBGPRINT(("NumberOfPorts: %d, NumberOfInterrupts: %d, NumberOfDmas: %d", ResourceList->NumberOfPorts(), ResourceList->NumberOfInterrupts(), ResourceList->NumberOfDmas()));
90 #ifdef UART
91  NTSTATUS ntStatus;
92 
93  (*UartResourceList) = NULL;
94 #endif
95 
96  if ((ResourceList->NumberOfPorts() == 0) || (ResourceList->NumberOfPorts() > 2) || (ResourceList->NumberOfInterrupts() != 1) || (ResourceList->NumberOfDmas() != 0)) {
97  DBGPRINT(("Unexpected configuration"));
99  }
100 
101 #ifdef UART
102  ntStatus = PcNewResourceSublist(UartResourceList, NULL, PagedPool, ResourceList, 2);
103  if (NT_SUCCESS(ntStatus)) {
104  (*UartResourceList)->AddPortFromParent(ResourceList, 1);
105  (*UartResourceList)->AddInterruptFromParent(ResourceList, 0);
106  }
107 #endif
108 
109  return STATUS_SUCCESS;
110 }
#define DBGPRINT(...)
Definition: pdo.c:21
LONG NTSTATUS
Definition: precomp.h:26
const MUI_LANGUAGE_RESOURCE ResourceList[]
Definition: muilanguages.h:414
#define PAGED_CODE()
Definition: video.h:57
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_DEVICE_CONFIGURATION_ERROR
Definition: ntstatus.h:605
return STATUS_SUCCESS
Definition: btrfs.c:2966
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

Referenced by StartDevice().

◆ StartDevice()

NTSTATUS NTAPI StartDevice ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PRESOURCELIST  ResourceList 
)

Definition at line 115 of file adapter.cpp.

116 {
117  PAGED_CODE();
119  ASSERT(Irp);
121  DBGPRINT(("StartDevice()"));
122 
123  NTSTATUS ntStatus;
124  PPORT pPort = 0;
125 #ifdef UART
126  ULONG* MPUBase;
127 #endif
128 
129  ntStatus = PcNewPort(&pPort,CLSID_PortWaveCyclic);
130  if (NT_SUCCESS(ntStatus)) {
131  // not supported in the first edition of win98
132  PPORTEVENTS pPortEvents = 0;
133  ntStatus = pPort->QueryInterface(IID_IPortEvents, (PVOID *)&pPortEvents);
134  if (!NT_SUCCESS(ntStatus)) {
135  DBGPRINT(("ERROR: This driver doesn't work under Win98!"));
136  ntStatus = STATUS_UNSUCCESSFUL;
137  }
138  else
139  {
140  pPortEvents->Release();
141  }
142  pPort->Release ();
143  } else {
144  return ntStatus;
145  }
146 
147  // resource validation
148  PRESOURCELIST UartResourceList = NULL;
149  ntStatus = ProcessResources(ResourceList, &UartResourceList);
150  if (!NT_SUCCESS(ntStatus)) {
151  DBGPRINT(("ProcessResources() failed"));
152  return ntStatus;
153  }
154 
155  PCMIADAPTER pCMIAdapter = NULL;
156  PUNKNOWN pUnknownCommon = NULL;
157 
158  // create the CMIAdapter object
159  ntStatus = NewCMIAdapter(&pUnknownCommon, IID_ICMIAdapter, NULL, NonPagedPool);
160  if (!NT_SUCCESS(ntStatus)) {
161  DBGPRINT(("NewCMIAdapter() failed"));
162  return ntStatus;
163  }
164 
165  ntStatus = pUnknownCommon->QueryInterface(IID_ICMIAdapter, (PVOID *)&pCMIAdapter);
166  if (!NT_SUCCESS(ntStatus)) {
167  DBGPRINT(("QueryInterface() for ICMIAdapter failed"));
168  return ntStatus;
169  }
170  ntStatus = pCMIAdapter->init(ResourceList, DeviceObject);
171  if (!NT_SUCCESS(ntStatus)) {
172  DBGPRINT(("CMIAdapter->init() failed"));
173  return ntStatus;
174  }
175 
176  ntStatus = PcRegisterAdapterPowerManagement((PUNKNOWN)pCMIAdapter, DeviceObject);
177 
178  pUnknownCommon->Release();
179 
180  PUNKNOWN unknownWave = NULL;
181  PUNKNOWN unknownTopology = NULL;
182 
183  // install the topology miniport.
184  ntStatus = InstallSubdevice(DeviceObject, Irp, L"Topology", CLSID_PortTopology, CLSID_PortTopology, CreateMiniportTopologyCMI, pCMIAdapter, NULL, GUID_NULL, &unknownTopology);
185  if (!NT_SUCCESS (ntStatus)) {
186  DBGPRINT(("Topology miniport installation failed"));
187  return ntStatus;
188  }
189 
190 #ifdef UART
191  // install the UART miniport - execution order important
192  ntStatus = STATUS_UNSUCCESSFUL;
193  MPUBase = 0;
194  for (int i=0;i<ResourceList->NumberOfPorts();i++) {
195  if (ResourceList->FindTranslatedPort(i)->u.Port.Length == 2) {
196  MPUBase = (UInt32*)ResourceList->FindTranslatedPort(i)->u.Port.Start.QuadPart;
197  }
198  }
199  if (MPUBase != 0) {
200  ntStatus = pCMIAdapter->activateMPU(MPUBase);
201  if (NT_SUCCESS(ntStatus)) {
202  ntStatus = InstallSubdevice(DeviceObject, Irp, L"Uart", CLSID_PortDMus, CLSID_MiniportDriverDMusUART, NULL, pCMIAdapter->getInterruptSync(), UartResourceList, IID_IPortDMus, NULL);
203  }
204  }
205  if (!NT_SUCCESS(ntStatus)) {
206  MPUBase = 0;
207  pCMIAdapter->activateMPU(0);
208  DBGPRINT(("UART miniport installation failed"));
209  }
210  if (UartResourceList) {
211  UartResourceList->Release();
212  }
213 #endif
214 
215  // install the wave miniport - the order matters here
216 #ifdef WAVERT
217  ntStatus = InstallSubdevice(DeviceObject, Irp, L"Wave", CLSID_PortWaveRT, CLSID_PortWaveRT, CreateMiniportWaveCMI, pCMIAdapter, ResourceList, IID_IPortWaveRT, &unknownWave);
218 #else
219  ntStatus = InstallSubdevice(DeviceObject, Irp, L"Wave", CLSID_PortWaveCyclic, CLSID_PortWaveCyclic, CreateMiniportWaveCMI, pCMIAdapter, ResourceList, IID_IPortWaveCyclic, &unknownWave);
220 #endif
221  if (!NT_SUCCESS(ntStatus)) {
222  DBGPRINT(("Wave miniport installation failed"));
223  return ntStatus;
224  }
225 
226  // connect wave and topology pins
227  ntStatus = PcRegisterPhysicalConnection(DeviceObject, unknownWave, PIN_WAVE_RENDER_SOURCE, unknownTopology, PIN_WAVEOUT_SOURCE);
228  if (!NT_SUCCESS(ntStatus)) {
229  DBGPRINT(("Cannot connect topology and wave miniport (render)!"));
230  return ntStatus;
231  }
232  ntStatus = PcRegisterPhysicalConnection(DeviceObject, unknownTopology, PIN_WAVEIN_DEST, unknownWave, PIN_WAVE_CAPTURE_SOURCE);
233  if (!NT_SUCCESS(ntStatus)) {
234  DBGPRINT(("Cannot connect topology and wave miniport (capture)!"));
235  return ntStatus;
236  }
237  if (!IoIsWdmVersionAvailable(6,0)) {
238  // this shit fixes the fucking XP mixer and breaks the vista mixer, so we have to check for vista here
240  if (!NT_SUCCESS(ntStatus)) {
241  DBGPRINT(("Cannot connect topology and wave miniport (ac3)!"));
242  }
243  }
244 
245  // clean up
246  if (pCMIAdapter) {
247  pCMIAdapter->Release();
248  }
249  if (unknownTopology) {
250  unknownTopology->Release();
251  }
252  if (unknownWave) {
253  unknownWave->Release();
254  }
255 
256  return ntStatus;
257 }
NTSTATUS NewCMIAdapter(OUT PUNKNOWN *Unknown, IN REFCLSID, IN PUNKNOWN UnknownOuter OPTIONAL, IN POOL_TYPE PoolType)
IPortEvents * PPORTEVENTS
Definition: portcls.h:2065
#define DBGPRINT(...)
Definition: pdo.c:21
_In_ PIRP Irp
Definition: csq.h:116
DWORD UInt32
Definition: chm_lib.c:104
NTSTATUS NTAPI PcRegisterPhysicalConnection(IN PDEVICE_OBJECT DeviceObject, IN PUNKNOWN FromUnknown, IN ULONG FromPin, IN PUNKNOWN ToUnknown, IN ULONG ToPin)
Definition: connection.cpp:286
ICMIAdapter * PCMIADAPTER
Definition: interfaces.hpp:260
LONG NTSTATUS
Definition: precomp.h:26
const MUI_LANGUAGE_RESOURCE ResourceList[]
Definition: muilanguages.h:414
NTSTATUS NTAPI PcRegisterAdapterPowerManagement(IN PUNKNOWN pUnknown, IN PVOID pvContext)
Definition: power.cpp:19
#define PAGED_CODE()
Definition: video.h:57
static NTSTATUS ProcessResources(PRESOURCELIST ResourceList, PRESOURCELIST *UartResourceList)
Definition: adapter.cpp:83
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
ULONG Release()
IPort * PPORT
Definition: portcls.h:1093
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI CreateMiniportWaveCMI(OUT PUNKNOWN *Unknown, IN REFCLSID, IN PUNKNOWN UnknownOuter OPTIONAL, IN POOL_TYPE PoolType)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
nsrefcnt Release()
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
static const WCHAR L[]
Definition: oid.c:1250
NTSTATUS NTAPI CreateMiniportTopologyCMI(OUT PUNKNOWN *Unknown, IN REFCLSID, IN PUNKNOWN UnknownOuter OPTIONAL, IN POOL_TYPE PoolType)
static NTSTATUS InstallSubdevice(PDEVICE_OBJECT DeviceObject, PIRP Irp, PWCHAR Name, REFGUID PortClassId, REFGUID MiniportClassId, PFNCREATEINSTANCE MiniportCreate, PUNKNOWN UnknownAdapter, PRESOURCELIST ResourceList, REFGUID PortInterfaceId, PUNKNOWN *OutPortUnknown)
Definition: adapter.cpp:38
#define GUID_NULL
Definition: ks.h:106
IResourceList * PRESOURCELIST
Definition: portcls.h:442
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI PcNewPort(OUT PPORT *OutPort, IN REFCLSID ClassId)
Definition: port.cpp:20
BOOLEAN NTAPI IoIsWdmVersionAvailable(IN UCHAR MajorVersion, IN UCHAR MinorVersion)
Definition: util.c:126

Referenced by AddDevice(), and PcAddAdapterDevice().