Changeset 105670 in vbox for trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseCacheMaintenanceLib
- Timestamp:
- Aug 14, 2024 1:16:30 PM (6 months ago)
- svn:sync-xref-src-repo-rev:
- 164367
- Location:
- trunk/src/VBox/Devices/EFI/FirmwareNew
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/FirmwareNew
-
Property svn:mergeinfo
changed from (toggle deleted branches)
to (toggle deleted branches)/vendor/edk2/current 103735-103757,103769-103776,129194-159268 /vendor/edk2/current 103735-103757,103769-103776,129194-164365
-
Property svn:mergeinfo
changed from (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf
r99404 r105670 57 57 DebugLib 58 58 59 [LibraryClasses.RISCV64] 60 PcdLib 61 62 [Pcd.RISCV64] 63 gEfiMdePkgTokenSpaceGuid.PcdRiscVFeatureOverride ## CONSUMES -
trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseCacheMaintenanceLib/RiscVCache.c
r101291 r105670 3 3 4 4 Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR> 5 Copyright (c) 2023, Rivos Inc. All rights reserved.<BR> 5 6 6 7 SPDX-License-Identifier: BSD-2-Clause-Patent … … 10 11 #include <Library/BaseLib.h> 11 12 #include <Library/DebugLib.h> 12 13 /** 14 RISC-V invalidate instruction cache. 15 16 **/ 17 VOID 18 EFIAPI 19 RiscVInvalidateInstCacheAsm ( 20 VOID 21 ); 22 23 /** 24 RISC-V invalidate data cache. 25 26 **/ 27 VOID 28 EFIAPI 29 RiscVInvalidateDataCacheAsm ( 30 VOID 31 ); 13 #include <Library/PcdLib.h> 14 15 // 16 // TODO: Grab cache block size and make Cache Management Operation 17 // enabling decision based on RISC-V CPU HOB in 18 // future when it is available and convert PcdRiscVFeatureOverride 19 // PCD to a pointer that contains pointer to bitmap structure 20 // which can be operated more elegantly. 21 // 22 #define RISCV_CACHE_BLOCK_SIZE 64 23 #define RISCV_CPU_FEATURE_CMO_BITMASK 0x1 24 25 typedef enum { 26 CacheOpClean, 27 CacheOpFlush, 28 CacheOpInvld, 29 } CACHE_OP; 30 31 /** 32 Verify CBOs are supported by this HW 33 TODO: Use RISC-V CPU HOB once available. 34 35 **/ 36 STATIC 37 BOOLEAN 38 RiscVIsCMOEnabled ( 39 VOID 40 ) 41 { 42 // If CMO is disabled in HW, skip Override check 43 // Otherwise this PCD can override settings 44 return ((PcdGet64 (PcdRiscVFeatureOverride) & RISCV_CPU_FEATURE_CMO_BITMASK) != 0); 45 } 46 47 /** 48 Performs required opeartion on cache lines in the cache coherency domain 49 of the calling CPU. If Address is not aligned on a cache line boundary, 50 then entire cache line containing Address is operated. If Address + Length 51 is not aligned on a cache line boundary, then the entire cache line 52 containing Address + Length -1 is operated. 53 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT(). 54 @param Address The base address of the cache lines to 55 invalidate. 56 @param Length The number of bytes to invalidate from the instruction 57 cache. 58 @param Op Type of CMO operation to be performed 59 @return Address. 60 61 **/ 62 STATIC 63 VOID 64 CacheOpCacheRange ( 65 IN VOID *Address, 66 IN UINTN Length, 67 IN CACHE_OP Op 68 ) 69 { 70 UINTN CacheLineSize; 71 UINTN Start; 72 UINTN End; 73 74 if (Length == 0) { 75 return; 76 } 77 78 if ((Op != CacheOpInvld) && (Op != CacheOpFlush) && (Op != CacheOpClean)) { 79 return; 80 } 81 82 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Address)); 83 84 CacheLineSize = RISCV_CACHE_BLOCK_SIZE; 85 86 Start = (UINTN)Address; 87 // 88 // Calculate the cache line alignment 89 // 90 End = (Start + Length + (CacheLineSize - 1)) & ~(CacheLineSize - 1); 91 Start &= ~((UINTN)CacheLineSize - 1); 92 93 DEBUG ( 94 (DEBUG_VERBOSE, 95 "CacheOpCacheRange: Performing Cache Management Operation %d \n", Op) 96 ); 97 98 do { 99 switch (Op) { 100 case CacheOpInvld: 101 RiscVCpuCacheInvalCmoAsm (Start); 102 break; 103 case CacheOpFlush: 104 RiscVCpuCacheFlushCmoAsm (Start); 105 break; 106 case CacheOpClean: 107 RiscVCpuCacheCleanCmoAsm (Start); 108 break; 109 default: 110 break; 111 } 112 113 Start = Start + CacheLineSize; 114 } while (Start != End); 115 } 32 116 33 117 /** 34 118 Invalidates the entire instruction cache in cache coherency domain of the 35 calling CPU. 119 calling CPU. Risc-V does not have currently an CBO implementation which can 120 invalidate the entire I-cache. Hence using Fence instruction for now. P.S. 121 Fence instruction may or may not implement full I-cache invd functionality 122 on all implementations. 36 123 37 124 **/ … … 42 129 ) 43 130 { 44 RiscVInvalidateInstCache Asm ();131 RiscVInvalidateInstCacheFenceAsm (); 45 132 } 46 133 … … 49 136 of the calling CPU. 50 137 51 Invalidates the instruction cache lines specified by Address and Length. If 52 Address is not aligned on a cache line boundary, then entire instruction 53 cache line containing Address is invalidated. If Address + Length is not 54 aligned on a cache line boundary, then the entire instruction cache line 55 containing Address + Length -1 is invalidated. This function may choose to 56 invalidate the entire instruction cache if that is more efficient than 57 invalidating the specified range. If Length is 0, then no instruction cache 58 lines are invalidated. Address is returned. 59 60 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT(). 61 138 An operation from a CMO instruction is defined to operate only on the copies 139 of a cache block that are cached in the caches accessible by the explicit 140 memory accesses performed by the set of coherent agents.In other words CMO 141 operations are not applicable to instruction cache. Use fence.i instruction 142 instead to achieve the same purpose. 62 143 @param Address The base address of the instruction cache lines to 63 144 invalidate. If the CPU is in a physical addressing mode, then … … 78 159 { 79 160 DEBUG ( 80 (DEBUG_WARN, 81 "%a:RISC-V unsupported function.\n" 82 "Invalidating the whole instruction cache instead.\n", __func__) 161 (DEBUG_VERBOSE, 162 "InvalidateInstructionCacheRange: RISC-V unsupported function.\n" 163 "Invalidating the whole instruction cache instead.\n" 164 ) 83 165 ); 84 166 InvalidateInstructionCache (); … … 102 184 ) 103 185 { 104 DEBUG ((DEBUG_ERROR, "%a:RISC-V unsupported function.\n", __func__)); 186 ASSERT (FALSE); 187 DEBUG (( 188 DEBUG_ERROR, 189 "WriteBackInvalidateDataCache: RISC-V unsupported function.\n" 190 )); 105 191 } 106 192 … … 138 224 ) 139 225 { 140 DEBUG ((DEBUG_ERROR, "%a:RISC-V unsupported function.\n", __func__)); 226 if (RiscVIsCMOEnabled ()) { 227 CacheOpCacheRange (Address, Length, CacheOpFlush); 228 } else { 229 ASSERT (FALSE); 230 } 231 141 232 return Address; 142 233 } … … 158 249 ) 159 250 { 160 DEBUG ((DEBUG_ERROR, "%a:RISC-V unsupported function.\n", __func__));251 ASSERT (FALSE); 161 252 } 162 253 … … 177 268 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT(). 178 269 179 @param Address The base address of the data cache lines to write back. If 180 the CPU is in a physical addressing mode, then Address is a 181 physical address. If the CPU is in a virtual addressing 182 mode, then Address is a virtual address. 270 @param Address The base address of the data cache lines to write back. 183 271 @param Length The number of bytes to write back from the data cache. 184 272 … … 193 281 ) 194 282 { 195 DEBUG ((DEBUG_ERROR, "%a:RISC-V unsupported function.\n", __func__)); 283 if (RiscVIsCMOEnabled ()) { 284 CacheOpCacheRange (Address, Length, CacheOpClean); 285 } else { 286 ASSERT (FALSE); 287 } 288 196 289 return Address; 197 290 } … … 214 307 ) 215 308 { 216 RiscVInvalidateDataCache Asm ();309 RiscVInvalidateDataCacheFenceAsm (); 217 310 } 218 311 … … 235 328 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT(). 236 329 237 @param Address The base address of the data cache lines to invalidate. If 238 the CPU is in a physical addressing mode, then Address is a 239 physical address. If the CPU is in a virtual addressing mode, 240 then Address is a virtual address. 330 @param Address The base address of the data cache lines to invalidate. 241 331 @param Length The number of bytes to invalidate from the data cache. 242 332 … … 251 341 ) 252 342 { 253 DEBUG ((DEBUG_ERROR, "%a:RISC-V unsupported function.\n", __func__)); 343 if (RiscVIsCMOEnabled ()) { 344 CacheOpCacheRange (Address, Length, CacheOpInvld); 345 } else { 346 DEBUG ( 347 (DEBUG_VERBOSE, 348 "InvalidateDataCacheRange: Zicbom not supported.\n" 349 "Invalidating the whole Data cache instead.\n") 350 ); 351 InvalidateDataCache (); 352 } 353 254 354 return Address; 255 355 }
Note:
See TracChangeset
for help on using the changeset viewer.