From 4d0da5fb769cb38a215daa1e42d46400c59f9711 Mon Sep 17 00:00:00 2001 From: Liming Gao Date: Fri, 15 Nov 2013 02:05:15 +0000 Subject: Add support for PI1.2.1 TempRam Done PPI. Signed-off-by: Liming Gao Reviewed-by: Jeff Fan git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14848 6f19259b-4bc3-4df7-8a09-765794883524 --- .../SecPeiDebugAgent/SecPeiDebugAgentLib.c | 59 +++++++++++++++++----- 1 file changed, 46 insertions(+), 13 deletions(-) (limited to 'SourceLevelDebugPkg') diff --git a/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c b/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c index c253fa59a3..d036880c1d 100644 --- a/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c +++ b/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c @@ -348,6 +348,7 @@ InitializeDebugAgent ( ) { DEBUG_AGENT_MAILBOX *Mailbox; + DEBUG_AGENT_MAILBOX *NewMailbox; DEBUG_AGENT_MAILBOX MailboxInStack; DEBUG_AGENT_PHASE2_CONTEXT Phase2Context; DEBUG_AGENT_CONTEXT_POSTMEM_SEC *DebugAgentContext; @@ -357,6 +358,7 @@ InitializeDebugAgent ( UINT64 DebugPortHandle; UINT64 MailboxLocation; UINT64 *MailboxLocationPointer; + EFI_PHYSICAL_ADDRESS Address; DisableInterrupts (); @@ -411,19 +413,50 @@ InitializeDebugAgent ( // Fix up Debug Port handle address and mailbox address // DebugAgentContext = (DEBUG_AGENT_CONTEXT_POSTMEM_SEC *) Context; - DebugPortHandle = (UINT64)(UINT32)(Mailbox->DebugPortHandle + DebugAgentContext->StackMigrateOffset); - UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle); - Mailbox = (DEBUG_AGENT_MAILBOX *) ((UINTN) Mailbox + DebugAgentContext->StackMigrateOffset); - MailboxLocation = (UINT64)(UINTN)Mailbox; - // - // Build mailbox location in HOB and fix-up its address - // - MailboxLocationPointer = BuildGuidDataHob ( - &gEfiDebugAgentGuid, - &MailboxLocation, - sizeof (UINT64) - ); - MailboxLocationPointer = (UINT64 *) ((UINTN) MailboxLocationPointer + DebugAgentContext->HeapMigrateOffset); + if (DebugAgentContext != NULL) { + DebugPortHandle = (UINT64)(UINT32)(Mailbox->DebugPortHandle + DebugAgentContext->StackMigrateOffset); + UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle); + Mailbox = (DEBUG_AGENT_MAILBOX *) ((UINTN) Mailbox + DebugAgentContext->StackMigrateOffset); + MailboxLocation = (UINT64)(UINTN)Mailbox; + // + // Build mailbox location in HOB and fix-up its address + // + MailboxLocationPointer = BuildGuidDataHob ( + &gEfiDebugAgentGuid, + &MailboxLocation, + sizeof (UINT64) + ); + MailboxLocationPointer = (UINT64 *) ((UINTN) MailboxLocationPointer + DebugAgentContext->HeapMigrateOffset); + } else { + // + // DebugAgentContext is NULL. Then, Mailbox can directly be copied into memory. + // Allocate ACPI NVS memory for new Mailbox and Debug Port Handle buffer + // + Status = PeiServicesAllocatePages ( + EfiACPIMemoryNVS, + EFI_SIZE_TO_PAGES (sizeof(DEBUG_AGENT_MAILBOX) + PcdGet16(PcdDebugPortHandleBufferSize)), + &Address + ); + ASSERT_EFI_ERROR (Status); + NewMailbox = (DEBUG_AGENT_MAILBOX *) (UINTN) Address; + // + // Copy Mailbox and Debug Port Handle buffer to new location in ACPI NVS memory, because original Mailbox + // and Debug Port Handle buffer in the allocated pool that may be marked as free by DXE Core after DXE Core + // reallocates the HOB. + // + CopyMem (NewMailbox, Mailbox, sizeof (DEBUG_AGENT_MAILBOX)); + CopyMem (NewMailbox + 1, (VOID *)(UINTN)Mailbox->DebugPortHandle, PcdGet16(PcdDebugPortHandleBufferSize)); + UpdateMailboxContent (NewMailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, (UINT64)(UINTN)(NewMailbox + 1)); + MailboxLocation = (UINT64)(UINTN)NewMailbox; + // + // Build mailbox location in HOB + // + MailboxLocationPointer = BuildGuidDataHob ( + &gEfiDebugAgentGuid, + &MailboxLocation, + sizeof (UINT64) + ); + } // // Update IDT entry to save the location saved mailbox pointer // -- cgit v1.2.3