PlatformHasAcpiDtDxe.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /** @file
  2. Decide whether the firmware should expose an ACPI- and/or a Device Tree-based
  3. hardware description to the operating system.
  4. Copyright (c) 2017, Red Hat, Inc.
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include <Guid/PlatformHasAcpi.h>
  8. #include <Guid/PlatformHasDeviceTree.h>
  9. #include <Library/BaseLib.h>
  10. #include <Library/DebugLib.h>
  11. #include <Library/PcdLib.h>
  12. #include <Library/QemuFwCfgLib.h>
  13. #include <Library/UefiBootServicesTableLib.h>
  14. EFI_STATUS
  15. EFIAPI
  16. PlatformHasAcpiDt (
  17. IN EFI_HANDLE ImageHandle,
  18. IN EFI_SYSTEM_TABLE *SystemTable
  19. )
  20. {
  21. EFI_STATUS Status;
  22. FIRMWARE_CONFIG_ITEM FwCfgItem;
  23. UINTN FwCfgSize;
  24. //
  25. // If we fail to install any of the necessary protocols below, the OS will be
  26. // unbootable anyway (due to lacking hardware description), so tolerate no
  27. // errors here.
  28. //
  29. if ((MAX_UINTN == MAX_UINT64) &&
  30. !PcdGetBool (PcdForceNoAcpi) &&
  31. !EFI_ERROR (
  32. QemuFwCfgFindFile (
  33. "etc/table-loader",
  34. &FwCfgItem,
  35. &FwCfgSize
  36. )
  37. ))
  38. {
  39. //
  40. // Only make ACPI available on 64-bit systems, and only if QEMU generates
  41. // (a subset of) the ACPI tables.
  42. //
  43. Status = gBS->InstallProtocolInterface (
  44. &ImageHandle,
  45. &gEdkiiPlatformHasAcpiGuid,
  46. EFI_NATIVE_INTERFACE,
  47. NULL
  48. );
  49. if (EFI_ERROR (Status)) {
  50. goto Failed;
  51. }
  52. return Status;
  53. }
  54. //
  55. // Expose the Device Tree otherwise.
  56. //
  57. Status = gBS->InstallProtocolInterface (
  58. &ImageHandle,
  59. &gEdkiiPlatformHasDeviceTreeGuid,
  60. EFI_NATIVE_INTERFACE,
  61. NULL
  62. );
  63. if (EFI_ERROR (Status)) {
  64. goto Failed;
  65. }
  66. return Status;
  67. Failed:
  68. ASSERT_EFI_ERROR (Status);
  69. CpuDeadLoop ();
  70. //
  71. // Keep compilers happy.
  72. //
  73. return Status;
  74. }