Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenhalpnpdd.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS HAL 00003 * LICENSE: BSD - See COPYING.ARM in the top level directory 00004 * FILE: hal/halx86/generic/legacy/halpnpdd.c 00005 * PURPOSE: HAL Plug and Play Device Driver 00006 * PROGRAMMERS: ReactOS Portable Systems Group 00007 */ 00008 00009 /* INCLUDES *******************************************************************/ 00010 00011 #include <hal.h> 00012 #define NDEBUG 00013 #include <debug.h> 00014 00015 typedef enum _EXTENSION_TYPE 00016 { 00017 PdoExtensionType = 0xC0, 00018 FdoExtensionType 00019 } EXTENSION_TYPE; 00020 00021 typedef enum _PDO_TYPE 00022 { 00023 AcpiPdo = 0x80, 00024 WdPdo 00025 } PDO_TYPE; 00026 00027 typedef struct _FDO_EXTENSION 00028 { 00029 EXTENSION_TYPE ExtensionType; 00030 struct _PDO_EXTENSION* ChildPdoList; 00031 PDEVICE_OBJECT PhysicalDeviceObject; 00032 PDEVICE_OBJECT FunctionalDeviceObject; 00033 PDEVICE_OBJECT AttachedDeviceObject; 00034 } FDO_EXTENSION, *PFDO_EXTENSION; 00035 00036 typedef struct _PDO_EXTENSION 00037 { 00038 EXTENSION_TYPE ExtensionType; 00039 struct _PDO_EXTENSION* Next; 00040 PDEVICE_OBJECT PhysicalDeviceObject; 00041 PFDO_EXTENSION ParentFdoExtension; 00042 PDO_TYPE PdoType; 00043 PDESCRIPTION_HEADER WdTable; 00044 LONG InterfaceReferenceCount; 00045 } PDO_EXTENSION, *PPDO_EXTENSION; 00046 00047 /* GLOBALS ********************************************************************/ 00048 00049 PDRIVER_OBJECT HalpDriverObject; 00050 00051 /* PRIVATE FUNCTIONS **********************************************************/ 00052 00053 VOID 00054 NTAPI 00055 HalpReportDetectedDevices(IN PDRIVER_OBJECT DriverObject, 00056 IN PVOID Context, 00057 IN ULONG Count) 00058 { 00059 PFDO_EXTENSION FdoExtension = Context; 00060 PPDO_EXTENSION PdoExtension; 00061 PDEVICE_OBJECT PdoDeviceObject; 00062 NTSTATUS Status; 00063 00064 /* Create the PDO */ 00065 Status = IoCreateDevice(DriverObject, 00066 sizeof(PDO_EXTENSION), 00067 NULL, 00068 FILE_DEVICE_BUS_EXTENDER, 00069 FILE_AUTOGENERATED_DEVICE_NAME, 00070 FALSE, 00071 &PdoDeviceObject); 00072 if (!NT_SUCCESS(Status)) 00073 { 00074 /* Fail */ 00075 DPRINT1("HAL: Could not create ACPI device object status=0x%08x\n", Status); 00076 return; 00077 } 00078 00079 /* Setup the PDO device extension */ 00080 PdoExtension = PdoDeviceObject->DeviceExtension; 00081 PdoExtension->ExtensionType = PdoExtensionType; 00082 PdoExtension->PhysicalDeviceObject = PdoDeviceObject; 00083 PdoExtension->ParentFdoExtension = FdoExtension; 00084 PdoExtension->PdoType = AcpiPdo; 00085 00086 /* Add the PDO to the head of the list */ 00087 PdoExtension->Next = FdoExtension->ChildPdoList; 00088 FdoExtension->ChildPdoList = PdoExtension; 00089 00090 /* Initialization is finished */ 00091 PdoDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING; 00092 00093 /* Invalidate device relations since we added a new device */ 00094 IoSynchronousInvalidateDeviceRelations(FdoExtension->PhysicalDeviceObject, BusRelations); 00095 } 00096 00097 NTSTATUS 00098 NTAPI 00099 HalpAddDevice(IN PDRIVER_OBJECT DriverObject, 00100 IN PDEVICE_OBJECT TargetDevice) 00101 { 00102 NTSTATUS Status; 00103 PFDO_EXTENSION FdoExtension; 00104 PDEVICE_OBJECT DeviceObject, AttachedDevice; 00105 // PDESCRIPTION_HEADER Wdrt; 00106 00107 DPRINT("HAL: PnP Driver ADD!\n"); 00108 00109 /* Create the FDO */ 00110 Status = IoCreateDevice(DriverObject, 00111 sizeof(FDO_EXTENSION), 00112 NULL, 00113 FILE_DEVICE_BUS_EXTENDER, 00114 0, 00115 FALSE, 00116 &DeviceObject); 00117 if (!NT_SUCCESS(Status)) 00118 { 00119 /* Should not happen */ 00120 DbgBreakPoint(); 00121 return Status; 00122 } 00123 00124 /* Setup the FDO extension */ 00125 FdoExtension = DeviceObject->DeviceExtension; 00126 FdoExtension->ExtensionType = FdoExtensionType; 00127 FdoExtension->PhysicalDeviceObject = TargetDevice; 00128 FdoExtension->FunctionalDeviceObject = DeviceObject; 00129 FdoExtension->ChildPdoList = NULL; 00130 00131 /* FDO is done initializing */ 00132 DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING; 00133 00134 /* Attach to the physical device object (the bus) */ 00135 AttachedDevice = IoAttachDeviceToDeviceStack(DeviceObject, TargetDevice); 00136 if (!AttachedDevice) 00137 { 00138 /* Failed, undo everything */ 00139 IoDeleteDevice(DeviceObject); 00140 return STATUS_NO_SUCH_DEVICE; 00141 } 00142 00143 /* Save the attachment */ 00144 FdoExtension->AttachedDeviceObject = AttachedDevice; 00145 00146 /* Register for reinitialization to report devices later */ 00147 IoRegisterBootDriverReinitialization(DriverObject, 00148 HalpReportDetectedDevices, 00149 FdoExtension); 00150 00151 /* Return status */ 00152 DPRINT("Device added %lx\n", Status); 00153 return Status; 00154 } 00155 00156 NTSTATUS 00157 NTAPI 00158 HalpQueryInterface(IN PDEVICE_OBJECT DeviceObject, 00159 IN CONST GUID* InterfaceType, 00160 IN USHORT Version, 00161 IN PVOID InterfaceSpecificData, 00162 IN ULONG InterfaceBufferSize, 00163 IN PINTERFACE Interface, 00164 OUT PULONG Length) 00165 { 00166 UNIMPLEMENTED; 00167 return STATUS_NOT_SUPPORTED; 00168 } 00169 00170 NTSTATUS 00171 NTAPI 00172 HalpQueryDeviceRelations(IN PDEVICE_OBJECT DeviceObject, 00173 IN DEVICE_RELATION_TYPE RelationType, 00174 OUT PDEVICE_RELATIONS* DeviceRelations) 00175 { 00176 EXTENSION_TYPE ExtensionType; 00177 PPDO_EXTENSION PdoExtension; 00178 PFDO_EXTENSION FdoExtension; 00179 PDEVICE_RELATIONS PdoRelations, FdoRelations; 00180 PDEVICE_OBJECT* ObjectEntry; 00181 ULONG i = 0, PdoCount = 0; 00182 00183 /* Get FDO device extension and PDO count */ 00184 FdoExtension = DeviceObject->DeviceExtension; 00185 ExtensionType = FdoExtension->ExtensionType; 00186 00187 /* What do they want? */ 00188 if (RelationType == BusRelations) 00189 { 00190 /* This better be an FDO */ 00191 if (ExtensionType == FdoExtensionType) 00192 { 00193 /* Count how many PDOs we have */ 00194 PdoExtension = FdoExtension->ChildPdoList; 00195 while (PdoExtension) 00196 { 00197 /* Next one */ 00198 PdoExtension = PdoExtension->Next; 00199 PdoCount++; 00200 } 00201 00202 /* Add the PDOs that already exist in the device relations */ 00203 if (*DeviceRelations) 00204 { 00205 PdoCount += (*DeviceRelations)->Count; 00206 } 00207 00208 /* Allocate our structure */ 00209 FdoRelations = ExAllocatePoolWithTag(PagedPool, 00210 FIELD_OFFSET(DEVICE_RELATIONS, 00211 Objects) + 00212 sizeof(PDEVICE_OBJECT) * PdoCount, 00213 ' laH'); 00214 if (!FdoRelations) return STATUS_INSUFFICIENT_RESOURCES; 00215 00216 /* Save our count */ 00217 FdoRelations->Count = PdoCount; 00218 00219 /* Query existing relations */ 00220 ObjectEntry = FdoRelations->Objects; 00221 if (*DeviceRelations) 00222 { 00223 /* Check if there were any */ 00224 if ((*DeviceRelations)->Count) 00225 { 00226 /* Loop them all */ 00227 do 00228 { 00229 /* Copy into our structure */ 00230 *ObjectEntry++ = (*DeviceRelations)->Objects[i]; 00231 } 00232 while (++i < (*DeviceRelations)->Count); 00233 } 00234 00235 /* Free existing structure */ 00236 ExFreePool(*DeviceRelations); 00237 } 00238 00239 /* Now check if we have a PDO list */ 00240 PdoExtension = FdoExtension->ChildPdoList; 00241 if (PdoExtension) 00242 { 00243 /* Loop the PDOs */ 00244 do 00245 { 00246 /* Save our own PDO and reference it */ 00247 *ObjectEntry++ = PdoExtension->PhysicalDeviceObject; 00248 ObReferenceObject(PdoExtension->PhysicalDeviceObject); 00249 00250 /* Go to our next PDO */ 00251 PdoExtension = PdoExtension->Next; 00252 } 00253 while (PdoExtension); 00254 } 00255 00256 /* Return the new structure */ 00257 *DeviceRelations = FdoRelations; 00258 return STATUS_SUCCESS; 00259 } 00260 } 00261 else 00262 { 00263 /* The only other thing we support is a target relation for the PDO */ 00264 if ((RelationType == TargetDeviceRelation) && 00265 (ExtensionType == PdoExtensionType)) 00266 { 00267 /* Only one entry */ 00268 PdoRelations = ExAllocatePoolWithTag(PagedPool, 00269 sizeof(DEVICE_RELATIONS), 00270 ' laH'); 00271 if (!PdoRelations) return STATUS_INSUFFICIENT_RESOURCES; 00272 00273 /* Fill it out and reference us */ 00274 PdoRelations->Count = 1; 00275 PdoRelations->Objects[0] = DeviceObject; 00276 ObReferenceObject(DeviceObject); 00277 00278 /* Return it */ 00279 *DeviceRelations = PdoRelations; 00280 return STATUS_SUCCESS; 00281 } 00282 } 00283 00284 /* We don't support anything else */ 00285 return STATUS_NOT_SUPPORTED; 00286 } 00287 00288 NTSTATUS 00289 NTAPI 00290 HalpQueryCapabilities(IN PDEVICE_OBJECT DeviceObject, 00291 OUT PDEVICE_CAPABILITIES Capabilities) 00292 { 00293 //PPDO_EXTENSION PdoExtension; 00294 NTSTATUS Status; 00295 PAGED_CODE(); 00296 00297 /* Get the extension and check for valid version */ 00298 //PdoExtension = DeviceObject->DeviceExtension; 00299 ASSERT(Capabilities->Version == 1); 00300 if (Capabilities->Version == 1) 00301 { 00302 /* Can't lock or eject us */ 00303 Capabilities->LockSupported = FALSE; 00304 Capabilities->EjectSupported = FALSE; 00305 00306 /* Can't remove or dock us */ 00307 Capabilities->Removable = FALSE; 00308 Capabilities->DockDevice = FALSE; 00309 00310 /* Can't access us raw */ 00311 Capabilities->RawDeviceOK = FALSE; 00312 00313 /* We have a unique ID, and don't bother the user */ 00314 Capabilities->UniqueID = TRUE; 00315 Capabilities->SilentInstall = TRUE; 00316 00317 /* Fill out the adress */ 00318 Capabilities->Address = InterfaceTypeUndefined; 00319 Capabilities->UINumber = InterfaceTypeUndefined; 00320 00321 /* Fill out latencies */ 00322 Capabilities->D1Latency = 0; 00323 Capabilities->D2Latency = 0; 00324 Capabilities->D3Latency = 0; 00325 00326 /* Fill out supported device states */ 00327 Capabilities->DeviceState[PowerSystemWorking] = PowerDeviceD0; 00328 Capabilities->DeviceState[PowerSystemHibernate] = PowerDeviceD3; 00329 Capabilities->DeviceState[PowerSystemShutdown] = PowerDeviceD3; 00330 Capabilities->DeviceState[PowerSystemSleeping3] = PowerDeviceD3; 00331 00332 /* Done */ 00333 Status = STATUS_SUCCESS; 00334 } 00335 else 00336 { 00337 /* Fail */ 00338 Status = STATUS_NOT_SUPPORTED; 00339 } 00340 00341 /* Return status */ 00342 return Status; 00343 } 00344 00345 NTSTATUS 00346 NTAPI 00347 HalpQueryResources(IN PDEVICE_OBJECT DeviceObject, 00348 OUT PCM_RESOURCE_LIST *Resources) 00349 { 00350 PPDO_EXTENSION DeviceExtension = DeviceObject->DeviceExtension; 00351 NTSTATUS Status; 00352 PCM_RESOURCE_LIST ResourceList; 00353 // PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList; 00354 // PIO_RESOURCE_DESCRIPTOR Descriptor; 00355 // PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDesc; 00356 // ULONG i; 00357 PAGED_CODE(); 00358 00359 /* Only the ACPI PDO has requirements */ 00360 if (DeviceExtension->PdoType == AcpiPdo) 00361 { 00362 #if 0 00363 /* Query ACPI requirements */ 00364 Status = HalpQueryAcpiResourceRequirements(&RequirementsList); 00365 if (!NT_SUCCESS(Status)) return Status; 00366 00367 ASSERT(RequirementsList->AlternativeLists == 1); 00368 #endif 00369 00370 /* Allocate the resourcel ist */ 00371 ResourceList = ExAllocatePoolWithTag(PagedPool, 00372 sizeof(CM_RESOURCE_LIST), 00373 ' laH'); 00374 if (!ResourceList ) 00375 { 00376 /* Fail, no memory */ 00377 Status = STATUS_INSUFFICIENT_RESOURCES; 00378 // ExFreePoolWithTag(RequirementsList, ' laH'); 00379 return Status; 00380 } 00381 00382 /* Initialize it */ 00383 RtlZeroMemory(ResourceList, sizeof(CM_RESOURCE_LIST)); 00384 ResourceList->Count = 1; 00385 00386 /* Setup the list fields */ 00387 ResourceList->List[0].BusNumber = 0; 00388 ResourceList->List[0].InterfaceType = PCIBus; 00389 ResourceList->List[0].PartialResourceList.Version = 1; 00390 ResourceList->List[0].PartialResourceList.Revision = 1; 00391 ResourceList->List[0].PartialResourceList.Count = 0; 00392 00393 /* Setup the first descriptor */ 00394 //PartialDesc = ResourceList->List[0].PartialResourceList.PartialDescriptors; 00395 00396 /* Find the requirement descriptor for the SCI */ 00397 #if 0 00398 for (i = 0; i < RequirementsList->List[0].Count; i++) 00399 { 00400 /* Get this descriptor */ 00401 Descriptor = &RequirementsList->List[0].Descriptors[i]; 00402 if (Descriptor->Type == CmResourceTypeInterrupt) 00403 { 00404 /* Copy requirements descriptor into resource descriptor */ 00405 PartialDesc->Type = CmResourceTypeInterrupt; 00406 PartialDesc->ShareDisposition = Descriptor->ShareDisposition; 00407 PartialDesc->Flags = Descriptor->Flags; 00408 ASSERT(Descriptor->u.Interrupt.MinimumVector == 00409 Descriptor->u.Interrupt.MaximumVector); 00410 PartialDesc->u.Interrupt.Vector = Descriptor->u.Interrupt.MinimumVector; 00411 PartialDesc->u.Interrupt.Level = Descriptor->u.Interrupt.MinimumVector; 00412 PartialDesc->u.Interrupt.Affinity = 0xFFFFFFFF; 00413 00414 ResourceList->List[0].PartialResourceList.Count++; 00415 00416 break; 00417 } 00418 } 00419 #endif 00420 00421 /* Return resources and success */ 00422 *Resources = ResourceList; 00423 00424 // ExFreePoolWithTag(RequirementsList, ' laH'); 00425 00426 return STATUS_SUCCESS; 00427 } 00428 else if (DeviceExtension->PdoType == WdPdo) 00429 { 00430 /* Watchdog doesn't */ 00431 return STATUS_NOT_SUPPORTED; 00432 } 00433 else 00434 { 00435 /* This shouldn't happen */ 00436 return STATUS_UNSUCCESSFUL; 00437 } 00438 } 00439 00440 NTSTATUS 00441 NTAPI 00442 HalpQueryResourceRequirements(IN PDEVICE_OBJECT DeviceObject, 00443 OUT PIO_RESOURCE_REQUIREMENTS_LIST *Requirements) 00444 { 00445 PPDO_EXTENSION DeviceExtension = DeviceObject->DeviceExtension; 00446 PAGED_CODE(); 00447 00448 /* Only the ACPI PDO has requirements */ 00449 if (DeviceExtension->PdoType == AcpiPdo) 00450 { 00451 /* Query ACPI requirements */ 00452 // return HalpQueryAcpiResourceRequirements(Requirements); 00453 return STATUS_SUCCESS; 00454 } 00455 else if (DeviceExtension->PdoType == WdPdo) 00456 { 00457 /* Watchdog doesn't */ 00458 return STATUS_NOT_SUPPORTED; 00459 } 00460 else 00461 { 00462 /* This shouldn't happen */ 00463 return STATUS_UNSUCCESSFUL; 00464 } 00465 } 00466 00467 NTSTATUS 00468 NTAPI 00469 HalpQueryIdPdo(IN PDEVICE_OBJECT DeviceObject, 00470 IN BUS_QUERY_ID_TYPE IdType, 00471 OUT PUSHORT *BusQueryId) 00472 { 00473 PPDO_EXTENSION PdoExtension; 00474 PDO_TYPE PdoType; 00475 PWCHAR CurrentId; 00476 WCHAR Id[100]; 00477 NTSTATUS Status; 00478 ULONG Length = 0; 00479 PWCHAR Buffer; 00480 00481 /* Get the PDO type */ 00482 PdoExtension = DeviceObject->DeviceExtension; 00483 PdoType = PdoExtension->PdoType; 00484 00485 /* What kind of ID is being requested? */ 00486 DPRINT("ID: %d\n", IdType); 00487 switch (IdType) 00488 { 00489 case BusQueryDeviceID: 00490 case BusQueryHardwareIDs: 00491 00492 /* What kind of PDO is this? */ 00493 if (PdoType == AcpiPdo) 00494 { 00495 /* ACPI ID */ 00496 CurrentId = L"PCI_HAL\\PNP0A03"; 00497 RtlCopyMemory(Id, CurrentId, (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL)); 00498 Length += (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL); 00499 00500 CurrentId = L"*PNP0A03"; 00501 RtlCopyMemory(&Id[wcslen(Id) + 1], CurrentId, (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL)); 00502 Length += (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL); 00503 } 00504 #if 0 00505 else if (PdoType == WdPdo) 00506 { 00507 /* WatchDog ID */ 00508 CurrentId = L"ACPI_HAL\\PNP0C18"; 00509 RtlCopyMemory(Id, CurrentId, (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL)); 00510 Length += (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL); 00511 00512 CurrentId = L"*PNP0C18"; 00513 RtlCopyMemory(&Id[wcslen(Id) + 1], CurrentId, (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL)); 00514 Length += (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL); 00515 } 00516 #endif 00517 else 00518 { 00519 /* Unknown */ 00520 return STATUS_NOT_SUPPORTED; 00521 } 00522 break; 00523 00524 case BusQueryInstanceID: 00525 00526 /* Instance ID */ 00527 CurrentId = L"0"; 00528 RtlCopyMemory(Id, CurrentId, (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL)); 00529 Length += (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL); 00530 break; 00531 00532 case BusQueryCompatibleIDs: 00533 default: 00534 00535 /* We don't support anything else */ 00536 return STATUS_NOT_SUPPORTED; 00537 } 00538 00539 /* Allocate the buffer */ 00540 Buffer = ExAllocatePoolWithTag(PagedPool, 00541 Length + sizeof(UNICODE_NULL), 00542 ' laH'); 00543 if (Buffer) 00544 { 00545 /* Copy the string and null-terminate it */ 00546 RtlCopyMemory(Buffer, Id, Length); 00547 Buffer[Length / sizeof(WCHAR)] = UNICODE_NULL; 00548 00549 /* Return string */ 00550 *BusQueryId = Buffer; 00551 Status = STATUS_SUCCESS; 00552 DPRINT("Returning: %S\n", *BusQueryId); 00553 } 00554 else 00555 { 00556 /* Fail */ 00557 Status = STATUS_INSUFFICIENT_RESOURCES; 00558 } 00559 00560 /* Return status */ 00561 return Status; 00562 } 00563 00564 NTSTATUS 00565 NTAPI 00566 HalpQueryIdFdo(IN PDEVICE_OBJECT DeviceObject, 00567 IN BUS_QUERY_ID_TYPE IdType, 00568 OUT PUSHORT *BusQueryId) 00569 { 00570 NTSTATUS Status; 00571 ULONG Length; 00572 PWCHAR Id; 00573 PWCHAR Buffer; 00574 00575 /* What kind of ID is being requested? */ 00576 DPRINT("ID: %d\n", IdType); 00577 switch (IdType) 00578 { 00579 case BusQueryDeviceID: 00580 /* HACK */ 00581 Id = L"Root\\PCI_HAL"; 00582 break; 00583 00584 case BusQueryHardwareIDs: 00585 00586 /* This is our hardware ID */ 00587 Id = HalHardwareIdString; 00588 break; 00589 00590 case BusQueryInstanceID: 00591 00592 /* And our instance ID */ 00593 Id = L"0"; 00594 break; 00595 00596 default: 00597 00598 /* We don't support anything else */ 00599 return STATUS_NOT_SUPPORTED; 00600 } 00601 00602 /* Calculate the length */ 00603 Length = (wcslen(Id) * sizeof(WCHAR)) + sizeof(UNICODE_NULL); 00604 00605 /* Allocate the buffer */ 00606 Buffer = ExAllocatePoolWithTag(PagedPool, 00607 Length + sizeof(UNICODE_NULL), 00608 ' laH'); 00609 if (Buffer) 00610 { 00611 /* Copy the string and null-terminate it */ 00612 RtlCopyMemory(Buffer, Id, Length); 00613 Buffer[Length / sizeof(WCHAR)] = UNICODE_NULL; 00614 00615 /* Return string */ 00616 *BusQueryId = Buffer; 00617 Status = STATUS_SUCCESS; 00618 DPRINT("Returning: %S\n", *BusQueryId); 00619 } 00620 else 00621 { 00622 /* Fail */ 00623 Status = STATUS_INSUFFICIENT_RESOURCES; 00624 } 00625 00626 /* Return status */ 00627 return Status; 00628 } 00629 00630 NTSTATUS 00631 NTAPI 00632 HalpDispatchPnp(IN PDEVICE_OBJECT DeviceObject, 00633 IN PIRP Irp) 00634 { 00635 PIO_STACK_LOCATION IoStackLocation; 00636 //PPDO_EXTENSION PdoExtension; 00637 PFDO_EXTENSION FdoExtension; 00638 NTSTATUS Status; 00639 UCHAR Minor; 00640 00641 /* Get the device extension and stack location */ 00642 FdoExtension = DeviceObject->DeviceExtension; 00643 IoStackLocation = IoGetCurrentIrpStackLocation(Irp); 00644 Minor = IoStackLocation->MinorFunction; 00645 00646 /* FDO? */ 00647 if (FdoExtension->ExtensionType == FdoExtensionType) 00648 { 00649 /* Query the IRP type */ 00650 switch (Minor) 00651 { 00652 case IRP_MN_QUERY_DEVICE_RELATIONS: 00653 00654 /* Call the worker */ 00655 DPRINT("Querying device relations for FDO\n"); 00656 Status = HalpQueryDeviceRelations(DeviceObject, 00657 IoStackLocation->Parameters.QueryDeviceRelations.Type, 00658 (PVOID)&Irp->IoStatus.Information); 00659 break; 00660 00661 case IRP_MN_QUERY_INTERFACE: 00662 00663 /* Call the worker */ 00664 DPRINT("Querying interface for FDO\n"); 00665 Status = HalpQueryInterface(DeviceObject, 00666 IoStackLocation->Parameters.QueryInterface.InterfaceType, 00667 IoStackLocation->Parameters.QueryInterface.Size, 00668 IoStackLocation->Parameters.QueryInterface.InterfaceSpecificData, 00669 IoStackLocation->Parameters.QueryInterface.Version, 00670 IoStackLocation->Parameters.QueryInterface.Interface, 00671 (PVOID)&Irp->IoStatus.Information); 00672 break; 00673 00674 case IRP_MN_QUERY_ID: 00675 00676 /* Call the worker */ 00677 DPRINT("Querying ID for FDO\n"); 00678 Status = HalpQueryIdFdo(DeviceObject, 00679 IoStackLocation->Parameters.QueryId.IdType, 00680 (PVOID)&Irp->IoStatus.Information); 00681 break; 00682 00683 case IRP_MN_QUERY_CAPABILITIES: 00684 00685 /* Call the worker */ 00686 DPRINT("Querying the capabilities for the FDO\n"); 00687 Status = HalpQueryCapabilities(DeviceObject, 00688 IoStackLocation->Parameters.DeviceCapabilities.Capabilities); 00689 break; 00690 00691 default: 00692 00693 DPRINT("Other IRP: %lx\n", Minor); 00694 Status = Irp->IoStatus.Status; 00695 break; 00696 } 00697 00698 /* Nowhere for the IRP to go since we also own the PDO */ 00699 Irp->IoStatus.Status = Status; 00700 IoCompleteRequest(Irp, IO_NO_INCREMENT); 00701 return Status; 00702 } 00703 else 00704 { 00705 /* This is a PDO instead */ 00706 ASSERT(FdoExtension->ExtensionType == PdoExtensionType); 00707 //PdoExtension = (PPDO_EXTENSION)FdoExtension; 00708 00709 /* Query the IRP type */ 00710 Status = STATUS_SUCCESS; 00711 switch (Minor) 00712 { 00713 case IRP_MN_START_DEVICE: 00714 00715 /* We only care about a PCI PDO */ 00716 DPRINT1("Start device received\n"); 00717 /* Complete the IRP normally */ 00718 break; 00719 00720 case IRP_MN_REMOVE_DEVICE: 00721 00722 /* Check if this is a PCI device */ 00723 DPRINT1("Remove device received\n"); 00724 00725 /* We're done */ 00726 Status = STATUS_SUCCESS; 00727 break; 00728 00729 case IRP_MN_SURPRISE_REMOVAL: 00730 00731 /* Inherit whatever status we had */ 00732 DPRINT1("Surprise removal IRP\n"); 00733 Status = Irp->IoStatus.Status; 00734 break; 00735 00736 case IRP_MN_QUERY_DEVICE_RELATIONS: 00737 00738 /* Query the device relations */ 00739 DPRINT("Querying PDO relations\n"); 00740 Status = HalpQueryDeviceRelations(DeviceObject, 00741 IoStackLocation->Parameters.QueryDeviceRelations.Type, 00742 (PVOID)&Irp->IoStatus.Information); 00743 break; 00744 00745 case IRP_MN_QUERY_INTERFACE: 00746 00747 /* Call the worker */ 00748 DPRINT("Querying interface for PDO\n"); 00749 Status = HalpQueryInterface(DeviceObject, 00750 IoStackLocation->Parameters.QueryInterface.InterfaceType, 00751 IoStackLocation->Parameters.QueryInterface.Size, 00752 IoStackLocation->Parameters.QueryInterface.InterfaceSpecificData, 00753 IoStackLocation->Parameters.QueryInterface.Version, 00754 IoStackLocation->Parameters.QueryInterface.Interface, 00755 (PVOID)&Irp->IoStatus.Information); 00756 break; 00757 00758 case IRP_MN_QUERY_CAPABILITIES: 00759 00760 /* Call the worker */ 00761 DPRINT("Querying the capabilities for the PDO\n"); 00762 Status = HalpQueryCapabilities(DeviceObject, 00763 IoStackLocation->Parameters.DeviceCapabilities.Capabilities); 00764 break; 00765 00766 case IRP_MN_QUERY_RESOURCES: 00767 00768 /* Call the worker */ 00769 DPRINT("Querying the resources for the PDO\n"); 00770 Status = HalpQueryResources(DeviceObject, (PVOID)&Irp->IoStatus.Information); 00771 break; 00772 00773 case IRP_MN_QUERY_RESOURCE_REQUIREMENTS: 00774 00775 /* Call the worker */ 00776 DPRINT("Querying the resource requirements for the PDO\n"); 00777 Status = HalpQueryResourceRequirements(DeviceObject, 00778 (PVOID)&Irp->IoStatus.Information); 00779 break; 00780 00781 case IRP_MN_QUERY_ID: 00782 00783 /* Call the worker */ 00784 DPRINT("Query the ID for the PDO\n"); 00785 Status = HalpQueryIdPdo(DeviceObject, 00786 IoStackLocation->Parameters.QueryId.IdType, 00787 (PVOID)&Irp->IoStatus.Information); 00788 break; 00789 00790 default: 00791 00792 /* We don't handle anything else, so inherit the old state */ 00793 DPRINT("Illegal IRP: %lx\n", Minor); 00794 Status = Irp->IoStatus.Status; 00795 break; 00796 } 00797 00798 /* If it's not supported, inherit the old status */ 00799 if (Status == STATUS_NOT_SUPPORTED) Status = Irp->IoStatus.Status; 00800 00801 /* Complete the IRP */ 00802 DPRINT("IRP completed with status: %lx\n", Status); 00803 Irp->IoStatus.Status = Status; 00804 IoCompleteRequest(Irp, IO_NO_INCREMENT); 00805 return Status; 00806 } 00807 } 00808 00809 NTSTATUS 00810 NTAPI 00811 HalpDispatchWmi(IN PDEVICE_OBJECT DeviceObject, 00812 IN PIRP Irp) 00813 { 00814 DPRINT1("HAL: PnP Driver WMI!\n"); 00815 while (TRUE); 00816 return STATUS_SUCCESS; 00817 } 00818 00819 NTSTATUS 00820 NTAPI 00821 HalpDispatchPower(IN PDEVICE_OBJECT DeviceObject, 00822 IN PIRP Irp) 00823 { 00824 DPRINT1("HAL: PnP Driver Power!\n"); 00825 return STATUS_SUCCESS; 00826 } 00827 00828 NTSTATUS 00829 NTAPI 00830 HalpDriverEntry(IN PDRIVER_OBJECT DriverObject, 00831 IN PUNICODE_STRING RegistryPath) 00832 { 00833 NTSTATUS Status; 00834 PDEVICE_OBJECT TargetDevice = NULL; 00835 00836 DPRINT("HAL: PnP Driver ENTRY!\n"); 00837 00838 /* This is us */ 00839 HalpDriverObject = DriverObject; 00840 00841 /* Set up add device */ 00842 DriverObject->DriverExtension->AddDevice = HalpAddDevice; 00843 00844 /* Set up the callouts */ 00845 DriverObject->MajorFunction[IRP_MJ_PNP] = HalpDispatchPnp; 00846 DriverObject->MajorFunction[IRP_MJ_POWER] = HalpDispatchPower; 00847 DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = HalpDispatchWmi; 00848 00849 /* Create the PDO */ 00850 Status = IoCreateDevice(DriverObject, 00851 0, 00852 NULL, 00853 FILE_DEVICE_CONTROLLER, 00854 0, 00855 FALSE, 00856 &TargetDevice); 00857 if (!NT_SUCCESS(Status)) 00858 return Status; 00859 00860 TargetDevice->Flags &= ~DO_DEVICE_INITIALIZING; 00861 00862 /* Set up the device stack */ 00863 Status = HalpAddDevice(DriverObject, TargetDevice); 00864 if (!NT_SUCCESS(Status)) 00865 { 00866 IoDeleteDevice(TargetDevice); 00867 return Status; 00868 } 00869 00870 /* Tell the PnP manager about us */ 00871 Status = IoReportDetectedDevice(DriverObject, 00872 InterfaceTypeUndefined, 00873 -1, 00874 -1, 00875 NULL, 00876 NULL, 00877 FALSE, 00878 &TargetDevice); 00879 00880 /* Return to kernel */ 00881 return Status; 00882 } 00883 00884 NTSTATUS 00885 NTAPI 00886 HaliInitPnpDriver(VOID) 00887 { 00888 NTSTATUS Status; 00889 UNICODE_STRING DriverString; 00890 PAGED_CODE(); 00891 00892 /* Create the driver */ 00893 RtlInitUnicodeString(&DriverString, L"\\Driver\\PCI_HAL"); 00894 Status = IoCreateDriver(&DriverString, HalpDriverEntry); 00895 00896 /* Return status */ 00897 return Status; 00898 } 00899 00900 /* EOF */ Generated on Sun May 27 2012 04:28:43 for ReactOS by
1.7.6.1
|