CloudHvHasAcpiDtDxe.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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) 2021, Arm Limited. All rights reserved.<BR>
  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/UefiBootServicesTableLib.h>
  13. /** Entry point for the Cloud Hypervisor PlatformHasAcpiDtDxe.
  14. @param [in] ImageHandle Handle for this image.
  15. @param [in] SystemTable Pointer to the EFI system table.
  16. @return EFI_SUCCESS If ACPI or Device Tree based hardware
  17. description protocol was installed.
  18. @return EFI_INVALID_PARAMETER A parameter was invalid.
  19. @return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete
  20. the request.
  21. **/
  22. EFI_STATUS
  23. EFIAPI
  24. PlatformHasAcpiDt (
  25. IN EFI_HANDLE ImageHandle,
  26. IN EFI_SYSTEM_TABLE *SystemTable
  27. )
  28. {
  29. EFI_STATUS Status;
  30. //
  31. // If we fail to install any of the necessary protocols below, the OS will be
  32. // unbootable anyway (due to lacking hardware description), so tolerate no
  33. // errors here.
  34. //
  35. if ((MAX_UINTN == MAX_UINT64) &&
  36. !PcdGetBool (PcdForceNoAcpi))
  37. {
  38. Status = gBS->InstallProtocolInterface (
  39. &ImageHandle,
  40. &gEdkiiPlatformHasAcpiGuid,
  41. EFI_NATIVE_INTERFACE,
  42. NULL
  43. );
  44. if (EFI_ERROR (Status)) {
  45. goto Failed;
  46. }
  47. return Status;
  48. }
  49. //
  50. // Expose the Device Tree otherwise.
  51. //
  52. Status = gBS->InstallProtocolInterface (
  53. &ImageHandle,
  54. &gEdkiiPlatformHasDeviceTreeGuid,
  55. EFI_NATIVE_INTERFACE,
  56. NULL
  57. );
  58. if (EFI_ERROR (Status)) {
  59. goto Failed;
  60. }
  61. return Status;
  62. Failed:
  63. ASSERT_EFI_ERROR (Status);
  64. CpuDeadLoop ();
  65. //
  66. // Keep compilers happy.
  67. //
  68. return Status;
  69. }