From patchwork Tue Aug 6 07:33:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1969361 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=zA6JIfoL; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=AJivsP9Y; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WdQ6f3dBxz1yYD for ; Tue, 6 Aug 2024 17:34:18 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VcY3kQp/pbcRegmT98gqD9e9l8M4gpaUNviyhJz0fIg=; b=zA6JIfoLCUXF8C VbWLHpVWHrJBKIGouE6vzOGVBDYpEyAvuhVQx+/pHLfXJtCPORc9qd9RllVma6ey06fDiveoNAZxG QRBUmZ4puxguifVZbdUbELex5mQC0xLxtMoz7y5C0cqoo7Xo6qRU4nhi3lU6U519KAGt6vhMgiTU3 p3CL3IQ5vxSSBmuds+LjPHHHzS1v6I7yiW8XQA830MdI7VEUtE2gruVfQ+vyDxT5evKKt42yj62o0 L2ZilxqjyW0FHPaIIKKlbiYNRLiEUGJtR+HnsUBn2KnoDYRz89h33gAPHUyXlwzHVHCQQj4DdIAtN 09Z0kE0Pd6+BGzG9wWQw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEhv-00000000nv5-1MCG; Tue, 06 Aug 2024 07:34:11 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEhs-00000000nsx-1ii0 for opensbi@lists.infradead.org; Tue, 06 Aug 2024 07:34:09 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-70d316f0060so4238633b3a.1 for ; Tue, 06 Aug 2024 00:34:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1722929648; x=1723534448; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9gsver5Q1fQKX5swvbK9rHFRA0LyT84jvHfArdMVnNM=; b=AJivsP9YS5veB4tDk1qAsy+OwL56XzXGqUsWcCFB5rGAmObKxyyMbNPj45cBmWvBRh 86xOEYn81Qi9cjMpGPoj7nZNFiu77KI6Jq3TfzFWQK/S0Gq3i83dcOpoXdV2At9EkV19 VDs9bp8l4SJWcFRolr4MkY5Az+xpVoxIOcVrMf3tY0CHwBgqMoiR144DSOcx9iKgxbyU fHEjgf+o44w31JbDNeHMsB+YvapIbNOFyeTZh5Zwtlk9fetyCsO+NTjIcjW9Rya6eFGG Sv9opRgRB6LmZZPjy9MSB+dIEp903hRBTXRvlZ/lpcbMhu2+/W0hgKzel/+5iKUOvXoq uvJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722929648; x=1723534448; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9gsver5Q1fQKX5swvbK9rHFRA0LyT84jvHfArdMVnNM=; b=af9IAT0SLgVLYXTC0SV8awVNwE5yvVjPR/JQnYtu8KFf1sBPttqS6otCCBJQcWVTrE PmwPMNVsehZPXBytnea0uV9PlDDD12wtiIXZ1u2BW6fU56//CcLWB5K3hKVmFe3j4KoU QL9IeAEE9jGzJSZ2jBSxL7CK1gF/T1It9+sogY6ywEyp6d120Vpr58cIljxFTAqq9KZV mw+aT0XAxkOjj/c+cV9YvRQVHSQ7dEYLKnwUJS9cprzqqaTiNzwJN6eAZAAqIAGUrZ/v 6LcF0Q8YdKr2mcCRyg3dUG7FRRkjN/mJ+pm1HPsSDp0HWNPTnQNixOg/HKJkNkgbpPdg WpjA== X-Forwarded-Encrypted: i=1; AJvYcCWEy/TMsoP9hsRlTd3y81T7ShbpT3MWzlQoXlhYmkN8uFUZNuuhd6fj9ajfWY5qmy4zF0QksmeOz6Jjp/ylKGbJQXT2VB7wqZtcl3I= X-Gm-Message-State: AOJu0Yy4si1GjuKHN2jofmEQh9XiFY2clF0iJL+kqX9dXAp6/VUPpKcV Jfk0E8yu99nnU4tt1/lrLcr4gttP2q8e3Vp1OW7R06ah46fHWrY0aJ2nTIF/+v0= X-Google-Smtp-Source: AGHT+IHhRBeEC1YH1LJpti8ZI+bkbUZTY+xDQhPxR1tSxbcssPP0elCuPmf51emznwaFkaDyZR9KEA== X-Received: by 2002:a05:6a20:a10c:b0:1c4:779b:fb02 with SMTP id adf61e73a8af0-1c69a69879amr23710540637.21.1722929647493; Tue, 06 Aug 2024 00:34:07 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.134.124]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ed2de28sm6455011b3a.191.2024.08.06.00.34.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 00:34:07 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 08/16] lib: utils: Add simple FDT based HSM driver framework Date: Tue, 6 Aug 2024 13:03:30 +0530 Message-Id: <20240806073338.1856901-9-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240806073338.1856901-1-apatel@ventanamicro.com> References: <20240806073338.1856901-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_003408_506322_4B7DD0D2 X-CRM114-Status: GOOD ( 21.24 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The generic platform can have multiple HSM drivers so add a simple FDT based HSM driver framework. Signed-off-by: Anup Patel --- include/sbi_utils/hsm/fdt_hsm.h | 39 ++++++++++++ lib/utils/Kconfig | 2 + lib/utils/hsm/Kconfig | 10 ++++ lib/utils/hsm/fdt_hsm.c | 89 +++++++++ [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:429 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The generic platform can have multiple HSM drivers so add a simple FDT based HSM driver framework. Signed-off-by: Anup Patel --- include/sbi_utils/hsm/fdt_hsm.h | 39 ++++++++++++ lib/utils/Kconfig | 2 + lib/utils/hsm/Kconfig | 10 ++++ lib/utils/hsm/fdt_hsm.c | 89 ++++++++++++++++++++++++++++ lib/utils/hsm/fdt_hsm_drivers.carray | 3 + lib/utils/hsm/objects.mk | 11 ++++ platform/generic/configs/defconfig | 1 + platform/generic/platform.c | 6 ++ 8 files changed, 161 insertions(+) create mode 100644 include/sbi_utils/hsm/fdt_hsm.h create mode 100644 lib/utils/hsm/Kconfig create mode 100644 lib/utils/hsm/fdt_hsm.c create mode 100644 lib/utils/hsm/fdt_hsm_drivers.carray create mode 100644 lib/utils/hsm/objects.mk diff --git a/include/sbi_utils/hsm/fdt_hsm.h b/include/sbi_utils/hsm/fdt_hsm.h new file mode 100644 index 00000000..7076873c --- /dev/null +++ b/include/sbi_utils/hsm/fdt_hsm.h @@ -0,0 +1,39 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#ifndef __FDT_HSM_H__ +#define __FDT_HSM_H__ + +#include + +#ifdef CONFIG_FDT_HSM + +struct fdt_hsm { + const struct fdt_match *match_table; + int (*fdt_fixup)(void *fdt); + int (*cold_init)(void *fdt, int nodeoff, const struct fdt_match *match); + int (*warm_init)(void); + void (*exit)(void); +}; + +int fdt_hsm_fixup(void *fdt); + +void fdt_hsm_exit(void); + +int fdt_hsm_init(bool cold_boot); + +#else + +static inline int fdt_hsm_fixup(void *fdt) { return 0; } +static inline void fdt_hsm_exit(void) { } +static inline int fdt_hsm_init(bool cold_boot) { return 0; } + +#endif + +#endif diff --git a/lib/utils/Kconfig b/lib/utils/Kconfig index 3f32c1ca..c860a185 100644 --- a/lib/utils/Kconfig +++ b/lib/utils/Kconfig @@ -6,6 +6,8 @@ source "$(OPENSBI_SRC_DIR)/lib/utils/fdt/Kconfig" source "$(OPENSBI_SRC_DIR)/lib/utils/gpio/Kconfig" +source "$(OPENSBI_SRC_DIR)/lib/utils/hsm/Kconfig" + source "$(OPENSBI_SRC_DIR)/lib/utils/i2c/Kconfig" source "$(OPENSBI_SRC_DIR)/lib/utils/ipi/Kconfig" diff --git a/lib/utils/hsm/Kconfig b/lib/utils/hsm/Kconfig new file mode 100644 index 00000000..31506116 --- /dev/null +++ b/lib/utils/hsm/Kconfig @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: BSD-2-Clause + +menu "HSM Device Support" + +config FDT_HSM + bool "FDT based HSM drivers" + depends on FDT + default n + +endmenu diff --git a/lib/utils/hsm/fdt_hsm.c b/lib/utils/hsm/fdt_hsm.c new file mode 100644 index 00000000..7166dce8 --- /dev/null +++ b/lib/utils/hsm/fdt_hsm.c @@ -0,0 +1,89 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#include +#include +#include + +/* List of FDT HSM drivers generated at compile time */ +extern struct fdt_hsm *fdt_hsm_drivers[]; +extern unsigned long fdt_hsm_drivers_size; + +static struct fdt_hsm *current_driver = NULL; + +int fdt_hsm_fixup(void *fdt) +{ + if (current_driver && current_driver->fdt_fixup) + return current_driver->fdt_fixup(fdt); + return 0; +} + +void fdt_hsm_exit(void) +{ + if (current_driver && current_driver->exit) + current_driver->exit(); +} + +static int fdt_hsm_warm_init(void) +{ + if (current_driver && current_driver->warm_init) + return current_driver->warm_init(); + return 0; +} + +static int fdt_hsm_cold_init(void) +{ + int pos, noff, rc; + struct fdt_hsm *drv; + const struct fdt_match *match; + void *fdt = fdt_get_address(); + + for (pos = 0; pos < fdt_hsm_drivers_size; pos++) { + drv = fdt_hsm_drivers[pos]; + + noff = -1; + while ((noff = fdt_find_match(fdt, noff, + drv->match_table, &match)) >= 0) { + /* drv->cold_init must not be NULL */ + if (drv->cold_init == NULL) + return SBI_EFAIL; + + rc = drv->cold_init(fdt, noff, match); + if (rc == SBI_ENODEV) + continue; + if (rc) + return rc; + current_driver = drv; + + /* + * We can have multiple HSM devices on multi-die or + * multi-socket systems so we cannot break here. + */ + } + } + + /* + * On some single-hart system there is no need for HSM, + * so we cannot return a failure here + */ + return 0; +} + +int fdt_hsm_init(bool cold_boot) +{ + int rc; + + if (cold_boot) { + rc = fdt_hsm_cold_init(); + if (rc) + return rc; + } + + return fdt_hsm_warm_init(); +} diff --git a/lib/utils/hsm/fdt_hsm_drivers.carray b/lib/utils/hsm/fdt_hsm_drivers.carray new file mode 100644 index 00000000..21396db2 --- /dev/null +++ b/lib/utils/hsm/fdt_hsm_drivers.carray @@ -0,0 +1,3 @@ +HEADER: sbi_utils/hsm/fdt_hsm.h +TYPE: struct fdt_hsm +NAME: fdt_hsm_drivers diff --git a/lib/utils/hsm/objects.mk b/lib/utils/hsm/objects.mk new file mode 100644 index 00000000..49337bf5 --- /dev/null +++ b/lib/utils/hsm/objects.mk @@ -0,0 +1,11 @@ +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2024 Ventana Micro Systems Inc. +# +# Authors: +# Anup Patel +# + +libsbiutils-objs-$(CONFIG_FDT_HSM) += hsm/fdt_hsm.o +libsbiutils-objs-$(CONFIG_FDT_HSM) += hsm/fdt_hsm_drivers.carray.o diff --git a/platform/generic/configs/defconfig b/platform/generic/configs/defconfig index 54300fb5..2efc7136 100644 --- a/platform/generic/configs/defconfig +++ b/platform/generic/configs/defconfig @@ -10,6 +10,7 @@ CONFIG_FDT_GPIO=y CONFIG_FDT_GPIO_DESIGNWARE=y CONFIG_FDT_GPIO_SIFIVE=y CONFIG_FDT_GPIO_STARFIVE=y +CONFIG_FDT_HSM=y CONFIG_FDT_I2C=y CONFIG_FDT_I2C_SIFIVE=y CONFIG_FDT_I2C_DW=y diff --git a/platform/generic/platform.c b/platform/generic/platform.c index 138a54c2..bcd7133b 100644 --- a/platform/generic/platform.c +++ b/platform/generic/platform.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -236,6 +237,8 @@ static int generic_early_init(bool cold_boot) return rc; } + fdt_hsm_init(cold_boot); + if (!generic_plat || !generic_plat->early_init) return 0; @@ -261,6 +264,7 @@ static int generic_final_init(bool cold_boot) fdt_cpu_fixup(fdt); fdt_fixups(fdt); fdt_domain_fixup(fdt); + fdt_hsm_fixup(fdt); if (generic_plat && generic_plat->fdt_fixup) { rc = generic_plat->fdt_fixup(fdt, generic_plat_match); @@ -287,6 +291,8 @@ static int generic_vendor_ext_provider(long funcid, static void generic_early_exit(void) { + fdt_hsm_exit(); + if (generic_plat && generic_plat->early_exit) generic_plat->early_exit(generic_plat_match); }