From patchwork Tue Aug 6 07:33:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1969359 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=PbVVpSX3; 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=gSZYznbz; 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 4WdQ6X6Xv4z1yYD for ; Tue, 6 Aug 2024 17:34:12 +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=SILTPtZ4A+rx0PnsLaxL5E05flAvL8exKcpNieDZKoA=; b=PbVVpSX3Lrsp2g wxTCD/hjLgW5NfePhLRqxerR0ay5aYdpW+Sp7Bgg/X10E9pMZW7hkGHoPIs4jgrt9fZZ3ItYyYnLs 1D4fK1y0UjmsGvEx9QbR7Gf6L0cfXrD0qEByzl7cS2U9B7pxlxs0vUE32uLbn6RAVqXbf6VpGliSX NsStZrJSXNTze9zAb27j9PjFnVnvuqNIvIuGZHT8594kkGIYjkHlYC/G3CgCDBnez/PVQn1U13HNc yoQ4KaIsewuRHD/v7iXQpXGoWOLMY2wAt5QnoJlOyRoEw0m3zHN7o16iMawmNpXVC/N/QlzMisggF ln1eEv2Vwp9uLBvc3IoA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEhq-00000000nr0-104h; Tue, 06 Aug 2024 07:34:06 +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 1sbEhn-00000000noP-0Gtl for opensbi@lists.infradead.org; Tue, 06 Aug 2024 07:34:04 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-70d23caf8ddso286103b3a.0 for ; Tue, 06 Aug 2024 00:34:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1722929642; x=1723534442; 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=Y3wVTSfdXdZyvs1TV9WfK2ZsbQutQPeJTwgVEH0FCGY=; b=gSZYznbzIx1/IwIITSy+QBfaVd0g0VzBvf+en9+aFHy17yCX3UpydkwQAVcK+XlJ5W Fu/tageak7TH3cwPdMjc+8FlIdtUS8cp6ZKtZszbfewlC+9mVV/BatYNgxDxFQhwDvUK vmW9cz7H8VLiJYPWkgcgvFikG5VfVbaQDF2ugTErCgaw/7Gjc7vY06RbKp1iqUqs/asS 7l70eUOT3cX3SfzDO+eRa4v3ZITrACw/rzY9N7SzCVkOsZRDrJ2qLtLX3cWbmkhD6+ld 43ghwG4X13hkK/bzOQkiDNvYHOxu2NHr78C7gJaVXU5wQPG4cPomKUC1NeIWGiRGn22o EuDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722929642; x=1723534442; 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=Y3wVTSfdXdZyvs1TV9WfK2ZsbQutQPeJTwgVEH0FCGY=; b=Hs2ix75BObDoEEeL8bqEijX4G906TKxX2gb5ey07YBkpSw6+h8x9AQwe8BshFlOfsA /NdGdDN/+OJWH+R6L6CWi7FmkQ52mtENpOuYnPoJYKkwercQ6mbXnAOH+LCSXkbnaPXo KtwRnP/dVZszLcTpsRmjhnp3B5CGVhHxWlPHpDxcK78rk/02FFbxfg3crbQ5TzOCgbIx MR62rznq0ZFSz8uijtX251B1TrklEQHHVvD2/+KXhOKMJjDqRXeJWnDlRdHuZxyXulxi HWdvyvgftMootKFFRIOFQjSE2KLf+RwaXkl9Wkf2zAuOA+IBX6ATlO6y1Y+glzlnYqPA ZrVw== X-Forwarded-Encrypted: i=1; AJvYcCU/7ywo76JIr5sLfcG+bgaNHrwzLT2rUVtnldiMh3JW0FFwsvphJC3RYWQkLMHK9g6kJJt8xDNKBfpwUy5Kif72Gi2kg/iQxwOlky4= X-Gm-Message-State: AOJu0Ywvux3vMa26jZirrGU3Lip4KzDObo+PKgK191LUgEzgqKJRrFXO wZCsCuVh3T2CvLMD+aJiMRBjGXwyW/vFYJ9Z9P+Rw/UDPpCsAEI7IzQFJnqyEhk= X-Google-Smtp-Source: AGHT+IFt0mvnEy7FYl0YzhWlRdLKeNnYbN5dqUzTx7j/vYajazqYJNqBiPZ01r3SYgPJImZK8+r0hA== X-Received: by 2002:a05:6a00:1790:b0:70d:21d9:e2ae with SMTP id d2e1a72fcca58-7106cf8ff18mr18029441b3a.6.1722929641855; Tue, 06 Aug 2024 00:34:01 -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.33.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 00:34:01 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 06/16] lib: utils: Add simple FDT based system suspend driver framework Date: Tue, 6 Aug 2024 13:03:28 +0530 Message-Id: <20240806073338.1856901-7-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_003403_149631_2A27FBB2 X-CRM114-Status: GOOD ( 19.41 ) 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 system suspend drivers so add a simple FDT based system suspend driver framework. Signed-off-by: Anup Patel --- include/sbi_utils/suspend/fdt_suspend.h | 45 +++++++++++++++++++ lib/utils/Kconfig | 2 + lib/utils/suspend/Kconfig | 10 +++++ lib/utils/suspend/ [...] 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 system suspend drivers so add a simple FDT based system suspend driver framework. Signed-off-by: Anup Patel --- include/sbi_utils/suspend/fdt_suspend.h | 45 +++++++++++++++++++ lib/utils/Kconfig | 2 + lib/utils/suspend/Kconfig | 10 +++++ lib/utils/suspend/fdt_suspend.c | 46 ++++++++++++++++++++ lib/utils/suspend/fdt_suspend_drivers.carray | 3 ++ lib/utils/suspend/objects.mk | 11 +++++ platform/generic/configs/defconfig | 1 + platform/generic/platform.c | 2 + 8 files changed, 120 insertions(+) create mode 100644 include/sbi_utils/suspend/fdt_suspend.h create mode 100644 lib/utils/suspend/Kconfig create mode 100644 lib/utils/suspend/fdt_suspend.c create mode 100644 lib/utils/suspend/fdt_suspend_drivers.carray create mode 100644 lib/utils/suspend/objects.mk diff --git a/include/sbi_utils/suspend/fdt_suspend.h b/include/sbi_utils/suspend/fdt_suspend.h new file mode 100644 index 00000000..cb6fb719 --- /dev/null +++ b/include/sbi_utils/suspend/fdt_suspend.h @@ -0,0 +1,45 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#ifndef __FDT_SUSPEND_H__ +#define __FDT_SUSPEND_H__ + +#include + +struct fdt_suspend { + const struct fdt_match *match_table; + int (*init)(void *fdt, int nodeoff, const struct fdt_match *match); +}; + +#ifdef CONFIG_FDT_SUSPEND + +/** + * fdt_suspend_driver_init() - initialize suspend driver based on the device-tree + */ +int fdt_suspend_driver_init(void *fdt, struct fdt_suspend *drv); + +/** + * fdt_suspend_init() - initialize reset drivers based on the device-tree + * + * This function shall be invoked in final init. + */ +void fdt_suspend_init(void); + +#else + +static inline int fdt_suspend_driver_init(void *fdt, struct fdt_suspend *drv) +{ + return 0; +} + +static inline void fdt_suspend_init(void) { } + +#endif + +#endif diff --git a/lib/utils/Kconfig b/lib/utils/Kconfig index 6aa7843c..3f32c1ca 100644 --- a/lib/utils/Kconfig +++ b/lib/utils/Kconfig @@ -22,6 +22,8 @@ source "$(OPENSBI_SRC_DIR)/lib/utils/reset/Kconfig" source "$(OPENSBI_SRC_DIR)/lib/utils/serial/Kconfig" +source "$(OPENSBI_SRC_DIR)/lib/utils/suspend/Kconfig" + source "$(OPENSBI_SRC_DIR)/lib/utils/sys/Kconfig" source "$(OPENSBI_SRC_DIR)/lib/utils/timer/Kconfig" diff --git a/lib/utils/suspend/Kconfig b/lib/utils/suspend/Kconfig new file mode 100644 index 00000000..416ae795 --- /dev/null +++ b/lib/utils/suspend/Kconfig @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: BSD-2-Clause + +menu "System Suspend Support" + +config FDT_SUSPEND + bool "FDT based suspend drivers" + depends on FDT + default n + +endmenu diff --git a/lib/utils/suspend/fdt_suspend.c b/lib/utils/suspend/fdt_suspend.c new file mode 100644 index 00000000..029d6476 --- /dev/null +++ b/lib/utils/suspend/fdt_suspend.c @@ -0,0 +1,46 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#include +#include +#include +#include + +/* List of FDT suspend drivers generated at compile time */ +extern struct fdt_suspend *fdt_suspend_drivers[]; +extern unsigned long fdt_suspend_drivers_size; + +int fdt_suspend_driver_init(void *fdt, struct fdt_suspend *drv) +{ + int noff, rc = SBI_ENODEV; + const struct fdt_match *match; + + noff = fdt_find_match(fdt, -1, drv->match_table, &match); + if (noff < 0) + return SBI_ENODEV; + + if (drv->init) { + rc = drv->init(fdt, noff, match); + if (rc && rc != SBI_ENODEV) { + sbi_printf("%s: %s init failed, %d\n", + __func__, match->compatible, rc); + } + } + + return rc; +} + +void fdt_suspend_init(void) +{ + int pos; + void *fdt = fdt_get_address(); + + for (pos = 0; pos < fdt_suspend_drivers_size; pos++) + fdt_suspend_driver_init(fdt, fdt_suspend_drivers[pos]); +} diff --git a/lib/utils/suspend/fdt_suspend_drivers.carray b/lib/utils/suspend/fdt_suspend_drivers.carray new file mode 100644 index 00000000..8793e4cf --- /dev/null +++ b/lib/utils/suspend/fdt_suspend_drivers.carray @@ -0,0 +1,3 @@ +HEADER: sbi_utils/suspend/fdt_suspend.h +TYPE: struct fdt_suspend +NAME: fdt_suspend_drivers diff --git a/lib/utils/suspend/objects.mk b/lib/utils/suspend/objects.mk new file mode 100644 index 00000000..30d897d1 --- /dev/null +++ b/lib/utils/suspend/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_SUSPEND) += suspend/fdt_suspend.o +libsbiutils-objs-$(CONFIG_FDT_SUSPEND) += suspend/fdt_suspend_drivers.carray.o diff --git a/platform/generic/configs/defconfig b/platform/generic/configs/defconfig index 48f8df4c..ec439d74 100644 --- a/platform/generic/configs/defconfig +++ b/platform/generic/configs/defconfig @@ -44,6 +44,7 @@ CONFIG_FDT_SERIAL_LITEX=y CONFIG_FDT_SERIAL_UART8250=y CONFIG_FDT_SERIAL_XILINX_UARTLITE=y CONFIG_SERIAL_SEMIHOSTING=y +CONFIG_FDT_SUSPEND=y CONFIG_FDT_TIMER=y CONFIG_FDT_TIMER_MTIMER=y CONFIG_FDT_TIMER_PLMT=y diff --git a/platform/generic/platform.c b/platform/generic/platform.c index 3470474a..138a54c2 100644 --- a/platform/generic/platform.c +++ b/platform/generic/platform.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -225,6 +226,7 @@ static int generic_early_init(bool cold_boot) if (cold_boot) { fdt_reset_init(); + fdt_suspend_init(); if (semihosting_enabled()) rc = semihosting_init();