blob: d6b80edd0be8743f3c30d78eca44987a9be8fad5 [file] [log] [blame]
Martin Roth7687e772023-08-22 16:32:20 -06001/* SPDX-License-Identifier: BSD-3-Clause */
2
Marc Jones0b11bd02015-07-19 15:20:17 -06003/* $NoKeywords:$ */
4/**
5 * @file
6 *
7 * AMD Heap Manager and Heap Allocation APIs, and related functions.
8 *
9 * Contains code that initialize, maintain, and allocate the heap space.
10 *
11 * @xrefitem bom "File Content Label" "Release Content"
12 * @e project: AGESA
13 * @e sub-project: CPU
14 * @e \$Revision: 281178 $ @e \$Date: 2013-12-18 02:14:15 -0600 (Wed, 18 Dec 2013) $
15 *
16 */
17/*****************************************************************************
18 *
19 * Copyright (c) 2008 - 2014, 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#ifndef _HEAP_MANAGER_H_
47#define _HEAP_MANAGER_H_
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 AMD_MTRR_VARIABLE_BASE0 0x200
60#define AMD_MTRR_VARIABLE_HEAP_BASE 0x20A
61#define AMD_MTRR_VARIABLE_HEAP_MASK (AMD_MTRR_VARIABLE_HEAP_BASE + 1)
62
63#define AMD_HEAP_START_ADDRESS 0x400000ul
64#define AMD_HEAP_REGION_END_ADDRESS 0xBFFFFFul
65#define AMD_HEAP_SIZE_PER_CORE 0x010000ul
66#define AMD_HEAP_INVALID_HEAP_OFFSET 0xFFFFFFFFul
67#define AMD_HEAP_MTRR_MASK ((0xFFFFFFFFFFFFF800ull & (((UINT64)AMD_HEAP_SIZE_PER_CORE ^ (-1)) + 1)) | 0x800)
68#define AMD_HEAP_SIZE_DWORD_PER_CORE (AMD_HEAP_SIZE_PER_CORE / 4)
69
70#define AMD_TEMP_TOM 0x20000000ul // Set TOM to 512 MB (temporary value)
71#define AMD_VAR_MTRR_ENABLE_BIT 0x100000ul // bit 20
72
73#define AMD_HEAP_RAM_ADDRESS 0xB0000ul
74
75#define HEAP_SIGNATURE_VALID 0x50414548ul // Signature: 'HEAP'
76#define HEAP_SIGNATURE_INVALID 0x00000000ul // Signature cleared
77
78///Heap Manager Life cycle
79#define HEAP_DO_NOT_EXIST_YET 1
80#define HEAP_LOCAL_CACHE 2
81#define HEAP_TEMP_MEM 3
82#define HEAP_SYSTEM_MEM 4
83#define HEAP_DO_NOT_EXIST_ANYMORE 5
84#define HEAP_S3_RESUME 6
85#define HEAP_RUNTIME_SYSTEM_MEM 7
86
87///Heap callout
88#define HEAP_CALLOUT_BOOTTIME 0
89#define HEAP_CALLOUT_RUNTIME 1
90
91#define AMD_MTRR_FIX64k_00000 0x250
92#define AMD_MTRR_FIX16k_80000 0x258
93#define AMD_MTRR_FIX16k_A0000 0x259
94#define AMD_MTRR_FIX4k_C0000 0x268
95#define AMD_MTRR_FIX4k_C8000 0x269
96#define AMD_MTRR_FIX4k_D0000 0x26A
97#define AMD_MTRR_FIX4k_D8000 0x26B
98#define AMD_MTRR_FIX4k_E0000 0x26C
99#define AMD_MTRR_FIX4k_E8000 0x26D
100#define AMD_MTRR_FIX4k_F0000 0x26E
101#define AMD_MTRR_FIX4k_F8000 0x26F
102
103#define AMD_MTRR_FIX64K_WB_DRAM 0x1E
104#define AMD_MTRR_FIX64K_WT_DRAM 0x1C
105#define AMD_MTRR_FIX64K_UC_DRAM 0x18
106#define AMD_MTRR_FIX16K_WB_DRAM 0x1E1E1E1E1E1E1E1Eull
107#define AMD_MTRR_FIX16K_WT_DRAM 0x1C1C1C1C1C1C1C1Cull
108#define AMD_MTRR_FIX16K_UC_DRAM 0x1818181818181818ull
109#define AMD_MTRR_FIX4K_WB_DRAM 0x1E1E1E1E1E1E1E1Eull
110#define AMD_MTRR_FIX4K_WT_DRAM 0x1C1C1C1C1C1C1C1Cull
111#define AMD_MTRR_FIX4K_UC_DRAM 0x1818181818181818ull
112
113/*---------------------------------------------------------------------------------------
114 * T Y P E D E F S, S T R U C T U R E S, E N U M S
115 *---------------------------------------------------------------------------------------
116 */
117/// Allocate Heap Parameters
118typedef struct _ALLOCATE_HEAP_PARAMS {
119 UINT32 RequestedBufferSize; ///< Size of buffer.
120 UINT32 BufferHandle; ///< An unique ID of buffer.
121 UINT8 Persist; ///< A flag. If marked, to be stored and passed to AmdInitLate.
122 UINT8 *BufferPtr; ///< Pointer to buffer.
123} ALLOCATE_HEAP_PARAMS;
124
125/// Locate Heap Parameters
126typedef struct _LOCATE_HEAP_PTR {
127 UINT32 BufferHandle; ///< An unique ID of buffer.
128 UINT32 BufferSize; ///< Data buffer size.
129 UINT8 *BufferPtr; ///< Pointer to buffer.
130} LOCATE_HEAP_PTR;
131
132/// Heap Node Header
133typedef struct _BUFFER_NODE {
134 UINT32 BufferHandle; ///< An unique ID of buffer.
135 UINT32 BufferSize; ///< Size of buffer.
136 UINT8 Persist; ///< A flag. If marked, to be stored and passed to AmdInitLate.
137 UINT8 PadSize; ///< Size of pad.
138 UINT32 OffsetOfNextNode; ///< Offset of next node (relative to the base).
139} BUFFER_NODE;
140
141/// Heap Manager
142typedef struct _HEAP_MANAGER {
143 UINT32 Signature; ///< a signature to indicate if the heap is valid.
144 UINT32 UsedSize; ///< Used size of heap.
145 UINT32 FirstActiveBufferOffset; ///< Offset of the first active buffer.
146 UINT32 FirstFreeSpaceOffset; ///< Offset of the first free space.
147} HEAP_MANAGER;
148
149/// AGESA Buffer Handles (These are reserved)
150typedef enum {
151 AMD_INIT_RESET_HANDLE = 0x000A000, ///< Assign 0x000A000 buffer handle to AmdInitReset routine.
152 AMD_INIT_EARLY_HANDLE, ///< Assign 0x000A001 buffer handle to AmdInitEarly routine.
153 AMD_INIT_POST_HANDLE, ///< Assign 0x000A002 buffer handle to AmdInitPost routine.
154 AMD_INIT_ENV_HANDLE, ///< Assign 0x000A003 buffer handle to AmdInitEnv routine.
155 AMD_INIT_MID_HANDLE, ///< Assign 0x000A004 buffer handle to AmdInitMid routine.
156 AMD_INIT_LATE_HANDLE, ///< Assign 0x000A005 buffer handle to AmdInitLate routine.
157 AMD_INIT_RESUME_HANDLE, ///< Assign 0x000A006 buffer handle to AmdInitResume routine.
158 AMD_LATE_RUN_AP_TASK_HANDLE, ///< Assign 0x000A007 buffer handle to AmdLateRunApTask routine.
159 AMD_S3_SAVE_HANDLE, ///< Assign 0x000A008 buffer handle to AmdS3Save routine.
160 AMD_S3_LATE_RESTORE_HANDLE, ///< Assign 0x000A009 buffer handle to AmdS3LateRestore routine.
161 AMD_S3_SCRIPT_SAVE_TABLE_HANDLE, ///< Assign 0x000A00A buffer handle to be used for S3 save table
162 AMD_S3_SCRIPT_TEMP_BUFFER_HANDLE, ///< Assign 0x000A00B buffer handle to be used for S3 save table
163 AMD_CPU_AP_TASKING_HANDLE, ///< Assign 0x000A00C buffer handle to AP tasking input parameters.
164 AMD_REC_MEM_SOCKET_HANDLE, ///< Assign 0x000A00D buffer handle to save socket with memory in memory recovery mode.
165 AMD_MEM_AUTO_HANDLE, ///< Assign 0x000A00E buffer handle to AmdMemAuto routine.
166 AMD_MEM_SPD_HANDLE, ///< Assign 0x000A00F buffer handle to AmdMemSpd routine.
167 AMD_MEM_DATA_HANDLE, ///< Assign 0x000A010 buffer handle to MemData
168 AMD_MEM_TRAIN_BUFFER_HANDLE, ///< Assign 0x000A011 buffer handle to allocate buffer for training
169 AMD_MEM_S3_DATA_HANDLE, ///< Assign 0x000A012 buffer handle to special case register for S3
170 AMD_MEM_S3_NB_HANDLE, ///< Assign 0x000A013 buffer handle to NB block for S3
171 AMD_MEM_S3_MR0_DATA_HANDLE, ///< Assign 0x000A014 buffer handle to MR0 data block for S3
172 AMD_UMA_INFO_HANDLE, ///< Assign 0x000A015 buffer handle to be used for Uma information
173 AMD_DMI_MEM_DEV_INFO_HANDLE, ///< Assign 0x000A016 buffer handle to DMI Type16 17 19 20 information
174 EVENT_LOG_BUFFER_HANDLE, ///< Assign 0x000A017 buffer handle to Event Log
175 IDS_CONTROL_HANDLE, ///< Assign 0x000A018 buffer handle to AmdIds routine.
176 IDS_HDT_OUT_BUFFER_HANDLE, ///< Assign 0x000A019 buffer handle to be used for HDTOUT support.
177 IDS_CHECK_POINT_PERF_HANDLE, ///< Assign 0x000A01A buffer handle to Performance analysis
178 AMD_PCIE_COMPLEX_DATA_HANDLE, ///< Assign 0x000A01B buffer handle to be used for PCIe support
179 AMD_MEM_SYS_DATA_HANDLE, ///< Assign 0x000A01C buffer handle to be used for memory data structure
180 AMD_GNB_SMU_CONFIG_HANDLE, ///< Assign 0x000A01D buffer handle to be used for GNB SMU configuration
181 AMD_PP_FUSE_TABLE_HANDLE, ///< Assign 0x000A01E buffer handle to be used for TT fuse table
182 AMD_GFX_PLATFORM_CONFIG_HANDLE, ///< Assign 0x000A01F buffer handle to be used for Gfx platform configuration
183 AMD_GNB_TEMP_DATA_HANDLE, ///< Assign 0x000A020 buffer handle for GNB general purpose data block
184 AMD_MEM_2D_RDQS_HANDLE, ///< Assign 0x000A021 buffer handle for 2D training
185 AMD_MEM_2D_RD_WR_HANDLE, ///< Assign 0x000A022 buffer handle for 2D Read/Write training
186 AMD_GNB_IOMMU_SCRATCH_MEM_HANDLE, ///< Assign 0x000A023 buffer handle to be used for GNB IOMMU scratch memory
187 AMD_MEM_S3_SAVE_HANDLE, ///< Assign 0x000A024 buffer handle for memory data saved right after memory init
188 AMD_MEM_2D_RDQS_RIM_HANDLE, ///< Assign 0x000A025 buffer handle for 2D training Eye RIM Search
189 AMD_MEM_2D_RD_WR_RIM_HANDLE, ///< Assign 0x000A026 buffer handle for 2D Read/Write training Eye RIM Search
190 AMD_CPU_NB_PSTATE_FIXUP_HANDLE, ///< Assign 0x000A027 buffer handle for an NB P-state workaround
191 AMD_MEM_CRAT_INFO_BUFFER_HANDLE, ///< Assign 0x000A028 buffer handle for CRAT Memory affinity component structure
192 AMD_SKIP_MEM_S3_SAVE, ///< Assign 0x000A029 buffer handle for the flag to skip memory S3 save
193 AMD_SCS_SMU_RAM_INFO, ///< Assign 0x000A02A buffer handle for keeping the result of SMU SCS service
194 AMD_SCS_HWP0_FREQ, ///< Assign 0x000A02B buffer handler for keeping frequency of HWP0
195 AMD_IS_FEATURE_ENABLED, ///< Assign 0x000A02C buffer handle for keeping the result of IsFeatureEnabled
196 AMD_MEM_DATAEYE_WORK_AREA_HANDLE, ///< Assign 0x000A02D buffer handle for Composite Data Eye Compression Work Area
197 AMD_GNB_SAMU_PATCH_HANDLE, ///< Assign 0x000A02E buffer handle for Samu patch buffer
198 AMD_GNB_SAMU_BOOT_CONTROL_HANDLE, ///< Assign 0x000A02F buffer handle for Samu boot control buffer
199 AMD_GNB_ACP_ENGINE_HANDLE, ///< Assign 0x000A030 buffer handle for GNB ACP engine buffer
200 AMD_MEM_PMU_SRAM_MSG_BLOCK_HANDLE, ///< Assign 0x000A031 buffer handle for PMU SRAM Message Block buffer
201 AMD_MEM_DRAM_CAD_BUS_CONFIG_HANDLE, ///< Assign 0x000A033 buffer handle for DRAM CAD Bus Configuration
202 AMD_GNB_SMU_TABLE_HANDLE, ///< Assign 0x000A034 buffer handle for GNB SMU table buffer
203 AMD_GNB_CRAT_HSA_TABLE_HANDLE, ///< Assign 0x000A035 buffer handle for GNB CRAT HSA unit table
204 AMD_GNB_BUILD_OPTIONS_HANDLE, ///< Assign 0x000A036 buffer handle for GNB build options
205 AMD_MEM_MISC_HANDLES_START = 0x1000000, ///< Reserve 0x1000000 to 0x1FFFFFF buffer handle
206 AMD_MEM_MISC_HANDLES_END = 0x1FFFFFF, ///< miscellaneous memory init tasks' buffers.
207 AMD_HEAP_IN_MAIN_MEMORY_HANDLE = 0x8000000, ///< Assign 0x8000000 to AMD_HEAP_IN_MAIN_MEMORY_HANDLE.
208 SOCKET_DIE_MAP_HANDLE = 0x534F4B54, ///< 'sokt'
209 NODE_ID_MAP_HANDLE = 0x4E4F4445, ///< 'node'
210 HOP_COUNT_TABLE_HANDLE = 0x484F5053, ///< 'hops'
211 AMD_FCH_RESET_DATA_BLOCK_HANDLE = 0x46434852, ///< 'FCHR' Buffer handle for FCH private data block at InitReset
212 AMD_FCH_DATA_BLOCK_HANDLE = 0x46434845, ///< 'FCHE' Buffer handle for FCH private data block at InitEnv
213 IDS_TRAP_TABLE_HANDLE = 0x49524547, ///< 'IREG' Handle for IDS register table
214 IDS_SAVE_IDTR_HANDLE = 0x49445452, ///< 'IDTR'
215 IDS_BSC_IDT_HANDLE = 0x42534349, ///< 'BSCI' BSC Idt table
216 IDS_NV_TO_CMOS_HANDLE = 0x534D4349, ///< 'ICMS' Handle for IDS CMOS save
217 IDS_GRA_HANDLE = 0x41524749, ///< 'IGRA' Handle for IDS GRA save
218 IDS_EXTEND_HANDLE = 0x54584549, ///< 'IEXT' Handle for IDS extend module
219 IDS_TEMP_DATA_HANDLE = 0x504D5459, ///< 'ITMP' Handle for IDS temp data
220} AGESA_BUFFER_HANDLE;
221
222
223/*---------------------------------------------------------------------------------------
224 * F U N C T I O N P R O T O T Y P E
225 *---------------------------------------------------------------------------------------
226 */
227
228AGESA_STATUS
229HeapManagerInit (
230 IN AMD_CONFIG_PARAMS *StdHeader
231 );
232
233AGESA_STATUS
234HeapAllocateBuffer (
235 IN OUT ALLOCATE_HEAP_PARAMS *AllocateHeapParams,
236 IN OUT AMD_CONFIG_PARAMS *StdHeader
237 );
238
239AGESA_STATUS
240HeapDeallocateBuffer (
241 IN UINT32 BufferHandle,
242 IN AMD_CONFIG_PARAMS *StdHeader
243 );
244
245AGESA_STATUS
246HeapLocateBuffer (
247 IN OUT LOCATE_HEAP_PTR *LocateHeap,
248 IN AMD_CONFIG_PARAMS *StdHeader
249 );
250
251UINT64
252HeapGetBaseAddress (
253 IN AMD_CONFIG_PARAMS *StdHeader
254 );
255
256AGESA_STATUS
257EventLogInitialization (
258 IN AMD_CONFIG_PARAMS *StdHeader
259 );
260#endif // _HEAP_MANAGER_H_