HalpDmaFreeChildAdapter
VOID __stdcall HalpDmaFreeChildAdapter(_ADAPTER_OBJECT *ChildAdapter){
UINT64 v1;
_MDL *MapRegisterMdl;
_LIST_ENTRY *p_AdapterList;
unsigned __int8 v5;
_LIST_ENTRY *Blink;
unsigned __int64 v7;
_LIST_ENTRY *Flink;
UINT64 *IommuDevice;
_HALP_DMA_TRANSLATION_BUFFER *ContiguousTranslations;
_HALP_DMA_TRANSLATION_ENTRY *Entries;
_HALP_ALLOC_CONTEXT *v12;
UINT64 v13;
void *AllocationHandle;
void *VirtualAddress;
__int64 i;
_HALP_DMA_TRANSLATION_BUFFER *Next;
VOID *ContiguousMapRegisters;
unsigned int NumberOfFreeScatterBuffers;
_HALP_DMA_TRANSLATION_ENTRY *ScatterBufferListHead;
__int64 v21;
_HALP_DMA_TRANSLATION_ENTRY *v22;
void *v23;
void *v24;
_HALP_DMA_TRANSLATION_BUFFER *ScatterTranslations;
MapRegisterMdl = ChildAdapter->MapRegisterMdl;
if( MapRegisterMdl )
{
IoFreeMdl(MapRegisterMdl);
ChildAdapter->MapRegisterMdl = 0i64;
}
p_AdapterList = &ChildAdapter->AdapterList;
if( ChildAdapter->AdapterList.Flink )
{
v5 = KeAcquireSpinLockRaiseToDpc(&HalpDmaAdapterListLock);
Blink = ChildAdapter->AdapterList.Blink;
v7 = v5;
Flink = p_AdapterList->Flink;
if( p_AdapterList->Flink->Blink != p_AdapterList || Blink->Flink != p_AdapterList )
__fastfail(3u);
Blink->Flink = Flink;
Flink->Blink = Blink;
KxReleaseSpinLock(&HalpDmaAdapterListLock);
__writecr8(v7);
}
if( ChildAdapter->DomainPointer )
{
ChildAdapter->AdapterInUse = 0;
HalpLeaveDmaDomain((INT64)ChildAdapter);
}
IommuDevice = (UINT64 *)ChildAdapter->IommuDevice;
if( IommuDevice )
{
HalpIommuDeleteDevice(IommuDevice);
ChildAdapter->IommuDevice = 0i64;
}
if( ChildAdapter->NeedsMapRegisters && !ChildAdapter->NoLocalPool )
{
if( !ChildAdapter->ScatterGather )
{
ContiguousTranslations = ChildAdapter->AdapterObject.ContiguousTranslations;
Entries = ContiguousTranslations->Entries;
if( ((__int64)Entries->u.VirtualAddress & 1) != 0 )
{
do
{
for( i = 0i64; (unsigned int)i < ContiguousTranslations->EntryCount; i = (unsigned int)(i + 1) )
HalpDmaReturnPageToSource(&ChildAdapter->AdapterObject, &ContiguousTranslations->Entries[i]);
Next = ContiguousTranslations->Next;
HalpMmAllocCtxFree((_HALP_ALLOC_CONTEXT *)IommuDevice, ContiguousTranslations);
ContiguousTranslations = Next;
}
while( Next );
}
else
{
HalpMmAllocCtxFree((_HALP_ALLOC_CONTEXT *)IommuDevice, Entries);
HalpMmAllocCtxFree(v12, ContiguousTranslations);
AllocationHandle = ChildAdapter->AllocationHandle;
if( ChildAdapter->IsAllocationMdlBased )
{
if( AllocationHandle )
{
VirtualAddress = ChildAdapter->VirtualAddress;
if( VirtualAddress )
MmUnmapLockedPages(VirtualAddress, (_MDL *)ChildAdapter->AllocationHandle);
MiFreePagesFromMdl(AllocationHandle, 0i64, v13);
ExFreePoolWithTag(AllocationHandle, 0);
}
}
else
{
MmFreeContiguousMemory(ChildAdapter->AllocationHandle);
}
}
ContiguousMapRegisters = ChildAdapter->AdapterObject.ContiguousMapRegisters;
goto LABEL_36;
}
NumberOfFreeScatterBuffers = ChildAdapter->AdapterObject.NumberOfFreeScatterBuffers;
ScatterBufferListHead = ChildAdapter->AdapterObject.ScatterBufferListHead;
if( NumberOfFreeScatterBuffers )
{
v21 = NumberOfFreeScatterBuffers;
do
{
v22 = ScatterBufferListHead->Next;
HalpDmaReturnPageToSource(&ChildAdapter->AdapterObject, ScatterBufferListHead);
ScatterBufferListHead = v22;
--v21;
}
while( v21 );
}
v23 = ChildAdapter->AllocationHandle;
if( v23 )
{
v24 = ChildAdapter->VirtualAddress;
if( v24 )
MmUnmapLockedPages(v24, (_MDL *)ChildAdapter->AllocationHandle);
MiFreePagesFromMdl(v23, 0i64, v1);
ExFreePoolWithTag(v23, 0);
}
ScatterTranslations = ChildAdapter->AdapterObject.ScatterTranslations;
if( ScatterTranslations )
{
HalpMmAllocCtxFree((_HALP_ALLOC_CONTEXT *)IommuDevice, ScatterTranslations->Entries);
ContiguousMapRegisters = ChildAdapter->AdapterObject.ScatterTranslations;
LABEL_36:
HalpMmAllocCtxFree((_HALP_ALLOC_CONTEXT *)IommuDevice, ContiguousMapRegisters);
}
}
}Referenced by:
No references.