From patchwork Tue Aug 6 07:33:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1969360 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=fh4Ymn0W; 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=jvOcz/5o; 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 4WdQ6b6BRPz1yYD for ; Tue, 6 Aug 2024 17:34:15 +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=kXpApPyLDZp3kSbIPFlA/daGZzmY/wkpZtjAiX/1pWI=; b=fh4Ymn0WA9aTEf eRe6yVZ6+GfFbEGo9BQPwBMBOpcJ7F6T8BUAXLeYINWV615ePiYSRwhkzRPs5Pv7xVkz16Q0JOdCJ 3Vg1LA5K628trKgKhCEuc9MYvlOnC10sTW73fECagpVpfSIka82SfwKZ5LYXd2LeztXamq7v1eJrL CXSSZeiSEWgT0+OYGD+UvoMSFgEeKb4WUQjrfkG2cfkx8sVA2FT/sBIO5HQ2nXNoKmjcNGIVCv2Ff vBA/nooe/McnKVKSeUisZky06FOwHPD4p3QzU09CKTJIoZZIwEpBLqy0KfTGMqwOzq0qXVuha+uFH 11xP4E/FrBR60C92SOgQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEht-00000000ntg-172i; Tue, 06 Aug 2024 07:34:09 +0000 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEhq-00000000nqV-1ehn for opensbi@lists.infradead.org; Tue, 06 Aug 2024 07:34:08 +0000 Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-3db50abf929so211464b6e.2 for ; Tue, 06 Aug 2024 00:34:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1722929645; x=1723534445; 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=F/fpWWtIO2vCJqymUn40LfuZlWWhkECO7uabcVsoxdY=; b=jvOcz/5oO2YpuN/hS6y4xwpZDtQct7bKxSmPO803Ce1NGRYyX99JVeXJiVrM7I5fmd nYhKfeQxyOSvpDYLt7/df131Q4Q1sKhti/BFkNO2oYc8sZA4Ne799cqNXxg/pyp29zEM 9RtMkiPehx1ZOdrDlsc1R0hcBvVljZ6Y8+p/stsNdZ33ah1ix2rjNZSq0LL5j6H0yMKs JSu99/7poMyVSYKIx9QWCfLYGKIvWfMXyTDPJBV59gT/nlgmPbhpn9oNcybWZhKBIKEl QqYCEYAag29ma6GB4s2AKbD8e5TCxhjBl4/OIZKkyZJhM1x0uRbMiqZZqsTV6b6MFM8P X2aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722929645; x=1723534445; 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=F/fpWWtIO2vCJqymUn40LfuZlWWhkECO7uabcVsoxdY=; b=Lb/3nz7Ulj+QkasjotwDbEq2E6gN70gODpRA6/6pOeBI/j+ZPApzkghRdLF3QcwwaH HgJAwhWB3r9dEuq0FqeshIe+X8OO/7LoekhbfEeftEoa2UB9qbSj8OXWIAo3raYCejGY K6esRCVBMcoJZYSUHDwS6GzW7pzaGhrOl5OCvtLmAnU3Axj1aiAXpaISO0/Q3QzKiHiT BKzJHhYPqKFMWGB/4SfDJRd8qgd9o6lnP24tQoRO7fiFps18cnEgv6J9nPZBZ//Uk07T wOVf7SWmWLwT2TLXncvob++bNQiZ+NlDlVn/JIx2Ic4/HtIhwEN1Ede3lp+9jr4VVF3z 457A== X-Forwarded-Encrypted: i=1; AJvYcCUGcvQuTPtBgEAfJ6l7PVz71XJUrVMYQeqISkpnT8MiVNq0Adio6KHle/YTdy/44rUr8yxkHgaoO3sEPJqpBB1E/VqUhA5F+KA9CN4= X-Gm-Message-State: AOJu0YyFrRohu055TH4hXqWVySMHsM8ElGRhN+L5Sp+6dcbuCarY+nd4 7Wmn58bmKPM4HAH/IwVlwUGzhhTBlOdqplGhOyCTXOuZz0rIODD32W/L7Gaoo7U= X-Google-Smtp-Source: AGHT+IHawp0DW1JjSF5+ql4dMRdI86NyB0kUzhexZRvPUBJ3xTeingOzWTPyVJEHI9khwjOLFu67ug== X-Received: by 2002:a05:6808:1710:b0:3d9:1f05:845 with SMTP id 5614622812f47-3db5580a5c5mr18850156b6e.19.1722929644813; Tue, 06 Aug 2024 00:34:04 -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.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 00:34:04 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Subrahmanya Lingappa , Anup Patel Subject: [PATCH 07/16] lib: utils/suspend: Add RPMI system suspend driver Date: Tue, 6 Aug 2024 13:03:29 +0530 Message-Id: <20240806073338.1856901-8-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_003406_644760_C8581186 X-CRM114-Status: GOOD ( 17.86 ) 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: From: Subrahmanya Lingappa Add RPMI based system suspend driver. To test this, execute the follwoing in Linux: $ echo mem > /sys/power/state 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:236 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 From: Subrahmanya Lingappa Add RPMI based system suspend driver. To test this, execute the follwoing in Linux: $ echo mem > /sys/power/state To wake up, execute the following command on qemu monitor terminal: (qemu) system_wakeup Signed-off-by: Subrahmanya Lingappa Signed-off-by: Anup Patel --- include/sbi_utils/mailbox/rpmi_msgprot.h | 34 ++++++ lib/utils/suspend/Kconfig | 9 ++ lib/utils/suspend/fdt_suspend_rpmi.c | 137 +++++++++++++++++++++++ lib/utils/suspend/objects.mk | 3 + platform/generic/configs/defconfig | 1 + 5 files changed, 184 insertions(+) create mode 100644 lib/utils/suspend/fdt_suspend_rpmi.c diff --git a/include/sbi_utils/mailbox/rpmi_msgprot.h b/include/sbi_utils/mailbox/rpmi_msgprot.h index 4ede28dd..a2403c90 100644 --- a/include/sbi_utils/mailbox/rpmi_msgprot.h +++ b/include/sbi_utils/mailbox/rpmi_msgprot.h @@ -5,6 +5,7 @@ * * Authors: * Rahul Pathak + * Subrahmanya Lingappa */ #ifndef __RPMI_MSGPROT_H__ @@ -149,6 +150,7 @@ enum rpmi_servicegroup_id { RPMI_SRVGRP_ID_MIN = 0, RPMI_SRVGRP_BASE = 0x00001, RPMI_SRVGRP_SYSTEM_RESET = 0x00002, + RPMI_SRVGRP_SYSTEM_SUSPEND = 0x00003, RPMI_SRVGRP_ID_MAX_COUNT, }; @@ -209,4 +211,36 @@ struct rpmi_sysrst_get_reset_attributes_resp { u32 flags; }; +/** RPMI System Suspend ServiceGroup Service IDs */ +enum rpmi_system_suspend_service_id { + RPMI_SYSSUSP_SRV_ENABLE_NOTIFICATION = 0x01, + RPMI_SYSSUSP_SRV_GET_SYSTEM_SUSPEND_ATTRIBUTES = 0x02, + RPMI_SYSSUSP_SRV_SYSTEM_SUSPEND = 0x03, + RPMI_SYSSUSP_SRV_ID_MAX_COUNT, +}; + +/** Request for system suspend attributes */ +struct rpmi_syssusp_get_attr_req { + u32 susp_type; +}; + +/** Response for system suspend attributes */ +struct rpmi_syssusp_get_attr_resp { + s32 status; +#define RPMI_SYSSUSP_FLAGS_CUSTOM_RESUME_ADDR_SUPPORTED (1U << 31) +#define RPMI_SYSSUSP_FLAGS_SUPPORTED (1U << 30) + u32 flags; +}; + +struct rpmi_syssusp_suspend_req { + u32 hartid; + u32 suspend_type; + u32 resume_addr_lo; + u32 resume_addr_hi; +}; + +struct rpmi_syssusp_suspend_resp { + s32 status; +}; + #endif /* !__RPMI_MSGPROT_H__ */ diff --git a/lib/utils/suspend/Kconfig b/lib/utils/suspend/Kconfig index 416ae795..2cbea75c 100644 --- a/lib/utils/suspend/Kconfig +++ b/lib/utils/suspend/Kconfig @@ -7,4 +7,13 @@ config FDT_SUSPEND depends on FDT default n +if FDT_SUSPEND + +config FDT_SUSPEND_RPMI + bool "FDT RPMI suspend driver" + depends on FDT_MAILBOX && RPMI_MAILBOX + default n + +endif + endmenu diff --git a/lib/utils/suspend/fdt_suspend_rpmi.c b/lib/utils/suspend/fdt_suspend_rpmi.c new file mode 100644 index 00000000..aa5db128 --- /dev/null +++ b/lib/utils/suspend/fdt_suspend_rpmi.c @@ -0,0 +1,137 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Subrahmanya Lingappa + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +struct rpmi_syssusp { + struct mbox_chan *chan; + bool cust_res_addr_supported; + bool suspend_supported; +}; + +static struct rpmi_syssusp syssusp_ctx; + +static int rpmi_syssusp_attrs(uint32_t *attrs) +{ + int rc; + struct rpmi_syssusp_get_attr_resp resp; + struct rpmi_syssusp_get_attr_req req; + + req.susp_type = SBI_SUSP_SLEEP_TYPE_SUSPEND; + + rc = rpmi_normal_request_with_status( + syssusp_ctx.chan, RPMI_SYSSUSP_SRV_GET_SYSTEM_SUSPEND_ATTRIBUTES, + &req, rpmi_u32_count(req), rpmi_u32_count(req), + &resp, rpmi_u32_count(resp), rpmi_u32_count(resp)); + if (rc) + return rc; + + *attrs = resp.flags; + + return 0; +} + +static int rpmi_syssusp(uint32_t suspend_type, ulong resume_addr) +{ + int rc; + struct rpmi_syssusp_suspend_req req; + struct rpmi_syssusp_suspend_resp resp; + + req.hartid = current_hartid(); + req.suspend_type = suspend_type; + req.resume_addr_lo = resume_addr; + req.resume_addr_hi = (u64)resume_addr >> 32; + + rc = rpmi_normal_request_with_status( + syssusp_ctx.chan, RPMI_SYSSUSP_SRV_SYSTEM_SUSPEND, + &req, rpmi_u32_count(req), rpmi_u32_count(req), + &resp, rpmi_u32_count(resp), rpmi_u32_count(resp)); + if (rc) + return rc; + + /* Wait for interrupt */ + wfi(); + + return 0; +} + +static int rpmi_system_suspend_check(u32 sleep_type) +{ + return ((sleep_type == SBI_SUSP_SLEEP_TYPE_SUSPEND) && + syssusp_ctx.suspend_supported) ? 0 : SBI_EINVAL; +} + +static int rpmi_system_suspend(u32 sleep_type, ulong resume_addr) +{ + int rc; + + if (sleep_type != SBI_SUSP_SLEEP_TYPE_SUSPEND) + return SBI_ENOTSUPP; + + rc = rpmi_syssusp(sleep_type, resume_addr); + if (rc) + return rc; + + return 0; +} + +static struct sbi_system_suspend_device rpmi_suspend_dev = { + .name = "rpmi-system-suspend", + .system_suspend_check = rpmi_system_suspend_check, + .system_suspend = rpmi_system_suspend, +}; + +static int rpmi_suspend_init(void *fdt, int nodeoff, + const struct fdt_match *match) +{ + int rc; + uint32_t attrs = 0; + + /* If channel already available then do nothing. */ + if (syssusp_ctx.chan) + return 0; + + /* + * If channel request failed then other end does not support + * suspend service group so do nothing. + */ + rc = fdt_mailbox_request_chan(fdt, nodeoff, 0, &syssusp_ctx.chan); + if (rc) + return 0; + + /* Get suspend attributes */ + rc = rpmi_syssusp_attrs(&attrs); + if (rc) + return rc; + + syssusp_ctx.suspend_supported = attrs & RPMI_SYSSUSP_FLAGS_SUPPORTED; + syssusp_ctx.cust_res_addr_supported = + attrs & RPMI_SYSSUSP_FLAGS_CUSTOM_RESUME_ADDR_SUPPORTED; + + sbi_system_suspend_set_device(&rpmi_suspend_dev); + + return 0; +} + +static const struct fdt_match rpmi_suspend_match[] = { + { .compatible = "riscv,rpmi-system-suspend" }, + {}, +}; + +struct fdt_suspend fdt_suspend_rpmi = { + .match_table = rpmi_suspend_match, + .init = rpmi_suspend_init, +}; diff --git a/lib/utils/suspend/objects.mk b/lib/utils/suspend/objects.mk index 30d897d1..657670a8 100644 --- a/lib/utils/suspend/objects.mk +++ b/lib/utils/suspend/objects.mk @@ -9,3 +9,6 @@ libsbiutils-objs-$(CONFIG_FDT_SUSPEND) += suspend/fdt_suspend.o libsbiutils-objs-$(CONFIG_FDT_SUSPEND) += suspend/fdt_suspend_drivers.carray.o + +carray-fdt_suspend_drivers-$(CONFIG_FDT_SUSPEND_RPMI) += fdt_suspend_rpmi +libsbiutils-objs-$(CONFIG_FDT_SUSPEND_RPMI) += suspend/fdt_suspend_rpmi.o diff --git a/platform/generic/configs/defconfig b/platform/generic/configs/defconfig index ec439d74..54300fb5 100644 --- a/platform/generic/configs/defconfig +++ b/platform/generic/configs/defconfig @@ -45,6 +45,7 @@ CONFIG_FDT_SERIAL_UART8250=y CONFIG_FDT_SERIAL_XILINX_UARTLITE=y CONFIG_SERIAL_SEMIHOSTING=y CONFIG_FDT_SUSPEND=y +CONFIG_FDT_SUSPEND_RPMI=y CONFIG_FDT_TIMER=y CONFIG_FDT_TIMER_MTIMER=y CONFIG_FDT_TIMER_PLMT=y