HalpTimerConfigureInterrupt

NTSTATUS __fastcall HalpTimerConfigureInterrupt(
        _KDPC *Dpc,
        PVOID Vector,
        _KINTERRUPT_MODE Irql,
        INT64 a4,
        UINT64 *DistinguishedSpinlockValue,
        INT64 a6,
        _GROUP_AFFINITY *GroupAffinity,
        VOID *Context){
  unsigned int v8; 
  char v9; 
  _GROUP_AFFINITY v11; 
  void *v12; 
  INT64 v13; 
  void *v14; 
  void *v15; 
  signed int v16; 
  int DeferredContext; 
  __int64 v18; 
  INT64 v19; 
  NTSTATUS v20; 
  VOID *v22; 
  VOID *v23; 
  unsigned int *v24; 
  unsigned int MessageAddressHigh; 
  int v26; 
  int v27; 
  unsigned int ProcessorHistory_high; 
  bool v29; 
  void *v30; 
  void *v31; 
  void *v32; 
  __int64 v33; 
  _KINTERRUPT_MODE v34; 
  unsigned __int8 v35; 
  _KINTERRUPT_MODE v36; 
  unsigned __int64 v37; 
  UINT64 VectorCount; 
  _INTERRUPT_LINE Line; 
  UINT64 Flags; 
  _INTERRUPT_LINE Destination; 
  NTSTATUS FirstSetRightGroupAffinity; 
  int v43; 
  __int128 *v44; 
  __int128 v45; 
  _INTERRUPT_VECTOR_DATA VectorData; 

  v8 = (unsigned int)Vector;
  Destination.Line = 0;
  v43 = 0;
  v9 = Irql;
  Line = 0i64;
  v45 = 0i64;
  memset(&VectorData, 0i64, sizeof(VectorData));
  v11 = *GroupAffinity;
  VectorData.Vector = v8;
  VectorData.Irql = v9;
  Destination.UnitId = 6;
  VectorData.IntRemapInfo._bf_0 = a6 & 0x3FFFFFFF | VectorData.IntRemapInfo._bf_0 & 0xC0000000 | 0x40000000;
  VectorData.TargetProcessors = v11;
  FirstSetRightGroupAffinity = KeFindFirstSetRightGroupAffinity((INT64)GroupAffinity);
  v44 = &v45;
  v16 = -1073741637;
  LODWORD(v45) = a6 & 0x3FFFFFFF;
  DeferredContext = (int)Dpc[3].DeferredContext;
  if( (DeferredContext & 0x800) != 0 )
  {
    HalpTimerGetInternalData(Dpc, v12, v14, v15);
    ((void(__fastcall *)(__int64, _QWORD))Dpc[2].SystemArgument1)(v18, v8);
    HalpInterruptSetIdtEntry(v8, Context, v9, v19, DistinguishedSpinlockValue);
    return 0;
  }
  if( (DeferredContext & 0x400) != 0 )
  {
    LOBYTE(v13) = 1;
    if( (unsigned __int8)HalpInterruptIsMsiSupported(v13) )
    {
      if( ((__int64)Dpc[2].DpcData & 0x50) != 64 )
      {
        HalpInterruptSetIdtEntry(v8, Context, v9, (INT64)v15, DistinguishedSpinlockValue);
        if( ((__int64)Dpc[2].DpcData & 0x40) == 0 )
        {
          v24 = (unsigned int *)Dpc[4].DeferredContext;
          VectorData.Polarity = InterruptPolarityUnknown;
          VectorData.Type = InterruptTypeMessageRequest;
          VectorData.Mode = Latched;
          LODWORD(VectorCount) = 1;
          v16 = HalpInterruptRemap(*v24, v24[1], (_PCI_BUSMASTER_DESCRIPTOR *)(v24 + 2), 0, &VectorData, VectorCount);
          if( v16 < 0 )
            goto LABEL_15;
          MessageAddressHigh = VectorData.IntRemapInfo.u.MessageAddressHigh;
          LODWORD(Dpc[2].DpcData) |= 0x40u;
          HIDWORD(Dpc[3].SystemArgument1) = MessageAddressHigh;
          LODWORD(Dpc[3].SystemArgument1) = VectorData.IntRemapInfo.u.MessageAddressLow;
          Dpc[3].SystemArgument2 = (void *)VectorData.IntRemapInfo.u.MessageData;
        }
        v16 = HalpTimerSetupMessageInterruptRouting((INT64)Dpc, v22, v23, v15);
        if( v16 >= 0 )
          LODWORD(Dpc[2].DpcData) |= 0x10u;
        else
          HalpTimerUnmapInterrupt((__int64)Dpc, v8, a6, 1);
        if( v16 >= 0 )
          return 0;
      }
    }
  }
LABEL_15:
  v26 = (int)Dpc[3].DeferredContext;
  if( (v26 & 0x200) != 0 )
  {
    v20 = HalpInterruptGsiToLine(LODWORD(Dpc[1].DeferredRoutine), &Line);
    if( v20 < 0 )
    {
      v27 = 16;
      Dpc[4].TargetInfoAsUlong = v20;
      LODWORD(Dpc[4].ProcessorHistory) = 356;
LABEL_37:
      HalpTimerLastProblem = v27;
      HIDWORD(Dpc[3].DpcData) = v27;
      Dpc[4].DpcListEntry.Next = (_SINGLE_LIST_ENTRY *)"minkernel\\hals\\lib\\timers\\common\\timersup.c";
      return v20;
    }
  }
  else
  {
    if( (v26 & 0x100) == 0 )
    {
      Dpc[4].TargetInfoAsUlong = v16;
      v27 = 17;
      v20 = -1073741811;
      LODWORD(Dpc[4].ProcessorHistory) = 371;
      goto LABEL_37;
    }
    ProcessorHistory_high = HIDWORD(Dpc[1].ProcessorHistory);
    if( ProcessorHistory_high >= 8 )
    {
      Line.UnitId = 45057;
      ProcessorHistory_high -= 8;
    }
    else
    {
      Line.UnitId = 45056;
    }
    v29 = HIDWORD(Dpc[1].DeferredRoutine) == 0;
    Line.Line = ProcessorHistory_high;
    if( v29 )
    {
      HIDWORD(Dpc[1].DeferredRoutine) = 1;
      LODWORD(Dpc[1].DeferredContext) = 1;
    }
  }
  HalpInterruptSetIdtEntry(v8, Context, v9, (INT64)v15, DistinguishedSpinlockValue);
  if( ((__int64)Dpc[2].DpcData & 0x10) == 0 )
    goto LABEL_28;
  HalpTimerGetInternalData(Dpc, v30, v31, v32);
  v20 = ((__int64(__fastcall *)(__int64, _QWORD, _QWORD, _QWORD))Dpc[2].DeferredRoutine)(v33, 0i64, 0i64, 0i64);
  if( v20 < 0 )
  {
    v27 = 24;
    Dpc[4].TargetInfoAsUlong = v20;
    LODWORD(Dpc[4].ProcessorHistory) = 398;
    goto LABEL_37;
  }
  LODWORD(Dpc[2].DpcData) &= ~0x10u;
  if( ((__int64)Dpc[2].DpcData & 0x10) == 0 )
  {
LABEL_28:
    if( v8 == 209 )
    {
      qword_140C4A4A0 = (__int64)Line;
      HalpTimerCriticalClockSourceCount = 1;
    }
  }
  v34 = (_KINTERRUPT_MODE)Dpc[1].DeferredContext;
  VectorData.Type = InterruptTypeControllerInput;
  VectorData.Mode = v34;
  VectorData.Polarity = HIDWORD(Dpc[1].DeferredRoutine);
  HalpInterruptApplyOverrides(&Line, &VectorData.Polarity, &VectorData.Mode);
  v20 = HalpInterruptLineToGsi(&Line, (UINT64 *)&VectorData.ControllerInput);
  if( v20 < 0 )
    return v20;
  if( ((__int64)Dpc[2].DpcData & 0x40) == 0 )
  {
    LODWORD(VectorCount) = 1;
    v20 = HalpInterruptRemap(
            *(unsigned int *)Dpc[4].DeferredContext,
            *((unsigned int *)Dpc[4].DeferredContext + 1),
            (_PCI_BUSMASTER_DESCRIPTOR *)((char *)Dpc[4].DeferredContext + 8),
            0,
            &VectorData,
            VectorCount);
    if( v20 < 0 )
      return v20;
    LODWORD(Dpc[2].DpcData) |= 0x40u;
  }
  Flags = 0x1FFFFFFFFi64;
  v35 = HalpAcquireHighLevelLock(&qword_140C49C40);
  LOBYTE(v36) = v9;
  v37 = v35;
  v20 = HalpInterruptSetLineState(
          &Line,
          (PVOID)v8,
          v36,
          (_KINTERRUPT_POLARITY)VectorData.Mode,
          VectorData.Polarity,
          &Destination,
          (UINT64)&Flags);
  KxReleaseSpinLock(&qword_140C49C40);
  __writecr8(v37);
  if( v20 < 0 )
    return v20;
  return 0;
}

Referenced by:

HalpTimerInitializeClock
HalpTimerInitializeProfiling
HalpTimerPrepareClockInterrupt
HalpTimerTestHypervisorTimer