123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- /** @file
- fw_cfg library implementation.
- Copyright (c) 2022 Loongson Technology Corporation Limited. All rights reserved.<BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
- @par Glossary:
- - FwCfg - firmWare Configure
- **/
- #include <Library/BaseLib.h>
- #include <Library/DebugLib.h>
- #include <Library/QemuFwCfgLib.h>
- #include "QemuFwCfgLibInternal.h"
- /**
- Returns a boolean indicating if the firmware configuration interface
- is available or not.
- This function may change fw_cfg state.
- @retval TRUE The interface is available
- @retval FALSE The interface is not available
- **/
- BOOLEAN
- EFIAPI
- QemuFwCfgIsAvailable (
- VOID
- )
- {
- UINT32 Signature;
- UINT32 Revision;
- QemuFwCfgSelectItem (QemuFwCfgItemSignature);
- Signature = QemuFwCfgRead32 ();
- DEBUG ((DEBUG_INFO, "FW CFG Signature: 0x%x\n", Signature));
- QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion);
- Revision = QemuFwCfgRead32 ();
- DEBUG ((DEBUG_INFO, "FW CFG Revision: 0x%x\n", Revision));
- if ((Signature != SIGNATURE_32 ('Q', 'E', 'M', 'U'))
- || (Revision < 1))
- {
- DEBUG ((DEBUG_INFO, "QemuFwCfg interface not supported.\n"));
- return FALSE;
- }
- DEBUG ((DEBUG_INFO, "QemuFwCfg interface is supported.\n"));
- return TRUE;
- }
- /**
- Returns a boolean indicating if the firmware configuration interface is
- available for library-internal purposes.
- This function never changes fw_cfg state.
- @retval TRUE The interface is available internally.
- @retval FALSE The interface is not available internally.
- **/
- BOOLEAN
- InternalQemuFwCfgIsAvailable (
- VOID
- )
- {
- //
- // We always return TRUE, because the consumer of this library ought to have
- // called QemuFwCfgIsAvailable before making other calls which would hit this
- // path.
- //
- return TRUE;
- }
- /**
- Returns a boolean indicating whether QEMU provides the DMA-like access method
- for fw_cfg.
- @retval TRUE The DMA-like access method is available.
- @retval FALSE The DMA-like access method is unavailable.
- **/
- BOOLEAN
- InternalQemuFwCfgDmaIsAvailable (
- VOID
- )
- {
- return FALSE;
- }
- /**
- Transfer an array of bytes, or skip a number of bytes, using the DMA
- interface.
- @param[in] Size Size in bytes to transfer or skip.
- @param[in, out] Buffer Buffer to read data into or write data from. Ignored,
- and may be NULL, if Size is zero, or Control is
- FW_CFG_DMA_CTL_SKIP.
- @param[in] Control One of the following:
- FW_CFG_DMA_CTL_WRITE - write to fw_cfg from Buffer.
- FW_CFG_DMA_CTL_READ - read from fw_cfg into Buffer.
- FW_CFG_DMA_CTL_SKIP - skip bytes in fw_cfg.
- **/
- VOID
- InternalQemuFwCfgDmaBytes (
- IN UINT32 Size,
- IN OUT VOID *Buffer OPTIONAL,
- IN UINT32 Control
- )
- {
- //
- // We should never reach here
- //
- ASSERT (FALSE);
- CpuDeadLoop ();
- }
|