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