]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/CpuCacheInfoLib/DxeCpuCacheInfoLib.c
UefiCpuPkg/CpuCacheInfoLib: Add new CpuCacheInfoLib.
[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 ASSERT_EFI_ERROR (Status);
55
56 Procedure (ProcedureArgument);
57 }
58
59 /**
60 Get detailed information of the requested logical processor.
61
62 @param[in] MpServices MP_SERVICES structure.
63 @param[in] ProcessorNum The requested logical processor number.
64 @param[out] ProcessorInfo A pointer to the buffer where the processor information is stored
65 **/
66 VOID
67 CpuCacheInfoGetProcessorInfo (
68 IN MP_SERVICES MpServices,
69 IN UINTN ProcessorNum,
70 OUT EFI_PROCESSOR_INFORMATION *ProcessorInfo
71 )
72 {
73 EFI_STATUS Status;
74
75 Status = MpServices.Protocol->GetProcessorInfo (MpServices.Protocol, ProcessorNum, ProcessorInfo);
76 ASSERT_EFI_ERROR (Status);
77 }
78
79 /**
80 Get the logical processor number.
81
82 @param[in] MpServices MP_SERVICES structure.
83
84 @retval Return the logical processor number.
85 **/
86 UINT32
87 CpuCacheInfoWhoAmI (
88 IN MP_SERVICES MpServices
89 )
90 {
91 EFI_STATUS Status;
92 UINTN ProcessorNum;
93
94 Status = MpServices.Protocol->WhoAmI (MpServices.Protocol, &ProcessorNum);
95 ASSERT_EFI_ERROR (Status);
96
97 return (UINT32)ProcessorNum;
98 }
99
100 /**
101 Get the total number of logical processors in the platform.
102
103 @param[in] MpServices MP_SERVICES structure.
104
105 @retval Return the total number of logical processors.
106 **/
107 UINT32
108 CpuCacheInfoGetNumberOfProcessors (
109 IN MP_SERVICES MpServices
110 )
111 {
112 EFI_STATUS Status;
113 UINTN NumberOfProcessor;
114 UINTN NumberOfEnabledProcessor;
115
116 Status = MpServices.Protocol->GetNumberOfProcessors (MpServices.Protocol, &NumberOfProcessor, &NumberOfEnabledProcessor);
117 ASSERT_EFI_ERROR (Status);
118
119 return (UINT32)NumberOfProcessor;
120 }