AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / Recovery / HT / htInitRecovery.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * Init the Socket and Node maps for Recovery mode.
6  *
7  * Create the Socket and Node maps just like normal boot,
8  * except that they only indicate the BSC is present.
9  *
10  * @xrefitem bom "File Content Label" "Release Content"
11  * @e project:      AGESA
12  * @e sub-project:  HyperTransport
13  * @e \$Revision: 44324 $   @e \$Date: 2010-12-22 02:16:51 -0700 (Wed, 22 Dec 2010) $
14  *
15  */
16 /*
17 *****************************************************************************
18 *
19 * Copyright (C) 2012 Advanced Micro Devices, Inc.
20 * All rights reserved.
21 *
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions are met:
24 *     * Redistributions of source code must retain the above copyright
25 *       notice, this list of conditions and the following disclaimer.
26 *     * Redistributions in binary form must reproduce the above copyright
27 *       notice, this list of conditions and the following disclaimer in the
28 *       documentation and/or other materials provided with the distribution.
29 *     * Neither the name of Advanced Micro Devices, Inc. nor the names of
30 *       its contributors may be used to endorse or promote products derived
31 *       from this software without specific prior written permission.
32 *
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
34 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
35 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
36 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
37 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
38 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
39 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
40 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
41 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 *
44 * ***************************************************************************
45 *
46 */
47
48
49 #include "AGESA.h"
50 #include "Ids.h"
51 #include "Topology.h"
52 #include "heapManager.h"
53 #include "Filecode.h"
54 CODE_GROUP (G2_PEI)
55 RDATA_GROUP (G2_PEI)
56
57 #define FILECODE PROC_RECOVERY_HT_HTINITRECOVERY_FILECODE
58
59 AGESA_STATUS
60 AmdHtInitRecovery (
61   IN       AMD_CONFIG_PARAMS *StdHeader
62   );
63
64 /*----------------------------------------------------------------------------------------*/
65 /**
66  * Get new Socket and Node Maps.
67  *
68  * Put the Socket Die Table and the Node Table in heap with known handles.
69  *
70  * @param[out]    SocketDieToNodeMap   The Socket, Module to Node info map
71  * @param[out]    NodeToSocketDieMap   The Node to Socket, Module map.
72  * @param[in]     StdHeader            Header for library and services.
73  */
74 VOID
75 STATIC
76 NewNodeAndSocketTablesRecovery (
77      OUT   SOCKET_DIE_TO_NODE_MAP *SocketDieToNodeMap,
78      OUT   NODE_TO_SOCKET_DIE_MAP *NodeToSocketDieMap,
79   IN       AMD_CONFIG_PARAMS      *StdHeader
80   )
81 {
82   UINT8 i;
83   UINT8 j;
84   ALLOCATE_HEAP_PARAMS AllocHeapParams;
85
86   // Allocate heap for the table
87   AllocHeapParams.RequestedBufferSize = (((MAX_SOCKETS) * (MAX_DIES)) * sizeof (SOCKET_DIE_TO_NODE_ITEM));
88   AllocHeapParams.BufferHandle = SOCKET_DIE_MAP_HANDLE;
89   AllocHeapParams.Persist = HEAP_SYSTEM_MEM;
90   if (HeapAllocateBuffer (&AllocHeapParams, StdHeader) == AGESA_SUCCESS) {
91     // HeapAllocateBuffer must set BufferPtr to valid or NULL.
92     *SocketDieToNodeMap = (SOCKET_DIE_TO_NODE_MAP)AllocHeapParams.BufferPtr;
93     ASSERT (SocketDieToNodeMap != NULL);
94     // Initialize shared data structures
95     for (i = 0; i < MAX_SOCKETS; i++) {
96       for (j = 0; j < MAX_DIES; j++) {
97         (**SocketDieToNodeMap)[i][j].Node = HT_LIST_TERMINAL;
98         (**SocketDieToNodeMap)[i][j].LowCore = HT_LIST_TERMINAL;
99         (**SocketDieToNodeMap)[i][j].HighCore = HT_LIST_TERMINAL;
100       }
101     }
102   }
103   // Allocate heap for the table
104   AllocHeapParams.RequestedBufferSize = (MAX_NODES * sizeof (NODE_TO_SOCKET_DIE_ITEM));
105   AllocHeapParams.BufferHandle = NODE_ID_MAP_HANDLE;
106   AllocHeapParams.Persist = HEAP_SYSTEM_MEM;
107   if (HeapAllocateBuffer (&AllocHeapParams, StdHeader) == AGESA_SUCCESS) {
108     // HeapAllocateBuffer must set BufferPtr to valid or NULL.
109     *NodeToSocketDieMap = (NODE_TO_SOCKET_DIE_MAP)AllocHeapParams.BufferPtr;
110     ASSERT (NodeToSocketDieMap != NULL);
111     // Initialize shared data structures
112     for (i = 0; i < MAX_NODES; i++) {
113       (**NodeToSocketDieMap)[i].Socket = HT_LIST_TERMINAL;
114       (**NodeToSocketDieMap)[i].Die = HT_LIST_TERMINAL;
115     }
116   }
117 }
118
119 /*----------------------------------------------------------------------------------------*/
120 /**
121  * Initialize the Node and Socket maps for an AP Core.
122  *
123  * In each core's local heap, create a Node to Socket map and a Socket/Module to Node map.
124  * The mapping is filled in by reading the AP Mailboxes from PCI config on each node.
125  *
126  * @param[in]    StdHeader    global state, input data
127  *
128  * @retval       AGESA_SUCCESS  Always succeeds.
129  */
130 AGESA_STATUS
131 AmdHtInitRecovery (
132   IN       AMD_CONFIG_PARAMS *StdHeader
133   )
134 {
135   AP_MAILBOXES NodeApMailBox;
136   ALLOCATE_HEAP_PARAMS AllocHeapParams;
137   SOCKET_DIE_TO_NODE_MAP SocketDieToNodeMap = NULL;
138   NODE_TO_SOCKET_DIE_MAP NodeToSocketDieMap = NULL;
139
140   NodeApMailBox.ApMailInfo.Info = 0;
141   NodeApMailBox.ApMailExtInfo.Info = 0;
142
143   // Allocate heap for caching the mailboxes
144   AllocHeapParams.RequestedBufferSize = sizeof (AP_MAILBOXES);
145   AllocHeapParams.BufferHandle = LOCAL_AP_MAIL_BOX_CACHE_HANDLE;
146   AllocHeapParams.Persist = HEAP_SYSTEM_MEM;
147   if (HeapAllocateBuffer (&AllocHeapParams, StdHeader) == AGESA_SUCCESS) {
148     *(AP_MAILBOXES *)AllocHeapParams.BufferPtr = NodeApMailBox;
149   }
150
151   NewNodeAndSocketTablesRecovery (&SocketDieToNodeMap, &NodeToSocketDieMap, StdHeader);
152   // HeapAllocateBuffer must set BufferPtr to valid or NULL, so the checks below are ok.
153
154   // There is no option to not have socket - node maps, if they aren't allocated that is a fatal bug.
155   ASSERT (SocketDieToNodeMap != NULL);
156   ASSERT (NodeToSocketDieMap != NULL);
157
158   (*SocketDieToNodeMap)[0][0].Node = 0;
159   (*SocketDieToNodeMap)[0][0].LowCore = 0;
160   (*SocketDieToNodeMap)[0][0].HighCore = 0;
161
162   // We lie about being Socket 0 and Module 0 always, it isn't necessarily true.
163   (*NodeToSocketDieMap)[0].Socket = (UINT8)0;
164   (*NodeToSocketDieMap)[0].Die = (UINT8)0;
165
166   return AGESA_SUCCESS;
167 }
168