HalpDmaAllocateContiguousMemory

__int64 __fastcall HalpDmaAllocateContiguousMemory(
        __int64 a1,
        unsigned int a2,
        _QWORD *a3,
        PHYSICAL_ADDRESS *a4,
        _QWORD *a5){
  LARGE_INTEGER v5; 
  char v6; 
  __int64 v7; 
  UINT64 v8; 
  unsigned int v9; 
  LARGE_INTEGER v10; 
  char i; 
  LARGE_INTEGER v12; 
  void *ContiguousNodeMemory; 
  void *v14; 
  PHYSICAL_ADDRESS PhysicalAddress; 
  UINT64 Protect; 
  UINT64 PreferredNode; 
  v5 = *(LARGE_INTEGER *)(a1 + 136);
  v6 = 0;
  v7 = a1;
  v8 = (unsigned __int64)a2 << 12;
  v9 = a2;
  while( 2 )
  {
    if( v6 || *(_BYTE *)(v7 + 145) || v9 > 0x10 )
      v10.QuadPart = 0i64;
    else
      v10.QuadPart = 0x10000i64;
    for( i = 0; ; i = 1 )
    {
      v12.QuadPart = 0i64;
      if( !i && v5.LowPart == -1 )
        v12.QuadPart = 0x1000000i64;
      LODWORD(PreferredNode) = 0x80000000;
      LODWORD(Protect) = 4;
      ContiguousNodeMemory = MmAllocateContiguousNodeMemory(v8, v12, v5, v10, Protect, PreferredNode);
      v14 = ContiguousNodeMemory;
      if( ContiguousNodeMemory )
      {
        PhysicalAddress = MmGetPhysicalAddress(ContiguousNodeMemory);
        *a3 = v14;
        *a4 = PhysicalAddress;
        goto LABEL_20;
      }
      if( i || !v12.QuadPart )
        break;
    }
    if( !v6 && v10.QuadPart )
    {
      v7 = a1;
      v6 = 1;
      continue;
    }
    break;
  }
  v9 = 0;
LABEL_20:
  *a5 = 0i64;
  return v9;
}

Referenced by:

HalpDmaAllocateLocalContiguousPool
HalpDmaAllocateMapRegisters
HalpDmaGrowContiguousMapBuffers