]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/MpInitLib/MpLibTdx.c
CryptoPkg/openssl: disable codestyle checks for generated files
[mirror_edk2.git] / UefiCpuPkg / Library / MpInitLib / MpLibTdx.c
1 /** @file
2 CPU MP Initialize Library common functions for Td guest.
3
4 Copyright (c) 2020 - 2022, Intel Corporation. All rights reserved.<BR>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include "MpLib.h"
11 #include "MpIntelTdx.h"
12
13 /**
14 Gets detailed MP-related information on the requested processor at the
15 instant this call is made. This service may only be called from the BSP.
16
17 In current stage only the BSP is workable. So ProcessorNumber should be 0.
18
19 @param[in] ProcessorNumber The handle number of processor.
20 @param[out] ProcessorInfoBuffer A pointer to the buffer where information for
21 the requested processor is deposited.
22 @param[out] HealthData Return processor health data.
23
24 @retval EFI_SUCCESS Processor information was returned.
25 @retval EFI_DEVICE_ERROR The calling processor is an AP.
26 @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL or ProcessorNumber is not 0.
27 @retval EFI_NOT_FOUND The processor with the handle specified by
28 ProcessorNumber does not exist in the platform.
29 @retval EFI_NOT_READY MP Initialize Library is not initialized.
30
31 **/
32 EFI_STATUS
33 TdxMpInitLibGetProcessorInfo (
34 IN UINTN ProcessorNumber,
35 OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer,
36 OUT EFI_HEALTH_FLAGS *HealthData OPTIONAL
37 )
38 {
39 UINTN OriginalProcessorNumber;
40
41 //
42 // Lower 24 bits contains the actual processor number.
43 //
44 OriginalProcessorNumber = ProcessorNumber;
45 ProcessorNumber &= BIT24 - 1;
46
47 if ((ProcessorInfoBuffer == NULL) || (ProcessorNumber != 0)) {
48 return EFI_INVALID_PARAMETER;
49 }
50
51 ProcessorInfoBuffer->ProcessorId = 0;
52 ProcessorInfoBuffer->StatusFlag = PROCESSOR_AS_BSP_BIT | PROCESSOR_ENABLED_BIT;
53 ZeroMem (&ProcessorInfoBuffer->Location, sizeof (EFI_CPU_PHYSICAL_LOCATION));
54
55 if ((OriginalProcessorNumber & CPU_V2_EXTENDED_TOPOLOGY) != 0) {
56 ZeroMem (&ProcessorInfoBuffer->ExtendedInformation.Location2, sizeof (EFI_CPU_PHYSICAL_LOCATION2));
57 }
58
59 if (HealthData != NULL) {
60 HealthData->Uint32 = 0;
61 }
62
63 return EFI_SUCCESS;
64 }
65
66 /**
67 Retrieves the number of logical processor in the platform and the number of
68 those logical processors that are enabled on this boot. This service may only
69 be called from the BSP.
70
71 @param[out] NumberOfProcessors Pointer to the total number of logical
72 processors in the system, including the BSP
73 and disabled APs.
74 @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
75 processors that exist in system, including
76 the BSP.
77
78 @retval EFI_SUCCESS The number of logical processors and enabled
79 logical processors was retrieved.
80 @retval EFI_DEVICE_ERROR The calling processor is an AP.
81 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL and NumberOfEnabledProcessors
82 is NULL.
83 @retval EFI_NOT_READY MP Initialize Library is not initialized.
84
85 **/
86 EFI_STATUS
87 TdxMpInitLibGetNumberOfProcessors (
88 OUT UINTN *NumberOfProcessors, OPTIONAL
89 OUT UINTN *NumberOfEnabledProcessors OPTIONAL
90 )
91 {
92 ASSERT (NumberOfProcessors != NULL || NumberOfEnabledProcessors != NULL);
93 //
94 // In current stage only the BSP is workable. So NumberOfProcessors
95 // & NumberOfEnableddProcessors are both 1.
96 //
97 if (NumberOfProcessors != NULL) {
98 *NumberOfProcessors = 1;
99 }
100
101 if (NumberOfEnabledProcessors != NULL) {
102 *NumberOfEnabledProcessors = 1;
103 }
104
105 return EFI_SUCCESS;
106 }