Newer
Older
AMI-Aptio-BIOS-Reversed / PurleySktPkg / SouthClusterLbg / SiInit / Pei / SiInitPreMem / XhciGpioPpiGlue.c
/* Consolidated from decompiled shard files. */

/* Source: ffd860b8.c */
int __thiscall ConfigureXhciPreMem(int this)
{
  int v2; // esi
  int v3; // edi
  int v4; // eax
  _DWORD *v5; // eax
  int n8; // edx
  int v8; // [esp+14h] [ebp-8h] BYREF
  int n17; // [esp+18h] [ebp-4h] BYREF

  DebugPrint(64, (int)"ConfigureXhci() - Start\n"); /*0xffd860c8*/
  v2 = *(_DWORD *)(this + 3510); /*0xffd860cd*/
  PchGetSteppingInfo(); /*0xffd860d9*/
  v3 = PchPciSegmentGetDevice(0, 20, 0); /*0xffd860f1*/
  PchPwrmBaseSet(&v8); /*0xffd860f3*/
  *(_DWORD *)(v3 + 16) = v2; /*0xffd860fd*/
  PchPciSegmentSetBar(v3 + 4, 6); /*0xffd86101*/
  if ( (*(_BYTE *)(this + 2263) & 2) != 0 ) /*0xffd86109*/
    *(_DWORD *)(v2 + 33004) |= 1u; /*0xffd86114*/
  v4 = GetPeiServicesPtr(); /*0xffd8611a*/
  (*(void (__cdecl **)(int, int *))(*(_DWORD *)v4 + 40))(v4, &n17); /*0xffd86127*/
  if ( n17 == 17 ) /*0xffd86133*/
    XhciConfigureSsic(this + 2263); /*0xffd86137*/
  else
    XhciDisableSsic(); /*0xffd8613e*/
  XhciConfigurePorts(this, v2, v3); /*0xffd86148*/
  XhciConfigureMisc(this, v2); /*0xffd86151*/
  DebugPrint(64, (int)"xHCI: XhciPostInitDone Start\n");
  *(_DWORD *)(v2 + 32992) &= ~0x10000u; /*0xffd86174*/
  *(_DWORD *)(v3 + 80) = 265186911; /*0xffd8617c*/
  DebugPrint(64, (int)"xHCI: XhciPostInitDone End\n");
  if ( (*(_BYTE *)(this + 2263) & 4) != 0 ) /*0xffd8618e*/
  {
    XhciClearOverCurrentRegisters(this + 2263, v3); /*0xffd86194*/
  }
  else
  {
    DebugPrint(0x80000000, (int)"Clear Over-Current registers\n"); /*0xffd861a5*/
    v5 = (_DWORD *)(v3 + 208); /*0xffd861ae*/
    n8 = 8; /*0xffd861b4*/
    do /*0xffd861c8*/
    {
      *(v5 - 8) = 0; /*0xffd861b5*/
      *v5++ = 0; /*0xffd861bc*/
      --n8; /*0xffd861c5*/
    }
    while ( n8 ); /*0xffd861c8*/
  }
  XhciFinalizePreMem(this + 2263, v2); /*0xffd861ce*/
  PchPciSegmentClearBar(v3 + 4, 65529); /*0xffd861db*/
  *(_DWORD *)(v3 + 16) = 0; /*0xffd861e7*/
  DebugPrint(64, (int)"ConfigureXhciPreMem () - End\n"); /*0xffd861ee*/
  return 0; /*0xffd861f5*/
}

/* Source: ffd8690c.c */
int __fastcall XhciProgramUsb2Afe(int a1, int a2)
{
  int v2; // ebp
  int n15_1; // ebx
  unsigned __int8 i_4; // cl
  unsigned __int8 i_1; // al
  unsigned __int64 v6; // rdi
  int v7; // ebx
  int v8; // ebp
  _DWORD *v9; // eax
  _DWORD *v10; // esi
  unsigned int v11; // ecx
  int result; // eax
  int v13; // [esp-8h] [ebp-34h]
  char v14; // [esp+11h] [ebp-1Bh] BYREF
  unsigned __int8 i; // [esp+12h] [ebp-1Ah]
  unsigned __int8 i_3; // [esp+13h] [ebp-19h]
  unsigned int n1342177280; // [esp+14h] [ebp-18h] BYREF
  int v18; // [esp+18h] [ebp-14h]
  int v19; // [esp+1Ch] [ebp-10h]
  int n15; // [esp+20h] [ebp-Ch] BYREF
  unsigned int i_2; // [esp+24h] [ebp-8h] BYREF
  unsigned int v22; // [esp+28h] [ebp-4h] BYREF

  v2 = a2; /*0xffd86913*/
  v19 = a1; /*0xffd86915*/
  v18 = a2; /*0xffd86920*/
  DebugPrint(64, (int)"xHCI: Usb2AfeProgramming Start\n");
  PchGetSteppingInfo(); /*0xffd86929*/
  PchInfoGetPchSteppingStr(v13); /*0xffd8692e*/
  PchPwrmBaseGet(&v22); /*0xffd86937*/
  n15_1 = PchPciSegmentGetDevice(0, 31, 2); /*0xffd8694b*/
  n15 = n15_1; /*0xffd86951*/
  PchPciSegmentRead32(202, 6, 16427, 0, 0, 0, &n1342177280, &v14, 6); /*0xffd86970*/
  n1342177280 |= 0x400000u; /*0xffd86975*/
  PchPciSegmentWrite32(202, 7, 16427, 0, 1u, 0, &n1342177280, &v14, 7); /*0xffd86999*/
  PchPciSegmentOr32(n1342177280, v2, n15_1); /*0xffd869a9*/
  PchPciSegmentRead32(202, 6, 16385, 0, 0, 0, &n1342177280, &v14, 6); /*0xffd869cc*/
  n1342177280 |= 0x3000000u; /*0xffd869d8*/
  PchPciSegmentWrite32(202, 7, 16385, 0, 1u, 0, &n1342177280, &v14, 7); /*0xffd869f5*/
  PchPciSegmentOr32(n1342177280, v2, n15_1); /*0xffd86a05*/
  PchPciSegmentRead32(202, 6, 28672, 0, 0, 0, &n1342177280, &v14, 6); /*0xffd86a2a*/
  n1342177280 = (unsigned __int16)n1342177280 | 0x50500000; /*0xffd86a41*/
  PchPciSegmentWrite32(202, 7, 28672, 0, 1u, 0, &n1342177280, &v14, 7); /*0xffd86a59*/
  PchPciSegmentOr32(n1342177280, v2, n15_1); /*0xffd86a69*/
  n1342177280 = 1342177280; /*0xffd86a71*/
  PchPciSegmentWrite32(202, 7, 28724, 0, 1u, 0, &n1342177280, &v14, 7); /*0xffd86a95*/
  PchPciSegmentOr32(n1342177280, v2, n15_1); /*0xffd86aa5*/
  n1342177280 = 175176950; /*0xffd86aad*/
  PchPciSegmentWrite32(202, 7, 28728, 0, 1u, 0, &n1342177280, &v14, 7); /*0xffd86ad3*/
  PchPciSegmentOr32(n1342177280, v2, n15_1); /*0xffd86ae3*/
  n1342177280 = 532398080; /*0xffd86aeb*/
  PchPciSegmentWrite32(202, 7, 28732, 0, 1u, 0, &n1342177280, &v14, 7); /*0xffd86b0f*/
  PchPciSegmentOr32(n1342177280, v2, n15_1); /*0xffd86b1f*/
  n1342177280 = 34432; /*0xffd86b27*/
  PchPciSegmentWrite32(202, 7, 32516, 0, 1u, 0, &n1342177280, &v14, 7); /*0xffd86b4d*/
  PchPciSegmentOr32(n1342177280, v2, n15_1); /*0xffd86b5d*/
  n1342177280 = 67251212; /*0xffd86b65*/
  PchPciSegmentWrite32(202, 7, 28712, 0, 1u, 0, &n1342177280, &v14, 7); /*0xffd86b8b*/
  PchPciSegmentOr32(n1342177280, v2, n15_1); /*0xffd86b9b*/
  n1342177280 = 184552192; /*0xffd86ba9*/
  PchPciSegmentWrite32(202, 7, 32515, 0, 1u, 0, &n1342177280, &v14, 7); /*0xffd86bc9*/
  PchPciSegmentOr32(n1342177280, v2, n15_1); /*0xffd86bd9*/
  i_4 = PchGetPchPortCount(); /*0xffd86be6*/
  i_1 = 1; /*0xffd86be8*/
  i_3 = i_4; /*0xffd86bea*/
  for ( i = 1; i_1 <= i_3; i = i_1 ) /*0xffd86bf4*/
  {
    i_2 = i_1; /*0xffd86c07*/
    v6 = (unsigned __int64)(i_1 | 0x40u) << 8; /*0xffd86c25*/
    PchPciSegmentRead32(202, 6, v6, SHIDWORD(v6), 0, 0, &n1342177280, &v14, 6); /*0xffd86c2c*/
    v7 = 2 * i; /*0xffd86c3d*/
    n1342177280 = n1342177280 & 0xFFFF80FF /*0xffd86c87*/
                | ((*(_BYTE *)(v19 + 16 * i - 3) & 7
                  | (8 * (*(_BYTE *)(v19 + 16 * i - 4) & 7 | (8 * (*(_BYTE *)(v19 + 16 * i - 1) & 1))))) << 8)
                | 0xFC000010;
    PchPciSegmentWrite32(202, 7, v6, SHIDWORD(v6), 1u, 0, &n1342177280, &v14, 7); /*0xffd86c93*/
    PchPciSegmentOr32(n1342177280, v18, n15); /*0xffd86ca9*/
    v8 = (unsigned __int64)i_2 >> 24; /*0xffd86cb9*/
    LODWORD(v6) = i_2 << 8; /*0xffd86cbd*/
    HIDWORD(v6) = (i_2 << 8) | 0x4026; /*0xffd86cca*/
    n1342177280 = 0; /*0xffd86cd8*/
    PchPciSegmentRead32(202, 6, SHIDWORD(v6), v8, 0, 0, &n1342177280, &v14, 6); /*0xffd86ce2*/
    n1342177280 ^= (n1342177280 ^ (*(unsigned __int8 *)(v19 + 8 * v7 - 2) << 23)) & 0x1800000; /*0xffd86d0b*/
    PchPciSegmentWrite32(202, 7, SHIDWORD(v6), v8, 1u, 0, &n1342177280, &v14, 7); /*0xffd86d22*/
    n15_1 = n15; /*0xffd86d27*/
    PchPciSegmentOr32(n1342177280, v18, n15); /*0xffd86d39*/
    LODWORD(v6) = v6 | 0x4008; /*0xffd86d47*/
    PchPciSegmentRead32(202, 6, v6, v8, 0, 0, &n1342177280, &v14, 6); /*0xffd86d61*/
    n1342177280 = n1342177280 & 0xFFFFC17F | 0x1A80; /*0xffd86d7c*/
    PchPciSegmentWrite32(202, 7, v6, v8, 1u, 0, &n1342177280, &v14, 7); /*0xffd86d94*/
    v2 = v18; /*0xffd86d99*/
    PchPciSegmentOr32(n1342177280, v18, n15_1); /*0xffd86da8*/
    i_1 = i + 1; /*0xffd86db4*/
  }
  if ( PchGetSteppingInfo() == 2 ) /*0xffd86dcc*/
  {
    i_3 = PchGetPchPortCount(&i_2); /*0xffd86ddd*/
    v9 = (_DWORD *)PchGetPchPortCount(); /*0xffd86de1*/
    v10 = v9; /*0xffd86de6*/
    if ( v9 ) /*0xffd86dea*/
    {
      v11 = i_2 + *v9; /*0xffd86df2*/
      n15 = 15; /*0xffd86df8*/
      PchPciSegmentWriteBuffer(v11, &n15, 4); /*0xffd86e00*/
      *v10 += 4; /*0xffd86e05*/
      if ( i_3 == 1 ) /*0xffd86e0e*/
        PchPciSegmentClearDevice(n15_1); /*0xffd86e12*/
    }
  }
  PchPciSegmentAndThenOr(v2, n15_1); /*0xffd86e1b*/
  result = *(_DWORD *)(v22 + 24) | 0x20000000; /*0xffd86e2a*/
  *(_DWORD *)(v22 + 24) = result; /*0xffd86e2f*/
  return result; /*0xffd86e24*/
}

/* Source: ffd87b03.c */
int __thiscall ConfigureXdciPreMem(int this)
{
  int v2; // edi
  int v3; // ebx
  int v5; // ebp
  unsigned int n0x3E8; // esi
  unsigned int i; // ebp
  int n2; // esi
  int n35; // edi
  unsigned int v10; // [esp+10h] [ebp-4h] BYREF

  v2 = *(_DWORD *)(this + 3510); /*0xffd87b11*/
  v3 = PchPciSegmentGetDevice(0, 20, 1); /*0xffd87b1d*/
  if ( (unsigned __int16)PchPciSegmentRead16((unsigned __int16 *)v3) == 0xFFFF )
  {
    DebugPrint(64, (int)"xDCI: Pci device NOT found\n");
    return -2147483634; /*0xffd87b3e*/
  }
  else
  {
    v5 = PchPciSegmentGetDevice(0, 20, 0); /*0xffd87b63*/
    PchPciSegmentAndThenOr(-1, 63); /*0xffd87b65*/
    PchPciSegmentWrite16(); /*0xffd87b6a*/
    if ( (*(_BYTE *)(this + 2683) & 1) != 0 )
    {
      *(_DWORD *)(v5 + 16) = v2; /*0xffd87cfb*/
      PchPciSegmentSetBar(v5 + 4, 2); /*0xffd87cfe*/
      *(_DWORD *)(v2 + 32984) &= 0xFFCFFFFF; /*0xffd87d11*/
      PchPciSegmentClearBar(v5 + 4, 65533); /*0xffd87d1e*/
      *(_DWORD *)(v5 + 16) = 0; /*0xffd87d2b*/
      PchPciSegmentFlush(4); /*0xffd87d34*/
    }
    else
    {
      DebugPrint(64, (int)"xDCI: Device disabled\n");
      *(_DWORD *)(v5 + 16) = v2; /*0xffd87b91*/
      PchPciSegmentSetBar(v5 + 4, 2); /*0xffd87b95*/
      *(_DWORD *)(v2 + 32984) |= 0x200000u; /*0xffd87ba5*/
      n0x3E8 = 0; /*0xffd87bb6*/
      *(_DWORD *)(v2 + 32984) &= ~0x100000u; /*0xffd87bb8*/
      while ( (*(_DWORD *)(v2 + 32988) & 0x20000000) == 0 && n0x3E8 < 0x3E8 ) /*0xffd87bc6*/
      {
        Stall(0x64u); /*0xffd87bcb*/
        ++n0x3E8; /*0xffd87bd0*/
      }
      *(_DWORD *)(v2 + 32984) = *(_DWORD *)(v2 + 32984) & 0xFFFFFFFC | 1; /*0xffd87bf4*/
      PchPciSegmentClearBar(v5 + 4, 65533); /*0xffd87bfa*/
      *(_DWORD *)(v5 + 16) = 0; /*0xffd87c01*/
      *(_DWORD *)(v3 + 16) = v2; /*0xffd87c0c*/
      PchPciSegmentSetBar(v3 + 4, 2); /*0xffd87c0f*/
      *(_DWORD *)(v2 + 49424) |= 2u; /*0xffd87c23*/
      *(_DWORD *)(v2 + 49664) |= 0x40u; /*0xffd87c32*/
      *(_DWORD *)(v2 + 49856) |= 0x8000000u; /*0xffd87c46*/
      PchPciSegmentSetBar(v2 + 1112088, 3); /*0xffd87c4c*/
      for ( i = 0; (PchPciSegmentRead16((unsigned __int16 *)(v2 + 1112080)) & 0xF00) == 0 && i < 0x3E8; ++i ) /*0xffd87c51*/
        Stall(0x64u); /*0xffd87c60*/
      PchPciSegmentClearBar(v3 + 4, 65533); /*0xffd87c80*/
      *(_DWORD *)(v3 + 16) = 0; /*0xffd87c85*/
      *(_DWORD *)(v3 + 132) |= 3u; /*0xffd87c95*/
      n2 = PchGetSteppingInfo(); /*0xffd87ca0*/
      n35 = PchInfoGetPchSteppingStr(); /*0xffd87ca7*/
      PchPciSegmentAndThenOr(-1, 256); /*0xffd87cc4*/
      PchPwrmBaseGet(&v10); /*0xffd87ccf*/
      if ( n2 == 2 && n35 >= 35 ) /*0xffd87cdc*/
        *(_DWORD *)(v10 + 1576) |= 0x1000000u; /*0xffd87ced*/
    }
    return 0; /*0xffd87d3a*/
  }
}

/* Source: ffd8b940.c */
int __thiscall InitializeGpioPads(void *this)
{
  int n256; // esi
  int n13; // edi
  int v3; // eax
  void *v4; // ecx
  int v5; // eax
  int result; // eax

  n256 = 256; /*0xffd8b947*/
  n13 = 13; /*0xffd8b94e*/
  do /*0xffd8b9e0*/
  {
    v3 = PchPcrWrite32(n256, this, -1, 0, 0); /*0xffd8b95f*/
    if ( v3 < 0 ) /*0xffd8b969*/
    {
      DebugPrint(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", v3); /*0xffd8b976*/
      v5 = GetReportStatusCodePpi(); /*0xffd8b97e*/
      if ( v5 ) /*0xffd8b985*/
        (*(void (__cdecl **)(const char *, int, const char *))(v5 + 4))( /*0xffd8b992*/
          "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmGpioLib\\GpioLib.c",
          1584,
          "!EFI_ERROR (Status)");
    }
    result = PchPcrWrite32(n256, v4, -1, 0, 0); /*0xffd8b9a3*/
    if ( result < 0 ) /*0xffd8b9ad*/
    {
      DebugPrint(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", result); /*0xffd8b9ba*/
      result = GetReportStatusCodePpi(); /*0xffd8b9c2*/
      if ( result ) /*0xffd8b9c9*/
        result = (*(int (__cdecl **)(const char *, int, const char *))(result + 4))( /*0xffd8b9d6*/
                   "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmGpioLib\\GpioLib.c",
                   1712,
                   "!EFI_ERROR (Status)");
    }
    ++n256; /*0xffd8b9dc*/
    --n13; /*0xffd8b9dd*/
  }
  while ( n13 ); /*0xffd8b9e0*/
  return result; /*0xffd8b9e6*/
}