3 Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 Lib function for table driven register initialization.
27 #include <Library/EfiRegTableLib.h>
28 #include <Library/S3BootScriptLib.h>
35 Local worker function to process PCI_WRITE table entries. Performs write and
36 may also call BootScriptSave protocol if indicated in the Entry flags
38 @param Entry A pointer to the PCI_WRITE entry to process
40 @param PciRootBridgeIo A pointer to the instance of PciRootBridgeIo that is used
41 when processing the entry.
49 EFI_REG_TABLE_PCI_WRITE
*Entry
,
50 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
55 Status
= PciRootBridgeIo
->Pci
.Write (
57 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) (OPCODE_EXTRA_DATA (Entry
->OpCode
)),
58 (UINT64
) Entry
->PciAddress
,
62 ASSERT_EFI_ERROR (Status
);
64 if (OPCODE_FLAGS (Entry
->OpCode
) & OPCODE_FLAG_S3SAVE
) {
65 Status
= S3BootScriptSavePciCfgWrite (
66 (EFI_BOOT_SCRIPT_WIDTH
) (OPCODE_EXTRA_DATA (Entry
->OpCode
)),
67 (UINT64
) Entry
->PciAddress
,
71 ASSERT_EFI_ERROR (Status
);
76 Local worker function to process PCI_READ_MODIFY_WRITE table entries.
77 Performs RMW write and may also call BootScriptSave protocol if indicated in
80 @param Entry A pointer to the PCI_READ_MODIFY_WRITE entry to process.
82 @param PciRootBridgeIo A pointer to the instance of PciRootBridgeIo that is used
83 when processing the entry.
91 EFI_REG_TABLE_PCI_READ_MODIFY_WRITE
*Entry
,
92 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
98 Status
= PciRootBridgeIo
->Pci
.Read (
100 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) (OPCODE_EXTRA_DATA (Entry
->OpCode
)),
101 (UINT64
) Entry
->PciAddress
,
105 ASSERT_EFI_ERROR (Status
);
107 Entry
->OrMask
&= Entry
->AndMask
;
108 TempData
&= ~Entry
->AndMask
;
109 TempData
|= Entry
->OrMask
;
111 Status
= PciRootBridgeIo
->Pci
.Write (
113 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) (OPCODE_EXTRA_DATA (Entry
->OpCode
)),
114 (UINT64
) Entry
->PciAddress
,
118 ASSERT_EFI_ERROR (Status
);
120 if (OPCODE_FLAGS (Entry
->OpCode
) & OPCODE_FLAG_S3SAVE
) {
121 Status
= S3BootScriptSavePciCfgReadWrite (
122 (EFI_BOOT_SCRIPT_WIDTH
) (OPCODE_EXTRA_DATA (Entry
->OpCode
)),
123 (UINT64
) Entry
->PciAddress
,
127 ASSERT_EFI_ERROR (Status
);
132 Local worker function to process MEM_READ_MODIFY_WRITE table entries.
133 Performs RMW write and may also call BootScriptSave protocol if indicated in
136 @param Entry A pointer to the MEM_READ_MODIFY_WRITE entry to process.
138 @param PciRootBridgeIo A pointer to the instance of PciRootBridgeIo that is used
139 when processing the entry.
147 EFI_REG_TABLE_MEM_READ_MODIFY_WRITE
*Entry
,
148 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
154 Status
= PciRootBridgeIo
->Mem
.Read (
156 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) (OPCODE_EXTRA_DATA (Entry
->OpCode
)),
157 (UINT64
) Entry
->MemAddress
,
161 ASSERT_EFI_ERROR (Status
);
163 Entry
->OrMask
&= Entry
->AndMask
;
164 TempData
&= ~Entry
->AndMask
;
165 TempData
|= Entry
->OrMask
;
167 Status
= PciRootBridgeIo
->Mem
.Write (
169 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) (OPCODE_EXTRA_DATA (Entry
->OpCode
)),
170 (UINT64
) Entry
->MemAddress
,
174 ASSERT_EFI_ERROR (Status
);
176 if (OPCODE_FLAGS (Entry
->OpCode
) & OPCODE_FLAG_S3SAVE
) {
177 Status
= S3BootScriptSaveMemReadWrite (
178 (EFI_BOOT_SCRIPT_WIDTH
) (OPCODE_EXTRA_DATA (Entry
->OpCode
)),
183 ASSERT_EFI_ERROR (Status
);
188 // Exported functions
192 Processes register table assuming which may contain PCI, IO, MEM, and STALL
195 No parameter checking is done so the caller must be careful about omitting
196 values for PciRootBridgeIo or CpuIo parameters. If the regtable does
197 not contain any PCI accesses, it is safe to omit the PciRootBridgeIo (supply
198 NULL). If the regtable does not contain any IO or Mem entries, it is safe to
199 omit the CpuIo (supply NULL).
201 The RegTableEntry parameter is not checked, but is required.
203 gBS is assumed to have been defined and is used when processing stalls.
205 The function processes each entry sequentially until an OP_TERMINATE_TABLE
206 entry is encountered.
208 @param RegTableEntry A pointer to the register table to process
210 @param PciRootBridgeIo A pointer to the instance of PciRootBridgeIo that is used
211 when processing PCI table entries
213 @param CpuIo A pointer to the instance of CpuIo that is used when processing IO and
221 EFI_REG_TABLE
*RegTableEntry
,
222 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
,
223 EFI_CPU_IO_PROTOCOL
*CpuIo
226 while (OPCODE_BASE (RegTableEntry
->Generic
.OpCode
) != OP_TERMINATE_TABLE
) {
227 switch (OPCODE_BASE (RegTableEntry
->Generic
.OpCode
)) {
229 PciWrite ((EFI_REG_TABLE_PCI_WRITE
*) RegTableEntry
, PciRootBridgeIo
);
232 case OP_PCI_READ_MODIFY_WRITE
:
233 PciReadModifyWrite ((EFI_REG_TABLE_PCI_READ_MODIFY_WRITE
*) RegTableEntry
, PciRootBridgeIo
);
236 case OP_MEM_READ_MODIFY_WRITE
:
237 MemReadModifyWrite ((EFI_REG_TABLE_MEM_READ_MODIFY_WRITE
*) RegTableEntry
, PciRootBridgeIo
);
241 DEBUG ((EFI_D_ERROR
, "RegTable ERROR: Unknown RegTable OpCode (%x)\n", OPCODE_BASE (RegTableEntry
->Generic
.OpCode
)));
251 Processes register table assuming which may contain IO, MEM, and STALL
252 entries, but must NOT contain any PCI entries. Any PCI entries cause an
253 ASSERT in a DEBUG build and are skipped in a free build.
255 No parameter checking is done. Both RegTableEntry and CpuIo parameters are
258 gBS is assumed to have been defined and is used when processing stalls.
260 The function processes each entry sequentially until an OP_TERMINATE_TABLE
261 entry is encountered.
263 @param RegTableEntry A pointer to the register table to process
265 @param CpuIo A pointer to the instance of CpuIo that is used when processing IO and
273 EFI_REG_TABLE
*RegTableEntry
,
274 EFI_CPU_IO_PROTOCOL
*CpuIo
277 while (OPCODE_BASE (RegTableEntry
->Generic
.OpCode
) != OP_TERMINATE_TABLE
) {
278 switch (OPCODE_BASE (RegTableEntry
->Generic
.OpCode
)) {
280 DEBUG ((EFI_D_ERROR
, "RegTable ERROR: Unknown RegTable OpCode (%x)\n", OPCODE_BASE (RegTableEntry
->Generic
.OpCode
)));