AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / Common / S3SaveState.h
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * Various PCI service routines.
6  *
7  *
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project:     AGESA
11  * @e sub-project: GNB
12  * @e \$Revision: 51711 $   @e \$Date: 2011-04-27 00:23:04 -0600 (Wed, 27 Apr 2011) $
13  *
14  */
15 /*
16 *****************************************************************************
17 *
18 * Copyright (C) 2012 Advanced Micro Devices, Inc.
19 * All rights reserved.
20 *
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.
31 *
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.
42 *
43 * ***************************************************************************
44 *
45 */
46
47 #ifndef _S3SAVESTATE_H_
48 #define _S3SAVESTATE_H_
49
50 #pragma pack (push, 1)
51
52 #ifndef S3_SCRIPT_DEBUG_CODE
53   #define S3_SCRIPT_DEBUG_CODE(Code) Code
54 #endif
55
56 /// Dispatch function ID repository
57 typedef enum {
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;
66
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
80
81
82 #define S3_TABLE_LENGTH             8 * 1024
83 #define S3_TABLE_LENGTH_INCREMENT   1 * 1024
84
85 /// S3 Save Table
86 typedef struct {
87   UINT16                      TableLength;        ///< Table Length
88   UINT32                      SaveOffset;         ///< Save Location
89   BOOLEAN                     Locked;             ///< Locked
90 } S3_SAVE_TABLE_HEADER;
91
92 /// S3 write operation header
93 typedef struct {
94   UINT16                      OpCode;             ///< Opcode
95   ACCESS_WIDTH                Width;              ///< Data width (byte, word, dword)
96   UINT64                      Address;            ///< Register address
97   UINT32                      Count;              ///< Write count
98 } S3_WRITE_OP_HEADER;
99
100 /// S3 Read and Write Operation header
101 typedef struct {
102   UINT16                      OpCode;             ///< Opcode
103   ACCESS_WIDTH                Width;              ///< Data width (byte, word, dword)
104   UINT64                      Address;            ///< Register Address
105 } S3_READ_WRITE_OP_HEADER;
106
107 /// S3 Poll operation header
108 typedef struct {
109   UINT16                      OpCode;             ///< Opcode
110   ACCESS_WIDTH                Width;              ///< Data width (byte, word, dword)
111   UINT64                      Address;            ///< Register address
112   UINT64                      Delay;              ///< Time delay
113 } S3_POLL_OP_HEADER;
114
115 /// Information operation header
116 typedef struct {
117   UINT16                      OpCode;             ///< Opcode
118   UINT32                      Length;             ///< Length of info
119 } S3_INFO_OP_HEADER;
120
121 /// Dispatch operation header
122 typedef struct {
123   UINT16                      OpCode;             ///< Opcode
124   UINT16                      FunctionId;         ///< Function ID
125   UINT16                      Length;             ///< Length in bytes of the context
126 } S3_DISPATCH_OP_HEADER;
127
128
129 typedef VOID S3_DISPATCH_FUNCTION (
130   IN      AMD_CONFIG_PARAMS     *StdHeader,
131   IN      UINT16                ContextLength,
132   IN      VOID                  *Context
133   );
134
135 /// Dispatch function table entry
136 typedef struct {
137   UINT16                        FunctionId;         ///<Function ID
138   S3_DISPATCH_FUNCTION          *Function;          ///<Function pointer
139 } S3_DISPATCH_FUNCTION_ENTRY;
140
141 typedef AGESA_STATUS (*S3_SCRIPT_INIT) (
142   IN      AMD_CONFIG_PARAMS     *StdHeader
143   );
144
145 typedef AGESA_STATUS (*S3_SCRIPT_RESTORE) (
146   IN      AMD_CONFIG_PARAMS     *StdHeader
147   );
148
149 /// S3 Script Configuration
150 typedef struct {
151   S3_SCRIPT_INIT              Init;               ///< Script initialization
152   S3_SCRIPT_RESTORE           Restore;            ///< Script restore
153 } S3_SCRIPT_CONFIGURATION;
154
155 AGESA_STATUS
156 S3ScriptInit (
157   IN      AMD_CONFIG_PARAMS     *StdHeader
158   );
159
160 AGESA_STATUS
161 S3ScriptInitState (
162   IN      AMD_CONFIG_PARAMS     *StdHeader
163   );
164
165 AGESA_STATUS
166 S3ScriptInitStateStub (
167   IN      AMD_CONFIG_PARAMS     *StdHeader
168   );
169
170 AGESA_STATUS
171 S3ScriptRestore (
172   IN      AMD_CONFIG_PARAMS     *StdHeader
173   );
174
175 AGESA_STATUS
176 S3ScriptRestoreState (
177   IN      AMD_CONFIG_PARAMS     *StdHeader
178   );
179
180 AGESA_STATUS
181 S3ScriptRestoreStateStub (
182   IN      AMD_CONFIG_PARAMS     *StdHeader
183   );
184
185 AGESA_STATUS
186 S3ScriptGetS3SaveTable (
187   IN      AMD_CONFIG_PARAMS     *StdHeader,
188   OUT     S3_SAVE_TABLE_HEADER  **S3SaveTable
189   );
190
191 VOID
192 S3SaveDebugPrintHexArray (
193   IN      AMD_CONFIG_PARAMS     *StdHeader,
194   IN      VOID                  *Array,
195   IN      UINT32                Count,
196   IN      ACCESS_WIDTH          Width
197   );
198
199 CHAR8*
200 S3SaveDebugOpcodeString (
201   IN      AMD_CONFIG_PARAMS     *StdHeader,
202   IN      UINT16                Op
203   );
204
205 AGESA_STATUS
206 S3SaveStateSaveWriteOp (
207   IN      AMD_CONFIG_PARAMS   *StdHeader,
208   IN      UINT16              OpCode,
209   IN      ACCESS_WIDTH        Width,
210   IN      UINT64              Address,
211   IN      UINT32              Count,
212   IN      VOID                *Buffer
213   );
214
215 AGESA_STATUS
216 S3SaveStateSaveReadWriteOp (
217   IN      AMD_CONFIG_PARAMS   *StdHeader,
218   IN      UINT16              OpCode,
219   IN      ACCESS_WIDTH        Width,
220   IN      UINT64              Address,
221   IN      VOID                *Data,
222   IN      VOID                *DataMask
223   );
224
225 AGESA_STATUS
226 S3SaveStateSavePollOp (
227   IN      AMD_CONFIG_PARAMS   *StdHeader,
228   IN      UINT16              OpCode,
229   IN      ACCESS_WIDTH        Width,
230   IN      UINT64              Address,
231   IN      VOID                *Data,
232   IN      VOID                *DataMask,
233   IN      UINT64              Delay
234   );
235
236 AGESA_STATUS
237 S3SaveStateSaveInfoOp (
238   IN      AMD_CONFIG_PARAMS   *StdHeader,
239   IN      UINT16              OpCode,
240   IN      UINT32              InformationLength,
241   IN      VOID                *Information
242   );
243
244 AGESA_STATUS
245 S3SaveStateSaveDispatchOp (
246   IN      AMD_CONFIG_PARAMS   *StdHeader,
247   IN      UINT16              OpCode,
248   IN      UINT16              FunctionId,
249   IN      UINT16              ContextLength,
250   IN      VOID                *Context
251   );
252
253 //PCI write
254 #define S3_SAVE_PCI_WRITE(StdHeader, Address, Width, DataPtr) \
255   S3SaveStateSaveWriteOp (  \
256     StdHeader,  \
257     SAVE_STATE_PCI_CONFIG_WRITE_OPCODE,  \
258     Width,  \
259     Address.AddressValue, \
260     1,  \
261     DataPtr  \
262     )
263
264 //PCI read modify write
265 #define S3_SAVE_PCI_RMW (StdHeader, Address, Width, DataPtr, DataMaskPtr) \
266   S3SaveStateSaveWriteOp (  \
267     StdHeader,  \
268     SAVE_STATE_PCI_CONFIG_READ_WRITE_OPCODE,  \
269     Width,  \
270     Address.AddressValue, \
271     DataPtr,  \
272     DataMask  \
273     )
274
275 //PCI read modify write
276 #define S3_SAVE_PCI_POLL(StdHeader, Address, Width, DataPtr, DataMaskPtr, Delay) \
277   S3SaveStateSavePollOp (  \
278     StdHeader,  \
279     SAVE_STATE_PCI_CONFIG_POLL_OPCODE,  \
280     Width,  \
281     Address.AddressValue, \
282     DataPtr,  \
283     DataMask,  \
284     Delay  \
285     )
286
287 //Memory/MMIO write
288 #define S3_SAVE_MEM_WRITE(StdHeader, Address, Width, DataPtr) \
289   S3SaveStateSaveWriteOp (  \
290     StdHeader,  \
291     SAVE_STATE_MEM_WRITE_OPCODE,  \
292     Width,  \
293     Address, \
294     1,  \
295     DataPtr  \
296     )
297
298 //Memory/MMIO read modify write
299 #define S3_SAVE_MEM_RMW(StdHeader, Address, Width, DataPtr, DataMaskPtr) \
300   S3SaveStateSaveWriteOp (  \
301     StdHeader,  \
302     SAVE_STATE_MEM_READ_WRITE_OPCODE,  \
303     Width,  \
304     Address, \
305     DataPtr,  \
306     DataMask  \
307     )
308
309 //Memory/MMIO read modify write
310 #define S3_SAVE_MEM_POLL(StdHeader, Address, Width, DataPtr, DataMaskPtr, Delay) \
311   S3SaveStateSavePollOp (  \
312     StdHeader,  \
313     SAVE_STATE_MEM_POLL_OPCODE,  \
314     Width,  \
315     Address, \
316     DataPtr,  \
317     DataMask,  \
318     Delay \
319     )
320
321 // I/O write
322 #define S3_SAVE_IO_WRITE(StdHeader, Address, Width, DataPtr) \
323   S3SaveStateSaveWriteOp (  \
324     StdHeader,  \
325     SAVE_STATE_IO_WRITE_OPCODE,  \
326     Width,  \
327     Address, \
328     1,  \
329     DataPtr  \
330     )
331
332 // Save information
333 #define S3_SAVE_INFORMATION(StdHeader, InformationLength, Information) \
334   S3SaveStateSaveInfoOp (  \
335     StdHeader,  \
336     SAVE_STATE_INFORMATION_OPCODE,  \
337     InformationLength,  \
338     Information \
339     )
340
341 // Save information string S3_SAVE_INFORMATION_STRING (StdHeader, "Message")
342 #define S3_SAVE_INFORMATION_STRING(StdHeader, Information) \
343   S3SaveStateSaveInfoOp (  \
344     StdHeader,  \
345     SAVE_STATE_INFORMATION_OPCODE,  \
346     sizeof (Information),  \
347     Information \
348     )
349
350 // Save dispatch function
351 #define S3_SAVE_DISPATCH(StdHeader, FunctionId, ContextLength, Context) \
352   S3SaveStateSaveDispatchOp (  \
353     StdHeader,  \
354     SAVE_STATE_DISPATCH_OPCODE,  \
355     FunctionId, \
356     ContextLength,  \
357     Context \
358     )
359
360 #pragma pack (pop)
361 #endif