Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1938 lines
50 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. ixpnpdrv.c
  5. Abstract:
  6. Implements functionality necessary for the
  7. HAL to become a PnP-style device driver
  8. after system initialization. This is done
  9. so that the HAL can enumerate the ACPI driver
  10. in the way that the PnP stuff expects.
  11. Author:
  12. Jake Oshins (jakeo) 27-Jan-1997
  13. Environment:
  14. Kernel mode only.
  15. Revision History:
  16. --*/
  17. #include "halp.h"
  18. #include "exboosts.h"
  19. #include "wchar.h"
  20. //
  21. // Cause the GUID to be defined.
  22. //
  23. #include "initguid.h"
  24. #include "wdmguid.h"
  25. #include "halpnpp.h"
  26. #if DBG
  27. ULONG HalDebug = 0;
  28. #endif
  29. WCHAR HalHardwareIdString[] = L"acpi";
  30. typedef enum {
  31. Hal = 0x80,
  32. AcpiDriver
  33. } PDO_TYPE;
  34. typedef enum {
  35. PdoExtensionType = 0xc0,
  36. FdoExtensionType
  37. } EXTENSION_TYPE;
  38. typedef struct _PDO_EXTENSION *PPDO_EXTENSION;
  39. typedef struct _FDO_EXTENSION *PFDO_EXTENSION;
  40. typedef struct _PDO_EXTENSION{
  41. EXTENSION_TYPE ExtensionType;
  42. PPDO_EXTENSION Next;
  43. PDEVICE_OBJECT PhysicalDeviceObject;
  44. PFDO_EXTENSION ParentFdoExtension;
  45. PDO_TYPE PdoType;
  46. LONG InterfaceReferenceCount;
  47. } PDO_EXTENSION, *PPDO_EXTENSION;
  48. #define ASSERT_PDO_EXTENSION(x) ASSERT((x)->ExtensionType == PdoExtensionType );
  49. typedef struct _FDO_EXTENSION{
  50. EXTENSION_TYPE ExtensionType;
  51. PPDO_EXTENSION ChildPdoList;
  52. PDEVICE_OBJECT PhysicalDeviceObject; // PDO passed into AddDevice()
  53. PDEVICE_OBJECT FunctionalDeviceObject;
  54. PDEVICE_OBJECT AttachedDeviceObject;
  55. } FDO_EXTENSION, *PFDO_EXTENSION;
  56. #define ASSERT_FDO_EXTENSION(x) ASSERT((x)->ExtensionType == FdoExtensionType );
  57. INT_ROUTE_INTERFACE_STANDARD PciIrqRoutingInterface = {0};
  58. NTSTATUS
  59. HalpDriverEntry (
  60. IN PDRIVER_OBJECT DriverObject,
  61. IN PUNICODE_STRING RegistryPath
  62. );
  63. NTSTATUS
  64. HalpAddDevice(
  65. IN PDRIVER_OBJECT DriverObject,
  66. IN PDEVICE_OBJECT PhysicalDeviceObject
  67. );
  68. NTSTATUS
  69. HalpDispatchPnp(
  70. IN PDEVICE_OBJECT DeviceObject,
  71. IN OUT PIRP Irp
  72. );
  73. NTSTATUS
  74. HalpDispatchWmi(
  75. IN PDEVICE_OBJECT DeviceObject,
  76. IN OUT PIRP Irp
  77. );
  78. NTSTATUS
  79. HalpDispatchPower(
  80. IN PDEVICE_OBJECT DeviceObject,
  81. IN OUT PIRP Irp
  82. );
  83. NTSTATUS
  84. HalpQueryDeviceRelations(
  85. IN PDEVICE_OBJECT DeviceObject,
  86. IN DEVICE_RELATION_TYPE RelationType,
  87. OUT PDEVICE_RELATIONS *DeviceRelations
  88. );
  89. NTSTATUS
  90. HalpQueryIdPdo(
  91. IN PDEVICE_OBJECT PdoExtension,
  92. IN BUS_QUERY_ID_TYPE IdType,
  93. IN OUT PWSTR *BusQueryId
  94. );
  95. NTSTATUS
  96. HalpQueryIdFdo(
  97. IN PDEVICE_OBJECT PdoExtension,
  98. IN BUS_QUERY_ID_TYPE IdType,
  99. IN OUT PWSTR *BusQueryId
  100. );
  101. NTSTATUS
  102. HalpQueryCapabilities(
  103. IN PDEVICE_OBJECT PdoExtension,
  104. IN PDEVICE_CAPABILITIES Capabilities
  105. );
  106. NTSTATUS
  107. HalpQueryResources(
  108. PDEVICE_OBJECT DeviceObject,
  109. PCM_RESOURCE_LIST *Resources
  110. );
  111. NTSTATUS
  112. HalpQueryResourceRequirements(
  113. PDEVICE_OBJECT DeviceObject,
  114. PIO_RESOURCE_REQUIREMENTS_LIST *Requirements
  115. );
  116. NTSTATUS
  117. HalpQueryInterface(
  118. IN PDEVICE_OBJECT DeviceObject,
  119. IN LPCGUID InterfaceType,
  120. IN USHORT Version,
  121. IN PVOID InterfaceSpecificData,
  122. IN ULONG InterfaceBufferSize,
  123. IN OUT PINTERFACE Interface,
  124. IN OUT PULONG Length
  125. );
  126. #ifdef WANT_IRQ_ROUTING
  127. NTSTATUS
  128. HalpQueryInterfaceFdo(
  129. IN PDEVICE_OBJECT DeviceObject,
  130. IN LPCGUID InterfaceType,
  131. IN USHORT Version,
  132. IN PVOID InterfaceSpecificData,
  133. IN ULONG InterfaceBufferSize,
  134. IN OUT PINTERFACE Interface,
  135. IN OUT PULONG Length
  136. );
  137. #endif
  138. NTSTATUS
  139. HalIrqTranslateResourcesRoot(
  140. IN PVOID Context,
  141. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Source,
  142. IN RESOURCE_TRANSLATION_DIRECTION Direction,
  143. IN ULONG AlternativesCount, OPTIONAL
  144. IN IO_RESOURCE_DESCRIPTOR Alternatives[], OPTIONAL
  145. IN PDEVICE_OBJECT PhysicalDeviceObject,
  146. OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR Target
  147. );
  148. NTSTATUS
  149. HalIrqTranslateResourceRequirementsRoot(
  150. IN PVOID Context,
  151. IN PIO_RESOURCE_DESCRIPTOR Source,
  152. IN PDEVICE_OBJECT PhysicalDeviceObject,
  153. OUT PULONG TargetCount,
  154. OUT PIO_RESOURCE_DESCRIPTOR *Target
  155. );
  156. VOID
  157. HalpMaskAcpiInterrupt(
  158. VOID
  159. );
  160. VOID
  161. HalpUnmaskAcpiInterrupt(
  162. VOID
  163. );
  164. // from xxacpi.c
  165. NTSTATUS
  166. HalpQueryAcpiResourceRequirements(
  167. IN PIO_RESOURCE_REQUIREMENTS_LIST *Requirements
  168. );
  169. //
  170. // Define the PNP interface functions.
  171. //
  172. VOID
  173. HalPnpInterfaceReference(
  174. PVOID Context
  175. );
  176. VOID
  177. HalPnpInterfaceDereference(
  178. PVOID Context
  179. );
  180. BOOLEAN
  181. HalPnpTranslateBusAddress(
  182. IN PVOID Context,
  183. IN PHYSICAL_ADDRESS BusAddress,
  184. IN ULONG Length,
  185. IN OUT PULONG AddressSpace,
  186. OUT PPHYSICAL_ADDRESS TranslatedAddress
  187. );
  188. struct _DMA_ADAPTER *
  189. HalPnpGetDmaAdapter(
  190. IN PVOID Context,
  191. IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
  192. OUT PULONG NumberOfMapRegisters
  193. );
  194. BOOLEAN
  195. HalpFakeAcpiRegisters(
  196. VOID
  197. );
  198. #define HAL_DRIVER_NAME L"\\Driver\\ACPI_HAL"
  199. #ifdef ALLOC_PRAGMA
  200. #pragma alloc_text(PAGE, HaliInitPnpDriver)
  201. #pragma alloc_text(PAGE, HalpOpenRegistryKey)
  202. #pragma alloc_text(PAGE, HalpDispatchPnp)
  203. #pragma alloc_text(PAGE, HalpAddDevice)
  204. #pragma alloc_text(PAGE, HalpDriverEntry)
  205. #pragma alloc_text(PAGE, HalpQueryDeviceRelations)
  206. #pragma alloc_text(PAGE, HalpQueryIdPdo)
  207. #pragma alloc_text(PAGE, HalpQueryIdFdo)
  208. #pragma alloc_text(PAGE, HalpQueryCapabilities)
  209. #pragma alloc_text(PAGE, HalpQueryResources)
  210. #pragma alloc_text(PAGE, HalpQueryResourceRequirements)
  211. #pragma alloc_text(PAGE, HalpQueryInterface)
  212. #ifdef WANT_IRQ_ROUTING
  213. #pragma alloc_text(PAGE, HalpQueryInterfaceFdo)
  214. #endif
  215. #pragma alloc_text(PAGELK, HalpDispatchPower)
  216. #pragma alloc_text(PAGE, HalpDispatchWmi)
  217. #endif
  218. PDRIVER_OBJECT HalpDriverObject;
  219. NTSTATUS
  220. HaliInitPnpDriver(
  221. VOID
  222. )
  223. /*++
  224. Routine Description:
  225. This routine starts the process of making the HAL into
  226. a "driver," which is necessary because we need to
  227. enumerate a Plug and Play PDO for the ACPI driver.
  228. Arguments:
  229. DriverName - Unicode string that will be used for the
  230. driver object.
  231. Return Value:
  232. status
  233. --*/
  234. {
  235. UNICODE_STRING DriverName;
  236. NTSTATUS Status;
  237. PAGED_CODE();
  238. RtlInitUnicodeString( &DriverName, HAL_DRIVER_NAME );
  239. Status = IoCreateDriver( &DriverName, HalpDriverEntry );
  240. ASSERT( NT_SUCCESS( Status ));
  241. return Status;
  242. }
  243. NTSTATUS
  244. HalpOpenRegistryKey(
  245. OUT PHANDLE Handle,
  246. IN HANDLE BaseHandle OPTIONAL,
  247. IN PUNICODE_STRING KeyName,
  248. IN ACCESS_MASK DesiredAccess,
  249. IN BOOLEAN Create
  250. )
  251. /*++
  252. Routine Description:
  253. Opens or creates a VOLATILE registry key using the name passed in based
  254. at the BaseHandle node.
  255. Arguments:
  256. Handle - Pointer to the handle which will contain the registry key that
  257. was opened.
  258. BaseHandle - Handle to the base path from which the key must be opened.
  259. KeyName - Name of the Key that must be opened/created.
  260. DesiredAccess - Specifies the desired access that the caller needs to
  261. the key.
  262. Create - Determines if the key is to be created if it does not exist.
  263. Return Value:
  264. The function value is the final status of the operation.
  265. --*/
  266. {
  267. OBJECT_ATTRIBUTES objectAttributes;
  268. ULONG disposition;
  269. PAGED_CODE();
  270. //
  271. // Initialize the object for the key.
  272. //
  273. InitializeObjectAttributes( &objectAttributes,
  274. KeyName,
  275. OBJ_CASE_INSENSITIVE,
  276. BaseHandle,
  277. (PSECURITY_DESCRIPTOR) NULL );
  278. //
  279. // Create the key or open it, as appropriate based on the caller's
  280. // wishes.
  281. //
  282. if (Create) {
  283. return ZwCreateKey( Handle,
  284. DesiredAccess,
  285. &objectAttributes,
  286. 0,
  287. (PUNICODE_STRING) NULL,
  288. REG_OPTION_VOLATILE,
  289. &disposition );
  290. } else {
  291. return ZwOpenKey( Handle,
  292. DesiredAccess,
  293. &objectAttributes );
  294. }
  295. }
  296. NTSTATUS
  297. HalpDriverEntry (
  298. IN PDRIVER_OBJECT DriverObject,
  299. IN PUNICODE_STRING RegistryPath
  300. )
  301. /*++
  302. Routine Description:
  303. This is the callback function when we call IoCreateDriver to create a
  304. PnP Driver Object. In this function, we need to remember the DriverObject.
  305. Arguments:
  306. DriverObject - Pointer to the driver object created by the system.
  307. RegistryPath - is NULL.
  308. Return Value:
  309. STATUS_SUCCESS
  310. --*/
  311. {
  312. NTSTATUS status;
  313. PDEVICE_OBJECT detectedDeviceObject = NULL;
  314. ANSI_STRING AKeyName;
  315. PAGED_CODE();
  316. //
  317. // File the pointer to our driver object away
  318. //
  319. HalpDriverObject = DriverObject;
  320. //
  321. // Fill in the driver object
  322. //
  323. DriverObject->DriverExtension->AddDevice = (PDRIVER_ADD_DEVICE)HalpAddDevice;
  324. DriverObject->MajorFunction[ IRP_MJ_PNP ] = HalpDispatchPnp;
  325. DriverObject->MajorFunction[ IRP_MJ_POWER ] = HalpDispatchPower;
  326. DriverObject->MajorFunction[ IRP_MJ_SYSTEM_CONTROL ] = HalpDispatchWmi;
  327. status = IoReportDetectedDevice(DriverObject,
  328. InterfaceTypeUndefined,
  329. -1,
  330. -1,
  331. NULL,
  332. NULL,
  333. FALSE,
  334. &detectedDeviceObject);
  335. ASSERT(detectedDeviceObject);
  336. if (!(NT_SUCCESS(status))) {
  337. return status;
  338. }
  339. HalpAddDevice(DriverObject,
  340. detectedDeviceObject);
  341. return STATUS_SUCCESS;
  342. }
  343. NTSTATUS
  344. HalpAddDevice(
  345. IN PDRIVER_OBJECT DriverObject,
  346. IN PDEVICE_OBJECT PhysicalDeviceObject
  347. )
  348. /*++
  349. Routine Description:
  350. This routine handles AddDevice for an madeup PDO device.
  351. Arguments:
  352. DriverObject - Pointer to our pseudo driver object.
  353. DeviceObject - Pointer to the device object for which this requestapplies.
  354. Return Value:
  355. NT status.
  356. --*/
  357. {
  358. PDEVICE_OBJECT functionalDeviceObject;
  359. PDEVICE_OBJECT childDeviceObject;
  360. PDEVICE_OBJECT AttachedDevice;
  361. NTSTATUS status;
  362. PFDO_EXTENSION FdoExtension;
  363. PPDO_EXTENSION PdoExtension;
  364. PAGED_CODE();
  365. //
  366. // We've been given the PhysicalDeviceObject. Create the
  367. // FunctionalDeviceObject. Our FDO will be nameless.
  368. //
  369. status = IoCreateDevice(
  370. DriverObject, // our driver object
  371. sizeof(FDO_EXTENSION), // size of our extension
  372. NULL, // our name
  373. FILE_DEVICE_BUS_EXTENDER, // device type
  374. 0, // device characteristics
  375. FALSE, // not exclusive
  376. &functionalDeviceObject // store new device object here
  377. );
  378. if( !NT_SUCCESS( status )){
  379. DbgBreakPoint();
  380. return status;
  381. }
  382. //
  383. // Fill in the FDO extension
  384. //
  385. FdoExtension = (PFDO_EXTENSION)functionalDeviceObject->DeviceExtension;
  386. FdoExtension->ExtensionType = FdoExtensionType;
  387. FdoExtension->PhysicalDeviceObject = PhysicalDeviceObject;
  388. FdoExtension->FunctionalDeviceObject = functionalDeviceObject;
  389. functionalDeviceObject->Flags &= ~(DO_DEVICE_INITIALIZING);
  390. //
  391. // Now attach to the PDO we were given.
  392. //
  393. AttachedDevice = IoAttachDeviceToDeviceStack(functionalDeviceObject,
  394. PhysicalDeviceObject );
  395. if(AttachedDevice == NULL){
  396. //
  397. // Couldn't attach. Delete the FDO.
  398. //
  399. IoDeleteDevice( functionalDeviceObject );
  400. return STATUS_NO_SUCH_DEVICE;
  401. }
  402. FdoExtension->AttachedDeviceObject = AttachedDevice;
  403. //
  404. // Next, create a PDO for the ACPI driver.
  405. //
  406. status = IoCreateDevice(
  407. DriverObject, // our driver object
  408. sizeof(PDO_EXTENSION), // size of our extension
  409. NULL, // our name
  410. FILE_DEVICE_BUS_EXTENDER, // device type
  411. FILE_AUTOGENERATED_DEVICE_NAME, // device characteristics
  412. FALSE, // not exclusive
  413. &childDeviceObject // store new device object here
  414. );
  415. if (!NT_SUCCESS(status)) {
  416. return status;
  417. }
  418. //
  419. // Fill in the PDO extension
  420. //
  421. PdoExtension = (PPDO_EXTENSION)childDeviceObject->DeviceExtension;
  422. PdoExtension->ExtensionType = PdoExtensionType;
  423. PdoExtension->Next = NULL;
  424. PdoExtension->PhysicalDeviceObject = childDeviceObject;
  425. PdoExtension->ParentFdoExtension = FdoExtension;
  426. PdoExtension->PdoType = AcpiDriver;
  427. childDeviceObject->Flags &= ~(DO_DEVICE_INITIALIZING);
  428. //
  429. // Record this as a child of the HAL
  430. //
  431. FdoExtension->ChildPdoList = PdoExtension;
  432. return STATUS_SUCCESS;
  433. }
  434. NTSTATUS
  435. HalpPassIrpFromFdoToPdo(
  436. PDEVICE_OBJECT DeviceObject,
  437. PIRP Irp
  438. )
  439. /*++
  440. Description:
  441. Given an FDO, pass the IRP to the next device object in the
  442. device stack. This is the PDO if there are no lower level
  443. filters.
  444. Arguments:
  445. DeviceObject - the Fdo
  446. Irp - the request
  447. Return Value:
  448. Returns the result from calling the next level.
  449. --*/
  450. {
  451. PIO_STACK_LOCATION irpSp; // our stack location
  452. PIO_STACK_LOCATION nextIrpSp; // next guy's
  453. PFDO_EXTENSION fdoExtension;
  454. //
  455. // Get the pointer to the device extension.
  456. //
  457. fdoExtension = (PFDO_EXTENSION)DeviceObject->DeviceExtension;
  458. IoSkipCurrentIrpStackLocation(Irp);
  459. //
  460. // Call the PDO driver with the request.
  461. //
  462. return IoCallDriver(fdoExtension->AttachedDeviceObject ,Irp);
  463. }
  464. NTSTATUS
  465. HalpDispatchPnp(
  466. IN PDEVICE_OBJECT DeviceObject,
  467. IN OUT PIRP Irp
  468. )
  469. /*++
  470. Routine Description:
  471. This routine handles all IRP_MJ_PNP IRPs for madeup PDO device.
  472. Arguments:
  473. DeviceObject - Pointer to the device object for which this IRP applies.
  474. Irp - Pointer to the IRP_MJ_PNP IRP to dispatch.
  475. Return Value:
  476. NT status.
  477. --*/
  478. {
  479. PIO_STACK_LOCATION irpSp;
  480. NTSTATUS status;
  481. ULONG length;
  482. DEVICE_RELATION_TYPE relationType;
  483. EXTENSION_TYPE extensionType;
  484. BOOLEAN passDown;
  485. PUCHAR objectTypeString;
  486. PAGED_CODE();
  487. extensionType = ((PFDO_EXTENSION)(DeviceObject->DeviceExtension))->ExtensionType;
  488. //
  489. // Get a pointer to our stack location and take appropriate action based
  490. // on the minor function.
  491. //
  492. irpSp = IoGetCurrentIrpStackLocation(Irp);
  493. status = Irp->IoStatus.Status;
  494. switch (extensionType) {
  495. case PdoExtensionType:
  496. objectTypeString = "PDO";
  497. switch (irpSp->MinorFunction) {
  498. case IRP_MN_START_DEVICE:
  499. HalDebugPrint(( HAL_PNP, "HAL: (%s) Start_Device Irp received\n",
  500. objectTypeString ));
  501. //
  502. // If we get a start device request for a PDO, we simply
  503. // return success.
  504. //
  505. status = STATUS_SUCCESS;
  506. break;
  507. case IRP_MN_QUERY_STOP_DEVICE:
  508. HalDebugPrint(( HAL_PNP, "HAL: (%s) Query_Stop_Device Irp received",
  509. objectTypeString));
  510. status = STATUS_SUCCESS;
  511. break;
  512. case IRP_MN_CANCEL_STOP_DEVICE:
  513. HalDebugPrint(( HAL_PNP, "HAL: (%s) Cancel_Stop_Device Irp received",
  514. objectTypeString ));
  515. status = STATUS_SUCCESS;
  516. break;
  517. case IRP_MN_STOP_DEVICE:
  518. HalDebugPrint(( HAL_PNP, "HAL: (%s) Stop_Device Irp received\n",
  519. objectTypeString ));
  520. //
  521. // If we get a stop device request for a PDO, we simply
  522. // return success.
  523. //
  524. status = STATUS_SUCCESS;
  525. break;
  526. case IRP_MN_QUERY_RESOURCES:
  527. HalDebugPrint(( HAL_PNP, "HAL: (%s) Query_Resources Irp received\n",
  528. objectTypeString ));
  529. status = HalpQueryResources(DeviceObject,
  530. (PCM_RESOURCE_LIST*)&Irp->IoStatus.Information);
  531. break;
  532. case IRP_MN_QUERY_RESOURCE_REQUIREMENTS:
  533. HalDebugPrint(( HAL_PNP, "HAL: (%s) Query_Resource_Requirements Irp received\n",
  534. objectTypeString ));
  535. status = HalpQueryResourceRequirements(DeviceObject,
  536. (PIO_RESOURCE_REQUIREMENTS_LIST*)&Irp->IoStatus.Information);
  537. break;
  538. case IRP_MN_QUERY_REMOVE_DEVICE:
  539. HalDebugPrint(( HAL_PNP, "HAL: (%s) Query_Remove_device Irp for %p",
  540. objectTypeString,
  541. DeviceObject ));
  542. status = STATUS_UNSUCCESSFUL;
  543. break;
  544. case IRP_MN_CANCEL_REMOVE_DEVICE:
  545. HalDebugPrint(( HAL_PNP, "HAL: (%s) Cancel_Remove_device Irp for %p",
  546. objectTypeString,
  547. DeviceObject));
  548. status = STATUS_SUCCESS;
  549. break;
  550. case IRP_MN_REMOVE_DEVICE:
  551. HalDebugPrint(( HAL_PNP, "HAL: (%s) Remove_device Irp for PDO %p\n",
  552. objectTypeString,
  553. DeviceObject ));
  554. status = STATUS_SUCCESS;
  555. break;
  556. case IRP_MN_QUERY_DEVICE_RELATIONS:
  557. HalDebugPrint(( HAL_PNP, "HAL: (%s) Query_Device_Relations Irp received\n",
  558. objectTypeString ));
  559. relationType = irpSp->Parameters.QueryDeviceRelations.Type;
  560. status = HalpQueryDeviceRelations(DeviceObject,
  561. relationType,
  562. (PDEVICE_RELATIONS*)&Irp->IoStatus.Information);
  563. break;
  564. case IRP_MN_QUERY_ID:
  565. HalDebugPrint(( HAL_PNP, "HAL: (%s) Query_Id Irp received\n",
  566. objectTypeString ));
  567. status = HalpQueryIdPdo(DeviceObject,
  568. irpSp->Parameters.QueryId.IdType,
  569. (PWSTR*)&Irp->IoStatus.Information);
  570. break;
  571. case IRP_MN_QUERY_INTERFACE:
  572. HalDebugPrint(( HAL_PNP, "HAL: (%s) Query_Interface Irp received\n",
  573. objectTypeString));
  574. status = HalpQueryInterface(
  575. DeviceObject,
  576. irpSp->Parameters.QueryInterface.InterfaceType,
  577. irpSp->Parameters.QueryInterface.Version,
  578. irpSp->Parameters.QueryInterface.InterfaceSpecificData,
  579. irpSp->Parameters.QueryInterface.Size,
  580. irpSp->Parameters.QueryInterface.Interface,
  581. (PULONG)&Irp->IoStatus.Information
  582. );
  583. break;
  584. case IRP_MN_QUERY_CAPABILITIES:
  585. HalDebugPrint(( HAL_PNP, "HAL: (%s) Query_Capabilities Irp received\n",
  586. objectTypeString));
  587. status = HalpQueryCapabilities(DeviceObject,
  588. irpSp->Parameters.DeviceCapabilities.Capabilities);
  589. break;
  590. case IRP_MN_DEVICE_USAGE_NOTIFICATION:
  591. HalDebugPrint(( HAL_PNP, "HAL: DEVICE_USAGE Irp received\n" ));
  592. status = STATUS_SUCCESS;
  593. break;
  594. default:
  595. HalDebugPrint(( HAL_PNP, "HAL: (%s) Unsupported Irp (%d) received\n",
  596. objectTypeString,
  597. irpSp->MinorFunction));
  598. status = STATUS_NOT_SUPPORTED ;
  599. break;
  600. }
  601. break; // end PDO cases
  602. case FdoExtensionType:
  603. objectTypeString = "FDO";
  604. passDown = TRUE;
  605. //
  606. // In case we don't touch this IRP, save the current status.
  607. //
  608. switch (irpSp->MinorFunction) {
  609. case IRP_MN_QUERY_DEVICE_RELATIONS:
  610. HalDebugPrint(( HAL_PNP, "HAL: (%s) Query_Device_Relations Irp received\n",
  611. objectTypeString));
  612. relationType = irpSp->Parameters.QueryDeviceRelations.Type;
  613. status = HalpQueryDeviceRelations(DeviceObject,
  614. relationType,
  615. (PDEVICE_RELATIONS*)&Irp->IoStatus.Information);
  616. break;
  617. #ifdef WANT_IRQ_ROUTING
  618. case IRP_MN_QUERY_INTERFACE:
  619. HalDebugPrint(( HAL_PNP, "(%s) Query_Interface Irp received",
  620. objectTypeString));
  621. HalDebugPrint(( HAL_PNP, "HAL: (%s) Query_Interface Irp received",
  622. objectTypeString ));
  623. Status = HalpQueryInterfaceFdo(
  624. DeviceObject,
  625. irpSp->Parameters.QueryInterface.InterfaceType,
  626. irpSp->Parameters.QueryInterface.Version,
  627. irpSp->Parameters.QueryInterface.InterfaceSpecificData,
  628. irpSp->Parameters.QueryInterface.Size,
  629. irpSp->Parameters.QueryInterface.Interface,
  630. &Irp->IoStatus.Information
  631. );
  632. break;
  633. #endif
  634. case IRP_MN_QUERY_ID:
  635. HalDebugPrint(( HAL_PNP, "HAL: (%s) Query_Id Irp received\n",
  636. objectTypeString ));
  637. status = HalpQueryIdFdo(DeviceObject,
  638. irpSp->Parameters.QueryId.IdType,
  639. (PWSTR*)&Irp->IoStatus.Information);
  640. break;
  641. default:
  642. //
  643. // Ignore any PNP Irps unknown by the FDO but allow them
  644. // down to the PDO.
  645. //
  646. status = STATUS_NOT_SUPPORTED ;
  647. break;
  648. }
  649. if (passDown && (NT_SUCCESS(status) || (status == STATUS_NOT_SUPPORTED))) {
  650. //
  651. // Pass FDO IRPs down to the PDO.
  652. //
  653. // Set Irp status first.
  654. //
  655. if (status != STATUS_NOT_SUPPORTED) {
  656. Irp->IoStatus.Status = status;
  657. }
  658. HalDebugPrint(( HAL_PNP, "HAL: (%s) Passing down Irp (%x)\n",
  659. objectTypeString, irpSp->MinorFunction ));
  660. return HalpPassIrpFromFdoToPdo(DeviceObject, Irp);
  661. }
  662. break; // end FDO cases
  663. default:
  664. HalDebugPrint(( HAL_PNP, "HAL: Received IRP for unknown Device Object\n" ));
  665. status = STATUS_INVALID_DEVICE_REQUEST ;
  666. break;
  667. }
  668. //
  669. // Complete the Irp and return.
  670. //
  671. if (status != STATUS_NOT_SUPPORTED) {
  672. Irp->IoStatus.Status = status;
  673. } else {
  674. status = Irp->IoStatus.Status ;
  675. }
  676. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  677. return status;
  678. }
  679. NTSTATUS
  680. HalpDispatchPower(
  681. IN PDEVICE_OBJECT DeviceObject,
  682. IN OUT PIRP Irp
  683. )
  684. /*++
  685. Routine Description:
  686. This routine handles all IRP_MJ_POWER IRPs for madeup PDO device.
  687. Note: We don't actually handle any Power IRPs at this level so
  688. all we do is return the status from the incoming IRP.
  689. Arguments:
  690. DeviceObject - Pointer to the device object for which this IRP applies.
  691. Irp - Pointer to the IRP_MJ_POWER IRP to dispatch.
  692. Return Value:
  693. NT status.
  694. --*/
  695. {
  696. NTSTATUS Status;
  697. EXTENSION_TYPE extensionType;
  698. PIO_STACK_LOCATION irpSp;
  699. HalDebugPrint(( HAL_PNP, "HAL: Power IRP for DevObj: %p\n", DeviceObject ));
  700. extensionType = ((PFDO_EXTENSION)(DeviceObject->DeviceExtension))->ExtensionType;
  701. irpSp = IoGetCurrentIrpStackLocation(Irp);
  702. //
  703. // Simply store the appropriate status and complete the request.
  704. //
  705. Status = Irp->IoStatus.Status;
  706. PoStartNextPowerIrp(Irp);
  707. if (extensionType == FdoExtensionType) {
  708. switch (irpSp->MinorFunction) {
  709. case IRP_MN_SET_POWER:
  710. if (irpSp->Parameters.Power.Type == SystemPowerState) {
  711. if (irpSp->Parameters.Power.State.SystemState ==
  712. PowerSystemWorking) {
  713. HalpUnmaskAcpiInterrupt();
  714. } else {
  715. HalpMaskAcpiInterrupt();
  716. }
  717. }
  718. //
  719. // Fall through.
  720. //
  721. case IRP_MN_QUERY_POWER:
  722. Irp->IoStatus.Status = Status = STATUS_SUCCESS;
  723. //
  724. // Fall through.
  725. //
  726. default:
  727. Status = HalpPassIrpFromFdoToPdo(DeviceObject, Irp);
  728. break;
  729. }
  730. } else {
  731. switch (irpSp->MinorFunction) {
  732. case IRP_MN_SET_POWER:
  733. case IRP_MN_QUERY_POWER:
  734. Irp->IoStatus.Status = Status = STATUS_SUCCESS;
  735. //
  736. // Fall through.
  737. //
  738. default:
  739. IoCompleteRequest( Irp, IO_NO_INCREMENT );
  740. break;
  741. }
  742. }
  743. return Status;
  744. }
  745. NTSTATUS
  746. HalpDispatchWmi(
  747. IN PDEVICE_OBJECT DeviceObject,
  748. IN OUT PIRP Irp
  749. )
  750. {
  751. NTSTATUS Status;
  752. EXTENSION_TYPE extensionType;
  753. extensionType = ((PFDO_EXTENSION)(DeviceObject->DeviceExtension))->ExtensionType;
  754. if (extensionType == FdoExtensionType) {
  755. Status = HalpPassIrpFromFdoToPdo(DeviceObject, Irp);
  756. } else {
  757. Status = Irp->IoStatus.Status;
  758. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  759. }
  760. return Status;
  761. }
  762. NTSTATUS
  763. HalpQueryDeviceRelations(
  764. IN PDEVICE_OBJECT DeviceObject,
  765. IN DEVICE_RELATION_TYPE RelationType,
  766. OUT PDEVICE_RELATIONS *DeviceRelations
  767. )
  768. /*++
  769. Routine Description:
  770. This routine builds a DEVICE_RELATIONS structure that
  771. tells the PnP manager how many children we have.
  772. Arguments:
  773. DeviceObject - FDO of ACPI_HAL
  774. RelationType - we only respond to BusRelations
  775. DeviceRelations - pointer to the structure
  776. Return Value:
  777. status
  778. --*/
  779. {
  780. PFDO_EXTENSION FdoExtension;
  781. PDEVICE_RELATIONS relations = NULL;
  782. PDEVICE_OBJECT deviceObjectToReturn ;
  783. EXTENSION_TYPE extensionType;
  784. NTSTATUS status ;
  785. PAGED_CODE();
  786. FdoExtension = (PFDO_EXTENSION)DeviceObject->DeviceExtension;
  787. extensionType = FdoExtension->ExtensionType;
  788. status = STATUS_NOT_SUPPORTED ;
  789. switch(RelationType) {
  790. case BusRelations:
  791. if (extensionType == FdoExtensionType) {
  792. deviceObjectToReturn = FdoExtension->ChildPdoList->PhysicalDeviceObject ;
  793. status = STATUS_SUCCESS ;
  794. }
  795. break;
  796. case TargetDeviceRelation:
  797. if (extensionType == PdoExtensionType) {
  798. deviceObjectToReturn = DeviceObject ;
  799. status = STATUS_SUCCESS ;
  800. }
  801. break;
  802. }
  803. if (status == STATUS_NOT_SUPPORTED) {
  804. HalDebugPrint(( HAL_PNP, "HAL: We don't support this kind of device relation\n" ));
  805. } else if (NT_SUCCESS(status)) {
  806. ASSERT(*DeviceRelations == 0);
  807. relations = ExAllocatePoolWithTag(
  808. PagedPool,
  809. sizeof(DEVICE_RELATIONS),
  810. HAL_POOL_TAG
  811. );
  812. if (!relations) {
  813. status = STATUS_INSUFFICIENT_RESOURCES;
  814. } else {
  815. relations->Count = 1;
  816. relations->Objects[0] = deviceObjectToReturn ;
  817. ObReferenceObject(relations->Objects[0]);
  818. *DeviceRelations = relations;
  819. }
  820. }
  821. return status ;
  822. }
  823. NTSTATUS
  824. HalpQueryIdPdo(
  825. IN PDEVICE_OBJECT DeviceObject,
  826. IN BUS_QUERY_ID_TYPE IdType,
  827. IN OUT PWSTR *BusQueryId
  828. )
  829. /*++
  830. Routine Description:
  831. This routine identifies each of the children that were
  832. enumerated in HalpQueryDeviceRelations.
  833. Arguments:
  834. DeviceObject - PDO of the child
  835. IdType - the type of ID to be returned, currently ignored
  836. BusQueryId - pointer to the wide string being returned
  837. Return Value:
  838. status
  839. --*/
  840. {
  841. PPDO_EXTENSION PdoExtension = DeviceObject->DeviceExtension;
  842. PWSTR idString;
  843. PWCHAR sourceString;
  844. ULONG stringLen;
  845. static WCHAR AcpiHardwareIdString[] = L"ACPI_HAL\\PNP0C08\0*PNP0C08";
  846. static WCHAR AcpiCompatibleString[] = L"*PNP0C08";
  847. static WCHAR AcpiInstanceIdString[] = L"0";
  848. PAGED_CODE();
  849. switch (IdType) {
  850. case BusQueryDeviceID:
  851. case BusQueryHardwareIDs:
  852. switch (PdoExtension->PdoType) {
  853. case AcpiDriver:
  854. sourceString = AcpiHardwareIdString;
  855. stringLen = sizeof(AcpiHardwareIdString);
  856. break;
  857. default:
  858. return STATUS_NOT_SUPPORTED;
  859. }
  860. break;
  861. case BusQueryCompatibleIDs:
  862. return STATUS_NOT_SUPPORTED;
  863. break;
  864. case BusQueryInstanceID:
  865. sourceString = AcpiInstanceIdString;
  866. stringLen = sizeof(AcpiInstanceIdString);
  867. break;
  868. default:
  869. return STATUS_NOT_SUPPORTED;
  870. }
  871. idString = ExAllocatePoolWithTag(PagedPool,
  872. stringLen + sizeof(UNICODE_NULL),
  873. HAL_POOL_TAG);
  874. if (!idString) {
  875. return STATUS_INSUFFICIENT_RESOURCES;
  876. }
  877. RtlCopyMemory(idString,
  878. sourceString, stringLen);
  879. *(idString + stringLen / sizeof(WCHAR)) = UNICODE_NULL;
  880. *BusQueryId = idString;
  881. return STATUS_SUCCESS;
  882. }
  883. NTSTATUS
  884. HalpQueryIdFdo(
  885. IN PDEVICE_OBJECT DeviceObject,
  886. IN BUS_QUERY_ID_TYPE IdType,
  887. IN OUT PWSTR *BusQueryId
  888. )
  889. /*++
  890. Routine Description:
  891. This routine identifies each of the children that were
  892. enumerated in HalpQueryDeviceRelations.
  893. Arguments:
  894. DeviceObject - PDO of the child
  895. IdType - the type of ID to be returned.
  896. BusQueryId - pointer to the wide string being returned
  897. Return Value:
  898. status
  899. --*/
  900. {
  901. PPDO_EXTENSION PdoExtension = DeviceObject->DeviceExtension;
  902. PWSTR idString;
  903. PWCHAR sourceString = NULL;
  904. ULONG stringLen;
  905. UNICODE_STRING String;
  906. WCHAR Buffer[16];
  907. NTSTATUS Status;
  908. PWCHAR widechar;
  909. static WCHAR HalInstanceIdString[] = L"0";
  910. PAGED_CODE();
  911. switch (IdType) {
  912. case BusQueryDeviceID:
  913. case BusQueryHardwareIDs:
  914. sourceString = HalHardwareIdString;
  915. widechar = (PWCHAR)&HalHardwareIdString;
  916. while (*widechar != 0) widechar++;
  917. stringLen = (ULONG)((PUCHAR)widechar - ((PUCHAR)&HalHardwareIdString) + 2);
  918. break;
  919. case BusQueryInstanceID:
  920. sourceString = HalInstanceIdString;
  921. stringLen = sizeof(HalInstanceIdString);
  922. break;
  923. default:
  924. break;
  925. }
  926. if (sourceString) {
  927. //
  928. // Note that hardware IDs and compatible IDs must be terminated by
  929. // 2 NULLs.
  930. //
  931. idString = ExAllocatePoolWithTag(PagedPool,
  932. stringLen + sizeof(UNICODE_NULL),
  933. HAL_POOL_TAG);
  934. if (!idString) {
  935. HalDebugPrint(( HAL_PNP, "HalpQueryIdFdo: couldn't allocate pool\n" ));
  936. return STATUS_INSUFFICIENT_RESOURCES;
  937. }
  938. RtlCopyMemory(idString,
  939. sourceString, stringLen);
  940. *(idString + stringLen / sizeof(WCHAR)) = UNICODE_NULL;
  941. *BusQueryId = idString;
  942. return STATUS_SUCCESS;
  943. } else {
  944. return STATUS_NOT_SUPPORTED;
  945. }
  946. }
  947. NTSTATUS
  948. HalpQueryCapabilities(
  949. IN PDEVICE_OBJECT PdoExtension,
  950. IN PDEVICE_CAPABILITIES Capabilities
  951. )
  952. /*++
  953. Routine Description:
  954. This routine fills in the DEVICE_CAPABILITIES structure for
  955. a device.
  956. Arguments:
  957. DeviceObject - PDO of the child
  958. Capabilities - pointer to the structure to be filled in.
  959. Return Value:
  960. status
  961. --*/
  962. {
  963. PAGED_CODE();
  964. ASSERT(Capabilities->Version == 1);
  965. if (Capabilities->Version != 1) {
  966. return STATUS_NOT_SUPPORTED;
  967. }
  968. Capabilities->LockSupported = FALSE;
  969. Capabilities->EjectSupported = FALSE;
  970. Capabilities->Removable = FALSE;
  971. Capabilities->DockDevice = FALSE;
  972. Capabilities->UniqueID = TRUE;
  973. Capabilities->SilentInstall = TRUE;
  974. Capabilities->RawDeviceOK = FALSE;
  975. Capabilities->Address = 0xffffffff;
  976. Capabilities->UINumber = 0xffffffff;
  977. Capabilities->D1Latency = 0;
  978. Capabilities->D2Latency = 0;
  979. Capabilities->D3Latency = 0;
  980. //
  981. // Default S->D mapping
  982. //
  983. Capabilities->DeviceState[PowerSystemWorking] = PowerDeviceD0;
  984. Capabilities->DeviceState[PowerSystemHibernate] = PowerDeviceD3;
  985. Capabilities->DeviceState[PowerSystemShutdown] = PowerDeviceD3;
  986. return STATUS_SUCCESS;
  987. }
  988. NTSTATUS
  989. HalpQueryResources(
  990. PDEVICE_OBJECT DeviceObject,
  991. PCM_RESOURCE_LIST *Resources
  992. )
  993. {
  994. PIO_RESOURCE_REQUIREMENTS_LIST requirements;
  995. PPDO_EXTENSION PdoExtension = DeviceObject->DeviceExtension;
  996. PIO_RESOURCE_DESCRIPTOR descriptor;
  997. PCM_RESOURCE_LIST cmResList;
  998. NTSTATUS status;
  999. ULONG i;
  1000. PAGED_CODE();
  1001. if (PdoExtension->PdoType == AcpiDriver) {
  1002. //
  1003. // The whole point behind creating a boot config for the
  1004. // ACPI PDO is that the PnP Manager will not terminate
  1005. // its algorithm that tries to reserve boot configs for
  1006. // all of ACPI's children. So it is not necessary that
  1007. // ACPI have a complicated list of resources in its boot
  1008. // config. We'll be happy with just the IRQ.
  1009. //
  1010. // N.B. At the time of this writing, it should also be
  1011. // true that the IRQ is the only resource that the ACPI
  1012. // claims anyhow.
  1013. //
  1014. status = HalpQueryAcpiResourceRequirements(&requirements);
  1015. if (!NT_SUCCESS(status)) {
  1016. return status;
  1017. }
  1018. cmResList = ExAllocatePoolWithTag(PagedPool,
  1019. sizeof(CM_RESOURCE_LIST),
  1020. HAL_POOL_TAG);
  1021. if (!cmResList) {
  1022. ExFreePool(requirements);
  1023. return STATUS_INSUFFICIENT_RESOURCES;
  1024. }
  1025. RtlZeroMemory(cmResList, sizeof(CM_RESOURCE_LIST));
  1026. cmResList->Count = 1;
  1027. cmResList->List[0].InterfaceType = PNPBus;
  1028. cmResList->List[0].BusNumber = -1;
  1029. cmResList->List[0].PartialResourceList.Version = 1;
  1030. cmResList->List[0].PartialResourceList.Revision = 1;
  1031. cmResList->List[0].PartialResourceList.Count = 1;
  1032. cmResList->List[0].PartialResourceList.PartialDescriptors[0].Type =
  1033. CmResourceTypeInterrupt;
  1034. ASSERT(requirements->AlternativeLists == 1);
  1035. for (i = 0; i < requirements->List[0].Count; i++) {
  1036. descriptor = &requirements->List[0].Descriptors[i];
  1037. if (descriptor->Type == CmResourceTypeInterrupt) {
  1038. cmResList->List[0].PartialResourceList.PartialDescriptors[0].ShareDisposition =
  1039. descriptor->ShareDisposition;
  1040. cmResList->List[0].PartialResourceList.PartialDescriptors[0].Flags =
  1041. descriptor->Flags;
  1042. ASSERT(descriptor->u.Interrupt.MinimumVector ==
  1043. descriptor->u.Interrupt.MaximumVector);
  1044. cmResList->List[0].PartialResourceList.PartialDescriptors[0].u.Interrupt.Level =
  1045. descriptor->u.Interrupt.MinimumVector;
  1046. cmResList->List[0].PartialResourceList.PartialDescriptors[0].u.Interrupt.Vector =
  1047. descriptor->u.Interrupt.MinimumVector;
  1048. cmResList->List[0].PartialResourceList.PartialDescriptors[0].u.Interrupt.Affinity = -1;
  1049. *Resources = cmResList;
  1050. ExFreePool(requirements);
  1051. return STATUS_SUCCESS;
  1052. }
  1053. }
  1054. ExFreePool(requirements);
  1055. ExFreePool(cmResList);
  1056. return STATUS_NOT_FOUND;
  1057. } else {
  1058. return STATUS_NOT_SUPPORTED;
  1059. }
  1060. }
  1061. NTSTATUS
  1062. HalpQueryResourceRequirements(
  1063. IN PDEVICE_OBJECT DeviceObject,
  1064. IN PIO_RESOURCE_REQUIREMENTS_LIST *Requirements
  1065. )
  1066. /*++
  1067. Routine Description:
  1068. This routine handles IRP_MN_QUERY_RESOURCE_REQUIREMENTS.
  1069. Arguments:
  1070. DeviceObject - PDO of the child
  1071. Requirements - pointer to be filled in with the devices
  1072. resource requirements.
  1073. Return Value:
  1074. status
  1075. --*/
  1076. {
  1077. PPDO_EXTENSION PdoExtension = DeviceObject->DeviceExtension;
  1078. PAGED_CODE();
  1079. if (PdoExtension->PdoType == AcpiDriver) {
  1080. return HalpQueryAcpiResourceRequirements(Requirements);
  1081. } else {
  1082. return STATUS_NOT_SUPPORTED;
  1083. }
  1084. }
  1085. NTSTATUS
  1086. HalpQueryInterface(
  1087. IN PDEVICE_OBJECT DeviceObject,
  1088. IN LPCGUID InterfaceType,
  1089. IN USHORT Version,
  1090. IN PVOID InterfaceSpecificData,
  1091. IN ULONG InterfaceBufferSize,
  1092. IN OUT PINTERFACE Interface,
  1093. IN OUT PULONG Length
  1094. )
  1095. /*++
  1096. Routine Description:
  1097. This routine fills in the interface structure for a device.
  1098. Arguments:
  1099. DeviceObject - PDO of the child
  1100. InterfaceType - Pointer to the interface type GUID.
  1101. Version - Supplies the requested interface version.
  1102. InterfaceSpecificData - This is context that means something based on the interface.
  1103. Interface Buffer Size - Supplies the length of a buffer for the interface structure.
  1104. Interface - Supplies a pointer where interference information should be returned.ointer to the supplied interface buffer.
  1105. Length - The value is updated on return to actual number of bytes modified.
  1106. Return Value:
  1107. status
  1108. --*/
  1109. {
  1110. PPDO_EXTENSION PdoExtension = (PPDO_EXTENSION)DeviceObject->DeviceExtension;
  1111. CM_RESOURCE_TYPE resource = (CM_RESOURCE_TYPE)(INT_PTR)InterfaceSpecificData;
  1112. PAGED_CODE();
  1113. ASSERT_PDO_EXTENSION(PdoExtension);
  1114. if (IsEqualGUID(&GUID_BUS_INTERFACE_STANDARD, InterfaceType)) {
  1115. PBUS_INTERFACE_STANDARD standard = (PBUS_INTERFACE_STANDARD)Interface;
  1116. //
  1117. // ASSERT we know about all of the fields in the structure.
  1118. //
  1119. ASSERT(sizeof(BUS_INTERFACE_STANDARD) == FIELD_OFFSET(BUS_INTERFACE_STANDARD, GetBusData) + sizeof(PGET_SET_DEVICE_DATA));
  1120. *Length = sizeof(BUS_INTERFACE_STANDARD);
  1121. if (InterfaceBufferSize < sizeof(BUS_INTERFACE_STANDARD)) {
  1122. return STATUS_BUFFER_TOO_SMALL;
  1123. }
  1124. //
  1125. // The only version this code knows about is 1.
  1126. //
  1127. standard->Size = sizeof(BUS_INTERFACE_STANDARD);
  1128. standard->Version = HAL_BUS_INTERFACE_STD_VERSION;
  1129. standard->Context = DeviceObject;
  1130. standard->InterfaceReference = HalPnpInterfaceReference;
  1131. standard->InterfaceDereference = HalPnpInterfaceDereference;
  1132. standard->TranslateBusAddress = HalPnpTranslateBusAddress;
  1133. standard->GetDmaAdapter = HalPnpGetDmaAdapter;
  1134. standard->SetBusData = NULL;
  1135. standard->GetBusData = NULL;
  1136. } else if (IsEqualGUID(&GUID_TRANSLATOR_INTERFACE_STANDARD, InterfaceType)) {
  1137. PTRANSLATOR_INTERFACE translator = (PTRANSLATOR_INTERFACE)Interface;
  1138. //
  1139. // Common initialization.
  1140. //
  1141. if (InterfaceBufferSize < sizeof(TRANSLATOR_INTERFACE)) {
  1142. *Length = sizeof(TRANSLATOR_INTERFACE);
  1143. return STATUS_BUFFER_TOO_SMALL;
  1144. }
  1145. switch ((CM_RESOURCE_TYPE)(INT_PTR)InterfaceSpecificData) {
  1146. case CmResourceTypeInterrupt:
  1147. translator->Size = sizeof(TRANSLATOR_INTERFACE);
  1148. translator->Version = HAL_IRQ_TRANSLATOR_VERSION;
  1149. translator->Context = DeviceObject;
  1150. translator->InterfaceReference = HalTranslatorReference;
  1151. translator->InterfaceDereference = HalTranslatorDereference;
  1152. translator->TranslateResources = HalIrqTranslateResourcesRoot;
  1153. translator->TranslateResourceRequirements =
  1154. HalIrqTranslateResourceRequirementsRoot;
  1155. *Length = sizeof(TRANSLATOR_INTERFACE);
  1156. break;
  1157. default:
  1158. return STATUS_NOT_SUPPORTED;
  1159. }
  1160. } else if (IsEqualGUID(&GUID_ACPI_REGS_INTERFACE_STANDARD, InterfaceType)) {
  1161. //
  1162. // ACPI register function interface.
  1163. //
  1164. PACPI_REGS_INTERFACE_STANDARD AcpiRegInterface =
  1165. (PACPI_REGS_INTERFACE_STANDARD)Interface;
  1166. if (!HalpFakeAcpiRegisters()) {
  1167. return STATUS_NOT_FOUND;
  1168. }
  1169. DbgPrint("Faking ACPI registers\n");
  1170. //
  1171. // Common initialization.
  1172. //
  1173. *Length = sizeof(ACPI_REGS_INTERFACE_STANDARD);
  1174. if (InterfaceBufferSize < sizeof(ACPI_REGS_INTERFACE_STANDARD)) {
  1175. return STATUS_BUFFER_TOO_SMALL;
  1176. }
  1177. AcpiRegInterface->Size = sizeof(ACPI_REGS_INTERFACE_STANDARD);
  1178. AcpiRegInterface->Context = NULL;
  1179. AcpiRegInterface->InterfaceReference = HalTranslatorReference;
  1180. AcpiRegInterface->InterfaceDereference = HalTranslatorDereference;
  1181. //
  1182. // Set the two ACPI register access routines.
  1183. //
  1184. AcpiRegInterface->ReadAcpiRegister = HalpReadAcpiRegister;
  1185. AcpiRegInterface->WriteAcpiRegister = HalpWriteAcpiRegister;
  1186. } else if (IsEqualGUID(&GUID_ACPI_PORT_RANGES_INTERFACE_STANDARD,
  1187. InterfaceType)) {
  1188. PHAL_PORT_RANGE_INTERFACE PortRanges = (PHAL_PORT_RANGE_INTERFACE)Interface;
  1189. *Length = sizeof(HAL_PORT_RANGE_INTERFACE);
  1190. if (InterfaceBufferSize < sizeof(HAL_PORT_RANGE_INTERFACE)) {
  1191. return STATUS_BUFFER_TOO_SMALL;
  1192. }
  1193. PortRanges->Size = sizeof(HAL_PORT_RANGE_INTERFACE);
  1194. PortRanges->Version = HAL_PORT_RANGE_INTERFACE_VERSION;
  1195. PortRanges->Context = DeviceObject;
  1196. PortRanges->InterfaceReference = HalPnpInterfaceReference;
  1197. PortRanges->InterfaceDereference = HalPnpInterfaceDereference;
  1198. PortRanges->QueryAllocateRange = HalpQueryAllocatePortRange;
  1199. PortRanges->FreeRange = HalpFreePortRange;
  1200. } else {
  1201. //
  1202. // Unsupport bus interface type.
  1203. //
  1204. return STATUS_NOT_SUPPORTED ;
  1205. }
  1206. //
  1207. // Bump the reference count.
  1208. //
  1209. InterlockedIncrement(&PdoExtension->InterfaceReferenceCount);
  1210. return STATUS_SUCCESS;
  1211. }
  1212. #ifdef WANT_IRQ_ROUTING
  1213. NTSTATUS
  1214. HalpQueryInterfaceFdo(
  1215. IN PDEVICE_OBJECT DeviceObject,
  1216. IN LPCGUID InterfaceType,
  1217. IN USHORT Version,
  1218. IN PVOID InterfaceSpecificData,
  1219. IN ULONG InterfaceBufferSize,
  1220. IN OUT PINTERFACE Interface,
  1221. IN OUT PULONG Length
  1222. )
  1223. /*++
  1224. Routine Description:
  1225. This routine fills in the interface structure for
  1226. a device.
  1227. Arguments:
  1228. DeviceObject - FDO of the child
  1229. InterfaceType - Pointer to the interface type GUID.
  1230. Version - Supplies the requested interface version.
  1231. InterfaceSpecificData - This is context that means something based on the
  1232. interface.
  1233. InterfaceBufferSize - Supplies the length of the buffer for the interface
  1234. structure.
  1235. Interface - Supplies a pointer where the interface informaiton should
  1236. be returned.
  1237. Length - Supplies the length of the buffer for the interface structure.
  1238. This value is updated on return to actual number of bytes modified.
  1239. Return Value:
  1240. status
  1241. --*/
  1242. {
  1243. NTSTATUS status = STATUS_NOT_SUPPORTED;
  1244. CM_RESOURCE_TYPE resource = (CM_RESOURCE_TYPE)InterfaceSpecificData;
  1245. PAGED_CODE();
  1246. if ( resource == CmResourceTypeInterrupt &&
  1247. IsPciIrqRoutingEnabled()) {
  1248. if (IsEqualGUID(&GUID_ARBITER_INTERFACE_STANDARD, InterfaceType)) {
  1249. status = HalpInitIrqArbiter(DeviceObject);
  1250. if (NT_SUCCESS(status))
  1251. {
  1252. status = HalpFillInIrqArbiter(
  1253. DeviceObject,
  1254. InterfaceType,
  1255. Version,
  1256. InterfaceSpecificData,
  1257. InterfaceBufferSize,
  1258. Interface,
  1259. Length
  1260. );
  1261. }
  1262. }
  1263. else if (IsEqualGUID(&GUID_TRANSLATOR_INTERFACE_STANDARD, InterfaceType)) {
  1264. PTRANSLATOR_INTERFACE translator;
  1265. *Length = sizeof(TRANSLATOR_INTERFACE);
  1266. if (InterfaceBufferSize < sizeof(TRANSLATOR_INTERFACE)) {
  1267. return STATUS_BUFFER_TOO_SMALL;
  1268. }
  1269. translator = (PTRANSLATOR_INTERFACE)Interface;
  1270. //
  1271. // Fill in the common bits.
  1272. //
  1273. RtlZeroMemory(translator, sizeof (TRANSLATOR_INTERFACE));
  1274. translator->Size = sizeof(TRANSLATOR_INTERFACE);
  1275. translator->Version = HAL_IRQ_TRANSLATOR_VERSION;
  1276. translator->Context = DeviceObject;
  1277. translator->InterfaceReference = HalTranslatorReference;
  1278. translator->InterfaceDereference = HalTranslatorDereference;
  1279. //
  1280. // Set IRQ translator for PCI interrupts.
  1281. //
  1282. translator->TranslateResources = HalIrqTranslateResourcesRoot;
  1283. translator->TranslateResourceRequirements =
  1284. HalIrqTranslateResourceRequirementsRoot;
  1285. status = STATUS_SUCCESS;
  1286. HalDebugPrint(( HAL_PNP, "Providing Irq translator for FDO %p since Pci Irq Routing is enabled!", DeviceObject));
  1287. }
  1288. }
  1289. return (status);
  1290. }
  1291. #endif
  1292. VOID
  1293. HalPnpInterfaceReference(
  1294. PVOID Context
  1295. )
  1296. /*++
  1297. Routine Description:
  1298. This function increments the reference count on the interface context.
  1299. Arguments:
  1300. Context - Supplies a pointer to the interface context. This is actually
  1301. the PDO for the root bus.
  1302. Return Value:
  1303. None
  1304. --*/
  1305. {
  1306. PPDO_EXTENSION PdoExtension = ((PDEVICE_OBJECT) Context)->DeviceExtension;
  1307. PAGED_CODE();
  1308. ASSERT_PDO_EXTENSION( PdoExtension );
  1309. InterlockedIncrement( &PdoExtension->InterfaceReferenceCount );
  1310. }
  1311. VOID
  1312. HalPnpInterfaceDereference(
  1313. PVOID Context
  1314. )
  1315. /*++
  1316. Routine Description:
  1317. This function decrements the reference count on the interface context.
  1318. Arguments:
  1319. Context - Supplies a pointer to the interface context. This is actually
  1320. the PDO for the root bus.
  1321. Return Value:
  1322. None
  1323. --*/
  1324. {
  1325. PPDO_EXTENSION PdoExtension = ((PDEVICE_OBJECT) Context)->DeviceExtension;
  1326. LONG Result;
  1327. PAGED_CODE();
  1328. ASSERT_PDO_EXTENSION( PdoExtension );
  1329. Result = InterlockedDecrement( &PdoExtension->InterfaceReferenceCount );
  1330. ASSERT( Result >= 0 );
  1331. }
  1332. BOOLEAN
  1333. HalPnpTranslateBusAddress(
  1334. IN PVOID Context,
  1335. IN PHYSICAL_ADDRESS BusAddress,
  1336. IN ULONG Length,
  1337. IN OUT PULONG AddressSpace,
  1338. OUT PPHYSICAL_ADDRESS TranslatedAddress
  1339. )
  1340. /*++
  1341. Routine Description:
  1342. This function is used to translate bus addresses from legacy drivers. It really
  1343. should never get called on an ACPI system as the PCI or ACPI driver should field
  1344. these requests before it gets here.
  1345. Arguments:
  1346. Context - Supplies a pointer to the interface context. This is actually
  1347. the PDO for the root bus.
  1348. BusAddress - Supplies the orginal address to be translated.
  1349. Length - Supplies the length of the range to be translated.
  1350. AddressSpace - Points to the location of of the address space type such as
  1351. memory or I/O port. This value is updated by the translation.
  1352. TranslatedAddress - Returns the translated address.
  1353. Return Value:
  1354. Returns a boolean indicating if the operations was a success.
  1355. --*/
  1356. {
  1357. HalDebugPrint(( HAL_PNP, "HAL: HalPnpTranslateBusAddress Called, BusAddress = %p\n", BusAddress ));
  1358. *TranslatedAddress = BusAddress;
  1359. return TRUE;
  1360. }
  1361. PDMA_ADAPTER
  1362. HalPnpGetDmaAdapter(
  1363. IN PVOID Context,
  1364. IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
  1365. OUT PULONG NumberOfMapRegisters
  1366. )
  1367. /*++
  1368. Routine Description:
  1369. This function writes the PCI configuration space.
  1370. Arguments:
  1371. Context - Supplies a pointer to the interface context. This is actually
  1372. the PDO for the root bus.
  1373. DeviceDescriptor - Supplies the device descriptor used to allocate the dma
  1374. adapter object.
  1375. NubmerOfMapRegisters - Returns the maximum number of map registers a device
  1376. can allocate at one time.
  1377. Return Value:
  1378. Returns a DMA adapter or NULL.
  1379. --*/
  1380. {
  1381. PPDO_EXTENSION PdoExtension = ((PDEVICE_OBJECT) Context)->DeviceExtension;
  1382. PAGED_CODE();
  1383. ASSERT_PDO_EXTENSION( PdoExtension );
  1384. //
  1385. // Fill in the bus number.
  1386. //
  1387. return (PDMA_ADAPTER) HalGetAdapter( DeviceDescriptor, NumberOfMapRegisters );
  1388. }