5 * Various PCI service routines.
9 * @xrefitem bom "File Content Label" "Release Content"
12 * @e \$Revision: 51711 $ @e \$Date: 2011-04-27 00:23:04 -0600 (Wed, 27 Apr 2011) $
16 *****************************************************************************
18 * Copyright (C) 2012 Advanced Micro Devices, Inc.
19 * All rights reserved.
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions are met:
23 * * Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 * * Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
28 * * Neither the name of Advanced Micro Devices, Inc. nor the names of
29 * its contributors may be used to endorse or promote products derived
30 * from this software without specific prior written permission.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
35 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
36 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
37 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
38 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
39 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 * ***************************************************************************
47 #ifndef _S3SAVESTATE_H_
48 #define _S3SAVESTATE_H_
50 #pragma pack (push, 1)
52 #ifndef S3_SCRIPT_DEBUG_CODE
53 #define S3_SCRIPT_DEBUG_CODE(Code) Code
56 /// Dispatch function ID repository
58 NbSmuIndirectWriteS3Script_ID = 1, ///< GNB SMU service request function ID.
59 NbSmuServiceRequestS3Script_ID, ///< GNB PCIe late restore function ID.
60 PcieLateRestoreS3Script_ID, ///< GNB SMU indirect write.
61 GnbSmuServiceRequestV4S3Script_ID, ///< SMU service request
62 GnbLibStallS3Script_ID, ///< Stall request
63 PcieLateRestoreTNS3Script_ID, ///< GNB PCIe late restore TN
64 PcieLateRestoreKMS3Script_ID, ///< GNB PCIe late restore KM
65 } S3_DISPATCH_FUNCTION_ID;
67 #define SAVE_STATE_IO_WRITE_OPCODE 0x00
68 #define SAVE_STATE_IO_READ_WRITE_OPCODE 0x01
69 #define SAVE_STATE_MEM_WRITE_OPCODE 0x02
70 #define SAVE_STATE_MEM_READ_WRITE_OPCODE 0x03
71 #define SAVE_STATE_PCI_CONFIG_WRITE_OPCODE 0x04
72 #define SAVE_STATE_PCI_CONFIG_READ_WRITE_OPCODE 0x05
73 #define SAVE_STATE_STALL_OPCODE 0x07
74 #define SAVE_STATE_INFORMATION_OPCODE 0x0A
75 #define SAVE_STATE_IO_POLL_OPCODE 0x0D
76 #define SAVE_STATE_MEM_POLL_OPCODE 0x0E
77 #define SAVE_STATE_PCI_CONFIG_POLL_OPCODE 0x0F
78 #define SAVE_STATE_DISPATCH_OPCODE 0x20
79 #define SAVE_STATE_BREAKPOINT_OPCODE 0x21
82 #define S3_TABLE_LENGTH 8 * 1024
83 #define S3_TABLE_LENGTH_INCREMENT 1 * 1024
87 UINT16 TableLength; ///< Table Length
88 UINT32 SaveOffset; ///< Save Location
89 BOOLEAN Locked; ///< Locked
90 } S3_SAVE_TABLE_HEADER;
92 /// S3 write operation header
94 UINT16 OpCode; ///< Opcode
95 ACCESS_WIDTH Width; ///< Data width (byte, word, dword)
96 UINT64 Address; ///< Register address
97 UINT32 Count; ///< Write count
100 /// S3 Read and Write Operation header
102 UINT16 OpCode; ///< Opcode
103 ACCESS_WIDTH Width; ///< Data width (byte, word, dword)
104 UINT64 Address; ///< Register Address
105 } S3_READ_WRITE_OP_HEADER;
107 /// S3 Poll operation header
109 UINT16 OpCode; ///< Opcode
110 ACCESS_WIDTH Width; ///< Data width (byte, word, dword)
111 UINT64 Address; ///< Register address
112 UINT64 Delay; ///< Time delay
115 /// Information operation header
117 UINT16 OpCode; ///< Opcode
118 UINT32 Length; ///< Length of info
121 /// Dispatch operation header
123 UINT16 OpCode; ///< Opcode
124 UINT16 FunctionId; ///< Function ID
125 UINT16 Length; ///< Length in bytes of the context
126 } S3_DISPATCH_OP_HEADER;
129 typedef VOID S3_DISPATCH_FUNCTION (
130 IN AMD_CONFIG_PARAMS *StdHeader,
131 IN UINT16 ContextLength,
135 /// Dispatch function table entry
137 UINT16 FunctionId; ///<Function ID
138 S3_DISPATCH_FUNCTION *Function; ///<Function pointer
139 } S3_DISPATCH_FUNCTION_ENTRY;
141 typedef AGESA_STATUS (*S3_SCRIPT_INIT) (
142 IN AMD_CONFIG_PARAMS *StdHeader
145 typedef AGESA_STATUS (*S3_SCRIPT_RESTORE) (
146 IN AMD_CONFIG_PARAMS *StdHeader
149 /// S3 Script Configuration
151 S3_SCRIPT_INIT Init; ///< Script initialization
152 S3_SCRIPT_RESTORE Restore; ///< Script restore
153 } S3_SCRIPT_CONFIGURATION;
157 IN AMD_CONFIG_PARAMS *StdHeader
162 IN AMD_CONFIG_PARAMS *StdHeader
166 S3ScriptInitStateStub (
167 IN AMD_CONFIG_PARAMS *StdHeader
172 IN AMD_CONFIG_PARAMS *StdHeader
176 S3ScriptRestoreState (
177 IN AMD_CONFIG_PARAMS *StdHeader
181 S3ScriptRestoreStateStub (
182 IN AMD_CONFIG_PARAMS *StdHeader
186 S3ScriptGetS3SaveTable (
187 IN AMD_CONFIG_PARAMS *StdHeader,
188 OUT S3_SAVE_TABLE_HEADER **S3SaveTable
192 S3SaveDebugPrintHexArray (
193 IN AMD_CONFIG_PARAMS *StdHeader,
196 IN ACCESS_WIDTH Width
200 S3SaveDebugOpcodeString (
201 IN AMD_CONFIG_PARAMS *StdHeader,
206 S3SaveStateSaveWriteOp (
207 IN AMD_CONFIG_PARAMS *StdHeader,
209 IN ACCESS_WIDTH Width,
216 S3SaveStateSaveReadWriteOp (
217 IN AMD_CONFIG_PARAMS *StdHeader,
219 IN ACCESS_WIDTH Width,
226 S3SaveStateSavePollOp (
227 IN AMD_CONFIG_PARAMS *StdHeader,
229 IN ACCESS_WIDTH Width,
237 S3SaveStateSaveInfoOp (
238 IN AMD_CONFIG_PARAMS *StdHeader,
240 IN UINT32 InformationLength,
245 S3SaveStateSaveDispatchOp (
246 IN AMD_CONFIG_PARAMS *StdHeader,
248 IN UINT16 FunctionId,
249 IN UINT16 ContextLength,
254 #define S3_SAVE_PCI_WRITE(StdHeader, Address, Width, DataPtr) \
255 S3SaveStateSaveWriteOp ( \
257 SAVE_STATE_PCI_CONFIG_WRITE_OPCODE, \
259 Address.AddressValue, \
264 //PCI read modify write
265 #define S3_SAVE_PCI_RMW (StdHeader, Address, Width, DataPtr, DataMaskPtr) \
266 S3SaveStateSaveWriteOp ( \
268 SAVE_STATE_PCI_CONFIG_READ_WRITE_OPCODE, \
270 Address.AddressValue, \
275 //PCI read modify write
276 #define S3_SAVE_PCI_POLL(StdHeader, Address, Width, DataPtr, DataMaskPtr, Delay) \
277 S3SaveStateSavePollOp ( \
279 SAVE_STATE_PCI_CONFIG_POLL_OPCODE, \
281 Address.AddressValue, \
288 #define S3_SAVE_MEM_WRITE(StdHeader, Address, Width, DataPtr) \
289 S3SaveStateSaveWriteOp ( \
291 SAVE_STATE_MEM_WRITE_OPCODE, \
298 //Memory/MMIO read modify write
299 #define S3_SAVE_MEM_RMW(StdHeader, Address, Width, DataPtr, DataMaskPtr) \
300 S3SaveStateSaveWriteOp ( \
302 SAVE_STATE_MEM_READ_WRITE_OPCODE, \
309 //Memory/MMIO read modify write
310 #define S3_SAVE_MEM_POLL(StdHeader, Address, Width, DataPtr, DataMaskPtr, Delay) \
311 S3SaveStateSavePollOp ( \
313 SAVE_STATE_MEM_POLL_OPCODE, \
322 #define S3_SAVE_IO_WRITE(StdHeader, Address, Width, DataPtr) \
323 S3SaveStateSaveWriteOp ( \
325 SAVE_STATE_IO_WRITE_OPCODE, \
333 #define S3_SAVE_INFORMATION(StdHeader, InformationLength, Information) \
334 S3SaveStateSaveInfoOp ( \
336 SAVE_STATE_INFORMATION_OPCODE, \
341 // Save information string S3_SAVE_INFORMATION_STRING (StdHeader, "Message")
342 #define S3_SAVE_INFORMATION_STRING(StdHeader, Information) \
343 S3SaveStateSaveInfoOp ( \
345 SAVE_STATE_INFORMATION_OPCODE, \
346 sizeof (Information), \
350 // Save dispatch function
351 #define S3_SAVE_DISPATCH(StdHeader, FunctionId, ContextLength, Context) \
352 S3SaveStateSaveDispatchOp ( \
354 SAVE_STATE_DISPATCH_OPCODE, \