From patchwork Tue Aug 6 07:33:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1969364 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=IdIubnEz; 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=iBTckI1Y; 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 4WdQ6s2V8kz1ydt for ; Tue, 6 Aug 2024 17:34:29 +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=V5QNWWXPG7+hRJOCQS8lsvmEppDmwwL6i+EVdfdXinA=; b=IdIubnEzFxy+kk DWEBKdCKqQyRRf0tDRF0bjJofcsdWjeUmFAq9B7dOLDn+hFNJXDOg2PsL/m+ZeAJCIaKiPryGMeiD EF3FGeJ5bvrV9JjWSEwECrp+rFjBQA+WD7khcTLIbYIYYYo97N5Jum0koDtD55wJkb1M6t8A389EV Ve8E7NT7PGOGGJL30lOONT51k/PNlqdgaewUk15n3qzZeRaK91q1NpQt+eUxM2/E6ClgxeWtHKHwd cq9AdR4GZ7H1dg8lEOy7e0nJK2C0kxOtx2husXyM5I0YNZe57UnqHtGGn42ZpYZ8YtJW1jWQFXkmO 8W42JUz4iIR24DH1K5pw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEi6-00000000o3j-25Ti; Tue, 06 Aug 2024 07:34:22 +0000 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEi1-00000000nzN-2BuI for opensbi@lists.infradead.org; Tue, 06 Aug 2024 07:34:19 +0000 Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-7a263f6439eso143894a12.3 for ; Tue, 06 Aug 2024 00:34:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1722929656; x=1723534456; 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=ZqgHPdXvyyiYF+mqE1Hfy5rLM6qVSm+QKCx6uIgLne0=; b=iBTckI1YGrWzVXuGtXt6XAs++1mNYWjrXtxeX2S8VTcNQpbZAwayIzEauxdOMnJnjO wBSFG866TF0YpBjZdyWN+0gdX92O9MtDDVHrd/73sGY/qUWVJT8Kb+x3xkekPSear02c zNMVfjbCXCFKFcN8nK/E9e1ROlUp48Beg5LP6M01o7Iv2DHhd9mHJYGEQYW2CBdDjuzY 1BzxAayWhZZgEcyepojOA+eZdoOiVHQ7/4x7uWaCcW4nUo/eODxFDPuWOba5XhS8zuC+ /bw+4mkBQjuWfoVXQOW00h5rGbfYqfrboibkUNVA5bwBY75X/DlmAYLMxoNUr7juYmCK ai+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722929656; x=1723534456; 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=ZqgHPdXvyyiYF+mqE1Hfy5rLM6qVSm+QKCx6uIgLne0=; b=jn/2emf0YWek+LWFozz587W4fYvoqLLnUAPV61xlhZzsLbpUeMSfRkxtq+VfIroaE2 TAaZMv7NmOM0KAeNYp8AAOhu376q7k/oQAbB9EjE/+aE6We7ncTNOqzln8+ooDyiW/eC mll8VDN50mpIY1TeU8iDNps4eKis/HR1EuNt56m9zGnhzVI6PkHvfJXdYlW5igwGZAMf u256U+oYHUd/SFnmiD1B/bp+vBSjY/u3tPzs8vDf4K10yYePuIkdDKBS2nmt1uAVZfDm B17AsgxN9H5DB8VdH5vIniAnQLjbG3yi32JNcLWemlNO17N1PngWaUCBrEshC8EnDED0 KdaQ== X-Forwarded-Encrypted: i=1; AJvYcCWp3K1JYP2yLSTvP6TW2wX6Pnt30MEJQLjw7KzqeDTdtBN87lgRIvlO896HWLO+Oub7aOlfvlQBCX/4LlUvvzLtHcdPQpZvuqaZsXc= X-Gm-Message-State: AOJu0YxT1YGK0qDhmQBa6KMZz/3phRJwpLAq+l8zMfJAL4x5q+8w2hSK /SQMvPT4mP/RpsA3wwv/XX/+iVo03Fg1E9aJsRk4bKH7fWk4z+6OuWGiPZkz9tGWcW1jwKwYxx8 d X-Google-Smtp-Source: AGHT+IGQiGw5WgMjIh2IBdqCT9IHUystflnfT6awYSybu71p+gn81ZSCpuSC629vP7Z4Q5B0oNvokQ== X-Received: by 2002:a05:6a20:6a0a:b0:1c4:d4b2:ffe6 with SMTP id adf61e73a8af0-1c69953e89emr15285869637.19.1722929656198; Tue, 06 Aug 2024 00:34:16 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 00:34:15 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 11/16] lib: utils: Add simple FDT based CPPC driver framework Date: Tue, 6 Aug 2024 13:03:33 +0530 Message-Id: <20240806073338.1856901-12-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_003417_725996_6ABE5AE7 X-CRM114-Status: GOOD ( 21.43 ) 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 CPPC drivers so add a simple FDT based CPPC driver framework. Signed-off-by: Anup Patel --- include/sbi_utils/cppc/fdt_cppc.h | 35 +++++++++++ lib/utils/Kconfig | 2 + lib/utils/cppc/Kconfig | 10 ++++ lib/utils/cppc/fdt_cppc.c | 82 +++++ [...] 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:52b 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 CPPC drivers so add a simple FDT based CPPC driver framework. Signed-off-by: Anup Patel --- include/sbi_utils/cppc/fdt_cppc.h | 35 +++++++++++ lib/utils/Kconfig | 2 + lib/utils/cppc/Kconfig | 10 ++++ lib/utils/cppc/fdt_cppc.c | 82 ++++++++++++++++++++++++++ lib/utils/cppc/fdt_cppc_drivers.carray | 3 + lib/utils/cppc/objects.mk | 11 ++++ platform/generic/configs/defconfig | 1 + platform/generic/platform.c | 3 + 8 files changed, 147 insertions(+) create mode 100644 include/sbi_utils/cppc/fdt_cppc.h create mode 100644 lib/utils/cppc/Kconfig create mode 100644 lib/utils/cppc/fdt_cppc.c create mode 100644 lib/utils/cppc/fdt_cppc_drivers.carray create mode 100644 lib/utils/cppc/objects.mk diff --git a/include/sbi_utils/cppc/fdt_cppc.h b/include/sbi_utils/cppc/fdt_cppc.h new file mode 100644 index 00000000..af0cdc41 --- /dev/null +++ b/include/sbi_utils/cppc/fdt_cppc.h @@ -0,0 +1,35 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#ifndef __FDT_CPPC_H__ +#define __FDT_CPPC_H__ + +#include + +#ifdef CONFIG_FDT_CPPC + +struct fdt_cppc { + const struct fdt_match *match_table; + int (*cold_init)(void *fdt, int nodeoff, const struct fdt_match *match); + int (*warm_init)(void); + void (*exit)(void); +}; + +void fdt_cppc_exit(void); + +int fdt_cppc_init(bool cold_boot); + +#else + +static inline void fdt_cppc_exit(void) { } +static inline int fdt_cppc_init(bool cold_boot) { return 0; } + +#endif + +#endif diff --git a/lib/utils/Kconfig b/lib/utils/Kconfig index c860a185..002d6f8f 100644 --- a/lib/utils/Kconfig +++ b/lib/utils/Kconfig @@ -2,6 +2,8 @@ menu "Utils and Drivers Support" +source "$(OPENSBI_SRC_DIR)/lib/utils/cppc/Kconfig" + source "$(OPENSBI_SRC_DIR)/lib/utils/fdt/Kconfig" source "$(OPENSBI_SRC_DIR)/lib/utils/gpio/Kconfig" diff --git a/lib/utils/cppc/Kconfig b/lib/utils/cppc/Kconfig new file mode 100644 index 00000000..08d1c97f --- /dev/null +++ b/lib/utils/cppc/Kconfig @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: BSD-2-Clause + +menu "CPPC Device Support" + +config FDT_CPPC + bool "FDT based CPPC drivers" + depends on FDT + default n + +endmenu diff --git a/lib/utils/cppc/fdt_cppc.c b/lib/utils/cppc/fdt_cppc.c new file mode 100644 index 00000000..de11f0e1 --- /dev/null +++ b/lib/utils/cppc/fdt_cppc.c @@ -0,0 +1,82 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#include +#include +#include + +/* List of FDT CPPC drivers generated at compile time */ +extern struct fdt_cppc *fdt_cppc_drivers[]; +extern unsigned long fdt_cppc_drivers_size; + +static struct fdt_cppc *current_driver = NULL; + +void fdt_cppc_exit(void) +{ + if (current_driver && current_driver->exit) + current_driver->exit(); +} + +static int fdt_cppc_warm_init(void) +{ + if (current_driver && current_driver->warm_init) + return current_driver->warm_init(); + return 0; +} + +static int fdt_cppc_cold_init(void) +{ + int pos, noff, rc; + struct fdt_cppc *drv; + const struct fdt_match *match; + void *fdt = fdt_get_address(); + + for (pos = 0; pos < fdt_cppc_drivers_size; pos++) { + drv = fdt_cppc_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 CPPC devices on multi-die or + * multi-socket systems so we cannot break here. + */ + } + } + + /* + * On some single-hart system there is no need for CPPC, + * so we cannot return a failure here + */ + return 0; +} + +int fdt_cppc_init(bool cold_boot) +{ + int rc; + + if (cold_boot) { + rc = fdt_cppc_cold_init(); + if (rc) + return rc; + } + + return fdt_cppc_warm_init(); +} diff --git a/lib/utils/cppc/fdt_cppc_drivers.carray b/lib/utils/cppc/fdt_cppc_drivers.carray new file mode 100644 index 00000000..c2a9af2c --- /dev/null +++ b/lib/utils/cppc/fdt_cppc_drivers.carray @@ -0,0 +1,3 @@ +HEADER: sbi_utils/cppc/fdt_cppc.h +TYPE: struct fdt_cppc +NAME: fdt_cppc_drivers diff --git a/lib/utils/cppc/objects.mk b/lib/utils/cppc/objects.mk new file mode 100644 index 00000000..fb37478a --- /dev/null +++ b/lib/utils/cppc/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_CPPC) += cppc/fdt_cppc.o +libsbiutils-objs-$(CONFIG_FDT_CPPC) += cppc/fdt_cppc_drivers.carray.o diff --git a/platform/generic/configs/defconfig b/platform/generic/configs/defconfig index 78fc96b6..bd18c3c1 100644 --- a/platform/generic/configs/defconfig +++ b/platform/generic/configs/defconfig @@ -6,6 +6,7 @@ CONFIG_PLATFORM_SIFIVE_FU740=y CONFIG_PLATFORM_SOPHGO_SG2042=y CONFIG_PLATFORM_STARFIVE_JH7110=y CONFIG_PLATFORM_THEAD=y +CONFIG_FDT_CPPC=y CONFIG_FDT_GPIO=y CONFIG_FDT_GPIO_DESIGNWARE=y CONFIG_FDT_GPIO_SIFIVE=y diff --git a/platform/generic/platform.c b/platform/generic/platform.c index bcd7133b..d085647d 100644 --- a/platform/generic/platform.c +++ b/platform/generic/platform.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -238,6 +239,7 @@ static int generic_early_init(bool cold_boot) } fdt_hsm_init(cold_boot); + fdt_cppc_init(cold_boot); if (!generic_plat || !generic_plat->early_init) return 0; @@ -291,6 +293,7 @@ static int generic_vendor_ext_provider(long funcid, static void generic_early_exit(void) { + fdt_cppc_exit(); fdt_hsm_exit(); if (generic_plat && generic_plat->early_exit)