All of lore.kernel.org
 help / color / mirror / Atom feed
From: chee.hong.ang at intel.com <chee.hong.ang@intel.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v1 10/20] arm: socfpga: Add secure register access helper functions for SoC 64bits
Date: Mon,  2 Dec 2019 02:25:11 -0800	[thread overview]
Message-ID: <1575282321-11597-11-git-send-email-chee.hong.ang@intel.com> (raw)
In-Reply-To: <1575282321-11597-1-git-send-email-chee.hong.ang@intel.com>

From: Chee Hong Ang <chee.hong.ang@intel.com>

These secure register access functions allow U-Boot proper running
at EL2 (non-secure) to access System Manager's secure registers
by calling the ATF's PSCI runtime services (EL3/secure). If these
helper functions are called from secure mode (EL3), the helper
function will direct access the secure registers without calling
the ATF's PSCI runtime services.

Signed-off-by: Chee Hong Ang <chee.hong.ang@intel.com>
---
 arch/arm/mach-socfpga/Makefile                     |  2 +
 .../mach-socfpga/include/mach/secure_reg_helper.h  | 20 +++++++
 arch/arm/mach-socfpga/secure_reg_helper.c          | 67 ++++++++++++++++++++++
 3 files changed, 89 insertions(+)
 create mode 100644 arch/arm/mach-socfpga/include/mach/secure_reg_helper.h
 create mode 100644 arch/arm/mach-socfpga/secure_reg_helper.c

diff --git a/arch/arm/mach-socfpga/Makefile b/arch/arm/mach-socfpga/Makefile
index 3310e92..4b46b65 100644
--- a/arch/arm/mach-socfpga/Makefile
+++ b/arch/arm/mach-socfpga/Makefile
@@ -34,6 +34,7 @@ obj-y	+= mailbox_s10.o
 obj-y	+= misc_s10.o
 obj-y	+= mmu-arm64_s10.o
 obj-y	+= reset_manager_s10.o
+obj-y	+= secure_reg_helper.o
 obj-y	+= system_manager_s10.o
 obj-y	+= timer_s10.o
 obj-y	+= wrap_pinmux_config_s10.o
@@ -47,6 +48,7 @@ obj-y	+= mailbox_s10.o
 obj-y	+= misc_s10.o
 obj-y	+= mmu-arm64_s10.o
 obj-y	+= reset_manager_s10.o
+obj-y	+= secure_reg_helper.o
 obj-y	+= system_manager_s10.o
 obj-y	+= timer_s10.o
 obj-y	+= wrap_pinmux_config_s10.o
diff --git a/arch/arm/mach-socfpga/include/mach/secure_reg_helper.h b/arch/arm/mach-socfpga/include/mach/secure_reg_helper.h
new file mode 100644
index 0000000..0dc6534
--- /dev/null
+++ b/arch/arm/mach-socfpga/include/mach/secure_reg_helper.h
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (C) 2019 Intel Corporation <www.intel.com>
+ *
+ */
+
+#ifndef	_SECURE_REG_HELPER_H_
+#define	_SECURE_REG_HELPER_H_
+
+#ifdef CONFIG_ARM_SMCCC
+u32 socfpga_secure_reg_read32(phys_addr_t reg_addr);
+void socfpga_secure_reg_write32(u32 val, phys_addr_t reg_addr);
+void socfpga_secure_reg_update32(phys_addr_t reg_addr, u32 mask, u32 val);
+#else
+#define socfpga_secure_reg_read32	readl
+#define socfpga_secure_reg_write32	writel
+#define socfpga_secure_reg_update32	clrsetbits_le32
+#endif
+
+#endif /* _SECURE_REG_HELPER_H_ */
diff --git a/arch/arm/mach-socfpga/secure_reg_helper.c b/arch/arm/mach-socfpga/secure_reg_helper.c
new file mode 100644
index 0000000..2968fab
--- /dev/null
+++ b/arch/arm/mach-socfpga/secure_reg_helper.c
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2019 Intel Corporation <www.intel.com>
+ *
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include <asm/system.h>
+#include <asm/arch/misc.h>
+#include <linux/intel-smc.h>
+
+u32 socfpga_secure_reg_read32(phys_addr_t reg_addr)
+{
+	int ret;
+	u64 ret_arg;
+	u64 args[1];
+
+	if (current_el() == 3)
+		return readl(reg_addr);
+
+	args[0] = (u64)reg_addr;
+	ret = invoke_smc(INTEL_SIP_SMC_REG_READ, args, 1, &ret_arg, 1);
+	if (ret) {
+		/* SMC call return error */
+		hang();
+	}
+
+	return ret_arg;
+}
+
+void socfpga_secure_reg_write32(u32 val, phys_addr_t reg_addr)
+{
+	int ret;
+	u64 args[2];
+
+	if (current_el() == 3) {
+		writel(val, (u32 *)reg_addr);
+	} else {
+		args[0] = (u64)reg_addr;
+		args[1] = val;
+		ret = invoke_smc(INTEL_SIP_SMC_REG_WRITE, args, 2, NULL, 0);
+		if (ret) {
+			/* SMC call return error */
+			hang();
+		}
+	}
+}
+
+void socfpga_secure_reg_update32(phys_addr_t reg_addr, u32 mask, u32 val)
+{
+	int ret;
+	u64 args[3];
+
+	if (current_el() == 3) {
+		clrsetbits_le32(reg_addr, mask, val);
+	} else {
+		args[0] = (u64)reg_addr;
+		args[1] = mask;
+		args[2] = val;
+		ret = invoke_smc(INTEL_SIP_SMC_REG_UPDATE, args, 3, NULL, 0);
+		if (ret) {
+			/* SMC call return error */
+			hang();
+		}
+	}
+}
-- 
2.7.4

  parent reply	other threads:[~2019-12-02 10:25 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-02 10:25 [U-Boot] [PATCH v1 00/20] Enable ARM Trusted Firmware for U-Boot chee.hong.ang at intel.com
2019-12-02 10:25 ` [U-Boot] [PATCH v1 01/20] configs: stratix10: Remove CONFIG_OF_EMBED chee.hong.ang at intel.com
2019-12-02 10:25 ` [U-Boot] [PATCH v1 02/20] arm: socfpga: add fit source file for pack itb with ATF chee.hong.ang at intel.com
2019-12-02 10:25 ` [U-Boot] [PATCH v1 03/20] arm: socfpga: Add function for checking description from FIT image chee.hong.ang at intel.com
2019-12-02 10:25 ` [U-Boot] [PATCH v1 04/20] arm: socfpga: Load FIT image with ATF support chee.hong.ang at intel.com
2019-12-02 10:25 ` [U-Boot] [PATCH v1 05/20] arm: socfpga: Override 'lowlevel_init' to support ATF chee.hong.ang at intel.com
2019-12-02 10:25 ` [U-Boot] [PATCH v1 06/20] configs: socfpga: Enable FIT image loading with ATF support chee.hong.ang at intel.com
2019-12-02 10:25 ` [U-Boot] [PATCH v1 07/20] arm: socfpga: Disable "spin-table" method for booting Linux chee.hong.ang at intel.com
2019-12-02 10:25 ` [U-Boot] [PATCH v1 08/20] arm: socfpga: Add SMC helper function for Intel SOCFPGA (64bits) chee.hong.ang at intel.com
2019-12-02 10:25 ` [U-Boot] [PATCH v1 09/20] arm: socfpga: Define SMC function identifiers for PSCI SiP services chee.hong.ang at intel.com
2019-12-02 10:25 ` chee.hong.ang at intel.com [this message]
2019-12-02 10:25 ` [U-Boot] [PATCH v1 11/20] arm: socfpga: Secure register access for clock manager (SoC 64bits) chee.hong.ang at intel.com
2019-12-02 10:25 ` [U-Boot] [PATCH v1 12/20] arm: socfpga: Secure register access in PHY mode setup chee.hong.ang at intel.com
2019-12-02 10:25 ` [U-Boot] [PATCH v1 13/20] arm: socfpga: Secure register access for reading PLL frequency chee.hong.ang at intel.com
2019-12-02 10:25 ` [U-Boot] [PATCH v1 14/20] mmc: dwmmc: socfpga: Secure register access in MMC driver chee.hong.ang at intel.com
2019-12-02 10:25 ` [U-Boot] [PATCH v1 15/20] net: designware: socfpga: Secure register access in MAC driver chee.hong.ang at intel.com
2019-12-02 10:25 ` [U-Boot] [PATCH v1 16/20] arm: socfpga: Secure register access in Reset Manager driver chee.hong.ang at intel.com
2019-12-02 10:25 ` [U-Boot] [PATCH v1 17/20] arm: socfpga: stratix10: Initialize timer in SPL chee.hong.ang at intel.com
2019-12-02 10:25 ` [U-Boot] [PATCH v1 18/20] arm: socfpga: stratix10: Refactor FPGA reconfig driver to support ATF chee.hong.ang at intel.com
2019-12-02 10:25 ` [U-Boot] [PATCH v1 19/20] arm: socfpga: Bridge reset now invokes SMC calls to query FPGA config status chee.hong.ang at intel.com
2019-12-02 10:25 ` [U-Boot] [PATCH v1 20/20] sysreset: socfpga: Invoke PSCI call for COLD reset chee.hong.ang at intel.com
2019-12-02 13:27 ` [U-Boot] [PATCH v1 00/20] Enable ARM Trusted Firmware for U-Boot Simon Goldschmidt
2019-12-02 13:38   ` Ang, Chee Hong
2019-12-02 13:53     ` Simon Goldschmidt
2019-12-02 14:05       ` Ang, Chee Hong
2019-12-02 14:19         ` Ang, Chee Hong
2019-12-02 14:28         ` Simon Goldschmidt
2019-12-02 15:18           ` Ang, Chee Hong
2019-12-02 15:32             ` Simon Goldschmidt
2019-12-02 16:10               ` Ang, Chee Hong
2019-12-02 20:40                 ` Simon Goldschmidt
2019-12-03  1:37                   ` Ang, Chee Hong
2019-12-03 11:35                     ` Simon Goldschmidt
2019-12-03 14:45                       ` Ang, Chee Hong
2019-12-03 14:59                         ` Dalon L Westergreen
2019-12-03 20:09                           ` Simon Goldschmidt
2019-12-03 23:18                             ` Tom Rini
2019-12-03 15:10                         ` Simon Goldschmidt
2019-12-03 18:31                           ` Ang, Chee Hong
2019-12-03 20:08                             ` Simon Goldschmidt
2019-12-04  7:34                               ` Ang, Chee Hong
2019-12-03 20:29 ` Simon Goldschmidt
2019-12-04  7:40   ` Ang, Chee Hong

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-all 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=1575282321-11597-11-git-send-email-chee.hong.ang@intel.com \
    --to=chee.hong.ang@intel.com \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.