1From 70e79ba5300f01a13422452c29e26c69042a0c8c Mon Sep 17 00:00:00 2001
2From: sahil <sahil@arm.com>
3Date: Mon, 2 May 2022 18:50:08 +0530
4Subject: [PATCH] Platform/ARM/N1Sdp: NOR flash library for N1Sdp
5
6Add NOR flash library, this library provides APIs for getting the list
7of NOR flash devices on the platform.
8
9Upstream-Status: Pending
10Signed-off-by: Xueliang Zhong <xueliang.zhong@arm.com>
11Signed-off-by: sahil <sahil@arm.com>
12Change-Id: I39ad4143b7fad7e33b3b151a019a74f23e0ed441
13---
14 .../Library/NorFlashLib/NorFlashLib.c         | 52 +++++++++++++++++++
15 .../Library/NorFlashLib/NorFlashLib.inf       | 36 +++++++++++++
16 2 files changed, 88 insertions(+)
17 create mode 100644 Silicon/ARM/NeoverseN1Soc/Library/NorFlashLib/NorFlashLib.c
18 create mode 100644 Silicon/ARM/NeoverseN1Soc/Library/NorFlashLib/NorFlashLib.inf
19
20diff --git a/Silicon/ARM/NeoverseN1Soc/Library/NorFlashLib/NorFlashLib.c b/Silicon/ARM/NeoverseN1Soc/Library/NorFlashLib/NorFlashLib.c
21new file mode 100644
22index 00000000..eee3d1c6
23--- /dev/null
24+++ b/Silicon/ARM/NeoverseN1Soc/Library/NorFlashLib/NorFlashLib.c
25@@ -0,0 +1,52 @@
26+/** @file
27+  NOR flash lib for N1Sdp
28+
29+  Copyright (c) 2023, ARM Limited. All rights reserved.<BR>
30+
31+  SPDX-License-Identifier: BSD-2-Clause-Patent
32+
33+**/
34+
35+#include <Library/DebugLib.h>
36+#include <Library/IoLib.h>
37+#include <Library/NorFlashPlatformLib.h>
38+#include <NeoverseN1Soc.h>
39+#include <PiDxe.h>
40+
41+#define FW_ENV_REGION_BASE            FixedPcdGet32 (PcdFlashNvStorageVariableBase)
42+#define FW_ENV_REGION_SIZE            (FixedPcdGet32 (PcdFlashNvStorageVariableSize) + \
43+                                      FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) + \
44+                                      FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize))
45+
46+STATIC NOR_FLASH_DESCRIPTION mNorFlashDevices[] = {
47+  {
48+    /// Environment variable region
49+    NEOVERSEN1SOC_SCP_QSPI_AHB_BASE,                    ///< device base
50+    FW_ENV_REGION_BASE,                                 ///< region base
51+    FW_ENV_REGION_SIZE,                                 ///< region size
52+    SIZE_4KB,                                           ///< block size
53+  },
54+};
55+
56+/**
57+  Get NOR flash region info
58+
59+  @param[out]    NorFlashDevices    NOR flash regions info.
60+  @param[out]    Count              number of flash instance.
61+
62+  @retval        EFI_SUCCESS        Success.
63+**/
64+EFI_STATUS
65+NorFlashPlatformGetDevices (
66+  OUT NOR_FLASH_DESCRIPTION   **NorFlashDevices,
67+  OUT UINT32                  *Count
68+  )
69+{
70+  if ((NorFlashDevices == NULL) || (Count == NULL)) {
71+    return EFI_INVALID_PARAMETER;
72+  }
73+
74+  *NorFlashDevices = mNorFlashDevices;
75+  *Count = ARRAY_SIZE (mNorFlashDevices);
76+  return EFI_SUCCESS;
77+}
78diff --git a/Silicon/ARM/NeoverseN1Soc/Library/NorFlashLib/NorFlashLib.inf b/Silicon/ARM/NeoverseN1Soc/Library/NorFlashLib/NorFlashLib.inf
79new file mode 100644
80index 00000000..784856c8
81--- /dev/null
82+++ b/Silicon/ARM/NeoverseN1Soc/Library/NorFlashLib/NorFlashLib.inf
83@@ -0,0 +1,36 @@
84+## @file
85+#  NOR flash lib for N1Sdp
86+#
87+#  Copyright (c) 2023, ARM Limited. All rights reserved.<BR>
88+#
89+#  SPDX-License-Identifier: BSD-2-Clause-Patent
90+#
91+##
92+
93+[Defines]
94+  INF_VERSION                    = 0x0001001B
95+  BASE_NAME                      = NorFlashN1SdpLib
96+  FILE_GUID                      = 7006fcf1-a585-4272-92e3-b286b1dff5bb
97+  MODULE_TYPE                    = DXE_DRIVER
98+  VERSION_STRING                 = 1.0
99+  LIBRARY_CLASS                  = NorFlashPlatformLib
100+
101+[Sources.common]
102+  NorFlashLib.c
103+
104+[Packages]
105+  MdeModulePkg/MdeModulePkg.dec
106+  MdePkg/MdePkg.dec
107+  Platform/ARM/ARM.dec
108+  Silicon/ARM/NeoverseN1Soc/NeoverseN1Soc.dec
109+
110+[LibraryClasses]
111+  BaseLib
112+  DebugLib
113+  IoLib
114+
115+[FixedPcd]
116+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
117+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
118+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase
119+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
120