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.

1030 lines
24 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. hanfnc.c
  5. Abstract:
  6. Default handlers for HAL functions which don't get handlers
  7. installed by the HAL.
  8. Author:
  9. Ken Reneris (kenr) 19-July-1994
  10. Revision History:
  11. --*/
  12. #include "ntos.h"
  13. #include "haldisp.h"
  14. HAL_DISPATCH HalDispatchTable = {
  15. HAL_DISPATCH_VERSION,
  16. xHalQuerySystemInformation,
  17. xHalSetSystemInformation,
  18. xHalQueryBusSlots,
  19. 0,
  20. HalExamineMBR,
  21. IoAssignDriveLetters,
  22. IoReadPartitionTable,
  23. IoSetPartitionInformation,
  24. IoWritePartitionTable,
  25. xHalHandlerForBus, // HalReferenceHandlerByBus
  26. xHalReferenceHandler, // HalReferenceBusHandler
  27. xHalReferenceHandler, // HalDereferenceBusHandler
  28. xHalInitPnpDriver,
  29. xHalInitPowerManagement,
  30. 0,
  31. xHalGetInterruptTranslator,
  32. xHalStartMirroring,
  33. xHalEndMirroring,
  34. xHalMirrorPhysicalMemory,
  35. xHalEndOfBoot,
  36. xHalMirrorVerify
  37. };
  38. HAL_PRIVATE_DISPATCH HalPrivateDispatchTable = {
  39. HAL_PRIVATE_DISPATCH_VERSION,
  40. xHalHandlerForBus,
  41. xHalHandlerForBus,
  42. xHalLocateHiberRanges,
  43. xHalRegisterBusHandler,
  44. xHalSetWakeEnable,
  45. xHalSetWakeAlarm,
  46. xHalTranslateBusAddress,
  47. xHalAssignSlotResources,
  48. xHalHaltSystem,
  49. (NULL), // HalFindBusAddressTranslation
  50. (NULL), // HalResetDisplay
  51. xKdSetupPciDeviceForDebugging,
  52. xKdReleasePciDeviceForDebugging,
  53. xKdGetAcpiTablePhase0,
  54. xKdCheckPowerButton,
  55. xHalVectorToIDTEntry,
  56. xKdMapPhysicalMemory64,
  57. xKdUnmapVirtualAddress,
  58. };
  59. #if 0
  60. DMA_OPERATIONS HalPrivateDmaOperations = {
  61. sizeof(DMA_OPERATIONS),
  62. xHalPutDmaAdapter,
  63. xHalAllocateCommonBuffer,
  64. xHalFreeCommonBuffer,
  65. xHalAllocateAdapterChannel,
  66. xHalFlushAdapterBuffers,
  67. xHalFreeAdapterChannel,
  68. xHalFreeMapRegisters,
  69. xHalMapTransfer,
  70. xHalGetDmaAlignment,
  71. xHalReadDmaCounter,
  72. xHalGetScatterGatherList,
  73. xHalPutScatterGatherList
  74. };
  75. #endif
  76. #ifdef ALLOC_PRAGMA
  77. #pragma alloc_text(PAGE, xHalLocateHiberRanges)
  78. #pragma alloc_text(PAGE, xHalQuerySystemInformation)
  79. #pragma alloc_text(PAGE, xHalSetSystemInformation)
  80. #pragma alloc_text(PAGE, xHalQueryBusSlots)
  81. #pragma alloc_text(PAGE, xHalRegisterBusHandler)
  82. #pragma alloc_text(PAGE, xHalStartMirroring)
  83. #pragma alloc_text(PAGE, xHalEndOfBoot)
  84. #pragma alloc_text(PAGELK, xHalSetWakeEnable)
  85. #pragma alloc_text(PAGELK, xHalSetWakeAlarm)
  86. #endif
  87. //
  88. // Global dispatch table for HAL apis
  89. //
  90. //
  91. // Stub handlers for HALs which don't provide the above functions
  92. //
  93. NTSTATUS
  94. xHalQuerySystemInformation(
  95. IN HAL_QUERY_INFORMATION_CLASS InformationClass,
  96. IN ULONG BufferSize,
  97. OUT PVOID Buffer,
  98. OUT PULONG ReturnedLength
  99. )
  100. {
  101. PAGED_CODE ();
  102. return STATUS_INVALID_LEVEL;
  103. }
  104. NTSTATUS
  105. xHalSetSystemInformation(
  106. IN HAL_SET_INFORMATION_CLASS InformationClass,
  107. IN ULONG BufferSize,
  108. OUT PVOID Buffer
  109. )
  110. {
  111. PAGED_CODE ();
  112. return STATUS_INVALID_LEVEL;
  113. }
  114. NTSTATUS
  115. xHalQueryBusSlots(
  116. IN PBUS_HANDLER BusHandler,
  117. IN ULONG BufferSize,
  118. OUT PULONG SlotNumbers,
  119. OUT PULONG ReturnedLength
  120. )
  121. {
  122. PAGED_CODE ();
  123. return STATUS_NOT_SUPPORTED;
  124. }
  125. NTSTATUS
  126. xHalRegisterBusHandler(
  127. IN INTERFACE_TYPE InterfaceType,
  128. IN BUS_DATA_TYPE ConfigurationSpace,
  129. IN ULONG BusNumber,
  130. IN INTERFACE_TYPE ParentBusType,
  131. IN ULONG ParentBusNumber,
  132. IN ULONG SizeofBusExtensionData,
  133. IN PINSTALL_BUS_HANDLER InstallBusHandler,
  134. OUT PBUS_HANDLER *BusHandler
  135. )
  136. {
  137. PAGED_CODE ();
  138. return STATUS_NOT_SUPPORTED;
  139. }
  140. VOID
  141. xHalSetWakeEnable(
  142. IN BOOLEAN Enable
  143. )
  144. {
  145. }
  146. VOID
  147. xHalSetWakeAlarm(
  148. IN ULONGLONG WakeTime,
  149. IN PTIME_FIELDS WakeTimeFields
  150. )
  151. {
  152. }
  153. VOID
  154. xHalLocateHiberRanges (
  155. IN PVOID MemoryMap
  156. )
  157. {
  158. }
  159. PBUS_HANDLER
  160. FASTCALL
  161. xHalHandlerForBus (
  162. IN INTERFACE_TYPE InterfaceType,
  163. IN ULONG BusNumber
  164. )
  165. {
  166. return NULL;
  167. }
  168. VOID
  169. FASTCALL
  170. xHalReferenceHandler (
  171. IN PBUS_HANDLER Handler
  172. )
  173. {
  174. }
  175. NTSTATUS
  176. xHalInitPnpDriver(
  177. VOID
  178. )
  179. {
  180. return STATUS_NOT_SUPPORTED;
  181. }
  182. NTSTATUS
  183. xHalInitPowerManagement(
  184. IN PPM_DISPATCH_TABLE PmDriverDispatchTable,
  185. IN OUT PPM_DISPATCH_TABLE *PmHalDispatchTable
  186. )
  187. {
  188. return STATUS_NOT_SUPPORTED;
  189. }
  190. NTSTATUS
  191. xHalStartMirroring(
  192. VOID
  193. )
  194. {
  195. PAGED_CODE ();
  196. return STATUS_NOT_SUPPORTED;
  197. }
  198. NTSTATUS
  199. xHalEndMirroring(
  200. IN ULONG PassNumber
  201. )
  202. {
  203. UNREFERENCED_PARAMETER (PassNumber);
  204. return STATUS_NOT_SUPPORTED;
  205. }
  206. NTSTATUS
  207. xHalMirrorPhysicalMemory(
  208. IN PHYSICAL_ADDRESS PhysicalAddress,
  209. IN LARGE_INTEGER NumberOfBytes
  210. )
  211. {
  212. return STATUS_NOT_SUPPORTED;
  213. }
  214. NTSTATUS
  215. xHalMirrorVerify(
  216. IN PHYSICAL_ADDRESS PhysicalAddress,
  217. IN LARGE_INTEGER NumberOfBytes
  218. )
  219. {
  220. return STATUS_NOT_SUPPORTED;
  221. }
  222. #if 0
  223. PDMA_ADAPTER
  224. xHalGetDmaAdapter (
  225. IN PVOID Context,
  226. IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
  227. OUT PULONG NumberOfMapRegisters
  228. )
  229. {
  230. PADAPTER_OBJECT AdapterObject;
  231. AdapterObject = ExAllocatePoolWithTag( NonPagedPool,
  232. sizeof( ADAPTER_OBJECT ),
  233. ' laH');
  234. if (AdapterObject == NULL) {
  235. return NULL;
  236. }
  237. AdapterObject->DmaAdapter.Size = sizeof( ADAPTER_OBJECT );
  238. AdapterObject->DmaAdapter.Version = 1;
  239. AdapterObject->DmaAdapter.DmaOperations = &HalPrivateDmaOperations;
  240. AdapterObject->RealAdapterObject = HalGetAdapter( DeviceDescriptor,
  241. NumberOfMapRegisters );
  242. if (AdapterObject->RealAdapterObject == NULL) {
  243. //
  244. // No adapter object was returned. Just return NULL to the caller.
  245. //
  246. ExFreePool( AdapterObject );
  247. return NULL;
  248. }
  249. return &AdapterObject->DmaAdapter;
  250. }
  251. VOID
  252. xHalPutDmaAdapter (
  253. PDMA_ADAPTER DmaAdapter
  254. )
  255. {
  256. ExFreePool( DmaAdapter );
  257. }
  258. PVOID
  259. xHalAllocateCommonBuffer (
  260. IN PDMA_ADAPTER DmaAdapter,
  261. IN ULONG Length,
  262. OUT PPHYSICAL_ADDRESS LogicalAddress,
  263. IN BOOLEAN CacheEnabled
  264. )
  265. {
  266. return HalAllocateCommonBuffer( ((PADAPTER_OBJECT) DmaAdapter)->RealAdapterObject,
  267. Length,
  268. LogicalAddress,
  269. CacheEnabled );
  270. }
  271. VOID
  272. xHalFreeCommonBuffer (
  273. IN PDMA_ADAPTER DmaAdapter,
  274. IN ULONG Length,
  275. IN PHYSICAL_ADDRESS LogicalAddress,
  276. IN PVOID VirtualAddress,
  277. IN BOOLEAN CacheEnabled
  278. )
  279. {
  280. HalFreeCommonBuffer( ((PADAPTER_OBJECT) DmaAdapter)->RealAdapterObject,
  281. Length,
  282. LogicalAddress,
  283. VirtualAddress,
  284. CacheEnabled );
  285. }
  286. NTSTATUS
  287. xHalAllocateAdapterChannel (
  288. IN PDMA_ADAPTER DmaAdapter,
  289. IN PDEVICE_OBJECT DeviceObject,
  290. IN ULONG NumberOfMapRegisters,
  291. IN PDRIVER_CONTROL ExecutionRoutine,
  292. IN PVOID Context
  293. )
  294. {
  295. return IoAllocateAdapterChannel( ((PADAPTER_OBJECT) DmaAdapter)->RealAdapterObject,
  296. DeviceObject,
  297. NumberOfMapRegisters,
  298. ExecutionRoutine,
  299. Context );
  300. }
  301. BOOLEAN
  302. xHalFlushAdapterBuffers (
  303. IN PDMA_ADAPTER DmaAdapter,
  304. IN PMDL Mdl,
  305. IN PVOID MapRegisterBase,
  306. IN PVOID CurrentVa,
  307. IN ULONG Length,
  308. IN BOOLEAN WriteToDevice
  309. )
  310. {
  311. return IoFlushAdapterBuffers( ((PADAPTER_OBJECT) DmaAdapter)->RealAdapterObject,
  312. Mdl,
  313. MapRegisterBase,
  314. CurrentVa,
  315. Length,
  316. WriteToDevice );
  317. }
  318. VOID
  319. xHalFreeAdapterChannel (
  320. IN PDMA_ADAPTER DmaAdapter
  321. )
  322. {
  323. IoFreeAdapterChannel( ((PADAPTER_OBJECT) DmaAdapter)->RealAdapterObject );
  324. }
  325. VOID
  326. xHalFreeMapRegisters (
  327. IN PDMA_ADAPTER DmaAdapter,
  328. PVOID MapRegisterBase,
  329. ULONG NumberOfMapRegisters
  330. )
  331. {
  332. IoFreeMapRegisters( ((PADAPTER_OBJECT) DmaAdapter)->RealAdapterObject,
  333. MapRegisterBase,
  334. NumberOfMapRegisters );
  335. }
  336. PHYSICAL_ADDRESS
  337. xHalMapTransfer (
  338. IN PDMA_ADAPTER DmaAdapter,
  339. IN PMDL Mdl,
  340. IN PVOID MapRegisterBase,
  341. IN PVOID CurrentVa,
  342. IN OUT PULONG Length,
  343. IN BOOLEAN WriteToDevice
  344. )
  345. {
  346. return IoMapTransfer( ((PADAPTER_OBJECT) DmaAdapter)->RealAdapterObject,
  347. Mdl,
  348. MapRegisterBase,
  349. CurrentVa,
  350. Length,
  351. WriteToDevice );
  352. }
  353. ULONG
  354. xHalGetDmaAlignment (
  355. IN PDMA_ADAPTER DmaAdapter
  356. )
  357. {
  358. return HalGetDmaAlignmentRequirement();
  359. }
  360. ULONG
  361. xHalReadDmaCounter (
  362. IN PDMA_ADAPTER DmaAdapter
  363. )
  364. {
  365. return HalReadDmaCounter( ((PADAPTER_OBJECT) DmaAdapter)->RealAdapterObject );
  366. }
  367. NTSTATUS
  368. xHalGetScatterGatherList (
  369. IN PDMA_ADAPTER DmaAdapter,
  370. IN PDEVICE_OBJECT DeviceObject,
  371. IN PMDL Mdl,
  372. IN PVOID CurrentVa,
  373. IN ULONG Length,
  374. IN PDRIVER_LIST_CONTROL ExecutionRoutine,
  375. IN PVOID Context,
  376. IN BOOLEAN WriteToDevice
  377. )
  378. /*++
  379. Routine Description:
  380. This routine allocates the adapter channel specified by the adapter
  381. object. Next a scatter/gather list is built based on the MDL, the
  382. CurrentVa and the requested Length. Finally the driver's execution
  383. function is called with the scatter/gather list. The adapter is
  384. released after the execution function returns.
  385. The scatter/gather list is freed by calling PutScatterGatherList.
  386. Arguments:
  387. DmaAdapter - Pointer to the adapter control object to allocate for the
  388. driver.
  389. DeviceObject - Pointer to the device object that is allocating the
  390. adapter.
  391. Mdl - Pointer to the MDL that describes the pages of memory that are being
  392. read or written.
  393. CurrentVa - Current virtual address in the buffer described by the MDL
  394. that the transfer is being done to or from.
  395. Length - Supplies the length of the transfer.
  396. ExecutionRoutine - The address of the driver's execution routine that is
  397. invoked once the adapter channel (and possibly map registers) have been
  398. allocated.
  399. Context - An untyped longword context parameter passed to the driver's
  400. execution routine.
  401. WriteToDevice - Supplies the value that indicates whether this is a
  402. write to the device from memory (TRUE), or vice versa.
  403. Return Value:
  404. Returns STATUS_SUCCESS unless too many map registers are requested or
  405. memory for the scatter/gather list could not be allocated.
  406. Notes:
  407. Note that this routine MUST be invoked at DISPATCH_LEVEL or above.
  408. The data in the buffer cannot be accessed until the put scatter/gather function has been called.
  409. --*/
  410. {
  411. PXHAL_WAIT_CONTEXT_BLOCK WaitBlock;
  412. PWAIT_CONTEXT_BLOCK Wcb;
  413. PMDL TempMdl;
  414. ULONG NumberOfMapRegisters;
  415. ULONG ContextSize;
  416. ULONG TransferLength;
  417. ULONG MdlLength;
  418. ULONG MdlCount;
  419. PUCHAR MdlVa;
  420. NTSTATUS Status;
  421. MdlVa = MmGetMdlVirtualAddress(Mdl);
  422. //
  423. // Calculate the number of required map registers.
  424. //
  425. TempMdl = Mdl;
  426. TransferLength = TempMdl->ByteCount - (ULONG)((PUCHAR) CurrentVa - MdlVa);
  427. MdlLength = TransferLength;
  428. MdlVa = (PUCHAR) BYTE_OFFSET(CurrentVa);
  429. NumberOfMapRegisters = 0;
  430. MdlCount = 1;
  431. //
  432. // Loop through the any chained MDLs accumulating the required
  433. // number of map registers.
  434. //
  435. while (TransferLength < Length && TempMdl->Next != NULL) {
  436. NumberOfMapRegisters += (ULONG)(((ULONG_PTR) MdlVa + MdlLength + PAGE_SIZE - 1) >>
  437. PAGE_SHIFT);
  438. TempMdl = TempMdl->Next;
  439. MdlVa = (PUCHAR) TempMdl->ByteOffset;
  440. MdlLength = TempMdl->ByteCount;
  441. TransferLength += MdlLength;
  442. MdlCount++;
  443. }
  444. if (TransferLength + PAGE_SIZE < (ULONG_PTR)(Length + MdlVa) ) {
  445. ASSERT(TransferLength >= Length);
  446. return(STATUS_BUFFER_TOO_SMALL);
  447. }
  448. //
  449. // Calculate the last number of map registers based on the requested
  450. // length - not the length of the last MDL.
  451. //
  452. ASSERT( TransferLength <= MdlLength + Length );
  453. NumberOfMapRegisters += (ULONG)(((ULONG_PTR) MdlVa + Length + MdlLength - TransferLength +
  454. PAGE_SIZE - 1) >> PAGE_SHIFT);
  455. //
  456. // Calculate how much memory is required for the context structure. This
  457. // this actually laid out as follows:
  458. //
  459. // XHAL_WAIT_CONTEXT_BLOCK;
  460. // MapRegisterBase[ MdlCount ];
  461. // union {
  462. // WAIT_CONTEXT_BLOCK[ MdlCount ];
  463. // SCATTER_GATHER_LIST [ NumberOfMapRegisters ];
  464. // };
  465. //
  466. ContextSize = NumberOfMapRegisters * sizeof( SCATTER_GATHER_ELEMENT ) +
  467. sizeof( SCATTER_GATHER_LIST );
  468. //
  469. // For each Mdl a separate Wcb is required since a separate map
  470. // register base must be allocated.
  471. //
  472. if (ContextSize < sizeof( WAIT_CONTEXT_BLOCK ) * MdlCount) {
  473. ContextSize = sizeof( WAIT_CONTEXT_BLOCK ) * MdlCount;
  474. }
  475. ContextSize += sizeof( XHAL_WAIT_CONTEXT_BLOCK ) +
  476. MdlCount * sizeof( PVOID );
  477. WaitBlock = ExAllocatePoolWithTag( NonPagedPool, ContextSize, ' laH' );
  478. if (WaitBlock == NULL) {
  479. return( STATUS_INSUFFICIENT_RESOURCES );
  480. }
  481. //
  482. // Store the wait context block at the end of our block.
  483. // All of the information in the wait block can be overwritten
  484. // by the scatter/gather list.
  485. //
  486. Wcb = (PWAIT_CONTEXT_BLOCK) ((PVOID *) (WaitBlock + 1) + MdlCount);
  487. //
  488. // Save the interesting data in the wait block.
  489. //
  490. WaitBlock->Mdl = Mdl;
  491. WaitBlock->CurrentVa = CurrentVa;
  492. WaitBlock->Length = Length;
  493. WaitBlock->RealAdapterObject = ((PADAPTER_OBJECT) DmaAdapter)->RealAdapterObject;
  494. WaitBlock->DriverExecutionRoutine = ExecutionRoutine;
  495. WaitBlock->DriverContext = Context;
  496. WaitBlock->CurrentIrp = DeviceObject->CurrentIrp;
  497. WaitBlock->MapRegisterLock = MdlCount;
  498. WaitBlock->WriteToDevice = WriteToDevice;
  499. WaitBlock->MdlCount = (UCHAR) MdlCount;
  500. //
  501. // Loop through each of the required MDLs, calling
  502. // IoAllocateAdapterChannel.
  503. //
  504. MdlCount = 0;
  505. TempMdl = Mdl;
  506. TransferLength = Length;
  507. MdlLength = TempMdl->ByteCount - (ULONG)((PUCHAR) CurrentVa - (PUCHAR) MmGetMdlVirtualAddress(Mdl));
  508. MdlVa = (PUCHAR) BYTE_OFFSET(CurrentVa);
  509. NumberOfMapRegisters = 0;
  510. //
  511. // Loop through the chained MDLs accumulating the required
  512. // number of map registers.
  513. //
  514. while (TransferLength > 0) {
  515. if (MdlLength > TransferLength) {
  516. MdlLength = TransferLength;
  517. }
  518. TransferLength -= MdlLength;
  519. NumberOfMapRegisters = (ULONG)(((ULONG_PTR) MdlVa + MdlLength + PAGE_SIZE - 1) >>
  520. PAGE_SHIFT);
  521. Wcb->DeviceContext = WaitBlock;
  522. Wcb->DeviceObject = DeviceObject;
  523. //
  524. // Store the map register index in the IRP pointer.
  525. //
  526. Wcb->CurrentIrp = (PVOID) MdlCount;
  527. //
  528. // Call the HAL to allocate the adapter channel.
  529. // xHalpAllocateAdapterCallback will fill in the scatter/gather list.
  530. //
  531. Status = HalAllocateAdapterChannel( ((PADAPTER_OBJECT) DmaAdapter)->RealAdapterObject,
  532. Wcb,
  533. NumberOfMapRegisters,
  534. xHalpAllocateAdapterCallback );
  535. if (TempMdl->Next == NULL) {
  536. break;
  537. }
  538. //
  539. // Advance to next MDL.
  540. //
  541. TempMdl = TempMdl->Next;
  542. MdlVa = (PUCHAR) TempMdl->ByteOffset;
  543. MdlLength = TempMdl->ByteCount;
  544. MdlCount++;
  545. Wcb++;
  546. }
  547. //
  548. // If HalAllocateAdapterChannel failed then free the wait block.
  549. //
  550. if (!NT_SUCCESS( Status)) {
  551. ExFreePool( WaitBlock );
  552. }
  553. return( Status );
  554. }
  555. VOID
  556. xHalPutScatterGatherList (
  557. IN PDMA_ADAPTER DmaAdapter,
  558. IN PSCATTER_GATHER_LIST ScatterGather,
  559. IN BOOLEAN WriteToDevice
  560. )
  561. {
  562. PXHAL_WAIT_CONTEXT_BLOCK WaitBlock = (PVOID) ScatterGather->Reserved;
  563. ULONG TransferLength;
  564. ULONG MdlLength;
  565. ULONG MdlCount = 0;
  566. PMDL Mdl;
  567. PUCHAR CurrentVa;
  568. //
  569. // Setup for the first MDL. We expect the MDL pointer to be pointing
  570. // at the first used MDL.
  571. //
  572. Mdl = WaitBlock->Mdl;
  573. CurrentVa = WaitBlock->CurrentVa;
  574. ASSERT( CurrentVa >= (PUCHAR) MmGetMdlVirtualAddress(Mdl) && CurrentVa < (PUCHAR) MmGetMdlVirtualAddress(Mdl) + Mdl->ByteCount );
  575. MdlLength = Mdl->ByteCount - (ULONG)(CurrentVa - (PUCHAR) MmGetMdlVirtualAddress(Mdl));
  576. TransferLength = WaitBlock->Length;
  577. //
  578. // Loop through the used MDLs calling IoFlushAdapterBuffers.
  579. //
  580. while (TransferLength > 0) {
  581. if (MdlLength > TransferLength) {
  582. MdlLength = TransferLength;
  583. }
  584. TransferLength -= MdlLength;
  585. IoFlushAdapterBuffers( WaitBlock->RealAdapterObject,
  586. Mdl,
  587. WaitBlock->MapRegisterBase[MdlCount],
  588. CurrentVa,
  589. MdlLength,
  590. WriteToDevice );
  591. if (Mdl->Next == NULL) {
  592. break;
  593. }
  594. //
  595. // Advance to the next MDL. Update the current VA and the MdlLength.
  596. //
  597. Mdl = Mdl->Next;
  598. CurrentVa = MmGetMdlVirtualAddress(Mdl);
  599. MdlLength = Mdl->ByteCount;
  600. MdlCount++;
  601. }
  602. ExFreePool( WaitBlock );
  603. }
  604. IO_ALLOCATION_ACTION
  605. xHalpAllocateAdapterCallback (
  606. IN struct _DEVICE_OBJECT *DeviceObject,
  607. IN struct _IRP *Irp,
  608. IN PVOID MapRegisterBase,
  609. IN PVOID Context
  610. )
  611. /*++
  612. Routine Description:
  613. This routine is called when the adapter object and map registers are
  614. available for the data transfer. This routine saves the map register
  615. base away. If all of the required bases have not been saved then it
  616. returns. Otherwise it builds the entire scatter/gather list by calling
  617. IoMapTransfer. After the list is built, it is passed to the driver.
  618. Arguments:
  619. DeviceObject - Pointer to the device object that is allocating the
  620. adapter.
  621. Irp - Supplies the map register offset assigned for this callback.
  622. MapRegisterBase - Supplies the map register base for use by the adapter
  623. routines.
  624. Context - Supplies a pointer to the xhal wait control block.
  625. Return Value:
  626. Returns DeallocateObjectKeepRegisters.
  627. --*/
  628. {
  629. PXHAL_WAIT_CONTEXT_BLOCK WaitBlock = Context;
  630. PVOID *MapRegisterBasePtr;
  631. ULONG TransferLength;
  632. LONG MdlLength;
  633. PMDL Mdl;
  634. PUCHAR CurrentVa;
  635. PSCATTER_GATHER_LIST ScatterGather;
  636. PSCATTER_GATHER_ELEMENT Element;
  637. //
  638. // Save the map register base in the appropriate slot.
  639. //
  640. WaitBlock->MapRegisterBase[ (ULONG_PTR) Irp ] = MapRegisterBase;
  641. //
  642. // See if this is the last callback.
  643. //
  644. if (InterlockedDecrement( &WaitBlock->MapRegisterLock ) != 0) {
  645. //
  646. // More to come, wait for the rest.
  647. //
  648. return( DeallocateObjectKeepRegisters );
  649. }
  650. //
  651. // Put the scatter gather list after wait block. Add a back pointer to
  652. // the beginning of the wait block.
  653. //
  654. MapRegisterBasePtr = (PVOID *) (WaitBlock + 1);
  655. ScatterGather = (PSCATTER_GATHER_LIST) (MapRegisterBasePtr +
  656. WaitBlock->MdlCount);
  657. ScatterGather->Reserved = (ULONG_PTR) WaitBlock;
  658. Element = ScatterGather->Elements;
  659. //
  660. // Setup for the first MDL. We expect the MDL pointer to be pointing
  661. // at the first used MDL.
  662. //
  663. Mdl = WaitBlock->Mdl;
  664. CurrentVa = WaitBlock->CurrentVa;
  665. ASSERT( CurrentVa >= (PUCHAR) MmGetMdlVirtualAddress(Mdl) && CurrentVa < (PUCHAR) MmGetMdlVirtualAddress(Mdl) + Mdl->ByteCount );
  666. MdlLength = Mdl->ByteCount - (ULONG)(CurrentVa - (PUCHAR) MmGetMdlVirtualAddress(Mdl));
  667. TransferLength = WaitBlock->Length;
  668. //
  669. // Loop build the list for each MDL.
  670. //
  671. while (TransferLength > 0) {
  672. if ((ULONG) MdlLength > TransferLength) {
  673. MdlLength = TransferLength;
  674. }
  675. TransferLength -= MdlLength;
  676. //
  677. // Loop building the list for the elements within an MDL.
  678. //
  679. while (MdlLength > 0) {
  680. Element->Length = MdlLength;
  681. Element->Address = IoMapTransfer( WaitBlock->RealAdapterObject,
  682. Mdl,
  683. *MapRegisterBasePtr,
  684. CurrentVa,
  685. &Element->Length,
  686. WaitBlock->WriteToDevice );
  687. ASSERT( (ULONG) MdlLength >= Element->Length );
  688. MdlLength -= Element->Length;
  689. CurrentVa += Element->Length;
  690. Element++;
  691. }
  692. if (Mdl->Next == NULL) {
  693. //
  694. // There are a few cases where the buffer described by the MDL
  695. // is less than the transfer length. This occurs when the
  696. // file system is transfering the last page of the file and MM
  697. // defines the MDL to be file size and the file system rounds
  698. // the write up to a sector. This extra amount should never
  699. // cross a page boundary. Add this extra to the length of the
  700. // last element.
  701. //
  702. ASSERT(((Element - 1)->Length & (PAGE_SIZE - 1)) + TransferLength <= PAGE_SIZE );
  703. (Element - 1)->Length += TransferLength;
  704. break;
  705. }
  706. //
  707. // Advance to the next MDL. Update the current VA and the MdlLength.
  708. //
  709. Mdl = Mdl->Next;
  710. CurrentVa = MmGetMdlVirtualAddress(Mdl);
  711. MdlLength = Mdl->ByteCount;
  712. MapRegisterBasePtr++;
  713. }
  714. //
  715. // Set the number of elements actually used.
  716. //
  717. ScatterGather->NumberOfElements = (ULONG)(Element - ScatterGather->Elements);
  718. //
  719. // Call the driver with the scatter/gather list.
  720. //
  721. WaitBlock->DriverExecutionRoutine( DeviceObject,
  722. WaitBlock->CurrentIrp,
  723. ScatterGather,
  724. WaitBlock->DriverContext );
  725. return( DeallocateObjectKeepRegisters );
  726. }
  727. #endif
  728. BOOLEAN
  729. xHalTranslateBusAddress(
  730. IN INTERFACE_TYPE InterfaceType,
  731. IN ULONG BusNumber,
  732. IN PHYSICAL_ADDRESS BusAddress,
  733. IN OUT PULONG AddressSpace,
  734. OUT PPHYSICAL_ADDRESS TranslatedAddress
  735. )
  736. {
  737. //
  738. // If the HAL fails to override this function, then
  739. // the HAL has clearly failed to initialize.
  740. //
  741. KeBugCheckEx(HAL_INITIALIZATION_FAILED, 0, 0, 0, 7);
  742. return FALSE;
  743. }
  744. NTSTATUS
  745. xHalAssignSlotResources (
  746. IN PUNICODE_STRING RegistryPath,
  747. IN PUNICODE_STRING DriverClassName OPTIONAL,
  748. IN PDRIVER_OBJECT DriverObject,
  749. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  750. IN INTERFACE_TYPE BusType,
  751. IN ULONG BusNumber,
  752. IN ULONG SlotNumber,
  753. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  754. )
  755. {
  756. //
  757. // If the HAL fails to override this function, then
  758. // the HAL has clearly failed to initialize.
  759. //
  760. KeBugCheckEx(HAL_INITIALIZATION_FAILED, 0, 0, 0, 7);
  761. return STATUS_NOT_IMPLEMENTED;
  762. }
  763. VOID
  764. xHalHaltSystem(
  765. VOID
  766. )
  767. {
  768. for (;;) ;
  769. }
  770. NTSTATUS
  771. xKdSetupPciDeviceForDebugging(
  772. IN PVOID LoaderBlock, OPTIONAL
  773. IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice
  774. )
  775. {
  776. return STATUS_NOT_IMPLEMENTED;
  777. }
  778. NTSTATUS
  779. xKdReleasePciDeviceForDebugging(
  780. IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice
  781. )
  782. {
  783. return STATUS_NOT_IMPLEMENTED;
  784. }
  785. PVOID
  786. xKdGetAcpiTablePhase0(
  787. IN PLOADER_PARAMETER_BLOCK LoaderBlock,
  788. IN ULONG Signature
  789. )
  790. {
  791. return NULL;
  792. }
  793. VOID
  794. xKdCheckPowerButton(
  795. VOID
  796. )
  797. {
  798. return;
  799. }
  800. VOID
  801. xHalEndOfBoot(
  802. VOID
  803. )
  804. {
  805. PAGED_CODE();
  806. return;
  807. }
  808. UCHAR
  809. xHalVectorToIDTEntry(
  810. ULONG Vector
  811. )
  812. {
  813. return (UCHAR)Vector;
  814. }
  815. PVOID
  816. xKdMapPhysicalMemory64(
  817. IN PHYSICAL_ADDRESS PhysicalAddress,
  818. IN ULONG NumberPages
  819. )
  820. {
  821. return NULL;
  822. }
  823. VOID
  824. xKdUnmapVirtualAddress(
  825. IN PVOID VirtualAddress,
  826. IN ULONG NumberPages
  827. )
  828. {
  829. return;
  830. }