1 /** @file
2 Initialize Debug Agent in DXE by invoking Debug Agent Library.
3
4 Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include <PiDxe.h>
16 #include <Guid/EventGroup.h>
17 #include <Library/UefiBootServicesTableLib.h>
18 #include <Library/DebugAgentLib.h>
19 #include <Library/UefiLib.h>
20
21 EFI_EVENT mExitBootServiceEvent;
22
23 /**
24 One notified function to disable Debug Timer interrupt when gBS->ExitBootServices() called.
25
26 @param[in] Event Pointer to this event
27 @param[in] Context Event handler private data
28
29 **/
30 VOID
31 EFIAPI
DisableDebugTimerExitBootService(EFI_EVENT Event,VOID * Context)32 DisableDebugTimerExitBootService (
33 EFI_EVENT Event,
34 VOID *Context
35 )
36
37 {
38 SaveAndSetDebugTimerInterrupt (FALSE);
39 }
40
41 /**
42 The Entry Point for Debug Agent Dxe driver.
43
44 It will invoke Debug Agent Library to enable source debugging feature in DXE phase.
45
46 @param[in] ImageHandle The firmware allocated handle for the EFI image.
47 @param[in] SystemTable A pointer to the EFI System Table.
48
49 @retval EFI_SUCCESS The entry point is executed successfully.
50 @retval other Some error occurs when initialzed Debug Agent.
51
52 **/
53 EFI_STATUS
54 EFIAPI
DebugAgentDxeInitialize(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)55 DebugAgentDxeInitialize(
56 IN EFI_HANDLE ImageHandle,
57 IN EFI_SYSTEM_TABLE *SystemTable
58 )
59 {
60 EFI_STATUS Status;
61
62 if (gST->ConOut != NULL) {
63 Print (L"If the Debug Port is serial port, please make sure this serial port isn't connected by");
64 Print (L" ISA Serial driver\r\n");
65 Print (L"You could do the following steps to disconnect the serial port:\r\n");
66 Print (L"1: Shell> drivers\r\n");
67 Print (L" ...\r\n");
68 Print (L" V VERSION E G G #D #C DRIVER NAME IMAGE NAME\r\n");
69 Print (L" == ======== = = = == == =================================== ===================\r\n");
70 Print (L" 8F 0000000A B - - 1 14 PCI Bus Driver PciBusDxe\r\n");
71 Print (L" 91 00000010 ? - - - - ATA Bus Driver AtaBusDxe\r\n");
72 Print (L" ...\r\n");
73 Print (L" A7 0000000A B - - 1 1 ISA Serial Driver IsaSerialDxe\r\n");
74 Print (L" ...\r\n");
75 Print (L"2: Shell> dh -d A7\r\n");
76 Print (L" A7: Image(IsaSerialDxe) ImageDevPath (..9FB3-11D4-9A3A-0090273FC14D))DriverBinding");
77 Print (L" ComponentName ComponentName2\r\n");
78 Print (L" Driver Name : ISA Serial Driver\r\n");
79 Print (L" Image Name : FvFile(93B80003-9FB3-11D4-9A3A-0090273FC14D)\r\n");
80 Print (L" Driver Version : 0000000A\r\n");
81 Print (L" Driver Type : BUS\r\n");
82 Print (L" Configuration : NO\r\n");
83 Print (L" Diagnostics : NO\r\n");
84 Print (L" Managing :\r\n");
85 Print (L" Ctrl[EA] : PciRoot(0x0)/Pci(0x1F,0x0)/Serial(0x0)\r\n");
86 Print (L" Child[EB] : PciRoot(0x0)/Pci(0x1F,0x0)/Serial(0x0)/Uart(115200,8,N,1)\r\n");
87 Print (L"3: Shell> disconnect EA\r\n");
88 Print (L"4: Shell> load -nc DebugAgentDxe.efi\r\n\r\n");
89 }
90 Status = EFI_UNSUPPORTED;
91 InitializeDebugAgent (DEBUG_AGENT_INIT_DXE_LOAD, &Status, NULL);
92 if (EFI_ERROR (Status)) {
93 return Status;
94 }
95 if (gST->ConOut != NULL) {
96 Print (L"Debug Agent: Initialized successfully!\r\n\r\n");
97 }
98 //
99 // Create event to disable Debug Timer interrupt when exit boot service.
100 //
101 Status = gBS->CreateEventEx (
102 EVT_NOTIFY_SIGNAL,
103 TPL_NOTIFY,
104 DisableDebugTimerExitBootService,
105 NULL,
106 &gEfiEventExitBootServicesGuid,
107 &mExitBootServiceEvent
108 );
109 return Status;
110 }
111
112 /**
113 This is the unload handle for Debug Agent Dxe driver.
114
115 It will invoke Debug Agent Library to disable source debugging feature.
116
117 @param[in] ImageHandle The drivers' driver image.
118
119 @retval EFI_SUCCESS The image is unloaded.
120 @retval Others Failed to unload the image.
121
122 **/
123 EFI_STATUS
124 EFIAPI
DebugAgentDxeUnload(IN EFI_HANDLE ImageHandle)125 DebugAgentDxeUnload (
126 IN EFI_HANDLE ImageHandle
127 )
128 {
129 EFI_STATUS Status;
130
131 Status = EFI_UNSUPPORTED;
132 InitializeDebugAgent (DEBUG_AGENT_INIT_DXE_UNLOAD, &Status, NULL);
133 switch (Status) {
134 case EFI_ACCESS_DENIED:
135 Print (L"Debug Agent: Host is still connected, please de-attach TARGET firstly!\r\n");
136 break;
137 case EFI_NOT_STARTED:
138 Print (L"Debug Agent: It hasn't been initialized, cannot unload it!\r\n");
139 break;
140 }
141
142 return Status;
143 }
144