HalGetDmaTransferInfoInternal

NTSTATUS __fastcall HalGetDmaTransferInfoInternal(
        _ADAPTER_OBJECT *ChildAdapter,
        INT64 *a2,
        UINT64 a3,
        UINT64 a4,
        INT64 a5,
        INT64 a6){
  _DWORD *v6; 
  unsigned int v7; 
  INT64 *v8; 
  int v10; 
  UINT64 v11; 
  unsigned int DmaAddressWidth; 
  int v13; 
  int v14; 
  int v15; 
  __int64 v16; 
  char v17; 
  INT64 v18; 
  unsigned int v19; 
  unsigned int v20; 
  unsigned int v21; 
  unsigned __int8 ScatterGather; 
  _LARGE_INTEGER MaximumPhysicalAddress; 
  INT64 *v24; 
  int v25; 
  __int64 v26; 
  INT64 v27; 
  unsigned int v28; 
  int v29; 
  NTSTATUS AdapterCacheAlignment; 
  int v32; 
  INT64 v33; 
  INT64 *v34; 
  __int64 v35; 
  int v36; 
  __int64 v37; 
  INT64 *v38; 
  unsigned int v39; 
  int a5a; 

  v6 = (_DWORD *)a6;
  v7 = a4;
  v8 = a2;
  v10 = *(_DWORD *)a6;
  v32 = *(_DWORD *)a6;
  if( *(_DWORD *)a6 > 2u )
    return -1073741637;
  if( a2 )
  {
    do
    {
      v11 = *((unsigned int *)v8 + 10);
      if( a3 < v11 )
        break;
      v8 = (INT64 *)*v8;
      a3 -= v11;
    }
    while( v8 );
    v38 = v8;
    if( v8 )
    {
      DmaAddressWidth = ChildAdapter->DmaAddressWidth;
      v13 = 0;
      v14 = 0;
      v15 = 0;
      v16 = 0i64;
      if( DmaAddressWidth < 0x40 )
        v16 = ~((1i64 << DmaAddressWidth) - 1);
      if( v7 )
      {
        do
        {
          if( !v8 )
            break;
          v17 = 0;
          v18 = 0i64;
          v19 = v7;
          if( *((_DWORD *)v8 + 10) - (int)a3 <= v7 )
            v19 = *((_DWORD *)v8 + 10) - a3;
          v20 = v19;
          v7 -= v19;
          v21 = ((_WORD)a3 + *((_WORD *)v8 + 22)) & 0xFFF;
          v39 = v7;
          v34 = &v8[((unsigned __int64)(unsigned int)(a3 + *((_DWORD *)v8 + 11)) >> 12) + 6];
          v15 += (v19 + (unsigned __int64)(((_WORD)a3 + *((_WORD *)v8 + 22)) & 0xFFF) + 4095) >> 12;
          a5a = v15;
          if( v19 )
          {
            ScatterGather = ChildAdapter->ScatterGather;
            MaximumPhysicalAddress = ChildAdapter->AdapterObject.MaximumPhysicalAddress;
            v24 = v34;
            do
            {
              v25 = v13 + 1;
              v26 = v20;
              if( 4096 - v21 <= v20 )
                v26 = 4096 - v21;
              if( ScatterGather )
                v25 = v13;
              v35 = v26;
              v27 = *v24 << 12;
              v37 = v21;
              v33 = v27;
              v36 = v27 + v21;
              if( (MaximumPhysicalAddress.QuadPart >= v27 + (unsigned __int64)v21 + v26 - 1
                 || ChildAdapter->TranslationType == ExtTranslationTypeTranslate)
                && (ChildAdapter->CacheCoherent
                 || (AdapterCacheAlignment = HalpDmaGetAdapterCacheAlignment(ChildAdapter),
                     v27 = v33,
                     ((AdapterCacheAlignment - 1) & v36) == 0)
                 && ((AdapterCacheAlignment - 1) & (unsigned int)v35) == 0) )
              {
                if( v21
                  || v27 != v18 + 1
                  || ((v27 ^ v18) & v16) != 0
                  || ((v27 ^ v18) & 0x100000000i64) != 0
                  || (v13 = v25, v17) )
                {
                  ++v14;
                  v13 = v25;
                  v17 = 0;
                }
              }
              else
              {
                ++v14;
                v13 = v25 + 1;
                v17 = 1;
                if( !ScatterGather )
                  v13 = v25;
              }
              ++v24;
              v21 = 0;
              v18 = v27 + v35 + v37 - 1;
              v20 -= v35;
            }
            while( v20 );
            v8 = v38;
            v7 = v39;
            v15 = a5a;
          }
          v8 = (INT64 *)*v8;
          LODWORD(a3) = 0;
          v38 = v8;
        }
        while( v7 );
        v6 = (_DWORD *)a6;
        v10 = v32;
      }
      if( !ChildAdapter->ScatterGather && (v14 != 1 || v13) )
      {
        v14 = 1;
        v13 = v15;
      }
      v28 = 24 * v14 + 208;
      if( v28 < 0xA8 )
        v28 = 168;
      v29 = v10 - 1;
      if( !v29 )
        goto LABEL_31;
      if( v29 == 1 )
      {
        v6[4] = v15;
LABEL_31:
        v6[1] = v13;
        v6[2] = v14;
        v6[3] = v28;
        return 0;
      }
      return -1073741637;
    }
  }
  return -1073741811;
}

Referenced by:

HalGetDmaTransferInfo
HalpBuildScatterGatherList