Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 Advanced Micro Devices, Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 18 | */ |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 19 | |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 20 | #include "agesawrapper.h" |
| 21 | #include "amdlib.h" |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 22 | #include "dimmSpd.h" |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 23 | #include "BiosCallOuts.h" |
| 24 | #include "heapManager.h" |
| 25 | #include "SB800.h" |
| 26 | |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 27 | STATIC BIOS_CALLOUT_STRUCT BiosCallouts[] = |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 28 | { |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 29 | {AGESA_ALLOCATE_BUFFER, |
| 30 | BiosAllocateBuffer |
| 31 | }, |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 32 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 33 | {AGESA_DEALLOCATE_BUFFER, |
| 34 | BiosDeallocateBuffer |
| 35 | }, |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 36 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 37 | {AGESA_DO_RESET, |
| 38 | BiosReset |
| 39 | }, |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 40 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 41 | {AGESA_LOCATE_BUFFER, |
| 42 | BiosLocateBuffer |
| 43 | }, |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 44 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 45 | {AGESA_READ_SPD, |
| 46 | BiosReadSpd |
| 47 | }, |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 48 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 49 | {AGESA_READ_SPD_RECOVERY, |
| 50 | BiosDefaultRet |
| 51 | }, |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 52 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 53 | {AGESA_RUNFUNC_ONAP, |
| 54 | BiosRunFuncOnAp |
| 55 | }, |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 56 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 57 | {AGESA_GNB_PCIE_SLOT_RESET, |
| 58 | BiosGnbPcieSlotReset |
| 59 | }, |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 60 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 61 | {AGESA_HOOKBEFORE_DRAM_INIT, |
| 62 | BiosHookBeforeDramInit |
| 63 | }, |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 64 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 65 | {AGESA_HOOKBEFORE_DRAM_INIT_RECOVERY, |
| 66 | BiosHookBeforeDramInitRecovery |
| 67 | }, |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 68 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 69 | {AGESA_HOOKBEFORE_DQS_TRAINING, |
| 70 | BiosHookBeforeDQSTraining |
| 71 | }, |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 72 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 73 | {AGESA_HOOKBEFORE_EXIT_SELF_REF, |
| 74 | BiosHookBeforeExitSelfRefresh |
| 75 | }, |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 78 | AGESA_STATUS GetBiosCallout (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 79 | { |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 80 | UINTN i; |
| 81 | AGESA_STATUS CalloutStatus; |
| 82 | UINTN CallOutCount = sizeof (BiosCallouts) / sizeof (BiosCallouts [0]); |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 83 | |
zbao | afd141d | 2012-03-30 15:32:07 +0800 | [diff] [blame] | 84 | /* |
| 85 | * printk(BIOS_SPEW,"%s function: %x\n", __func__, (u32) Func); |
| 86 | */ |
| 87 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 88 | CalloutStatus = AGESA_UNSUPPORTED; |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 89 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 90 | for (i = 0; i < CallOutCount; i++) { |
| 91 | if (BiosCallouts[i].CalloutName == Func) { |
| 92 | CalloutStatus = BiosCallouts[i].CalloutPtr (Func, Data, ConfigPtr); |
| 93 | return CalloutStatus; |
| 94 | } |
| 95 | } |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 96 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 97 | return CalloutStatus; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | AGESA_STATUS BiosAllocateBuffer (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 101 | { |
zbao | afd141d | 2012-03-30 15:32:07 +0800 | [diff] [blame] | 102 | UINT32 AvailableHeapSize; |
| 103 | UINT8 *BiosHeapBaseAddr; |
| 104 | UINT32 CurrNodeOffset; |
| 105 | UINT32 PrevNodeOffset; |
| 106 | UINT32 FreedNodeOffset; |
| 107 | UINT32 BestFitNodeOffset; |
| 108 | UINT32 BestFitPrevNodeOffset; |
| 109 | UINT32 NextFreeOffset; |
| 110 | BIOS_BUFFER_NODE *CurrNodePtr; |
| 111 | BIOS_BUFFER_NODE *FreedNodePtr; |
| 112 | BIOS_BUFFER_NODE *BestFitNodePtr; |
| 113 | BIOS_BUFFER_NODE *BestFitPrevNodePtr; |
| 114 | BIOS_BUFFER_NODE *NextFreePtr; |
| 115 | BIOS_HEAP_MANAGER *BiosHeapBasePtr; |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 116 | AGESA_BUFFER_PARAMS *AllocParams; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 117 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 118 | AllocParams = ((AGESA_BUFFER_PARAMS *) ConfigPtr); |
| 119 | AllocParams->BufferPointer = NULL; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 120 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 121 | AvailableHeapSize = BIOS_HEAP_SIZE - sizeof (BIOS_HEAP_MANAGER); |
zbao | f543c7b | 2012-04-13 13:42:46 +0800 | [diff] [blame] | 122 | BiosHeapBaseAddr = (UINT8 *) GetHeapBase(&(AllocParams->StdHeader)); |
| 123 | BiosHeapBasePtr = (BIOS_HEAP_MANAGER *) BiosHeapBaseAddr; |
| 124 | |
| 125 | printk(BIOS_SPEW, "%s BiosHeapBaseAddr: %x\n", __func__, (u32) BiosHeapBaseAddr); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 126 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 127 | if (BiosHeapBasePtr->StartOfAllocatedNodes == 0) { |
| 128 | /* First allocation */ |
| 129 | CurrNodeOffset = sizeof (BIOS_HEAP_MANAGER); |
| 130 | CurrNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + CurrNodeOffset); |
| 131 | CurrNodePtr->BufferHandle = AllocParams->BufferHandle; |
| 132 | CurrNodePtr->BufferSize = AllocParams->BufferLength; |
| 133 | CurrNodePtr->NextNodeOffset = 0; |
| 134 | AllocParams->BufferPointer = (UINT8 *) CurrNodePtr + sizeof (BIOS_BUFFER_NODE); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 135 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 136 | /* Update the remaining free space */ |
| 137 | FreedNodeOffset = CurrNodeOffset + CurrNodePtr->BufferSize + sizeof (BIOS_BUFFER_NODE); |
| 138 | FreedNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + FreedNodeOffset); |
| 139 | FreedNodePtr->BufferSize = AvailableHeapSize - sizeof (BIOS_BUFFER_NODE) - CurrNodePtr->BufferSize; |
| 140 | FreedNodePtr->NextNodeOffset = 0; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 141 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 142 | /* Update the offsets for Allocated and Freed nodes */ |
| 143 | BiosHeapBasePtr->StartOfAllocatedNodes = CurrNodeOffset; |
| 144 | BiosHeapBasePtr->StartOfFreedNodes = FreedNodeOffset; |
| 145 | } else { |
| 146 | /* Find out whether BufferHandle has been allocated on the heap. */ |
| 147 | /* If it has, return AGESA_BOUNDS_CHK */ |
| 148 | CurrNodeOffset = BiosHeapBasePtr->StartOfAllocatedNodes; |
| 149 | CurrNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + CurrNodeOffset); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 150 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 151 | while (CurrNodeOffset != 0) { |
| 152 | CurrNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + CurrNodeOffset); |
| 153 | if (CurrNodePtr->BufferHandle == AllocParams->BufferHandle) { |
| 154 | return AGESA_BOUNDS_CHK; |
| 155 | } |
| 156 | CurrNodeOffset = CurrNodePtr->NextNodeOffset; |
| 157 | /* If BufferHandle has not been allocated on the heap, CurrNodePtr here points |
zbao | afd141d | 2012-03-30 15:32:07 +0800 | [diff] [blame] | 158 | to the end of the allocated nodes list. |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 159 | */ |
zbao | afd141d | 2012-03-30 15:32:07 +0800 | [diff] [blame] | 160 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 161 | } |
| 162 | /* Find the node that best fits the requested buffer size */ |
| 163 | FreedNodeOffset = BiosHeapBasePtr->StartOfFreedNodes; |
| 164 | PrevNodeOffset = FreedNodeOffset; |
| 165 | BestFitNodeOffset = 0; |
| 166 | BestFitPrevNodeOffset = 0; |
| 167 | while (FreedNodeOffset != 0) { |
| 168 | FreedNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + FreedNodeOffset); |
| 169 | if (FreedNodePtr->BufferSize >= (AllocParams->BufferLength + sizeof (BIOS_BUFFER_NODE))) { |
| 170 | if (BestFitNodeOffset == 0) { |
| 171 | /* First node that fits the requested buffer size */ |
| 172 | BestFitNodeOffset = FreedNodeOffset; |
| 173 | BestFitPrevNodeOffset = PrevNodeOffset; |
| 174 | } else { |
| 175 | /* Find out whether current node is a better fit than the previous nodes */ |
| 176 | BestFitNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + BestFitNodeOffset); |
| 177 | if (BestFitNodePtr->BufferSize > FreedNodePtr->BufferSize) { |
| 178 | BestFitNodeOffset = FreedNodeOffset; |
| 179 | BestFitPrevNodeOffset = PrevNodeOffset; |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | PrevNodeOffset = FreedNodeOffset; |
| 184 | FreedNodeOffset = FreedNodePtr->NextNodeOffset; |
| 185 | } /* end of while loop */ |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 186 | |
| 187 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 188 | if (BestFitNodeOffset == 0) { |
| 189 | /* If we could not find a node that fits the requested buffer */ |
| 190 | /* size, return AGESA_BOUNDS_CHK */ |
| 191 | return AGESA_BOUNDS_CHK; |
| 192 | } else { |
| 193 | BestFitNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + BestFitNodeOffset); |
| 194 | BestFitPrevNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + BestFitPrevNodeOffset); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 195 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 196 | /* If BestFitNode is larger than the requested buffer, fragment the node further */ |
| 197 | if (BestFitNodePtr->BufferSize > (AllocParams->BufferLength + sizeof (BIOS_BUFFER_NODE))) { |
| 198 | NextFreeOffset = BestFitNodeOffset + AllocParams->BufferLength + sizeof (BIOS_BUFFER_NODE); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 199 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 200 | NextFreePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + NextFreeOffset); |
| 201 | NextFreePtr->BufferSize = BestFitNodePtr->BufferSize - (AllocParams->BufferLength + sizeof (BIOS_BUFFER_NODE)); |
| 202 | NextFreePtr->NextNodeOffset = BestFitNodePtr->NextNodeOffset; |
| 203 | } else { |
| 204 | /* Otherwise, next free node is NextNodeOffset of BestFitNode */ |
| 205 | NextFreeOffset = BestFitNodePtr->NextNodeOffset; |
| 206 | } |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 207 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 208 | /* If BestFitNode is the first buffer in the list, then update |
zbao | afd141d | 2012-03-30 15:32:07 +0800 | [diff] [blame] | 209 | StartOfFreedNodes to reflect the new free node |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 210 | */ |
| 211 | if (BestFitNodeOffset == BiosHeapBasePtr->StartOfFreedNodes) { |
| 212 | BiosHeapBasePtr->StartOfFreedNodes = NextFreeOffset; |
| 213 | } else { |
| 214 | BestFitPrevNodePtr->NextNodeOffset = NextFreeOffset; |
| 215 | } |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 216 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 217 | /* Add BestFitNode to the list of Allocated nodes */ |
| 218 | CurrNodePtr->NextNodeOffset = BestFitNodeOffset; |
| 219 | BestFitNodePtr->BufferSize = AllocParams->BufferLength; |
| 220 | BestFitNodePtr->BufferHandle = AllocParams->BufferHandle; |
| 221 | BestFitNodePtr->NextNodeOffset = 0; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 222 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 223 | /* Remove BestFitNode from list of Freed nodes */ |
| 224 | AllocParams->BufferPointer = (UINT8 *) BestFitNodePtr + sizeof (BIOS_BUFFER_NODE); |
| 225 | } |
| 226 | } |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 227 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 228 | return AGESA_SUCCESS; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | AGESA_STATUS BiosDeallocateBuffer (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 232 | { |
| 233 | |
zbao | f543c7b | 2012-04-13 13:42:46 +0800 | [diff] [blame] | 234 | UINT8 *BiosHeapBaseAddr; |
| 235 | UINT32 AllocNodeOffset; |
| 236 | UINT32 PrevNodeOffset; |
| 237 | UINT32 NextNodeOffset; |
| 238 | UINT32 FreedNodeOffset; |
| 239 | UINT32 EndNodeOffset; |
| 240 | BIOS_BUFFER_NODE *AllocNodePtr; |
| 241 | BIOS_BUFFER_NODE *PrevNodePtr; |
| 242 | BIOS_BUFFER_NODE *FreedNodePtr; |
| 243 | BIOS_BUFFER_NODE *NextNodePtr; |
| 244 | BIOS_HEAP_MANAGER *BiosHeapBasePtr; |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 245 | AGESA_BUFFER_PARAMS *AllocParams; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 246 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 247 | AllocParams = (AGESA_BUFFER_PARAMS *) ConfigPtr; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 248 | |
zbao | f543c7b | 2012-04-13 13:42:46 +0800 | [diff] [blame] | 249 | BiosHeapBaseAddr = (UINT8 *) GetHeapBase(&(AllocParams->StdHeader)); |
| 250 | BiosHeapBasePtr = (BIOS_HEAP_MANAGER *) BiosHeapBaseAddr; |
| 251 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 252 | /* Find target node to deallocate in list of allocated nodes. |
zbao | f543c7b | 2012-04-13 13:42:46 +0800 | [diff] [blame] | 253 | Return AGESA_BOUNDS_CHK if the BufferHandle is not found |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 254 | */ |
| 255 | AllocNodeOffset = BiosHeapBasePtr->StartOfAllocatedNodes; |
| 256 | AllocNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + AllocNodeOffset); |
| 257 | PrevNodeOffset = AllocNodeOffset; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 258 | |
zbao | afd141d | 2012-03-30 15:32:07 +0800 | [diff] [blame] | 259 | while (AllocNodePtr->BufferHandle != AllocParams->BufferHandle) { |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 260 | if (AllocNodePtr->NextNodeOffset == 0) { |
| 261 | return AGESA_BOUNDS_CHK; |
| 262 | } |
| 263 | PrevNodeOffset = AllocNodeOffset; |
| 264 | AllocNodeOffset = AllocNodePtr->NextNodeOffset; |
| 265 | AllocNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + AllocNodeOffset); |
| 266 | } |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 267 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 268 | /* Remove target node from list of allocated nodes */ |
| 269 | PrevNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + PrevNodeOffset); |
| 270 | PrevNodePtr->NextNodeOffset = AllocNodePtr->NextNodeOffset; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 271 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 272 | /* Zero out the buffer, and clear the BufferHandle */ |
| 273 | LibAmdMemFill ((UINT8 *)AllocNodePtr + sizeof (BIOS_BUFFER_NODE), 0, AllocNodePtr->BufferSize, &(AllocParams->StdHeader)); |
| 274 | AllocNodePtr->BufferHandle = 0; |
| 275 | AllocNodePtr->BufferSize += sizeof (BIOS_BUFFER_NODE); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 276 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 277 | /* Add deallocated node in order to the list of freed nodes */ |
| 278 | FreedNodeOffset = BiosHeapBasePtr->StartOfFreedNodes; |
| 279 | FreedNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + FreedNodeOffset); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 280 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 281 | EndNodeOffset = AllocNodeOffset + AllocNodePtr->BufferSize; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 282 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 283 | if (AllocNodeOffset < FreedNodeOffset) { |
| 284 | /* Add to the start of the freed list */ |
| 285 | if (EndNodeOffset == FreedNodeOffset) { |
| 286 | /* If the freed node is adjacent to the first node in the list, concatenate both nodes */ |
| 287 | AllocNodePtr->BufferSize += FreedNodePtr->BufferSize; |
| 288 | AllocNodePtr->NextNodeOffset = FreedNodePtr->NextNodeOffset; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 289 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 290 | /* Clear the BufferSize and NextNodeOffset of the previous first node */ |
| 291 | FreedNodePtr->BufferSize = 0; |
| 292 | FreedNodePtr->NextNodeOffset = 0; |
zbao | afd141d | 2012-03-30 15:32:07 +0800 | [diff] [blame] | 293 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 294 | } else { |
| 295 | /* Otherwise, add freed node to the start of the list |
zbao | afd141d | 2012-03-30 15:32:07 +0800 | [diff] [blame] | 296 | Update NextNodeOffset and BufferSize to include the |
| 297 | size of BIOS_BUFFER_NODE |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 298 | */ |
| 299 | AllocNodePtr->NextNodeOffset = FreedNodeOffset; |
| 300 | } |
| 301 | /* Update StartOfFreedNodes to the new first node */ |
| 302 | BiosHeapBasePtr->StartOfFreedNodes = AllocNodeOffset; |
| 303 | } else { |
| 304 | /* Traverse list of freed nodes to find where the deallocated node |
zbao | afd141d | 2012-03-30 15:32:07 +0800 | [diff] [blame] | 305 | should be place |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 306 | */ |
| 307 | NextNodeOffset = FreedNodeOffset; |
| 308 | NextNodePtr = FreedNodePtr; |
| 309 | while (AllocNodeOffset > NextNodeOffset) { |
| 310 | PrevNodeOffset = NextNodeOffset; |
| 311 | if (NextNodePtr->NextNodeOffset == 0) { |
zbao | afd141d | 2012-03-30 15:32:07 +0800 | [diff] [blame] | 312 | break; |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 313 | } |
| 314 | NextNodeOffset = NextNodePtr->NextNodeOffset; |
| 315 | NextNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + NextNodeOffset); |
| 316 | } |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 317 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 318 | /* If deallocated node is adjacent to the next node, |
zbao | afd141d | 2012-03-30 15:32:07 +0800 | [diff] [blame] | 319 | concatenate both nodes |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 320 | */ |
| 321 | if (NextNodeOffset == EndNodeOffset) { |
| 322 | NextNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + NextNodeOffset); |
| 323 | AllocNodePtr->BufferSize += NextNodePtr->BufferSize; |
| 324 | AllocNodePtr->NextNodeOffset = NextNodePtr->NextNodeOffset; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 325 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 326 | NextNodePtr->BufferSize = 0; |
| 327 | NextNodePtr->NextNodeOffset = 0; |
| 328 | } else { |
| 329 | /*AllocNodePtr->NextNodeOffset = FreedNodePtr->NextNodeOffset; */ |
| 330 | AllocNodePtr->NextNodeOffset = NextNodeOffset; |
| 331 | } |
| 332 | /* If deallocated node is adjacent to the previous node, |
zbao | afd141d | 2012-03-30 15:32:07 +0800 | [diff] [blame] | 333 | concatenate both nodes |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 334 | */ |
| 335 | PrevNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + PrevNodeOffset); |
| 336 | EndNodeOffset = PrevNodeOffset + PrevNodePtr->BufferSize; |
| 337 | if (AllocNodeOffset == EndNodeOffset) { |
| 338 | PrevNodePtr->NextNodeOffset = AllocNodePtr->NextNodeOffset; |
| 339 | PrevNodePtr->BufferSize += AllocNodePtr->BufferSize; |
zbao | afd141d | 2012-03-30 15:32:07 +0800 | [diff] [blame] | 340 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 341 | AllocNodePtr->BufferSize = 0; |
| 342 | AllocNodePtr->NextNodeOffset = 0; |
| 343 | } else { |
| 344 | PrevNodePtr->NextNodeOffset = AllocNodeOffset; |
| 345 | } |
| 346 | } |
| 347 | return AGESA_SUCCESS; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | AGESA_STATUS BiosLocateBuffer (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 351 | { |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 352 | UINT32 AllocNodeOffset; |
| 353 | UINT8 *BiosHeapBaseAddr; |
| 354 | BIOS_BUFFER_NODE *AllocNodePtr; |
| 355 | BIOS_HEAP_MANAGER *BiosHeapBasePtr; |
| 356 | AGESA_BUFFER_PARAMS *AllocParams; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 357 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 358 | AllocParams = (AGESA_BUFFER_PARAMS *) ConfigPtr; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 359 | |
zbao | f543c7b | 2012-04-13 13:42:46 +0800 | [diff] [blame] | 360 | BiosHeapBaseAddr = (UINT8 *) GetHeapBase(&(AllocParams->StdHeader)); |
| 361 | BiosHeapBasePtr = (BIOS_HEAP_MANAGER *) BiosHeapBaseAddr; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 362 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 363 | AllocNodeOffset = BiosHeapBasePtr->StartOfAllocatedNodes; |
| 364 | AllocNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + AllocNodeOffset); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 365 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 366 | while (AllocParams->BufferHandle != AllocNodePtr->BufferHandle) { |
| 367 | if (AllocNodePtr->NextNodeOffset == 0) { |
| 368 | AllocParams->BufferPointer = NULL; |
| 369 | AllocParams->BufferLength = 0; |
| 370 | return AGESA_BOUNDS_CHK; |
| 371 | } else { |
| 372 | AllocNodeOffset = AllocNodePtr->NextNodeOffset; |
| 373 | AllocNodePtr = (BIOS_BUFFER_NODE *) (BiosHeapBaseAddr + AllocNodeOffset); |
| 374 | } |
| 375 | } |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 376 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 377 | AllocParams->BufferPointer = (UINT8 *) ((UINT8 *) AllocNodePtr + sizeof (BIOS_BUFFER_NODE)); |
| 378 | AllocParams->BufferLength = AllocNodePtr->BufferSize; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 379 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 380 | return AGESA_SUCCESS; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 381 | |
| 382 | } |
| 383 | |
| 384 | AGESA_STATUS BiosRunFuncOnAp (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 385 | { |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 386 | AGESA_STATUS Status; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 387 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 388 | Status = agesawrapper_amdlaterunaptask (Func, Data, ConfigPtr); |
| 389 | return Status; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | AGESA_STATUS BiosReset (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 393 | { |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 394 | AGESA_STATUS Status; |
| 395 | UINT8 Value; |
| 396 | UINTN ResetType; |
| 397 | AMD_CONFIG_PARAMS *StdHeader; |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 398 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 399 | ResetType = Data; |
| 400 | StdHeader = ConfigPtr; |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 401 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 402 | // |
| 403 | // Perform the RESET based upon the ResetType. In case of |
| 404 | // WARM_RESET_WHENVER and COLD_RESET_WHENEVER, the request will go to |
| 405 | // AmdResetManager. During the critical condition, where reset is required |
| 406 | // immediately, the reset will be invoked directly by writing 0x04 to port |
| 407 | // 0xCF9 (Reset Port). |
| 408 | // |
| 409 | switch (ResetType) { |
zbao | afd141d | 2012-03-30 15:32:07 +0800 | [diff] [blame] | 410 | case WARM_RESET_WHENEVER: |
| 411 | case COLD_RESET_WHENEVER: |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 412 | break; |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 413 | |
zbao | afd141d | 2012-03-30 15:32:07 +0800 | [diff] [blame] | 414 | case WARM_RESET_IMMEDIATELY: |
| 415 | case COLD_RESET_IMMEDIATELY: |
| 416 | Value = 0x06; |
| 417 | LibAmdIoWrite (AccessWidth8, 0xCf9, &Value, StdHeader); |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 418 | break; |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 419 | |
zbao | afd141d | 2012-03-30 15:32:07 +0800 | [diff] [blame] | 420 | default: |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 421 | break; |
| 422 | } |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 423 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 424 | Status = 0; |
| 425 | return Status; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | AGESA_STATUS BiosReadSpd (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 429 | { |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 430 | AGESA_STATUS Status; |
| 431 | Status = AmdMemoryReadSPD (Func, Data, (AGESA_READ_SPD_PARAMS *)ConfigPtr); |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 432 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 433 | return Status; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | AGESA_STATUS BiosDefaultRet (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 437 | { |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 438 | return AGESA_UNSUPPORTED; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 439 | } |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 440 | /* Call the host environment interface to provide a user hook opportunity. */ |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 441 | AGESA_STATUS BiosHookBeforeDQSTraining (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 442 | { |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 443 | return AGESA_SUCCESS; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 444 | } |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 445 | /* Call the host environment interface to provide a user hook opportunity. */ |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 446 | AGESA_STATUS BiosHookBeforeDramInit (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 447 | { |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 448 | AGESA_STATUS Status; |
| 449 | UINTN FcnData; |
| 450 | MEM_DATA_STRUCT *MemData; |
| 451 | UINT32 AcpiMmioAddr; |
| 452 | UINT32 GpioMmioAddr; |
| 453 | UINT8 Data8; |
| 454 | UINT16 Data16; |
| 455 | UINT8 TempData8; |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 456 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 457 | FcnData = Data; |
| 458 | MemData = ConfigPtr; |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 459 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 460 | Status = AGESA_SUCCESS; |
| 461 | /* Get SB MMIO Base (AcpiMmioAddr) */ |
| 462 | WriteIo8 (0xCD6, 0x27); |
| 463 | Data8 = ReadIo8(0xCD7); |
| 464 | Data16 = Data8<<8; |
| 465 | WriteIo8 (0xCD6, 0x26); |
| 466 | Data8 = ReadIo8(0xCD7); |
| 467 | Data16 |= Data8; |
| 468 | AcpiMmioAddr = (UINT32)Data16 << 16; |
| 469 | GpioMmioAddr = AcpiMmioAddr + GPIO_BASE; |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 470 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 471 | Data8 = Read64Mem8(GpioMmioAddr+SB_GPIO_REG178); |
| 472 | Data8 &= ~BIT5; |
| 473 | TempData8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG178); |
| 474 | TempData8 &= 0x03; |
| 475 | TempData8 |= Data8; |
| 476 | Write64Mem8(GpioMmioAddr+SB_GPIO_REG178, TempData8); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 477 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 478 | Data8 |= BIT2+BIT3; |
| 479 | Data8 &= ~BIT4; |
| 480 | TempData8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG178); |
| 481 | TempData8 &= 0x23; |
| 482 | TempData8 |= Data8; |
| 483 | Write64Mem8(GpioMmioAddr+SB_GPIO_REG178, TempData8); |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 484 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 485 | Data8 = Read64Mem8(GpioMmioAddr+SB_GPIO_REG179); |
| 486 | Data8 &= ~BIT5; |
| 487 | TempData8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG179); |
| 488 | TempData8 &= 0x03; |
| 489 | TempData8 |= Data8; |
| 490 | Write64Mem8(GpioMmioAddr+SB_GPIO_REG179, TempData8); |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 491 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 492 | Data8 |= BIT2+BIT3; |
| 493 | Data8 &= ~BIT4; |
| 494 | TempData8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG179); |
| 495 | TempData8 &= 0x23; |
| 496 | TempData8 |= Data8; |
| 497 | Write64Mem8(GpioMmioAddr+SB_GPIO_REG179, TempData8); |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 498 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 499 | switch(MemData->ParameterListPtr->DDR3Voltage){ |
| 500 | case VOLT1_35: |
| 501 | Data8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG178); |
| 502 | Data8 &= ~(UINT8)BIT6; |
| 503 | Write64Mem8(GpioMmioAddr+SB_GPIO_REG178, Data8); |
| 504 | Data8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG179); |
| 505 | Data8 |= (UINT8)BIT6; |
| 506 | Write64Mem8(GpioMmioAddr+SB_GPIO_REG179, Data8); |
| 507 | break; |
| 508 | case VOLT1_25: |
| 509 | Data8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG178); |
| 510 | Data8 &= ~(UINT8)BIT6; |
| 511 | Write64Mem8(GpioMmioAddr+SB_GPIO_REG178, Data8); |
| 512 | Data8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG179); |
| 513 | Data8 &= ~(UINT8)BIT6; |
| 514 | Write64Mem8(GpioMmioAddr+SB_GPIO_REG179, Data8); |
| 515 | break; |
| 516 | case VOLT1_5: |
| 517 | default: |
| 518 | Data8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG178); |
| 519 | Data8 |= (UINT8)BIT6; |
| 520 | Write64Mem8(GpioMmioAddr+SB_GPIO_REG178, Data8); |
| 521 | Data8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG179); |
| 522 | Data8 &= ~(UINT8)BIT6; |
| 523 | Write64Mem8(GpioMmioAddr+SB_GPIO_REG179, Data8); |
| 524 | } |
| 525 | return Status; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 526 | } |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 527 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 528 | /* Call the host environment interface to provide a user hook opportunity. */ |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 529 | AGESA_STATUS BiosHookBeforeDramInitRecovery (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 530 | { |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 531 | return AGESA_SUCCESS; |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 532 | } |
| 533 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 534 | /* Call the host environment interface to provide a user hook opportunity. */ |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 535 | AGESA_STATUS BiosHookBeforeExitSelfRefresh (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 536 | { |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 537 | return AGESA_SUCCESS; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 538 | } |
| 539 | /* PCIE slot reset control */ |
| 540 | AGESA_STATUS BiosGnbPcieSlotReset (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 541 | { |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 542 | AGESA_STATUS Status; |
| 543 | UINTN FcnData; |
| 544 | PCIe_SLOT_RESET_INFO *ResetInfo; |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 545 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 546 | UINT32 GpioMmioAddr; |
| 547 | UINT32 AcpiMmioAddr; |
| 548 | UINT8 Data8; |
| 549 | UINT16 Data16; |
efdesign98 | d7a696d | 2011-09-15 15:24:26 -0600 | [diff] [blame] | 550 | |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 551 | FcnData = Data; |
| 552 | ResetInfo = ConfigPtr; |
| 553 | // Get SB800 MMIO Base (AcpiMmioAddr) |
| 554 | WriteIo8(0xCD6, 0x27); |
| 555 | Data8 = ReadIo8(0xCD7); |
| 556 | Data16=Data8<<8; |
| 557 | WriteIo8(0xCD6, 0x26); |
| 558 | Data8 = ReadIo8(0xCD7); |
| 559 | Data16|=Data8; |
| 560 | AcpiMmioAddr = (UINT32)Data16 << 16; |
| 561 | Status = AGESA_UNSUPPORTED; |
| 562 | GpioMmioAddr = AcpiMmioAddr + GPIO_BASE; |
| 563 | switch (ResetInfo->ResetId) |
| 564 | { |
Jens Rottmann | fa8702c | 2013-02-18 19:40:33 +0100 | [diff] [blame^] | 565 | case 46: // GPIO50 = SBGPIO_PCIE_RST# affects LAN0, LAN1, PCIe slot |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 566 | switch (ResetInfo->ResetControl) { |
zbao | afd141d | 2012-03-30 15:32:07 +0800 | [diff] [blame] | 567 | case AssertSlotReset: |
Jens Rottmann | fa8702c | 2013-02-18 19:40:33 +0100 | [diff] [blame^] | 568 | Data8 = Read64Mem8(GpioMmioAddr+SB_GPIO_REG50); |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 569 | Data8 &= ~(UINT8)BIT6 ; |
Jens Rottmann | fa8702c | 2013-02-18 19:40:33 +0100 | [diff] [blame^] | 570 | Write64Mem8(GpioMmioAddr+SB_GPIO_REG50, Data8); |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 571 | Status = AGESA_SUCCESS; |
| 572 | break; |
zbao | afd141d | 2012-03-30 15:32:07 +0800 | [diff] [blame] | 573 | case DeassertSlotReset: |
Jens Rottmann | fa8702c | 2013-02-18 19:40:33 +0100 | [diff] [blame^] | 574 | Data8 = Read64Mem8(GpioMmioAddr+SB_GPIO_REG50); |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 575 | Data8 |= BIT6 ; |
Jens Rottmann | fa8702c | 2013-02-18 19:40:33 +0100 | [diff] [blame^] | 576 | Write64Mem8 (GpioMmioAddr+SB_GPIO_REG50, Data8); |
Marc Jones | 36abff1 | 2011-11-07 23:26:14 -0700 | [diff] [blame] | 577 | Status = AGESA_SUCCESS; |
| 578 | break; |
| 579 | } |
| 580 | break; |
| 581 | } |
| 582 | return Status; |
Frank Vibrans | 69da1b6 | 2011-02-14 19:04:45 +0000 | [diff] [blame] | 583 | } |