public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Jit Loon Lim <jit.loon.lim@intel.com>
To: u-boot@lists.denx.de
Cc: Jagan Teki <jagan@amarulasolutions.com>,
	Vignesh R <vigneshr@ti.com>, Marek <marex@denx.de>,
	Simon <simon.k.r.goldschmidt@gmail.com>,
	Tien Fong <tien.fong.chee@intel.com>,
	Kok Kiang <kok.kiang.hea@intel.com>,
	Raaj <raaj.lokanathan@intel.com>,
	Dinesh <dinesh.maniyam@intel.com>,
	Boon Khai <boon.khai.ng@intel.com>,
	Alif <alif.zakuan.yuslaimi@intel.com>,
	Teik Heng <teik.heng.chong@intel.com>,
	Hazim <muhammad.hazim.izzat.zamri@intel.com>,
	Jit Loon Lim <jit.loon.lim@intel.com>,
	Sieu Mun Tang <sieu.mun.tang@intel.com>
Subject: [PATCH v1 10/17] drivers: misc: update driver misc for agilex5
Date: Wed, 21 Jun 2023 11:16:03 +0800	[thread overview]
Message-ID: <20230621031610.28401-11-jit.loon.lim@intel.com> (raw)
In-Reply-To: <20230621031610.28401-1-jit.loon.lim@intel.com>

This is for new platform enablement for agilex5.
Update secure registers, Kconfig and makefile for new platform.

Signed-off-by: Jit Loon Lim <jit.loon.lim@intel.com>
---
 drivers/misc/Kconfig          |   9 +++
 drivers/misc/Makefile         |   1 +
 drivers/misc/socfpga_secreg.c | 116 ++++++++++++++++++++++++++++++++++
 3 files changed, 126 insertions(+)
 create mode 100644 drivers/misc/socfpga_secreg.c

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 04460f1acb..3b6f5314ff 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -666,4 +666,13 @@ config SL28CPLD
 	  the base driver which provides common access methods for the
 	  sub-drivers.
 
+config SPL_SOCFPGA_SEC_REG
+	bool "Enable register setting from device tree in SPL"
+	depends on SPL
+	help
+	  Enable register setting from device tree in SPL, which require
+	  high privilege access like firewall registers. This also
+	  provides user a clean interface and all register settings are
+	  centralized in one place, device tree.
+
 endmenu
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 52aed09602..441c03509f 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -88,3 +88,4 @@ obj-$(CONFIG_K3_AVS0) += k3_avs.o
 obj-$(CONFIG_ESM_K3) += k3_esm.o
 obj-$(CONFIG_ESM_PMIC) += esm_pmic.o
 obj-$(CONFIG_SL28CPLD) += sl28cpld.o
+obj-$(CONFIG_SPL_SOCFPGA_SEC_REG) += socfpga_secreg.o
diff --git a/drivers/misc/socfpga_secreg.c b/drivers/misc/socfpga_secreg.c
new file mode 100644
index 0000000000..3f3ba8b0c1
--- /dev/null
+++ b/drivers/misc/socfpga_secreg.c
@@ -0,0 +1,116 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2021-2023 Intel Corporation <www.intel.com>
+ */
+
+#include <asm/io.h>
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <linux/sizes.h>
+
+#define NUMBER_OF_ELEMENTS 3
+
+static int socfpga_secreg_probe(struct udevice *dev)
+{
+	const fdt32_t *list;
+	fdt_addr_t offset, base;
+	fdt_val_t val, read_val, mask, set_mask;
+	int size, i;
+	u32 blk_sz, reg;
+	ofnode node;
+	const char *name = NULL;
+
+	debug("%s(dev=%p)\n", __func__, dev);
+
+	if (!dev_has_ofnode(dev))
+		return 0;
+
+	dev_for_each_subnode(node, dev) {
+		name = ofnode_get_name(node);
+		if (!name)
+			return -EINVAL;
+
+		if (ofnode_read_u32_index(node, "reg", 1, &blk_sz))
+			return -EINVAL;
+
+		base = ofnode_get_addr(node);
+		if (base == FDT_ADDR_T_NONE)
+			return -EINVAL;
+
+		debug("%s(node_offset 0x%lx node_name %s ", __func__,
+		      node.of_offset, name);
+		debug("node addr 0x%llx blk sz 0x%x)\n", base, blk_sz);
+
+		list = ofnode_read_prop(node, "intel,offset-settings", &size);
+		if (!list)
+			return -EINVAL;
+
+		debug("%s(intel,offset-settings property size=%x)\n", __func__,
+		      size);
+		size /= sizeof(*list) * NUMBER_OF_ELEMENTS;
+
+		/*
+		 * First element: offset
+		 * Second element: val
+		 * Third element: mask
+		 */
+		for (i = 0; i < size; i++) {
+			offset = fdt32_to_cpu(*list++);
+			val = fdt32_to_cpu(*list++);
+
+			/* Reads the masking bit value from the list */
+			mask = fdt32_to_cpu(*list++);
+
+			/*
+			 * Reads out the offsets, value and masking bits
+			 * Ex: <0x00000000 0x00000230 0xffffffff>
+			 */
+			debug("%s(intel,offset-settings 0x%llx : 0x%llx : 0x%llx)\n",
+			      __func__, offset, val, mask);
+
+			if (blk_sz < offset + SZ_4) {
+				printf("%s: Overflow as offset 0x%llx or reg",
+				       __func__, offset);
+				printf(" write is more than block size 0x%x\n",
+				       blk_sz);
+				return -EINVAL;
+			}
+
+			if (mask != 0) {
+				if (mask == 0xffffffff) {
+					reg = base + offset;
+					writel(val, (uintptr_t)reg);
+				} else {
+					/* Mask the value with the masking bits */
+					set_mask = val & mask;
+
+					reg = base + offset;
+
+					/* Clears and sets specific bits in the register */
+					clrsetbits_le32((uintptr_t)reg, mask, set_mask);
+				}
+			}
+
+			read_val = readl((uintptr_t)reg);
+
+			/* Reads out the register, masked value and the read value */
+			debug("%s(reg 0x%x = wr : 0x%llx  rd : 0x%llx)\n",
+			      __func__, reg, set_mask, read_val);
+		}
+	}
+
+	return 0;
+};
+
+static const struct udevice_id socfpga_secreg_ids[] = {
+	{.compatible = "intel,socfpga-secreg"},
+	{ }
+};
+
+U_BOOT_DRIVER(socfpga_secreg) = {
+	.name		= "socfpga-secreg",
+	.id		= UCLASS_NOP,
+	.of_match	= socfpga_secreg_ids,
+	.probe		= socfpga_secreg_probe,
+};
-- 
2.26.2


  parent reply	other threads:[~2023-06-21  3:18 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-21  3:15 [PATCH v1 00/17] Agilex5 Platform Enablement Jit Loon Lim
2023-06-21  3:15 ` [PATCH v1 01/17] arch: arm: update kconfig for new platform agilex5 Jit Loon Lim
2023-06-28  8:17   ` Chee, Tien Fong
2023-06-30  8:18     ` Lim, Jit Loon
2023-06-21  3:15 ` [PATCH v1 02/17] arch: arm: dts: add dts and dtsi " Jit Loon Lim
2023-06-28  9:13   ` Chee, Tien Fong
2023-06-30  8:29     ` Lim, Jit Loon
2023-06-21  3:15 ` [PATCH v1 03/17] arch: arm: mach-socfpga: add new platform agilex5 mach-socfpga enablement Jit Loon Lim
2023-06-28  9:49   ` Chee, Tien Fong
2023-06-21  3:15 ` [PATCH v1 04/17] arch: arm: mach-socfpga: include: mach: " Jit Loon Lim
2023-06-21  3:15 ` [PATCH v1 05/17] board: intel: add new platform agilex5 socdk Jit Loon Lim
2023-06-21  3:15 ` [PATCH v1 06/17] configs: add new platform agilex5 defconfig Jit Loon Lim
2023-06-21  3:16 ` [PATCH v1 07/17] doc: device-tree-bindings: misc: add secreg text file for agilex5 Jit Loon Lim
2023-06-21  3:16 ` [PATCH v1 08/17] drivers: ddr: altera: add ddr support " Jit Loon Lim
2023-06-21  3:16 ` [PATCH v1 09/17] drivers: clk: altera: add clock " Jit Loon Lim
2023-06-21  3:16 ` Jit Loon Lim [this message]
2023-06-21  3:16 ` [PATCH v1 11/17] drivers: mmc: add mmc/cadence driver " Jit Loon Lim
2023-06-21  3:16 ` [PATCH v1 12/17] drivers: phy: add combo phy " Jit Loon Lim
2023-06-21  3:16 ` [PATCH v1 13/17] drivers: reset: add reset " Jit Loon Lim
2023-06-21  3:16 ` [PATCH v1 14/17] drivers: sysreset: add system " Jit Loon Lim
2023-06-21  3:16 ` [PATCH v1 15/17] drivers: watchdog: update watchdog " Jit Loon Lim
2023-06-21  3:16 ` [PATCH v1 16/17] includes: add and update configuration " Jit Loon Lim
2023-06-21  3:16 ` [PATCH v1 17/17] tools: binman: update binman tool " Jit Loon Lim

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=20230621031610.28401-11-jit.loon.lim@intel.com \
    --to=jit.loon.lim@intel.com \
    --cc=alif.zakuan.yuslaimi@intel.com \
    --cc=boon.khai.ng@intel.com \
    --cc=dinesh.maniyam@intel.com \
    --cc=jagan@amarulasolutions.com \
    --cc=kok.kiang.hea@intel.com \
    --cc=marex@denx.de \
    --cc=muhammad.hazim.izzat.zamri@intel.com \
    --cc=raaj.lokanathan@intel.com \
    --cc=sieu.mun.tang@intel.com \
    --cc=simon.k.r.goldschmidt@gmail.com \
    --cc=teik.heng.chong@intel.com \
    --cc=tien.fong.chee@intel.com \
    --cc=u-boot@lists.denx.de \
    --cc=vigneshr@ti.com \
    /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