VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.c@ 99396

最後變更 在這個檔案從99396是 80721,由 vboxsync 提交於 6 年 前

Devices/EFI/FirmwareNew: Start upgrade process to edk2-stable201908 (compiles on Windows and works to some extent), bugref:4643

  • 屬性 svn:eol-style 設為 native
檔案大小: 7.2 KB
 
1/** @file
2 Debug Port Library implementation based on usb3 debug port.
3
4 Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7**/
8
9#include <PiPei.h>
10#include <Library/PeiServicesLib.h>
11#include <Library/HobLib.h>
12#include <Ppi/MemoryDiscovered.h>
13#include <Ppi/IoMmu.h>
14#include "DebugCommunicationLibUsb3Internal.h"
15
16GUID gUsb3DbgGuid = USB3_DBG_GUID;
17
18/**
19 USB3 IOMMU PPI notify.
20
21 @param[in] PeiServices Pointer to PEI Services Table.
22 @param[in] NotifyDesc Pointer to the descriptor for the Notification event that
23 caused this function to execute.
24 @param[in] Ppi Pointer to the PPI data associated with this function.
25
26 @retval EFI_STATUS Always return EFI_SUCCESS
27**/
28EFI_STATUS
29EFIAPI
30Usb3IoMmuPpiNotify (
31 IN EFI_PEI_SERVICES **PeiServices,
32 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
33 IN VOID *Ppi
34 )
35{
36 USB3_DEBUG_PORT_HANDLE *Instance;
37
38 DEBUG ((DEBUG_INFO, "%a()\n", __FUNCTION__));
39
40 Instance = GetUsb3DebugPortInstance ();
41 ASSERT (Instance != NULL);
42 if (!Instance->Ready) {
43 return EFI_SUCCESS;
44 }
45
46 Instance->InNotify = TRUE;
47
48 //
49 // Reinitialize USB3 debug port with granted DMA buffer from IOMMU PPI.
50 //
51 InitializeUsbDebugHardware (Instance);
52
53 //
54 // Wait some time for host to be ready after re-initialization.
55 //
56 MicroSecondDelay (1000000);
57
58 Instance->InNotify = FALSE;
59
60 return EFI_SUCCESS;
61}
62
63EFI_PEI_NOTIFY_DESCRIPTOR mUsb3IoMmuPpiNotifyDesc = {
64 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
65 &gEdkiiIoMmuPpiGuid,
66 Usb3IoMmuPpiNotify
67};
68
69/**
70 Allocates pages that are suitable for an OperationBusMasterCommonBuffer or
71 OperationBusMasterCommonBuffer64 mapping.
72
73 @param IoMmu Pointer to IOMMU PPI.
74 @param Pages The number of pages to allocate.
75 @param HostAddress A pointer to store the base system memory address of the
76 allocated range.
77 @param DeviceAddress The resulting map address for the bus master PCI controller to use to
78 access the hosts HostAddress.
79 @param Mapping A resulting value to pass to Unmap().
80
81 @retval EFI_SUCCESS The requested memory pages were allocated.
82 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
83 MEMORY_WRITE_COMBINE and MEMORY_CACHED.
84 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
85 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
86
87**/
88EFI_STATUS
89IoMmuAllocateBuffer (
90 IN EDKII_IOMMU_PPI *IoMmu,
91 IN UINTN Pages,
92 OUT VOID **HostAddress,
93 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
94 OUT VOID **Mapping
95 )
96{
97 EFI_STATUS Status;
98 UINTN NumberOfBytes;
99
100 *HostAddress = NULL;
101 *DeviceAddress = 0;
102 *Mapping = NULL;
103
104 Status = IoMmu->AllocateBuffer (
105 IoMmu,
106 EfiRuntimeServicesData,
107 Pages,
108 HostAddress,
109 0
110 );
111 if (EFI_ERROR (Status)) {
112 return EFI_OUT_OF_RESOURCES;
113 }
114
115 NumberOfBytes = EFI_PAGES_TO_SIZE (Pages);
116 Status = IoMmu->Map (
117 IoMmu,
118 EdkiiIoMmuOperationBusMasterCommonBuffer,
119 *HostAddress,
120 &NumberOfBytes,
121 DeviceAddress,
122 Mapping
123 );
124 if (EFI_ERROR (Status)) {
125 IoMmu->FreeBuffer (IoMmu, Pages, *HostAddress);
126 *HostAddress = NULL;
127 return EFI_OUT_OF_RESOURCES;
128 }
129 Status = IoMmu->SetAttribute (
130 IoMmu,
131 *Mapping,
132 EDKII_IOMMU_ACCESS_READ | EDKII_IOMMU_ACCESS_WRITE
133 );
134 if (EFI_ERROR (Status)) {
135 IoMmu->Unmap (IoMmu, *Mapping);
136 IoMmu->FreeBuffer (IoMmu, Pages, *HostAddress);
137 *Mapping = NULL;
138 *HostAddress = NULL;
139 return Status;
140 }
141
142 return Status;
143}
144
145/**
146 USB3 get IOMMU PPI.
147
148 @return Pointer to IOMMU PPI.
149
150**/
151EDKII_IOMMU_PPI *
152Usb3GetIoMmu (
153 VOID
154 )
155{
156 EFI_STATUS Status;
157 EDKII_IOMMU_PPI *IoMmu;
158
159 IoMmu = NULL;
160 Status = PeiServicesLocatePpi (
161 &gEdkiiIoMmuPpiGuid,
162 0,
163 NULL,
164 (VOID **) &IoMmu
165 );
166 if (!EFI_ERROR (Status) && (IoMmu != NULL)) {
167 return IoMmu;
168 }
169
170 return NULL;
171}
172
173/**
174 Return USB3 debug instance address pointer.
175
176**/
177EFI_PHYSICAL_ADDRESS *
178GetUsb3DebugPortInstanceAddrPtr (
179 VOID
180 )
181{
182 USB3_DEBUG_PORT_HANDLE *Instance;
183 EFI_PHYSICAL_ADDRESS *AddrPtr;
184 EFI_PEI_HOB_POINTERS Hob;
185 EFI_STATUS Status;
186
187 Hob.Raw = GetFirstGuidHob (&gUsb3DbgGuid);
188 if (Hob.Raw == NULL) {
189 //
190 // Build HOB for the local instance and the buffer to save instance address pointer.
191 // Use the local instance in HOB temporarily.
192 //
193 AddrPtr = BuildGuidHob (
194 &gUsb3DbgGuid,
195 sizeof (EFI_PHYSICAL_ADDRESS) + sizeof (USB3_DEBUG_PORT_HANDLE)
196 );
197 ASSERT (AddrPtr != NULL);
198 ZeroMem (AddrPtr, sizeof (EFI_PHYSICAL_ADDRESS) + sizeof (USB3_DEBUG_PORT_HANDLE));
199 Instance = (USB3_DEBUG_PORT_HANDLE *) (AddrPtr + 1);
200 *AddrPtr = (EFI_PHYSICAL_ADDRESS) (UINTN) Instance;
201 Instance->FromHob = TRUE;
202 Instance->Initialized = USB3DBG_UNINITIALIZED;
203 if (Usb3GetIoMmu () == NULL) {
204 Status = PeiServicesNotifyPpi (&mUsb3IoMmuPpiNotifyDesc);
205 ASSERT_EFI_ERROR (Status);
206 }
207 } else {
208 AddrPtr = GET_GUID_HOB_DATA (Hob.Guid);
209 }
210
211 return AddrPtr;
212}
213
214/**
215 Allocate aligned memory for XHC's usage.
216
217 @param BufferSize The size, in bytes, of the Buffer.
218
219 @return A pointer to the allocated buffer or NULL if allocation fails.
220
221**/
222VOID*
223AllocateAlignBuffer (
224 IN UINTN BufferSize
225 )
226{
227 VOID *Buf;
228 EFI_PHYSICAL_ADDRESS Address;
229 EFI_STATUS Status;
230 VOID *MemoryDiscoveredPpi;
231 EDKII_IOMMU_PPI *IoMmu;
232 VOID *HostAddress;
233 VOID *Mapping;
234
235 Buf = NULL;
236
237 //
238 // Make sure the allocated memory is physical memory.
239 //
240 Status = PeiServicesLocatePpi (
241 &gEfiPeiMemoryDiscoveredPpiGuid,
242 0,
243 NULL,
244 (VOID **) &MemoryDiscoveredPpi
245 );
246 if (!EFI_ERROR (Status)) {
247 IoMmu = Usb3GetIoMmu ();
248 if (IoMmu != NULL) {
249 Status = IoMmuAllocateBuffer (
250 IoMmu,
251 EFI_SIZE_TO_PAGES (BufferSize),
252 &HostAddress,
253 &Address,
254 &Mapping
255 );
256 if (!EFI_ERROR (Status)) {
257 ASSERT (Address == ((EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress));
258 Buf = (VOID *)(UINTN) Address;
259 }
260 } else {
261 Status = PeiServicesAllocatePages (
262 EfiACPIMemoryNVS,
263 EFI_SIZE_TO_PAGES (BufferSize),
264 &Address
265 );
266 if (!EFI_ERROR (Status)) {
267 Buf = (VOID *)(UINTN) Address;
268 }
269 }
270 }
271 return Buf;
272}
273
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette