VirtualBox

Ignore:
Timestamp:
Aug 14, 2024 1:16:30 PM (6 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
164367
Message:

Devices/EFI/FirmwareNew: Merge edk2-stable-202405 and make it build on aarch64, bugref:4643

Location:
trunk/src/VBox/Devices/EFI/FirmwareNew
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/FirmwareNew

  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf

    r99404 r105670  
    5757  DebugLib
    5858
     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  
    33
    44  Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
     5  Copyright (c) 2023, Rivos Inc. All rights reserved.<BR>
    56
    67  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    1011#include <Library/BaseLib.h>
    1112#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
     25typedef enum {
     26  CacheOpClean,
     27  CacheOpFlush,
     28  CacheOpInvld,
     29} CACHE_OP;
     30
     31/**
     32Verify CBOs are supported by this HW
     33TODO: Use RISC-V CPU HOB once available.
     34
     35**/
     36STATIC
     37BOOLEAN
     38RiscVIsCMOEnabled (
     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**/
     62STATIC
     63VOID
     64CacheOpCacheRange (
     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}
    32116
    33117/**
    34118  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.
    36123
    37124**/
     
    42129  )
    43130{
    44   RiscVInvalidateInstCacheAsm ();
     131  RiscVInvalidateInstCacheFenceAsm ();
    45132}
    46133
     
    49136  of the calling CPU.
    50137
    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.
    62143  @param  Address The base address of the instruction cache lines to
    63144                  invalidate. If the CPU is in a physical addressing mode, then
     
    78159{
    79160  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    )
    83165    );
    84166  InvalidateInstructionCache ();
     
    102184  )
    103185{
    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    ));
    105191}
    106192
     
    138224  )
    139225{
    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
    141232  return Address;
    142233}
     
    158249  )
    159250{
    160   DEBUG ((DEBUG_ERROR, "%a:RISC-V unsupported function.\n", __func__));
     251  ASSERT (FALSE);
    161252}
    162253
     
    177268  If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().
    178269
    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.
    183271  @param  Length  The number of bytes to write back from the data cache.
    184272
     
    193281  )
    194282{
    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
    196289  return Address;
    197290}
     
    214307  )
    215308{
    216   RiscVInvalidateDataCacheAsm ();
     309  RiscVInvalidateDataCacheFenceAsm ();
    217310}
    218311
     
    235328  If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().
    236329
    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.
    241331  @param  Length  The number of bytes to invalidate from the data cache.
    242332
     
    251341  )
    252342{
    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
    254354  return Address;
    255355}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette