]> git.proxmox.com Git - mirror_edk2.git/blob - SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.c
902a3b626accf8a740b89b917fd0afb6168678ec
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugCommunicationLibUsb3 / DebugCommunicationLibUsb3Pei.c
1 /** @file
2 Debug Port Library implementation based on usb3 debug port.
3
4 Copyright (c) 2014 - 2017, 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 <PiPei.h>
16 #include <Library/PeiServicesLib.h>
17 #include <Ppi/MemoryDiscovered.h>
18 #include "DebugCommunicationLibUsb3Internal.h"
19
20 /**
21 Allocate aligned memory for XHC's usage.
22
23 @param BufferSize The size, in bytes, of the Buffer.
24
25 @return A pointer to the allocated buffer or NULL if allocation fails.
26
27 **/
28 VOID*
29 AllocateAlignBuffer (
30 IN UINTN BufferSize
31 )
32 {
33 VOID *Buf;
34 EFI_PHYSICAL_ADDRESS Address;
35 EFI_STATUS Status;
36 VOID *MemoryDiscoveredPpi;
37
38 Buf = NULL;
39
40 //
41 // Make sure the allocated memory is physical memory.
42 //
43 Status = PeiServicesLocatePpi (
44 &gEfiPeiMemoryDiscoveredPpiGuid,
45 0,
46 NULL,
47 (VOID **) &MemoryDiscoveredPpi
48 );
49 if (!EFI_ERROR (Status)) {
50 Status = PeiServicesAllocatePages (EfiACPIMemoryNVS, EFI_SIZE_TO_PAGES (BufferSize), &Address);
51 if (!EFI_ERROR (Status)) {
52 Buf = (VOID *)(UINTN) Address;
53 }
54 }
55 return Buf;
56 }
57