public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Abner Chang" <abner.chang@hpe.com>
To: devel@edk2.groups.io
Cc: abner.chang@hpe.com,
	Michael D Kinney <michael.d.kinney@intel.com>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Leif Lindholm <leif.lindholm@linaro.org>,
	Gilbert Chen <gilbert.chen@hpe.com>,
	Palmer Dabbelt <palmer@sifive.com>
Subject: [platform/devel-riscv-v2 PATCHv5 08/18] U5SeriesPkg/RiscVPlatformTimerLib: Platform Timer library
Date: Mon, 28 Oct 2019 12:20:23 +0800	[thread overview]
Message-ID: <1572236433-15404-9-git-send-email-abner.chang@hpe.com> (raw)
In-Reply-To: <1572236433-15404-1-git-send-email-abner.chang@hpe.com>

Timer library used to access to machine mode timer Control Status Registers
for U5 series platforms.

Signed-off-by: Abner Chang <abner.chang@hpe.com>

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Gilbert Chen <gilbert.chen@hpe.com>
Cc: Palmer Dabbelt <palmer@sifive.com>
Signed-off-by: Abner Chang <abner.chang@hpe.com>
---
 .../RiscVPlatformTimerLib.inf                      | 36 ++++++++++++++++
 Platform/SiFive/U5SeriesPkg/Include/U5Clint.h      | 20 +++++++++
 .../RiscVPlatformTimerLib/RiscVPlatformTimerLib.S  | 48 ++++++++++++++++++++++
 3 files changed, 104 insertions(+)
 create mode 100644 Platform/SiFive/U5SeriesPkg/Library/RiscVPlatformTimerLib/RiscVPlatformTimerLib.inf
 create mode 100644 Platform/SiFive/U5SeriesPkg/Include/U5Clint.h
 create mode 100644 Platform/SiFive/U5SeriesPkg/Library/RiscVPlatformTimerLib/RiscVPlatformTimerLib.S

diff --git a/Platform/SiFive/U5SeriesPkg/Library/RiscVPlatformTimerLib/RiscVPlatformTimerLib.inf b/Platform/SiFive/U5SeriesPkg/Library/RiscVPlatformTimerLib/RiscVPlatformTimerLib.inf
new file mode 100644
index 0000000..777ec98
--- /dev/null
+++ b/Platform/SiFive/U5SeriesPkg/Library/RiscVPlatformTimerLib/RiscVPlatformTimerLib.inf
@@ -0,0 +1,36 @@
+## @file
+# RISC-V CPU lib to override timer mechanism for U5 series platform.
+#
+# Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x0001001b
+  BASE_NAME                      = RiscVPlatformTimerLib
+  FILE_GUID                      = AFA75BBD-DE9D-4E77-BD88-1EA401BE931D
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = RiscVPlatformTimerLib
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+#  VALID_ARCHITECTURES           = RISCV64
+#
+
+[Sources]
+
+[Sources.RISCV64]
+  RiscVPlatformTimerLib.S
+
+[Packages]
+  MdeModulePkg/MdeModulePkg.dec
+  MdePkg/MdePkg.dec
+  Platform/SiFive/U5SeriesPkg/U5SeriesPkg.dec
+  RiscVPkg/RiscVPkg.dec
+
+
+
diff --git a/Platform/SiFive/U5SeriesPkg/Include/U5Clint.h b/Platform/SiFive/U5SeriesPkg/Include/U5Clint.h
new file mode 100644
index 0000000..26260dc
--- /dev/null
+++ b/Platform/SiFive/U5SeriesPkg/Include/U5Clint.h
@@ -0,0 +1,20 @@
+/** @file
+  RISC-V Timer Architectural definition for U500 platform.
+
+  Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+#ifndef U5_CLINT_H_
+#define U5_CLINT_H_
+
+#define CLINT_REG_BASE_ADDR 0x02000000
+    #define CLINT_REG_MTIME     0x0200BFF8
+    #define CLINT_REG_MTIMECMP0 0x02004000
+    #define CLINT_REG_MTIMECMP1 0x02004008
+    #define CLINT_REG_MTIMECMP2 0x02004010
+    #define CLINT_REG_MTIMECMP3 0x02004018
+    #define CLINT_REG_MTIMECMP4 0x02004020
+
+#endif
diff --git a/Platform/SiFive/U5SeriesPkg/Library/RiscVPlatformTimerLib/RiscVPlatformTimerLib.S b/Platform/SiFive/U5SeriesPkg/Library/RiscVPlatformTimerLib/RiscVPlatformTimerLib.S
new file mode 100644
index 0000000..a49149e
--- /dev/null
+++ b/Platform/SiFive/U5SeriesPkg/Library/RiscVPlatformTimerLib/RiscVPlatformTimerLib.S
@@ -0,0 +1,48 @@
+//------------------------------------------------------------------------------
+//
+// SiFive U5 Series Timer CSR functions.
+//
+// Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+//------------------------------------------------------------------------------
+#include <Base.h>
+#include <RiscVImpl.h>
+#include <U5Clint.h>
+
+.data
+
+.text
+.align 3
+
+.global ASM_PFX(RiscVReadMachineTimer)
+.global ASM_PFX(RiscVSetMachineTimerCmp)
+.global ASM_PFX(RiscVReadMachineTimerCmp)
+
+//
+// Read machine timer CSR.
+// @retval a0 : 64-bit machine timer.
+//
+ASM_PFX (RiscVReadMachineTimer):
+    li t1, CLINT_REG_MTIME
+    ld a0, (t1)
+    ret
+
+//
+// Set machine timer compare CSR.
+// @param a0 : UINT64
+//
+ASM_PFX (RiscVSetMachineTimerCmp):
+    li t1, CLINT_REG_MTIMECMP0
+    sd a0, (t1)
+    ret
+
+//
+// Read machine timer compare CSR.
+// @param a0 : UINT64
+//
+ASM_PFX (RiscVReadMachineTimerCmp):
+    li t1, CLINT_REG_MTIMECMP0
+    ld a0, (t1)
+    ret
-- 
2.7.4


  parent reply	other threads:[~2019-10-28  4:52 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-28  4:20 [platform/devel-riscv-v2 PATCHv5 00/18] Initial version of RISC-V Abner Chang
2019-10-28  4:20 ` [platform/devel-riscv-v2 PATCHv5 01/18] Silicon/SiFive: Initial version of SiFive silicon package Abner Chang
2019-10-28  4:20 ` [platform/devel-riscv-v2 PATCHv5 02/18] SiFive/E51: Initial version of SiFive E51 core library Abner Chang
2019-10-28  4:20 ` [platform/devel-riscv-v2 PATCHv5 03/18] SiFive/U54: Initial version of SiFive U54 " Abner Chang
2019-10-28  4:20 ` [platform/devel-riscv-v2 PATCHv5 04/18] SiFive/U54MC: Initial version of SiFive U54MC Coreplex library Abner Chang
2019-10-28  4:20 ` [platform/devel-riscv-v2 PATCHv5 05/18] U5SeriesPkg/PeiCoreInfoHobLib: Library to create core information Abner Chang
2019-10-28  4:20 ` [platform/devel-riscv-v2 PATCHv5 06/18] U5SeriesPkg/TimerDxe: U5 Series Platform Timer DXE driver Abner Chang
2019-10-28  4:20 ` [platform/devel-riscv-v2 PATCHv5 07/18] U5SeriesPkg/RamFvbServicesRuntimeDxe: Firmware Volume Block service Abner Chang
2019-10-28  4:20 ` Abner Chang [this message]
2019-10-28  4:20 ` [platform/devel-riscv-v2 PATCHv5 09/18] U5SeriesPkg/SerialIoLib: Platform Serial Port library Abner Chang
2019-11-19 15:30   ` [edk2-devel] " Mark Salter
2019-10-28  4:20 ` [platform/devel-riscv-v2 PATCHv5 10/18] FreedomU540HiFiveUnleashedBoard/PlatformPei:Platform PEI Abner Chang
2019-10-28  4:20 ` [platform/devel-riscv-v2 PATCHv5 11/18] FreedomU540HiFiveUnleashedBoard/OpensbiPlatformLib:OpenSBI platform lib Abner Chang
2019-11-19 15:30   ` [edk2-devel] " Mark Salter
2019-10-28  4:20 ` [platform/devel-riscv-v2 PATCHv5 12/18] U5SeriesPkg/FreedomU540HiFiveUnleashedBoard: Add SiFive U540 platform Abner Chang
2019-10-28  4:20 ` [platform/devel-riscv-v2 PATCHv5 13/18] FreedomU500VC707Board/PlatformPei: Platform initialization PEI module Abner Chang
2019-10-28  4:20 ` [platform/devel-riscv-v2 PATCHv5 14/18] FreedomU500VC707Board/OpensbiPlatformLib: OpenSBI platform interface Abner Chang
2019-10-28  4:20 ` [platform/devel-riscv-v2 PATCHv5 15/18] U5SeriesPkg/FreedomU500VC707Board: Add SiFive U500 platform Abner Chang
2019-10-28  4:20 ` [platform/devel-riscv-v2 PATCHv5 16/18] SiFive/U5SeriesPkg Add U5SeriesPkg Abner Chang
2019-10-28  4:20 ` [platform/devel-riscv-v2 PATCHv5 17/18] edk2-platforms: Update Readme.md for RISC-V platform Abner Chang
2019-10-28  4:20 ` [platform/devel-riscv-v2 PATCHv5 18/18] edk2-platforms: Update Maintainers file Abner Chang
2019-11-26 15:22 ` [edk2-devel] [platform/devel-riscv-v2 PATCHv5 00/18] Initial version of RISC-V Leif Lindholm
2019-12-22  6:09   ` Abner Chang

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=1572236433-15404-9-git-send-email-abner.chang@hpe.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