]> git.proxmox.com Git - mirror_edk2.git/blame - Vlv2TbltDevicePkg/Include/Library/EfiRegTableLib.h
Upload BSD-licensed Vlv2TbltDevicePkg and Vlv2DeviceRefCodePkg to
[mirror_edk2.git] / Vlv2TbltDevicePkg / Include / Library / EfiRegTableLib.h
CommitLineData
3cbfba02
DW
1/*++\r
2\r
3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
4 \r\r
5 This program and the accompanying materials are licensed and made available under\r\r
6 the terms and conditions of the BSD License that accompanies this distribution. \r\r
7 The full text of the license may be found at \r\r
8 http://opensource.org/licenses/bsd-license.php. \r\r
9 \r\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r\r
12 \r\r
13\r
14\r
15Module Name:\r
16\r
17 EfiRegTableLib.h\r
18\r
19Abstract:\r
20\r
21 Definitions and macros for building register tables for chipset\r
22 initialization..\r
23\r
24 Components linking this lib must include CpuIo, PciRootBridgeIo, and\r
25 BootScriptSave protocols in their DPX.\r
26\r
27\r
28\r
29--*/\r
30\r
31#ifndef EFI_REG_TABLE_H\r
32#define EFI_REG_TABLE_H\r
33\r
34\r
35#include <PiDxe.h>\r
36#include <Library/BaseLib.h>\r
37#include <Library/DebugLib.h>\r
38#include <Library/UefiLib.h>\r
39#include <Library/UefiDriverEntryPoint.h>\r
40#include <Protocol/CpuIo.h>\r
41#include <Protocol/BootScriptSave.h>\r
42#include <Framework/BootScript.h>\r
43#include <Protocol/PciRootBridgeIo.h>\r
44\r
45\r
46#define OPCODE_BASE(OpCode) ((UINT8)((OpCode) & 0xFF))\r
47#define OPCODE_FLAGS(OpCode) ((UINT8)(((OpCode) >> 8) & 0xFF))\r
48#define OPCODE_EXTRA_DATA(OpCode) ((UINT16)((OpCode) >> 16))\r
49\r
50//\r
51// RegTable Base OpCodes\r
52//\r
53#define OP_TERMINATE_TABLE 0\r
54#define OP_MEM_WRITE 1\r
55#define OP_MEM_READ_MODIFY_WRITE 2\r
56#define OP_IO_WRITE 3\r
57#define OP_IO_READ_MODIFY_WRITE 4\r
58#define OP_PCI_WRITE 5\r
59#define OP_PCI_READ_MODIFY_WRITE 6\r
60#define OP_STALL 7\r
61\r
62//\r
63// RegTable OpCode Flags\r
64//\r
65#define OPCODE_FLAG_S3SAVE 1\r
66\r
67\r
68#define TERMINATE_TABLE { (UINT32) OP_TERMINATE_TABLE, (UINT32) 0, (UINT32) 0 }\r
69\r
70\r
71//\r
72// REG_TABLE_ENTRY_PCI_WRITE encodes the width in the upper bits of the OpCode\r
73// as one of the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH values\r
74//\r
75typedef struct {\r
76 UINT32 OpCode;\r
77 UINT32 PciAddress;\r
78 UINT32 Data;\r
79} EFI_REG_TABLE_PCI_WRITE;\r
80\r
81#define PCI_WRITE(Bus, Dev, Fnc, Reg, Width, Data, S3Flag) \\r
82 { \\r
83 (UINT32) (OP_PCI_WRITE | ((S3Flag) << 8) | ((Width) << 16)), \\r
84 (UINT32) (EFI_PCI_ADDRESS ((Bus), (Dev), (Fnc), (Reg))), \\r
85 (UINT32) (Data), \\r
86 (UINT32) (0) \\r
87 }\r
88\r
89typedef struct {\r
90 UINT32 OpCode;\r
91 UINT32 MemAddress;\r
92 UINT32 Data;\r
93} EFI_REG_TABLE_MEM_WRITE;\r
94\r
95typedef struct {\r
96 UINT32 OpCode;\r
97 UINT32 PciAddress;\r
98 UINT32 OrMask;\r
99 UINT32 AndMask;\r
100} EFI_REG_TABLE_PCI_READ_MODIFY_WRITE;\r
101\r
102#define PCI_READ_MODIFY_WRITE(Bus, Dev, Fnc, Reg, Width, OrMask, AndMask, S3Flag) \\r
103 { \\r
104 (UINT32) (OP_PCI_READ_MODIFY_WRITE | ((S3Flag) << 8) | ((Width) << 16)), \\r
105 (UINT32) (EFI_PCI_ADDRESS ((Bus), (Dev), (Fnc), (Reg))), \\r
106 (UINT32) (OrMask), \\r
107 (UINT32) (AndMask) \\r
108 }\r
109\r
110typedef struct {\r
111 UINT32 OpCode;\r
112 UINT32 MemAddress;\r
113 UINT32 OrMask;\r
114 UINT32 AndMask;\r
115} EFI_REG_TABLE_MEM_READ_MODIFY_WRITE;\r
116\r
117#define MEM_READ_MODIFY_WRITE(Address, Width, OrMask, AndMask, S3Flag) \\r
118 { \\r
119 (UINT32) (OP_MEM_READ_MODIFY_WRITE | ((S3Flag) << 8) | ((Width) << 16)), \\r
120 (UINT32) (Address), \\r
121 (UINT32) (OrMask), \\r
122 (UINT32) (AndMask) \\r
123 }\r
124\r
125typedef struct {\r
126 UINT32 OpCode;\r
127 UINT32 Field2;\r
128 UINT32 Field3;\r
129 UINT32 Field4;\r
130} EFI_REG_TABLE_GENERIC;\r
131\r
132typedef union {\r
133 EFI_REG_TABLE_GENERIC Generic;\r
134 EFI_REG_TABLE_PCI_WRITE PciWrite;\r
135 EFI_REG_TABLE_PCI_READ_MODIFY_WRITE PciReadModifyWrite;\r
136 EFI_REG_TABLE_MEM_READ_MODIFY_WRITE MemReadModifyWrite;\r
137} EFI_REG_TABLE;\r
138\r
139/**\r
140 Processes register table assuming which may contain PCI, IO, MEM, and STALL\r
141 entries.\r
142\r
143 No parameter checking is done so the caller must be careful about omitting\r
144 values for PciRootBridgeIo or CpuIo parameters. If the regtable does\r
145 not contain any PCI accesses, it is safe to omit the PciRootBridgeIo (supply\r
146 NULL). If the regtable does not contain any IO or Mem entries, it is safe to\r
147 omit the CpuIo (supply NULL).\r
148\r
149 The RegTableEntry parameter is not checked, but is required.\r
150\r
151 gBS is assumed to have been defined and is used when processing stalls.\r
152\r
153 The function processes each entry sequentially until an OP_TERMINATE_TABLE\r
154 entry is encountered.\r
155\r
156 @param[in] RegTableEntry A pointer to the register table to process\r
157\r
158 @param[in] PciRootBridgeIo A pointer to the instance of PciRootBridgeIo that is used\r
159 when processing PCI table entries\r
160\r
161 @param[in] CpuIo A pointer to the instance of CpuIo that is used when processing IO and\r
162 MEM table entries\r
163\r
164 @retval Nothing.\r
165\r
166**/\r
167VOID\r
168ProcessRegTablePci (\r
169 EFI_REG_TABLE * RegTableEntry,\r
170 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL * PciRootBridgeIo,\r
171 EFI_CPU_IO_PROTOCOL * CpuIo\r
172 );\r
173\r
174/**\r
175 Processes register table assuming which may contain IO, MEM, and STALL\r
176 entries, but must NOT contain any PCI entries. Any PCI entries cause an\r
177 ASSERT in a DEBUG build and are skipped in a free build.\r
178\r
179 No parameter checking is done. Both RegTableEntry and CpuIo parameters are\r
180 required.\r
181\r
182 gBS is assumed to have been defined and is used when processing stalls.\r
183\r
184 The function processes each entry sequentially until an OP_TERMINATE_TABLE\r
185 entry is encountered.\r
186\r
187 @param[in] RegTableEntry - A pointer to the register table to process\r
188\r
189 @param[in] CpuIo - A pointer to the instance of CpuIo that is used when processing IO and\r
190 MEM table entries\r
191\r
192 @retval Nothing.\r
193\r
194**/\r
195VOID\r
196ProcessRegTableCpu (\r
197 EFI_REG_TABLE * RegTableEntry,\r
198 EFI_CPU_IO_PROTOCOL * CpuIo\r
199 );\r
200\r
201#endif\r