/** @file\r
Debug Agent library implementition for Dxe Core and Dxr modules.\r
\r
- Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
}\r
\r
/**\r
- Worker function to setup IDT table and initialize the IDT entries.\r
+ Worker function to set up Debug Agent environment.\r
+\r
+ This function will set up IDT table and initialize the IDT entries and \r
+ initialize CPU LOCAL APIC timer.\r
+ It also tries to connect HOST if Debug Agent was not initialized before.\r
\r
@param[in] Mailbox Pointer to Mailbox.\r
\r
**/\r
VOID\r
-SetupDebugAgentEnviroment (\r
+SetupDebugAgentEnvironment (\r
IN DEBUG_AGENT_MAILBOX *Mailbox\r
)\r
{\r
IA32_DESCRIPTOR Idtr;\r
UINT16 IdtEntryCount;\r
UINT64 DebugPortHandle;\r
+ UINT32 DebugTimerFrequency;\r
\r
if (mMultiProcessorDebugSupport) {\r
InitializeSpinLock (&mDebugMpContext.MpContextSpinLock);\r
mMailboxPointer = &mMailbox;\r
}\r
\r
+ //\r
+ // Initialize Debug Timer hardware and save its initial count and frequency\r
+ //\r
+ mDebugMpContext.DebugTimerInitCount = InitializeDebugTimer (&DebugTimerFrequency, TRUE);\r
+ UpdateMailboxContent (mMailboxPointer, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency);\r
//\r
// Initialize debug communication port\r
//\r
/**\r
Initialize debug agent.\r
\r
- This function is used to set up debug enviroment for DXE phase.\r
+ This function is used to set up debug environment for DXE phase.\r
\r
If this function is called by DXE Core, Context must be the pointer\r
to HOB list which will be used to get GUIDed HOB. It will enable\r
IA32_DESCRIPTOR IdtDescriptor;\r
IA32_DESCRIPTOR *Ia32Idtr;\r
IA32_IDT_ENTRY *Ia32IdtEntry;\r
+ BOOLEAN PeriodicMode;\r
+ UINTN TimerCycle;\r
\r
if (InitFlag == DEBUG_AGENT_INIT_DXE_AP) {\r
+ //\r
+ // Check if CPU APIC Timer is working, otherwise initialize it.\r
+ //\r
+ InitializeLocalApicSoftwareEnable (TRUE);\r
+ GetApicTimerState (NULL, &PeriodicMode, NULL);\r
+ TimerCycle = GetApicTimerInitCount ();\r
+ if (!PeriodicMode || TimerCycle == 0) {\r
+ InitializeDebugTimer (NULL, FALSE);\r
+ }\r
//\r
// Invoked by AP, enable interrupt to let AP could receive IPI from other processors\r
//\r
mSaveIdtTableSize = IdtDescriptor.Limit + 1;\r
mSavedIdtTable = AllocateCopyPool (mSaveIdtTableSize, (VOID *) IdtDescriptor.Base);\r
//\r
- // Initialize Debug Timer hardware and save its initial count\r
- //\r
- mDebugMpContext.DebugTimerInitCount = InitializeDebugTimer ();\r
- //\r
// Check if Debug Agent initialized in DXE phase\r
//\r
Mailbox = GetMailboxFromConfigurationTable ();\r
Mailbox = GetMailboxFromHob (HobList);\r
}\r
//\r
- // Set up IDT table and prepare for IDT entries\r
+ // Set up Debug Agent Environment and try to connect HOST if required\r
//\r
- SetupDebugAgentEnviroment (Mailbox);\r
+ SetupDebugAgentEnvironment (Mailbox);\r
//\r
// For DEBUG_AGENT_INIT_S3, needn't to install configuration table and EFI Serial IO protocol\r
// For DEBUG_AGENT_INIT_DXE_CORE, InternalConstructorWorker() will invoked in Constructor()\r
//\r
InternalConstructorWorker ();\r
//\r
+ // Enable Debug Timer interrupt\r
+ //\r
+ SaveAndSetDebugTimerInterrupt (TRUE);\r
+ //\r
// Enable interrupt to receive Debug Timer interrupt\r
//\r
EnableInterrupts ();\r
\r
*(EFI_STATUS *)Context = EFI_SUCCESS;\r
\r
- if (gST->ConOut != NULL) {\r
- Print (L"Debug Agent: Initialized successfully!\r\n");\r
- Print (L"If the Debug Port is serial port, please make sure this serial port isn't connected by ISA Serial driver\r\n");\r
- Print (L"You could do the following steps to disconnect the serial port:\r\n");\r
- Print (L"1: Shell> drivers\r\n");\r
- Print (L" ...\r\n");\r
- Print (L" V VERSION E G G #D #C DRIVER NAME IMAGE NAME\r\n");\r
- Print (L" == ======== = = = == == =================================== ===================\r\n");\r
- Print (L" 8F 0000000A B - - 1 14 PCI Bus Driver PciBusDxe\r\n");\r
- Print (L" 91 00000010 ? - - - - ATA Bus Driver AtaBusDxe\r\n");\r
- Print (L" ...\r\n");\r
- Print (L" A7 0000000A B - - 1 1 ISA Serial Driver IsaSerialDxe\r\n");\r
- Print (L" ...\r\n");\r
- Print (L"2: Shell> dh -d A7\r\n");\r
- Print (L" A7: Image(IsaSerialDxe) ImageDevPath (..9FB3-11D4-9A3A-0090273FC14D))DriverBinding ComponentName ComponentName2\r\n");\r
- Print (L" Driver Name : ISA Serial Driver\r\n");\r
- Print (L" Image Name : FvFile(93B80003-9FB3-11D4-9A3A-0090273FC14D)\r\n");\r
- Print (L" Driver Version : 0000000A\r\n");\r
- Print (L" Driver Type : BUS\r\n");\r
- Print (L" Configuration : NO\r\n");\r
- Print (L" Diagnostics : NO\r\n");\r
- Print (L" Managing :\r\n");\r
- Print (L" Ctrl[EA] : PciRoot(0x0)/Pci(0x1F,0x0)/Serial(0x0)\r\n");\r
- Print (L" Child[EB] : PciRoot(0x0)/Pci(0x1F,0x0)/Serial(0x0)/Uart(115200,8,N,1)\r\n");\r
- Print (L"3: Shell> disconnect EA\r\n");\r
- Print (L"4: Shell> load -nc DebugAgentDxe.efi\r\n\r\n");\r
- }\r
break;\r
\r
case DEBUG_AGENT_INIT_DXE_UNLOAD:\r
if (mDebugAgentInitialized) {\r
if (IsHostAttached ()) {\r
- Print (L"Debug Agent: Host is still connected, please de-attach TARGET firstly!\r\n");\r
*(EFI_STATUS *)Context = EFI_ACCESS_DENIED;\r
//\r
// Enable Debug Timer interrupt again\r
*(EFI_STATUS *)Context = EFI_SUCCESS;\r
}\r
} else {\r
- Print (L"Debug Agent: It hasn't been initialized, cannot unload it!\r\n");\r
*(EFI_STATUS *)Context = EFI_NOT_STARTED;\r
}\r
\r
mDxeCoreFlag = TRUE;\r
mMultiProcessorDebugSupport = TRUE;\r
//\r
- // Initialize Debug Timer hardware and its initial count\r
- //\r
- mDebugMpContext.DebugTimerInitCount = InitializeDebugTimer ();\r
- //\r
// Try to get mailbox from GUIDed HOB build in PEI\r
//\r
HobList = Context;\r
Mailbox = GetMailboxFromHob (HobList);\r
//\r
- // Set up IDT table and prepare for IDT entries\r
+ // Set up Debug Agent Environment and try to connect HOST if required\r
+ //\r
+ SetupDebugAgentEnvironment (Mailbox);\r
+ //\r
+ // Enable Debug Timer interrupt\r
//\r
- SetupDebugAgentEnviroment (Mailbox);\r
+ SaveAndSetDebugTimerInterrupt (TRUE);\r
//\r
// Enable interrupt to receive Debug Timer interrupt\r
//\r
if (Context != NULL) {\r
Ia32Idtr = (IA32_DESCRIPTOR *) Context;\r
Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base);\r
- MailboxLocation = (UINT64 *) (UINTN) (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +\r
- (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));\r
+ MailboxLocation = (UINT64 *) ((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +\r
+ ((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));\r
Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);\r
VerifyMailboxChecksum (Mailbox);\r
}\r
//\r
mMailboxPointer = Mailbox;\r
//\r
- // Set up IDT table and prepare for IDT entries\r
+ // Set up Debug Agent Environment and try to connect HOST if required\r
//\r
- SetupDebugAgentEnviroment (Mailbox);\r
+ SetupDebugAgentEnvironment (Mailbox);\r
//\r
// Disable interrupt\r
//\r