diff mbox series

[edk2,edk2-platforms,v4,2/9] Platform/ARM/Sgi: add NOR flash platform library implementation

Message ID 1526891152-18739-3-git-send-email-thomas.abraham@arm.com
State Superseded
Headers show
Series None | expand

Commit Message

Thomas Abraham May 21, 2018, 8:25 a.m. UTC
From: Vishwanatha HG <vishwanatha.hg@arm.com>


Add a initial NOR flash driver platform wrapper as part of the platform
library. Access to NOR flash devices connected to CS0 and CS1 is enabled
in this initial implementation.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Vishwanatha HG <vishwanatha.hg@arm.com>

Signed-off-by: Thomas Abraham <thomas.abraham@arm.com>

---
 .../ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.c   | 66 ++++++++++++++++++++++
 .../ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.inf | 34 +++++++++++
 2 files changed, 100 insertions(+)
 create mode 100644 Platform/ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.c
 create mode 100644 Platform/ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.inf

-- 
2.7.4

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Comments

Ard Biesheuvel May 21, 2018, 8:53 a.m. UTC | #1
On 21 May 2018 at 10:25, Thomas Abraham <thomas.abraham@arm.com> wrote:
> From: Vishwanatha HG <vishwanatha.hg@arm.com>

>

> Add a initial NOR flash driver platform wrapper as part of the platform

> library. Access to NOR flash devices connected to CS0 and CS1 is enabled

> in this initial implementation.

>

> Contributed-under: TianoCore Contribution Agreement 1.1

> Signed-off-by: Vishwanatha HG <vishwanatha.hg@arm.com>

> Signed-off-by: Thomas Abraham <thomas.abraham@arm.com>

> ---

>  .../ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.c   | 66 ++++++++++++++++++++++

>  .../ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.inf | 34 +++++++++++

>  2 files changed, 100 insertions(+)

>  create mode 100644 Platform/ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.c

>  create mode 100644 Platform/ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.inf

>

> diff --git a/Platform/ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.c b/Platform/ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.c

> new file mode 100644

> index 0000000..9b4981f

> --- /dev/null

> +++ b/Platform/ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.c

> @@ -0,0 +1,66 @@

> +/** @file

> +

> +  Copyright (c) 2018, ARM Ltd. All rights reserved.

> +

> +  This program and the accompanying materials are licensed and made available

> +  under the terms and conditions of the BSD License which accompanies this

> +  distribution.  The full text of the license may be found at

> +  http://opensource.org/licenses/bsd-license.php

> +

> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,

> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

> +

> + **/

> +

> +#include <PiDxe.h>

> +#include <Library/DebugLib.h>

> +#include <Library/IoLib.h>

> +#include <Library/NorFlashPlatformLib.h>

> +#include <SgiPlatform.h>

> +

> +STATIC NOR_FLASH_DESCRIPTION mNorFlashDevices[] = {

> +  {

> +    SGI_EXP_SMC_CS0_BASE,

> +    SGI_EXP_SMC_CS0_BASE,

> +    SIZE_256KB * 256,

> +    SIZE_256KB,

> +    {0xEBF0B9DF, 0x17d0, 0x4812, { 0xA9, 0x59, 0xCF, 0xD7, 0x92, 0xEE, 0x31, 0x13} }

> +  },

> +  {

> +    SGI_EXP_SMC_CS1_BASE,

> +    SGI_EXP_SMC_CS1_BASE,

> +    SIZE_256KB * 256,

> +    SIZE_256KB,

> +    { 0x1F15DA3C, 0x37FF, 0x4070, { 0xB4, 0x71, 0xBB, 0x4A, 0xF1, 0x2A, 0x72, 0x4A } }


Please use consistent whitespace in these GUID definitions.

> +  },

> +};

> +

> +EFI_STATUS

> +NorFlashPlatformInitialization (

> +  VOID

> +  )

> +{

> +  UINT64 SysRegFlash;

> +

> +  SysRegFlash = SGI_EXP_SYSPH_SYSTEM_REGISTERS + SGI_SYSPH_SYS_REG_FLASH;

> +  if ((MmioRead32 (SysRegFlash) & SGI_SYSPH_SYS_REG_FLASH_RWEN) == 0) {

> +    MmioWrite32 (SysRegFlash, 1);


SGI_SYSPH_SYS_REG_FLASH_RWEN?

Should you use MmioOr32() here? (I can't tell, I don't have the docs)

> +  }

> +

> +  return EFI_SUCCESS;

> +}

> +

> +EFI_STATUS

> +NorFlashPlatformGetDevices (

> +  OUT NOR_FLASH_DESCRIPTION   **NorFlashDevices,

> +  OUT UINT32                  *Count

> +  )

> +{

> +  if ((NorFlashDevices == NULL) || (Count == NULL)) {

> +    return EFI_INVALID_PARAMETER;

> +  }

> +

> +  *NorFlashDevices = mNorFlashDevices;

> +  *Count = ARRAY_SIZE (mNorFlashDevices);

> +  return EFI_SUCCESS;

> +}

> diff --git a/Platform/ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.inf b/Platform/ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.inf

> new file mode 100644

> index 0000000..3a6b33b

> --- /dev/null

> +++ b/Platform/ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.inf

> @@ -0,0 +1,34 @@

> +#/** @file

> +#

> +#  Copyright (c) 2018, ARM Ltd. All rights reserved.

> +

> +#  This program and the accompanying materials are licensed and made available

> +#  under the terms and conditions of the BSD License which accompanies this

> +#  distribution.  The full text of the license may be found at

> +#  http://opensource.org/licenses/bsd-license.php

> +#

> +#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,

> +#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

> +#

> +#**/

> +

> +[Defines]

> +  INF_VERSION                    = 0x0001001A

> +  BASE_NAME                      = NorFlashSgiLib

> +  FILE_GUID                      = 3f021755-6d74-4065-9ee4-98225267b36e

> +  MODULE_TYPE                    = DXE_DRIVER

> +  VERSION_STRING                 = 1.0

> +  LIBRARY_CLASS                  = NorFlashPlatformLib

> +

> +[Sources.common]

> +  NorFlashLib.c

> +

> +[Packages]

> +  ArmPlatformPkg/ArmPlatformPkg.dec

> +  MdePkg/MdePkg.dec

> +  Platform/ARM/SgiPkg/SgiPlatform.dec

> +

> +[LibraryClasses]

> +  BaseLib

> +  DebugLib

> +  IoLib

> --

> 2.7.4

>

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Thomas Abraham May 23, 2018, 4:07 a.m. UTC | #2
Hi Ard,

On Mon, May 21, 2018 at 2:23 PM, Ard Biesheuvel
<ard.biesheuvel@linaro.org> wrote:
> On 21 May 2018 at 10:25, Thomas Abraham <thomas.abraham@arm.com> wrote:

>> From: Vishwanatha HG <vishwanatha.hg@arm.com>

>>

>> Add a initial NOR flash driver platform wrapper as part of the platform

>> library. Access to NOR flash devices connected to CS0 and CS1 is enabled

>> in this initial implementation.

>>

>> Contributed-under: TianoCore Contribution Agreement 1.1

>> Signed-off-by: Vishwanatha HG <vishwanatha.hg@arm.com>

>> Signed-off-by: Thomas Abraham <thomas.abraham@arm.com>

>> ---

>>  .../ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.c   | 66 ++++++++++++++++++++++

>>  .../ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.inf | 34 +++++++++++

>>  2 files changed, 100 insertions(+)

>>  create mode 100644 Platform/ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.c

>>  create mode 100644 Platform/ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.inf

>>

>> diff --git a/Platform/ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.c b/Platform/ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.c

>> new file mode 100644

>> index 0000000..9b4981f

>> --- /dev/null

>> +++ b/Platform/ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.c

>> @@ -0,0 +1,66 @@

>> +/** @file

>> +

>> +  Copyright (c) 2018, ARM Ltd. All rights reserved.

>> +

>> +  This program and the accompanying materials are licensed and made available

>> +  under the terms and conditions of the BSD License which accompanies this

>> +  distribution.  The full text of the license may be found at

>> +  http://opensource.org/licenses/bsd-license.php

>> +

>> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,

>> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

>> +

>> + **/

>> +

>> +#include <PiDxe.h>

>> +#include <Library/DebugLib.h>

>> +#include <Library/IoLib.h>

>> +#include <Library/NorFlashPlatformLib.h>

>> +#include <SgiPlatform.h>

>> +

>> +STATIC NOR_FLASH_DESCRIPTION mNorFlashDevices[] = {

>> +  {

>> +    SGI_EXP_SMC_CS0_BASE,

>> +    SGI_EXP_SMC_CS0_BASE,

>> +    SIZE_256KB * 256,

>> +    SIZE_256KB,

>> +    {0xEBF0B9DF, 0x17d0, 0x4812, { 0xA9, 0x59, 0xCF, 0xD7, 0x92, 0xEE, 0x31, 0x13} }

>> +  },

>> +  {

>> +    SGI_EXP_SMC_CS1_BASE,

>> +    SGI_EXP_SMC_CS1_BASE,

>> +    SIZE_256KB * 256,

>> +    SIZE_256KB,

>> +    { 0x1F15DA3C, 0x37FF, 0x4070, { 0xB4, 0x71, 0xBB, 0x4A, 0xF1, 0x2A, 0x72, 0x4A } }

>

> Please use consistent whitespace in these GUID definitions.

>

>> +  },

>> +};

>> +

>> +EFI_STATUS

>> +NorFlashPlatformInitialization (

>> +  VOID

>> +  )

>> +{

>> +  UINT64 SysRegFlash;

>> +

>> +  SysRegFlash = SGI_EXP_SYSPH_SYSTEM_REGISTERS + SGI_SYSPH_SYS_REG_FLASH;

>> +  if ((MmioRead32 (SysRegFlash) & SGI_SYSPH_SYS_REG_FLASH_RWEN) == 0) {

>> +    MmioWrite32 (SysRegFlash, 1);

>

> SGI_SYSPH_SYS_REG_FLASH_RWEN?


The SysReg register has a bit in it that has to be set to allow
read/write access to the NOR flash. So this macros represents that
bit.

>

> Should you use MmioOr32() here? (I can't tell, I don't have the docs)


Tested with MmioOr32() and that works as well. So updated the code.

Thanks,
Thomas.

<snip>
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
diff mbox series

Patch

diff --git a/Platform/ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.c b/Platform/ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.c
new file mode 100644
index 0000000..9b4981f
--- /dev/null
+++ b/Platform/ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.c
@@ -0,0 +1,66 @@ 
+/** @file
+
+  Copyright (c) 2018, ARM Ltd. All rights reserved.
+
+  This program and the accompanying materials are licensed and made available
+  under the terms and conditions of the BSD License which accompanies this
+  distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ **/
+
+#include <PiDxe.h>
+#include <Library/DebugLib.h>
+#include <Library/IoLib.h>
+#include <Library/NorFlashPlatformLib.h>
+#include <SgiPlatform.h>
+
+STATIC NOR_FLASH_DESCRIPTION mNorFlashDevices[] = {
+  {
+    SGI_EXP_SMC_CS0_BASE,
+    SGI_EXP_SMC_CS0_BASE,
+    SIZE_256KB * 256,
+    SIZE_256KB,
+    {0xEBF0B9DF, 0x17d0, 0x4812, { 0xA9, 0x59, 0xCF, 0xD7, 0x92, 0xEE, 0x31, 0x13} }
+  },
+  {
+    SGI_EXP_SMC_CS1_BASE,
+    SGI_EXP_SMC_CS1_BASE,
+    SIZE_256KB * 256,
+    SIZE_256KB,
+    { 0x1F15DA3C, 0x37FF, 0x4070, { 0xB4, 0x71, 0xBB, 0x4A, 0xF1, 0x2A, 0x72, 0x4A } }
+  },
+};
+
+EFI_STATUS
+NorFlashPlatformInitialization (
+  VOID
+  )
+{
+  UINT64 SysRegFlash;
+
+  SysRegFlash = SGI_EXP_SYSPH_SYSTEM_REGISTERS + SGI_SYSPH_SYS_REG_FLASH;
+  if ((MmioRead32 (SysRegFlash) & SGI_SYSPH_SYS_REG_FLASH_RWEN) == 0) {
+    MmioWrite32 (SysRegFlash, 1);
+  }
+
+  return EFI_SUCCESS;
+}
+
+EFI_STATUS
+NorFlashPlatformGetDevices (
+  OUT NOR_FLASH_DESCRIPTION   **NorFlashDevices,
+  OUT UINT32                  *Count
+  )
+{
+  if ((NorFlashDevices == NULL) || (Count == NULL)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  *NorFlashDevices = mNorFlashDevices;
+  *Count = ARRAY_SIZE (mNorFlashDevices);
+  return EFI_SUCCESS;
+}
diff --git a/Platform/ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.inf b/Platform/ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.inf
new file mode 100644
index 0000000..3a6b33b
--- /dev/null
+++ b/Platform/ARM/SgiPkg/Library/NorFlashLib/NorFlashLib.inf
@@ -0,0 +1,34 @@ 
+#/** @file
+#
+#  Copyright (c) 2018, ARM Ltd. All rights reserved.
+
+#  This program and the accompanying materials are licensed and made available
+#  under the terms and conditions of the BSD License which accompanies this
+#  distribution.  The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#**/
+
+[Defines]
+  INF_VERSION                    = 0x0001001A
+  BASE_NAME                      = NorFlashSgiLib
+  FILE_GUID                      = 3f021755-6d74-4065-9ee4-98225267b36e
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = NorFlashPlatformLib
+
+[Sources.common]
+  NorFlashLib.c
+
+[Packages]
+  ArmPlatformPkg/ArmPlatformPkg.dec
+  MdePkg/MdePkg.dec
+  Platform/ARM/SgiPkg/SgiPlatform.dec
+
+[LibraryClasses]
+  BaseLib
+  DebugLib
+  IoLib