]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/CpuCacheInfoLib/DxeCpuCacheInfoLib.c
ebf2db86ba1e8a909e30000397c86bf6fe251ad8
[mirror_edk2.git] / UefiCpuPkg / Library / CpuCacheInfoLib / DxeCpuCacheInfoLib.c
1 /** @file
2 Provides cache info for each package, core type, cache level and cache type.
3
4 Copyright (c) 2020 Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <PiDxe.h>
10 #include <Library/BaseLib.h>
11 #include <Library/DebugLib.h>
12 #include <Library/UefiBootServicesTableLib.h>
13 #include <Library/CpuCacheInfoLib.h>
14 #include <InternalCpuCacheInfoLib.h>
15
16 /**
17 Get EFI_MP_SERVICES_PROTOCOL pointer.
18
19 @param[out] MpServices A pointer to the buffer where EFI_MP_SERVICES_PROTOCOL is stored
20
21 @retval EFI_SUCCESS EFI_MP_SERVICES_PROTOCOL interface is returned
22 @retval EFI_NOT_FOUND EFI_MP_SERVICES_PROTOCOL interface is not found
23 **/
24 EFI_STATUS
25 CpuCacheInfoGetMpServices (
26 OUT MP_SERVICES *MpServices
27 )
28 {
29 EFI_STATUS Status;
30
31 Status = gBS->LocateProtocol (&gEfiMpServiceProtocolGuid, NULL, (VOID **)&MpServices->Protocol);
32 ASSERT_EFI_ERROR (Status);
33
34 return Status;
35 }
36
37 /**
38 Activate all of the logical processors.
39
40 @param[in] MpServices MP_SERVICES structure.
41 @param[in] Procedure A pointer to the function to be run on enabled logical processors.
42 @param[in] ProcedureArgument The parameter passed into Procedure for all enabled logical processors.
43 **/
44 VOID
45 CpuCacheInfoStartupAllCPUs (
46 IN MP_SERVICES MpServices,
47 IN EFI_AP_PROCEDURE Procedure,
48 IN VOID *ProcedureArgument
49 )
50 {
51 EFI_STATUS Status;
52
53 Status = MpServices.Protocol->StartupAllAPs (MpServices.Protocol, Procedure, FALSE, NULL, 0, ProcedureArgument, NULL);
54 if (Status == EFI_NOT_STARTED) {
55 //
56 // EFI_NOT_STARTED is returned when there is no enabled AP.
57 // Treat this case as EFI_SUCCESS.
58 //
59 Status = EFI_SUCCESS;
60 }
61
62 ASSERT_EFI_ERROR (Status);
63
64 Procedure (ProcedureArgument);
65 }
66
67 /**
68 Get detailed information of the requested logical processor.
69
70 @param[in] MpServices MP_SERVICES structure.
71 @param[in] ProcessorNum The requested logical processor number.
72 @param[out] ProcessorInfo A pointer to the buffer where the processor information is stored
73 **/
74 VOID
75 CpuCacheInfoGetProcessorInfo (
76 IN MP_SERVICES MpServices,
77 IN UINTN ProcessorNum,
78 OUT EFI_PROCESSOR_INFORMATION *ProcessorInfo
79 )
80 {
81 EFI_STATUS Status;
82
83 Status = MpServices.Protocol->GetProcessorInfo (MpServices.Protocol, ProcessorNum, ProcessorInfo);
84 ASSERT_EFI_ERROR (Status);
85 }
86
87 /**
88 Get the logical processor number.
89
90 @param[in] MpServices MP_SERVICES structure.
91
92 @retval Return the logical processor number.
93 **/
94 UINT32
95 CpuCacheInfoWhoAmI (
96 IN MP_SERVICES MpServices
97 )
98 {
99 EFI_STATUS Status;
100 UINTN ProcessorNum;
101
102 Status = MpServices.Protocol->WhoAmI (MpServices.Protocol, &ProcessorNum);
103 ASSERT_EFI_ERROR (Status);
104
105 return (UINT32)ProcessorNum;
106 }
107
108 /**
109 Get the total number of logical processors in the platform.
110
111 @param[in] MpServices MP_SERVICES structure.
112
113 @retval Return the total number of logical processors.
114 **/
115 UINT32
116 CpuCacheInfoGetNumberOfProcessors (
117 IN MP_SERVICES MpServices
118 )
119 {
120 EFI_STATUS Status;
121 UINTN NumberOfProcessor;
122 UINTN NumberOfEnabledProcessor;
123
124 Status = MpServices.Protocol->GetNumberOfProcessors (MpServices.Protocol, &NumberOfProcessor, &NumberOfEnabledProcessor);
125 ASSERT_EFI_ERROR (Status);
126
127 return (UINT32)NumberOfProcessor;
128 }