1 /** @file
2   Header file for CPU Cache info Library.
3 
4   Copyright (c) 2020 - 2021, Intel Corporation. All rights reserved.<BR>
5   SPDX-License-Identifier: BSD-2-Clause-Patent
6 
7 **/
8 
9 #ifndef _CPU_CACHE_INFO_LIB_H_
10 #define _CPU_CACHE_INFO_LIB_H_
11 
12 typedef struct {
13   //
14   // Package number.
15   //
16   UINT32    Package;
17   //
18   // Core type of logical processor.
19   // Value = CPUID.1Ah:EAX[31:24]
20   //
21   UINT8     CoreType;
22   //
23   // Level of the cache that this package's this type of logical processor corresponds to.
24   // Value = CPUID.04h:EAX[07:05]
25   //
26   UINT8     CacheLevel            : 3;
27   //
28   // Type of the cache that this package's this type of logical processor corresponds to.
29   // Value = CPUID.04h:EAX[04:00]
30   //
31   UINT8     CacheType             : 5;
32   //
33   // Ways of associativity.
34   // Value = CPUID.04h:EBX[31:22]
35   //
36   UINT16    CacheWays             : 10;
37   //
38   // Fully associative cache.
39   // Value = CPUID.04h:EAX[09]
40   //
41   UINT16    FullyAssociativeCache : 1;
42   //
43   // Direct mapped cache.
44   // Value = CPUID.04h:EDX[02]
45   //
46   UINT16    DirectMappedCache     : 1;
47   UINT16    Reserved              : 4;
48   //
49   // Size of single cache that this package's this type of logical processor corresponds to.
50   // Value = (CPUID.04h:EBX[31:22] + 1) * (CPUID.04h:EBX[21:12] + 1) *
51   //         (CPUID.04h:EBX[11:00] + 1) * (CPUID.04h:ECX[31:00] + 1)
52   //
53   UINT32    CacheSizeinKB;
54   //
55   // Number of the cache that this package's this type of logical processor corresponds to.
56   // Have subtracted the number of caches that are shared.
57   //
58   UINT16    CacheCount;
59 } CPU_CACHE_INFO;
60 
61 /**
62   Get CpuCacheInfo data array. The array is sorted by CPU package ID, core type, cache level and cache type.
63 
64   @param[in, out] CpuCacheInfo        Pointer to the CpuCacheInfo array.
65   @param[in, out] CpuCacheInfoCount   As input, point to the length of response CpuCacheInfo array.
66                                       As output, point to the actual length of response CpuCacheInfo array.
67 
68   @retval         EFI_SUCCESS             Function completed successfully.
69   @retval         EFI_INVALID_PARAMETER   CpuCacheInfoCount is NULL.
70   @retval         EFI_INVALID_PARAMETER   CpuCacheInfo is NULL while CpuCacheInfoCount contains the value
71                                           greater than zero.
72   @retval         EFI_UNSUPPORTED         Processor does not support CPUID_CACHE_PARAMS Leaf.
73   @retval         EFI_OUT_OF_RESOURCES    Required resources could not be allocated.
74   @retval         EFI_BUFFER_TOO_SMALL    CpuCacheInfoCount is too small to hold the response CpuCacheInfo
75                                           array. CpuCacheInfoCount has been updated with the length needed
76                                           to complete the request.
77 **/
78 EFI_STATUS
79 EFIAPI
80 GetCpuCacheInfo (
81   IN OUT CPU_CACHE_INFO  *CpuCacheInfo,
82   IN OUT UINTN           *CpuCacheInfoCount
83   );
84 
85 #endif
86