diff options
Diffstat (limited to 'SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent')
3 files changed, 511 insertions, 199 deletions
diff --git a/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c b/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c index f8e3f6c1ab..35c6acfd9d 100644 --- a/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c +++ b/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c @@ -1,7 +1,7 @@ /** @file
Debug Agent library implementition for Dxe Core and Dxr modules.
- Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -15,57 +15,51 @@ #include "DxeDebugAgentLib.h"
DEBUG_AGENT_MAILBOX mMailbox;
-DEBUG_AGENT_MAILBOX *mMailboxPointer;
+DEBUG_AGENT_MAILBOX *mMailboxPointer = NULL;
IA32_IDT_GATE_DESCRIPTOR mIdtEntryTable[33];
-BOOLEAN mDxeCoreFlag = FALSE;
-CONST BOOLEAN MultiProcessorDebugSupport = TRUE;
+BOOLEAN mDxeCoreFlag = FALSE;
+BOOLEAN mMultiProcessorDebugSupport = FALSE;
+VOID *mSavedIdtTable = NULL;
+UINTN mSaveIdtTableSize = 0;
+BOOLEAN mDebugAgentInitialized = FALSE;
+BOOLEAN mSkipBreakpoint = FALSE;
/**
- Constructor allocates the NVS memory to store Mailbox and install configuration table
- in system table to store its pointer.
+ Check if debug agent support multi-processor.
- @param[in] ImageHandle The firmware allocated handle for the EFI image.
- @param[in] SystemTable A pointer to the EFI System Table.
+ @retval TRUE Multi-processor is supported.
+ @retval FALSE Multi-processor is not supported.
+
+**/
+BOOLEAN
+MultiProcessorDebugSupport (
+ VOID
+ )
+{
+ return mMultiProcessorDebugSupport;
+}
- @retval RETURN_SUCCESS Allocate the global memory space to store guid and function tables.
+/**
+ Internal constructor worker function.
+
+ It will register one callback function on EFI PCD Protocol.
+ It will allocate the NVS memory to store Mailbox and install configuration table
+ in system table to store its pointer.
**/
-RETURN_STATUS
-EFIAPI
-DxeDebugAgentLibConstructor (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+VOID
+InternalConstructorWorker (
+ VOID
)
{
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS Address;
- EFI_EVENT Event;
- VOID *EventRegistration;
-
- if (!mDxeCoreFlag) {
- return RETURN_SUCCESS;
- }
-
- Status = gBS->CreateEvent (
- EVT_NOTIFY_SIGNAL,
- TPL_CALLBACK,
- InstallSerialIoNotification,
- NULL,
- &Event
- );
- ASSERT_EFI_ERROR (Status);
+ BOOLEAN DebugTimerInterruptState;
//
- // Register for protocol notifications on this event
+ // Install EFI Serial IO protocol on debug port
//
-
- Status = gBS->RegisterProtocolNotify (
- &gEfiPcdProtocolGuid,
- Event,
- &EventRegistration
- );
-
- ASSERT_EFI_ERROR (Status);
+ InstallSerialIo ();
Address = 0;
Status = gBS->AllocatePages (
@@ -76,18 +70,67 @@ DxeDebugAgentLibConstructor ( );
ASSERT_EFI_ERROR (Status);
+ DebugTimerInterruptState = SaveAndSetDebugTimerInterrupt (FALSE);
CopyMem (
(UINT8 *) (UINTN) Address,
- (UINT8 *) (UINTN) mMailboxPointer,
+ (UINT8 *) (UINTN) GetMailboxPointer (),
sizeof (DEBUG_AGENT_MAILBOX)
);
+ DebugTimerInterruptState = SaveAndSetDebugTimerInterrupt (DebugTimerInterruptState);
mMailboxPointer = (DEBUG_AGENT_MAILBOX *) (UINTN) Address;
Status = gBS->InstallConfigurationTable (&gEfiDebugAgentGuid, (VOID *) mMailboxPointer);
ASSERT_EFI_ERROR (Status);
+}
+
+/**
+ Debug Agent constructor function.
+
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.
+ @param[in] SystemTable A pointer to the EFI System Table.
+
+ @retval RETURN_SUCCESS When this function completed.
+
+**/
+RETURN_STATUS
+EFIAPI
+DxeDebugAgentLibConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ if (mDxeCoreFlag) {
+ //
+ // Invoke internal constructor function only when DXE core links this library instance
+ //
+ InternalConstructorWorker ();
+ }
+
+ return RETURN_SUCCESS;
+}
+
+/**
+ Get the pointer to Mailbox from the configuration table.
+
+ @return Pointer to Mailbox.
+
+**/
+DEBUG_AGENT_MAILBOX *
+GetMailboxFromConfigurationTable (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ DEBUG_AGENT_MAILBOX *Mailbox;
- return Status;
+ Status = EfiGetSystemConfigurationTable (&gEfiDebugAgentGuid, (VOID **) &Mailbox);
+ if (Status == EFI_SUCCESS && Mailbox != NULL) {
+ VerifyMailboxChecksum (Mailbox);
+ return Mailbox;
+ } else {
+ return NULL;
+ }
}
/**
@@ -104,13 +147,18 @@ GetMailboxFromHob ( )
{
EFI_HOB_GUID_TYPE *GuidHob;
+ UINT64 *MailboxLocation;
+ DEBUG_AGENT_MAILBOX *Mailbox;
GuidHob = GetNextGuidHob (&gEfiDebugAgentGuid, HobStart);
if (GuidHob == NULL) {
return NULL;
}
+ MailboxLocation = (UINT64 *) (GET_GUID_HOB_DATA(GuidHob));
+ Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);
+ VerifyMailboxChecksum (Mailbox);
- return (DEBUG_AGENT_MAILBOX *) (GET_GUID_HOB_DATA(GuidHob));
+ return Mailbox;
}
/**
@@ -124,6 +172,9 @@ GetMailboxPointer ( VOID
)
{
+ AcquireMpSpinLock (&mDebugMpContext.MailboxSpinLock);
+ VerifyMailboxChecksum (mMailboxPointer);
+ ReleaseMpSpinLock (&mDebugMpContext.MailboxSpinLock);
return mMailboxPointer;
}
@@ -138,10 +189,86 @@ GetDebugPortHandle ( VOID
)
{
- return (DEBUG_PORT_HANDLE) (UINTN)(mMailboxPointer->DebugPortHandle);
+ return (DEBUG_PORT_HANDLE) (UINTN)(GetMailboxPointer ()->DebugPortHandle);
+}
+
+/**
+ Worker function to setup IDT table and initialize the IDT entries.
+
+ @param[in] Mailbox Pointer to Mailbox.
+
+**/
+VOID
+SetupDebugAgentEnviroment (
+ IN DEBUG_AGENT_MAILBOX *Mailbox
+ )
+{
+ IA32_DESCRIPTOR Idtr;
+ UINT16 IdtEntryCount;
+ UINT64 DebugPortHandle;
+
+ if (mMultiProcessorDebugSupport) {
+ InitializeSpinLock (&mDebugMpContext.MpContextSpinLock);
+ InitializeSpinLock (&mDebugMpContext.DebugPortSpinLock);
+ InitializeSpinLock (&mDebugMpContext.MailboxSpinLock);
+ //
+ // Clear Break CPU index value
+ //
+ mDebugMpContext.BreakAtCpuIndex = (UINT32) -1;
+ }
+
+ //
+ // Get original IDT address and size.
+ //
+ AsmReadIdtr ((IA32_DESCRIPTOR *) &Idtr);
+ IdtEntryCount = (UINT16) ((Idtr.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR));
+ if (IdtEntryCount < 33) {
+ Idtr.Limit = (UINT16) (sizeof (IA32_IDT_GATE_DESCRIPTOR) * 33 - 1);
+ Idtr.Base = (UINTN) &mIdtEntryTable;
+ ZeroMem (&mIdtEntryTable, Idtr.Limit + 1);
+ AsmWriteIdtr ((IA32_DESCRIPTOR *) &Idtr);
+ }
+
+ //
+ // Initialize the IDT table entries to support source level debug.
+ //
+ InitializeDebugIdt ();
+
+ if (Mailbox != NULL) {
+ //
+ // If Mailbox exists, copy it into one global variable,
+ //
+ CopyMem (&mMailbox, Mailbox, sizeof (DEBUG_AGENT_MAILBOX));
+ } else {
+ ZeroMem (&mMailbox, sizeof (DEBUG_AGENT_MAILBOX));
+ }
+
+ mMailboxPointer = &mMailbox;
+ //
+ // Initialize debug communication port
+ //
+ DebugPortHandle = (UINT64) (UINTN)DebugPortInitialize ((VOID *)(UINTN)mMailboxPointer->DebugPortHandle, NULL);
+ UpdateMailboxContent (mMailboxPointer, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle);
+
+ if (Mailbox == NULL) {
+ //
+ // Trigger one software interrupt to inform HOST
+ //
+ TriggerSoftInterrupt (SYSTEM_RESET_SIGNATURE);
+ SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY, 1);
+ //
+ // Memory has been ready
+ //
+ if (IsHostAttached ()) {
+ //
+ // Trigger one software interrupt to inform HOST
+ //
+ TriggerSoftInterrupt (MEMORY_READY_SIGNATURE);
+ }
+ }
}
-
+
/**
Initialize debug agent.
@@ -167,105 +294,207 @@ InitializeDebugAgent ( IN DEBUG_AGENT_CONTINUE Function OPTIONAL
)
{
+ UINT64 *MailboxLocation;
DEBUG_AGENT_MAILBOX *Mailbox;
- IA32_DESCRIPTOR Idtr;
- UINT16 IdtEntryCount;
BOOLEAN InterruptStatus;
+ VOID *HobList;
+ IA32_DESCRIPTOR IdtDescriptor;
+ IA32_DESCRIPTOR *Ia32Idtr;
+ IA32_IDT_ENTRY *Ia32IdtEntry;
- if (InitFlag != DEBUG_AGENT_INIT_DXE_CORE &&
- InitFlag != DEBUG_AGENT_INIT_S3 &&
- InitFlag != DEBUG_AGENT_INIT_DXE_AP) {
- return;
+ if (InitFlag == DEBUG_AGENT_INIT_DXE_AP) {
+ //
+ // Invoked by AP, enable interrupt to let AP could receive IPI from other processors
+ //
+ EnableInterrupts ();
+ return ;
}
+ //
+ // Disable Debug Timer interrupt
+ //
+ SaveAndSetDebugTimerInterrupt (FALSE);
//
// Save and disable original interrupt status
//
InterruptStatus = SaveAndDisableInterrupts ();
- if (InitFlag == DEBUG_AGENT_INIT_DXE_CORE) {
+ //
+ // Try to get mailbox firstly
+ //
+ HobList = NULL;
+ Mailbox = NULL;
+ MailboxLocation = NULL;
+
+ switch (InitFlag) {
+
+ case DEBUG_AGENT_INIT_DXE_LOAD:
//
- // Try to get Mailbox from GUIDed HOB.
+ // Check if Debug Agent has been initialized before
//
- mDxeCoreFlag = TRUE;
- Mailbox = GetMailboxFromHob (Context);
-
+ if (IsDebugAgentInitialzed ()) {
+ DEBUG ((EFI_D_INFO, "Debug Agent: The former agent will be overwritten by the new one!\n"));
+ }
+
+ mMultiProcessorDebugSupport = TRUE;
//
- // Clear Break CPU index value
+ // Save original IDT table
+ //
+ AsmReadIdtr (&IdtDescriptor);
+ mSaveIdtTableSize = IdtDescriptor.Limit + 1;
+ mSavedIdtTable = AllocateCopyPool (mSaveIdtTableSize, (VOID *) IdtDescriptor.Base);
+ //
+ // Initialize Debug Timer hardware
+ //
+ InitializeDebugTimer ();
+ //
+ // Check if Debug Agent initialized in DXE phase
+ //
+ Mailbox = GetMailboxFromConfigurationTable ();
+ if (Mailbox == NULL) {
+ //
+ // Try to get mailbox from GUIDed HOB build in PEI
+ //
+ HobList = GetHobList ();
+ Mailbox = GetMailboxFromHob (HobList);
+ }
+ //
+ // Set up IDT table and prepare for IDT entries
+ //
+ SetupDebugAgentEnviroment (Mailbox);
+ //
+ // For DEBUG_AGENT_INIT_S3, needn't to install configuration table and EFI Serial IO protocol
+ // For DEBUG_AGENT_INIT_DXE_CORE, InternalConstructorWorker() will invoked in Constructor()
+ //
+ InternalConstructorWorker ();
+ //
+ // Enable interrupt to receive Debug Timer interrupt
//
- mDebugMpContext.BreakAtCpuIndex = (UINT32) -1;
-
- } else if (InitFlag == DEBUG_AGENT_INIT_DXE_AP) {
-
EnableInterrupts ();
- return;
+ mDebugAgentInitialized = TRUE;
+ FindAndReportModuleImageInfo (SIZE_4KB);
+
+ *(EFI_STATUS *)Context = EFI_SUCCESS;
+
+ if (gST->ConOut != NULL) {
+ Print (L"Debug Agent: Initialized successfully!\r\n");
+ Print (L"If the Debug Port is serial port, please make sure this serial port isn't connected by ISA Serial driver\r\n");
+ Print (L"You could do the following steps to disconnect the serial port:\r\n");
+ Print (L"1: Shell> drivers\r\n");
+ Print (L" ...\r\n");
+ Print (L" V VERSION E G G #D #C DRIVER NAME IMAGE NAME\r\n");
+ Print (L" == ======== = = = == == =================================== ===================\r\n");
+ Print (L" 8F 0000000A B - - 1 14 PCI Bus Driver PciBusDxe\r\n");
+ Print (L" 91 00000010 ? - - - - ATA Bus Driver AtaBusDxe\r\n");
+ Print (L" ...\r\n");
+ Print (L" A7 0000000A B - - 1 1 ISA Serial Driver IsaSerialDxe\r\n");
+ Print (L" ...\r\n");
+ Print (L"2: Shell> dh -d A7\r\n");
+ Print (L" A7: Image(IsaSerialDxe) ImageDevPath (..9FB3-11D4-9A3A-0090273FC14D))DriverBinding ComponentName ComponentName2\r\n");
+ Print (L" Driver Name : ISA Serial Driver\r\n");
+ Print (L" Image Name : FvFile(93B80003-9FB3-11D4-9A3A-0090273FC14D)\r\n");
+ Print (L" Driver Version : 0000000A\r\n");
+ Print (L" Driver Type : BUS\r\n");
+ Print (L" Configuration : NO\r\n");
+ Print (L" Diagnostics : NO\r\n");
+ Print (L" Managing :\r\n");
+ Print (L" Ctrl[EA] : PciRoot(0x0)/Pci(0x1F,0x0)/Serial(0x0)\r\n");
+ Print (L" Child[EB] : PciRoot(0x0)/Pci(0x1F,0x0)/Serial(0x0)/Uart(115200,8,N,1)\r\n");
+ Print (L"3: Shell> disconnect EA\r\n");
+ Print (L"4: Shell> load -nc DebugAgentDxe.efi\r\n\r\n");
+ }
+ break;
+
+ case DEBUG_AGENT_INIT_DXE_UNLOAD:
+ if (mDebugAgentInitialized) {
+ if (IsHostAttached ()) {
+ Print (L"Debug Agent: Host is still connected, please de-attach TARGET firstly!\r\n");
+ *(EFI_STATUS *)Context = EFI_ACCESS_DENIED;
+ //
+ // Enable Debug Timer interrupt again
+ //
+ SaveAndSetDebugTimerInterrupt (TRUE);
+ } else {
+ //
+ // Restore original IDT table
+ //
+ AsmReadIdtr (&IdtDescriptor);
+ IdtDescriptor.Limit = (UINT16) (mSaveIdtTableSize - 1);
+ CopyMem ((VOID *) IdtDescriptor.Base, mSavedIdtTable, mSaveIdtTableSize);
+ AsmWriteIdtr (&IdtDescriptor);
+ FreePool (mSavedIdtTable);
+ mDebugAgentInitialized = FALSE;
+ *(EFI_STATUS *)Context = EFI_SUCCESS;
+ }
+ } else {
+ Print (L"Debug Agent: It hasn't been initialized, cannot unload it!\r\n");
+ *(EFI_STATUS *)Context = EFI_NOT_STARTED;
+ }
- } else {
//
- // If it is in S3 path, needn't to install configuration table.
+ // Restore interrupt state.
//
- Mailbox = NULL;
- }
+ SetInterruptState (InterruptStatus);
+ break;
- if (Mailbox != NULL) {
+ case DEBUG_AGENT_INIT_DXE_CORE:
+ mDxeCoreFlag = TRUE;
+ mMultiProcessorDebugSupport = TRUE;
//
- // If Mailbox exists, copy it into one global variable.
+ // Initialize Debug Timer hardware
//
- CopyMem (&mMailbox, Mailbox, sizeof (DEBUG_AGENT_MAILBOX));
- } else {
+ InitializeDebugTimer ();
//
- // If Mailbox not exists, used the local Mailbox.
+ // Try to get mailbox from GUIDed HOB build in PEI
//
- ZeroMem (&mMailbox, sizeof (DEBUG_AGENT_MAILBOX));
- }
-
- mMailboxPointer = &mMailbox;
-
- //
- // Get original IDT address and size.
- //
- AsmReadIdtr ((IA32_DESCRIPTOR *) &Idtr);
- IdtEntryCount = (UINT16) ((Idtr.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR));
- if (IdtEntryCount < 33) {
- Idtr.Limit = (UINT16) (sizeof (IA32_IDT_GATE_DESCRIPTOR) * 33 - 1);
- Idtr.Base = (UINTN) &mIdtEntryTable;
- ZeroMem (&mIdtEntryTable, Idtr.Limit + 1);
- AsmWriteIdtr ((IA32_DESCRIPTOR *) &Idtr);
- }
+ HobList = Context;
+ Mailbox = GetMailboxFromHob (HobList);
+ //
+ // Set up IDT table and prepare for IDT entries
+ //
+ SetupDebugAgentEnviroment (Mailbox);
+ //
+ // Enable interrupt to receive Debug Timer interrupt
+ //
+ EnableInterrupts ();
- //
- // Initialize the IDT table entries to support source level debug.
- //
- InitializeDebugIdt ();
+ break;
- //
- // Initialize debug communication port
- //
- mMailboxPointer->DebugPortHandle = (UINT64) (UINTN)DebugPortInitialize ((VOID *)(UINTN)mMailbox.DebugPortHandle, NULL);
+ case DEBUG_AGENT_INIT_S3:
- InitializeSpinLock (&mDebugMpContext.MpContextSpinLock);
- InitializeSpinLock (&mDebugMpContext.DebugPortSpinLock);
-
- if (InitFlag == DEBUG_AGENT_INIT_DXE_CORE) {
+ if (Context != NULL) {
+ Ia32Idtr = (IA32_DESCRIPTOR *) Context;
+ Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base);
+ MailboxLocation = (UINT64 *) (UINTN) (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +
+ (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));
+ Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);
+ VerifyMailboxChecksum (Mailbox);
+ }
//
- // Initialize Debug Timer hardware and enable interrupt.
+ // Set up IDT table and prepare for IDT entries
//
- InitializeDebugTimer ();
- EnableInterrupts ();
-
- return;
- } else {
+ SetupDebugAgentEnviroment (Mailbox);
//
- // Disable Debug Timer interrupt in S3 path.
+ // Disable interrupt
//
- SaveAndSetDebugTimerInterrupt (FALSE);
-
+ DisableInterrupts ();
+ FindAndReportModuleImageInfo (SIZE_4KB);
+ if (GetDebugFlag (DEBUG_AGENT_FLAG_BREAK_BOOT_SCRIPT) == 1) {
+ //
+ // If Boot Script entry break is set, code will be break at here.
+ //
+ CpuBreakpoint ();
+ }
+ break;
+
+ default:
//
- // Restore interrupt state.
+ // Only DEBUG_AGENT_INIT_PREMEM_SEC and DEBUG_AGENT_INIT_POSTMEM_SEC are allowed for this
+ // Debug Agent library instance.
//
- SetInterruptState (InterruptStatus);
+ DEBUG ((EFI_D_ERROR, "Debug Agent: The InitFlag value is not allowed!\n"));
+ CpuDeadLoop ();
+ break;
}
-
}
-
diff --git a/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.h b/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.h index ab561812cd..536fb71dc5 100644 --- a/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.h +++ b/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.h @@ -1,7 +1,7 @@ /** @file
Header file for Dxe Core Debug Agent Library instance.
- Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -24,22 +24,17 @@ #include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/DevicePathLib.h>
+#include <Library/MemoryAllocationLib.h>
#include "DebugAgent.h"
/**
- Notification function on EFI PCD protocol to install EFI Serial IO protocol based
- on Debug Communication Library.
-
- @param[in] Event The event of notify protocol.
- @param[in] Context Notify event context.
+ Install EFI Serial IO protocol based on Debug Communication Library.
**/
VOID
-EFIAPI
-InstallSerialIoNotification (
- IN EFI_EVENT Event,
- IN VOID *Context
+InstallSerialIo (
+ VOID
);
#endif
diff --git a/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/SerialIo.c b/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/SerialIo.c index 0cb7c52554..9b181e3ac7 100644 --- a/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/SerialIo.c +++ b/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/SerialIo.c @@ -1,7 +1,7 @@ /** @file
Install Serial IO Protocol that layers on top of a Debug Communication Library instance.
- Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2012 - 2013, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -149,11 +149,11 @@ SerialRead ( EFI_SERIAL_IO_MODE mSerialIoMode = {
SERIAL_PORT_DEFAULT_CONTROL_MASK,
SERIAL_PORT_DEFAULT_TIMEOUT,
- 0, // BaudRate
+ 0, // default BaudRate
SERIAL_PORT_DEFAULT_RECEIVE_FIFO_DEPTH,
- 0, // DataBits
- 0, // Parity
- 0 // StopBits
+ 0, // default DataBits
+ 0, // default Parity
+ 0 // default StopBits
};
//
@@ -204,10 +204,10 @@ SERIAL_IO_DEVICE_PATH mSerialIoDevicePath = { }
},
0,
- 0, // BaudRate
- 0, // DataBits
- 0, // Parity
- 0, // StopBits
+ 0, // default BaudRate
+ 0, // default DataBits
+ 0, // default Parity
+ 0, // default StopBits
},
{
END_DEVICE_PATH_TYPE,
@@ -357,34 +357,15 @@ DebugTerminalFifoRemove ( }
/**
- Notification function on EFI PCD protocol to install EFI Serial IO protocol based
- on Debug Communication Library.
-
- @param[in] Event The event of notify protocol.
- @param[in] Context Notify event context.
+ Install EFI Serial IO protocol based on Debug Communication Library.
**/
VOID
-EFIAPI
-InstallSerialIoNotification (
- IN EFI_EVENT Event,
- IN VOID *Context
+InstallSerialIo (
+ VOID
)
{
- EFI_STATUS Status;
-
- //
- // Get Debug Port parameters from PCDs
- //
- mSerialIoDevicePath.UartDevicePath.BaudRate = PcdGet64 (PcdUartDefaultBaudRate);
- mSerialIoDevicePath.UartDevicePath.DataBits = PcdGet8 (PcdUartDefaultDataBits);
- mSerialIoDevicePath.UartDevicePath.Parity = PcdGet8 (PcdUartDefaultParity);
- mSerialIoDevicePath.UartDevicePath.StopBits = PcdGet8 (PcdUartDefaultStopBits);
-
- mSerialIoMode.BaudRate = mSerialIoDevicePath.UartDevicePath.BaudRate;
- mSerialIoMode.DataBits = mSerialIoDevicePath.UartDevicePath.DataBits;
- mSerialIoMode.Parity = mSerialIoDevicePath.UartDevicePath.Parity;
- mSerialIoMode.StopBits = mSerialIoDevicePath.UartDevicePath.StopBits;
+ EFI_STATUS Status;
Status = gBS->InstallMultipleProtocolInterfaces (
&mSerialIoHandle,
@@ -448,22 +429,10 @@ SerialSetAttributes ( )
{
//
- // The Debug Communication Library does not support changing communications parameters, so unless
- // the request is to use the default value or the value the Debug Communication Library is already
- // using, then return EFI_INVALID_PARAMETER.
+ // The Debug Communication Library CAN NOT change communications parameters (if it has)
+ // actually. Because it also has no any idea on what parameters are based on, we cannot
+ // check the input parameters (like BaudRate, Parity, DataBits and StopBits).
//
- if (BaudRate != 0 && BaudRate != PcdGet64 (PcdUartDefaultBaudRate)) {
- return EFI_INVALID_PARAMETER;
- }
- if (Parity != DefaultParity && Parity != PcdGet8 (PcdUartDefaultParity)) {
- return EFI_INVALID_PARAMETER;
- }
- if (DataBits != 0 && DataBits != PcdGet8 (PcdUartDefaultDataBits)) {
- return EFI_INVALID_PARAMETER;
- }
- if (StopBits != DefaultStopBits && StopBits != PcdGet8 (PcdUartDefaultStopBits)) {
- return EFI_INVALID_PARAMETER;
- }
//
// Update the Timeout value in the mode structure based on the request.
@@ -536,7 +505,18 @@ SerialGetControl ( )
{
DEBUG_PORT_HANDLE Handle;
+ BOOLEAN DebugTimerInterruptState;
+ EFI_TPL Tpl;
+ //
+ // Raise TPL to prevent recursion from EFI timer interrupts
+ //
+ Tpl = gBS->RaiseTPL (TPL_NOTIFY);
+
+ //
+ // Save and disable Debug Timer interrupt to avoid it to access Debug Port
+ //
+ DebugTimerInterruptState = SaveAndSetDebugTimerInterrupt (FALSE);
Handle = GetDebugPortHandle ();
//
@@ -552,6 +532,17 @@ SerialGetControl ( if (!IsDebugTermianlFifoEmpty (&mSerialFifoForTerminal) || DebugPortPollBuffer (Handle)) {
*Control &= ~EFI_SERIAL_INPUT_BUFFER_EMPTY;
}
+
+ //
+ // Restore Debug Timer interrupt
+ //
+ SaveAndSetDebugTimerInterrupt (DebugTimerInterruptState);
+
+ //
+ // Restore to original TPL
+ //
+ gBS->RestoreTPL (Tpl);
+
return EFI_SUCCESS;
}
@@ -577,7 +568,18 @@ SerialWrite ( )
{
DEBUG_PORT_HANDLE Handle;
+ BOOLEAN DebugTimerInterruptState;
+ EFI_TPL Tpl;
+ //
+ // Raise TPL to prevent recursion from EFI timer interrupts
+ //
+ Tpl = gBS->RaiseTPL (TPL_NOTIFY);
+
+ //
+ // Save and disable Debug Timer interrupt to avoid it to access Debug Port
+ //
+ DebugTimerInterruptState = SaveAndSetDebugTimerInterrupt (FALSE);
Handle = GetDebugPortHandle ();
if ((mSerialIoMode.ControlMask & EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE) != 0) {
@@ -593,6 +595,17 @@ SerialWrite ( } else {
*BufferSize = DebugPortWriteBuffer (Handle, Buffer, *BufferSize);
}
+
+ //
+ // Restore Debug Timer interrupt
+ //
+ SaveAndSetDebugTimerInterrupt (DebugTimerInterruptState);
+
+ //
+ // Restore to original TPL
+ //
+ gBS->RestoreTPL (Tpl);
+
return EFI_SUCCESS;
}
@@ -620,17 +633,24 @@ SerialRead ( EFI_STATUS Status;
UINTN Index;
UINT8 *Uint8Buffer;
- BOOLEAN OldInterruptState;
+ BOOLEAN DebugTimerInterruptState;
+ EFI_TPL Tpl;
DEBUG_PORT_HANDLE Handle;
- UINT8 Data;
-
- Handle = GetDebugPortHandle ();
+ DEBUG_PACKET_HEADER DebugHeader;
+ UINT8 *Data8;
//
- // Save and disable Debug Timer interrupt to avoid it to access Debug Port
+ // Raise TPL to prevent recursion from EFI timer interrupts
//
- OldInterruptState = SaveAndSetDebugTimerInterrupt (FALSE);
+ Tpl = gBS->RaiseTPL (TPL_NOTIFY);
+ //
+ // Save and disable Debug Timer interrupt to avoid it to access Debug Port
+ //
+ DebugTimerInterruptState = SaveAndSetDebugTimerInterrupt (FALSE);
+ Handle = GetDebugPortHandle ();
+
+ Data8 = (UINT8 *) &DebugHeader;
Uint8Buffer = (UINT8 *)Buffer;
if ((mSerialIoMode.ControlMask & EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE) != 0) {
if ((mLoopbackBuffer & SERIAL_PORT_LOOPBACK_BUFFER_FULL) == 0) {
@@ -644,9 +664,9 @@ SerialRead ( //
// Read input character from terminal FIFO firstly
//
- Status = DebugTerminalFifoRemove (&mSerialFifoForTerminal, &Data);
+ Status = DebugTerminalFifoRemove (&mSerialFifoForTerminal, Data8);
if (Status == EFI_SUCCESS) {
- *Uint8Buffer = Data;
+ *Uint8Buffer = *Data8;
Uint8Buffer ++;
continue;
}
@@ -656,16 +676,25 @@ SerialRead ( if (!DebugPortPollBuffer (Handle)) {
break;
}
- DebugPortReadBuffer (Handle, &Data, 1, 0);
+ DebugPortReadBuffer (Handle, Data8, 1, 0);
- if (Data== DEBUG_STARTING_SYMBOL_ATTACH ||
- Data == DEBUG_STARTING_SYMBOL_BREAK) {
+ if (*Data8 == DEBUG_STARTING_SYMBOL_ATTACH) {
//
// Add the debug symbol into Debug FIFO
//
- DebugTerminalFifoAdd (&mSerialFifoForDebug, Data);
+ DebugAgentMsgPrint (DEBUG_AGENT_INFO, "Terminal Timer attach symbol received %x", *Data8);
+ DebugTerminalFifoAdd (&mSerialFifoForDebug, *Data8);
+ } else if (*Data8 == DEBUG_STARTING_SYMBOL_NORMAL) {
+ Status = ReadRemainingBreakPacket (Handle, &DebugHeader);
+ if (Status == EFI_SUCCESS) {
+ DebugAgentMsgPrint (DEBUG_AGENT_INFO, "Terminal Timer break symbol received %x", DebugHeader.Command);
+ DebugTerminalFifoAdd (&mSerialFifoForDebug, DebugHeader.Command);
+ }
+ if (Status == EFI_TIMEOUT) {
+ continue;
+ }
} else {
- *Uint8Buffer = Data;
+ *Uint8Buffer = *Data8;
Uint8Buffer ++;
}
}
@@ -675,7 +704,12 @@ SerialRead ( //
// Restore Debug Timer interrupt
//
- SaveAndSetDebugTimerInterrupt (OldInterruptState);
+ SaveAndSetDebugTimerInterrupt (DebugTimerInterruptState);
+
+ //
+ // Restore to original TPL
+ //
+ gBS->RestoreTPL (Tpl);
return EFI_SUCCESS;
}
@@ -691,36 +725,90 @@ SerialRead ( **/
EFI_STATUS
-DebugReadBreakSymbol (
+DebugReadBreakFromDebugPort (
IN DEBUG_PORT_HANDLE Handle,
OUT UINT8 *BreakSymbol
)
{
- EFI_STATUS Status;
- UINT8 Data;
+ EFI_STATUS Status;
+ DEBUG_PACKET_HEADER DebugHeader;
+ UINT8 *Data8;
- Status = DebugTerminalFifoRemove (&mSerialFifoForDebug, &Data);
- if (Status != EFI_SUCCESS) {
+ *BreakSymbol = 0;
+ //
+ // If Debug Port buffer has data, read it till it was break symbol or Debug Port buffer empty.
+ //
+ Data8 = (UINT8 *) &DebugHeader;
+ while (TRUE) {
+ //
+ // If start symbol is not received
+ //
if (!DebugPortPollBuffer (Handle)) {
//
- // No data in Debug Port buffer.
+ // If no data in Debug Port, exit
//
- return EFI_NOT_FOUND;
+ break;
+ }
+ //
+ // Try to read the start symbol
+ //
+ DebugPortReadBuffer (Handle, Data8, 1, 0);
+ if (*Data8 == DEBUG_STARTING_SYMBOL_ATTACH) {
+ DebugAgentMsgPrint (DEBUG_AGENT_INFO, "Debug Timer attach symbol received %x", *Data8);
+ *BreakSymbol = *Data8;
+ return EFI_SUCCESS;
+ }
+ if (*Data8 == DEBUG_STARTING_SYMBOL_NORMAL) {
+ Status = ReadRemainingBreakPacket (Handle, &DebugHeader);
+ if (Status == EFI_SUCCESS) {
+ DebugAgentMsgPrint (DEBUG_AGENT_INFO, "Debug Timer break symbol received %x", DebugHeader.Command);
+ *BreakSymbol = DebugHeader.Command;
+ return EFI_SUCCESS;
+ }
+ if (Status == EFI_TIMEOUT) {
+ break;
+ }
} else {
//
- // Read one character from Debug Port.
+ // Add to Terminal FIFO
//
- DebugPortReadBuffer (Handle, &Data, 1, 0);
- if ((Data != DEBUG_STARTING_SYMBOL_ATTACH) && (Data != DEBUG_STARTING_SYMBOL_BREAK)) {
- //
- // If the data is not Break symbol, add it into Terminal FIFO
- //
- DebugTerminalFifoAdd (&mSerialFifoForTerminal, Data);
- return EFI_NOT_FOUND;
- }
+ DebugTerminalFifoAdd (&mSerialFifoForTerminal, *Data8);
}
}
- *BreakSymbol = Data;
- return EFI_SUCCESS;
+ return EFI_NOT_FOUND;
+}
+
+/**
+ Read the Attach/Break-in symbols.
+
+ @param[in] Handle Pointer to Debug Port handle.
+ @param[out] BreakSymbol Returned break symbol.
+
+ @retval EFI_SUCCESS Read the symbol in BreakSymbol.
+ @retval EFI_NOT_FOUND No read the break symbol.
+
+**/
+EFI_STATUS
+DebugReadBreakSymbol (
+ IN DEBUG_PORT_HANDLE Handle,
+ OUT UINT8 *BreakSymbol
+ )
+{
+ EFI_STATUS Status;
+ UINT8 Data8;
+
+ //
+ // Read break symbol from debug FIFO firstly
+ //
+ Status = DebugTerminalFifoRemove (&mSerialFifoForDebug, &Data8);
+ if (Status == EFI_SUCCESS) {
+ *BreakSymbol = Data8;
+ return EFI_SUCCESS;
+ } else {
+ //
+ // Read Break symbol from debug port
+ //
+ return DebugReadBreakFromDebugPort (Handle, BreakSymbol);
+ }
}
|