diff options
author | zbao <fishbaozi@gmail.com> | 2012-07-02 14:19:14 +0800 |
---|---|---|
committer | Patrick Georgi <patrick@georgi-clan.de> | 2012-07-03 09:36:35 +0200 |
commit | 7d94cf93eec15dfb8eef9cd044fe39319d4ee9bc (patch) | |
tree | b0b385455992f0ad3ca6dbbd3266a7a386a80d4f /src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug | |
parent | 78efc4c36c68b51b3e73acdb721a12ec23ed0369 (diff) |
AGESA F15tn: AMD family15 AGESA code for Trinity
AMD AGESA code for trinity.
Change-Id: I847a54b15e8ce03ad5dbc17b95ee6771a9da0592
Signed-off-by: Zheng Bao <zheng.bao@amd.com>
Signed-off-by: zbao <fishbaozi@gmail.com>
Reviewed-on: http://review.coreboot.org/1155
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <patrick@georgi-clan.de>
Diffstat (limited to 'src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug')
8 files changed, 2648 insertions, 0 deletions
diff --git a/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsDebug.c b/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsDebug.c new file mode 100644 index 0000000000..24d64b3fc0 --- /dev/null +++ b/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsDebug.c @@ -0,0 +1,229 @@ +/** + * @file + * + * AMD Integrated Debug Debug_library Routines + * + * Contains AMD AGESA debug macros and library functions + * + * @xrefitem bom "File Content Label" "Release Content" + * @e project: AGESA + * @e sub-project: IDS + * @e \$Revision: 63552 $ @e \$Date: 2011-12-26 19:46:05 -0600 (Mon, 26 Dec 2011) $ + */ +/***************************************************************************** + * Copyright 2008 - 2012 ADVANCED MICRO DEVICES, INC. All Rights Reserved. + * + * AMD is granting you permission to use this software (the Materials) + * pursuant to the terms and conditions of your Software License Agreement + * with AMD. This header does *NOT* give you permission to use the Materials + * or any rights under AMD's intellectual property. Your use of any portion + * of these Materials shall constitute your acceptance of those terms and + * conditions. If you do not agree to the terms and conditions of the Software + * License Agreement, please do not use any portion of these Materials. + * + * CONFIDENTIALITY: The Materials and all other information, identified as + * confidential and provided to you by AMD shall be kept confidential in + * accordance with the terms and conditions of the Software License Agreement. + * + * LIMITATION OF LIABILITY: THE MATERIALS AND ANY OTHER RELATED INFORMATION + * PROVIDED TO YOU BY AMD ARE PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTY OF ANY KIND, INCLUDING BUT NOT LIMITED TO WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, TITLE, FITNESS FOR ANY PARTICULAR PURPOSE, + * OR WARRANTIES ARISING FROM CONDUCT, COURSE OF DEALING, OR USAGE OF TRADE. + * IN NO EVENT SHALL AMD OR ITS LICENSORS BE LIABLE FOR ANY DAMAGES WHATSOEVER + * (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS + * INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF AMD'S NEGLIGENCE, + * GROSS NEGLIGENCE, THE USE OF OR INABILITY TO USE THE MATERIALS OR ANY OTHER + * RELATED INFORMATION PROVIDED TO YOU BY AMD, EVEN IF AMD HAS BEEN ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGES. BECAUSE SOME JURISDICTIONS PROHIBIT THE + * EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES, + * THE ABOVE LIMITATION MAY NOT APPLY TO YOU. + * + * AMD does not assume any responsibility for any errors which may appear in + * the Materials or any other related information provided to you by AMD, or + * result from use of the Materials or any related information. + * + * You agree that you will not reverse engineer or decompile the Materials. + * + * NO SUPPORT OBLIGATION: AMD is not obligated to furnish, support, or make any + * further information, software, technical information, know-how, or show-how + * available to you. Additionally, AMD retains the right to modify the + * Materials at any time, without notice, and is not obligated to provide such + * modified Materials to you. + * + * U.S. GOVERNMENT RESTRICTED RIGHTS: The Materials are provided with + * "RESTRICTED RIGHTS." Use, duplication, or disclosure by the Government is + * subject to the restrictions as set forth in FAR 52.227-14 and + * DFAR252.227-7013, et seq., or its successor. Use of the Materials by the + * Government constitutes acknowledgement of AMD's proprietary rights in them. + * + * EXPORT ASSURANCE: You agree and certify that neither the Materials, nor any + * direct product thereof will be exported directly or indirectly, into any + * country prohibited by the United States Export Administration Act and the + * regulations thereunder, without the required authorization from the U.S. + * government nor will be used for any purpose prohibited by the same. + ****************************************************************************** + */ + + /*---------------------------------------------------------------------------------------- + * M O D U L E S U S E D + *---------------------------------------------------------------------------------------- + */ +#include "AGESA.h" +#include "Ids.h" +#include "IdsLib.h" +#include "amdlib.h" +#include "AMD.h" +#include "heapManager.h" +#include "cpuRegisters.h" +#include "cpuServices.h" +#include "GeneralServices.h" +#include "IdsDebugPrint.h" +#include "IdsDpHdtout.h" +#include "Filecode.h" +CODE_GROUP (G1_PEICC) +RDATA_GROUP (G1_PEICC) + +#define FILECODE PROC_IDS_DEBUG_IDSDEBUG_FILECODE + +/*--------------------------------------------------------------------------------------*/ +/** + * IDS back-end code for AGESA_TESTPOINT + * + * @param[in] TestPoint Progress indicator value, see @ref AGESA_TP + * @param[in,out] StdHeader The Pointer of AGESA Header + * + **/ +/*--------------------------------------------------------------------------------------*/ +VOID +IdsAgesaTestPoint ( + IN AGESA_TP TestPoint, + IN OUT AMD_CONFIG_PARAMS *StdHeader + ) +{ + LibAmdIoWrite (AccessWidth8, IDS_DEBUG_PORT, &TestPoint, StdHeader); +} + +/** + * + * HDT out Function for Assert. + * + * fire a HDTOUT Command of assert to let hdtout script do corresponding things. + * + * @param[in,out] FileCode FileCode of the line + * + **/ +#if 0 +VOID +AmdIdsDebugPrintAssert ( + IN UINT32 FileCode + ) +{ + //TODO:if (AmdIdsHdtOutSupport ()) { + // IdsOutPort (HDTOUT_ASSERT, FileCode, 0); + //} +} +#endif + +/** + * IDS Backend Function for ASSERT + * + * Halt execution with stop code display. Stop Code is displayed on port 80, with rotation so that + * it is visible on 8, 16, or 32 bit display. The stop code is alternated with 0xDEAD on the display, + * to help distinguish the stop code from a post code loop. + * Additional features may be available if using simulation. + * + * @param[in] FileCode File code(define in FILECODE.h) mix with assert Line num. + * + * @retval TRUE No error + **/ +BOOLEAN +IdsAssert ( + IN UINT32 FileCode + ) +{ + UINT32 file; + UINT32 line; + + file = (FileCode >> 16); + line = (FileCode & 0xFFFF); + IDS_HDT_CONSOLE (MAIN_FLOW, "ASSERT on File[%x] Line[%x]\n", (UINTN) file, (UINTN) line); + IDS_HDT_CONSOLE_FLUSH_BUFFER (NULL); + IDS_HDT_CONSOLE_ASSERT (FileCode); + //IdsErrorStop (FileCode); + return TRUE; +} + +/** + * IDS Backend Function for Memory timeout control + * + * This function is used to override Memory timeout control. + * + * @param[in,out] DataPtr The Pointer of UINT8. + * + **/ +VOID +IdsMemTimeOut ( + IN OUT VOID *DataPtr + ) +{ +//TODO: UINTN i; +// +// IDS_DEBUG_PRINT **DebugPrintList; +// +// GetDebugPrintList (&DebugPrintList); +// +// for (i = 0; DebugPrintList[i] != NULL; i++) { +// if (DebugPrintList[i]->support ()) { +// // Turn timeout off if any Debug service is on +// *((UINT8 *)DataPtr) = (UINT8)0; +// } +// } +} + +/** + * + * IDS Debug Function to check the sentinels are intact + * + * This function complete heap walk and check to be performed at any time. + * + * @param[in] StdHeader Config handle for library and services. + * + * @retval TRUE No error + * + **/ +BOOLEAN +AmdHeapIntactCheck ( + IN AMD_CONFIG_PARAMS *StdHeader + ) +{ + return TRUE; +} + +/** + * Check for CAR Corruption, the performance monitor number three programed to log the CAR Corruption. + * Check to see if control register is enabled and then check the preformance counter and stop the system by executing + * IDS_ERROR_TRAP if counter has any value other than zero. + * + * @param[in,out] StdHeader The Pointer of Standard Header. + * + * + **/ +VOID +IdsCarCorruptionCheck ( + IN OUT AMD_CONFIG_PARAMS *StdHeader + ) +{ + + UINT64 Perf_Msr; + + LibAmdMsrRead (MSR_PERF_CONTROL3, (UINT64*)&Perf_Msr, StdHeader); + if ((Perf_Msr & PERF_RESERVE_BIT_MASK) == PERF_CAR_CORRUPTION_EVENT) { + LibAmdMsrRead (MSR_PERF_COUNTER3, (UINT64*)&Perf_Msr, StdHeader); + if ((Perf_Msr != 0)) { + IDS_ERROR_TRAP; + } + } +} + + diff --git a/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsDebugPrint.c b/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsDebugPrint.c new file mode 100644 index 0000000000..67ec5974c2 --- /dev/null +++ b/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsDebugPrint.c @@ -0,0 +1,678 @@ +/** + * @file + * + * AMD Integrated Debug Print Routines + * + * Contains all functions related to IDS Debug Print + * + * @xrefitem bom "File Content Label" "Release Content" + * @e project: AGESA + * @e sub-project: IDS + * @e \$Revision: 63425 $ @e \$Date: 2011-12-22 11:24:10 -0600 (Thu, 22 Dec 2011) $ + */ +/***************************************************************************** + * Copyright 2008 - 2012 ADVANCED MICRO DEVICES, INC. All Rights Reserved. + * + * AMD is granting you permission to use this software (the Materials) + * pursuant to the terms and conditions of your Software License Agreement + * with AMD. This header does *NOT* give you permission to use the Materials + * or any rights under AMD's intellectual property. Your use of any portion + * of these Materials shall constitute your acceptance of those terms and + * conditions. If you do not agree to the terms and conditions of the Software + * License Agreement, please do not use any portion of these Materials. + * + * CONFIDENTIALITY: The Materials and all other information, identified as + * confidential and provided to you by AMD shall be kept confidential in + * accordance with the terms and conditions of the Software License Agreement. + * + * LIMITATION OF LIABILITY: THE MATERIALS AND ANY OTHER RELATED INFORMATION + * PROVIDED TO YOU BY AMD ARE PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTY OF ANY KIND, INCLUDING BUT NOT LIMITED TO WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, TITLE, FITNESS FOR ANY PARTICULAR PURPOSE, + * OR WARRANTIES ARISING FROM CONDUCT, COURSE OF DEALING, OR USAGE OF TRADE. + * IN NO EVENT SHALL AMD OR ITS LICENSORS BE LIABLE FOR ANY DAMAGES WHATSOEVER + * (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS + * INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF AMD'S NEGLIGENCE, + * GROSS NEGLIGENCE, THE USE OF OR INABILITY TO USE THE MATERIALS OR ANY OTHER + * RELATED INFORMATION PROVIDED TO YOU BY AMD, EVEN IF AMD HAS BEEN ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGES. BECAUSE SOME JURISDICTIONS PROHIBIT THE + * EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES, + * THE ABOVE LIMITATION MAY NOT APPLY TO YOU. + * + * AMD does not assume any responsibility for any errors which may appear in + * the Materials or any other related information provided to you by AMD, or + * result from use of the Materials or any related information. + * + * You agree that you will not reverse engineer or decompile the Materials. + * + * NO SUPPORT OBLIGATION: AMD is not obligated to furnish, support, or make any + * further information, software, technical information, know-how, or show-how + * available to you. Additionally, AMD retains the right to modify the + * Materials at any time, without notice, and is not obligated to provide such + * modified Materials to you. + * + * U.S. GOVERNMENT RESTRICTED RIGHTS: The Materials are provided with + * "RESTRICTED RIGHTS." Use, duplication, or disclosure by the Government is + * subject to the restrictions as set forth in FAR 52.227-14 and + * DFAR252.227-7013, et seq., or its successor. Use of the Materials by the + * Government constitutes acknowledgement of AMD's proprietary rights in them. + * + * EXPORT ASSURANCE: You agree and certify that neither the Materials, nor any + * direct product thereof will be exported directly or indirectly, into any + * country prohibited by the United States Export Administration Act and the + * regulations thereunder, without the required authorization from the U.S. + * government nor will be used for any purpose prohibited by the same. + ****************************************************************************** + */ + + /*---------------------------------------------------------------------------------------- + * M O D U L E S U S E D + *---------------------------------------------------------------------------------------- + */ +#include "AGESA.h" +#include "Ids.h" +#include "IdsLib.h" +#include "amdlib.h" +#include "IdsDebugPrint.h" +#include "Filecode.h" +CODE_GROUP (G1_PEICC) +RDATA_GROUP (G1_PEICC) + +#define FILECODE PROC_IDS_DEBUG_IDSDEBUGPRINT_FILECODE + +// +// Also support coding convention rules for var arg macros +// +#define _INT_SIZE_OF(n) ((sizeof (n) + sizeof (UINTN) - 1) &~(sizeof (UINTN) - 1)) +typedef CHAR8 *VA_LIST; +#define VA_START(ap, v) (ap = (VA_LIST) & (v) + _INT_SIZE_OF (v)) +#define VA_ARG(ap, t) (*(t *) ((ap += _INT_SIZE_OF (t)) - _INT_SIZE_OF (t))) +#define VA_END(ap) (ap = (VA_LIST) 0) + +#define LEFT_JUSTIFY 0x01 +#define PREFIX_SIGN 0x02 +#define PREFIX_BLANK 0x04 +#define COMMA_TYPE 0x08 +#define LONG_TYPE 0x10 +#define PREFIX_ZERO 0x20 + +#define MAX_LOCAL_BUFFER_SIZE 512 +#define BUFFER_OVERFLOW 0xFFFF + +/** + * Check If any print service is enabled. + * + * @param[in] DebugPrintList The Pointer to print service list + * + * @retval TRUE At least on print service is enabled + * @retval FALSE All print service is disabled + * + **/ +STATIC BOOLEAN +AmdIdsDebugPrintCheckSupportAll ( + IN IDS_DEBUG_PRINT **DebugPrintList + ) +{ + BOOLEAN IsSupported; + UINTN i; + IsSupported = FALSE; + for (i = 0; DebugPrintList[i] != NULL; i++) { + if (DebugPrintList[i]->support ()) { + IsSupported = TRUE; + } + } + return IsSupported; +} + +/** + * Parses flag and width information from theFormat string and returns the next index + * into the Format string that needs to be parsed. See file headed for details of Flag and Width. + * + * @param[in] Format Current location in the AvSPrint format string. + * @param[out] Flags Returns flags + * @param[out] Width Returns width of element + * @param[out] Marker Vararg list that may be partially consumed and returned. + * + * @retval Pointer indexed into the Format string for all the information parsed by this routine. + * + **/ +STATIC CHAR8 * +GetFlagsAndWidth ( + IN CHAR8 *Format, + OUT UINTN *Flags, + OUT UINTN *Width, + IN OUT VA_LIST *Marker + ) +{ + UINTN Count; + BOOLEAN Done; + + *Flags = 0; + *Width = 0; + for (Done = FALSE; !Done; ) { + Format++; + + switch (*Format) { + + case '-': /* ' - ' */ + *Flags |= LEFT_JUSTIFY; + break; + case '+': /* ' + ' */ + *Flags |= PREFIX_SIGN; + break; + case ' ': + *Flags |= PREFIX_BLANK; + break; + case ',': /* ', ' */ + *Flags |= COMMA_TYPE; + break; + case 'L': + case 'l': + *Flags |= LONG_TYPE; + break; + + case '*': + *Width = VA_ARG (*Marker, UINTN); + break; + + case '0': + *Flags |= PREFIX_ZERO; + break; + + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + Count = 0; + do { + Count = (Count * 10) + *Format - '0'; + Format++; + } while ((*Format >= '0') && (*Format <= '9')); + Format--; + *Width = Count; + break; + + default: + Done = TRUE; + } + } + return Format; +} + +CHAR8 STATIC HexStr[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; +extern CONST IDS_DEBUG_PRINT* ROMDATA IdsDebugPrint[]; + +/** + * + * @param[in,out] Value - Hex value to convert to a string in Buffer. + * + * + */ +VOID +GetDebugPrintList ( + IN OUT CONST IDS_DEBUG_PRINT ***pIdsDebugPrintListPtr + ) +{ + *pIdsDebugPrintListPtr = &IdsDebugPrint[0]; +} + +/** + * + * @param[in,out] Buffer Location to place ascii hex string of Value. + * @param[in] Value - Hex value to convert to a string in Buffer. + * @param[in] Flags - Flags to use in printing Hex string, see file header for details. + * @param[in] Width - Width of hex value. + * @param[in,out] BufferSize - Size of input buffer + * + * @retval Number of characters printed. + **/ + +STATIC UINTN +ValueToHexStr ( + IN OUT CHAR8 *Buffer, + IN UINT64 Value, + IN UINTN Flags, + IN UINTN Width, + IN OUT UINTN *BufferSize + ) +{ + CHAR8 TempBuffer[30]; + CHAR8 *TempStr; + CHAR8 Prefix; + CHAR8 *BufferPtr; + UINTN Count; + UINTN Index; + + TempStr = TempBuffer; + BufferPtr = Buffer; + // + // Count starts at one since we will null terminate. Each iteration of the + // loop picks off one nibble. Oh yea TempStr ends up backwards + // + Count = 0; + do { + *(TempStr++) = HexStr[Value & 0x0f]; + Value >>= 4; + Count++; + } while (Value != 0); + + if (Flags & PREFIX_ZERO) { + Prefix = '0'; + } else if (!(Flags & LEFT_JUSTIFY)) { + Prefix = ' '; + } else { + Prefix = 0x00; + } + for (Index = Count; Index < Width; Index++) { + *(TempStr++) = Prefix; + } + + // + // Reverse temp string into Buffer. + // + while (TempStr != TempBuffer) { + (*BufferSize)--; + if (*BufferSize == 0) { + return BUFFER_OVERFLOW; + } + *(BufferPtr++) = *(--TempStr); + } + + *BufferPtr = 0; + return Index; +} + +/** + * Prints a Value as a decimal number in Buffer + * + * @param[in] Buffer Location to place ascii decimal number string of Value. + * @param[in] Value Decimal value to convert to a string in Buffer. + * @param[in] Flags Flags to use in printing decimal string, see file header for details. + * @param[in,out] BufferSize Size of input buffer + * + * @retval Number of characters printed. + * +**/ + +STATIC UINTN +ValueToString ( + IN OUT CHAR8 *Buffer, + IN INT32 Value, + IN UINTN Flags, + IN OUT UINTN *BufferSize + ) +{ + CHAR8 TempBuffer[30]; + CHAR8 *TempStr; + CHAR8 *BufferPtr; + UINTN Count; + UINTN Remainder; + + ASSERT (*BufferSize); + TempStr = TempBuffer; + BufferPtr = Buffer; + Count = 0; + + if (Value < 0) { + (*BufferSize)--; + if (*BufferSize == 0) { + return BUFFER_OVERFLOW; + } + *(BufferPtr++) = '-'; /* ' - ' */ + Value = - Value; + Count++; + } + + do { + Remainder = Value % 10; + Value /= 10; + *(TempStr++) = (CHAR8)(Remainder + '0'); + Count++; + if ((Flags & COMMA_TYPE) == COMMA_TYPE) { + if (Count % 3 == 0) { + *(TempStr++) = ','; + } + } + } while (Value != 0); + + // + // Reverse temp string into Buffer. + // + while (TempStr != TempBuffer) { + (*BufferSize)--; + if (*BufferSize == 0) { + return BUFFER_OVERFLOW; + } + *(BufferPtr++) = *(--TempStr); + } + + *BufferPtr = 0; + return Count; +} + +/** + * Worker function for print string to buffer + * + * @param[in] Flag - filter flag + * @param[in] *Format - format string + * @param[in] Marker - Variable parameter + * @param[in] Buffer - Point to input buffer + * @param[in] BufferSize - Buffer size + * @param[out] OutputStringLen - output string length, include '\0' at the end + * + * @retval IDS_DEBUG_PRINT_SUCCESS succeed + * @retval IDS_DEBUG_PRINT_BUFFER_OVERFLOW input buffer overflow +**/ +STATIC IDS_DEBUG_PRINT_STATUS +AmdIdsDebugPrintWorker ( + IN CONST CHAR8 *Format, + IN VA_LIST Marker, + IN CHAR8 *Buffer, + IN UINTN BufferSize, + OUT UINTN *OutputStringLen + ) +{ + UINTN Index; + UINTN Length; + UINTN Flags; + UINTN Width; + UINT64 Value; + CHAR8 *AsciiStr; + + //Init the default Value + Index = 0; + // + // Process format string + // + for (; (*Format != '\0') && (BufferSize > 0); Format++) { + if (*Format != '%') { + Buffer[Index++] = *Format; + BufferSize--; + } else { + Format = GetFlagsAndWidth ((CHAR8 *)Format, &Flags, &Width, &Marker); + switch (*Format) { + case 'X': + Flags |= PREFIX_ZERO; + Width = sizeof (UINT64) * 2; + // + // break skipped on purpose + // + case 'x': + if ((Flags & LONG_TYPE) == LONG_TYPE) { + Value = VA_ARG (Marker, UINT64); + } else { + Value = VA_ARG (Marker, UINTN); + } + Length = ValueToHexStr (&Buffer[Index], Value, Flags, Width, &BufferSize); + if (Length != BUFFER_OVERFLOW) { + Index += Length; + } else { + return IDS_DEBUG_PRINT_BUFFER_OVERFLOW; + } + break; + + case 'd': + Value = (UINTN)VA_ARG (Marker, UINT32); + Length = ValueToString (&Buffer[Index], (UINT32)Value, Flags, &BufferSize); + if (Length != BUFFER_OVERFLOW) { + Index += Length; + } else { + return IDS_DEBUG_PRINT_BUFFER_OVERFLOW; + } + + break; + + case 's': + case 'S': + AsciiStr = (CHAR8 *)VA_ARG (Marker, CHAR8 *); + while (*AsciiStr != '\0') { + BufferSize--; + if (BufferSize == 0) { + return IDS_DEBUG_PRINT_BUFFER_OVERFLOW; + } + Buffer[Index++] = *AsciiStr++; + } + break; + + case 'c': + BufferSize--; + if (BufferSize == 0) { + return IDS_DEBUG_PRINT_BUFFER_OVERFLOW; + } + Buffer[Index++] = (CHAR8)VA_ARG (Marker, UINTN); + break; + + case 'v': + ASSERT (FALSE); // %v is no longer supported + break; + + case '%': + BufferSize--; + if (BufferSize == 0) { + return IDS_DEBUG_PRINT_BUFFER_OVERFLOW; + } + Buffer[Index++] = *Format; + break; + + default: + // + // if the type is unknown print it to the screen + // + BufferSize--; + if (BufferSize == 0) { + return IDS_DEBUG_PRINT_BUFFER_OVERFLOW; + } + Buffer[Index++] = '%'; + + BufferSize--; + if (BufferSize == 0) { + return IDS_DEBUG_PRINT_BUFFER_OVERFLOW; + } + Buffer[Index++] = *Format; + break; + } + } + } + if (BufferSize == 0) { + return IDS_DEBUG_PRINT_BUFFER_OVERFLOW; + } + //Mark the end of word + Buffer[Index] = 0; + *OutputStringLen = Index; + return IDS_DEBUG_PRINT_SUCCESS; +} + + +/** + * Insert Overflow warning to the tail of output + * + * @param[in] Buffer - Point to input buffer + * @param[in] BufferSize - Buffer size + * +**/ +STATIC VOID +InsertOverflowWarningMessage ( + IN CHAR8 *Buffer, + IN UINTN BufferSize + ) +{ + CHAR8 *Destination; + CHAR8 WarningString[] = "\n#BUFFER OVERFLOW#\n"; + AMD_CONFIG_PARAMS StdHeader; + + Destination = Buffer + BufferSize - sizeof (WarningString); + LibAmdMemCopy (Destination, WarningString, sizeof (WarningString), &StdHeader); +} + +/** + * Process debug string + * + * @param[in] Flag - filter flag + * @param[in] *Format - format string + * @param[in] Marker - Variable parameter + * +**/ +STATIC VOID +AmdIdsDebugPrintProcess ( + IN UINT64 Flag, + IN CONST CHAR8 *Format, + IN VA_LIST Marker + ) +{ + UINT64 Filter; + CHAR8 LocalBuffer[MAX_LOCAL_BUFFER_SIZE]; + UINTN OutPutStringLen; + IDS_DEBUG_PRINT **DebugPrintList; + IDS_DEBUG_PRINT_PRIVATE_DATA debugPrintPrivate; + UINT8 i; + + + GetDebugPrintList ((CONST IDS_DEBUG_PRINT ***)&DebugPrintList); + if (AmdIdsDebugPrintCheckSupportAll (DebugPrintList)) { + if (AmdIdsDebugPrintWorker (Format, Marker, &LocalBuffer[0], sizeof (LocalBuffer), &OutPutStringLen) == IDS_DEBUG_PRINT_BUFFER_OVERFLOW) { + InsertOverflowWarningMessage (&LocalBuffer[0], sizeof (LocalBuffer)); + OutPutStringLen = sizeof (LocalBuffer); + } + + //init input + debugPrintPrivate.saveContext = FALSE; + + for (i = 0; DebugPrintList[i] != NULL; i++) { + if (DebugPrintList[i]->support ()) { + Filter = IDS_DEBUG_PRINT_MASK; + //Get Customize filter (Option) + DebugPrintList[i]->customfilter (&Filter); + if (Flag & Filter) { + //Init Private Date (Option) + DebugPrintList[i]->InitPrivateData (Flag, &debugPrintPrivate); + //Print Physical Layer + DebugPrintList[i]->print (&LocalBuffer[0], OutPutStringLen, &debugPrintPrivate); + } + } + } + } +} + +/** + * Prints string to debug host like printf in C + * + * @param[in] Flag - filter flag + * @param[in] *Format - format string + * @param[in] ... Variable parameter + * +**/ +VOID +AmdIdsDebugPrint ( + IN UINT64 Flag, + IN CONST CHAR8 *Format, + IN ... + ) +{ + VA_LIST Marker; + VA_START (Marker, Format); //init marker to 1st dynamic parameters. + AmdIdsDebugPrintProcess (Flag, Format, Marker); + VA_END (Marker); +} + +/** + * Prints memory debug strings + * + * @param[in] *Format - format string + * @param[in] ... Variable parameter + * +**/ +VOID +AmdIdsDebugPrintMem ( + IN CHAR8 *Format, + IN ... + ) +{ + VA_LIST Marker; + VA_START (Marker, Format); //init marker to 1st dynamic parameters. + AmdIdsDebugPrintProcess (MEM_FLOW, Format, Marker); + VA_END (Marker); +} + +/** + * Prints CPU debug strings + * + * @param[in] *Format - format string + * @param[in] ... Variable parameter + * +**/ +VOID +AmdIdsDebugPrintCpu ( + IN CHAR8 *Format, + IN ... + ) +{ + VA_LIST Marker; + VA_START (Marker, Format); //init marker to 1st dynamic parameters. + AmdIdsDebugPrintProcess (CPU_TRACE, Format, Marker); + VA_END (Marker); +} + + +/** + * Prints HT debug strings + * + * @param[in] *Format - format string + * @param[in] ... Variable parameter + * +**/ +VOID +AmdIdsDebugPrintHt ( + IN CHAR8 *Format, + IN ... + ) +{ + VA_LIST Marker; + VA_START (Marker, Format); //init marker to 1st dynamic parameters. + AmdIdsDebugPrintProcess (HT_TRACE, Format, Marker); + VA_END (Marker); +} + + +/** + * Prints GNB debug strings + * + * @param[in] *Format - format string + * @param[in] ... Variable parameter + * +**/ +VOID +AmdIdsDebugPrintGnb ( + IN CHAR8 *Format, + IN ... + ) +{ + VA_LIST Marker; + VA_START (Marker, Format); //init marker to 1st dynamic parameters. + AmdIdsDebugPrintProcess (GNB_TRACE, Format, Marker); + VA_END (Marker); +} + +/** + * Prints debug strings in any condition + * + * @param[in] *Format - format string + * @param[in] ... Variable parameter + * +**/ +VOID +AmdIdsDebugPrintAll ( + IN CHAR8 *Format, + IN ... + ) +{ + VA_LIST Marker; + VA_START (Marker, Format); //init marker to 1st dynamic parameters. + AmdIdsDebugPrintProcess (TRACE_MASK_ALL, Format, Marker); + VA_END (Marker); +} + diff --git a/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsDebugPrint.h b/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsDebugPrint.h new file mode 100644 index 0000000000..5061426cd0 --- /dev/null +++ b/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsDebugPrint.h @@ -0,0 +1,105 @@ +/* $NoKeywords:$ */ +/** + * @file + * + * AMD Integrated Debug Print Routines + * + * Contains all functions related to IDS Debug Print + * + * @xrefitem bom "File Content Label" "Release Content" + * @e project: AGESA + * @e sub-project: IDS + * @e \$Revision: 63425 $ @e \$Date: 2011-12-22 11:24:10 -0600 (Thu, 22 Dec 2011) $ + */ +/***************************************************************************** + * + * Copyright 2008 - 2012 ADVANCED MICRO DEVICES, INC. All Rights Reserved. + * + * AMD is granting you permission to use this software (the Materials) + * pursuant to the terms and conditions of your Software License Agreement + * with AMD. This header does *NOT* give you permission to use the Materials + * or any rights under AMD's intellectual property. Your use of any portion + * of these Materials shall constitute your acceptance of those terms and + * conditions. If you do not agree to the terms and conditions of the Software + * License Agreement, please do not use any portion of these Materials. + * + * CONFIDENTIALITY: The Materials and all other information, identified as + * confidential and provided to you by AMD shall be kept confidential in + * accordance with the terms and conditions of the Software License Agreement. + * + * LIMITATION OF LIABILITY: THE MATERIALS AND ANY OTHER RELATED INFORMATION + * PROVIDED TO YOU BY AMD ARE PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTY OF ANY KIND, INCLUDING BUT NOT LIMITED TO WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, TITLE, FITNESS FOR ANY PARTICULAR PURPOSE, + * OR WARRANTIES ARISING FROM CONDUCT, COURSE OF DEALING, OR USAGE OF TRADE. + * IN NO EVENT SHALL AMD OR ITS LICENSORS BE LIABLE FOR ANY DAMAGES WHATSOEVER + * (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS + * INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF AMD'S NEGLIGENCE, + * GROSS NEGLIGENCE, THE USE OF OR INABILITY TO USE THE MATERIALS OR ANY OTHER + * RELATED INFORMATION PROVIDED TO YOU BY AMD, EVEN IF AMD HAS BEEN ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGES. BECAUSE SOME JURISDICTIONS PROHIBIT THE + * EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES, + * THE ABOVE LIMITATION MAY NOT APPLY TO YOU. + * + * AMD does not assume any responsibility for any errors which may appear in + * the Materials or any other related information provided to you by AMD, or + * result from use of the Materials or any related information. + * + * You agree that you will not reverse engineer or decompile the Materials. + * + * NO SUPPORT OBLIGATION: AMD is not obligated to furnish, support, or make any + * further information, software, technical information, know-how, or show-how + * available to you. Additionally, AMD retains the right to modify the + * Materials at any time, without notice, and is not obligated to provide such + * modified Materials to you. + * + * U.S. GOVERNMENT RESTRICTED RIGHTS: The Materials are provided with + * "RESTRICTED RIGHTS." Use, duplication, or disclosure by the Government is + * subject to the restrictions as set forth in FAR 52.227-14 and + * DFAR252.227-7013, et seq., or its successor. Use of the Materials by the + * Government constitutes acknowledgement of AMD's proprietary rights in them. + * + * EXPORT ASSURANCE: You agree and certify that neither the Materials, nor any + * direct product thereof will be exported directly or indirectly, into any + * country prohibited by the United States Export Administration Act and the + * regulations thereunder, without the required authorization from the U.S. + * government nor will be used for any purpose prohibited by the same. + * + ***************************************************************************/ + +#ifndef _IDS_DEBUGPRINT_H_ +#define _IDS_DEBUGPRINT_H_ + +/// return status for debug print +typedef enum { + IDS_DEBUG_PRINT_SUCCESS = 0, ///< success + IDS_DEBUG_PRINT_BUFFER_OVERFLOW, ///< Bufer overflow +} IDS_DEBUG_PRINT_STATUS; + +/// Private datas for debug print +typedef struct _IDS_DEBUG_PRINT_PRIVATE_DATA { + BOOLEAN saveContext; /// save context +} IDS_DEBUG_PRINT_PRIVATE_DATA; + +typedef BOOLEAN (*PF_IDS_DEBUG_PRINT_SUPPORT) (VOID); +typedef BOOLEAN (*PF_IDS_DEBUG_PRINT_FILTER) (UINT64 *Filter); +typedef VOID (*PF_IDS_DEBUG_PRINT_PRINT) (CHAR8 *Buffer, UINTN BufferSize, IDS_DEBUG_PRINT_PRIVATE_DATA *debugPrintPrivate); +typedef VOID (*PF_IDS_DEBUG_INIT_PRIVATE_DATA) (UINT64 flag, IDS_DEBUG_PRINT_PRIVATE_DATA *debugPrintPrivate); + +/// Debug print Hw layer service class +typedef struct _IDS_DEBUG_PRINT { + PF_IDS_DEBUG_PRINT_SUPPORT support; ///Check if support + PF_IDS_DEBUG_PRINT_FILTER customfilter; ///Get if any customize filters + PF_IDS_DEBUG_INIT_PRIVATE_DATA InitPrivateData; ///Init private data + PF_IDS_DEBUG_PRINT_PRINT print; ///Print data to Hw layer +} IDS_DEBUG_PRINT; + + +VOID +GetDebugPrintList ( + IN OUT CONST IDS_DEBUG_PRINT ***pIdsDebugPrintListPtr + ); + + +#endif //_IDS_DEBUGPRINT_H_ + diff --git a/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsDpHdtout.c b/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsDpHdtout.c new file mode 100644 index 0000000000..bb180cefb9 --- /dev/null +++ b/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsDpHdtout.c @@ -0,0 +1,778 @@ +/** + * @file + * + * AMD Integrated Debug Debug_library Routines + * + * Contains all functions related to HDTOUT + * + * @xrefitem bom "File Content Label" "Release Content" + * @e project: AGESA + * @e sub-project: IDS + * @e \$Revision: 63688 $ @e \$Date: 2012-01-03 21:18:53 -0600 (Tue, 03 Jan 2012) $ + */ +/***************************************************************************** + * Copyright 2008 - 2012 ADVANCED MICRO DEVICES, INC. All Rights Reserved. + * + * AMD is granting you permission to use this software (the Materials) + * pursuant to the terms and conditions of your Software License Agreement + * with AMD. This header does *NOT* give you permission to use the Materials + * or any rights under AMD's intellectual property. Your use of any portion + * of these Materials shall constitute your acceptance of those terms and + * conditions. If you do not agree to the terms and conditions of the Software + * License Agreement, please do not use any portion of these Materials. + * + * CONFIDENTIALITY: The Materials and all other information, identified as + * confidential and provided to you by AMD shall be kept confidential in + * accordance with the terms and conditions of the Software License Agreement. + * + * LIMITATION OF LIABILITY: THE MATERIALS AND ANY OTHER RELATED INFORMATION + * PROVIDED TO YOU BY AMD ARE PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTY OF ANY KIND, INCLUDING BUT NOT LIMITED TO WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, TITLE, FITNESS FOR ANY PARTICULAR PURPOSE, + * OR WARRANTIES ARISING FROM CONDUCT, COURSE OF DEALING, OR USAGE OF TRADE. + * IN NO EVENT SHALL AMD OR ITS LICENSORS BE LIABLE FOR ANY DAMAGES WHATSOEVER + * (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS + * INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF AMD'S NEGLIGENCE, + * GROSS NEGLIGENCE, THE USE OF OR INABILITY TO USE THE MATERIALS OR ANY OTHER + * RELATED INFORMATION PROVIDED TO YOU BY AMD, EVEN IF AMD HAS BEEN ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGES. BECAUSE SOME JURISDICTIONS PROHIBIT THE + * EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES, + * THE ABOVE LIMITATION MAY NOT APPLY TO YOU. + * + * AMD does not assume any responsibility for any errors which may appear in + * the Materials or any other related information provided to you by AMD, or + * result from use of the Materials or any related information. + * + * You agree that you will not reverse engineer or decompile the Materials. + * + * NO SUPPORT OBLIGATION: AMD is not obligated to furnish, support, or make any + * further information, software, technical information, know-how, or show-how + * available to you. Additionally, AMD retains the right to modify the + * Materials at any time, without notice, and is not obligated to provide such + * modified Materials to you. + * + * U.S. GOVERNMENT RESTRICTED RIGHTS: The Materials are provided with + * "RESTRICTED RIGHTS." Use, duplication, or disclosure by the Government is + * subject to the restrictions as set forth in FAR 52.227-14 and + * DFAR252.227-7013, et seq., or its successor. Use of the Materials by the + * Government constitutes acknowledgement of AMD's proprietary rights in them. + * + * EXPORT ASSURANCE: You agree and certify that neither the Materials, nor any + * direct product thereof will be exported directly or indirectly, into any + * country prohibited by the United States Export Administration Act and the + * regulations thereunder, without the required authorization from the U.S. + * government nor will be used for any purpose prohibited by the same. + ****************************************************************************** + */ + + /*---------------------------------------------------------------------------------------- + * M O D U L E S U S E D + *---------------------------------------------------------------------------------------- + */ +#include "AGESA.h" +#include "Ids.h" +#include "IdsLib.h" +#include "amdlib.h" +#include "AMD.h" +#include "heapManager.h" +#include "cpuRegisters.h" +#include "cpuServices.h" +#include "GeneralServices.h" +#include "IdsDebugPrint.h" +#include "IdsDpHdtout.h" +#include "Filecode.h" +CODE_GROUP (G1_PEICC) +RDATA_GROUP (G1_PEICC) + +#define FILECODE PROC_IDS_DEBUG_IDSDPHDTOUT_FILECODE + +/** + * Check if String contain the substring + * + * @param[in] String Pointer of string. + * @param[in] Substr Pointer of sub string. + * + * @retval TRUE S2 is substring of S1 + * @retval FALSE S2 isn't substring of S1 + * +**/ +BOOLEAN +AmdIdsSubStr ( + IN CHAR8 *String, + IN CHAR8 *Substr + ) +{ + UINT16 i; + UINT16 j; + + for (i = 0; String[i] != 0 ; i++) { + for (j = 0; (Substr[j] != 0) && (Substr[j] == String[i + j]); j++) { + } + if (Substr[j] == 0) { + return TRUE; + } + } + + return FALSE; +} + +/** + * Determine whether IDS console is enabled. + * + * @param[in,out] pHdtoutHeader Address of hdtout header pointer + * @param[in,out] StdHeader The Pointer of AGESA Header + * + * @retval TRUE pHdtoutHeader Non zero + * @retval FALSE pHdtoutHeader is NULL + * + **/ +BOOLEAN +AmdIdsHdtoutGetHeader ( + IN OUT HDTOUT_HEADER **pHdtoutHeaderPtr, + IN OUT AMD_CONFIG_PARAMS *StdHeader + ) +{ + UINT32 Dr3Reg; + HDTOUT_HEADER *HdtoutHeaderPtr; + LibAmdReadCpuReg (DR3_REG, &Dr3Reg); + HdtoutHeaderPtr = (HDTOUT_HEADER *) (UINTN) Dr3Reg; + if ((HdtoutHeaderPtr != NULL) && (HdtoutHeaderPtr->Signature == HDTOUT_HEADER_SIGNATURE)) { + *pHdtoutHeaderPtr = HdtoutHeaderPtr; + return TRUE; + } else { + return FALSE; + } +} +/** + * Determine whether IDS console is enabled. + * + * @param[in,out] IdsConsole The Pointer of Ids console data + * + * @retval TRUE Ids console is enabled. + * @retval FALSE Ids console is disabled. + * + **/ +BOOLEAN +AmdIdsHdtOutSupport ( + VOID + ) +{ + BOOLEAN Result; + UINT32 DR2reg; + + Result = FALSE; + + LibAmdReadCpuReg (DR2_REG, &DR2reg); + if (DR2reg == 0x99CC) { + Result = TRUE; + } + + return Result; +} + +/** + * Get HDTOUT customize Filter + * + * @param[in,out] Filter Filter do be filled + * + * @retval TRUE Alway return true, for HDTOUT has its own filter mechanism + * + **/ +BOOLEAN +AmdIdsHdtOutGetFilter ( + IN OUT UINT64 *Filter + ) +{ + HDTOUT_HEADER *HdtoutHeaderPtr; + + if (AmdIdsHdtoutGetHeader (&HdtoutHeaderPtr, NULL) == TRUE) { + *Filter = HdtoutHeaderPtr->ConsoleFilter; + } + return TRUE; +} + +/** + * + * Initial register setting used for HDT out Function. + * + * + * @param[in,out] StdHeader The Pointer of AGESA Header + * + **/ +VOID +AmdIdsHdtOutRegisterRestore ( + IN OUT AMD_CONFIG_PARAMS *StdHeader + ) +{ + UINT32 CR4reg; + UINT64 SMsr; + + SMsr &= ~BIT0; + + LibAmdWriteCpuReg (DR2_REG, 0); + LibAmdWriteCpuReg (DR3_REG, 0); + LibAmdWriteCpuReg (DR7_REG, 0); + + LibAmdReadCpuReg (CR4_REG, &CR4reg); + LibAmdWriteCpuReg (CR4_REG, CR4reg & (~BIT3)); + +} + +/** + * + * Restore register setting used for HDT out Function. + * + * + * @param[in,out] StdHeader The Pointer of AGESA Header + * + **/ +VOID +AmdIdsHdtOutRegisterInit ( + IN OUT AMD_CONFIG_PARAMS *StdHeader + ) +{ + UINT32 CR4reg; + UINT64 SMsr; + + SMsr |= 1; + + LibAmdWriteCpuReg (DR2_REG, 0x99CC); + + LibAmdWriteCpuReg (DR7_REG, 0x02000420); + + LibAmdReadCpuReg (CR4_REG, &CR4reg); + LibAmdWriteCpuReg (CR4_REG, CR4reg | ((UINT32)1 << 3)); +} + +/** + * + * Initial function for HDT out Function. + * + * Init required Debug register & heap, and will also fire a HDTOUT + * Command to let hdtout script do corresponding things. + * + * @param[in,out] StdHeader The Pointer of AGESA Header + * + **/ +VOID +AmdIdsHdtOutInit ( + IN OUT AMD_CONFIG_PARAMS *StdHeader + ) +{ + ALLOCATE_HEAP_PARAMS AllocHeapParams; + HDTOUT_HEADER HdtoutHeader; + UINT8 Persist; + AGESA_STATUS IgnoreSts; + HDTOUT_HEADER *pHdtoutHeader; + + IDS_FUNCLIST_EXTERN (); + if (AmdIdsHdtOutSupport ()) { + AmdIdsHdtOutRegisterInit (StdHeader); + // Initialize HDTOUT Header + HdtoutHeader.Signature = HDTOUT_HEADER_SIGNATURE; + HdtoutHeader.Version = HDTOUT_VERSION; + HdtoutHeader.BufferSize = HDTOUT_DEFAULT_BUFFER_SIZE; + HdtoutHeader.DataIndex = 0; + HdtoutHeader.PrintCtrl = HDTOUT_PRINTCTRL_ON; + HdtoutHeader.NumBreakpointUnit = 0; + HdtoutHeader.FuncListAddr = (UINT32) (UINT64) IDS_FUNCLIST_ADDR; + HdtoutHeader.StatusStr[0] = 0; + HdtoutHeader.OutBufferMode = HDTOUT_BUFFER_MODE_ON; + HdtoutHeader.EnableMask = 0; + HdtoutHeader.ConsoleFilter = IDS_DEBUG_PRINT_MASK; + + // Trigger HDTOUT breakpoint to get inputs from script + IdsOutPort (HDTOUT_INIT, (UINT32) (UINT64) &HdtoutHeader, 0); + // Disable AP HDTOUT if set BspOnlyFlag + if (HdtoutHeader.BspOnlyFlag == HDTOUT_BSP_ONLY) { + if (!IsBsp (StdHeader, &IgnoreSts)) { + AmdIdsHdtOutRegisterRestore (StdHeader); + return; + } + } + // Convert legacy EnableMask to new ConsoleFilter + HdtoutHeader.ConsoleFilter |= HdtoutHeader.EnableMask; + + // Disable the buffer if the size is not large enough + if (HdtoutHeader.BufferSize < 128) { + HdtoutHeader.BufferSize = 0; + HdtoutHeader.OutBufferMode = HDTOUT_BUFFER_MODE_OFF; + } else { + HdtoutHeader.OutBufferMode = HDTOUT_BUFFER_MODE_ON; + } + + // Check if Hdtout header have been initialed, if so it must 2nd time come here + if (AmdIdsHdtoutGetHeader (&pHdtoutHeader, StdHeader)) { + Persist = HEAP_SYSTEM_MEM; + } else { + Persist = HEAP_LOCAL_CACHE; + } + + // Allocate heap + do { + AllocHeapParams.RequestedBufferSize = HdtoutHeader.BufferSize + sizeof (HdtoutHeader) - 2; + AllocHeapParams.BufferHandle = IDS_HDT_OUT_BUFFER_HANDLE; + AllocHeapParams.Persist = Persist; + if (HeapAllocateBuffer (&AllocHeapParams, StdHeader) == AGESA_SUCCESS) { + break; + } else { + IdsOutPort (HDTOUT_ERROR, HDTOUT_ERROR_HEAP_ALLOCATION, AllocHeapParams.RequestedBufferSize); + HdtoutHeader.BufferSize -= 256; + } + } while ((HdtoutHeader.BufferSize & 0x8000) == 0); + // If the buffer have been successfully allocated? + if ((HdtoutHeader.BufferSize & 0x8000) == 0) { + LibAmdWriteCpuReg (DR3_REG, (UINT32) (UINT64) AllocHeapParams.BufferPtr); + LibAmdMemCopy (AllocHeapParams.BufferPtr, &HdtoutHeader, sizeof (HdtoutHeader) - 2, StdHeader); + } else { + /// Clear DR3_REG + IdsOutPort (HDTOUT_ERROR, HDTOUT_ERROR_HEAP_AllOCATE_FAIL, IDS_DEBUG_PRINT_MASK); + LibAmdWriteCpuReg (DR3_REG, 0); + } + } +} + +/** + * + * Flush all HDTOUT buffer data before HOB transfer + * + * @param[in,out] StdHeader The Pointer of AGESA Header + * + **/ +VOID +AmdIdsHdtOutBufferFlush ( + IN OUT AMD_CONFIG_PARAMS *StdHeader + ) +{ + HDTOUT_HEADER *HdtoutHeaderPtr ; + + if (AmdIdsHdtOutSupport ()) { + if (AmdIdsHdtoutGetHeader (&HdtoutHeaderPtr, StdHeader)) { + if ((HdtoutHeaderPtr->PrintCtrl == HDTOUT_PRINTCTRL_ON) && + (HdtoutHeaderPtr->OutBufferMode == HDTOUT_BUFFER_MODE_ON)) { + IdsOutPort (HDTOUT_PRINT, (UINT32) (UINT64) HdtoutHeaderPtr->Data, HdtoutHeaderPtr->DataIndex); + HdtoutHeaderPtr->DataIndex = 0; + } + } + } +} + +/** + * Exit function for HDT out Function for each cores + * + * @param[in] Ignored no used + * @param[in,out] StdHeader The Pointer of AMD_CONFIG_PARAMS. + * + * @retval AGESA_SUCCESS Success + * @retval AGESA_ERROR meet some error + * + **/ +AGESA_STATUS +AmdIdsHdtOutExitCoreTask ( + IN VOID *Ignored, + IN OUT AMD_CONFIG_PARAMS *StdHeader + ) +{ + HDTOUT_HEADER *HdtoutHeaderPtr; + + if (AmdIdsHdtoutGetHeader (&HdtoutHeaderPtr, StdHeader)) { + if ((HdtoutHeaderPtr->PrintCtrl == HDTOUT_PRINTCTRL_ON) && + (HdtoutHeaderPtr->OutBufferMode == HDTOUT_BUFFER_MODE_ON)) { + IdsOutPort (HDTOUT_PRINT, (UINT32) (UINT64) HdtoutHeaderPtr->Data, HdtoutHeaderPtr->DataIndex); + } + } + IdsOutPort (HDTOUT_EXIT, (UINT32) (UINT64) HdtoutHeaderPtr, 0); + + AmdIdsHdtOutRegisterRestore (StdHeader); + + return AGESA_SUCCESS; +} +/** + * + * Exit function for HDT out Function. + * + * Restore debug register and Deallocate heap, and will also fire a HDTOUT + * Command to let hdtout script do corresponding things. + * + * @param[in,out] StdHeader The Pointer of AGESA Header + * + **/ +VOID +AmdIdsHdtOutExit ( + IN OUT AMD_CONFIG_PARAMS *StdHeader + ) +{ + IDSAPLATETASK IdsApLateTask; + if (AmdIdsHdtOutSupport ()) { + IdsApLateTask.ApTask = (PF_IDS_AP_TASK) AmdIdsHdtOutExitCoreTask; + IdsApLateTask.ApTaskPara = NULL; + IdsAgesaRunFcnOnAllCoresLate (&IdsApLateTask, StdHeader); + HeapDeallocateBuffer (IDS_HDT_OUT_BUFFER_HANDLE, StdHeader); + } +} + +/** + * + * Exit function for HDT out Function of S3 Resume + * + * Restore debug register and Deallocate heap, and will also fire a HDTOUT + * Command to let hdtout script do corresponding things. + * + * @param[in,out] StdHeader The Pointer of AGESA Header + * + **/ +VOID +AmdIdsHdtOutS3Exit ( + IN OUT AMD_CONFIG_PARAMS *StdHeader + ) +{ + AGESA_STATUS AgesaStatus; + + if (AmdIdsHdtOutSupport ()) { + //Ap debug print exit have been done at the end of AmdInitResume, so we only BSP at here + AmdIdsHdtOutExitCoreTask (NULL, StdHeader); + if (IsBsp (StdHeader, &AgesaStatus)) { + HeapDeallocateBuffer (IDS_HDT_OUT_BUFFER_HANDLE, StdHeader); + } + } +} +/** + * + * Exit function for HDT out Function of S3 Resume + * + * Restore debug register and Deallocate heap, and will also fire a HDTOUT + * Command to let hdtout script do corresponding things. + * + * @param[in,out] StdHeader The Pointer of AGESA Header + * + **/ +VOID +AmdIdsHdtOutS3ApExit ( + IN OUT AMD_CONFIG_PARAMS *StdHeader + ) +{ + AP_TASK TaskPtr; + UINT32 Ignored; + UINT32 BscSocket; + UINT32 BscCoreNum; + UINT32 Core; + UINT32 Socket; + UINT32 NumberOfSockets; + UINT32 NumberOfCores; + AGESA_STATUS IgnoredSts; + + if (AmdIdsHdtOutSupport ()) { + // run code on all APs except BSP + TaskPtr.FuncAddress.PfApTaskI = (PF_AP_TASK_I)AmdIdsHdtOutExitCoreTask; + TaskPtr.DataTransfer.DataSizeInDwords = 0; + TaskPtr.DataTransfer.DataPtr = NULL; + TaskPtr.DataTransfer.DataTransferFlags = 0; + TaskPtr.ExeFlags = WAIT_FOR_CORE; + + NumberOfSockets = GetPlatformNumberOfSockets (); + IdentifyCore (StdHeader, &BscSocket, &Ignored, &BscCoreNum, &IgnoredSts); + + for (Socket = 0; Socket < NumberOfSockets; Socket++) { + if (IsProcessorPresent (Socket, StdHeader)) { + if (GetActiveCoresInGivenSocket (Socket, &NumberOfCores, StdHeader)) { + for (Core = 0; Core < NumberOfCores; Core++) { + if ((Socket != BscSocket) || (Core != BscCoreNum)) { + ApUtilRunCodeOnSocketCore ((UINT8) Socket, (UINT8) Core, &TaskPtr, StdHeader); + } + } + } + } + } + } +} + +/** + * Print formated string with accerate buffer + * Flow out only when buffer will full + * + * @param[in] Buffer - Point to input buffer + * @param[in] BufferSize - Buffer size + * @param[in] HdtoutHeaderPtr - Point to Hdtout Header + * +**/ +VOID +AmdIdsHdtOutPrintWithBuffer ( + IN CHAR8 *Buffer, + IN UINTN BufferSize, + IN HDTOUT_HEADER *HdtoutHeaderPtr + ) +{ + if ((HdtoutHeaderPtr == NULL) || (Buffer == NULL)) { + ASSERT (FALSE); + return; + } + + while (BufferSize--) { + if (HdtoutHeaderPtr->DataIndex >= HdtoutHeaderPtr->BufferSize) { + //Flow out current buffer, and clear the index + IdsOutPort (HDTOUT_PRINT, (UINT32) (UINTN) &HdtoutHeaderPtr->Data[0], HdtoutHeaderPtr->BufferSize); + HdtoutHeaderPtr->DataIndex = 0; + } + HdtoutHeaderPtr->Data[HdtoutHeaderPtr->DataIndex++] = *(Buffer++); + } +} +/** + * Save HDTOUT context, use for break point function + * + * @param[in] Buffer - Point to input buffer + * @param[in] BufferSize - Buffer size + * @param[in] HdtoutHeaderPtr - Point to Hdtout Header + * +**/ +VOID +AmdIdsHdtOutSaveContext ( + IN CHAR8 *Buffer, + IN UINTN BufferSize, + IN HDTOUT_HEADER *HdtoutHeaderPtr + ) +{ + UINTN i; + UINTN j; + UINTN ArrayIndex; + UINTN unusedPrefix; + UINTN ArrayLength; + BOOLEAN SaveStatus; + + ArrayLength = 0; + + // Look for the start of the first ASCII + for (i = 0; i < BufferSize - 1; i++) { + if ((Buffer[i] > 32) && (Buffer[i] < 127)) { + break; + } + } + + unusedPrefix = i; + //ASSERT if no "\n" in status string + ASSERT (AmdIdsSubStr (&Buffer[i], "\n")); + + if (i < (BufferSize - 1)) { + // Match the first word in StatusStr + SaveStatus = FALSE; + for (j = 0; !SaveStatus && (HdtoutHeaderPtr->StatusStr[j] != 0); j++) { + for (; (Buffer[i] == HdtoutHeaderPtr->StatusStr[j]) && (i < BufferSize); i++, j++) { + ArrayLength++; + if (Buffer[i] == ' ') { + ArrayIndex = j; + for (; HdtoutHeaderPtr->StatusStr[j] != '\n'; j++) { + ArrayLength++; + } + // Remove old entry if it's size does not fit + if (ArrayLength != ((UINT32) BufferSize - unusedPrefix)) { + for (++j; HdtoutHeaderPtr->StatusStr[j] != 0; j++) { + HdtoutHeaderPtr->StatusStr[j - ArrayLength] = HdtoutHeaderPtr->StatusStr[j]; + } + j = j - ArrayLength - 1; + i = unusedPrefix; + // Mark the end of string + HdtoutHeaderPtr->StatusStr[j + BufferSize - unusedPrefix + 1] = 0; + } else { + j = ArrayIndex - 1; + } + + // Word match, exit for saving + SaveStatus = TRUE; + break; + } + } + } + + // Copy string to StatusStr + if ((HdtoutHeaderPtr->StatusStr[j] == 0) || SaveStatus) { + for (; i < BufferSize; j++, i++) { + HdtoutHeaderPtr->StatusStr[j] = Buffer[i]; + } + } + + if (!SaveStatus) { + // Mark the end of string if not done so + HdtoutHeaderPtr->StatusStr[j] = 0; + } + } +} + +BOOLEAN +AmdIdsHdtOutBreakPointUnit ( + IN OUT BREAKPOINT_UNIT **pBpunitptr, + IN OUT UINT32 *numBp, + IN HDTOUT_HEADER *HdtoutHeaderPtr, + IN CHAR8 *Buffer + ) +{ + BOOLEAN isMatched; + CHAR8 *PCmpStr; + CHAR8 *Pbpstr; + BREAKPOINT_UNIT *pBpunit; + + pBpunit = *pBpunitptr; + if ((pBpunit == NULL) || + (numBp == NULL) || + (HdtoutHeaderPtr == NULL) || + (*numBp == 0)) { + ASSERT (FALSE); + return FALSE; + } + //Get to be compared string + if (pBpunit->BpFlag == IDS_HDTOUT_BPFLAG_FORMAT_STR) { + PCmpStr = Buffer; + } else { + PCmpStr = HdtoutHeaderPtr->StatusStr; + } + //Get BreakPoint string + Pbpstr = HdtoutHeaderPtr->BreakpointList + pBpunit->BpStrOffset; + isMatched = AmdIdsSubStr (PCmpStr, Pbpstr); + //Point to next one, and decrease the numbp + *pBpunitptr = ++pBpunit; + (*numBp)--; + return isMatched; +} +/** + * Process HDTOUT breakpoint + * + * @param[in] Buffer - Point to input buffer + * @param[in] BufferSize - Buffer size + * @param[in] HdtoutHeaderPtr - Point to Hdtout Header + * +**/ +VOID +AmdIdsHdtOutBreakPoint ( + IN CHAR8 *Buffer, + IN UINTN BufferSize, + IN HDTOUT_HEADER *HdtoutHeaderPtr + ) +{ + UINT32 numBp; + BREAKPOINT_UNIT *Pbpunit; + BOOLEAN isMatched; + UINT32 i; + Pbpunit = (BREAKPOINT_UNIT *) &HdtoutHeaderPtr->BreakpointList[0]; + numBp = HdtoutHeaderPtr->NumBreakpointUnit; + + for (;;) { + if (Pbpunit->AndFlag == IDS_HDTOUT_BP_AND_ON) { + isMatched = TRUE; + do { + isMatched &= AmdIdsHdtOutBreakPointUnit (&Pbpunit, &numBp, HdtoutHeaderPtr, Buffer); + } while ((Pbpunit->AndFlag == IDS_HDTOUT_BP_AND_ON) && + (isMatched == TRUE) && + (numBp > 0)); + //Next one is IDS_HDTOUT_BP_AND_OFF + if (numBp > 0) { + if (isMatched == TRUE) { + isMatched &= AmdIdsHdtOutBreakPointUnit (&Pbpunit, &numBp, HdtoutHeaderPtr, Buffer); + } else { + Pbpunit++; + numBp--; + } + } + } else { + isMatched = AmdIdsHdtOutBreakPointUnit (&Pbpunit, &numBp, HdtoutHeaderPtr, Buffer); + } + if ((isMatched == TRUE) || (numBp == 0)) { + break; + } + } + //Do action + if (isMatched) { +// AmdIdsSerialPrint (Buffer, BufferSize, NULL); + Pbpunit--; + switch (Pbpunit->Action) { + case HDTOUT_BP_ACTION_HALT: + i = (UINT32) (Pbpunit - ((BREAKPOINT_UNIT *) &HdtoutHeaderPtr->BreakpointList[0])); + IdsOutPort (HDTOUT_BREAKPOINT, (UINT32) (UINTN) Buffer, ( i << 16) | (UINT32) BufferSize); + break; + case HDTOUT_BP_ACTION_PRINTON: + if (HdtoutHeaderPtr->PrintCtrl != 1) { + HdtoutHeaderPtr->PrintCtrl = 1; + if (HdtoutHeaderPtr->OutBufferMode == HDTOUT_BUFFER_MODE_ON) { + AmdIdsHdtOutPrintWithBuffer (Buffer, BufferSize, HdtoutHeaderPtr); + } else { + IdsOutPort (HDTOUT_PRINT, (UINT32) (UINTN) Buffer, (UINT32) BufferSize); + } + } + break; + case HDTOUT_BP_ACTION_PRINTOFF: + if (HdtoutHeaderPtr->PrintCtrl != 0) { + HdtoutHeaderPtr->PrintCtrl = 0; + IdsOutPort (HDTOUT_PRINT, (UINT32) (UINTN) Buffer, (UINT32)BufferSize); + } + break; + default: + ASSERT (FALSE); + } + } +} + + +/** + * Print formated string to HDTOUT + * + * @param[in] Buffer - Point to input buffer + * @param[in] BufferSize - Buffer size + * @param[in] debugPrintPrivate - Option + * +**/ +VOID +AmdIdsHdtOutPrint ( + IN CHAR8 *Buffer, + IN UINTN BufferSize, + IN IDS_DEBUG_PRINT_PRIVATE_DATA *debugPrintPrivate + ) +{ + HDTOUT_HEADER *HdtoutHeaderPtr; + if (AmdIdsHdtoutGetHeader (&HdtoutHeaderPtr, NULL)) { + //Print Function + if (HdtoutHeaderPtr->PrintCtrl == HDTOUT_PRINTCTRL_ON) { + if (HdtoutHeaderPtr->OutBufferMode == HDTOUT_BUFFER_MODE_ON) { + AmdIdsHdtOutPrintWithBuffer (Buffer, BufferSize, HdtoutHeaderPtr); + } else { + IdsOutPort (HDTOUT_PRINT, (UINT32) (UINTN) Buffer, (UINT32) BufferSize); + } + } + //Check BreakPoint + if (HdtoutHeaderPtr->NumBreakpointUnit) { + AmdIdsHdtOutBreakPoint (Buffer, BufferSize, HdtoutHeaderPtr); + if (debugPrintPrivate->saveContext) { + AmdIdsHdtOutSaveContext (Buffer, BufferSize, HdtoutHeaderPtr); + debugPrintPrivate->saveContext = FALSE; + } + } + } else { + //No HDTOUT header found print directly without buffer + IdsOutPort (HDTOUT_PRINT, (UINT32) (UINTN) Buffer, (UINT32) BufferSize); + } +} + +/** + * Init local private data for HDTOUT + * + * @param[in] Flag - filter flag + * @param[in] debugPrintPrivate - Point to debugPrintPrivate + * +**/ +VOID +AmdIdsHdtOutInitPrivateData ( + IN UINT64 Flag, + IN IDS_DEBUG_PRINT_PRIVATE_DATA *debugPrintPrivate + ) +{ + if (Flag == MEM_STATUS) { + debugPrintPrivate->saveContext = TRUE; + } +} + +CONST IDS_DEBUG_PRINT ROMDATA IdsDebugPrintHdtoutInstance = +{ + AmdIdsHdtOutSupport, + AmdIdsHdtOutGetFilter, + AmdIdsHdtOutInitPrivateData, + AmdIdsHdtOutPrint +}; + + + diff --git a/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsDpHdtout.h b/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsDpHdtout.h new file mode 100644 index 0000000000..bb4cc1df87 --- /dev/null +++ b/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsDpHdtout.h @@ -0,0 +1,146 @@ +/* $NoKeywords:$ */ +/** + * @file + * + * AMD Integrated Debug Debug_library Routines + * + * Contains all functions related to HDTOUT + * + * @xrefitem bom "File Content Label" "Release Content" + * @e project: AGESA + * @e sub-project: IDS + * @e \$Revision: 63425 $ @e \$Date: 2011-12-22 11:24:10 -0600 (Thu, 22 Dec 2011) $ + */ +/***************************************************************************** + * + * Copyright 2008 - 2012 ADVANCED MICRO DEVICES, INC. All Rights Reserved. + * + * AMD is granting you permission to use this software (the Materials) + * pursuant to the terms and conditions of your Software License Agreement + * with AMD. This header does *NOT* give you permission to use the Materials + * or any rights under AMD's intellectual property. Your use of any portion + * of these Materials shall constitute your acceptance of those terms and + * conditions. If you do not agree to the terms and conditions of the Software + * License Agreement, please do not use any portion of these Materials. + * + * CONFIDENTIALITY: The Materials and all other information, identified as + * confidential and provided to you by AMD shall be kept confidential in + * accordance with the terms and conditions of the Software License Agreement. + * + * LIMITATION OF LIABILITY: THE MATERIALS AND ANY OTHER RELATED INFORMATION + * PROVIDED TO YOU BY AMD ARE PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTY OF ANY KIND, INCLUDING BUT NOT LIMITED TO WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, TITLE, FITNESS FOR ANY PARTICULAR PURPOSE, + * OR WARRANTIES ARISING FROM CONDUCT, COURSE OF DEALING, OR USAGE OF TRADE. + * IN NO EVENT SHALL AMD OR ITS LICENSORS BE LIABLE FOR ANY DAMAGES WHATSOEVER + * (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS + * INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF AMD'S NEGLIGENCE, + * GROSS NEGLIGENCE, THE USE OF OR INABILITY TO USE THE MATERIALS OR ANY OTHER + * RELATED INFORMATION PROVIDED TO YOU BY AMD, EVEN IF AMD HAS BEEN ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGES. BECAUSE SOME JURISDICTIONS PROHIBIT THE + * EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES, + * THE ABOVE LIMITATION MAY NOT APPLY TO YOU. + * + * AMD does not assume any responsibility for any errors which may appear in + * the Materials or any other related information provided to you by AMD, or + * result from use of the Materials or any related information. + * + * You agree that you will not reverse engineer or decompile the Materials. + * + * NO SUPPORT OBLIGATION: AMD is not obligated to furnish, support, or make any + * further information, software, technical information, know-how, or show-how + * available to you. Additionally, AMD retains the right to modify the + * Materials at any time, without notice, and is not obligated to provide such + * modified Materials to you. + * + * U.S. GOVERNMENT RESTRICTED RIGHTS: The Materials are provided with + * "RESTRICTED RIGHTS." Use, duplication, or disclosure by the Government is + * subject to the restrictions as set forth in FAR 52.227-14 and + * DFAR252.227-7013, et seq., or its successor. Use of the Materials by the + * Government constitutes acknowledgement of AMD's proprietary rights in them. + * + * EXPORT ASSURANCE: You agree and certify that neither the Materials, nor any + * direct product thereof will be exported directly or indirectly, into any + * country prohibited by the United States Export Administration Act and the + * regulations thereunder, without the required authorization from the U.S. + * government nor will be used for any purpose prohibited by the same. + * + ***************************************************************************/ + +#ifndef _IDS_HDTOUT_H_ +#define _IDS_HDTOUT_H_ + +#define HDTOUT_VERSION 0x0200 + +/// HDTOUT command +#define HDTOUT_COMMAND 0x99cc +#define HDTOUT_INIT (0x10BF0000ul | HDTOUT_COMMAND) +#define HDTOUT_ASSERT (0xA0BF0000ul | HDTOUT_COMMAND) +#define HDTOUT_EXIT (0xE0BF0000ul | HDTOUT_COMMAND) +#define HDTOUT_PRINT (0xC0BF0000ul | HDTOUT_COMMAND) +#define HDTOUT_TIME_ANALYSE (0xD0BF0000ul | HDTOUT_COMMAND) +#define HDTOUT_BREAKPOINT (0xB0BF0000ul | HDTOUT_COMMAND) +#define HDTOUT_ERROR (0x1EBF0000ul | HDTOUT_COMMAND) + + +#define HDTOUT_ERROR_HEAP_ALLOCATION 0x1 +#define HDTOUT_ERROR_HEAP_AllOCATE_FAIL 0x2 + +#define HDTOUT_PRINTCTRL_OFF 0 +#define HDTOUT_PRINTCTRL_ON 1 +#define HDTOUT_ALL_CORES 0 +#define HDTOUT_BSP_ONLY 1 +#define HDTOUT_BUFFER_MODE_OFF 0 +#define HDTOUT_BUFFER_MODE_ON 1 + +#define HDTOUT_HEADER_SIGNATURE 0xDB1099CCul +#define HDTOUT_DEFAULT_BUFFER_SIZE 0x1000 +/// HDTOUT Header. +typedef struct _HDTOUT_HEADER { + UINT32 Signature; ///< 0xDB1099CC + UINT16 Version; ///< HDTOUT version. + UINT16 BufferSize; ///< Size in bytes. + UINT16 DataIndex; ///< Data Index. + UINT8 PrintCtrl; ///< 0 off no print 1 on print + UINT8 NumBreakpointUnit; ///< default 0 no bp unit others number of bp unit + UINT32 FuncListAddr; ///< 32 bit address to the list of functions that script can execute + UINT8 ConsoleType; ///< Console type - deprecated + UINT8 Event; ///< Event type. - deprecated + UINT8 OutBufferMode; ///< Off:stack mode, On: heap mode - deprecated + UINT32 EnableMask; ///< Bitmap to select which part should be streamed out + UINT64 ConsoleFilter; ///< Filter use to select which part should be streamed out + UINT8 BspOnlyFlag; ///< 1 Only Enable Bsp output, 0 enable On All cores + UINT8 Reserved[56 - 32]; ///< Reserved for header expansion + + CHAR8 BreakpointList[300]; ///< Breakpoint list + CHAR8 StatusStr[156]; ///< Shows current node, DCT, CS,... + CHAR8 Data[2]; ///< HDTOUT content. Its size will be determined by BufferSize. +} HDTOUT_HEADER; + +#define IDS_HDTOUT_BP_AND_OFF 0 +#define IDS_HDTOUT_BP_AND_ON 1 + +#define IDS_HDTOUT_BPFLAG_FORMAT_STR 0 +#define IDS_HDTOUT_BPFLAG_STATUS_STR 1 + +#define HDTOUT_BP_ACTION_HALT 1 +#define HDTOUT_BP_ACTION_PRINTON 2 +#define HDTOUT_BP_ACTION_PRINTONE 3 +#define HDTOUT_BP_ACTION_PRINTOFF 4 + +///breakpoint unit of HDTOUT +typedef struct _BREAKPOINT_UNIT { + UINT8 AndFlag : 1; ///< Next string is ANDed to current string + UINT8 BpFlag : 1; ///< Format string or Status string + UINT8 Action : 4; ///< Halt, start HDTOUT, or stop HDT,... + UINT8 BpStrOffset; ///< Offset from BreakpointList to the breakpoint string +} BREAKPOINT_UNIT; + + +BOOLEAN +AmdIdsHdtOutSupport ( + VOID + ); + +#endif //_IDS_HDTOUT_H_ + diff --git a/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsDpRedirectIo.c b/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsDpRedirectIo.c new file mode 100644 index 0000000000..fbcf1b749d --- /dev/null +++ b/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsDpRedirectIo.c @@ -0,0 +1,172 @@ +/** + * @file + * + * AMD Integrated Debug Debug_library Routines + * + * Contains all functions related to Redirect IO + * + * @xrefitem bom "File Content Label" "Release Content" + * @e project: AGESA + * @e sub-project: IDS + * @e \$Revision: 63425 $ @e \$Date: 2011-12-22 11:24:10 -0600 (Thu, 22 Dec 2011) $ + */ +/***************************************************************************** + * Copyright 2008 - 2012 ADVANCED MICRO DEVICES, INC. All Rights Reserved. + * + * AMD is granting you permission to use this software (the Materials) + * pursuant to the terms and conditions of your Software License Agreement + * with AMD. This header does *NOT* give you permission to use the Materials + * or any rights under AMD's intellectual property. Your use of any portion + * of these Materials shall constitute your acceptance of those terms and + * conditions. If you do not agree to the terms and conditions of the Software + * License Agreement, please do not use any portion of these Materials. + * + * CONFIDENTIALITY: The Materials and all other information, identified as + * confidential and provided to you by AMD shall be kept confidential in + * accordance with the terms and conditions of the Software License Agreement. + * + * LIMITATION OF LIABILITY: THE MATERIALS AND ANY OTHER RELATED INFORMATION + * PROVIDED TO YOU BY AMD ARE PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTY OF ANY KIND, INCLUDING BUT NOT LIMITED TO WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, TITLE, FITNESS FOR ANY PARTICULAR PURPOSE, + * OR WARRANTIES ARISING FROM CONDUCT, COURSE OF DEALING, OR USAGE OF TRADE. + * IN NO EVENT SHALL AMD OR ITS LICENSORS BE LIABLE FOR ANY DAMAGES WHATSOEVER + * (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS + * INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF AMD'S NEGLIGENCE, + * GROSS NEGLIGENCE, THE USE OF OR INABILITY TO USE THE MATERIALS OR ANY OTHER + * RELATED INFORMATION PROVIDED TO YOU BY AMD, EVEN IF AMD HAS BEEN ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGES. BECAUSE SOME JURISDICTIONS PROHIBIT THE + * EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES, + * THE ABOVE LIMITATION MAY NOT APPLY TO YOU. + * + * AMD does not assume any responsibility for any errors which may appear in + * the Materials or any other related information provided to you by AMD, or + * result from use of the Materials or any related information. + * + * You agree that you will not reverse engineer or decompile the Materials. + * + * NO SUPPORT OBLIGATION: AMD is not obligated to furnish, support, or make any + * further information, software, technical information, know-how, or show-how + * available to you. Additionally, AMD retains the right to modify the + * Materials at any time, without notice, and is not obligated to provide such + * modified Materials to you. + * + * U.S. GOVERNMENT RESTRICTED RIGHTS: The Materials are provided with + * "RESTRICTED RIGHTS." Use, duplication, or disclosure by the Government is + * subject to the restrictions as set forth in FAR 52.227-14 and + * DFAR252.227-7013, et seq., or its successor. Use of the Materials by the + * Government constitutes acknowledgement of AMD's proprietary rights in them. + * + * EXPORT ASSURANCE: You agree and certify that neither the Materials, nor any + * direct product thereof will be exported directly or indirectly, into any + * country prohibited by the United States Export Administration Act and the + * regulations thereunder, without the required authorization from the U.S. + * government nor will be used for any purpose prohibited by the same. + ****************************************************************************** + */ + + /*---------------------------------------------------------------------------------------- + * M O D U L E S U S E D + *---------------------------------------------------------------------------------------- + */ +#include "AGESA.h" +#include "Ids.h" +#include "IdsLib.h" +#include "amdlib.h" +#include "AMD.h" +#include "IdsDebugPrint.h" +#include "Filecode.h" +CODE_GROUP (G1_PEICC) +RDATA_GROUP (G1_PEICC) + +#define FILECODE PROC_IDS_DEBUG_IDSDPSERIAL_FILECODE + +/** + * Determine whether IDS console is enabled. + * + * + * @retval TRUE Alway return true + * + **/ +BOOLEAN +AmdIdsRedirectIoSupport ( + VOID + ) +{ + + return TRUE; +} + +/** + * Get customize Filter + * + * @param[in,out] Filter Filter do be filled + * + * @retval FALSE Alway return FALSE + * + **/ +BOOLEAN +AmdIdsRedirectIoGetFilter ( + IN OUT UINT64 *Filter + ) +{ + return FALSE; +} + +#define REDIRECT_IO_DATA_BEGIN 0x5f535452ul +#define REDIRECT_IO_DATA_END 0x5f454e44ul + +/** + * Print formated string with redirect IO + * + * @param[in] Buffer - Point to input buffer + * @param[in] BufferSize - Buffer size + * @param[in] debugPrintPrivate - Option + * +**/ +VOID +AmdIdsRedirectIoPrint ( + IN CHAR8 *Buffer, + IN UINTN BufferSize, + IN IDS_DEBUG_PRINT_PRIVATE_DATA *debugPrintPrivate + ) +{ + UINT32 Value; + + Value = REDIRECT_IO_DATA_BEGIN; + LibAmdIoWrite (AccessWidth32, IDS_DEBUG_PRINT_IO_PORT, &Value, NULL); + + while (BufferSize--) { + LibAmdIoWrite (AccessWidth8, IDS_DEBUG_PRINT_IO_PORT, Buffer++, NULL); + } + + Value = REDIRECT_IO_DATA_END; + LibAmdIoWrite (AccessWidth32, IDS_DEBUG_PRINT_IO_PORT, &Value, NULL); +} + +/** + * Init local private data + * + * @param[in] Flag - filter flag + * @param[in] debugPrintPrivate - Point to debugPrintPrivate + * +**/ +VOID +AmdIdsRedirectIoInitPrivateData ( + IN UINT64 Flag, + IN IDS_DEBUG_PRINT_PRIVATE_DATA *debugPrintPrivate + ) +{ + +} + +CONST IDS_DEBUG_PRINT ROMDATA IdsDebugPrintRedirectIoInstance = +{ + AmdIdsRedirectIoSupport, + AmdIdsRedirectIoGetFilter, + AmdIdsRedirectIoInitPrivateData, + AmdIdsRedirectIoPrint +}; + + + diff --git a/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsDpSerial.c b/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsDpSerial.c new file mode 100644 index 0000000000..749c02a652 --- /dev/null +++ b/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsDpSerial.c @@ -0,0 +1,211 @@ +/** + * @file + * + * AMD Integrated Debug Debug_library Routines + * + * Contains all functions related to HDTOUT + * + * @xrefitem bom "File Content Label" "Release Content" + * @e project: AGESA + * @e sub-project: IDS + * @e \$Revision: 63425 $ @e \$Date: 2011-12-22 11:24:10 -0600 (Thu, 22 Dec 2011) $ + */ +/***************************************************************************** + * Copyright 2008 - 2012 ADVANCED MICRO DEVICES, INC. All Rights Reserved. + * + * AMD is granting you permission to use this software (the Materials) + * pursuant to the terms and conditions of your Software License Agreement + * with AMD. This header does *NOT* give you permission to use the Materials + * or any rights under AMD's intellectual property. Your use of any portion + * of these Materials shall constitute your acceptance of those terms and + * conditions. If you do not agree to the terms and conditions of the Software + * License Agreement, please do not use any portion of these Materials. + * + * CONFIDENTIALITY: The Materials and all other information, identified as + * confidential and provided to you by AMD shall be kept confidential in + * accordance with the terms and conditions of the Software License Agreement. + * + * LIMITATION OF LIABILITY: THE MATERIALS AND ANY OTHER RELATED INFORMATION + * PROVIDED TO YOU BY AMD ARE PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTY OF ANY KIND, INCLUDING BUT NOT LIMITED TO WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, TITLE, FITNESS FOR ANY PARTICULAR PURPOSE, + * OR WARRANTIES ARISING FROM CONDUCT, COURSE OF DEALING, OR USAGE OF TRADE. + * IN NO EVENT SHALL AMD OR ITS LICENSORS BE LIABLE FOR ANY DAMAGES WHATSOEVER + * (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS + * INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF AMD'S NEGLIGENCE, + * GROSS NEGLIGENCE, THE USE OF OR INABILITY TO USE THE MATERIALS OR ANY OTHER + * RELATED INFORMATION PROVIDED TO YOU BY AMD, EVEN IF AMD HAS BEEN ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGES. BECAUSE SOME JURISDICTIONS PROHIBIT THE + * EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES, + * THE ABOVE LIMITATION MAY NOT APPLY TO YOU. + * + * AMD does not assume any responsibility for any errors which may appear in + * the Materials or any other related information provided to you by AMD, or + * result from use of the Materials or any related information. + * + * You agree that you will not reverse engineer or decompile the Materials. + * + * NO SUPPORT OBLIGATION: AMD is not obligated to furnish, support, or make any + * further information, software, technical information, know-how, or show-how + * available to you. Additionally, AMD retains the right to modify the + * Materials at any time, without notice, and is not obligated to provide such + * modified Materials to you. + * + * U.S. GOVERNMENT RESTRICTED RIGHTS: The Materials are provided with + * "RESTRICTED RIGHTS." Use, duplication, or disclosure by the Government is + * subject to the restrictions as set forth in FAR 52.227-14 and + * DFAR252.227-7013, et seq., or its successor. Use of the Materials by the + * Government constitutes acknowledgement of AMD's proprietary rights in them. + * + * EXPORT ASSURANCE: You agree and certify that neither the Materials, nor any + * direct product thereof will be exported directly or indirectly, into any + * country prohibited by the United States Export Administration Act and the + * regulations thereunder, without the required authorization from the U.S. + * government nor will be used for any purpose prohibited by the same. + ****************************************************************************** + */ + + /*---------------------------------------------------------------------------------------- + * M O D U L E S U S E D + *---------------------------------------------------------------------------------------- + */ +#include "AGESA.h" +#include "Ids.h" +#include "IdsLib.h" +#include "amdlib.h" +#include "AMD.h" +#include "IdsDebugPrint.h" +#include "Filecode.h" +CODE_GROUP (G1_PEICC) +RDATA_GROUP (G1_PEICC) + +#define FILECODE PROC_IDS_DEBUG_IDSDPSERIAL_FILECODE + +/** + * Determine whether IDS console is enabled. + * + * + * @retval TRUE Alway return true + * + **/ +STATIC BOOLEAN +AmdIdsSerialSupport ( + VOID + ) +{ + + return TRUE; +} + +/** + * Get Serial customize Filter + * + * @param[in,out] Filter Filter do be filled + * + * @retval FALSE Alway return FALSE + * + **/ +STATIC BOOLEAN +AmdIdsSerialGetFilter ( + IN OUT UINT64 *Filter + ) +{ + return FALSE; +} + + +#define IDS_SERIAL_PORT_LSR (IDS_SERIAL_PORT + 5) +#define IDS_LSR_TRANSMIT_HOLDING_REGISTER_EMPTY_MASK BIT5 +/** + * Send byte to Serial Port + * + * Before use this routine, please make sure Serial Communications Chip have been initialed + * + * @param[in] ByteSended Byte to be sended + * + * @retval TRUE Byte sended successfully + * @retval FALSE Byte sended failed + * + **/ +STATIC BOOLEAN +AmdIdsSerialSendByte ( + IN CHAR8 ByteSended + ) +{ + UINT32 RetryCount; + UINT8 Value; + + //Wait until LSR.Bit5 (Transmitter holding register Empty) + RetryCount = 200; + do { + LibAmdIoRead (AccessWidth8, IDS_SERIAL_PORT_LSR, &Value, NULL); + RetryCount--; + } while (((Value & IDS_LSR_TRANSMIT_HOLDING_REGISTER_EMPTY_MASK) == 0) && + (RetryCount > 0)); + + if (RetryCount == 0) { + //Time expired + return FALSE; + } else { + LibAmdIoWrite (AccessWidth8, IDS_SERIAL_PORT, &ByteSended, NULL); + return TRUE; + } +} + + +/** + * Print formated string + * + * @param[in] Buffer - Point to input buffer + * @param[in] BufferSize - Buffer size + * @param[in] debugPrintPrivate - Option + * +**/ +STATIC VOID +AmdIdsSerialPrint ( + IN CHAR8 *Buffer, + IN UINTN BufferSize, + IN IDS_DEBUG_PRINT_PRIVATE_DATA *debugPrintPrivate + ) +{ + BOOLEAN SendStatus; + UINT32 RetryCount; + RetryCount = 200; + while (BufferSize--) { + do { + if (*Buffer == '\n') { + SendStatus = AmdIdsSerialSendByte ('\r'); + } + SendStatus = AmdIdsSerialSendByte (*Buffer); + RetryCount--; + } while ((SendStatus == FALSE) && (RetryCount > 0)); + Buffer ++; + } +} + +/** + * Init local private data + * + * @param[in] Flag - filter flag + * @param[in] debugPrintPrivate - Point to debugPrintPrivate + * +**/ +STATIC VOID +AmdIdsSerialInitPrivateData ( + IN UINT64 Flag, + IN IDS_DEBUG_PRINT_PRIVATE_DATA *debugPrintPrivate + ) +{ + +} + +CONST IDS_DEBUG_PRINT ROMDATA IdsDebugPrintSerialInstance = +{ + AmdIdsSerialSupport, + AmdIdsSerialGetFilter, + AmdIdsSerialInitPrivateData, + AmdIdsSerialPrint +}; + + + diff --git a/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsIdtTable.c b/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsIdtTable.c new file mode 100644 index 0000000000..f7e6a560eb --- /dev/null +++ b/src/vendorcode/amd/agesa/f15tn/Proc/IDS/Debug/IdsIdtTable.c @@ -0,0 +1,329 @@ +/** + * @file + * + * Adding IDT table for debugging exception + * + * Contains IDT related function + * + * @xrefitem bom "File Content Label" "Release Content" + * @e project: AGESA + * @e sub-project: IDS + * @e \$Revision: 63425 $ @e \$Date: 2011-12-22 11:24:10 -0600 (Thu, 22 Dec 2011) $ + */ +/***************************************************************************** + * Copyright 2008 - 2012 ADVANCED MICRO DEVICES, INC. All Rights Reserved. + * + * AMD is granting you permission to use this software (the Materials) + * pursuant to the terms and conditions of your Software License Agreement + * with AMD. This header does *NOT* give you permission to use the Materials + * or any rights under AMD's intellectual property. Your use of any portion + * of these Materials shall constitute your acceptance of those terms and + * conditions. If you do not agree to the terms and conditions of the Software + * License Agreement, please do not use any portion of these Materials. + * + * CONFIDENTIALITY: The Materials and all other information, identified as + * confidential and provided to you by AMD shall be kept confidential in + * accordance with the terms and conditions of the Software License Agreement. + * + * LIMITATION OF LIABILITY: THE MATERIALS AND ANY OTHER RELATED INFORMATION + * PROVIDED TO YOU BY AMD ARE PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTY OF ANY KIND, INCLUDING BUT NOT LIMITED TO WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, TITLE, FITNESS FOR ANY PARTICULAR PURPOSE, + * OR WARRANTIES ARISING FROM CONDUCT, COURSE OF DEALING, OR USAGE OF TRADE. + * IN NO EVENT SHALL AMD OR ITS LICENSORS BE LIABLE FOR ANY DAMAGES WHATSOEVER + * (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS + * INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF AMD'S NEGLIGENCE, + * GROSS NEGLIGENCE, THE USE OF OR INABILITY TO USE THE MATERIALS OR ANY OTHER + * RELATED INFORMATION PROVIDED TO YOU BY AMD, EVEN IF AMD HAS BEEN ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGES. BECAUSE SOME JURISDICTIONS PROHIBIT THE + * EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES, + * THE ABOVE LIMITATION MAY NOT APPLY TO YOU. + * + * AMD does not assume any responsibility for any errors which may appear in + * the Materials or any other related information provided to you by AMD, or + * result from use of the Materials or any related information. + * + * You agree that you will not reverse engineer or decompile the Materials. + * + * NO SUPPORT OBLIGATION: AMD is not obligated to furnish, support, or make any + * further information, software, technical information, know-how, or show-how + * available to you. Additionally, AMD retains the right to modify the + * Materials at any time, without notice, and is not obligated to provide such + * modified Materials to you. + * + * U.S. GOVERNMENT RESTRICTED RIGHTS: The Materials are provided with + * "RESTRICTED RIGHTS." Use, duplication, or disclosure by the Government is + * subject to the restrictions as set forth in FAR 52.227-14 and + * DFAR252.227-7013, et seq., or its successor. Use of the Materials by the + * Government constitutes acknowledgement of AMD's proprietary rights in them. + * + * EXPORT ASSURANCE: You agree and certify that neither the Materials, nor any + * direct product thereof will be exported directly or indirectly, into any + * country prohibited by the United States Export Administration Act and the + * regulations thereunder, without the required authorization from the U.S. + * government nor will be used for any purpose prohibited by the same. + ****************************************************************************** + */ + + /*---------------------------------------------------------------------------------------- + * M O D U L E S U S E D + *---------------------------------------------------------------------------------------- + */ +#include "AGESA.h" +#include "Ids.h" +#include "IdsLib.h" +#include "amdlib.h" +#include "AMD.h" +#include "GeneralServices.h" +#include "cpuApicUtilities.h" +#include "heapManager.h" +#include "cpuRegisters.h" +#include "Filecode.h" +CODE_GROUP (G1_PEICC) +RDATA_GROUP (G1_PEICC) + +#define FILECODE PROC_IDS_DEBUG_IDSIDTTABLE_FILECODE + +/*---------------------------------------------------------------------------------------- + * P R O T O T Y P E S O F L O C A L F U N C T I O N S + *---------------------------------------------------------------------------------------- + */ + IDS_STATUS +STATIC +IdsReplaceIdtr ( + IN OUT AMD_CONFIG_PARAMS *StdHeader + ); + +IDS_STATUS +STATIC +IdsRestoreIdtr ( + IN OUT AMD_CONFIG_PARAMS *StdHeader + ); + +IDS_STATUS +STATIC +IdsUpdateExceptionVector ( + IN VOID *DataPtr, + IN OUT AMD_CONFIG_PARAMS *StdHeader + ); + +/*---------------------------------------------------------------------------------------- + * E X P O R T E D F U N C T I O N S + *---------------------------------------------------------------------------------------- + */ +extern UINT64 IdsExceptionHandler; +extern UINT32 SizeIdtDescriptor; +extern UINT32 SizeTotalIdtDescriptors; + +/** + * IDS IDT table. + * + * This is the top level interface for IDS IDT table function. + * Adding a 'jmp $' into every exception handler. + * So debugger could use HDT to skip 'jmp $' and execute the iret, + * then they could find which instruction cause the exception. + * + * @param[in] IdsIdtFuncId IDT indicator value, see @ref IDS_IDT_FUNC_ID + * @param[in] DataPtr Points to data that may used by IdsIdtTable routine + * @param[in,out] StdHeader The Pointer of AMD_CONFIG_PARAMS. + * + * @retval IDS_SUCCESS Backend function is called successfully. + * @retval IDS_UNSUPPORTED No Backend function is found. + **/ +IDS_STATUS +IdsExceptionTrap ( + IN IDS_IDT_FUNC_ID IdsIdtFuncId, + IN VOID *DataPtr, + IN OUT AMD_CONFIG_PARAMS *StdHeader + ) +{ + IDS_STATUS ReturnFlag; + AGESA_STATUS Ignored; + + ReturnFlag = IDS_SUCCESS; + switch (IdsIdtFuncId) { + case IDS_IDT_REPLACE_IDTR_FOR_BSC: + if (IsBsp (StdHeader, &Ignored)) { + ReturnFlag = IdsReplaceIdtr (StdHeader); + } + break; + case IDS_IDT_RESTORE_IDTR_FOR_BSC: + if (IsBsp (StdHeader, &Ignored)) { + ReturnFlag = IdsRestoreIdtr (StdHeader); + } + break; + case IDS_IDT_UPDATE_EXCEPTION_VECTOR_FOR_AP: + ReturnFlag = IdsUpdateExceptionVector (DataPtr, StdHeader); + break; + default: + return IDS_UNSUPPORTED; + break; + } + return ReturnFlag; +} + +/*--------------------------------------------------------------------------------------- + * L O C A L F U N C T I O N S + *--------------------------------------------------------------------------------------- + */ + +/** + * Replace IDTR of BSC. + * + * Save IDTR of BSC to heap and replace IDTR. + * + * @param[in,out] StdHeader The Pointer of AMD_CONFIG_PARAMS. + * + * @retval IDS_SUCCESS Backend function is called successfully. + * @retval IDS_UNSUPPORTED No Backend function is found. + **/ +IDS_STATUS +STATIC +IdsReplaceIdtr ( + IN OUT AMD_CONFIG_PARAMS *StdHeader + ) +{ + ALLOCATE_HEAP_PARAMS AllocParams; + LOCATE_HEAP_PTR LocateHeap; + IDT_BASE_LIMIT IdtInfo; + + // Save IDTR to Heap + AllocParams.BufferHandle = IDS_SAVE_IDTR_HANDLE; + AllocParams.RequestedBufferSize = sizeof (IDT_BASE_LIMIT); + AllocParams.Persist = HEAP_TEMP_MEM; + if (HeapAllocateBuffer (&AllocParams, StdHeader) != AGESA_SUCCESS) { + return IDS_UNSUPPORTED; + } + GetIdtr ((IDT_BASE_LIMIT *) AllocParams.BufferPtr, StdHeader); + + // Check if host env has their own IDT + if (((IDT_BASE_LIMIT *) AllocParams.BufferPtr)->Base == 0) { + // Load AGESA's IDT + LocateHeap.BufferHandle = IDS_BSC_IDT_HANDLE; + // Check if we already allocated heap for creating IDT + if (HeapLocateBuffer (&LocateHeap, StdHeader) != AGESA_SUCCESS) { + // Create IDT for BSC in heap + AllocParams.BufferHandle = IDS_BSC_IDT_HANDLE; + AllocParams.RequestedBufferSize = sizeof (IDT_DESCRIPTOR) * 32; + AllocParams.Persist = HEAP_SYSTEM_MEM; + if (HeapAllocateBuffer (&AllocParams, StdHeader) != AGESA_SUCCESS) { + return IDS_UNSUPPORTED; + } + IdtInfo.Base = (UINT64) AllocParams.BufferPtr; + } else { + IdtInfo.Base = (UINT64) LocateHeap.BufferPtr; + } + IdsUpdateExceptionVector ((VOID *) &IdtInfo, StdHeader); + SetIdtr (&IdtInfo, StdHeader); + } else { + return IDS_UNSUPPORTED; + } + return IDS_SUCCESS; +} + +/** + * Restore IDTR of BSC. + * + * Restore IDTR of BSC from heap. + * + * @param[in,out] StdHeader The Pointer of AMD_CONFIG_PARAMS. + * + * @retval IDS_SUCCESS Backend function is called successfully. + * @retval IDS_UNSUPPORTED No Backend function is found. + **/ +IDS_STATUS +STATIC +IdsRestoreIdtr ( + IN OUT AMD_CONFIG_PARAMS *StdHeader + ) +{ + LOCATE_HEAP_PTR LocateHeap; + IDT_BASE_LIMIT IdtInfo; + + IdtInfo.Base = 0; + IdtInfo.Limit = 0; + GetIdtr (&IdtInfo, StdHeader); + + LocateHeap.BufferHandle = IDS_BSC_IDT_HANDLE; + if (HeapLocateBuffer (&LocateHeap, StdHeader) != AGESA_SUCCESS) { + // If AGESA loaded its own IDT, there must be a buffer with handle IDS_BSC_IDT_HANDLE in heap + return IDS_UNSUPPORTED; + } + // If current IDTR.Base != address of AGESA's own IDT, it is possibile that Host env load their own IDT + if (IdtInfo.Base != ((UINT64) (LocateHeap.BufferPtr))) { + return IDS_UNSUPPORTED; + } else { + LocateHeap.BufferHandle = IDS_SAVE_IDTR_HANDLE; + if (HeapLocateBuffer (&LocateHeap, StdHeader) != AGESA_SUCCESS) { + return IDS_UNSUPPORTED; + } + SetIdtr ((IDT_BASE_LIMIT *) LocateHeap.BufferPtr, StdHeader); + HeapDeallocateBuffer (IDS_SAVE_IDTR_HANDLE, StdHeader); + } + return IDS_SUCCESS; +} + +/** + * Update exception vector. + * + * Adding a 'jmp $' into every exception handler. + * So debugger could use HDT to skip 'jmp $' and execute the iret, + * then they could find which instruction cause the exception. + * + * @param[in,out] StdHeader The Pointer of AMD_CONFIG_PARAMS. + * + * @retval IDS_SUCCESS Backend function is called successfully. + * @retval IDS_UNSUPPORTED No Backend function is found. + **/ +IDS_STATUS +STATIC +IdsUpdateExceptionVector ( + IN VOID *DataPtr, + IN OUT AMD_CONFIG_PARAMS *StdHeader + ) +{ + IDT_DESCRIPTOR *IdtDesc; + UINT8 DescSize; + UINT16 Selector; + UINT16 i; + UINT64 HandlerOffset; + UINT64 EferRegister; + AGESA_STATUS Ignored; + + LibAmdMsrRead (MSR_EXTENDED_FEATURE_EN, &EferRegister, StdHeader); + if ((EferRegister & 0x100) != 0) { + DescSize = 16; + } else { + DescSize = 8; + } + + // Update limit + ((IDT_BASE_LIMIT *) DataPtr)->Limit = (UINT16) ((DescSize * 32) - 1); + // Update IDT + IdtDesc = (IDT_DESCRIPTOR *) (((IDT_BASE_LIMIT *) DataPtr)->Base); + HandlerOffset = (UINT64) IdsExceptionHandler; + GetCsSelector (&Selector, StdHeader); + + ASSERT (SizeTotalIdtDescriptors == (SizeIdtDescriptor * 32)); + for (i = 0; i < 32; i++) { + // Vector - 2 NMI handler for APs is used by AGESA. So we should not replace that handler. + if ((i == 2) && (!IsBsp (StdHeader, &Ignored))) { + IdtDesc = (IDT_DESCRIPTOR *) (((UINT8 *) IdtDesc) + DescSize); + HandlerOffset += SizeIdtDescriptor; + continue; + } + IdtDesc->OffsetLo = (UINT16) HandlerOffset & 0xFFFF; + IdtDesc->OffsetHi = (UINT16) (HandlerOffset >> 16); + IdtDesc->Flags = IDT_DESC_PRESENT | IDT_DESC_TYPE_INT32; + IdtDesc->Selector = Selector; + IdtDesc->Rsvd = 0; + if ((EferRegister & 0x100) != 0) { + IdtDesc->Offset64 = (UINT32) (HandlerOffset >> 32); + IdtDesc->Rsvd64 = 0; + } + IdtDesc = (IDT_DESCRIPTOR *) (((UINT8 *) IdtDesc) + DescSize); + HandlerOffset += SizeIdtDescriptor; + } + return IDS_SUCCESS; +} + |