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