3 Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved
5 SPDX-License-Identifier: BSD-2-Clause-Patent
16 Lib function for table driven register initialization.
22 #include <Library/EfiRegTableLib.h>
23 #include <Library/S3BootScriptLib.h>
30 Local worker function to process PCI_WRITE table entries. Performs write and
31 may also call BootScriptSave protocol if indicated in the Entry flags
33 @param Entry A pointer to the PCI_WRITE entry to process
35 @param PciRootBridgeIo A pointer to the instance of PciRootBridgeIo that is used
36 when processing the entry.
44 EFI_REG_TABLE_PCI_WRITE
*Entry
,
45 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
50 Status
= PciRootBridgeIo
->Pci
.Write (
52 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) (OPCODE_EXTRA_DATA (Entry
->OpCode
)),
53 (UINT64
) Entry
->PciAddress
,
57 ASSERT_EFI_ERROR (Status
);
59 if (OPCODE_FLAGS (Entry
->OpCode
) & OPCODE_FLAG_S3SAVE
) {
60 Status
= S3BootScriptSavePciCfgWrite (
61 (EFI_BOOT_SCRIPT_WIDTH
) (OPCODE_EXTRA_DATA (Entry
->OpCode
)),
62 (UINT64
) Entry
->PciAddress
,
66 ASSERT_EFI_ERROR (Status
);
71 Local worker function to process PCI_READ_MODIFY_WRITE table entries.
72 Performs RMW write and may also call BootScriptSave protocol if indicated in
75 @param Entry A pointer to the PCI_READ_MODIFY_WRITE entry to process.
77 @param PciRootBridgeIo A pointer to the instance of PciRootBridgeIo that is used
78 when processing the entry.
86 EFI_REG_TABLE_PCI_READ_MODIFY_WRITE
*Entry
,
87 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
93 Status
= PciRootBridgeIo
->Pci
.Read (
95 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) (OPCODE_EXTRA_DATA (Entry
->OpCode
)),
96 (UINT64
) Entry
->PciAddress
,
100 ASSERT_EFI_ERROR (Status
);
102 Entry
->OrMask
&= Entry
->AndMask
;
103 TempData
&= ~Entry
->AndMask
;
104 TempData
|= Entry
->OrMask
;
106 Status
= PciRootBridgeIo
->Pci
.Write (
108 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) (OPCODE_EXTRA_DATA (Entry
->OpCode
)),
109 (UINT64
) Entry
->PciAddress
,
113 ASSERT_EFI_ERROR (Status
);
115 if (OPCODE_FLAGS (Entry
->OpCode
) & OPCODE_FLAG_S3SAVE
) {
116 Status
= S3BootScriptSavePciCfgReadWrite (
117 (EFI_BOOT_SCRIPT_WIDTH
) (OPCODE_EXTRA_DATA (Entry
->OpCode
)),
118 (UINT64
) Entry
->PciAddress
,
122 ASSERT_EFI_ERROR (Status
);
127 Local worker function to process MEM_READ_MODIFY_WRITE table entries.
128 Performs RMW write and may also call BootScriptSave protocol if indicated in
131 @param Entry A pointer to the MEM_READ_MODIFY_WRITE entry to process.
133 @param PciRootBridgeIo A pointer to the instance of PciRootBridgeIo that is used
134 when processing the entry.
142 EFI_REG_TABLE_MEM_READ_MODIFY_WRITE
*Entry
,
143 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
149 Status
= PciRootBridgeIo
->Mem
.Read (
151 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) (OPCODE_EXTRA_DATA (Entry
->OpCode
)),
152 (UINT64
) Entry
->MemAddress
,
156 ASSERT_EFI_ERROR (Status
);
158 Entry
->OrMask
&= Entry
->AndMask
;
159 TempData
&= ~Entry
->AndMask
;
160 TempData
|= Entry
->OrMask
;
162 Status
= PciRootBridgeIo
->Mem
.Write (
164 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) (OPCODE_EXTRA_DATA (Entry
->OpCode
)),
165 (UINT64
) Entry
->MemAddress
,
169 ASSERT_EFI_ERROR (Status
);
171 if (OPCODE_FLAGS (Entry
->OpCode
) & OPCODE_FLAG_S3SAVE
) {
172 Status
= S3BootScriptSaveMemReadWrite (
173 (EFI_BOOT_SCRIPT_WIDTH
) (OPCODE_EXTRA_DATA (Entry
->OpCode
)),
178 ASSERT_EFI_ERROR (Status
);
183 // Exported functions
187 Processes register table assuming which may contain PCI, IO, MEM, and STALL
190 No parameter checking is done so the caller must be careful about omitting
191 values for PciRootBridgeIo or CpuIo parameters. If the regtable does
192 not contain any PCI accesses, it is safe to omit the PciRootBridgeIo (supply
193 NULL). If the regtable does not contain any IO or Mem entries, it is safe to
194 omit the CpuIo (supply NULL).
196 The RegTableEntry parameter is not checked, but is required.
198 gBS is assumed to have been defined and is used when processing stalls.
200 The function processes each entry sequentially until an OP_TERMINATE_TABLE
201 entry is encountered.
203 @param RegTableEntry A pointer to the register table to process
205 @param PciRootBridgeIo A pointer to the instance of PciRootBridgeIo that is used
206 when processing PCI table entries
208 @param CpuIo A pointer to the instance of CpuIo that is used when processing IO and
216 EFI_REG_TABLE
*RegTableEntry
,
217 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
,
218 EFI_CPU_IO_PROTOCOL
*CpuIo
221 while (OPCODE_BASE (RegTableEntry
->Generic
.OpCode
) != OP_TERMINATE_TABLE
) {
222 switch (OPCODE_BASE (RegTableEntry
->Generic
.OpCode
)) {
224 PciWrite ((EFI_REG_TABLE_PCI_WRITE
*) RegTableEntry
, PciRootBridgeIo
);
227 case OP_PCI_READ_MODIFY_WRITE
:
228 PciReadModifyWrite ((EFI_REG_TABLE_PCI_READ_MODIFY_WRITE
*) RegTableEntry
, PciRootBridgeIo
);
231 case OP_MEM_READ_MODIFY_WRITE
:
232 MemReadModifyWrite ((EFI_REG_TABLE_MEM_READ_MODIFY_WRITE
*) RegTableEntry
, PciRootBridgeIo
);
236 DEBUG ((EFI_D_ERROR
, "RegTable ERROR: Unknown RegTable OpCode (%x)\n", OPCODE_BASE (RegTableEntry
->Generic
.OpCode
)));
246 Processes register table assuming which may contain IO, MEM, and STALL
247 entries, but must NOT contain any PCI entries. Any PCI entries cause an
248 ASSERT in a DEBUG build and are skipped in a free build.
250 No parameter checking is done. Both RegTableEntry and CpuIo parameters are
253 gBS is assumed to have been defined and is used when processing stalls.
255 The function processes each entry sequentially until an OP_TERMINATE_TABLE
256 entry is encountered.
258 @param RegTableEntry A pointer to the register table to process
260 @param CpuIo A pointer to the instance of CpuIo that is used when processing IO and
268 EFI_REG_TABLE
*RegTableEntry
,
269 EFI_CPU_IO_PROTOCOL
*CpuIo
272 while (OPCODE_BASE (RegTableEntry
->Generic
.OpCode
) != OP_TERMINATE_TABLE
) {
273 switch (OPCODE_BASE (RegTableEntry
->Generic
.OpCode
)) {
275 DEBUG ((EFI_D_ERROR
, "RegTable ERROR: Unknown RegTable OpCode (%x)\n", OPCODE_BASE (RegTableEntry
->Generic
.OpCode
)));