3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/hal/x86/dma.c
6 * PURPOSE: DMA functions
7 * PROGRAMMERS: David Welch (welch@mcmail.com)
8 * Filip Navara (navaraf@reactos.com)
14 * @page DMA Implementation Notes
20 * Abstract encapsulation of physically contiguous buffer that resides
21 * in memory accessible by both the DMA device / controller and the system.
22 * The map registers are allocated and distributed on demand and are
25 * The actual use of map registers is to allow transfers from/to buffer
26 * located in physical memory at address inaccessible by the DMA device /
27 * controller directly. For such transfers the map register buffers
28 * are used as intermediate data storage.
32 * A container for map registers (typically corresponding to one physical
33 * bus connection type). There can be master adapters for 24-bit address
34 * ranges, 32-bit address ranges, etc. Every time a new DMA adapter is
35 * created it's associated with a corresponding master adapter that
36 * is used for any map register allocation requests.
38 * - Bus-master / Slave DMA
40 * Slave DMA is term used for DMA transfers done by the system (E)ISA
41 * controller as opposed to transfers mastered by the device itself
44 * For slave DMA special care is taken to actually access the system
45 * controller and handle the transfers. The relevant code is in
46 * HalpDmaInitializeEisaAdapter, HalReadDmaCounter, IoFlushAdapterBuffers
51 * - Allocation of map registers
53 * Initial set of map registers is allocated on the system start to
54 * ensure that low memory won't get filled up later. Additional map
55 * registers are allocated as needed by HalpGrowMapBuffers. This
56 * routine is called on two places:
58 * - HalGetAdapter, since we're at PASSIVE_LEVEL and it's known that
59 * more map registers will probably be needed.
60 * - IoAllocateAdapterChannel (indirectly using HalpGrowMapBufferWorker
61 * since we're at DISPATCH_LEVEL and call HalpGrowMapBuffers directly)
62 * when no more map registers are free.
64 * Note that even if no more map registers can be allocated it's not
65 * the end of the world. The adapters waiting for free map registers
66 * are queued in the master adapter's queue and once one driver hands
67 * back it's map registers (using IoFreeMapRegisters or indirectly using
68 * the execution routine callback in IoAllocateAdapterChannel) the
69 * queue gets processed and the map registers are reassigned.
72 /* INCLUDES *****************************************************************/
78 #define MAX_SG_ELEMENTS 0x10
81 static KEVENT HalpDmaLock
;
82 static LIST_ENTRY HalpDmaAdapterList
;
83 static PADAPTER_OBJECT HalpEisaAdapter
[8];
85 static BOOLEAN HalpEisaDma
;
87 static PADAPTER_OBJECT HalpMasterAdapter
;
90 static const ULONG_PTR HalpEisaPortPage
[8] = {
91 FIELD_OFFSET(DMA_PAGE
, Channel0
),
92 FIELD_OFFSET(DMA_PAGE
, Channel1
),
93 FIELD_OFFSET(DMA_PAGE
, Channel2
),
94 FIELD_OFFSET(DMA_PAGE
, Channel3
),
96 FIELD_OFFSET(DMA_PAGE
, Channel5
),
97 FIELD_OFFSET(DMA_PAGE
, Channel6
),
98 FIELD_OFFSET(DMA_PAGE
, Channel7
)
102 static DMA_OPERATIONS HalpDmaOperations
= {
103 sizeof(DMA_OPERATIONS
),
104 (PPUT_DMA_ADAPTER
)HalPutDmaAdapter
,
105 (PALLOCATE_COMMON_BUFFER
)HalAllocateCommonBuffer
,
106 (PFREE_COMMON_BUFFER
)HalFreeCommonBuffer
,
107 NULL
, /* Initialized in HalpInitDma() */
108 NULL
, /* Initialized in HalpInitDma() */
109 NULL
, /* Initialized in HalpInitDma() */
110 NULL
, /* Initialized in HalpInitDma() */
111 NULL
, /* Initialized in HalpInitDma() */
112 (PGET_DMA_ALIGNMENT
)HalpDmaGetDmaAlignment
,
113 (PREAD_DMA_COUNTER
)HalReadDmaCounter
,
114 /* FIXME: Implement the S/G funtions. */
115 (PGET_SCATTER_GATHER_LIST
)HalGetScatterGatherList
,
116 (PPUT_SCATTER_GATHER_LIST
)HalPutScatterGatherList
,
117 NULL
/*(PCALCULATE_SCATTER_GATHER_LIST_SIZE)HalCalculateScatterGatherListSize*/,
118 NULL
/*(PBUILD_SCATTER_GATHER_LIST)HalBuildScatterGatherList*/,
119 NULL
/*(PBUILD_MDL_FROM_SCATTER_GATHER_LIST)HalBuildMdlFromScatterGatherList*/
123 #define MAX_MAP_REGISTERS 64
125 #define TAG_DMA ' AMD'
127 /* FUNCTIONS *****************************************************************/
135 * Initialize the DMA Operation table
137 HalpDmaOperations
.AllocateAdapterChannel
= (PALLOCATE_ADAPTER_CHANNEL
)IoAllocateAdapterChannel
;
138 HalpDmaOperations
.FlushAdapterBuffers
= (PFLUSH_ADAPTER_BUFFERS
)IoFlushAdapterBuffers
;
139 HalpDmaOperations
.FreeAdapterChannel
= (PFREE_ADAPTER_CHANNEL
)IoFreeAdapterChannel
;
140 HalpDmaOperations
.FreeMapRegisters
= (PFREE_MAP_REGISTERS
)IoFreeMapRegisters
;
141 HalpDmaOperations
.MapTransfer
= (PMAP_TRANSFER
)IoMapTransfer
;
144 * Check if Extended DMA is available. We're just going to do a random
147 WRITE_PORT_UCHAR((PUCHAR
)FIELD_OFFSET(EISA_CONTROL
, DmaController2Pages
.Channel2
), 0x2A);
148 if (READ_PORT_UCHAR((PUCHAR
)FIELD_OFFSET(EISA_CONTROL
, DmaController2Pages
.Channel2
)) == 0x2A)
154 * Intialize all the global variables and allocate master adapter with
157 InitializeListHead(&HalpDmaAdapterList
);
158 KeInitializeEvent(&HalpDmaLock
, NotificationEvent
, TRUE
);
159 HalpMasterAdapter
= HalpDmaAllocateMasterAdapter();
162 * Setup the HalDispatchTable callback for creating PnP DMA adapters. It's
163 * used by IoGetDmaAdapter in the kernel.
165 HalGetDmaAdapter
= HalpGetDmaAdapter
;
170 * @name HalpGetAdapterMaximumPhysicalAddress
172 * Get the maximum physical address acceptable by the device represented
173 * by the passed DMA adapter.
177 HalpGetAdapterMaximumPhysicalAddress(IN PADAPTER_OBJECT AdapterObject
)
179 PHYSICAL_ADDRESS HighestAddress
;
181 if (AdapterObject
->MasterDevice
)
183 if (AdapterObject
->Dma64BitAddresses
)
185 HighestAddress
.QuadPart
= 0xFFFFFFFFFFFFFFFFULL
;
186 return HighestAddress
;
188 else if (AdapterObject
->Dma32BitAddresses
)
190 HighestAddress
.QuadPart
= 0xFFFFFFFF;
191 return HighestAddress
;
195 HighestAddress
.QuadPart
= 0xFFFFFF;
196 return HighestAddress
;
201 * @name HalpGrowMapBuffers
203 * Allocate initial, or additional, map buffers for DMA master adapter.
205 * @param MasterAdapter
206 * DMA master adapter to allocate buffers for.
207 * @param SizeOfMapBuffers
208 * Size of the map buffers to allocate (not including the size
209 * already allocated).
213 HalpGrowMapBuffers(IN PADAPTER_OBJECT AdapterObject
,
214 IN ULONG SizeOfMapBuffers
)
216 PVOID VirtualAddress
;
217 PHYSICAL_ADDRESS PhysicalAddress
;
218 PHYSICAL_ADDRESS HighestAcceptableAddress
;
219 PHYSICAL_ADDRESS LowestAcceptableAddress
;
220 PHYSICAL_ADDRESS BoundryAddressMultiple
;
222 ULONG MapRegisterCount
;
224 /* Check if enough map register slots are available. */
225 MapRegisterCount
= BYTES_TO_PAGES(SizeOfMapBuffers
);
226 if (MapRegisterCount
+ AdapterObject
->NumberOfMapRegisters
> MAX_MAP_REGISTERS
)
228 DPRINT("No more map register slots available! (Current: %d | Requested: %d | Limit: %d)\n",
229 AdapterObject
->NumberOfMapRegisters
,
236 * Allocate memory for the new map registers. For 32-bit adapters we use
237 * two passes in order not to waste scare resource (low memory).
239 HighestAcceptableAddress
= HalpGetAdapterMaximumPhysicalAddress(AdapterObject
);
240 LowestAcceptableAddress
.HighPart
= 0;
241 LowestAcceptableAddress
.LowPart
= HighestAcceptableAddress
.LowPart
== 0xFFFFFFFF ? 0x1000000 : 0;
242 BoundryAddressMultiple
.QuadPart
= 0;
244 VirtualAddress
= MmAllocateContiguousMemorySpecifyCache(MapRegisterCount
<< PAGE_SHIFT
,
245 LowestAcceptableAddress
,
246 HighestAcceptableAddress
,
247 BoundryAddressMultiple
,
249 if (!(VirtualAddress
) && (LowestAcceptableAddress
.LowPart
))
251 LowestAcceptableAddress
.LowPart
= 0;
252 VirtualAddress
= MmAllocateContiguousMemorySpecifyCache(MapRegisterCount
<< PAGE_SHIFT
,
253 LowestAcceptableAddress
,
254 HighestAcceptableAddress
,
255 BoundryAddressMultiple
,
259 if (!VirtualAddress
) return FALSE
;
261 PhysicalAddress
= MmGetPhysicalAddress(VirtualAddress
);
264 * All the following must be done with the master adapter lock held
265 * to prevent corruption.
267 KeAcquireSpinLock(&AdapterObject
->SpinLock
, &OldIrql
);
270 * Setup map register entries for the buffer allocated. Each entry has
271 * a virtual and physical address and corresponds to PAGE_SIZE large
274 if (MapRegisterCount
> 0)
276 PROS_MAP_REGISTER_ENTRY CurrentEntry
, PreviousEntry
;
278 CurrentEntry
= AdapterObject
->MapRegisterBase
+ AdapterObject
->NumberOfMapRegisters
;
282 * Leave one entry free for every non-contiguous memory region
283 * in the map register bitmap. This ensures that we can search
284 * using RtlFindClearBits for contiguous map register regions.
286 * Also for non-EISA DMA leave one free entry for every 64Kb
287 * break, because the DMA controller can handle only coniguous
290 if (CurrentEntry
!= AdapterObject
->MapRegisterBase
)
292 PreviousEntry
= CurrentEntry
- 1;
293 if ((PreviousEntry
->PhysicalAddress
.LowPart
+ PAGE_SIZE
) == PhysicalAddress
.LowPart
)
297 if ((PreviousEntry
->PhysicalAddress
.LowPart
^ PhysicalAddress
.LowPart
) & 0xFFFF0000)
300 AdapterObject
->NumberOfMapRegisters
++;
307 AdapterObject
->NumberOfMapRegisters
++;
311 RtlClearBit(AdapterObject
->MapRegisters
,
312 CurrentEntry
- AdapterObject
->MapRegisterBase
);
313 CurrentEntry
->VirtualAddress
= VirtualAddress
;
314 CurrentEntry
->PhysicalAddress
= PhysicalAddress
;
316 PhysicalAddress
.LowPart
+= PAGE_SIZE
;
317 VirtualAddress
= (PVOID
)((ULONG_PTR
)VirtualAddress
+ PAGE_SIZE
);
320 AdapterObject
->NumberOfMapRegisters
++;
322 } while (MapRegisterCount
);
325 KeReleaseSpinLock(&AdapterObject
->SpinLock
, OldIrql
);
331 * @name HalpDmaAllocateMasterAdapter
333 * Helper routine to allocate and initialize master adapter object and it's
334 * associated map register buffers.
340 HalpDmaAllocateMasterAdapter(VOID
)
342 PADAPTER_OBJECT MasterAdapter
;
343 ULONG Size
, SizeOfBitmap
;
345 SizeOfBitmap
= MAX_MAP_REGISTERS
;
346 Size
= sizeof(ADAPTER_OBJECT
);
347 Size
+= sizeof(RTL_BITMAP
);
348 Size
+= (SizeOfBitmap
+ 7) >> 3;
350 MasterAdapter
= ExAllocatePoolWithTag(NonPagedPool
, Size
, TAG_DMA
);
351 if (!MasterAdapter
) return NULL
;
353 RtlZeroMemory(MasterAdapter
, Size
);
355 KeInitializeSpinLock(&MasterAdapter
->SpinLock
);
356 InitializeListHead(&MasterAdapter
->AdapterQueue
);
358 MasterAdapter
->MapRegisters
= (PVOID
)(MasterAdapter
+ 1);
359 RtlInitializeBitMap(MasterAdapter
->MapRegisters
,
360 (PULONG
)(MasterAdapter
->MapRegisters
+ 1),
362 RtlSetAllBits(MasterAdapter
->MapRegisters
);
363 MasterAdapter
->NumberOfMapRegisters
= 0;
364 MasterAdapter
->CommittedMapRegisters
= 0;
366 MasterAdapter
->MapRegisterBase
= ExAllocatePoolWithTag(NonPagedPool
,
368 sizeof(ROS_MAP_REGISTER_ENTRY
),
370 if (!MasterAdapter
->MapRegisterBase
)
372 ExFreePool(MasterAdapter
);
376 RtlZeroMemory(MasterAdapter
->MapRegisterBase
,
377 SizeOfBitmap
* sizeof(ROS_MAP_REGISTER_ENTRY
));
378 if (!HalpGrowMapBuffers(MasterAdapter
, 0x10000))
380 ExFreePool(MasterAdapter
);
384 return MasterAdapter
;
388 * @name HalpDmaAllocateChildAdapter
390 * Helper routine of HalGetAdapter. Allocate child adapter object and
391 * fill out some basic fields.
397 HalpDmaAllocateChildAdapter(IN ULONG NumberOfMapRegisters
,
398 IN PDEVICE_DESCRIPTION DeviceDescription
)
400 PADAPTER_OBJECT AdapterObject
;
401 OBJECT_ATTRIBUTES ObjectAttributes
;
405 InitializeObjectAttributes(&ObjectAttributes
,
407 OBJ_KERNEL_HANDLE
| OBJ_PERMANENT
,
411 Status
= ObCreateObject(KernelMode
,
416 sizeof(ADAPTER_OBJECT
),
419 (PVOID
)&AdapterObject
);
420 if (!NT_SUCCESS(Status
)) return NULL
;
422 Status
= ObReferenceObjectByPointer(AdapterObject
,
423 FILE_READ_DATA
| FILE_WRITE_DATA
,
426 if (!NT_SUCCESS(Status
)) return NULL
;
428 RtlZeroMemory(AdapterObject
, sizeof(ADAPTER_OBJECT
));
430 Status
= ObInsertObject(AdapterObject
,
432 FILE_READ_DATA
| FILE_WRITE_DATA
,
436 if (!NT_SUCCESS(Status
)) return NULL
;
440 AdapterObject
->DmaHeader
.Version
= (USHORT
)DeviceDescription
->Version
;
441 AdapterObject
->DmaHeader
.Size
= sizeof(ADAPTER_OBJECT
);
442 AdapterObject
->DmaHeader
.DmaOperations
= &HalpDmaOperations
;
443 AdapterObject
->MapRegistersPerChannel
= 1;
444 AdapterObject
->Dma32BitAddresses
= DeviceDescription
->Dma32BitAddresses
;
445 AdapterObject
->ChannelNumber
= 0xFF;
446 AdapterObject
->MasterAdapter
= HalpMasterAdapter
;
447 KeInitializeDeviceQueue(&AdapterObject
->ChannelWaitQueue
);
449 return AdapterObject
;
454 * @name HalpDmaInitializeEisaAdapter
456 * Setup DMA modes and extended modes for (E)ISA DMA adapter object.
460 HalpDmaInitializeEisaAdapter(IN PADAPTER_OBJECT AdapterObject
,
461 IN PDEVICE_DESCRIPTION DeviceDescription
)
464 DMA_MODE DmaMode
= {{0 }};
465 DMA_EXTENDED_MODE ExtendedMode
= {{ 0 }};
468 Controller
= (DeviceDescription
->DmaChannel
& 4) ? 2 : 1;
472 AdapterBaseVa
= (PVOID
)FIELD_OFFSET(EISA_CONTROL
, DmaController1
);
476 AdapterBaseVa
= (PVOID
)FIELD_OFFSET(EISA_CONTROL
, DmaController2
);
479 AdapterObject
->AdapterNumber
= Controller
;
480 AdapterObject
->ChannelNumber
= (UCHAR
)(DeviceDescription
->DmaChannel
& 3);
481 AdapterObject
->PagePort
= (PUCHAR
)HalpEisaPortPage
[DeviceDescription
->DmaChannel
];
482 AdapterObject
->Width16Bits
= FALSE
;
483 AdapterObject
->AdapterBaseVa
= AdapterBaseVa
;
487 ExtendedMode
.ChannelNumber
= AdapterObject
->ChannelNumber
;
489 switch (DeviceDescription
->DmaSpeed
)
491 case Compatible
: ExtendedMode
.TimingMode
= COMPATIBLE_TIMING
; break;
492 case TypeA
: ExtendedMode
.TimingMode
= TYPE_A_TIMING
; break;
493 case TypeB
: ExtendedMode
.TimingMode
= TYPE_B_TIMING
; break;
494 case TypeC
: ExtendedMode
.TimingMode
= BURST_TIMING
; break;
499 switch (DeviceDescription
->DmaWidth
)
501 case Width8Bits
: ExtendedMode
.TransferSize
= B_8BITS
; break;
502 case Width16Bits
: ExtendedMode
.TransferSize
= B_16BITS
; break;
503 case Width32Bits
: ExtendedMode
.TransferSize
= B_32BITS
; break;
510 WRITE_PORT_UCHAR((PUCHAR
)FIELD_OFFSET(EISA_CONTROL
, DmaExtendedMode1
),
515 WRITE_PORT_UCHAR((PUCHAR
)FIELD_OFFSET(EISA_CONTROL
, DmaExtendedMode2
),
522 * Validate setup for non-busmaster DMA adapter. Secondary controller
523 * supports only 16-bit transfers and main controller supports only
524 * 8-bit transfers. Anything else is invalid.
526 if (!DeviceDescription
->Master
)
528 if ((Controller
== 2) && (DeviceDescription
->DmaWidth
== Width16Bits
))
530 AdapterObject
->Width16Bits
= TRUE
;
532 else if ((Controller
!= 1) || (DeviceDescription
->DmaWidth
!= Width8Bits
))
539 DmaMode
.Channel
= AdapterObject
->ChannelNumber
;
540 DmaMode
.AutoInitialize
= DeviceDescription
->AutoInitialize
;
543 * Set the DMA request mode.
545 * For (E)ISA bus master devices just unmask (enable) the DMA channel
546 * and set it to cascade mode. Otherwise just select the right one
547 * bases on the passed device description.
549 if (DeviceDescription
->Master
)
551 DmaMode
.RequestMode
= CASCADE_REQUEST_MODE
;
554 /* Set the Request Data */
555 WRITE_PORT_UCHAR(&((PDMA1_CONTROL
)AdapterBaseVa
)->Mode
, DmaMode
.Byte
);
557 /* Unmask DMA Channel */
558 WRITE_PORT_UCHAR(&((PDMA1_CONTROL
)AdapterBaseVa
)->SingleMask
,
559 AdapterObject
->ChannelNumber
| DMA_CLEARMASK
);
563 /* Set the Request Data */
564 WRITE_PORT_UCHAR(&((PDMA2_CONTROL
)AdapterBaseVa
)->Mode
, DmaMode
.Byte
);
566 /* Unmask DMA Channel */
567 WRITE_PORT_UCHAR(&((PDMA2_CONTROL
)AdapterBaseVa
)->SingleMask
,
568 AdapterObject
->ChannelNumber
| DMA_CLEARMASK
);
573 if (DeviceDescription
->DemandMode
)
575 DmaMode
.RequestMode
= DEMAND_REQUEST_MODE
;
579 DmaMode
.RequestMode
= SINGLE_REQUEST_MODE
;
583 AdapterObject
->AdapterMode
= DmaMode
;
590 * @name HalGetAdapter
592 * Allocate an adapter object for DMA device.
594 * @param DeviceDescription
595 * Structure describing the attributes of the device.
596 * @param NumberOfMapRegisters
597 * On return filled with the maximum number of map registers the
598 * device driver can allocate for DMA transfer operations.
600 * @return The DMA adapter on success, NULL otherwise.
606 HalGetAdapter(IN PDEVICE_DESCRIPTION DeviceDescription
,
607 OUT PULONG NumberOfMapRegisters
)
609 PADAPTER_OBJECT AdapterObject
= NULL
;
614 /* Validate parameters in device description */
615 if (DeviceDescription
->Version
> DEVICE_DESCRIPTION_VERSION2
) return NULL
;
618 * See if we're going to use ISA/EISA DMA adapter. These adapters are
619 * special since they're reused.
621 * Also note that we check for channel number since there are only 8 DMA
622 * channels on ISA, so any request above this requires new adapter.
624 if (((DeviceDescription
->InterfaceType
== Eisa
) ||
625 (DeviceDescription
->InterfaceType
== Isa
)) || !(DeviceDescription
->Master
))
627 if (((DeviceDescription
->InterfaceType
== Isa
) ||
628 (DeviceDescription
->InterfaceType
== Eisa
)) &&
629 (DeviceDescription
->DmaChannel
>= 8))
644 * Disallow creating adapter for ISA/EISA DMA channel 4 since it's used
645 * for cascading the controllers and it's not available for software use.
647 if ((EisaAdapter
) && (DeviceDescription
->DmaChannel
== 4)) return NULL
;
650 * Calculate the number of map registers.
652 * - For EISA and PCI scatter/gather no map registers are needed.
653 * - For ISA slave scatter/gather one map register is needed.
654 * - For all other cases the number of map registers depends on
655 * DeviceDescription->MaximumLength.
657 MaximumLength
= DeviceDescription
->MaximumLength
& MAXLONG
;
658 if ((DeviceDescription
->ScatterGather
) &&
659 ((DeviceDescription
->InterfaceType
== Eisa
) ||
660 (DeviceDescription
->InterfaceType
== PCIBus
)))
664 else if ((DeviceDescription
->ScatterGather
) && !(DeviceDescription
->Master
))
671 * In the equation below the additional map register added by
672 * the "+1" accounts for the case when a transfer does not start
673 * at a page-aligned address.
675 MapRegisters
= BYTES_TO_PAGES(MaximumLength
) + 1;
676 if (MapRegisters
> 16) MapRegisters
= 16;
680 * Acquire the DMA lock that is used to protect adapter lists and
681 * EISA adapter array.
683 KeWaitForSingleObject(&HalpDmaLock
, Executive
, KernelMode
, FALSE
, NULL
);
686 * Now we must get ahold of the adapter object. For first eight ISA/EISA
687 * channels there are static adapter objects that are reused and updated
688 * on succesive HalGetAdapter calls. In other cases a new adapter object
689 * is always created and it's to the DMA adapter list (HalpDmaAdapterList).
693 AdapterObject
= HalpEisaAdapter
[DeviceDescription
->DmaChannel
];
696 if ((AdapterObject
->NeedsMapRegisters
) &&
697 (MapRegisters
> AdapterObject
->MapRegistersPerChannel
))
699 AdapterObject
->MapRegistersPerChannel
= MapRegisters
;
704 if (AdapterObject
== NULL
)
706 AdapterObject
= HalpDmaAllocateChildAdapter(MapRegisters
, DeviceDescription
);
707 if (AdapterObject
== NULL
)
709 KeSetEvent(&HalpDmaLock
, 0, 0);
715 HalpEisaAdapter
[DeviceDescription
->DmaChannel
] = AdapterObject
;
718 if (MapRegisters
> 0)
720 AdapterObject
->NeedsMapRegisters
= TRUE
;
721 AdapterObject
->MapRegistersPerChannel
= MapRegisters
;
725 AdapterObject
->NeedsMapRegisters
= FALSE
;
726 if (DeviceDescription
->Master
)
728 AdapterObject
->MapRegistersPerChannel
= BYTES_TO_PAGES(MaximumLength
) + 1;
732 AdapterObject
->MapRegistersPerChannel
= 1;
737 if (!EisaAdapter
) InsertTailList(&HalpDmaAdapterList
, &AdapterObject
->AdapterList
);
740 * Release the DMA lock. HalpDmaAdapterList and HalpEisaAdapter will
741 * no longer be touched, so we don't need it.
743 KeSetEvent(&HalpDmaLock
, 0, 0);
746 * Setup the values in the adapter object that are common for all
749 if (DeviceDescription
->Version
>= DEVICE_DESCRIPTION_VERSION1
)
751 AdapterObject
->IgnoreCount
= DeviceDescription
->IgnoreCount
;
755 AdapterObject
->IgnoreCount
= 0;
758 AdapterObject
->Dma32BitAddresses
= DeviceDescription
->Dma32BitAddresses
;
759 AdapterObject
->Dma64BitAddresses
= DeviceDescription
->Dma64BitAddresses
;
760 AdapterObject
->ScatterGather
= DeviceDescription
->ScatterGather
;
761 AdapterObject
->MasterDevice
= DeviceDescription
->Master
;
762 *NumberOfMapRegisters
= AdapterObject
->MapRegistersPerChannel
;
765 * For non-(E)ISA adapters we have already done all the work. On the
766 * other hand for (E)ISA adapters we must still setup the DMA modes
767 * and prepare the controller.
771 if (!HalpDmaInitializeEisaAdapter(AdapterObject
, DeviceDescription
))
773 ObDereferenceObject(AdapterObject
);
778 return AdapterObject
;
782 * @name HalpGetDmaAdapter
784 * Internal routine to allocate PnP DMA adapter object. It's exported through
785 * HalDispatchTable and used by IoGetDmaAdapter.
791 HalpGetDmaAdapter(IN PVOID Context
,
792 IN PDEVICE_DESCRIPTION DeviceDescription
,
793 OUT PULONG NumberOfMapRegisters
)
795 return &HalGetAdapter(DeviceDescription
, NumberOfMapRegisters
)->DmaHeader
;
799 * @name HalPutDmaAdapter
801 * Internal routine to free DMA adapter and resources for reuse. It's exported
802 * using the DMA_OPERATIONS interface by HalGetAdapter.
808 HalPutDmaAdapter(IN PADAPTER_OBJECT AdapterObject
)
810 if (AdapterObject
->ChannelNumber
== 0xFF)
812 KeWaitForSingleObject(&HalpDmaLock
, Executive
, KernelMode
, FALSE
, NULL
);
813 RemoveEntryList(&AdapterObject
->AdapterList
);
814 KeSetEvent(&HalpDmaLock
, 0, 0);
817 ObDereferenceObject(AdapterObject
);
821 * @name HalAllocateCommonBuffer
823 * Allocates memory that is visible to both the processor(s) and the DMA
826 * @param AdapterObject
827 * Adapter object representing the bus master or system dma controller.
829 * Number of bytes to allocate.
830 * @param LogicalAddress
831 * Logical address the driver can use to access the buffer.
832 * @param CacheEnabled
833 * Specifies if the memory can be cached.
835 * @return The base virtual address of the memory allocated or NULL on failure.
838 * On real NT x86 systems the CacheEnabled parameter is ignored, we honour
839 * it. If it proves to cause problems change it.
841 * @see HalFreeCommonBuffer
847 HalAllocateCommonBuffer(IN PADAPTER_OBJECT AdapterObject
,
849 IN PPHYSICAL_ADDRESS LogicalAddress
,
850 IN BOOLEAN CacheEnabled
)
852 PHYSICAL_ADDRESS LowestAcceptableAddress
;
853 PHYSICAL_ADDRESS HighestAcceptableAddress
;
854 PHYSICAL_ADDRESS BoundryAddressMultiple
;
855 PVOID VirtualAddress
;
857 LowestAcceptableAddress
.QuadPart
= 0;
858 HighestAcceptableAddress
= HalpGetAdapterMaximumPhysicalAddress(AdapterObject
);
859 BoundryAddressMultiple
.QuadPart
= 0;
862 * For bus-master DMA devices the buffer mustn't cross 4Gb boundary. For
863 * slave DMA devices the 64Kb boundary mustn't be crossed since the
864 * controller wouldn't be able to handle it.
866 if (AdapterObject
->MasterDevice
)
868 BoundryAddressMultiple
.HighPart
= 1;
872 BoundryAddressMultiple
.LowPart
= 0x10000;
875 VirtualAddress
= MmAllocateContiguousMemorySpecifyCache(Length
,
876 LowestAcceptableAddress
,
877 HighestAcceptableAddress
,
878 BoundryAddressMultiple
,
879 CacheEnabled
? MmCached
:
881 if (VirtualAddress
== NULL
) return NULL
;
883 *LogicalAddress
= MmGetPhysicalAddress(VirtualAddress
);
885 return VirtualAddress
;
889 * @name HalFreeCommonBuffer
891 * Free common buffer allocated with HalAllocateCommonBuffer.
893 * @see HalAllocateCommonBuffer
899 HalFreeCommonBuffer(IN PADAPTER_OBJECT AdapterObject
,
901 IN PHYSICAL_ADDRESS LogicalAddress
,
902 IN PVOID VirtualAddress
,
903 IN BOOLEAN CacheEnabled
)
905 MmFreeContiguousMemorySpecifyCache(VirtualAddress
,
907 CacheEnabled
? MmCached
: MmNonCached
);
910 typedef struct _SCATTER_GATHER_CONTEXT
{
911 PADAPTER_OBJECT AdapterObject
;
915 PDRIVER_LIST_CONTROL AdapterListControlRoutine
;
916 PVOID AdapterListControlContext
, MapRegisterBase
;
917 ULONG MapRegisterCount
;
918 BOOLEAN WriteToDevice
;
919 } SCATTER_GATHER_CONTEXT
, *PSCATTER_GATHER_CONTEXT
;
924 HalpScatterGatherAdapterControl(IN PDEVICE_OBJECT DeviceObject
,
926 IN PVOID MapRegisterBase
,
929 PSCATTER_GATHER_CONTEXT AdapterControlContext
= Context
;
930 PADAPTER_OBJECT AdapterObject
= AdapterControlContext
->AdapterObject
;
931 PSCATTER_GATHER_LIST ScatterGatherList
;
932 SCATTER_GATHER_ELEMENT TempElements
[MAX_SG_ELEMENTS
];
933 ULONG ElementCount
= 0, RemainingLength
= AdapterControlContext
->Length
;
934 PUCHAR CurrentVa
= AdapterControlContext
->CurrentVa
;
936 /* Store the map register base for later in HalPutScatterGatherList */
937 AdapterControlContext
->MapRegisterBase
= MapRegisterBase
;
939 while (RemainingLength
> 0 && ElementCount
< MAX_SG_ELEMENTS
)
941 TempElements
[ElementCount
].Length
= RemainingLength
;
942 TempElements
[ElementCount
].Reserved
= 0;
943 TempElements
[ElementCount
].Address
= IoMapTransfer(AdapterObject
,
944 AdapterControlContext
->Mdl
,
946 CurrentVa
+ (AdapterControlContext
->Length
- RemainingLength
),
947 &TempElements
[ElementCount
].Length
,
948 AdapterControlContext
->WriteToDevice
);
949 if (TempElements
[ElementCount
].Length
== 0)
952 DPRINT("Allocated one S/G element: 0x%I64u with length: 0x%x\n",
953 TempElements
[ElementCount
].Address
.QuadPart
,
954 TempElements
[ElementCount
].Length
);
956 ASSERT(TempElements
[ElementCount
].Length
<= RemainingLength
);
957 RemainingLength
-= TempElements
[ElementCount
].Length
;
961 if (RemainingLength
> 0)
963 DPRINT1("Scatter/gather list construction failed!\n");
964 return DeallocateObject
;
967 ScatterGatherList
= ExAllocatePoolWithTag(NonPagedPool
,
968 sizeof(SCATTER_GATHER_LIST
) + sizeof(SCATTER_GATHER_ELEMENT
) * ElementCount
,
970 ASSERT(ScatterGatherList
);
972 ScatterGatherList
->NumberOfElements
= ElementCount
;
973 ScatterGatherList
->Reserved
= (ULONG_PTR
)AdapterControlContext
;
974 RtlCopyMemory(ScatterGatherList
->Elements
,
976 sizeof(SCATTER_GATHER_ELEMENT
) * ElementCount
);
978 DPRINT("Initiating S/G DMA with %d element(s)\n", ElementCount
);
980 AdapterControlContext
->AdapterListControlRoutine(DeviceObject
,
983 AdapterControlContext
->AdapterListControlContext
);
985 return DeallocateObjectKeepRegisters
;
989 * @name HalGetScatterGatherList
991 * Creates a scatter-gather list to be using in scatter/gather DMA
993 * @param AdapterObject
994 * Adapter object representing the bus master or system dma controller.
995 * @param DeviceObject
996 * The device target for DMA.
998 * The MDL that describes the buffer to be mapped.
1000 * The current VA in the buffer to be mapped for transfer.
1002 * Specifies the length of data in bytes to be mapped.
1003 * @param ExecutionRoutine
1004 * A caller supplied AdapterListControl routine to be called when DMA is available.
1006 * Context passed to the AdapterListControl routine.
1007 * @param WriteToDevice
1008 * Indicates direction of DMA operation.
1010 * @return The status of the operation.
1012 * @see HalPutScatterGatherList
1018 HalGetScatterGatherList(IN PADAPTER_OBJECT AdapterObject
,
1019 IN PDEVICE_OBJECT DeviceObject
,
1023 IN PDRIVER_LIST_CONTROL ExecutionRoutine
,
1025 IN BOOLEAN WriteToDevice
)
1027 PSCATTER_GATHER_CONTEXT AdapterControlContext
;
1029 AdapterControlContext
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(SCATTER_GATHER_CONTEXT
), TAG_DMA
);
1030 if (!AdapterControlContext
) return STATUS_INSUFFICIENT_RESOURCES
;
1032 AdapterControlContext
->AdapterObject
= AdapterObject
;
1033 AdapterControlContext
->Mdl
= Mdl
;
1034 AdapterControlContext
->CurrentVa
= CurrentVa
;
1035 AdapterControlContext
->Length
= Length
;
1036 AdapterControlContext
->MapRegisterCount
= PAGE_ROUND_UP(Length
) >> PAGE_SHIFT
;
1037 AdapterControlContext
->AdapterListControlRoutine
= ExecutionRoutine
;
1038 AdapterControlContext
->AdapterListControlContext
= Context
;
1039 AdapterControlContext
->WriteToDevice
= WriteToDevice
;
1041 return IoAllocateAdapterChannel(AdapterObject
,
1043 AdapterControlContext
->MapRegisterCount
,
1044 HalpScatterGatherAdapterControl
,
1045 AdapterControlContext
);
1049 * @name HalPutScatterGatherList
1051 * Frees a scatter-gather list allocated from HalGetScatterGatherList
1053 * @param AdapterObject
1054 * Adapter object representing the bus master or system dma controller.
1055 * @param ScatterGather
1056 * The scatter/gather list to be freed.
1057 * @param WriteToDevice
1058 * Indicates direction of DMA operation.
1062 * @see HalGetScatterGatherList
1068 HalPutScatterGatherList(IN PADAPTER_OBJECT AdapterObject
,
1069 IN PSCATTER_GATHER_LIST ScatterGather
,
1070 IN BOOLEAN WriteToDevice
)
1072 PSCATTER_GATHER_CONTEXT AdapterControlContext
= (PSCATTER_GATHER_CONTEXT
)ScatterGather
->Reserved
;
1075 for (i
= 0; i
< ScatterGather
->NumberOfElements
; i
++)
1077 IoFlushAdapterBuffers(AdapterObject
,
1078 AdapterControlContext
->Mdl
,
1079 AdapterControlContext
->MapRegisterBase
,
1080 AdapterControlContext
->CurrentVa
,
1081 ScatterGather
->Elements
[i
].Length
,
1082 AdapterControlContext
->WriteToDevice
);
1083 AdapterControlContext
->CurrentVa
+= ScatterGather
->Elements
[i
].Length
;
1086 IoFreeMapRegisters(AdapterObject
,
1087 AdapterControlContext
->MapRegisterBase
,
1088 AdapterControlContext
->MapRegisterCount
);
1090 DPRINT("S/G DMA has finished!\n");
1092 ExFreePoolWithTag(AdapterControlContext
, TAG_DMA
);
1093 ExFreePoolWithTag(ScatterGather
, TAG_DMA
);
1098 * @name HalpDmaGetDmaAlignment
1100 * Internal routine to return the DMA alignment requirement. It's exported
1101 * using the DMA_OPERATIONS interface by HalGetAdapter.
1103 * @see HalGetAdapter
1107 HalpDmaGetDmaAlignment(IN PADAPTER_OBJECT AdapterObject
)
1113 * @name HalReadDmaCounter
1115 * Read DMA operation progress counter.
1121 HalReadDmaCounter(IN PADAPTER_OBJECT AdapterObject
)
1124 ULONG Count
, OldCount
;
1126 ASSERT(!AdapterObject
->MasterDevice
);
1129 * Acquire the master adapter lock since we're going to mess with the
1130 * system DMA controller registers and we really don't want anyone
1131 * to do the same at the same time.
1133 KeAcquireSpinLock(&AdapterObject
->MasterAdapter
->SpinLock
, &OldIrql
);
1135 /* Send the request to the specific controller. */
1136 if (AdapterObject
->AdapterNumber
== 1)
1138 PDMA1_CONTROL DmaControl1
= AdapterObject
->AdapterBaseVa
;
1146 WRITE_PORT_UCHAR(&DmaControl1
->ClearBytePointer
, 0);
1149 Count
= READ_PORT_UCHAR(&DmaControl1
->DmaAddressCount
1150 [AdapterObject
->ChannelNumber
].DmaBaseCount
);
1151 Count
|= READ_PORT_UCHAR(&DmaControl1
->DmaAddressCount
1152 [AdapterObject
->ChannelNumber
].DmaBaseCount
) << 8;
1153 } while (0xffff00 & (OldCount
^ Count
));
1157 PDMA2_CONTROL DmaControl2
= AdapterObject
->AdapterBaseVa
;
1165 WRITE_PORT_UCHAR(&DmaControl2
->ClearBytePointer
, 0);
1168 Count
= READ_PORT_UCHAR(&DmaControl2
->DmaAddressCount
1169 [AdapterObject
->ChannelNumber
].DmaBaseCount
);
1170 Count
|= READ_PORT_UCHAR(&DmaControl2
->DmaAddressCount
1171 [AdapterObject
->ChannelNumber
].DmaBaseCount
) << 8;
1172 } while (0xffff00 & (OldCount
^ Count
));
1175 KeReleaseSpinLock(&AdapterObject
->MasterAdapter
->SpinLock
, OldIrql
);
1179 if (AdapterObject
->Width16Bits
) Count
*= 2;
1186 * @name HalpGrowMapBufferWorker
1188 * Helper routine of HalAllocateAdapterChannel for allocating map registers
1189 * at PASSIVE_LEVEL in work item.
1193 HalpGrowMapBufferWorker(IN PVOID DeferredContext
)
1195 PGROW_WORK_ITEM WorkItem
= (PGROW_WORK_ITEM
)DeferredContext
;
1200 * Try to allocate new map registers for the adapter.
1202 * NOTE: The NT implementation actually tries to allocate more map
1203 * registers than needed as an optimization.
1205 KeWaitForSingleObject(&HalpDmaLock
, Executive
, KernelMode
, FALSE
, NULL
);
1206 Succeeded
= HalpGrowMapBuffers(WorkItem
->AdapterObject
->MasterAdapter
,
1207 WorkItem
->NumberOfMapRegisters
<< PAGE_SHIFT
);
1208 KeSetEvent(&HalpDmaLock
, 0, 0);
1213 * Flush the adapter queue now that new map registers are ready. The
1214 * easiest way to do that is to call IoFreeMapRegisters to not free
1215 * any registers. Note that we use the magic (PVOID)2 map register
1216 * base to bypass the parameter checking.
1218 OldIrql
= KfRaiseIrql(DISPATCH_LEVEL
);
1219 IoFreeMapRegisters(WorkItem
->AdapterObject
, (PVOID
)2, 0);
1220 KfLowerIrql(OldIrql
);
1223 ExFreePool(WorkItem
);
1227 * @name HalAllocateAdapterChannel
1229 * Setup map registers for an adapter object.
1231 * @param AdapterObject
1232 * Pointer to an ADAPTER_OBJECT to set up.
1233 * @param WaitContextBlock
1234 * Context block to be used with ExecutionRoutine.
1235 * @param NumberOfMapRegisters
1236 * Number of map registers requested.
1237 * @param ExecutionRoutine
1238 * Callback to call when map registers are allocated.
1241 * If not enough map registers can be allocated then
1242 * STATUS_INSUFFICIENT_RESOURCES is returned. If the function
1243 * succeeds or the callback is queued for later delivering then
1244 * STATUS_SUCCESS is returned.
1246 * @see IoFreeAdapterChannel
1252 HalAllocateAdapterChannel(IN PADAPTER_OBJECT AdapterObject
,
1253 IN PWAIT_CONTEXT_BLOCK WaitContextBlock
,
1254 IN ULONG NumberOfMapRegisters
,
1255 IN PDRIVER_CONTROL ExecutionRoutine
)
1257 PADAPTER_OBJECT MasterAdapter
;
1258 PGROW_WORK_ITEM WorkItem
;
1259 ULONG Index
= MAXULONG
;
1263 ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL
);
1265 /* Set up the wait context block in case we can't run right away. */
1266 WaitContextBlock
->DeviceRoutine
= ExecutionRoutine
;
1267 WaitContextBlock
->NumberOfMapRegisters
= NumberOfMapRegisters
;
1269 /* Returns true if queued, else returns false and sets the queue to busy */
1270 if (KeInsertDeviceQueue(&AdapterObject
->ChannelWaitQueue
,
1271 &WaitContextBlock
->WaitQueueEntry
))
1273 return STATUS_SUCCESS
;
1276 MasterAdapter
= AdapterObject
->MasterAdapter
;
1278 AdapterObject
->NumberOfMapRegisters
= NumberOfMapRegisters
;
1279 AdapterObject
->CurrentWcb
= WaitContextBlock
;
1281 if ((NumberOfMapRegisters
) && (AdapterObject
->NeedsMapRegisters
))
1283 if (NumberOfMapRegisters
> AdapterObject
->MapRegistersPerChannel
)
1285 AdapterObject
->NumberOfMapRegisters
= 0;
1286 IoFreeAdapterChannel(AdapterObject
);
1287 return STATUS_INSUFFICIENT_RESOURCES
;
1291 * Get the map registers. This is partly complicated by the fact
1292 * that new map registers can only be allocated at PASSIVE_LEVEL
1293 * and we're currently at DISPATCH_LEVEL. The following code has
1296 * - If there is no adapter queued for map register allocation,
1297 * try to see if enough contiguous map registers are present.
1298 * In case they're we can just get them and proceed further.
1300 * - If some adapter is already present in the queue we must
1301 * respect the order of adapters asking for map registers and
1302 * so the fast case described above can't take place.
1303 * This case is also entered if not enough coniguous map
1304 * registers are present.
1306 * A work queue item is allocated and queued, the adapter is
1307 * also queued into the master adapter queue. The worker
1308 * routine does the job of allocating the map registers at
1309 * PASSIVE_LEVEL and calling the ExecutionRoutine.
1312 KeAcquireSpinLock(&MasterAdapter
->SpinLock
, &OldIrql
);
1314 if (IsListEmpty(&MasterAdapter
->AdapterQueue
))
1316 Index
= RtlFindClearBitsAndSet(MasterAdapter
->MapRegisters
, NumberOfMapRegisters
, 0);
1317 if (Index
!= MAXULONG
)
1319 AdapterObject
->MapRegisterBase
= MasterAdapter
->MapRegisterBase
+ Index
;
1320 if (!AdapterObject
->ScatterGather
)
1322 AdapterObject
->MapRegisterBase
= (PROS_MAP_REGISTER_ENTRY
)((ULONG_PTR
)AdapterObject
->MapRegisterBase
| MAP_BASE_SW_SG
);
1327 if (Index
== MAXULONG
)
1329 InsertTailList(&MasterAdapter
->AdapterQueue
, &AdapterObject
->AdapterQueue
);
1331 WorkItem
= ExAllocatePoolWithTag(NonPagedPool
,
1332 sizeof(GROW_WORK_ITEM
),
1336 ExInitializeWorkItem(&WorkItem
->WorkQueueItem
, HalpGrowMapBufferWorker
, WorkItem
);
1337 WorkItem
->AdapterObject
= AdapterObject
;
1338 WorkItem
->NumberOfMapRegisters
= NumberOfMapRegisters
;
1340 ExQueueWorkItem(&WorkItem
->WorkQueueItem
, DelayedWorkQueue
);
1343 KeReleaseSpinLock(&MasterAdapter
->SpinLock
, OldIrql
);
1345 return STATUS_SUCCESS
;
1348 KeReleaseSpinLock(&MasterAdapter
->SpinLock
, OldIrql
);
1352 AdapterObject
->MapRegisterBase
= NULL
;
1353 AdapterObject
->NumberOfMapRegisters
= 0;
1356 AdapterObject
->CurrentWcb
= WaitContextBlock
;
1358 Result
= ExecutionRoutine(WaitContextBlock
->DeviceObject
,
1359 WaitContextBlock
->CurrentIrp
,
1360 AdapterObject
->MapRegisterBase
,
1361 WaitContextBlock
->DeviceContext
);
1364 * Possible return values:
1367 * Don't free any resources, the ADAPTER_OBJECT is still in use and
1368 * the caller will call IoFreeAdapterChannel later.
1370 * - DeallocateObject
1371 * Deallocate the map registers and release the ADAPTER_OBJECT, so
1372 * someone else can use it.
1374 * - DeallocateObjectKeepRegisters
1375 * Release the ADAPTER_OBJECT, but hang on to the map registers. The
1376 * client will later call IoFreeMapRegisters.
1379 * IoFreeAdapterChannel runs the queue, so it must be called unless
1380 * the adapter object is not to be freed.
1382 if (Result
== DeallocateObject
)
1384 IoFreeAdapterChannel(AdapterObject
);
1386 else if (Result
== DeallocateObjectKeepRegisters
)
1388 AdapterObject
->NumberOfMapRegisters
= 0;
1389 IoFreeAdapterChannel(AdapterObject
);
1392 return STATUS_SUCCESS
;
1396 * @name IoFreeAdapterChannel
1398 * Free DMA resources allocated by IoAllocateAdapterChannel.
1400 * @param AdapterObject
1401 * Adapter object with resources to free.
1404 * This function releases map registers registers assigned to the DMA
1405 * adapter. After releasing the adapter, it checks the adapter's queue
1406 * and runs each queued device object in series until the queue is
1407 * empty. This is the only way the device queue is emptied.
1409 * @see IoAllocateAdapterChannel
1415 IoFreeAdapterChannel(IN PADAPTER_OBJECT AdapterObject
)
1417 PADAPTER_OBJECT MasterAdapter
;
1418 PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
;
1419 PWAIT_CONTEXT_BLOCK WaitContextBlock
;
1420 ULONG Index
= MAXULONG
;
1424 MasterAdapter
= AdapterObject
->MasterAdapter
;
1429 * To keep map registers, call here with AdapterObject->
1430 * NumberOfMapRegisters set to zero. This trick is used in
1431 * HalAllocateAdapterChannel for example.
1433 if (AdapterObject
->NumberOfMapRegisters
)
1435 IoFreeMapRegisters(AdapterObject
,
1436 AdapterObject
->MapRegisterBase
,
1437 AdapterObject
->NumberOfMapRegisters
);
1440 DeviceQueueEntry
= KeRemoveDeviceQueue(&AdapterObject
->ChannelWaitQueue
);
1441 if (!DeviceQueueEntry
) break;
1443 WaitContextBlock
= CONTAINING_RECORD(DeviceQueueEntry
,
1447 AdapterObject
->CurrentWcb
= WaitContextBlock
;
1448 AdapterObject
->NumberOfMapRegisters
= WaitContextBlock
->NumberOfMapRegisters
;
1450 if ((WaitContextBlock
->NumberOfMapRegisters
) && (AdapterObject
->MasterAdapter
))
1452 KeAcquireSpinLock(&MasterAdapter
->SpinLock
, &OldIrql
);
1454 if (IsListEmpty(&MasterAdapter
->AdapterQueue
))
1456 Index
= RtlFindClearBitsAndSet(MasterAdapter
->MapRegisters
,
1457 WaitContextBlock
->NumberOfMapRegisters
,
1459 if (Index
!= MAXULONG
)
1461 AdapterObject
->MapRegisterBase
= MasterAdapter
->MapRegisterBase
+ Index
;
1462 if (!AdapterObject
->ScatterGather
)
1464 AdapterObject
->MapRegisterBase
=(PROS_MAP_REGISTER_ENTRY
)((ULONG_PTR
)AdapterObject
->MapRegisterBase
| MAP_BASE_SW_SG
);
1469 if (Index
== MAXULONG
)
1471 InsertTailList(&MasterAdapter
->AdapterQueue
, &AdapterObject
->AdapterQueue
);
1472 KeReleaseSpinLock(&MasterAdapter
->SpinLock
, OldIrql
);
1476 KeReleaseSpinLock(&MasterAdapter
->SpinLock
, OldIrql
);
1480 AdapterObject
->MapRegisterBase
= NULL
;
1481 AdapterObject
->NumberOfMapRegisters
= 0;
1484 /* Call the adapter control routine. */
1485 Result
= ((PDRIVER_CONTROL
)WaitContextBlock
->DeviceRoutine
)(WaitContextBlock
->DeviceObject
,
1486 WaitContextBlock
->CurrentIrp
,
1487 AdapterObject
->MapRegisterBase
,
1488 WaitContextBlock
->DeviceContext
);
1493 * We're done until the caller manually calls IoFreeAdapterChannel
1494 * or IoFreeMapRegisters.
1498 case DeallocateObjectKeepRegisters
:
1500 * Hide the map registers so they aren't deallocated next time
1503 AdapterObject
->NumberOfMapRegisters
= 0;
1513 * @name IoFreeMapRegisters
1515 * Free map registers reserved by the system for a DMA.
1517 * @param AdapterObject
1518 * DMA adapter to free map registers on.
1519 * @param MapRegisterBase
1520 * Handle to map registers to free.
1521 * @param NumberOfRegisters
1522 * Number of map registers to be freed.
1528 IoFreeMapRegisters(IN PADAPTER_OBJECT AdapterObject
,
1529 IN PVOID MapRegisterBase
,
1530 IN ULONG NumberOfMapRegisters
)
1532 PADAPTER_OBJECT MasterAdapter
= AdapterObject
->MasterAdapter
;
1533 PLIST_ENTRY ListEntry
;
1538 ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL
);
1540 if (!(MasterAdapter
) || !(MapRegisterBase
)) return;
1542 KeAcquireSpinLock(&MasterAdapter
->SpinLock
, &OldIrql
);
1544 if (NumberOfMapRegisters
!= 0)
1546 PROS_MAP_REGISTER_ENTRY RealMapRegisterBase
;
1548 RealMapRegisterBase
= (PROS_MAP_REGISTER_ENTRY
)((ULONG_PTR
)MapRegisterBase
& ~MAP_BASE_SW_SG
);
1549 RtlClearBits(MasterAdapter
->MapRegisters
,
1550 RealMapRegisterBase
- MasterAdapter
->MapRegisterBase
,
1551 NumberOfMapRegisters
);
1555 * Now that we freed few map registers it's time to look at the master
1556 * adapter queue and see if there is someone waiting for map registers.
1558 while (!IsListEmpty(&MasterAdapter
->AdapterQueue
))
1560 ListEntry
= RemoveHeadList(&MasterAdapter
->AdapterQueue
);
1561 AdapterObject
= CONTAINING_RECORD(ListEntry
, struct _ADAPTER_OBJECT
, AdapterQueue
);
1563 Index
= RtlFindClearBitsAndSet(MasterAdapter
->MapRegisters
,
1564 AdapterObject
->NumberOfMapRegisters
,
1566 if (Index
== MAXULONG
)
1568 InsertHeadList(&MasterAdapter
->AdapterQueue
, ListEntry
);
1572 KeReleaseSpinLock(&MasterAdapter
->SpinLock
, OldIrql
);
1574 AdapterObject
->MapRegisterBase
= MasterAdapter
->MapRegisterBase
+ Index
;
1575 if (!AdapterObject
->ScatterGather
)
1577 AdapterObject
->MapRegisterBase
=
1578 (PROS_MAP_REGISTER_ENTRY
)((ULONG_PTR
)AdapterObject
->MapRegisterBase
| MAP_BASE_SW_SG
);
1581 Result
= ((PDRIVER_CONTROL
)AdapterObject
->CurrentWcb
->DeviceRoutine
)(AdapterObject
->CurrentWcb
->DeviceObject
,
1582 AdapterObject
->CurrentWcb
->CurrentIrp
,
1583 AdapterObject
->MapRegisterBase
,
1584 AdapterObject
->CurrentWcb
->DeviceContext
);
1587 case DeallocateObjectKeepRegisters
:
1588 AdapterObject
->NumberOfMapRegisters
= 0;
1591 case DeallocateObject
:
1592 if (AdapterObject
->NumberOfMapRegisters
)
1594 KeAcquireSpinLock(&MasterAdapter
->SpinLock
, &OldIrql
);
1595 RtlClearBits(MasterAdapter
->MapRegisters
,
1596 AdapterObject
->MapRegisterBase
-
1597 MasterAdapter
->MapRegisterBase
,
1598 AdapterObject
->NumberOfMapRegisters
);
1599 KeReleaseSpinLock(&MasterAdapter
->SpinLock
, OldIrql
);
1602 IoFreeAdapterChannel(AdapterObject
);
1609 KeAcquireSpinLock(&MasterAdapter
->SpinLock
, &OldIrql
);
1612 KeReleaseSpinLock(&MasterAdapter
->SpinLock
, OldIrql
);
1616 * @name HalpCopyBufferMap
1618 * Helper function for copying data from/to map register buffers.
1620 * @see IoFlushAdapterBuffers, IoMapTransfer
1624 HalpCopyBufferMap(IN PMDL Mdl
,
1625 IN PROS_MAP_REGISTER_ENTRY MapRegisterBase
,
1628 IN BOOLEAN WriteToDevice
)
1630 ULONG CurrentLength
;
1631 ULONG_PTR CurrentAddress
;
1633 PVOID VirtualAddress
;
1635 VirtualAddress
= MmGetSystemAddressForMdlSafe(Mdl
, HighPagePriority
);
1636 if (!VirtualAddress
)
1639 * NOTE: On real NT a mechanism with reserved pages is implemented
1640 * to handle this case in a slow, but graceful non-fatal way.
1642 KeBugCheckEx(HAL_MEMORY_ALLOCATION
, PAGE_SIZE
, 0, (ULONG_PTR
)__FILE__
, 0);
1645 CurrentAddress
= (ULONG_PTR
)VirtualAddress
+
1646 (ULONG_PTR
)CurrentVa
-
1647 (ULONG_PTR
)MmGetMdlVirtualAddress(Mdl
);
1651 ByteOffset
= BYTE_OFFSET(CurrentAddress
);
1652 CurrentLength
= PAGE_SIZE
- ByteOffset
;
1653 if (CurrentLength
> Length
) CurrentLength
= Length
;
1657 RtlCopyMemory((PVOID
)((ULONG_PTR
)MapRegisterBase
->VirtualAddress
+ ByteOffset
),
1658 (PVOID
)CurrentAddress
,
1663 RtlCopyMemory((PVOID
)CurrentAddress
,
1664 (PVOID
)((ULONG_PTR
)MapRegisterBase
->VirtualAddress
+ ByteOffset
),
1668 Length
-= CurrentLength
;
1669 CurrentAddress
+= CurrentLength
;
1675 * @name IoFlushAdapterBuffers
1677 * Flush any data remaining in the DMA controller's memory into the host
1680 * @param AdapterObject
1681 * The adapter object to flush.
1683 * Original MDL to flush data into.
1684 * @param MapRegisterBase
1685 * Map register base that was just used by IoMapTransfer, etc.
1687 * Offset into Mdl to be flushed into, same as was passed to
1690 * Length of the buffer to be flushed into.
1691 * @param WriteToDevice
1692 * TRUE if it's a write, FALSE if it's a read.
1694 * @return TRUE in all cases.
1697 * This copies data from the map register-backed buffer to the user's
1698 * target buffer. Data are not in the user buffer until this function
1700 * For slave DMA transfers the controller channel is masked effectively
1701 * stopping the current transfer.
1707 IoFlushAdapterBuffers(IN PADAPTER_OBJECT AdapterObject
,
1709 IN PVOID MapRegisterBase
,
1712 IN BOOLEAN WriteToDevice
)
1714 BOOLEAN SlaveDma
= FALSE
;
1715 PROS_MAP_REGISTER_ENTRY RealMapRegisterBase
;
1716 PHYSICAL_ADDRESS HighestAcceptableAddress
;
1717 PHYSICAL_ADDRESS PhysicalAddress
;
1718 PPFN_NUMBER MdlPagesPtr
;
1721 ASSERT_IRQL_LESS_OR_EQUAL(DISPATCH_LEVEL
);
1722 ASSERT(AdapterObject
);
1724 if (!AdapterObject
->MasterDevice
)
1726 /* Mask out (disable) the DMA channel. */
1727 if (AdapterObject
->AdapterNumber
== 1)
1729 PDMA1_CONTROL DmaControl1
= AdapterObject
->AdapterBaseVa
;
1730 WRITE_PORT_UCHAR(&DmaControl1
->SingleMask
,
1731 AdapterObject
->ChannelNumber
| DMA_SETMASK
);
1735 PDMA2_CONTROL DmaControl2
= AdapterObject
->AdapterBaseVa
;
1736 WRITE_PORT_UCHAR(&DmaControl2
->SingleMask
,
1737 AdapterObject
->ChannelNumber
| DMA_SETMASK
);
1742 /* This can happen if the device supports hardware scatter/gather. */
1743 if (MapRegisterBase
== NULL
) return TRUE
;
1745 RealMapRegisterBase
= (PROS_MAP_REGISTER_ENTRY
)((ULONG_PTR
)MapRegisterBase
& ~MAP_BASE_SW_SG
);
1749 if ((ULONG_PTR
)MapRegisterBase
& MAP_BASE_SW_SG
)
1751 if (RealMapRegisterBase
->Counter
!= MAXULONG
)
1753 if ((SlaveDma
) && !(AdapterObject
->IgnoreCount
))
1755 Length
-= HalReadDmaCounter(AdapterObject
);
1758 HalpCopyBufferMap(Mdl
,
1759 RealMapRegisterBase
,
1766 MdlPagesPtr
= MmGetMdlPfnArray(Mdl
);
1767 MdlPagesPtr
+= ((ULONG_PTR
)CurrentVa
- (ULONG_PTR
)Mdl
->StartVa
) >> PAGE_SHIFT
;
1769 PhysicalAddress
.QuadPart
= *MdlPagesPtr
<< PAGE_SHIFT
;
1770 PhysicalAddress
.QuadPart
+= BYTE_OFFSET(CurrentVa
);
1772 HighestAcceptableAddress
= HalpGetAdapterMaximumPhysicalAddress(AdapterObject
);
1773 if ((PhysicalAddress
.QuadPart
+ Length
) > HighestAcceptableAddress
.QuadPart
)
1775 HalpCopyBufferMap(Mdl
,
1776 RealMapRegisterBase
,
1784 RealMapRegisterBase
->Counter
= 0;
1790 * @name IoMapTransfer
1792 * Map a DMA for transfer and do the DMA if it's a slave.
1794 * @param AdapterObject
1795 * Adapter object to do the DMA on. Bus-master may pass NULL.
1797 * Locked-down user buffer to DMA in to or out of.
1798 * @param MapRegisterBase
1799 * Handle to map registers to use for this dma.
1801 * Index into Mdl to transfer into/out of.
1803 * Length of transfer. Number of bytes actually transferred on
1805 * @param WriteToDevice
1806 * TRUE if it's an output DMA, FALSE otherwise.
1809 * A logical address that can be used to program a DMA controller, it's
1810 * not meaningful for slave DMA device.
1813 * This function does a copyover to contiguous memory <16MB represented
1814 * by the map registers if needed. If the buffer described by MDL can be
1815 * used as is no copyover is done.
1816 * If it's a slave transfer, this function actually performs it.
1822 IoMapTransfer(IN PADAPTER_OBJECT AdapterObject
,
1824 IN PVOID MapRegisterBase
,
1826 IN OUT PULONG Length
,
1827 IN BOOLEAN WriteToDevice
)
1829 PPFN_NUMBER MdlPagesPtr
;
1830 PFN_NUMBER MdlPage1
, MdlPage2
;
1832 ULONG TransferOffset
;
1833 ULONG TransferLength
;
1834 BOOLEAN UseMapRegisters
;
1835 PROS_MAP_REGISTER_ENTRY RealMapRegisterBase
;
1836 PHYSICAL_ADDRESS PhysicalAddress
;
1837 PHYSICAL_ADDRESS HighestAcceptableAddress
;
1839 DMA_MODE AdapterMode
;
1843 * Precalculate some values that are used in all cases.
1845 * ByteOffset is offset inside the page at which the transfer starts.
1846 * MdlPagesPtr is pointer inside the MDL page chain at the page where the
1848 * PhysicalAddress is physical address corresponding to the transfer
1849 * start page and offset.
1850 * TransferLength is the inital length of the transfer, which is reminder
1851 * of the first page. The actual value is calculated below.
1853 * Note that all the variables can change during the processing which
1854 * takes place below. These are just initial values.
1856 ByteOffset
= BYTE_OFFSET(CurrentVa
);
1858 MdlPagesPtr
= MmGetMdlPfnArray(Mdl
);
1859 MdlPagesPtr
+= ((ULONG_PTR
)CurrentVa
- (ULONG_PTR
)Mdl
->StartVa
) >> PAGE_SHIFT
;
1861 PhysicalAddress
.QuadPart
= *MdlPagesPtr
<< PAGE_SHIFT
;
1862 PhysicalAddress
.QuadPart
+= ByteOffset
;
1864 TransferLength
= PAGE_SIZE
- ByteOffset
;
1867 * Special case for bus master adapters with S/G support. We can directly
1868 * use the buffer specified by the MDL, so not much work has to be done.
1870 * Just return the passed VA's corresponding physical address and update
1871 * length to the number of physically contiguous bytes found. Also
1872 * pages crossing the 4Gb boundary aren't considered physically contiguous.
1874 if (MapRegisterBase
== NULL
)
1876 while (TransferLength
< *Length
)
1878 MdlPage1
= *MdlPagesPtr
;
1879 MdlPage2
= *(MdlPagesPtr
+ 1);
1880 if (MdlPage1
+ 1 != MdlPage2
) break;
1881 if ((MdlPage1
^ MdlPage2
) & ~0xFFFFF) break;
1882 TransferLength
+= PAGE_SIZE
;
1886 if (TransferLength
< *Length
) *Length
= TransferLength
;
1888 return PhysicalAddress
;
1892 * The code below applies to slave DMA adapters and bus master adapters
1893 * without hardward S/G support.
1895 RealMapRegisterBase
= (PROS_MAP_REGISTER_ENTRY
)((ULONG_PTR
)MapRegisterBase
& ~MAP_BASE_SW_SG
);
1898 * Try to calculate the size of the transfer. We can only transfer
1899 * pages that are physically contiguous and that don't cross the
1900 * 64Kb boundary (this limitation applies only for ISA controllers).
1902 while (TransferLength
< *Length
)
1904 MdlPage1
= *MdlPagesPtr
;
1905 MdlPage2
= *(MdlPagesPtr
+ 1);
1906 if (MdlPage1
+ 1 != MdlPage2
) break;
1907 if (!HalpEisaDma
&& ((MdlPage1
^ MdlPage2
) & ~0xF)) break;
1908 TransferLength
+= PAGE_SIZE
;
1912 if (TransferLength
> *Length
) TransferLength
= *Length
;
1915 * If we're about to simulate software S/G and not all the pages are
1916 * physically contiguous then we must use the map registers to store
1917 * the data and allow the whole transfer to proceed at once.
1919 if (((ULONG_PTR
)MapRegisterBase
& MAP_BASE_SW_SG
) && (TransferLength
< *Length
))
1921 UseMapRegisters
= TRUE
;
1922 PhysicalAddress
= RealMapRegisterBase
->PhysicalAddress
;
1923 PhysicalAddress
.QuadPart
+= ByteOffset
;
1924 TransferLength
= *Length
;
1925 RealMapRegisterBase
->Counter
= MAXULONG
;
1931 * This is ordinary DMA transfer, so just update the progress
1932 * counters. These are used by IoFlushAdapterBuffers to track
1933 * the transfer progress.
1935 UseMapRegisters
= FALSE
;
1936 Counter
= RealMapRegisterBase
->Counter
;
1937 RealMapRegisterBase
->Counter
+= BYTES_TO_PAGES(ByteOffset
+ TransferLength
);
1940 * Check if the buffer doesn't exceed the highest physical address
1941 * limit of the device. In that case we must use the map registers to
1944 HighestAcceptableAddress
= HalpGetAdapterMaximumPhysicalAddress(AdapterObject
);
1945 if ((PhysicalAddress
.QuadPart
+ TransferLength
) > HighestAcceptableAddress
.QuadPart
)
1947 UseMapRegisters
= TRUE
;
1948 PhysicalAddress
= RealMapRegisterBase
[Counter
].PhysicalAddress
;
1949 PhysicalAddress
.QuadPart
+= ByteOffset
;
1950 if ((ULONG_PTR
)MapRegisterBase
& MAP_BASE_SW_SG
)
1952 RealMapRegisterBase
->Counter
= MAXULONG
;
1959 * If we decided to use the map registers (see above) and we're about
1960 * to transfer data to the device then copy the buffers into the map
1963 if ((UseMapRegisters
) && (WriteToDevice
))
1965 HalpCopyBufferMap(Mdl
,
1966 RealMapRegisterBase
+ Counter
,
1973 * Return the length of transfer that actually takes place.
1975 *Length
= TransferLength
;
1978 * If we're doing slave (system) DMA then program the (E)ISA controller
1979 * to actually start the transfer.
1981 if ((AdapterObject
) && !(AdapterObject
->MasterDevice
))
1983 AdapterMode
= AdapterObject
->AdapterMode
;
1987 AdapterMode
.TransferType
= WRITE_TRANSFER
;
1991 AdapterMode
.TransferType
= READ_TRANSFER
;
1992 if (AdapterObject
->IgnoreCount
)
1994 RtlZeroMemory((PUCHAR
)RealMapRegisterBase
[Counter
].VirtualAddress
+ ByteOffset
,
1999 TransferOffset
= PhysicalAddress
.LowPart
& 0xFFFF;
2000 if (AdapterObject
->Width16Bits
)
2002 TransferLength
>>= 1;
2003 TransferOffset
>>= 1;
2006 KeAcquireSpinLock(&AdapterObject
->MasterAdapter
->SpinLock
, &OldIrql
);
2008 if (AdapterObject
->AdapterNumber
== 1)
2010 PDMA1_CONTROL DmaControl1
= AdapterObject
->AdapterBaseVa
;
2012 /* Reset Register */
2013 WRITE_PORT_UCHAR(&DmaControl1
->ClearBytePointer
, 0);
2016 WRITE_PORT_UCHAR(&DmaControl1
->Mode
, AdapterMode
.Byte
);
2018 /* Set the Offset Register */
2019 WRITE_PORT_UCHAR(&DmaControl1
->DmaAddressCount
[AdapterObject
->ChannelNumber
].DmaBaseAddress
,
2020 (UCHAR
)(TransferOffset
));
2021 WRITE_PORT_UCHAR(&DmaControl1
->DmaAddressCount
[AdapterObject
->ChannelNumber
].DmaBaseAddress
,
2022 (UCHAR
)(TransferOffset
>> 8));
2024 /* Set the Page Register */
2025 WRITE_PORT_UCHAR(AdapterObject
->PagePort
+ FIELD_OFFSET(EISA_CONTROL
, DmaController1Pages
),
2026 (UCHAR
)(PhysicalAddress
.LowPart
>> 16));
2029 WRITE_PORT_UCHAR(AdapterObject
->PagePort
+ FIELD_OFFSET(EISA_CONTROL
, DmaController2Pages
),
2033 /* Set the Length */
2034 WRITE_PORT_UCHAR(&DmaControl1
->DmaAddressCount
[AdapterObject
->ChannelNumber
].DmaBaseCount
,
2035 (UCHAR
)(TransferLength
- 1));
2036 WRITE_PORT_UCHAR(&DmaControl1
->DmaAddressCount
[AdapterObject
->ChannelNumber
].DmaBaseCount
,
2037 (UCHAR
)((TransferLength
- 1) >> 8));
2039 /* Unmask the Channel */
2040 WRITE_PORT_UCHAR(&DmaControl1
->SingleMask
, AdapterObject
->ChannelNumber
| DMA_CLEARMASK
);
2044 PDMA2_CONTROL DmaControl2
= AdapterObject
->AdapterBaseVa
;
2046 /* Reset Register */
2047 WRITE_PORT_UCHAR(&DmaControl2
->ClearBytePointer
, 0);
2050 WRITE_PORT_UCHAR(&DmaControl2
->Mode
, AdapterMode
.Byte
);
2052 /* Set the Offset Register */
2053 WRITE_PORT_UCHAR(&DmaControl2
->DmaAddressCount
[AdapterObject
->ChannelNumber
].DmaBaseAddress
,
2054 (UCHAR
)(TransferOffset
));
2055 WRITE_PORT_UCHAR(&DmaControl2
->DmaAddressCount
[AdapterObject
->ChannelNumber
].DmaBaseAddress
,
2056 (UCHAR
)(TransferOffset
>> 8));
2058 /* Set the Page Register */
2059 WRITE_PORT_UCHAR(AdapterObject
->PagePort
+ FIELD_OFFSET(EISA_CONTROL
, DmaController1Pages
),
2060 (UCHAR
)(PhysicalAddress
.u
.LowPart
>> 16));
2063 WRITE_PORT_UCHAR(AdapterObject
->PagePort
+ FIELD_OFFSET(EISA_CONTROL
, DmaController2Pages
),
2067 /* Set the Length */
2068 WRITE_PORT_UCHAR(&DmaControl2
->DmaAddressCount
[AdapterObject
->ChannelNumber
].DmaBaseCount
,
2069 (UCHAR
)(TransferLength
- 1));
2070 WRITE_PORT_UCHAR(&DmaControl2
->DmaAddressCount
[AdapterObject
->ChannelNumber
].DmaBaseCount
,
2071 (UCHAR
)((TransferLength
- 1) >> 8));
2073 /* Unmask the Channel */
2074 WRITE_PORT_UCHAR(&DmaControl2
->SingleMask
,
2075 AdapterObject
->ChannelNumber
| DMA_CLEARMASK
);
2078 KeReleaseSpinLock(&AdapterObject
->MasterAdapter
->SpinLock
, OldIrql
);
2082 * Return physical address of the buffer with data that is used for the
2083 * transfer. It can either point inside the Mdl that was passed by the
2084 * caller or into the map registers if the Mdl buffer can't be used
2087 return PhysicalAddress
;
2092 * @name HalFlushCommonBuffer
2098 HalFlushCommonBuffer(IN PADAPTER_OBJECT AdapterObject
,
2100 IN PHYSICAL_ADDRESS LogicalAddress
,
2101 IN PVOID VirtualAddress
)
2103 /* Function always returns true */
2112 HalAllocateCrashDumpRegisters(IN PADAPTER_OBJECT AdapterObject
,
2113 IN OUT PULONG NumberOfMapRegisters
)
2115 PADAPTER_OBJECT MasterAdapter
= AdapterObject
->MasterAdapter
;
2116 ULONG MapRegisterNumber
;
2118 /* Check if it needs map registers */
2119 if (AdapterObject
->NeedsMapRegisters
)
2121 /* Check if we have enough */
2122 if (*NumberOfMapRegisters
> AdapterObject
->MapRegistersPerChannel
)
2124 /* We don't, fail */
2125 AdapterObject
->NumberOfMapRegisters
= 0;
2129 /* Try to find free map registers */
2130 MapRegisterNumber
= RtlFindClearBitsAndSet(MasterAdapter
->MapRegisters
,
2131 *NumberOfMapRegisters
,
2134 /* Check if nothing was found */
2135 if (MapRegisterNumber
== MAXULONG
)
2137 /* No free registers found, so use the base registers */
2138 RtlSetBits(MasterAdapter
->MapRegisters
,
2140 *NumberOfMapRegisters
);
2141 MapRegisterNumber
= 0;
2144 /* Calculate the new base */
2145 AdapterObject
->MapRegisterBase
=
2146 (PROS_MAP_REGISTER_ENTRY
)(MasterAdapter
->MapRegisterBase
+
2149 /* Check if scatter gather isn't supported */
2150 if (!AdapterObject
->ScatterGather
)
2153 AdapterObject
->MapRegisterBase
=
2154 (PROS_MAP_REGISTER_ENTRY
)
2155 ((ULONG_PTR
)AdapterObject
->MapRegisterBase
| MAP_BASE_SW_SG
);
2160 AdapterObject
->MapRegisterBase
= NULL
;
2161 AdapterObject
->NumberOfMapRegisters
= 0;
2164 /* Return the base */
2165 return AdapterObject
->MapRegisterBase
;