AMD Agesa macro expansion fix
[coreboot.git] / src / vendorcode / amd / agesa / f12 / Proc / CPU / cpuApicUtilities.h
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * AMD CPU APIC related utility functions and structures
6  *
7  * Contains code that provides mechanism to invoke and control APIC communication.
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project:      AGESA
11  * @e sub-project:  CPU
12  * @e \$Revision: 44393 $   @e \$Date: 2010-12-24 07:38:46 +0800 (Fri, 24 Dec 2010) $
13  *
14  */
15 /*
16  ******************************************************************************
17  *
18  * Copyright (c) 2011, 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 #ifndef _CPU_APIC_UTILITIES_H_
46 #define _CPU_APIC_UTILITIES_H_
47
48
49 /*---------------------------------------------------------------------------------------
50  *          M I X E D   (Definitions And Macros / Typedefs, Structures, Enums)
51  *---------------------------------------------------------------------------------------
52  */
53
54
55 /*---------------------------------------------------------------------------------------
56  *                 D E F I N I T I O N S     A N D     M A C R O S
57  *---------------------------------------------------------------------------------------
58  */
59 #define APIC_CTRL_DWORD 0xF
60 #define APIC_CTRL_REG (APIC_CTRL_DWORD << 4)
61 #define APIC_CTRL_MASK 0xFF
62 #define APIC_CTRL_SHIFT 0
63
64 #define APIC_DATA_DWORD 0x38
65 #define APIC_DATA_REG (APIC_DATA_DWORD << 4)
66
67 #define APIC_REMOTE_READ_REG 0xC0
68 #define APIC_CMD_LO_REG 0x300
69 #define APIC_CMD_HI_REG 0x310
70
71 // APIC_CMD_LO_REG bits
72 #define CMD_REG_DELIVERY_STATUS 0x1000
73 #define CMD_REG_TO_READ 0x300
74 #define CMD_REG_REMOTE_RD_STS_MSK 0x30000
75 #define CMD_REG_REMOTE_DELIVERY_PENDING 0x10000
76 #define CMD_REG_REMOTE_DELIVERY_DONE 0x20000
77 #define CMD_REG_TO_NMI 0x400
78
79 // ExeFlags bits
80 #define WAIT_FOR_CORE     0x00000001
81 #define TASK_HAS_OUTPUT   0x00000002
82 #define RETURN_PARAMS     0x00000004
83 #define END_AT_HLT        0x00000008
84 #define PASS_EARLY_PARAMS 0x00000010
85
86 // Control Byte Values
87 // bit 7 indicates the type of message
88 // 1 - control message
89 // 0 - launch + APIC ID = message to go
90 //
91 #define CORE_UNAVAILABLE            0xFF
92 #define CORE_IDLE                   0xFE
93 #define CORE_IDLE_HLT               0xFD
94 #define CORE_ACTIVE                 0xFC
95 #define CORE_NEEDS_PTR              0xFB
96 #define CORE_NEEDS_DATA_SIZE        0xFA
97 #define CORE_STS_DATA_READY_1       0xF9
98 #define CORE_STS_DATA_READY_0       0xF8
99 #define CORE_DATA_FLAGS_READY       0xF7
100 #define CORE_DATA_FLAGS_ACKNOWLEDGE 0xF6
101 #define CORE_DATA_PTR_READY         0xF5
102
103 // Macro used to determine the number of dwords to transmit to the AP as input
104 #define SIZE_IN_DWORDS(sInput) ((UINT32) (((sizeof (sInput)) + 3) >> 2))
105
106 // IDT table
107 #define IDT_DESC_PRESENT     0x80
108
109 #define IDT_DESC_TYPE_LDT    0x02
110 #define IDT_DESC_TYPE_CALL16 0x04
111 #define IDT_DESC_TYPE_TASK   0x05
112 #define IDT_DESC_TYPE_INT16  0x06
113 #define IDT_DESC_TYPE_TRAP16 0x07
114 #define IDT_DESC_TYPE_CALL32 0x0C
115 #define IDT_DESC_TYPE_INT32  0x0E
116 #define IDT_DESC_TYPE_TRAP32 0x0F
117 /*---------------------------------------------------------------------------------------
118  *               T Y P E D E F S,   S T R U C T U R E S,    E N U M S
119  *---------------------------------------------------------------------------------------
120  */
121 typedef VOID (*PF_AP_TASK) (AMD_CONFIG_PARAMS *StdHeader);
122 typedef VOID (*PF_AP_TASK_I) (VOID *, AMD_CONFIG_PARAMS *StdHeader);
123 typedef VOID (*PF_AP_TASK_C) (AMD_CONFIG_PARAMS *StdHeader, AMD_CPU_EARLY_PARAMS *);
124 typedef VOID (*PF_AP_TASK_IC) (VOID *, AMD_CONFIG_PARAMS *StdHeader, AMD_CPU_EARLY_PARAMS *);
125 typedef UINT32 (*PF_AP_TASK_O) (AMD_CONFIG_PARAMS *StdHeader);
126 typedef UINT32 (*PF_AP_TASK_IO) (VOID *, AMD_CONFIG_PARAMS *StdHeader);
127 typedef UINT32 (*PF_AP_TASK_OC) (AMD_CONFIG_PARAMS *StdHeader, AMD_CPU_EARLY_PARAMS *);
128 typedef UINT32 (*PF_AP_TASK_IOC) (VOID *, AMD_CONFIG_PARAMS *StdHeader, AMD_CPU_EARLY_PARAMS *);
129
130 /// Function pointer union representing the eight different
131 /// types of functions that an AP can be asked to perform.
132 typedef union {
133   PF_AP_TASK     PfApTask;      ///< AMD_CONFIG_PARAMS *  input with no output
134   PF_AP_TASK_I   PfApTaskI;     ///< VOID * + AMD_CONFIG_PARAMS *  input with no output
135   PF_AP_TASK_C   PfApTaskC;     ///< AMD_CONFIG_PARAMS * + AMD_CPU_EARLY_PARAMS *  input with no output
136   PF_AP_TASK_IC  PfApTaskIC;    ///< VOID * + AMD_CONFIG_PARAMS * + AMD_CPU_EARLY_PARAMS *  input with no output
137   PF_AP_TASK_O   PfApTaskO;     ///< AMD_CONFIG_PARAMS * input with UINT32 output
138   PF_AP_TASK_IO  PfApTaskIO;    ///< VOID * + AMD_CONFIG_PARAMS * input with UINT32 output
139   PF_AP_TASK_OC  PfApTaskOC;    ///< AMD_CONFIG_PARAMS * + AMD_CPU_EARLY_PARAMS * input with UINT32 output
140   PF_AP_TASK_IOC PfApTaskIOC;   ///< VOID * + AMD_CONFIG_PARAMS * + AMD_CPU_EARLY_PARAMS *  input with UINT32 output
141 } AP_FUNCTION_PTR;
142
143 /// Input structure for ApUtilTransmitBuffer and ApUtilReceiveBuffer
144 /// containing information about the data transfer from one core
145 /// to another.
146 typedef struct {
147   IN OUT   UINT16 DataSizeInDwords;   ///< Size of the data to be transferred rounded up to the nearest dword
148   IN OUT   VOID   *DataPtr;           ///< Pointer to the data
149   IN       UINT32 DataTransferFlags;  ///< Flags dictating certain aspects of the data transfer
150 } AP_DATA_TRANSFER;
151
152 /// Input structure for ApUtilRunCodeOnSocketCore.
153 typedef struct _AP_TASK {
154   AP_FUNCTION_PTR  FuncAddress;   ///< Pointer to the function that the AP will run
155   AP_DATA_TRANSFER DataTransfer;  ///< Data transfer struct for optionally passing data that the AP should use as input to the function
156   UINT32           ExeFlags;      ///< Flags dictating certain aspects of the AP tasking sequence
157 } AP_TASK;
158
159 /// Input structure for ApUtilWaitForCoreStatus.
160 typedef struct {
161   IN       UINT8  *Status;            ///< Pointer to the 1st element of an array of values to wait for
162   IN       UINT8  NumberOfElements;   ///< Number of elements in the array
163   IN       UINT32 RetryCount;         ///< Number of remote read cycles to complete before quitting
164   IN       UINT32 WaitForStatusFlags; ///< Flags dictating certain aspects of ApUtilWaitForCoreStatus
165 } AP_WAIT_FOR_STATUS;
166
167 /// Interrupt Descriptor Table entry
168 typedef struct {
169   UINT16 OffsetLo;     ///< Lower 16 bits of the interrupt handler routine's offset
170   UINT16 Selector;     ///< Interrupt handler routine's selector
171   UINT8  Rsvd;         ///< Reserved
172   UINT8  Flags;        ///< Interrupt flags
173   UINT16 OffsetHi;     ///< Upper 16 bits of the interrupt handler routine's offset
174   UINT32 Offset64;     ///< High order 32 bits of the handler's offset needed when in 64 bit mode
175   UINT32 Rsvd64;       ///< Reserved
176 } IDT_DESCRIPTOR;
177
178 /// Structure needed to load the IDTR using the lidt instruction
179 typedef struct {
180   UINT16 Limit;        ///< Interrupt Descriptor Table size
181   UINT64 Base;         ///< Interrupt Descriptor Table base address
182 } IDT_BASE_LIMIT;
183
184 #define WAIT_STATUS_EQUALITY 0x00000001
185 #define WAIT_INFINITELY 0
186
187 // Data Transfer Flags
188 #define DATA_IN_MEMORY 0x00000001
189
190
191 /*---------------------------------------------------------------------------------------
192  *                        F U N C T I O N    P R O T O T Y P E
193  *---------------------------------------------------------------------------------------
194  */
195 //                   These are   P U B L I C   functions, used by AGESA
196 UINT8
197 ApUtilReadRemoteControlByte (
198   IN       UINT32 TargetApicId,
199   IN       AMD_CONFIG_PARAMS *StdHeader
200   );
201
202 VOID
203 ApUtilWriteControlByte (
204   IN       UINT8 Value,
205   IN       AMD_CONFIG_PARAMS *StdHeader
206   );
207
208 UINT32
209 ApUtilReadRemoteDataDword (
210   IN       UINT32 TargetApicId,
211   IN       AMD_CONFIG_PARAMS *StdHeader
212   );
213
214 VOID
215 ApUtilWriteDataDword (
216   IN       UINT32 Value,
217   IN       AMD_CONFIG_PARAMS *StdHeader
218   );
219
220 UINT32
221 ApUtilRunCodeOnSocketCore (
222   IN       UINT8 Socket,
223   IN       UINT8 Core,
224   IN       AP_TASK *TaskPtr,
225   IN       AMD_CONFIG_PARAMS *StdHeader
226   );
227
228 UINT8
229 ApUtilWaitForCoreStatus (
230   IN       UINT32 TargetApicId,
231   IN       AP_WAIT_FOR_STATUS *WaitParamsPtr,
232   IN       AMD_CONFIG_PARAMS *StdHeader
233   );
234
235 VOID
236 ApEntry (
237   IN       AMD_CONFIG_PARAMS *StdHeader,
238   IN       AMD_CPU_EARLY_PARAMS *CpuEarlyParams
239   );
240
241 UINT32
242 ApUtilTaskOnExecutingCore (
243   IN       AP_TASK *TaskPtr,
244   IN       AMD_CONFIG_PARAMS *StdHeader,
245   IN       VOID    *ConfigParams
246   );
247
248 VOID
249 ApUtilTransmitBuffer (
250   IN     UINT8   Socket,
251   IN     UINT8   Core,
252   IN     AP_DATA_TRANSFER *BufferInfo,
253   IN     AMD_CONFIG_PARAMS *StdHeader
254   );
255
256 AGESA_STATUS
257 ApUtilReceiveBuffer (
258   IN       UINT8   Socket,
259   IN       UINT8   Core,
260   IN OUT   AP_DATA_TRANSFER  *BufferInfo,
261   IN       AMD_CONFIG_PARAMS *StdHeader
262   );
263
264 VOID
265 GetLocalApicIdForCore (
266   IN       UINT32 TargetSocket,
267   IN       UINT32 TargetCore,
268      OUT   UINT32 *LocalApicId,
269   IN       AMD_CONFIG_PARAMS *StdHeader
270   );
271
272 VOID
273 ApUtilRunCodeOnAllLocalCoresAtEarly (
274   IN       AP_TASK *TaskPtr,
275   IN       AMD_CONFIG_PARAMS *StdHeader,
276   IN       AMD_CPU_EARLY_PARAMS *CpuEarlyParamsPtr
277   );
278
279 VOID
280 RelinquishControlOfAllAPs (
281   IN       AMD_CONFIG_PARAMS   *StdHeader
282   );
283
284 VOID
285 GetCsSelector (
286   IN       UINT16 *Selector,
287   IN       AMD_CONFIG_PARAMS *StdHeader
288   );
289
290 VOID
291 SetIdtr (
292   IN       IDT_BASE_LIMIT *IdtInfo,
293   IN       AMD_CONFIG_PARAMS *StdHeader
294   );
295
296 VOID
297 GetIdtr (
298   IN       IDT_BASE_LIMIT *IdtInfo,
299   IN       AMD_CONFIG_PARAMS *StdHeader
300   );
301
302 #endif  /* _CPU_APIC_UTILITIES_H_ */
303