ReactOS  0.4.15-dev-1068-g467feb9
isapnp.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS ISA PnP Bus driver
3  * FILE: isapnp.c
4  * PURPOSE: Driver entry
5  * PROGRAMMERS: Cameron Gutman (cameron.gutman@reactos.org)
6  * HervĂ© Poussineau
7  */
8 
9 #include <isapnp.h>
10 
11 #define NDEBUG
12 #include <debug.h>
13 
15 NTAPI
17  IN ULONG Flags,
20 {
21  if (SourceString == NULL ||
26  Flags >= 4)
27  {
29  }
30 
31  if ((SourceString->Length == 0) &&
34  {
38  }
39  else
40  {
41  USHORT DestMaxLength = SourceString->Length;
42 
44  DestMaxLength += sizeof(UNICODE_NULL);
45 
48  return STATUS_NO_MEMORY;
49 
52  DestinationString->MaximumLength = DestMaxLength;
53 
56  }
57 
58  return STATUS_SUCCESS;
59 }
60 
61 static
63 NTAPI
66 {
67  PISAPNP_LOGICAL_DEVICE LogDev = PdoExt->IsaPnpDevice;
68  UNICODE_STRING TempString;
69  WCHAR TempBuffer[256];
70  PWCHAR End;
72  USHORT i;
73 
74  TempString.Buffer = TempBuffer;
75  TempString.MaximumLength = sizeof(TempBuffer);
76  TempString.Length = 0;
77 
78  /* Device ID */
79  Status = RtlStringCbPrintfExW(TempString.Buffer,
80  TempString.MaximumLength / sizeof(WCHAR),
81  &End,
82  NULL, 0,
83  L"ISAPNP\\%.3S%04x",
84  LogDev->VendorId,
85  LogDev->ProdId);
86  if (!NT_SUCCESS(Status))
87  return Status;
88  TempString.Length = (USHORT)((End - TempString.Buffer) * sizeof(WCHAR));
91  &TempString,
92  &PdoExt->DeviceID);
93  if (!NT_SUCCESS(Status))
94  return Status;
95 
96  /* HardwareIDs */
97  Status = RtlStringCbPrintfExW(TempString.Buffer,
98  TempString.MaximumLength / sizeof(WCHAR),
99  &End,
100  NULL, 0,
101  L"ISAPNP\\%.3S%04x@"
102  L"*%.3S%04x@",
103  LogDev->VendorId,
104  LogDev->ProdId,
105  LogDev->VendorId,
106  LogDev->ProdId);
107  if (!NT_SUCCESS(Status))
108  return Status;
109  TempString.Length = (USHORT)((End - TempString.Buffer) * sizeof(WCHAR));
112  &TempString,
113  &PdoExt->HardwareIDs);
114  if (!NT_SUCCESS(Status))
115  return Status;
116  for (i = 0; i < PdoExt->HardwareIDs.Length / sizeof(WCHAR); i++)
117  if (PdoExt->HardwareIDs.Buffer[i] == '@')
118  PdoExt->HardwareIDs.Buffer[i] = UNICODE_NULL;
119 
120  /* InstanceID */
121  Status = RtlStringCbPrintfExW(TempString.Buffer,
122  TempString.MaximumLength / sizeof(WCHAR),
123  &End,
124  NULL, 0,
125  L"%X",
126  LogDev->SerialNumber);
127  if (!NT_SUCCESS(Status))
128  return Status;
129  TempString.Length = (USHORT)((End - TempString.Buffer) * sizeof(WCHAR));
132  &TempString,
133  &PdoExt->InstanceID);
134  if (!NT_SUCCESS(Status))
135  return Status;
136 
137  return STATUS_SUCCESS;
138 }
139 
140 static
141 NTSTATUS
142 NTAPI
145 {
146  PISAPNP_LOGICAL_DEVICE LogDev = PdoExt->IsaPnpDevice;
147  RTL_BITMAP IrqBitmap[ARRAYSIZE(LogDev->Irq)];
148  RTL_BITMAP DmaBitmap[ARRAYSIZE(LogDev->Dma)];
149  ULONG IrqData[ARRAYSIZE(LogDev->Irq)];
150  ULONG DmaData[ARRAYSIZE(LogDev->Dma)];
151  ULONG ResourceCount = 0;
152  ULONG ListSize, i, j;
153  BOOLEAN FirstIrq = TRUE, FirstDma = TRUE;
154  PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList;
156 
157  /* Count number of requirements */
158  for (i = 0; i < ARRAYSIZE(LogDev->Io); i++)
159  {
160  if (!LogDev->Io[i].Description.Length)
161  break;
162  ResourceCount++;
163  }
164  for (i = 0; i < ARRAYSIZE(LogDev->Irq); i++)
165  {
166  if (!LogDev->Irq[i].Description.Mask)
167  break;
168  IrqData[i] = LogDev->Irq[i].Description.Mask;
169  RtlInitializeBitMap(&IrqBitmap[i], &IrqData[i], 16);
170  ResourceCount += RtlNumberOfSetBits(&IrqBitmap[i]);
171  if (LogDev->Irq[i].Description.Information & 0x4)
172  {
173  /* Add room for level sensitive */
174  ResourceCount += RtlNumberOfSetBits(&IrqBitmap[i]);
175  }
176  }
177  if (ResourceCount == 0)
178  return STATUS_SUCCESS;
179  for (i = 0; i < ARRAYSIZE(LogDev->Irq); i++)
180  {
181  if (!LogDev->Dma[i].Description.Mask)
182  break;
183  DmaData[i] = LogDev->Dma[i].Description.Mask;
184  RtlInitializeBitMap(&DmaBitmap[i], &DmaData[i], 8);
185  ResourceCount += RtlNumberOfSetBits(&DmaBitmap[i]);
186  }
187 
188  /* Allocate memory to store requirements */
189  ListSize = sizeof(IO_RESOURCE_REQUIREMENTS_LIST)
191  RequirementsList = ExAllocatePool(PagedPool, ListSize);
192  if (!RequirementsList)
193  return STATUS_NO_MEMORY;
194 
195  RtlZeroMemory(RequirementsList, ListSize);
196  RequirementsList->ListSize = ListSize;
197  RequirementsList->InterfaceType = Isa;
198  RequirementsList->AlternativeLists = 1;
199 
200  RequirementsList->List[0].Version = 1;
201  RequirementsList->List[0].Revision = 1;
202  RequirementsList->List[0].Count = ResourceCount;
203 
204  /* Store requirements */
205  Descriptor = RequirementsList->List[0].Descriptors;
206  for (i = 0; i < ARRAYSIZE(LogDev->Io); i++)
207  {
208  if (!LogDev->Io[i].Description.Length)
209  break;
210  DPRINT("Device.Io[%d].Information = 0x%02x\n", i, LogDev->Io[i].Description.Information);
211  DPRINT("Device.Io[%d].Minimum = 0x%02x\n", i, LogDev->Io[i].Description.Minimum);
212  DPRINT("Device.Io[%d].Maximum = 0x%02x\n", i, LogDev->Io[i].Description.Maximum);
213  DPRINT("Device.Io[%d].Alignment = 0x%02x\n", i, LogDev->Io[i].Description.Alignment);
214  DPRINT("Device.Io[%d].Length = 0x%02x\n", i, LogDev->Io[i].Description.Length);
216  Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
217  if (LogDev->Io[i].Description.Information & 0x1)
219  else
221  Descriptor->u.Port.Length = LogDev->Io[i].Description.Length;
222  Descriptor->u.Port.Alignment = LogDev->Io[i].Description.Alignment;
223  Descriptor->u.Port.MinimumAddress.LowPart = LogDev->Io[i].Description.Minimum;
224  Descriptor->u.Port.MaximumAddress.LowPart = LogDev->Io[i].Description.Maximum + LogDev->Io[i].Description.Length - 1;
225  Descriptor++;
226  }
227  for (i = 0; i < ARRAYSIZE(LogDev->Irq); i++)
228  {
229  if (!LogDev->Irq[i].Description.Mask)
230  break;
231  DPRINT("Device.Irq[%d].Mask = 0x%02x\n", i, LogDev->Irq[i].Description.Mask);
232  DPRINT("Device.Irq[%d].Information = 0x%02x\n", i, LogDev->Irq[i].Description.Information);
233  for (j = 0; j < 15; j++)
234  {
235  if (!RtlCheckBit(&IrqBitmap[i], j))
236  continue;
237  if (FirstIrq)
238  FirstIrq = FALSE;
239  else
243  Descriptor->u.Interrupt.MinimumVector = Descriptor->u.Interrupt.MaximumVector = j;
244  Descriptor++;
245  if (LogDev->Irq[i].Description.Information & 0x4)
246  {
247  /* Level interrupt */
251  Descriptor->u.Interrupt.MinimumVector = Descriptor->u.Interrupt.MaximumVector = j;
252  Descriptor++;
253  }
254  }
255  }
256  for (i = 0; i < ARRAYSIZE(LogDev->Dma); i++)
257  {
258  if (!LogDev->Dma[i].Description.Mask)
259  break;
260  DPRINT("Device.Dma[%d].Mask = 0x%02x\n", i, LogDev->Dma[i].Description.Mask);
261  DPRINT("Device.Dma[%d].Information = 0x%02x\n", i, LogDev->Dma[i].Description.Information);
262  for (j = 0; j < 8; j++)
263  {
264  if (!RtlCheckBit(&DmaBitmap[i], j))
265  continue;
266  if (FirstDma)
267  FirstDma = FALSE;
268  else
271  switch (LogDev->Dma[i].Description.Information & 0x3)
272  {
273  case 0x0: Descriptor->Flags |= CM_RESOURCE_DMA_8; break;
274  case 0x1: Descriptor->Flags |= CM_RESOURCE_DMA_8_AND_16; break;
275  case 0x2: Descriptor->Flags |= CM_RESOURCE_DMA_16; break;
276  default: break;
277  }
278  if (LogDev->Dma[i].Description.Information & 0x4)
280  switch ((LogDev->Dma[i].Description.Information >> 5) & 0x3)
281  {
282  case 0x1: Descriptor->Flags |= CM_RESOURCE_DMA_TYPE_A; break;
283  case 0x2: Descriptor->Flags |= CM_RESOURCE_DMA_TYPE_B; break;
284  case 0x3: Descriptor->Flags |= CM_RESOURCE_DMA_TYPE_F; break;
285  default: break;
286  }
287  Descriptor->u.Dma.MinimumChannel = Descriptor->u.Dma.MaximumChannel = j;
288  Descriptor++;
289  }
290  }
291 
292  PdoExt->RequirementsList = RequirementsList;
293  return STATUS_SUCCESS;
294 }
295 
296 static
297 NTSTATUS
298 NTAPI
301 {
302  PISAPNP_LOGICAL_DEVICE LogDev = PdoExt->IsaPnpDevice;
303  ULONG ResourceCount = 0;
304  ULONG ListSize, i;
307 
308  /* Count number of required resources */
309  for (i = 0; i < ARRAYSIZE(LogDev->Io); i++)
310  {
311  if (LogDev->Io[i].CurrentBase)
312  ResourceCount++;
313  else
314  break;
315  }
316  for (i = 0; i < ARRAYSIZE(LogDev->Irq); i++)
317  {
318  if (LogDev->Irq[i].CurrentNo)
319  ResourceCount++;
320  else
321  break;
322  }
323  for (i = 0; i < ARRAYSIZE(LogDev->Dma); i++)
324  {
325  if (LogDev->Dma[i].CurrentChannel != 4)
326  ResourceCount++;
327  else
328  break;
329  }
330  if (ResourceCount == 0)
331  return STATUS_SUCCESS;
332 
333  /* Allocate memory to store resources */
334  ListSize = sizeof(CM_RESOURCE_LIST)
337  if (!ResourceList)
338  return STATUS_NO_MEMORY;
339 
340  RtlZeroMemory(ResourceList, ListSize);
341  ResourceList->Count = 1;
342  ResourceList->List[0].InterfaceType = Isa;
343  ResourceList->List[0].PartialResourceList.Version = 1;
344  ResourceList->List[0].PartialResourceList.Revision = 1;
345  ResourceList->List[0].PartialResourceList.Count = ResourceCount;
346 
347  /* Store resources */
348  ResourceCount = 0;
349  for (i = 0; i < ARRAYSIZE(LogDev->Io); i++)
350  {
351  if (!LogDev->Io[i].CurrentBase)
352  continue;
353  Descriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[ResourceCount++];
355  Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
356  if (LogDev->Io[i].Description.Information & 0x1)
358  else
360  Descriptor->u.Port.Length = LogDev->Io[i].Description.Length;
361  Descriptor->u.Port.Start.LowPart = LogDev->Io[i].CurrentBase;
362  }
363  for (i = 0; i < ARRAYSIZE(LogDev->Irq); i++)
364  {
365  if (!LogDev->Irq[i].CurrentNo)
366  continue;
367  Descriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[ResourceCount++];
369  Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
370  if (LogDev->Irq[i].CurrentType & 0x01)
372  else
374  Descriptor->u.Interrupt.Level = LogDev->Irq[i].CurrentNo;
375  Descriptor->u.Interrupt.Vector = LogDev->Irq[i].CurrentNo;
376  Descriptor->u.Interrupt.Affinity = -1;
377  }
378  for (i = 0; i < ARRAYSIZE(LogDev->Dma); i++)
379  {
380  if (LogDev->Dma[i].CurrentChannel == 4)
381  continue;
382  Descriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[ResourceCount++];
384  Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
385  switch (LogDev->Dma[i].Description.Information & 0x3)
386  {
387  case 0x0: Descriptor->Flags |= CM_RESOURCE_DMA_8; break;
388  case 0x1: Descriptor->Flags |= CM_RESOURCE_DMA_8 | CM_RESOURCE_DMA_16; break;
389  case 0x2: Descriptor->Flags |= CM_RESOURCE_DMA_16; break;
390  default: break;
391  }
392  if (LogDev->Dma[i].Description.Information & 0x4)
394  switch ((LogDev->Dma[i].Description.Information >> 5) & 0x3)
395  {
396  case 0x1: Descriptor->Flags |= CM_RESOURCE_DMA_TYPE_A; break;
397  case 0x2: Descriptor->Flags |= CM_RESOURCE_DMA_TYPE_B; break;
398  case 0x3: Descriptor->Flags |= CM_RESOURCE_DMA_TYPE_F; break;
399  default: break;
400  }
401  Descriptor->u.Dma.Channel = LogDev->Dma[i].CurrentChannel;
402  }
403 
404  PdoExt->ResourceList = ResourceList;
405  PdoExt->ResourceListSize = ListSize;
406  return STATUS_SUCCESS;
407 }
408 
409 NTSTATUS
410 NTAPI
412  IN PISAPNP_FDO_EXTENSION FdoExt,
413  IN PIRP Irp,
414  IN BOOLEAN IncludeDataPort)
415 {
418  PLIST_ENTRY CurrentEntry;
419  PISAPNP_LOGICAL_DEVICE IsaDevice;
420  PDEVICE_RELATIONS DeviceRelations;
421  ULONG i = 0;
422 
423  DeviceRelations = ExAllocatePool(NonPagedPool,
424  sizeof(DEVICE_RELATIONS) + sizeof(DEVICE_OBJECT) * FdoExt->DeviceCount);
425  if (!DeviceRelations)
426  {
427  return STATUS_NO_MEMORY;
428  }
429 
430  if (IncludeDataPort)
431  {
432  DeviceRelations->Objects[i++] = FdoExt->DataPortPdo;
433  ObReferenceObject(FdoExt->DataPortPdo);
434  }
435 
436  CurrentEntry = FdoExt->DeviceListHead.Flink;
437  while (CurrentEntry != &FdoExt->DeviceListHead)
438  {
439  IsaDevice = CONTAINING_RECORD(CurrentEntry, ISAPNP_LOGICAL_DEVICE, ListEntry);
440 
441  if (!IsaDevice->Pdo)
442  {
443  Status = IoCreateDevice(FdoExt->DriverObject,
444  sizeof(ISAPNP_PDO_EXTENSION),
445  NULL,
448  FALSE,
449  &IsaDevice->Pdo);
450  if (!NT_SUCCESS(Status))
451  {
452  break;
453  }
454 
455  IsaDevice->Pdo->Flags &= ~DO_DEVICE_INITIALIZING;
456 
457  //Device->Pdo->Flags |= DO_POWER_PAGABLE;
458 
460 
462 
463  PdoExt->Common.IsFdo = FALSE;
464  PdoExt->Common.Self = IsaDevice->Pdo;
465  PdoExt->Common.State = dsStopped;
466  PdoExt->IsaPnpDevice = IsaDevice;
467  PdoExt->FdoExt = FdoExt;
468 
470 
471  if (NT_SUCCESS(Status))
473 
474  if (NT_SUCCESS(Status))
476 
477  if (!NT_SUCCESS(Status))
478  {
479  IoDeleteDevice(IsaDevice->Pdo);
480  IsaDevice->Pdo = NULL;
481  break;
482  }
483  }
484  DeviceRelations->Objects[i++] = IsaDevice->Pdo;
485 
486  ObReferenceObject(IsaDevice->Pdo);
487 
488  CurrentEntry = CurrentEntry->Flink;
489  }
490 
491  DeviceRelations->Count = i;
492 
493  Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
494 
495  return Status;
496 }
497 
498 
499 static IO_COMPLETION_ROUTINE ForwardIrpCompletion;
500 
501 static
502 NTSTATUS
503 NTAPI
506  IN PIRP Irp,
507  IN PVOID Context)
508 {
510 
511  if (Irp->PendingReturned)
513 
515 }
516 
517 NTSTATUS
518 NTAPI
520  IN PISAPNP_FDO_EXTENSION FdoExt,
521  IN PIRP Irp)
522 {
523  KEVENT Event;
525 
528 
530 
531  Status = IoCallDriver(FdoExt->Ldo, Irp);
532  if (Status == STATUS_PENDING)
533  {
535  if (NT_SUCCESS(Status))
536  Status = Irp->IoStatus.Status;
537  }
538 
539  return Status;
540 }
541 
543 
544 static
545 NTSTATUS
546 NTAPI
549  IN PIRP Irp)
550 {
551  Irp->IoStatus.Status = STATUS_SUCCESS;
552  Irp->IoStatus.Information = FILE_OPENED;
553 
554  DPRINT("%s(%p, %p)\n", __FUNCTION__, DeviceObject, Irp);
555 
557 
558  return STATUS_SUCCESS;
559 }
560 
562 
563 static
564 NTSTATUS
565 NTAPI
568  IN PIRP Irp)
569 {
572 
573  DPRINT("%s(%p, %p)\n", __FUNCTION__, DeviceObject, Irp);
574 
575  switch (IrpSp->Parameters.DeviceIoControl.IoControlCode)
576  {
577  default:
578  DPRINT1("Unknown ioctl code: %x\n", IrpSp->Parameters.DeviceIoControl.IoControlCode);
580  break;
581  }
582 
583  Irp->IoStatus.Status = Status;
585 
586  return Status;
587 }
588 
590 
591 static
592 NTSTATUS
593 NTAPI
596  IN PIRP Irp)
597 {
598  DPRINT("%s(%p, %p)\n", __FUNCTION__, DeviceObject, Irp);
599 
600  Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
601  Irp->IoStatus.Information = 0;
602 
604 
605  return STATUS_NOT_SUPPORTED;
606 }
607 
608 static
609 NTSTATUS
610 NTAPI
613 {
614  USHORT Ports[] = { ISAPNP_WRITE_DATA, ISAPNP_ADDRESS, 0x274, 0x3e4, 0x204, 0x2e4, 0x354, 0x2f4 };
615  ULONG ListSize, i;
616  PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList;
618 
619  ListSize = sizeof(IO_RESOURCE_REQUIREMENTS_LIST)
620  + 2 * ARRAYSIZE(Ports) * sizeof(IO_RESOURCE_DESCRIPTOR);
621  RequirementsList = ExAllocatePool(PagedPool, ListSize);
622  if (!RequirementsList)
623  return STATUS_NO_MEMORY;
624 
625  RtlZeroMemory(RequirementsList, ListSize);
626  RequirementsList->ListSize = ListSize;
627  RequirementsList->AlternativeLists = 1;
628 
629  RequirementsList->List[0].Version = 1;
630  RequirementsList->List[0].Revision = 1;
631  RequirementsList->List[0].Count = 2 * ARRAYSIZE(Ports);
632 
633  for (i = 0; i < 2 * ARRAYSIZE(Ports); i += 2)
634  {
635  Descriptor = &RequirementsList->List[0].Descriptors[i];
636 
637  /* Expected port */
638  Descriptor[0].Type = CmResourceTypePort;
639  Descriptor[0].ShareDisposition = CmResourceShareDeviceExclusive;
641  Descriptor[0].u.Port.Length = Ports[i / 2] & 1 ? 0x01 : 0x04;
642  Descriptor[0].u.Port.Alignment = 0x01;
643  Descriptor[0].u.Port.MinimumAddress.LowPart = Ports[i / 2];
644  Descriptor[0].u.Port.MaximumAddress.LowPart = Ports[i / 2] + Descriptor[0].u.Port.Length - 1;
645 
646  /* ... but mark it as optional */
648  Descriptor[1].Type = CmResourceTypePort;
649  Descriptor[1].ShareDisposition = CmResourceShareDeviceExclusive;
651  Descriptor[1].u.Port.Alignment = 0x01;
652  }
653 
654  PdoExt->RequirementsList = RequirementsList;
655  return STATUS_SUCCESS;
656 }
657 
658 static
659 NTSTATUS
660 NTAPI
663 {
665  ULONG ListSize, i;
668 
669  ListSize = sizeof(CM_RESOURCE_LIST)
672  if (!ResourceList)
673  return STATUS_NO_MEMORY;
674 
675  RtlZeroMemory(ResourceList, ListSize);
676  ResourceList->Count = 1;
677  ResourceList->List[0].InterfaceType = Internal;
678  ResourceList->List[0].PartialResourceList.Version = 1;
679  ResourceList->List[0].PartialResourceList.Revision = 1;
680  ResourceList->List[0].PartialResourceList.Count = 2;
681 
682  for (i = 0; i < ARRAYSIZE(Ports); i++)
683  {
684  Descriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[i];
686  Descriptor->ShareDisposition = CmResourceShareDeviceExclusive;
688  Descriptor->u.Port.Length = 0x01;
689  Descriptor->u.Port.Start.LowPart = Ports[i];
690  }
691 
692  PdoExt->ResourceList = ResourceList;
693  PdoExt->ResourceListSize = ListSize;
694  return STATUS_SUCCESS;
695 }
696 
697 static
698 NTSTATUS
699 NTAPI
701 {
702  UNICODE_STRING DeviceID = RTL_CONSTANT_STRING(L"ISAPNP\\ReadDataPort\0");
703  UNICODE_STRING HardwareIDs = RTL_CONSTANT_STRING(L"ISAPNP\\ReadDataPort\0\0");
704  UNICODE_STRING CompatibleIDs = RTL_CONSTANT_STRING(L"\0\0");
705  UNICODE_STRING InstanceID = RTL_CONSTANT_STRING(L"0\0");
707 
710  sizeof(ISAPNP_PDO_EXTENSION),
711  NULL,
714  FALSE,
715  &FdoExt->DataPortPdo);
716  if (!NT_SUCCESS(Status))
717  return Status;
720  PdoExt->Common.IsFdo = FALSE;
721  PdoExt->Common.Self = FdoExt->DataPortPdo;
722  PdoExt->Common.State = dsStopped;
723  PdoExt->FdoExt = FdoExt;
724 
726  &DeviceID,
727  &PdoExt->DeviceID);
728  if (!NT_SUCCESS(Status))
729  return Status;
730 
732  &HardwareIDs,
733  &PdoExt->HardwareIDs);
734  if (!NT_SUCCESS(Status))
735  return Status;
736 
738  &CompatibleIDs,
739  &PdoExt->CompatibleIDs);
740  if (!NT_SUCCESS(Status))
741  return Status;
742 
744  &InstanceID,
745  &PdoExt->InstanceID);
746  if (!NT_SUCCESS(Status))
747  return Status;
748 
750  if (!NT_SUCCESS(Status))
751  return Status;
752 
754  if (!NT_SUCCESS(Status))
755  return Status;
756 
757  return Status;
758 }
759 
760 static
761 NTSTATUS
762 NTAPI
766 {
767  PDEVICE_OBJECT Fdo;
768  PISAPNP_FDO_EXTENSION FdoExt;
770 
772 
774  sizeof(*FdoExt),
775  NULL,
778  TRUE,
779  &Fdo);
780  if (!NT_SUCCESS(Status))
781  {
782  DPRINT1("Failed to create FDO (0x%x)\n", Status);
783  return Status;
784  }
785 
786  FdoExt = Fdo->DeviceExtension;
787  RtlZeroMemory(FdoExt, sizeof(*FdoExt));
788 
789  FdoExt->Common.Self = Fdo;
790  FdoExt->Common.IsFdo = TRUE;
791  FdoExt->Common.State = dsStopped;
792  FdoExt->DriverObject = DriverObject;
793  FdoExt->Pdo = PhysicalDeviceObject;
794  FdoExt->Ldo = IoAttachDeviceToDeviceStack(Fdo,
796 
798  KeInitializeSpinLock(&FdoExt->Lock);
799 
800  Status = IsaPnpCreateReadPortDO(FdoExt);
801  if (!NT_SUCCESS(Status))
802  return Status;
803 
804  Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
806 
807  return STATUS_SUCCESS;
808 }
809 
811 NTSTATUS
812 NTAPI
815  IN PIRP Irp)
816 {
817  PISAPNP_COMMON_EXTENSION DevExt = DeviceObject->DeviceExtension;
819 
820  if (!DevExt->IsFdo)
821  {
822  Status = Irp->IoStatus.Status;
824  return Status;
825  }
826 
829  return PoCallDriver(((PISAPNP_FDO_EXTENSION)DevExt)->Ldo, Irp);
830 }
831 
833 
834 static
835 NTSTATUS
836 NTAPI
839  IN PIRP Irp)
840 {
842  PISAPNP_COMMON_EXTENSION DevExt = DeviceObject->DeviceExtension;
843 
844  DPRINT("%s(%p, %p)\n", __FUNCTION__, DeviceObject, Irp);
845 
846  if (DevExt->IsFdo)
847  {
848  return IsaFdoPnp((PISAPNP_FDO_EXTENSION)DevExt,
849  Irp,
850  IrpSp);
851  }
852  else
853  {
854  return IsaPdoPnp((PISAPNP_PDO_EXTENSION)DevExt,
855  Irp,
856  IrpSp);
857  }
858 }
859 
860 NTSTATUS
861 NTAPI
865 {
866  DPRINT("%s(%p, %wZ)\n", __FUNCTION__, DriverObject, RegistryPath);
867 
876 
877  return STATUS_SUCCESS;
878 }
879 
880 /* EOF */
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define CM_RESOURCE_DMA_16
Definition: cmtypes.h:132
struct _IO_RESOURCE_REQUIREMENTS_LIST IO_RESOURCE_REQUIREMENTS_LIST
#define IN
Definition: typedefs.h:39
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
PDEVICE_OBJECT DataPortPdo
Definition: isapnp.h:59
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
UCHAR CurrentNo
Definition: isapnp.h:25
ISAPNP_IO_DESCRIPTION Description
Definition: isapnp.h:21
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2143
NTSTATUS NTAPI IsaPnpFillDeviceRelations(IN PISAPNP_FDO_EXTENSION FdoExt, IN PIRP Irp, IN BOOLEAN IncludeDataPort)
Definition: isapnp.c:411
LIST_ENTRY DeviceListHead
Definition: isapnp.h:60
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG x1
Definition: winddi.h:3706
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
_In_ USHORT DeviceID
Definition: iotypes.h:875
NTSYSAPI void WINAPI RtlInitializeBitMap(PRTL_BITMAP, PULONG, ULONG)
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_OPENED
Definition: nt_native.h:769
PUSBHUB_PORT_PDO_EXTENSION NTAPI PdoExt(IN PDEVICE_OBJECT DeviceObject)
Definition: usbhub.c:133
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
unsigned short Length
Definition: sprintf.c:451
NTSTRSAFEVAPI RtlStringCbPrintfExW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _Outptr_opt_result_bytebuffer_(*pcbRemaining) NTSTRSAFE_PWSTR *ppszDestEnd, _Out_opt_ size_t *pcbRemaining, _In_ STRSAFE_DWORD dwFlags, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1335
#define RtlCheckBit(BMH, BP)
Definition: rtlfuncs.h:3154
UCHAR CurrentType
Definition: isapnp.h:26
ISAPNP_IO Io[8]
Definition: isapnp.h:41
uint16_t * PWCHAR
Definition: typedefs.h:56
#define CM_RESOURCE_DMA_TYPE_F
Definition: cmtypes.h:138
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1155
PDEVICE_OBJECT Pdo
Definition: isapnp.h:58
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
static DRIVER_DISPATCH IsaReadWrite
Definition: isapnp.c:589
#define CM_RESOURCE_DMA_TYPE_A
Definition: cmtypes.h:136
const MUI_LANGUAGE_RESOURCE ResourceList[]
Definition: muilanguages.h:414
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR CM_PARTIAL_RESOURCE_DESCRIPTOR
#define CmResourceTypePort
Definition: hwresource.cpp:123
static NTSTATUS NTAPI IsaFdoCreateRequirements(IN PISAPNP_PDO_EXTENSION PdoExt)
Definition: isapnp.c:143
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
static NTSTATUS NTAPI IsaAddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
Definition: isapnp.c:763
DRIVER_DISPATCH IsaPower
Definition: isapnp.c:810
FORCEINLINE VOID IoCopyCurrentIrpStackLocationToNext(_Inout_ PIRP Irp)
Definition: iofuncs.h:2864
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
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
void * Buffer
Definition: sprintf.c:453
static NTSTATUS NTAPI IsaFdoCreateResources(IN PISAPNP_PDO_EXTENSION PdoExt)
Definition: isapnp.c:299
ISAPNP_DMA_DESCRIPTION Description
Definition: isapnp.h:32
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FILE_DEVICE_CONTROLLER
Definition: winioctl.h:109
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
NTSTATUS NTAPI IsaPdoPnp(IN PISAPNP_PDO_EXTENSION PdoDeviceExtension, IN PIRP Irp, IN PIO_STACK_LOCATION IrpSp)
Definition: pdo.c:298
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2262
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
COMMON_DEVICE_EXTENSION Common
Definition: usbhub.h:204
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
NTSYSAPI ULONG WINAPI RtlNumberOfSetBits(PCRTL_BITMAP)
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
#define CM_RESOURCE_DMA_8_AND_16
Definition: cmtypes.h:134
_Out_ _Inout_ POEM_STRING DestinationString
Definition: rtlfuncs.h:1868
smooth NULL
Definition: ftsmooth.c:416
#define CM_RESOURCE_PORT_16_BIT_DECODE
Definition: cmtypes.h:112
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define ISAPNP_ADDRESS
Definition: isapnphw.h:7
ISAPNP_DEVICE_STATE State
Definition: isapnp.h:52
NTSTATUS NTAPI IsaForwardIrpSynchronous(IN PISAPNP_FDO_EXTENSION FdoExt, IN PIRP Irp)
Definition: isapnp.c:519
UCHAR CurrentChannel
Definition: isapnp.h:31
PDEVICE_OBJECT Pdo
Definition: isapnp.h:36
#define CM_RESOURCE_PORT_10_BIT_DECODE
Definition: cmtypes.h:110
#define FILE_AUTOGENERATED_DEVICE_NAME
Definition: iotypes.h:138
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
UCHAR VendorId[3]
Definition: isapnp.h:38
KSPIN_LOCK Lock
Definition: isapnp.h:64
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 GLint GLint j
Definition: glfuncs.h:250
struct _IO_RESOURCE_DESCRIPTOR IO_RESOURCE_DESCRIPTOR
static DRIVER_DISPATCH IsaPnp
Definition: isapnp.c:832
IO_RESOURCE_DESCRIPTOR Descriptors[1]
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
Definition: isapnp.h:82
_In_z_ PWSTR RegistryPath
Definition: classp.h:1930
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
USHORT CurrentBase
Definition: isapnp.h:20
ISAPNP_COMMON_EXTENSION Common
Definition: isapnp.h:56
static NTSTATUS NTAPI IsaFdoCreateDeviceIDs(IN PISAPNP_PDO_EXTENSION PdoExt)
Definition: isapnp.c:64
static NTSTATUS NTAPI IsaPnpCreateReadPortDO(PISAPNP_FDO_EXTENSION FdoExt)
Definition: isapnp.c:700
#define IO_RESOURCE_ALTERNATIVE
static PS2_PORT Ports[PS2_PORTS]
Definition: ps2.c:52
#define CM_RESOURCE_DMA_TYPE_B
Definition: cmtypes.h:137
static NTSTATUS NTAPI IsaPnpCreateReadPortDOResources(IN PISAPNP_PDO_EXTENSION PdoExt)
Definition: isapnp.c:661
static ULONG ResourceCount
Definition: inbv.c:92
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
Status
Definition: gdiplustypes.h:24
_Out_ _Inout_ POEM_STRING _In_ PCUNICODE_STRING SourceString
Definition: rtlfuncs.h:1868
static const WCHAR L[]
Definition: oid.c:1250
#define CM_RESOURCE_DMA_8
Definition: cmtypes.h:131
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
static IO_COMPLETION_ROUTINE ForwardIrpCompletion
Definition: isapnp.c:499
ISAPNP_IRQ_DESCRIPTION Description
Definition: isapnp.h:27
Definition: typedefs.h:119
static NTSTATUS NTAPI IsaPnpCreateReadPortDORequirements(IN PISAPNP_PDO_EXTENSION PdoExt)
Definition: isapnp.c:611
DRIVER_DISPATCH(nfs41_FsdDispatch)
struct _CM_RESOURCE_LIST CM_RESOURCE_LIST
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
PDRIVER_ADD_DEVICE AddDevice
Definition: iotypes.h:2200
ISAPNP_DMA Dma[2]
Definition: isapnp.h:43
#define RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING
Definition: isapnp.h:83
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:737
PDRIVER_OBJECT DriverObject
Definition: isapnp.h:62
NTSTATUS NTAPI DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
Definition: isapnp.c:862
unsigned short USHORT
Definition: pedump.c:61
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE
Definition: cmtypes.h:143
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define CmResourceTypeInterrupt
Definition: hwresource.cpp:124
#define DPRINT1
Definition: precomp.h:8
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define OUT
Definition: typedefs.h:40
#define ObReferenceObject
Definition: obfuncs.h:204
#define CM_RESOURCE_INTERRUPT_LATCHED
Definition: cmtypes.h:144
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2269
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:581
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define ULONG_PTR
Definition: config.h:101
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
static DRIVER_DISPATCH IsaIoctl
Definition: isapnp.c:561
PDEVICE_OBJECT Ldo
Definition: isapnp.h:57
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
#define ISAPNP_WRITE_DATA
Definition: isapnphw.h:8
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define FILE_DEVICE_BUS_EXTENDER
Definition: winioctl.h:147
unsigned short MaximumLength
Definition: sprintf.c:452
#define __FUNCTION__
Definition: types.h:112
PDEVICE_OBJECT Self
Definition: isapnp.h:50
#define CM_RESOURCE_DMA_BUS_MASTER
Definition: cmtypes.h:135
NTSTATUS NTAPI IsaFdoPnp(IN PISAPNP_FDO_EXTENSION FdoExt, IN PIRP Irp, IN PIO_STACK_LOCATION IrpSp)
Definition: fdo.c:44
#define CmResourceTypeDma
Definition: hwresource.cpp:126
NTSTATUS NTAPI IsaPnpDuplicateUnicodeString(IN ULONG Flags, IN PCUNICODE_STRING SourceString, OUT PUNICODE_STRING DestinationString)
Definition: isapnp.c:16
static DRIVER_DISPATCH IsaCreateClose
Definition: isapnp.c:542
struct _ISAPNP_PDO_EXTENSION * PISAPNP_PDO_EXTENSION
_In_ PSTORAGE_PROPERTY_ID _Outptr_ PVOID * Descriptor
Definition: classpnp.h:1159
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
ISAPNP_IRQ Irq[2]
Definition: isapnp.h:42