Source code of Windows XP (NT5)
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.

1012 lines
30 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. report.c
  5. Abstract:
  6. This module contains the subroutines used to report resources used by
  7. the drivers and the HAL into the registry resource map.
  8. Author:
  9. Andre Vachon (andreva) 15-Dec-1992
  10. Environment:
  11. Kernel mode, local to I/O system
  12. Revision History:
  13. --*/
  14. #include "pnpmgrp.h"
  15. #pragma hdrstop
  16. #include <hdlsblk.h>
  17. #include <hdlsterm.h>
  18. #define DBG_AR 0
  19. #define MAX_MEMORY_RUN_LENGTH ((ULONG)~(PAGE_SIZE - 1))
  20. extern const WCHAR IopWstrRaw[];
  21. extern const WCHAR IopWstrTranslated[];
  22. extern const WCHAR IopWstrBusTranslated[];
  23. extern const WCHAR IopWstrOtherDrivers[];
  24. extern const WCHAR IopWstrHal[];
  25. extern const WCHAR IopWstrSystem[];
  26. extern const WCHAR IopWstrPhysicalMemory[];
  27. extern const WCHAR IopWstrSpecialMemory[];
  28. extern const WCHAR IopWstrLoaderReservedMemory[];
  29. BOOLEAN
  30. IopChangeInterfaceType(
  31. IN OUT PIO_RESOURCE_REQUIREMENTS_LIST IoResources,
  32. IN OUT PCM_RESOURCE_LIST *AllocatedResource
  33. );
  34. #ifdef ALLOC_PRAGMA
  35. #pragma alloc_text(PAGE, IoReportResourceUsageInternal)
  36. #pragma alloc_text(PAGE, IoReportResourceUsage)
  37. #pragma alloc_text(PAGE, IoReportResourceForDetection)
  38. #pragma alloc_text(PAGE, IopChangeInterfaceType)
  39. #pragma alloc_text(PAGE, IopWriteResourceList)
  40. #pragma alloc_text(INIT, IopInitializeResourceMap)
  41. #pragma alloc_text(INIT, IoReportHalResourceUsage)
  42. #endif
  43. VOID
  44. IopInitializeResourceMap (
  45. PLOADER_PARAMETER_BLOCK LoaderBlock
  46. )
  47. /*++
  48. Initializes the resource map by adding in the physical memory
  49. which is in use by the system.
  50. --*/
  51. {
  52. ULONG i, j, pass, length;
  53. LARGE_INTEGER li;
  54. HANDLE keyHandle;
  55. UNICODE_STRING unicodeString, systemString, listString;
  56. NTSTATUS status;
  57. PCM_RESOURCE_LIST ResourceList;
  58. PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor;
  59. BOOLEAN IncludeType[LoaderMaximum];
  60. PPHYSICAL_MEMORY_DESCRIPTOR MemoryBlock;
  61. LONGLONG rangeLength;
  62. RtlInitUnicodeString( &systemString, IopWstrSystem);
  63. for (pass=0; pass < 3; pass += 1) {
  64. switch (pass) {
  65. case 0:
  66. //
  67. // Add MmPhysicalMemoryBlock to registry
  68. //
  69. RtlInitUnicodeString( &unicodeString, IopWstrPhysicalMemory);
  70. RtlInitUnicodeString( &listString, IopWstrTranslated );
  71. MemoryBlock = MmPhysicalMemoryBlock;
  72. break;
  73. case 1:
  74. //
  75. // Add LoaderSpecialMemory and LoaderHALCachedMemory
  76. // to registry
  77. //
  78. RtlInitUnicodeString( &unicodeString, IopWstrSpecialMemory);
  79. RtlInitUnicodeString( &listString, IopWstrTranslated );
  80. //
  81. // Compute memory limits of LoaderSpecialMemory and
  82. // LoaderHalCachedMemory
  83. //
  84. for (j=0; j < LoaderMaximum; j += 1) {
  85. IncludeType[j] = FALSE;
  86. }
  87. IncludeType[LoaderSpecialMemory] = TRUE;
  88. IncludeType[LoaderHALCachedMemory] = TRUE;
  89. MemoryBlock = MmInitializeMemoryLimits (LoaderBlock,
  90. IncludeType,
  91. NULL);
  92. if (MemoryBlock == NULL) {
  93. continue;
  94. }
  95. break;
  96. case 2:
  97. //
  98. // Create registry key that includes:
  99. // LoaderBad
  100. // LoaderFirmwarePermanent
  101. // LoaderSpecialMemory
  102. // LoaderBBTMemory
  103. // LoaderHALCachedMemory
  104. //
  105. RtlInitUnicodeString( &unicodeString, IopWstrLoaderReservedMemory);
  106. RtlInitUnicodeString( &listString, IopWstrRaw );
  107. //
  108. // Compute memory limits of specified loader memory
  109. // descriptors.
  110. //
  111. for (j=0; j < LoaderMaximum; j += 1) {
  112. IncludeType[j] = FALSE;
  113. }
  114. IncludeType[LoaderBad] = TRUE;
  115. IncludeType[LoaderFirmwarePermanent] = TRUE;
  116. IncludeType[LoaderSpecialMemory] = TRUE;
  117. IncludeType[LoaderBBTMemory] = TRUE;
  118. IncludeType[LoaderHALCachedMemory] = TRUE;
  119. MemoryBlock = MmInitializeMemoryLimits (LoaderBlock,
  120. IncludeType,
  121. NULL);
  122. if (MemoryBlock == NULL) {
  123. return;
  124. }
  125. break;
  126. }
  127. //
  128. // Allocate and build a CM_RESOURCE_LIST to describe all
  129. // of physical memory
  130. //
  131. j = MemoryBlock->NumberOfRuns;
  132. if (j == 0) {
  133. if (pass != 0) {
  134. ExFreePool (MemoryBlock);
  135. }
  136. continue;
  137. }
  138. //
  139. // This is to take care of systems where individual memory run can
  140. // exceed 4G since our current descriptors only have 32-bit length.
  141. // Account for runs with length > MAX_MEMORY_RUN_LENGTH by splitting
  142. // them into lengths <= MAX_MEMORY_RUN_LENGTH.
  143. //
  144. for (i = 0; i < MemoryBlock->NumberOfRuns; i += 1) {
  145. rangeLength = ((LONGLONG)MemoryBlock->Run[i].PageCount) << PAGE_SHIFT;
  146. while ((rangeLength -= MAX_MEMORY_RUN_LENGTH) > 0) {
  147. j += 1;
  148. }
  149. }
  150. length = sizeof(CM_RESOURCE_LIST) + (j-1) * sizeof (CM_PARTIAL_RESOURCE_DESCRIPTOR);
  151. ResourceList = (PCM_RESOURCE_LIST) ExAllocatePool (PagedPool, length);
  152. if (!ResourceList) {
  153. if (pass != 0) {
  154. ExFreePool (MemoryBlock);
  155. }
  156. return;
  157. }
  158. RtlZeroMemory ((PVOID) ResourceList, length);
  159. ResourceList->Count = 1;
  160. ResourceList->List[0].PartialResourceList.Count = j;
  161. CmDescriptor = ResourceList->List[0].PartialResourceList.PartialDescriptors;
  162. for (i=0; i < MemoryBlock->NumberOfRuns; i += 1) {
  163. rangeLength = ((LONGLONG)MemoryBlock->Run[i].PageCount) << PAGE_SHIFT;
  164. li.QuadPart = ((LONGLONG)MemoryBlock->Run[i].BasePage) << PAGE_SHIFT;
  165. //
  166. // Split up runs > MAX_MEMORY_RUN_LENGTH into multiple descriptors
  167. // with lengths <= MAX_MEMORY_RUN_LENGTH. All descriptors (except
  168. // the last one) have length = MAX_MEMORY_RUN_LENGTH. Length of the
  169. // last one is the remaining portion.
  170. //
  171. do {
  172. CmDescriptor->Type = CmResourceTypeMemory;
  173. CmDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
  174. CmDescriptor->u.Memory.Start = li;
  175. CmDescriptor->u.Memory.Length = MAX_MEMORY_RUN_LENGTH;
  176. CmDescriptor++;
  177. li.QuadPart += MAX_MEMORY_RUN_LENGTH;
  178. } while ((rangeLength -= MAX_MEMORY_RUN_LENGTH) > 0);
  179. //
  180. // Adjust the length of the last one.
  181. //
  182. (CmDescriptor - 1)->u.Memory.Length = (ULONG)(rangeLength + MAX_MEMORY_RUN_LENGTH);
  183. }
  184. //
  185. // Add the resource list to the resourcemap
  186. //
  187. status = IopOpenRegistryKey( &keyHandle,
  188. (HANDLE) NULL,
  189. &CmRegistryMachineHardwareResourceMapName,
  190. KEY_READ | KEY_WRITE,
  191. TRUE );
  192. if (NT_SUCCESS( status )) {
  193. IopWriteResourceList ( keyHandle,
  194. &systemString,
  195. &unicodeString,
  196. &listString,
  197. ResourceList,
  198. length
  199. );
  200. ZwClose( keyHandle );
  201. }
  202. ExFreePool (ResourceList);
  203. if (pass != 0) {
  204. ExFreePool (MemoryBlock);
  205. }
  206. }
  207. }
  208. NTSTATUS
  209. IoReportHalResourceUsage(
  210. IN PUNICODE_STRING HalName,
  211. IN PCM_RESOURCE_LIST RawResourceList,
  212. IN PCM_RESOURCE_LIST TranslatedResourceList,
  213. IN ULONG ResourceListSize
  214. )
  215. /*++
  216. Routine Description:
  217. This routine is called by the HAL to report its resources.
  218. The HAL is the first component to report its resources, so we don't need
  219. to acquire the resourcemap semaphore and we do not need to check for
  220. conflicts.
  221. Arguments:
  222. HalName - Name of the HAL reporting the resources.
  223. RawResourceList - Pointer to the HAL's raw resource list.
  224. TranslatedResourceList - Pointer to the HAL's translated resource list.
  225. DriverListSize - Value determining the size of the HAL's resource list.
  226. Return Value:
  227. The status returned is the final completion status of the operation.
  228. --*/
  229. {
  230. HANDLE keyHandle;
  231. UNICODE_STRING halString;
  232. UNICODE_STRING listString;
  233. NTSTATUS status;
  234. PCM_RESOURCE_LIST NewList = NULL;
  235. ULONG NewListSize;
  236. PCM_RESOURCE_LIST NewTranslatedList;
  237. ULONG NewTranslatedListSize;
  238. PAGED_CODE();
  239. //
  240. // First open a handle to the RESOURCEMAP key.
  241. //
  242. RtlInitUnicodeString( &halString, IopWstrHal );
  243. status = IopOpenRegistryKey( &keyHandle,
  244. (HANDLE) NULL,
  245. &CmRegistryMachineHardwareResourceMapName,
  246. KEY_READ | KEY_WRITE,
  247. TRUE );
  248. //
  249. // Write out the raw resource list
  250. //
  251. if (NT_SUCCESS( status )) {
  252. RtlInitUnicodeString( &listString, IopWstrRaw);
  253. //
  254. // Add any resources that Headless is reserving.
  255. //
  256. status = HeadlessTerminalAddResources(RawResourceList,
  257. ResourceListSize,
  258. FALSE,
  259. &NewList,
  260. &NewListSize
  261. );
  262. if (NT_SUCCESS(status)) {
  263. status = IopWriteResourceList( keyHandle,
  264. &halString,
  265. HalName,
  266. &listString,
  267. (NewList != NULL) ? NewList : RawResourceList,
  268. (NewList != NULL) ? NewListSize : ResourceListSize
  269. );
  270. }
  271. //
  272. // If we successfully wrote out the raw resource list, write out
  273. // the translated resource list.
  274. //
  275. if (NT_SUCCESS( status )) {
  276. RtlInitUnicodeString( &listString, IopWstrTranslated);
  277. //
  278. // Add any resources that Headless is reserving.
  279. //
  280. status = HeadlessTerminalAddResources(TranslatedResourceList,
  281. ResourceListSize,
  282. TRUE,
  283. &NewTranslatedList,
  284. &NewTranslatedListSize
  285. );
  286. if (NT_SUCCESS(status)) {
  287. status = IopWriteResourceList(keyHandle,
  288. &halString,
  289. HalName,
  290. &listString,
  291. (NewTranslatedList != NULL) ?
  292. NewTranslatedList : TranslatedResourceList,
  293. (NewTranslatedList != NULL) ?
  294. NewTranslatedListSize : ResourceListSize
  295. );
  296. if (NewTranslatedList != NULL) {
  297. ExFreePool(NewTranslatedList);
  298. }
  299. }
  300. }
  301. ZwClose( keyHandle );
  302. }
  303. //
  304. // If every resource looks fine, we will store the copy of the HAL
  305. // resources so we can call Arbiters to reserve the resources after
  306. // they are initialized.
  307. //
  308. if (NT_SUCCESS(status)) {
  309. if (NewList != NULL) {
  310. //
  311. // An easy way is if headless created a new list for us, just don't free it.
  312. //
  313. IopInitHalResources = NewList;
  314. } else {
  315. //
  316. // Otherwise we have to create a copy ourselves.
  317. //
  318. IopInitHalResources = (PCM_RESOURCE_LIST) ExAllocatePool(PagedPool,
  319. ResourceListSize
  320. );
  321. if (IopInitHalResources != NULL) {
  322. RtlCopyMemory(IopInitHalResources, RawResourceList, ResourceListSize);
  323. } else {
  324. status = STATUS_INSUFFICIENT_RESOURCES;
  325. }
  326. }
  327. } else if (NewList != NULL) {
  328. //
  329. // Free any failed list
  330. //
  331. ExFreePool(NewList);
  332. }
  333. return status;
  334. }
  335. NTSTATUS
  336. IoReportResourceForDetection(
  337. IN PDRIVER_OBJECT DriverObject,
  338. IN PCM_RESOURCE_LIST DriverList OPTIONAL,
  339. IN ULONG DriverListSize OPTIONAL,
  340. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  341. IN PCM_RESOURCE_LIST DeviceList OPTIONAL,
  342. IN ULONG DeviceListSize OPTIONAL,
  343. OUT PBOOLEAN ConflictDetected
  344. )
  345. /*++
  346. Routine Description:
  347. This routine will automatically search through the configuration
  348. registry for resource conflicts between resources requested by a device
  349. and the resources already claimed by previously installed drivers. The
  350. contents of the DriverList and the DeviceList will be matched against
  351. all the other resource list stored in the registry to determine
  352. conflicts.
  353. The function may be called more than once for a given device or driver.
  354. If a new resource list is given, the previous resource list stored in
  355. the registry will be replaced by the new list.
  356. Note, this function is for the drivers acquiring resources for detection.
  357. Arguments:
  358. DriverObject - Pointer to the driver's driver object.
  359. DriverList - Optional pointer to the driver's resource list.
  360. DriverListSize - Optional value determining the size of the driver's
  361. resource list.
  362. DeviceObject - Optional pointer to driver's device object.
  363. DeviceList - Optional pointer to the device's resource list.
  364. DriverListSize - Optional value determining the size of the device's
  365. resource list.
  366. ConflictDetected - Supplies a pointer to a boolean that is set to TRUE
  367. if the resource list conflicts with an already existing resource
  368. list in the configuration registry.
  369. Return Value:
  370. The status returned is the final completion status of the operation.
  371. --*/
  372. {
  373. //
  374. // Sanity check that the caller did not pass in a PnP PDO.
  375. //
  376. if (DeviceObject) {
  377. if ( DeviceObject->DeviceObjectExtension->DeviceNode &&
  378. !(((PDEVICE_NODE)DeviceObject->DeviceObjectExtension->DeviceNode)->Flags & DNF_LEGACY_RESOURCE_DEVICENODE)) {
  379. PP_SAVE_DRIVEROBJECT_TO_TRIAGE_DUMP(DriverObject);
  380. PP_SAVE_DEVICEOBJECT_TO_TRIAGE_DUMP(DeviceObject);
  381. KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, PNP_ERR_INVALID_PDO, (ULONG_PTR)DeviceObject, 0, 0);
  382. }
  383. }
  384. return IoReportResourceUsageInternal( ArbiterRequestPnpDetected,
  385. NULL,
  386. DriverObject,
  387. DriverList,
  388. DriverListSize,
  389. DeviceObject,
  390. DeviceList,
  391. DeviceListSize,
  392. FALSE,
  393. ConflictDetected);
  394. }
  395. NTSTATUS
  396. IoReportResourceUsage(
  397. IN PUNICODE_STRING DriverClassName OPTIONAL,
  398. IN PDRIVER_OBJECT DriverObject,
  399. IN PCM_RESOURCE_LIST DriverList OPTIONAL,
  400. IN ULONG DriverListSize OPTIONAL,
  401. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  402. IN PCM_RESOURCE_LIST DeviceList OPTIONAL,
  403. IN ULONG DeviceListSize OPTIONAL,
  404. IN BOOLEAN OverrideConflict,
  405. OUT PBOOLEAN ConflictDetected
  406. )
  407. /*++
  408. Routine Description:
  409. This routine will automatically search through the configuration
  410. registry for resource conflicts between resources requested by a device
  411. and the resources already claimed by previously installed drivers. The
  412. contents of the DriverList and the DeviceList will be matched against
  413. all the other resource list stored in the registry to determine
  414. conflicts.
  415. If not conflict was detected, or if the OverrideConflict flag is set,
  416. this routine will create appropriate entries in the system resource map
  417. (in the registry) that will contain the specified resource lists.
  418. The function may be called more than once for a given device or driver.
  419. If a new resource list is given, the previous resource list stored in
  420. the registry will be replaced by the new list.
  421. Arguments:
  422. DriverClassName - Optional pointer to a UNICODE_STRING which describes
  423. the class of driver under which the driver information should be
  424. stored. A default type is used if none is given.
  425. DriverObject - Pointer to the driver's driver object.
  426. DriverList - Optional pointer to the driver's resource list.
  427. DriverListSize - Optional value determining the size of the driver's
  428. resource list.
  429. DeviceObject - Optional pointer to driver's device object.
  430. DeviceList - Optional pointer to the device's resource list.
  431. DriverListSize - Optional value determining the size of the driver's
  432. resource list.
  433. OverrideConflict - Determines if the information should be reported
  434. in the configuration registry eventhough a conflict was found with
  435. another driver or device.
  436. ConflictDetected - Supplies a pointer to a boolean that is set to TRUE
  437. if the resource list conflicts with an already existing resource
  438. list in the configuration registry.
  439. Return Value:
  440. The status returned is the final completion status of the operation.
  441. --*/
  442. {
  443. if (DeviceObject) {
  444. if ( DeviceObject->DeviceObjectExtension->DeviceNode &&
  445. !(((PDEVICE_NODE)DeviceObject->DeviceObjectExtension->DeviceNode)->Flags & DNF_LEGACY_RESOURCE_DEVICENODE)) {
  446. PP_SAVE_DRIVEROBJECT_TO_TRIAGE_DUMP(DriverObject);
  447. PP_SAVE_DEVICEOBJECT_TO_TRIAGE_DUMP(DeviceObject);
  448. KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, PNP_ERR_INVALID_PDO, (ULONG_PTR)DeviceObject, 0, 0);
  449. }
  450. }
  451. return IoReportResourceUsageInternal( ArbiterRequestLegacyReported,
  452. DriverClassName,
  453. DriverObject,
  454. DriverList,
  455. DriverListSize,
  456. DeviceObject,
  457. DeviceList,
  458. DeviceListSize,
  459. OverrideConflict,
  460. ConflictDetected);
  461. }
  462. NTSTATUS
  463. IoReportResourceUsageInternal(
  464. IN ARBITER_REQUEST_SOURCE AllocationType,
  465. IN PUNICODE_STRING DriverClassName OPTIONAL,
  466. IN PDRIVER_OBJECT DriverObject,
  467. IN PCM_RESOURCE_LIST DriverList OPTIONAL,
  468. IN ULONG DriverListSize OPTIONAL,
  469. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  470. IN PCM_RESOURCE_LIST DeviceList OPTIONAL,
  471. IN ULONG DeviceListSize OPTIONAL,
  472. IN BOOLEAN OverrideConflict,
  473. OUT PBOOLEAN ConflictDetected
  474. )
  475. /*++
  476. Routine Description:
  477. This internal routine will do all the work for IoReportResourceUsage.
  478. Arguments:
  479. AllocationType - Specifies the request type.
  480. DriverClassName - Optional pointer to a UNICODE_STRING which describes
  481. the class of driver under which the driver information should be
  482. stored. A default type is used if none is given.
  483. DriverObject - Pointer to the driver's driver object.
  484. DriverList - Optional pointer to the driver's resource list.
  485. DriverListSize - Optional value determining the size of the driver's
  486. resource list.
  487. DeviceObject - Optional pointer to driver's device object.
  488. DeviceList - Optional pointer to the device's resource list.
  489. DriverListSize - Optional value determining the size of the driver's
  490. resource list.
  491. OverrideConflict - Determines if the information should be reported
  492. in the configuration registry eventhough a conflict was found with
  493. another driver or device.
  494. ConflictDetected - Supplies a pointer to a boolean that is set to TRUE
  495. if the resource list conflicts with an already existing resource
  496. list in the configuration registry.
  497. Return Value:
  498. The status returned is the final completion status of the operation.
  499. --*/
  500. {
  501. NTSTATUS status = STATUS_UNSUCCESSFUL;
  502. PCM_RESOURCE_LIST resourceList;
  503. PCM_RESOURCE_LIST allocatedResources;
  504. PIO_RESOURCE_REQUIREMENTS_LIST resourceRequirements;
  505. ULONG attempt;
  506. BOOLEAN freeAllocatedResources;
  507. UNREFERENCED_PARAMETER( DriverClassName );
  508. UNREFERENCED_PARAMETER( DriverListSize );
  509. UNREFERENCED_PARAMETER( DeviceListSize );
  510. UNREFERENCED_PARAMETER( OverrideConflict );
  511. ASSERT(DriverObject && ConflictDetected);
  512. if (DeviceList) {
  513. resourceList = DeviceList;
  514. } else if (DriverList) {
  515. resourceList = DriverList;
  516. } else {
  517. resourceList = NULL;
  518. }
  519. resourceRequirements = NULL;
  520. if (resourceList) {
  521. if (resourceList->Count && resourceList->List[0].PartialResourceList.Count) {
  522. resourceRequirements = IopCmResourcesToIoResources (0, resourceList, LCPRI_NORMAL);
  523. if (resourceRequirements == NULL) {
  524. return status;
  525. }
  526. } else {
  527. resourceList = NULL;
  528. }
  529. }
  530. *ConflictDetected = TRUE;
  531. attempt = 0;
  532. allocatedResources = resourceList;
  533. freeAllocatedResources = FALSE;
  534. do {
  535. //
  536. // Do the legacy resource allocation.
  537. //
  538. status = IopLegacyResourceAllocation ( AllocationType,
  539. DriverObject,
  540. DeviceObject,
  541. resourceRequirements,
  542. &allocatedResources);
  543. if (NT_SUCCESS(status)) {
  544. *ConflictDetected = FALSE;
  545. break;
  546. }
  547. //
  548. // Change the interface type and try again.
  549. //
  550. if (!IopChangeInterfaceType(resourceRequirements, &allocatedResources)) {
  551. break;
  552. }
  553. freeAllocatedResources = TRUE;
  554. } while (++attempt < 2);
  555. if (resourceRequirements) {
  556. ExFreePool(resourceRequirements);
  557. }
  558. if (freeAllocatedResources) {
  559. ExFreePool(allocatedResources);
  560. }
  561. if (NT_SUCCESS(status)) {
  562. status = STATUS_SUCCESS;
  563. } else if (status != STATUS_INSUFFICIENT_RESOURCES) {
  564. status = STATUS_CONFLICTING_ADDRESSES;
  565. }
  566. return status;
  567. }
  568. BOOLEAN
  569. IopChangeInterfaceType(
  570. IN OUT PIO_RESOURCE_REQUIREMENTS_LIST IoResources,
  571. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  572. )
  573. /*++
  574. Routine Description:
  575. This routine takes an Io resourcelist and changes its interfacetype
  576. from internal to default type (isa or eisa or mca).
  577. Arguments:
  578. IoResources - Pointer to requirement list.
  579. AllocatedResources - Pointer to a variable that receives the pointer to the resource list.
  580. Return Value:
  581. BOOLEAN value to indicate if the change was made or not.
  582. --*/
  583. {
  584. PIO_RESOURCE_LIST IoResourceList;
  585. PIO_RESOURCE_DESCRIPTOR IoResourceDescriptor;
  586. PIO_RESOURCE_DESCRIPTOR IoResourceDescriptorEnd;
  587. LONG IoResourceListCount;
  588. BOOLEAN changed;
  589. ASSERT(AllocatedResources);
  590. changed = FALSE;
  591. if (!IoResources) {
  592. return changed;
  593. }
  594. if (IoResources->InterfaceType == Internal) {
  595. IoResources->InterfaceType = PnpDefaultInterfaceType;
  596. changed = TRUE;
  597. }
  598. IoResourceList = IoResources->List;
  599. IoResourceListCount = IoResources->AlternativeLists;
  600. while (--IoResourceListCount >= 0) {
  601. IoResourceDescriptor = IoResourceList->Descriptors;
  602. IoResourceDescriptorEnd = IoResourceDescriptor + IoResourceList->Count;
  603. for (;IoResourceDescriptor < IoResourceDescriptorEnd; IoResourceDescriptor++) {
  604. if (IoResourceDescriptor->Type == CmResourceTypeReserved &&
  605. IoResourceDescriptor->u.DevicePrivate.Data[0] == Internal) {
  606. IoResourceDescriptor->u.DevicePrivate.Data[0] = PnpDefaultInterfaceType;
  607. changed = TRUE;
  608. }
  609. }
  610. IoResourceList = (PIO_RESOURCE_LIST) IoResourceDescriptorEnd;
  611. }
  612. if (changed) {
  613. PCM_RESOURCE_LIST oldResources = *AllocatedResources;
  614. PCM_RESOURCE_LIST newResources;
  615. PCM_FULL_RESOURCE_DESCRIPTOR cmFullDesc;
  616. PCM_PARTIAL_RESOURCE_DESCRIPTOR cmPartDesc;
  617. ULONG size;
  618. if (oldResources) {
  619. size = IopDetermineResourceListSize(oldResources);
  620. newResources = ExAllocatePool(PagedPool, size);
  621. if (newResources == NULL) {
  622. changed = FALSE;
  623. } else {
  624. ULONG i;
  625. ULONG j;
  626. RtlCopyMemory(newResources, oldResources, size);
  627. //
  628. // Fix up the interface type
  629. //
  630. cmFullDesc = &newResources->List[0];
  631. for (i = 0; i < oldResources->Count; i++) {
  632. if (cmFullDesc->InterfaceType == Internal) {
  633. cmFullDesc->InterfaceType = PnpDefaultInterfaceType;
  634. }
  635. cmPartDesc = &cmFullDesc->PartialResourceList.PartialDescriptors[0];
  636. for (j = 0; j < cmFullDesc->PartialResourceList.Count; j++) {
  637. size = 0;
  638. switch (cmPartDesc->Type) {
  639. case CmResourceTypeDeviceSpecific:
  640. size = cmPartDesc->u.DeviceSpecificData.DataSize;
  641. break;
  642. }
  643. cmPartDesc++;
  644. cmPartDesc = (PCM_PARTIAL_RESOURCE_DESCRIPTOR) ((PUCHAR)cmPartDesc + size);
  645. }
  646. cmFullDesc = (PCM_FULL_RESOURCE_DESCRIPTOR)cmPartDesc;
  647. }
  648. *AllocatedResources = newResources;
  649. }
  650. }
  651. }
  652. return changed;
  653. }
  654. NTSTATUS
  655. IopWriteResourceList(
  656. HANDLE ResourceMapKey,
  657. PUNICODE_STRING ClassName,
  658. PUNICODE_STRING DriverName,
  659. PUNICODE_STRING DeviceName,
  660. PCM_RESOURCE_LIST ResourceList,
  661. ULONG ResourceListSize
  662. )
  663. /*++
  664. Routine Description:
  665. This routine takes a resourcelist and stores it in the registry resource
  666. map, using the ClassName, DriverName and DeviceName as the path of the
  667. key to store it in.
  668. Arguments:
  669. ResourceMapKey - Handle to the root of the resource map.
  670. ClassName - Pointer to a Unicode String that contains the name of the Class
  671. for this resource list.
  672. DriverName - Pointer to a Unicode String that contains the name of the
  673. Driver for this resource list.
  674. DeviceName - Pointer to a Unicode String that contains the name of the
  675. Device for this resource list.
  676. ResourceList - P to the resource list.
  677. ResourceListSize - Value determining the size of the resource list.
  678. Return Value:
  679. The status returned is the final completion status of the operation.
  680. --*/
  681. {
  682. NTSTATUS status;
  683. HANDLE classKeyHandle;
  684. HANDLE driverKeyHandle;
  685. PAGED_CODE();
  686. status = IopOpenRegistryKey( &classKeyHandle,
  687. ResourceMapKey,
  688. ClassName,
  689. KEY_READ | KEY_WRITE,
  690. TRUE );
  691. if (NT_SUCCESS( status )) {
  692. //
  693. // Take the resulting name to create the key.
  694. //
  695. status = IopOpenRegistryKey( &driverKeyHandle,
  696. classKeyHandle,
  697. DriverName,
  698. KEY_READ | KEY_WRITE,
  699. TRUE );
  700. ZwClose( classKeyHandle );
  701. if (NT_SUCCESS( status )) {
  702. //
  703. // With this key handle, we can now store the required information
  704. // in the value entries of the key.
  705. //
  706. //
  707. // Store the device name as a value name and the device information
  708. // as the rest of the data.
  709. // Only store the information if the CM_RESOURCE_LIST was present.
  710. //
  711. if (ResourceList->Count == 0) {
  712. status = ZwDeleteValueKey( driverKeyHandle,
  713. DeviceName );
  714. } else {
  715. status = ZwSetValueKey( driverKeyHandle,
  716. DeviceName,
  717. 0L,
  718. REG_RESOURCE_LIST,
  719. ResourceList,
  720. ResourceListSize );
  721. }
  722. ZwClose( driverKeyHandle );
  723. }
  724. }
  725. return status;
  726. }