public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Thomas Abraham <thomas.abraham@arm.com>
To: edk2-devel@lists.01.org
Cc: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org,
	Thomas Abraham <thomas.abraham@arm.com>
Subject: [PATCH edk2-platforms v2 1/6] Platform/ARM/Sgi: Add Platform library implementation
Date: Fri, 13 Apr 2018 00:17:38 +0530	[thread overview]
Message-ID: <1523558863-5427-2-git-send-email-thomas.abraham@arm.com> (raw)
In-Reply-To: <1523558863-5427-1-git-send-email-thomas.abraham@arm.com>

Add initial SGI platform library support. This includes the virtual
memory map and helper functions for platform intialization.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Thomas Abraham <thomas.abraham@arm.com>
---
 Platform/ARM/SgiPkg/Include/SgiPlatform.h          |  63 ++++++++++++
 .../SgiPkg/Library/PlatformLib/AArch64/Helper.S    |  65 ++++++++++++
 Platform/ARM/SgiPkg/Library/PlatformLib/Mem.c      | 111 +++++++++++++++++++++
 Platform/ARM/SgiPkg/Library/PlatformLib/Platform.c |  72 +++++++++++++
 .../ARM/SgiPkg/Library/PlatformLib/PlatformLib.inf |  56 +++++++++++
 5 files changed, 367 insertions(+)
 create mode 100644 Platform/ARM/SgiPkg/Include/SgiPlatform.h
 create mode 100644 Platform/ARM/SgiPkg/Library/PlatformLib/AArch64/Helper.S
 create mode 100644 Platform/ARM/SgiPkg/Library/PlatformLib/Mem.c
 create mode 100644 Platform/ARM/SgiPkg/Library/PlatformLib/Platform.c
 create mode 100644 Platform/ARM/SgiPkg/Library/PlatformLib/PlatformLib.inf

diff --git a/Platform/ARM/SgiPkg/Include/SgiPlatform.h b/Platform/ARM/SgiPkg/Include/SgiPlatform.h
new file mode 100644
index 0000000..86994d5
--- /dev/null
+++ b/Platform/ARM/SgiPkg/Include/SgiPlatform.h
@@ -0,0 +1,63 @@
+/** @file
+*
+*  Copyright (c) 2018, ARM Limited. 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.
+*
+**/
+
+#ifndef __SGI_PLATFORM_H__
+#define __SGI_PLATFORM_H__
+
+/***********************************************************************************
+// Platform Memory Map
+************************************************************************************/
+
+// Expansion AXI - SMC Chip Select 0
+#define SGI_EXP_SMC_CS0_BASE                      0x08000000
+#define SGI_EXP_SMC_CS0_SZ                        SIZE_64MB
+
+// Expansion AXI - SMSC 91C111 (Ethernet)
+#define SGI_EXP_SMSC91X_BASE                      0x18000000
+#define SGI_EXP_SMSC91X_SZ                        SIZE_64MB
+
+// Expansion AXI - System peripherals
+#define SGI_EXP_SYS_PERIPH_BASE                   0x1C000000
+#define SGI_EXP_SYS_PERIPH_SZ                     SIZE_2MB
+
+#define SGI_EXP_SYSPH_VIRTIO_BLOCK_BASE           0x1c130000
+
+// Sub System Peripherals - UART0
+#define SGI_SUBSYS_UART0_BASE                     0x2A400000
+#define SGI_SUBSYS_UART0_SZ                       0x00010000
+
+// Sub System Peripherals - UART1
+#define SGI_SUBSYS_UART1_BASE                     0x2A410000
+#define SGI_SUBSYS_UART1_SZ                       0x00010000
+
+// Sub System Peripherals - Generic Watchdog
+#define SGI_SUBSYS_GENERIC_WDOG_BASE              0x2A440000
+#define SGI_SUBSYS_GENERIC_WDOG_SZ                SIZE_128KB
+
+// Sub System Peripherals - GIC
+#define SGI_SUBSYS_GENERIC_GIC_BASE               0x30000000
+#define SGI_SUBSYS_GENERIC_GICR_BASE              0x300C0000
+#define SGI_SUBSYS_GENERIC_GIC_SZ                 SIZE_1MB
+
+// Expansion AXI - Platform Peripherals - UART0
+#define SGI_EXP_PLAT_PERIPH_UART0_BASE            0x7FF70000
+#define SGI_EXP_PLAT_PERIPH_UART0_SZ              SIZE_64KB
+
+// Expansion AXI - Platform Peripherals - UART1
+#define SGI_EXP_PLAT_PERIPH_UART1_BASE            0x7FF80000
+#define SGI_EXP_PLAT_PERIPH_UART1_SZ              SIZE_64KB
+
+#define ARM_PLATFORM_WATCHDOG_COUNT  2
+
+#endif // __SGI_PLATFORM_H__
diff --git a/Platform/ARM/SgiPkg/Library/PlatformLib/AArch64/Helper.S b/Platform/ARM/SgiPkg/Library/PlatformLib/AArch64/Helper.S
new file mode 100644
index 0000000..9537bb0
--- /dev/null
+++ b/Platform/ARM/SgiPkg/Library/PlatformLib/AArch64/Helper.S
@@ -0,0 +1,65 @@
+/** @file
+*
+*  Copyright (c) 2018, ARM Limited. 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 <AsmMacroIoLibV8.h>
+#include <Library/ArmLib.h>
+
+.text
+.align 3
+
+GCC_ASM_EXPORT(ArmPlatformPeiBootAction)
+GCC_ASM_EXPORT(ArmPlatformGetCorePosition)
+GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId)
+GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore)
+
+//
+// First platform specific function to be called in the PEI phase
+//
+// This function is actually the first function called by the PrePi
+// or PrePeiCore modules. It allows to retrieve arguments passed to
+// the UEFI firmware through the CPU registers.
+//
+ASM_PFX(ArmPlatformPeiBootAction):
+  ret
+
+//UINTN
+//ArmPlatformGetCorePosition (
+//  IN UINTN MpId
+//  );
+// With this function: CorePos = (ClusterId * 2) + CoreId
+ASM_PFX(ArmPlatformGetCorePosition):
+  and   x1, x0, #ARM_CORE_MASK
+  and   x0, x0, #ARM_CLUSTER_MASK
+  add   x0, x1, x0, LSR #7
+  ret
+
+//UINTN
+//ArmPlatformGetPrimaryCoreMpId (
+//  VOID
+//  );
+ASM_PFX(ArmPlatformGetPrimaryCoreMpId):
+  MOV32 (w0, FixedPcdGet32(PcdArmPrimaryCore))
+  ret
+
+//UINTN
+//ArmPlatformIsPrimaryCore (
+//  IN UINTN MpId
+//  );
+ASM_PFX(ArmPlatformIsPrimaryCore):
+  MOV32 (w1, FixedPcdGet32(PcdArmPrimaryCoreMask))
+  and   x0, x0, x1
+  MOV32 (w1, FixedPcdGet32(PcdArmPrimaryCore))
+  cmp   w0, w1
+  cset  x0, eq
+  ret
diff --git a/Platform/ARM/SgiPkg/Library/PlatformLib/Mem.c b/Platform/ARM/SgiPkg/Library/PlatformLib/Mem.c
new file mode 100644
index 0000000..124742b
--- /dev/null
+++ b/Platform/ARM/SgiPkg/Library/PlatformLib/Mem.c
@@ -0,0 +1,111 @@
+/** @file
+*
+*  Copyright (c) 2018, ARM Limited. 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 <Library/ArmPlatformLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <Library/PcdLib.h>
+#include <Library/IoLib.h>
+#include <Library/MemoryAllocationLib.h>
+
+#include <SgiPlatform.h>
+
+// The total number of descriptors, including the final "end-of-table" descriptor.
+#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS  8
+
+// DDR attributes
+#define DDR_ATTRIBUTES_CACHED           ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
+#define DDR_ATTRIBUTES_UNCACHED         ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED
+
+/**
+  Return the Virtual Memory Map of your platform
+
+  This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.
+
+  @param[out]   VirtualMemoryMap    Array of ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-
+                                    Virtual Memory mapping. This array must be ended by a zero-filled
+                                    entry
+
+**/
+VOID
+ArmPlatformGetVirtualMemoryMap (
+  IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap
+  )
+{
+  ARM_MEMORY_REGION_ATTRIBUTES  CacheAttributes;
+  UINTN                         Index = 0;
+  ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;
+
+  ASSERT (VirtualMemoryMap != NULL);
+
+  VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages (EFI_SIZE_TO_PAGES (
+              sizeof (ARM_MEMORY_REGION_DESCRIPTOR) * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS ) );
+  if (VirtualMemoryTable == NULL) {
+    return;
+  }
+
+  CacheAttributes = DDR_ATTRIBUTES_CACHED;
+
+  // Expansion AXI - SMC Chip Select 0 (NOR Flash)
+  VirtualMemoryTable[Index].PhysicalBase    = SGI_EXP_SMC_CS0_BASE;
+  VirtualMemoryTable[Index].VirtualBase     = SGI_EXP_SMC_CS0_BASE;
+  VirtualMemoryTable[Index].Length          = SIZE_64MB;
+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
+
+  // Expansion AXI - SMSC 91X (Ethernet)
+  VirtualMemoryTable[++Index].PhysicalBase  = SGI_EXP_SMSC91X_BASE;
+  VirtualMemoryTable[Index].VirtualBase     = SGI_EXP_SMSC91X_BASE;
+  VirtualMemoryTable[Index].Length          = SGI_EXP_SMSC91X_SZ;
+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
+
+  // Expansion AXI - System Peripherals
+  VirtualMemoryTable[++Index].PhysicalBase  = SGI_EXP_SYS_PERIPH_BASE;
+  VirtualMemoryTable[Index].VirtualBase     = SGI_EXP_SYS_PERIPH_BASE;
+  VirtualMemoryTable[Index].Length          = SGI_EXP_SYS_PERIPH_SZ;
+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
+
+  // Sub System Peripherals - Generic Watchdog
+  VirtualMemoryTable[++Index].PhysicalBase  = SGI_SUBSYS_GENERIC_WDOG_BASE;
+  VirtualMemoryTable[Index].VirtualBase     = SGI_SUBSYS_GENERIC_WDOG_BASE;
+  VirtualMemoryTable[Index].Length          = SGI_SUBSYS_GENERIC_WDOG_SZ;
+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
+
+  // Sub System Peripherals - GIC-600
+  VirtualMemoryTable[++Index].PhysicalBase  = SGI_SUBSYS_GENERIC_GIC_BASE;
+  VirtualMemoryTable[Index].VirtualBase     = SGI_SUBSYS_GENERIC_GIC_BASE;
+  VirtualMemoryTable[Index].Length          = SGI_SUBSYS_GENERIC_GIC_SZ;
+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
+
+  // Expansion AXI - Platform Peripherals - UART1
+  VirtualMemoryTable[++Index].PhysicalBase  = SGI_EXP_PLAT_PERIPH_UART1_BASE;
+  VirtualMemoryTable[Index].VirtualBase     = SGI_EXP_PLAT_PERIPH_UART1_BASE;
+  VirtualMemoryTable[Index].Length          = SGI_EXP_PLAT_PERIPH_UART1_SZ;
+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
+
+  // DDR - (2GB - 16MB)
+  VirtualMemoryTable[++Index].PhysicalBase  = PcdGet64 (PcdSystemMemoryBase);
+  VirtualMemoryTable[Index].VirtualBase     = PcdGet64 (PcdSystemMemoryBase);
+  VirtualMemoryTable[Index].Length          = PcdGet64 (PcdSystemMemorySize);
+  VirtualMemoryTable[Index].Attributes      = CacheAttributes;
+
+  // End of Table
+  VirtualMemoryTable[++Index].PhysicalBase  = 0;
+  VirtualMemoryTable[Index].VirtualBase     = 0;
+  VirtualMemoryTable[Index].Length          = 0;
+  VirtualMemoryTable[Index].Attributes      = (ARM_MEMORY_REGION_ATTRIBUTES)0;
+
+  ASSERT ( (Index + 1) <= MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);
+
+  *VirtualMemoryMap = VirtualMemoryTable;
+}
diff --git a/Platform/ARM/SgiPkg/Library/PlatformLib/Platform.c b/Platform/ARM/SgiPkg/Library/PlatformLib/Platform.c
new file mode 100644
index 0000000..6b29768
--- /dev/null
+++ b/Platform/ARM/SgiPkg/Library/PlatformLib/Platform.c
@@ -0,0 +1,72 @@
+/** @file
+*
+*  Copyright (c) 2018, ARM Limited. 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 <Library/ArmPlatformLib.h>
+#include <Library/BaseLib.h>
+#include <Ppi/ArmMpCoreInfo.h>
+
+STATIC ARM_CORE_INFO mCoreInfoTable[] = {
+  {
+    // Cluster 0, Core 0
+    0x0, 0x0,
+  },
+};
+
+EFI_BOOT_MODE
+ArmPlatformGetBootMode (
+  VOID
+  )
+{
+  return BOOT_WITH_FULL_CONFIGURATION;
+}
+
+RETURN_STATUS
+ArmPlatformInitialize (
+  IN  UINTN                     MpId
+  )
+{
+  return RETURN_SUCCESS;
+}
+
+EFI_STATUS
+PrePeiCoreGetMpCoreInfo (
+  OUT UINTN                   *CoreCount,
+  OUT ARM_CORE_INFO           **ArmCoreTable
+  )
+{
+  *CoreCount = 1;
+  *ArmCoreTable = mCoreInfoTable;
+  return EFI_SUCCESS;
+}
+
+STATIC EFI_GUID mArmMpCoreInfoPpiGuid = ARM_MP_CORE_INFO_PPI_GUID;
+STATIC ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi = { PrePeiCoreGetMpCoreInfo };
+
+EFI_PEI_PPI_DESCRIPTOR      gPlatformPpiTable[] = {
+  {
+    EFI_PEI_PPI_DESCRIPTOR_PPI,
+    &mArmMpCoreInfoPpiGuid,
+    &mMpCoreInfoPpi
+  }
+};
+
+VOID
+ArmPlatformGetPlatformPpiList (
+  OUT UINTN                   *PpiListSize,
+  OUT EFI_PEI_PPI_DESCRIPTOR  **PpiList
+  )
+{
+  *PpiListSize = sizeof (gPlatformPpiTable);
+  *PpiList = gPlatformPpiTable;
+}
diff --git a/Platform/ARM/SgiPkg/Library/PlatformLib/PlatformLib.inf b/Platform/ARM/SgiPkg/Library/PlatformLib/PlatformLib.inf
new file mode 100644
index 0000000..c4b7719
--- /dev/null
+++ b/Platform/ARM/SgiPkg/Library/PlatformLib/PlatformLib.inf
@@ -0,0 +1,56 @@
+#
+#  Copyright (c) 2018, ARM Limited. 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                    = 0x00010005
+  BASE_NAME                      = ArmSgiLib
+  FILE_GUID                      = 1d0ee1e1-d791-4ecf-a43e-a9c76e674264
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = ArmPlatformLib
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  EmbeddedPkg/EmbeddedPkg.dec
+  ArmPkg/ArmPkg.dec
+  ArmPlatformPkg/ArmPlatformPkg.dec
+  edk2-platforms/Platform/ARM/SgiPkg/SgiPlatform.dec
+
+[LibraryClasses]
+  IoLib
+  ArmLib
+  DebugLib
+  HobLib
+  MemoryAllocationLib
+  SerialPortLib
+
+[Sources.common]
+  Platform.c
+  Mem.c
+
+[Sources.AARCH64]
+  AArch64/Helper.S | GCC
+
+[FixedPcd]
+  gArmPlatformTokenSpaceGuid.PcdClusterCount
+  gArmPlatformTokenSpaceGuid.PcdCoreCount
+  gArmTokenSpaceGuid.PcdSystemMemoryBase
+  gArmTokenSpaceGuid.PcdSystemMemorySize
+  gArmTokenSpaceGuid.PcdGicDistributorBase
+  gArmTokenSpaceGuid.PcdGicRedistributorsBase
+  gArmTokenSpaceGuid.PcdFvBaseAddress
+  gArmTokenSpaceGuid.PcdArmPrimaryCore
+  gArmTokenSpaceGuid.PcdArmPrimaryCoreMask
+
+  [Guids]
+  gEfiHobListGuid          ## CONSUMES  ## SystemTable
-- 
2.7.4



  reply	other threads:[~2018-04-12 18:48 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-12 18:47 [PATCH edk2-platforms v2 0/6] Platform/ARM/Sgi: Add Arm's SGI platform support Thomas Abraham
2018-04-12 18:47 ` Thomas Abraham [this message]
2018-04-16  6:19   ` [PATCH edk2-platforms v2 1/6] Platform/ARM/Sgi: Add Platform library implementation Ard Biesheuvel
2018-04-12 18:47 ` [PATCH edk2-platforms v2 2/6] Platform/ARM/Sgi: add NOR flash platform " Thomas Abraham
2018-04-16  6:21   ` Ard Biesheuvel
2018-04-12 18:47 ` [PATCH edk2-platforms v2 3/6] Platform/ARM/Sgi: add initial platform dxe driver implementation Thomas Abraham
2018-04-16  6:23   ` Ard Biesheuvel
2018-04-12 18:47 ` [PATCH edk2-platforms v2 4/6] Platform/ARM/Sgi: add support for virtio block device Thomas Abraham
2018-04-16  6:25   ` Ard Biesheuvel
2018-04-12 18:47 ` [PATCH edk2-platforms v2 5/6] Platform/ARM/Sgi: add the initial set of acpi tables Thomas Abraham
2018-04-16  6:31   ` Ard Biesheuvel
2018-04-12 18:47 ` [PATCH edk2-platforms v2 6/6] Platform/ARM/Sgi: add initial support for ARM SGI platform Thomas Abraham
2018-04-16  6:35   ` Ard Biesheuvel
2018-04-16 10:44   ` Ard Biesheuvel
2018-05-09  8:56     ` Thomas Abraham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1523558863-5427-2-git-send-email-thomas.abraham@arm.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox