QemuFwCfgPei.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /** @file
  2. fw_cfg library implementation.
  3. Copyright (c) 2022 Loongson Technology Corporation Limited. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. @par Glossary:
  6. - FwCfg - firmWare Configure
  7. **/
  8. #include <Library/BaseLib.h>
  9. #include <Library/DebugLib.h>
  10. #include <Library/QemuFwCfgLib.h>
  11. #include "QemuFwCfgLibInternal.h"
  12. /**
  13. Returns a boolean indicating if the firmware configuration interface
  14. is available or not.
  15. This function may change fw_cfg state.
  16. @retval TRUE The interface is available
  17. @retval FALSE The interface is not available
  18. **/
  19. BOOLEAN
  20. EFIAPI
  21. QemuFwCfgIsAvailable (
  22. VOID
  23. )
  24. {
  25. UINT32 Signature;
  26. UINT32 Revision;
  27. QemuFwCfgSelectItem (QemuFwCfgItemSignature);
  28. Signature = QemuFwCfgRead32 ();
  29. DEBUG ((DEBUG_INFO, "FW CFG Signature: 0x%x\n", Signature));
  30. QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion);
  31. Revision = QemuFwCfgRead32 ();
  32. DEBUG ((DEBUG_INFO, "FW CFG Revision: 0x%x\n", Revision));
  33. if ((Signature != SIGNATURE_32 ('Q', 'E', 'M', 'U'))
  34. || (Revision < 1))
  35. {
  36. DEBUG ((DEBUG_INFO, "QemuFwCfg interface not supported.\n"));
  37. return FALSE;
  38. }
  39. DEBUG ((DEBUG_INFO, "QemuFwCfg interface is supported.\n"));
  40. return TRUE;
  41. }
  42. /**
  43. Returns a boolean indicating if the firmware configuration interface is
  44. available for library-internal purposes.
  45. This function never changes fw_cfg state.
  46. @retval TRUE The interface is available internally.
  47. @retval FALSE The interface is not available internally.
  48. **/
  49. BOOLEAN
  50. InternalQemuFwCfgIsAvailable (
  51. VOID
  52. )
  53. {
  54. //
  55. // We always return TRUE, because the consumer of this library ought to have
  56. // called QemuFwCfgIsAvailable before making other calls which would hit this
  57. // path.
  58. //
  59. return TRUE;
  60. }
  61. /**
  62. Returns a boolean indicating whether QEMU provides the DMA-like access method
  63. for fw_cfg.
  64. @retval TRUE The DMA-like access method is available.
  65. @retval FALSE The DMA-like access method is unavailable.
  66. **/
  67. BOOLEAN
  68. InternalQemuFwCfgDmaIsAvailable (
  69. VOID
  70. )
  71. {
  72. return FALSE;
  73. }
  74. /**
  75. Transfer an array of bytes, or skip a number of bytes, using the DMA
  76. interface.
  77. @param[in] Size Size in bytes to transfer or skip.
  78. @param[in, out] Buffer Buffer to read data into or write data from. Ignored,
  79. and may be NULL, if Size is zero, or Control is
  80. FW_CFG_DMA_CTL_SKIP.
  81. @param[in] Control One of the following:
  82. FW_CFG_DMA_CTL_WRITE - write to fw_cfg from Buffer.
  83. FW_CFG_DMA_CTL_READ - read from fw_cfg into Buffer.
  84. FW_CFG_DMA_CTL_SKIP - skip bytes in fw_cfg.
  85. **/
  86. VOID
  87. InternalQemuFwCfgDmaBytes (
  88. IN UINT32 Size,
  89. IN OUT VOID *Buffer OPTIONAL,
  90. IN UINT32 Control
  91. )
  92. {
  93. //
  94. // We should never reach here
  95. //
  96. ASSERT (FALSE);
  97. CpuDeadLoop ();
  98. }