From patchwork Wed Mar 31 20:18:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Opaniuk X-Patchwork-Id: 1460714 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=foundries.io header.i=@foundries.io header.a=rsa-sha256 header.s=google header.b=iRH0UqIH; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F9d2v3gN1z9sRf for ; Thu, 1 Apr 2021 07:19:51 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B44888293E; Wed, 31 Mar 2021 22:19:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=foundries.io 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=foundries.io header.i=@foundries.io header.b="iRH0UqIH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 31DE482903; Wed, 31 Mar 2021 22:19:10 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3FCFF82898 for ; Wed, 31 Mar 2021 22:19:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=foundries.io Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=igor.opaniuk@foundries.io Received: by mail-lf1-x12b.google.com with SMTP id d12so9880018lfv.11 for ; Wed, 31 Mar 2021 13:19:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foundries.io; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VZuUD3mp+5hJaVkqbjkbiKYtp/TZ9NXPqx5FEKgHYcY=; b=iRH0UqIHUMZvKYkgEgDPAis59OG0eKA+Q/7AjIo7gvrtugHk1OHDqi7SGnWGtd88kN hOEvsS3RzXpOSbnrO2tMVKfeT8njkdJ847TxZrlxva6gkH9rTwXWyidKubHmdpYvYiCc SR4VdrWryvRjol3kw8ogdNJUSKDk8UvjSe5oDcwd+R3Z1ix2YunImGzVtVuJ1SJmsrTE QvwpGCT4tG5lJK27di0ptUPkJIyD95PViDQ/lVYbPAwO8czMnNd7Xy8d0YfRKQ8FbIT8 /+/frMkOpurTSzVlBRJpxcVhF2T58N6MbxLqd6IafwCvd1KJ96xOJruxnl8eKgx1IdJI fJuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VZuUD3mp+5hJaVkqbjkbiKYtp/TZ9NXPqx5FEKgHYcY=; b=ABKabNUtdIgiWtjtlmNotBQrbyINWkCSeSDBRdCglY81mtXcQ5O7N9WBnLZDfdttFq ndHiSW1bke1JcXFNAz6EsGjv55dRDgZrC8r/+bV24RdcDlLYGumJ3nurmtAEekwsMMWi Efuq+ArlEMP8J2FFYQSJqwbJD2SWXJ+OuNhzylH0y97beF/fW661ti0stKnEZzqB/by9 37VxEvYHXSIt5ELK+HVcMOMWLUqbsgzaQq00JOrueaoA0IEYLtC7TjHMER/PeAYX9qYw hd7O0+yfIMdKLRRtuDWUYxh82k093xrCTr2jEu69kK0Wr8XhVyjLlBIK+bJ0amGvOmha KLxQ== X-Gm-Message-State: AOAM533remiK2FaVYxzTM4lLpMS49X5hJ9eRT8RaseZjMBuHWShqkYTK zKtL0GaNxnhmWO6qCYjAfTW+7dv0LI9Nrydp X-Google-Smtp-Source: ABdhPJwb60MDCPvBEwSZmMEi0MY/LUBeWmXmySa9YaJr7dbleZDAIGIxJq6PF6VGsU2mJsD2ie7/+A== X-Received: by 2002:a05:6512:2026:: with SMTP id s6mr3107022lfs.43.1617221941386; Wed, 31 Mar 2021 13:19:01 -0700 (PDT) Received: from localhost ([109.108.76.111]) by smtp.gmail.com with ESMTPSA id q25sm324249lfn.42.2021.03.31.13.19.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Mar 2021 13:19:00 -0700 (PDT) From: Igor Opaniuk X-Google-Original-From: Igor Opaniuk To: u-boot@lists.denx.de Cc: xypron.glpk@gmx.de, ricardo@foundries.io, tim.anderson@foundries.io, mike@foundries.io, patrick.delaunay@foss.st.com, jorge@foundries.io, vanessa.maegima@foundries.io, daiane.angolini@foundries.io, Igor Opaniuk , Jon Hunter , Masahiro Yamada , Michal Simek , Simon Glass , Yann Gautier Subject: [RESEND PATCH v3 2/5] psci: add features/reset2 support Date: Wed, 31 Mar 2021 23:18:52 +0300 Message-Id: <20210331201855.1425276-3-igor.opaniuk@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210331201855.1425276-1-igor.opaniuk@gmail.com> References: <20210331201855.1425276-1-igor.opaniuk@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.4 at phobos.denx.de X-Virus-Status: Clean From: Igor Opaniuk Adds support for: * PSCI_FEATURES, which was introduced in PSCI 1.0. This provides API that allows discovering whether a specific PSCI function is implemented and its features. * SYSTEM_RESET2, which was introduced in PSCI 1.1, which extends existing SYSTEM_RESET. It provides support for vendor-specific resets, providing reset_type as an additional param. For additional details visit [1]. Implementations of some functions were borrowed from Linux PSCI driver code [2]. [1] https://developer.arm.com/documentation/den0022/latest/ [2] drivers/firmware/psci/psci.c Signed-off-by: Igor Opaniuk --- drivers/firmware/psci.c | 68 +++++++++++++++++++++++++++++++++++++++++ include/linux/psci.h | 3 ++ 2 files changed, 71 insertions(+) diff --git a/drivers/firmware/psci.c b/drivers/firmware/psci.c index 68953cc4f4..be57552aba 100644 --- a/drivers/firmware/psci.c +++ b/drivers/firmware/psci.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -26,6 +27,18 @@ #define PSCI_METHOD_HVC 1 #define PSCI_METHOD_SMC 2 +/* + * While a 64-bit OS can make calls with SMC32 calling conventions, for some + * calls it is necessary to use SMC64 to pass or return 64-bit values. + * For such calls PSCI_FN_NATIVE(version, name) will choose the appropriate + * (native-width) function ID. + */ +#if defined(CONFIG_ARM64) +#define PSCI_FN_NATIVE(version, name) PSCI_##version##_FN64_##name +#else +#define PSCI_FN_NATIVE(version, name) PSCI_##version##_FN_##name +#endif + #if CONFIG_IS_ENABLED(EFI_LOADER) int __efi_runtime_data psci_method; #else @@ -53,6 +66,34 @@ unsigned long __efi_runtime invoke_psci_fn return res.a0; } +static int psci_features(u32 psci_func_id) +{ + return invoke_psci_fn(PSCI_1_0_FN_PSCI_FEATURES, + psci_func_id, 0, 0); +} + +static u32 psci_0_2_get_version(void) +{ + return invoke_psci_fn(PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0); +} + +static bool psci_is_system_reset2_supported(void) +{ + int ret; + u32 ver; + + ver = psci_0_2_get_version(); + + if (PSCI_VERSION_MAJOR(ver) >= 1) { + ret = psci_features(PSCI_FN_NATIVE(1_1, SYSTEM_RESET2)); + + if (ret != PSCI_RET_NOT_SUPPORTED) + return true; + } + + return false; +} + static int psci_bind(struct udevice *dev) { /* No SYSTEM_RESET support for PSCI 0.1 */ @@ -141,6 +182,33 @@ void reset_misc(void) } #endif /* CONFIG_PSCI_RESET */ +void psci_sys_reset(u32 type) +{ + bool reset2_supported; + + do_psci_probe(); + + reset2_supported = psci_is_system_reset2_supported(); + + if (type == SYSRESET_WARM && reset2_supported) { + /* + * reset_type[31] = 0 (architectural) + * reset_type[30:0] = 0 (SYSTEM_WARM_RESET) + * cookie = 0 (ignored by the implementation) + */ + invoke_psci_fn(PSCI_FN_NATIVE(1_1, SYSTEM_RESET2), 0, 0, 0); + } else { + invoke_psci_fn(PSCI_0_2_FN_SYSTEM_RESET, 0, 0, 0); + } +} + +void psci_sys_poweroff(void) +{ + do_psci_probe(); + + invoke_psci_fn(PSCI_0_2_FN_SYSTEM_OFF, 0, 0, 0); +} + #ifdef CONFIG_CMD_POWEROFF int do_poweroff(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { diff --git a/include/linux/psci.h b/include/linux/psci.h index 38edde3137..c78c1079a8 100644 --- a/include/linux/psci.h +++ b/include/linux/psci.h @@ -118,6 +118,9 @@ #ifdef CONFIG_ARM_PSCI_FW unsigned long invoke_psci_fn(unsigned long a0, unsigned long a1, unsigned long a2, unsigned long a3); +void psci_sys_reset(u32 type); +void psci_sys_poweroff(void); + #else static inline unsigned long invoke_psci_fn(unsigned long a0, unsigned long a1, unsigned long a2, unsigned long a3)