Browse Source

SiFive/U540: RiscVSpecialPlatformLib instance of U540

Provide platform_override of U540 platform.

Cc: Sunil V L <sunilvl@ventanamicro.com>
Cc: Daniel Schaefer <daniel.schaefer@hpe.com>
Signed-off-by: Abner Chang <abner.chang@hpe.com>
Reviewed-by: Daniel Schaefer <daniel.schaefer@hpe.com>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
Abner Chang 2 years ago
parent
commit
229cbf9fe8

+ 36 - 0
Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/Library/RiscVSpecialPlatformLib/RiscVSpecialPlatformLib.inf

@@ -0,0 +1,36 @@
+## @file
+#  Null library instance to provide platform_override for the
+#  special RISC-V platform. This module incorporates with
+#  OpensbiPlatformLib and RISC-V Opensbi library.
+#
+#  Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x0001001b
+  BASE_NAME                      = RiscVSpecialPlatformLib
+  FILE_GUID                      = FE0AE3E6-90A4-421D-851D-E092CBEEE645
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = RiscVSpecialPlatformLib|SEC
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+#  VALID_ARCHITECTURES           = RISCV64
+#
+
+[Sources]
+ SifiveFu540.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  Platform/RISC-V/PlatformPkg/RiscVPlatformPkg.dec
+  Silicon/RISC-V/ProcessorPkg/RiscVProcessorPkg.dec
+
+[LibraryClasses]
+  BaseLib

+ 56 - 0
Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/Library/RiscVSpecialPlatformLib/SifiveFu540.c

@@ -0,0 +1,56 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2020 Western Digital Corporation or its affiliates.
+ *
+ * Authors:
+ *   Anup Patel <anup.patel@wdc.com>
+
+   Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+
+   SPDX-License-Identifier: BSD-2-Clause-Patent
+ */
+
+#include <Library/RiscVSpecialPlatformLib.h>
+#include <sbi_utils/fdt/fdt_helper.h>
+#include <sbi_utils/fdt/fdt_fixup.h>
+
+static u64 sifive_fu540_tlbr_flush_limit(const struct fdt_match *match)
+{
+  /*
+   * The sfence.vma by virtual address does not work on
+   * SiFive FU540 so we return remote TLB flush limit as zero.
+   */
+  return 0;
+}
+
+static int sifive_fu540_fdt_fixup(void *fdt, const struct fdt_match *match)
+{
+  /*
+   * SiFive Freedom U540 has an erratum that prevents S-mode software
+   * to access a PMP protected region using 1GB page table mapping, so
+   * always add the no-map attribute on this platform.
+   */
+  fdt_reserved_memory_nomap_fixup(fdt);
+
+  return 0;
+}
+
+static const struct fdt_match sifive_fu540_match[] = {
+  { .compatible = "sifive,fu540" },
+  { .compatible = "sifive,fu540g" },
+  { .compatible = "sifive,fu540-c000" },
+  { .compatible = "sifive,hifive-unleashed-a00" },
+  { },
+};
+
+const struct platform_override sifive_fu540 = {
+  .match_table = sifive_fu540_match,
+  .tlbr_flush_limit = sifive_fu540_tlbr_flush_limit,
+  .fdt_fixup = sifive_fu540_fdt_fixup,
+};
+
+const struct platform_override *special_platforms[] = {
+  &sifive_fu540,
+};
+INTN NumberOfPlaformsInArray = array_size(special_platforms);

+ 1 - 0
Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.dsc

@@ -163,6 +163,7 @@
 
   ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/BaseExtractGuidedSectionLib/BaseExtractGuidedSectionLib.inf
+  RiscVSpecialPlatformLib|Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/Library/RiscVSpecialPlatformLib/RiscVSpecialPlatformLib.inf
 
 !ifdef $(SOURCE_DEBUG_ENABLE)
   DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgentLib.inf