Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5D51AC4332F for ; Sun, 11 Dec 2022 13:07:26 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 457F485394; Sun, 11 Dec 2022 14:07:08 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="OrzXNSlr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A496B85395; Sun, 11 Dec 2022 14:07:01 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9EF338539A for ; Sun, 11 Dec 2022 14:06:55 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=jitloonl@ecsmtp.png.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670764015; x=1702300015; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jhE5NsGO93Yyin9JcKpSVrae+OtA6b4SkQR2WCAHAvQ=; b=OrzXNSlrLW4io07hBkOxyN0meXZ77IaU9oVw+XLH6mhhASKLj6EMPB6R 8DZM2omaNsxlCC+8c7vq71tAC/cBFckA2Vhqu0AUB6ElX2aFqskaq6c5m FhiEZYvYQcN/SxElsaiVWcNNayaT6YxhkqIuK2O1fd0YpsVDyTwKRPCTk mUoQQGfNp2poCzef7pkz/Bb5pRJKlJV/8d+Q8Fmk7Sll2493ldnzYopgv hFAxhrtnBEVTsHIZml8wBiTgBRZLN+G8MBq1+mXP2KW+3G8I9HUx7HBw9 OpDYOQNeOv3l/w638szZqvMMDuVwYamb7ba/K0EyEetOLG14KmfhucCBD Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10557"; a="316394347" X-IronPort-AV: E=Sophos;i="5.96,236,1665471600"; d="scan'208";a="316394347" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Dec 2022 05:06:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10557"; a="678625510" X-IronPort-AV: E=Sophos;i="5.96,236,1665471600"; d="scan'208";a="678625510" Received: from pglmail07.png.intel.com ([10.221.193.207]) by orsmga008.jf.intel.com with ESMTP; 11 Dec 2022 05:06:48 -0800 Received: from localhost (pgli0028.png.intel.com [10.221.84.177]) by pglmail07.png.intel.com (Postfix) with ESMTP id DAD0B2B0D; Sun, 11 Dec 2022 21:06:47 +0800 (+08) Received: by localhost (Postfix, from userid 12048045) id D89F7E00218; Sun, 11 Dec 2022 21:06:47 +0800 (+08) From: Jit Loon Lim To: u-boot@lists.denx.de Cc: Jagan Teki , Vignesh R , Marek , Simon , Tien Fong , Kok Kiang , Siew Chin , Sin Hui , Raaj , Dinesh , Boon Khai , Alif , Teik Heng , Hazim , Jit Loon Lim , Sieu Mun Tang Subject: [PATCH 2/6] misc: socfpga_secreg: Enable register settings in DTS Date: Sun, 11 Dec 2022 21:06:40 +0800 Message-Id: <20221211130644.24832-2-jit.loon.lim@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20221211130644.24832-1-jit.loon.lim@intel.com> References: <20221211130644.24832-1-jit.loon.lim@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean From: Tien Fong Chee Enable register settings 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. Signed-off-by: Tien Fong Chee Signed-off-by: Jit Loon Lim --- drivers/misc/Kconfig | 9 ++++ drivers/misc/Makefile | 2 + drivers/misc/socfpga_secreg.c | 86 +++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 drivers/misc/socfpga_secreg.c diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index a6da6e215d..d9da836675 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -645,4 +645,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 d494639cd9..183d92b6e0 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -29,6 +29,7 @@ ifdef CONFIG_SPL_BUILD obj-$(CONFIG_SANDBOX) += spltest_sandbox.o endif endif + obj-$(CONFIG_ALI152X) += ali512x.o obj-$(CONFIG_ALTERA_SYSID) += altera_sysid.o obj-$(CONFIG_ATSHA204A) += atsha204a-i2c.o @@ -89,3 +90,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..a4b297e7f1 --- /dev/null +++ b/drivers/misc/socfpga_secreg.c @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2021 Intel Corporation + * + */ + +#include +#include +#include +#include + +static int socfpga_secreg_probe(struct udevice *dev) +{ + const fdt32_t *list; + fdt_addr_t offset, base; + fdt_val_t val, read_val; + 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) * 2; + for (i = 0; i < size; i++) { + offset = fdt32_to_cpu(*list++); + val = fdt32_to_cpu(*list++); + debug("%s(intel,offset-settings 0x%llx : 0x%llx)\n", + __func__, offset, val); + + if (blk_sz <= offset) { + printf("%s: Overflow as offset 0x%llx", + __func__, offset); + printf(" is larger than block size 0x%x\n", + blk_sz); + return -EINVAL; + } + + reg = base + offset; + writel(val, (uintptr_t)reg); + + read_val = readl((uintptr_t)reg); + debug("%s(reg 0x%x = wr : 0x%llx rd : 0x%llx)\n", + __func__, reg, val, 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