예제 #1
0
파일: IScsiIbft.c 프로젝트: Kohrara/edk
VOID
IScsiPublishIbft (
  IN VOID
  )
/*++

Routine Description:

  Publish and remove the iSCSI Boot Firmware Table according to the iSCSI
  session status.

Arguments:

  None.

Returns:

  None.

--*/
{
  EFI_STATUS                                    Status;
  UINTN                                         TableHandle;
  EFI_ACPI_SUPPORT_PROTOCOL                     *AcpiSupport;
  EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_HEADER     *Table;
  EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER  *Rsdp;
  EFI_ACPI_DESCRIPTION_HEADER                   *Rsdt;
  UINTN                                         HandleCount;
  EFI_HANDLE                                    *HandleBuffer;
  UINT8                                         *Heap;
  UINTN                                         Index;
  INTN                                          TableIndex;
  EFI_ACPI_TABLE_VERSION                        Version;
  UINT32                                        Signature;

  Status = gBS->LocateProtocol (&gEfiAcpiSupportGuid, NULL, &AcpiSupport);
  if (EFI_ERROR (Status)) {
    return ;
  }

  //
  // Find ACPI table RSD_PTR from system table
  //
  for (Index = 0, Rsdp = NULL; Index < gST->NumberOfTableEntries; Index++) {
    if (EfiCompareGuid (&(gST->ConfigurationTable[Index].VendorGuid), &gEfiAcpi30TableGuid) ||
      EfiCompareGuid (&(gST->ConfigurationTable[Index].VendorGuid), &gEfiAcpi20TableGuid) ||
      EfiCompareGuid (&(gST->ConfigurationTable[Index].VendorGuid), &gEfiAcpiTableGuid)
      ) {
      //
      // A match was found.
      //
      Rsdp = (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *) gST->ConfigurationTable[Index].VendorTable;
      break;
    }
  }

  if (Rsdp == NULL) {
    return ;
  } else {
    Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) Rsdp->RsdtAddress;
  }

  //
  // Try to remove the old iSCSI Boot Firmware Table.
  //
  for (TableIndex = 0;; TableIndex++) {
    Status = AcpiSupport->GetAcpiTable (
                            AcpiSupport,
                            TableIndex,
                            &Table,
                            &Version,
                            &TableHandle
                            );
    if (EFI_ERROR (Status)) {
      break;
    }

    Signature = Table->Signature;
    NetFreePool (Table);

    if (Signature == EFI_ACPI_3_0_ISCSI_BOOT_FIRMWARE_TABLE_SIGNATURE) {
      //
      // Remove the table.
      //
      Status = AcpiSupport->SetAcpiTable (
                              AcpiSupport,
                              NULL,
                              FALSE,
                              Version,
                              &TableHandle
                              );
      if (EFI_ERROR (Status)) {
        return ;
      }

      break;
    }
  }
  //
  // Get all iSCSI private protocols.
  //
  Status = gBS->LocateHandleBuffer (
                  ByProtocol,
                  &mIScsiPrivateGuid,
                  NULL,
                  &HandleCount,
                  &HandleBuffer
                  );
  if (EFI_ERROR (Status)) {
    return ;
  }
  //
  // Allocate 4k bytes to hold the ACPI table.
  //
  Table = NetAllocatePool (IBFT_MAX_SIZE);
  if (Table == NULL) {
    return ;
  }

  Heap = (CHAR8 *) Table + IBFT_HEAP_OFFSET;

  //
  // Fill in the various section of the iSCSI Boot Firmware Table.
  //
  IScsiInitIbfTableHeader (Table, Rsdt->OemId, &Rsdt->OemTableId);
  IScsiInitControlSection (Table, HandleCount);
  IScsiFillInitiatorSection (Table, &Heap, HandleBuffer[0]);
  IScsiFillNICAndTargetSections (Table, &Heap, HandleCount, HandleBuffer);

  NetFreePool (HandleBuffer);

  TableHandle = 0;

  //
  // Install or update the iBFT table.
  //
  Status = AcpiSupport->SetAcpiTable (
                          AcpiSupport,
                          Table,
                          TRUE,
                          EFI_ACPI_TABLE_VERSION_3_0,
                          &TableHandle
                          );
  if (!EFI_ERROR (Status)) {
    AcpiSupport->PublishTables (AcpiSupport, EFI_ACPI_TABLE_VERSION_3_0);
  }

  NetFreePool (Table);
}
예제 #2
0
VOID
EFIAPI
FchAcpiInstall2Notify (
  IN EFI_EVENT                              Event,
  IN VOID                                   *Context
  )
{
  UINT8                                     *Temp;
  UINT8                                     *AmdAcpiDataTree;
  UINTN                                     Index;
  UINTN                                     TableHandle;
  EFI_STATUS                                Status;
  EFI_HANDLE                                Handle;
  EFI_ACPI_DESCRIPTION_HEADER               *Table;
  EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt;
  EFI_ACPI_TABLE_VERSION                    Version;
  EFI_ACPI_SUPPORT_PROTOCOL                 *AcpiSupport;
  FCH_ACPI_PROTOCOL                         *FchAcpiProtocol;
  EFI_PCI_IO_PROTOCOL                       *PciIo;

  Status = EFI_SUCCESS;
  AmdAcpiDataTree = NULL;

  Status = gBS->LocateProtocol (
                  &gEfiPciIoProtocolGuid,
                  NULL,
                  &PciIo
                  );

  if (EFI_ERROR (Status)) {
    return;
  }

  Status = gBS->LocateProtocol (
                  &gFchAcpiProtocolGuid,
                  NULL,
                  &FchAcpiProtocol
                  );

  if (!EFI_ERROR (Status)) {
    return;
  }

  Status = gBS->LocateProtocol (
                  &gEfiAcpiSupportGuid,
                  NULL,
                  &AcpiSupport
                  );

  if (EFI_ERROR (Status)) {
    return;
  }

  Index  = 0;
  TableHandle = 0;
  do {
    Table  = NULL;
    Status = AcpiSupport->GetAcpiTable (
                            AcpiSupport,
                            Index,
                            &Table,
                            &Version,
                            &TableHandle
                            );
    if (EFI_ERROR (Status)) {
      break;
    }
    //
    // Check Signture and update DSDT table
    //
    if (Table->Signature == EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE) {
      Status = AmdBuildAcpiDsdtTree ((EFI_ACPI_DESCRIPTION_HEADER *)Table, &AmdAcpiDataTree);
      if (EFI_ERROR (Status)) {
        return;
      }

      Status = gBS->AllocatePool (
                      EfiBootServicesData,
                      0x01,
                      &Temp
                      );
      ASSERT_EFI_ERROR (Status);

      *Temp = FCH_ACPI_FIELD_INFO_END;

      Status = gBS->AllocatePool (
                      EfiBootServicesData,
                      sizeof (FCH_ACPI_PROTOCOL),
                      &FchAcpiProtocol
                      );
      ASSERT_EFI_ERROR (Status);

      FchAcpiProtocol->Revision                      = FCH_ACPI_PROTOCOL_REV;
      FchAcpiProtocol->FchAcpiGetIntDevPathName      = AmdFchGetIntDevPath;
      FchAcpiProtocol->FchAcpiAddDataField           = AmdFchDataDxeAddItem;
      FchAcpiProtocol->FchAcpiEnableGpio             = AmdFchAcpiEnableGpio;
      FchAcpiProtocol->FchAcpiEnableAsf              = AmdFchAcpiEnableAsf;
      FchAcpiProtocol->FchAcpiTool.FindNextSig       = FchFindNextSig;
      FchAcpiProtocol->FchAcpiTool.UpdateAcpiName    = UpdateAcpiName;
      FchAcpiProtocol->FchAcpiTool.GetPkgLength      = FchAcpiPkgLength;
      FchAcpiProtocol->FchAcpiData.DataLength        = sizeof (AMD_FCH_COMMON_DATA);
      FchAcpiProtocol->FchAcpiData.AcpiInfoLength    = 0x01;
      FchAcpiProtocol->FchAcpiData.FchData           = mFchCommonData;
      FchAcpiProtocol->FchAcpiData.AcpiFieldNames    = Temp;

      Handle = NULL;
      Status = gBS->InstallProtocolInterface (
                      &Handle,
                      &gFchAcpiProtocolGuid,
                      EFI_NATIVE_INTERFACE,
                      FchAcpiProtocol
                      );
      if (EFI_ERROR (Status)) {
        return;
      }
    }

    //
    // Check Signture and update FADT table
    //
    if (Table->Signature == EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {
      Fadt = (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)Table;
      mFchCommonData->SciInterrupt = Fadt->SciInt;
    }

    gBS->FreePool (Table);
    Index++;
  } while (TRUE);

}
예제 #3
0
EFI_STATUS
AmdFchWheaInitEntryEinj (
  VOID
  )
{
  EFI_ACPI_SUPPORT_PROTOCOL       *AcpiSupport;
  EFI_STATUS                      Status;
  INTN                            Index;
  UINTN                           Handle;
  EFI_ACPI_TABLE_VERSION          Version;
  EFI_ACPI_DESCRIPTION_HEADER     *Table;
  EFI_ACPI_DESCRIPTION_HEADER     *NewTable;

  Status = gBS->LocateProtocol (
                  &gEfiAcpiSupportGuid,
                  NULL,
                  &AcpiSupport
                  );
  if (EFI_ERROR (Status)) {
    return Status;
  }
  //
  // Search EINJ table
  //
  Index  = 0;
  Handle = 0;
  do {
    Table  = NULL;
    Status = AcpiSupport->GetAcpiTable (
                            AcpiSupport,
                            Index,
                            &Table,
                            &Version,
                            &Handle
                            );
    if (EFI_ERROR (Status)) {
      break;
    }

    //
    // Check Signture and update EINJ table
    //
    if (Table->Signature == 0x4A4E4945) {
      //
      // allocate memory for new Table
      //
      Status = gBS->AllocatePool (
                      EfiReservedMemoryType,
                      MAX_EINJ_SIZE,
                      &NewTable
                      );
      if (Status != EFI_SUCCESS) {
        return Status;
      }
      EfiZeroMem (NewTable, MAX_EINJ_SIZE);
      //
      // Copy Table
      //
      EfiCopyMem (NewTable, Table, Table->Length);
      //
      // Update new table
      //
      AmdFchUpdateEinj (NewTable);

      if (!EFI_ERROR (Status)) {
      // Patch EINJ table here and save table back.

        //
        // Remove previous table
        //
        gBS->FreePool (Table);
        Table = NULL;
        Status = AcpiSupport->SetAcpiTable (
                                AcpiSupport,
                                Table,
                                TRUE,
                                Version,
                                &Handle
                                );
        //
        // Add new table
        //
        Handle = 0;
        Status = AcpiSupport->SetAcpiTable (
                                AcpiSupport,
                                NewTable,
                                TRUE,
                                Version,
                                &Handle
                                );
        gBS->FreePool (NewTable);
        return Status;
      }
      gBS->FreePool (NewTable);
    }
    gBS->FreePool (Table);
    Index++;
  } while (TRUE);

  return Status;
}
예제 #4
0
VOID
EFIAPI
FchD3ColdAcpiInstallNotify (
  IN EFI_EVENT                              Event,
  IN VOID                                   *Context
  )
{
  UINTN                                     Index;
  INTN                                      Instance;
  UINTN                                     Size;
  UINTN                                     NumberOfHandles;
  UINTN                                     TableHandle;
  UINTN                                     TableSize;
  UINT32                                    FvStatus;
  BOOLEAN                                   HwReducedAcpi;
  EFI_STATUS                                Status;
  EFI_HANDLE                                *HandleBuffer;
  EFI_FV_FILETYPE                           FileType;
  EFI_FV_FILE_ATTRIBUTES                    Attributes;
  EFI_ACPI_COMMON_HEADER                    *CurrentTable;
  EFI_ACPI_DESCRIPTION_HEADER               *FchD3ColdAcpiBlockPtr  = NULL;

  EFI_ACPI_TABLE_PROTOCOL                   *AcpiTableProtocol;
  FCH_ACPI_PROTOCOL                         *FchAcpiProtocol;
  FCH_INIT_PROTOCOL                         *FchInitProtocol;
  EFI_FIRMWARE_VOLUME_PROTOCOL              *FwVol = NULL;
  EFI_ACPI_SUPPORT_PROTOCOL                 *AcpiSupport = NULL;
  EFI_ACPI_DESCRIPTION_HEADER               *Table;
  EFI_ACPI_TABLE_VERSION                    Version;
  EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt;

  Status = gBS->LocateProtocol (
                  &gEfiAcpiTableProtocolGuid,
                  NULL,
                  &AcpiTableProtocol
                  );
  if (EFI_ERROR (Status)) {
    return;
  }

  Status = gBS->LocateProtocol (
                  &gFchAcpiProtocolGuid,
                  NULL,
                  &FchAcpiProtocol
                  );
  if (EFI_ERROR (Status)) {
    return;
  }

  Status = gBS->LocateProtocol (
                  &gFchInitProtocolGuid,
                  NULL,
                  &FchInitProtocol
                  );
  if (EFI_ERROR (Status)) {
    return;
  }
  HwReducedAcpi = FchInitProtocol->FchPolicy.Misc.FchCsSupport.FchCsHwReduced;

  FvStatus = 0;
  //
  // Locate protocol.
  //
  Status = gBS->LocateHandleBuffer (
                   ByProtocol,
                   &gEfiFirmwareVolumeProtocolGuid,
                   NULL,
                   &NumberOfHandles,
                   &HandleBuffer
                   );
  if (EFI_ERROR (Status)) {
    return;
  }

  //
  // Looking for FV with FCH ACPI Data Block file
  //
  for (Index = 0; Index < NumberOfHandles; Index++) {
    //
    // Get the protocol on this handle
    // This should not fail because of LocateHandleBuffer
    //
    Status = gBS->HandleProtocol (
                     HandleBuffer[Index],
                     &gEfiFirmwareVolumeProtocolGuid,
                     (VOID**) &FwVol
                     );
    ASSERT_EFI_ERROR (Status);

    //
    // See if it has the ACPI storage file
    //
    Size      = 0;
    FvStatus  = 0;
    Status = FwVol->ReadFile (
                      FwVol,
                      &gAmdFchD3ColdAcpiGuid,
                      NULL,
                      &Size,
                      &FileType,
                      &Attributes,
                      &FvStatus
                      );

    //
    // If we found it, then we are done
    //
    if (Status == EFI_SUCCESS) {
      break;
    }
  }

  //
  // Read tables from the storage file.
  //
  Instance = 0;
  CurrentTable = NULL;
  while (Status == EFI_SUCCESS) {
    Status = FwVol->ReadSection (
                      FwVol,
                      &gAmdFchD3ColdAcpiGuid,
                      EFI_SECTION_RAW,
                      Instance,
                      &CurrentTable,
                      &Size,
                      &FvStatus
                      );

    if (!EFI_ERROR (Status)) {
      //
      // Check the table ID to modify the table
      //
      if (((EFI_ACPI_DESCRIPTION_HEADER*) CurrentTable)->OemTableId == EFI_SIGNATURE_64 ('F', 'C', 'H', 'C', 'S', 'D', '3', 0)) {
        FchD3ColdAcpiBlockPtr = (EFI_ACPI_DESCRIPTION_HEADER*) CurrentTable;

        Status = FchD3ColdUpdateAcpiTable (FchAcpiProtocol, &FchD3ColdAcpiBlockPtr);

        TableHandle = 0;
        TableSize = FchD3ColdAcpiBlockPtr->Length;

        //
        // Install ACPI table
        //
        Status = AcpiTableProtocol->InstallAcpiTable (
                                      AcpiTableProtocol,
                                      FchD3ColdAcpiBlockPtr,
                                      TableSize,
                                      &TableHandle
                                      );

        //
        // Free memory allocated by ReadSection
        //
        gBS->FreePool (CurrentTable);

        if (EFI_ERROR (Status)) {
          return;
        }
      }

      //
      // Increment the instance
      //
      Instance++;
      CurrentTable = NULL;
    }
  }

  //
  // Our exit status is determined by the success of the previous operations
  // If the protocol was found, Instance already points to it.
  //
  //
  // Free any allocated buffers
  //
  gBS->FreePool (HandleBuffer);

  //set FACP
  Status = gBS->LocateProtocol (
                  &gEfiAcpiSupportGuid,
                  NULL,
                  &AcpiSupport
                  );

  if (EFI_ERROR (Status)) {
    return;
  }
  // modify FADT to add HW_REDUCED_ACPI and LOW_POWER_S0_IDLE_CAPABLE flag
  //
  // Search FADT table
  //
  Index  = 0;
  TableHandle = 0;
  do {
    Table  = NULL;
    Status = AcpiSupport->GetAcpiTable (
                            AcpiSupport,
                            Index,
                            &Table,
                            &Version,
                            &TableHandle
                            );
    if (EFI_ERROR (Status)) {
      break;
    }
    //
    // Check Signture and update FADT table
    //
    if ((Table->Signature == EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) && (Table->Revision == 0x05 )) {
      Fadt = (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)Table;
      Fadt->Flags |= LOW_POWER_S0_IDLE_CAPABLE;
      if (HwReducedAcpi) {
        Fadt->Flags |= HW_REDUCED_ACPI;
      }

      Status = AcpiSupport->SetAcpiTable (
                      AcpiSupport,
                      Table,
                      TRUE,
                      (EFI_ACPI_TABLE_VERSION_1_0B | EFI_ACPI_TABLE_VERSION_2_0 | EFI_ACPI_TABLE_VERSION_3_0 | EFI_ACPI_TABLE_VERSION_4_0 | EFI_ACPI_TABLE_VERSION_5_0),
                      &TableHandle
                      );
    }
    gBS->FreePool (Table);
    Index++;
  } while (TRUE);


}