From nobody Tue Jun 30 08:15:45 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7EDB9C433EF for ; Sat, 22 Jan 2022 03:55:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232552AbiAVDzB (ORCPT ); Fri, 21 Jan 2022 22:55:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232419AbiAVDy6 (ORCPT ); Fri, 21 Jan 2022 22:54:58 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99D1BC06173B for ; Fri, 21 Jan 2022 19:54:58 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id w190so4424579pfw.7 for ; Fri, 21 Jan 2022 19:54:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CYdDKM03pUu8N31R+N2Sqs9jO4GAOic0QVQiqI/HaA0=; b=AL2qCcPoqTFgjUzcFRRvL/VvqnFeTVVqoh4+z1cDdox9JJR+seu/JofKDmnNLqorsm lKQZA5LxkK+eEjxZgNTLx6uT2x2yQYek1gmIgOohxsef9l/nMjwN37YUi+EbZYX1XkrN N/POapTPbDWDWF2o7bdFQS0bDx0H8xsIs0fJs+mUnMIjY40M535YCAKh+cgcTxWldvMw e8u/Rr3NakeU8KYtuBAwmGWOjeTv16t1rquUOPETA4WpswWl3rbb0gDzCnVs2DGT8ge9 MwdY6QO0rFMdLKJ3PFp6DgxnhUE7qP8NtL5GLTRQKtkbnHgFCEFUvAd9ISk3o8T0epqU oLsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CYdDKM03pUu8N31R+N2Sqs9jO4GAOic0QVQiqI/HaA0=; b=Yf4S3eKjRd00n77b4aPjOE6hrGGuTyuCiFiKovkp9OpFx/lywAhTaZZWi9oNamV4k8 toRD7YG0VneOx/DMj2yMnCrRSazH43gghCOK3YNwBO6W1SrM62xpm2G9uTOz+HB2Inx5 bJ24i8kyQMmogVwYUY7qyz+Yd/zHKCGu3NlYodhQ2ITnM+jz5agNOf7tUqT1fV+ct9IY isflVv2TBcUoc8ZIZRXmMPs8nUwnB1J/ZIrhSZrvOtMyPaQ4seIox3mSNwJLZJsAlnAr +sRz2fwGfVFlDK1AsckDhJsAXPH9mh9B3Y77CuT5bCGt8KFseOTy5z2/M9vZx92YpBvM sdGg== X-Gm-Message-State: AOAM533D7Ju+w2ec7YXLMM0MgoYsusrQ6U74xzDpAu2bzx9vK3oj7MIC lgPK1HPGsueZ61zfz6AYg1c= X-Google-Smtp-Source: ABdhPJw070FOByJBVA42p0u7yayirhUO5FRDBBLKlCn0n55ddqhnL/gfrRUE2tQjo3x9yiLZseeJRA== X-Received: by 2002:a05:6a00:810:b0:4c1:e21d:a900 with SMTP id m16-20020a056a00081000b004c1e21da900mr6325088pfk.6.1642823697311; Fri, 21 Jan 2022 19:54:57 -0800 (PST) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id a1sm667255pjm.1.2022.01.21.19.54.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jan 2022 19:54:56 -0800 (PST) From: Florian Fainelli To: linux-arm-kernel@lists.infradead.org Cc: Florian Fainelli , bcm-kernel-feedback-list@broadcom.com (maintainer:BROADCOM BCM7XXX ARM ARCHITECTURE), Mark Rutland , Lorenzo Pieralisi , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 1/4] firmware: psci: Export a couple of suspend symbols Date: Fri, 21 Jan 2022 19:54:18 -0800 Message-Id: <20220122035421.4086618-2-f.fainelli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220122035421.4086618-1-f.fainelli@gmail.com> References: <20220122035421.4086618-1-f.fainelli@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Export psci_system_suspend_enter() and psci_cpu_suspend_enter() for the Broadcom STB PSCI extension to be usable and built as a loadable module. Signed-off-by: Florian Fainelli Reported-by: kernel test robot --- drivers/firmware/psci/psci.c | 9 ++++++++- include/linux/psci.h | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index cfb448eabdaa..9a60e340c248 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -355,7 +355,13 @@ int psci_cpu_suspend_enter(u32 state) =20 return ret; } +#else +int psci_cpu_suspend_enter(u32 state) +{ + return -EOPNOTSUPP; +} #endif +EXPORT_SYMBOL_GPL(psci_cpu_suspend_enter); =20 static int psci_system_suspend(unsigned long unused) { @@ -365,10 +371,11 @@ static int psci_system_suspend(unsigned long unused) pa_cpu_resume, 0, 0); } =20 -static int psci_system_suspend_enter(suspend_state_t state) +int psci_system_suspend_enter(suspend_state_t state) { return cpu_suspend(0, psci_system_suspend); } +EXPORT_SYMBOL_GPL(psci_system_suspend_enter); =20 static const struct platform_suspend_ops psci_suspend_ops =3D { .valid =3D suspend_valid_only_mem, diff --git a/include/linux/psci.h b/include/linux/psci.h index 4ca0060a3fc4..ffeba6b08e10 100644 --- a/include/linux/psci.h +++ b/include/linux/psci.h @@ -9,6 +9,7 @@ =20 #include #include +#include #include =20 #define PSCI_POWER_STATE_TYPE_STANDBY 0 @@ -17,6 +18,7 @@ bool psci_tos_resident_on(int cpu); =20 int psci_cpu_suspend_enter(u32 state); +int psci_system_suspend_enter(suspend_state_t state); bool psci_power_state_is_valid(u32 state); int psci_set_osi_mode(bool enable); bool psci_has_osi_support(void); --=20 2.25.1 From nobody Tue Jun 30 08:15:45 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D79D1C433F5 for ; Sat, 22 Jan 2022 03:55:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232870AbiAVDzE (ORCPT ); Fri, 21 Jan 2022 22:55:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229996AbiAVDy7 (ORCPT ); Fri, 21 Jan 2022 22:54:59 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41A97C06173B for ; Fri, 21 Jan 2022 19:54:59 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id v11-20020a17090a520b00b001b512482f36so7888539pjh.3 for ; Fri, 21 Jan 2022 19:54:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2AZpnBw4RaqQoYcagsg73LF4yfaWi1RtR7CrBVPWFJk=; b=GCFLOCrbsT3vYYjj9sk0+iqHPAU3MLHKF65dsd63ve3ERaTGwlgAhWbIuXV7/qP0jD cfNREdPKYJL8TlLF1zuKbNcP3qtsmzHPVFzzMTtKapTLuhLclZwMfkBZMRrz+peIA4x0 PNCckGsGHYkV/umugZOXh1zFqA5Q77jEsqHan+Z6uXtmQ5aXIR6/S6NT69MPnUrw/Hcg AjsO43kW4LJXOvWMObXxiRQPfnZ8bCiXEUS+ysmoLZv/41asA1TWA0repTbb1+WomnVO djJrSIk76Vy7j7FQYOWHgpowR+0mND4oc3icvUnfma0Tg+4g9Eds5tnLtpJcrFVSmXBB 7doQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2AZpnBw4RaqQoYcagsg73LF4yfaWi1RtR7CrBVPWFJk=; b=R7kzGhrT1L2CPSVadwHlvNpZMElza0VIzHKgz19UZri0yBBvS6vi0J0w35ZR5fGLUJ /icpRjuC6wb2VHH/MUbTZmrEzxRyREhZHQ2wRlk2NBYax5rx6yKGrJL5vnLwhd2yqgCa B4xGEUYeWeF8LLaUk+WVhuPDw6/3HUlAzABVWNwOM5yd4JTgkWX7DeeqEWwoXinKZ/jZ /vZ0Q6CVDWbgWFm2laXeAEN5mUTxr/duMlGGm6P6/hUSCToorys73JVsrWUrc6L/BGuo Bd/KU8/E8PO1Velm/MYeupPdLuNJ7yB1qAnOi7irRV8lz8EpCDQ/OMlar55tap13y28S bbnw== X-Gm-Message-State: AOAM531nfTrN59glNubRZbFSGH6f+hNH0aSthrgxiQpD+Dju2Uj/sWhQ S5t+zQEf7rhyd0GAVxLDfjo= X-Google-Smtp-Source: ABdhPJwDYRuZLdzX0adpwP9PuSyBj4/BK+RZDPdijFhKrsxH1DKB9ec1FpU3+ccpt5KLM51iJ2Y2bA== X-Received: by 2002:a17:90a:5d17:: with SMTP id s23mr3622752pji.65.1642823698692; Fri, 21 Jan 2022 19:54:58 -0800 (PST) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id a1sm667255pjm.1.2022.01.21.19.54.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jan 2022 19:54:58 -0800 (PST) From: Florian Fainelli To: linux-arm-kernel@lists.infradead.org Cc: Florian Fainelli , bcm-kernel-feedback-list@broadcom.com (maintainer:BROADCOM BCM7XXX ARM ARCHITECTURE), Mark Rutland , Lorenzo Pieralisi , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 2/4] soc: bcm: brcmstb: Make legacy PM code depend on !ARM_PSCI_FW Date: Fri, 21 Jan 2022 19:54:19 -0800 Message-Id: <20220122035421.4086618-3-f.fainelli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220122035421.4086618-1-f.fainelli@gmail.com> References: <20220122035421.4086618-1-f.fainelli@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" On ARM 32-bit the legacy PM code would conflict with a PSCI based implementation that we are going to introduce in subsequent commits. Make PM_BRCMSTB depend on !ARM_PSCI_FW to exclude the two implementations from each other. Signed-off-by: Florian Fainelli --- drivers/soc/bcm/brcmstb/pm/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/soc/bcm/brcmstb/pm/Makefile b/drivers/soc/bcm/brcmstb/= pm/Makefile index 8e10abb14f8b..86004458260c 100644 --- a/drivers/soc/bcm/brcmstb/pm/Makefile +++ b/drivers/soc/bcm/brcmstb/pm/Makefile @@ -1,4 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only +ifndef CONFIG_ARM_PSCI_FW obj-$(CONFIG_ARM) +=3D s2-arm.o pm-arm.o AFLAGS_s2-arm.o :=3D -march=3Darmv7-a +endif obj-$(CONFIG_BMIPS_GENERIC) +=3D s2-mips.o s3-mips.o pm-mips.o --=20 2.25.1 From nobody Tue Jun 30 08:15:45 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3D74C433F5 for ; Sat, 22 Jan 2022 03:55:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233043AbiAVDzJ (ORCPT ); Fri, 21 Jan 2022 22:55:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232796AbiAVDzB (ORCPT ); Fri, 21 Jan 2022 22:55:01 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E0BDC06173B for ; Fri, 21 Jan 2022 19:55:01 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id d12-20020a17090a628c00b001b4f47e2f51so12197038pjj.3 for ; Fri, 21 Jan 2022 19:55:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Rstih+bCUvI8qAsoOEFphlMMvh1FNlDra3LljL6dx4g=; b=b8Np5CfAwmYacAM1cntSktfj9EngIXuFis1GJEPT0s34kMoc3CunPKJvPpOX4KVjIO kpNpdKnqFPdScyqiamWBmaaN1v+BBcmYxzh6kqr4gaKW2Ok21LOUl4zNyfEwetj+KaOt s81tuSNgNAm8AY/ajc8jPF24UgAX5XYtapmovhqGG7lQGIeuqmld3SaPAvVIVqA2zrxh T0UBafQkfkEG+5NSwY6rPD3Luk7cQhlmeiT7EnN2UCUHuhrTQU6WU75TGNm+82VZlym9 2BBeaL5vf4iNqdOHDVWrUvhZiuavIQqHcuRdSzKcrMw4DF8cL1GJTOLyekbpO8qhXa95 fSOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Rstih+bCUvI8qAsoOEFphlMMvh1FNlDra3LljL6dx4g=; b=H4o/Az/p9cSCbacnQ9nJY9VrXSuxVyVS5xRRHho0hNtXMr/RB7GQITVqu81RvkTAxl +7bmeu1j212Dy8GLsk+/F7lNsq7T0cgoSz2KllPlVDny98YYuNr+o/jA0/x1Jm0QvjK7 Ndvtm7YTtBKJ+wRnda+BJAuT9qPWcn/mePIEjISpJBvNhSFr0TaP8iKq7OrqgEvlLEpJ vjjtTogncAG9hcXV/hlAmzOALHM6BNRE2R/mPtI06laBksb34mE+d38BGgs/i28CyhI1 Il61frbLWcxpsXlKxQKXmIdtiBizofUrxigiT8GmLx+4LjNbwAy1pBUhNZk0kuBDbxO6 Y4ww== X-Gm-Message-State: AOAM532Bs+YAr5dozRtzRfqTYSK5si8ks1plX4PUqfLM9nPn+NP72bYO 6zFvm9uI1PQhjrtf5TKAZoo= X-Google-Smtp-Source: ABdhPJwVyZbUIgjV0k63poA6oysZewo8wDokaLYLS/DJqHD4243wcBR59+RF6I/B5WkBMBGSAbFoDQ== X-Received: by 2002:a17:90a:6782:: with SMTP id o2mr3624424pjj.116.1642823700061; Fri, 21 Jan 2022 19:55:00 -0800 (PST) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id a1sm667255pjm.1.2022.01.21.19.54.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jan 2022 19:54:59 -0800 (PST) From: Florian Fainelli To: linux-arm-kernel@lists.infradead.org Cc: Florian Fainelli , bcm-kernel-feedback-list@broadcom.com (maintainer:BROADCOM BCM7XXX ARM ARCHITECTURE), Mark Rutland , Lorenzo Pieralisi , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 3/4] soc: bcm: brcmstb: Added support for PSCI system suspend operations Date: Fri, 21 Jan 2022 19:54:20 -0800 Message-Id: <20220122035421.4086618-4-f.fainelli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220122035421.4086618-1-f.fainelli@gmail.com> References: <20220122035421.4086618-1-f.fainelli@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for the Broadcom STB system suspend operations which leverage the standard PSCI functions and uses the psci_cpu_suspend_enter() operation to power off the system with or without retention ("echo standby > /sys/power/state"). The system reset path also supports a special "powercycle" mode which signals to the ARM Trusted Firmware that an external PMIC chip must force the SoC into a power cycle. As much as possible extensions were built using the SIP namespace rather than the standard PSCI namespace, however compatibility with the standard PSCI implementation is retained when CONFIG_BRCMSTB_PM is not selected. Signed-off-by: Florian Fainelli --- drivers/soc/bcm/brcmstb/Kconfig | 4 +- drivers/soc/bcm/brcmstb/pm/Makefile | 1 + drivers/soc/bcm/brcmstb/pm/pm-psci.c | 315 ++++++++++++++++++++++ include/linux/soc/brcmstb/brcmstb-smccc.h | 84 ++++++ 4 files changed, 402 insertions(+), 2 deletions(-) create mode 100644 drivers/soc/bcm/brcmstb/pm/pm-psci.c create mode 100644 include/linux/soc/brcmstb/brcmstb-smccc.h diff --git a/drivers/soc/bcm/brcmstb/Kconfig b/drivers/soc/bcm/brcmstb/Kcon= fig index 38e476905d96..a2b31717096e 100644 --- a/drivers/soc/bcm/brcmstb/Kconfig +++ b/drivers/soc/bcm/brcmstb/Kconfig @@ -2,8 +2,8 @@ if SOC_BRCMSTB =20 config BRCMSTB_PM - bool "Support suspend/resume for STB platforms" - default y + tristate "Support suspend/resume for STB platforms" + default ARCH_BRCMSTB || BMIPS_GENERIC depends on PM depends on ARCH_BRCMSTB || BMIPS_GENERIC select ARM_CPU_SUSPEND if ARM diff --git a/drivers/soc/bcm/brcmstb/pm/Makefile b/drivers/soc/bcm/brcmstb/= pm/Makefile index 86004458260c..4ece53db8937 100644 --- a/drivers/soc/bcm/brcmstb/pm/Makefile +++ b/drivers/soc/bcm/brcmstb/pm/Makefile @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_BRCMSTB_PM) +=3D pm-psci.o ifndef CONFIG_ARM_PSCI_FW obj-$(CONFIG_ARM) +=3D s2-arm.o pm-arm.o AFLAGS_s2-arm.o :=3D -march=3Darmv7-a diff --git a/drivers/soc/bcm/brcmstb/pm/pm-psci.c b/drivers/soc/bcm/brcmstb= /pm/pm-psci.c new file mode 100644 index 000000000000..7ba34d01c2fc --- /dev/null +++ b/drivers/soc/bcm/brcmstb/pm/pm-psci.c @@ -0,0 +1,315 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Broadcom STB PSCI based system wide PM support + * + * Copyright =C2=A9 2018-2022 Broadcom + */ + +#define pr_fmt(fmt) "brcmstb-pm-psci: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include "aon_defs.h" + +static psci_fn *invoke_psci_fn; +static bool brcmstb_psci_system_reset2_supported; +static bool brcmstb_psci_system_suspend_supported; +static bool brcmstb_psci_cpu_retention =3D true; + +static int brcmstb_psci_integ_region(unsigned long function_id, + unsigned long base, + unsigned long size) +{ + unsigned long end; + + if (!size) + return -EINVAL; + + end =3D DIV_ROUND_UP(base + size, SIP_MIN_REGION_SIZE); + base /=3D SIP_MIN_REGION_SIZE; + size =3D end - base; + + return invoke_psci_fn(function_id, base, size, 0); +} + +static int __maybe_unused brcmstb_psci_integ_region_set(unsigned long base, + unsigned long size) +{ + return brcmstb_psci_integ_region(SIP_FUNC_INTEG_REGION_SET, base, size); +} + +static int __maybe_unused brcmstb_psci_integ_region_del(unsigned long base, + unsigned long size) +{ + return brcmstb_psci_integ_region(SIP_FUNC_INTEG_REGION_DEL, base, size); +} + +static int brcmstb_psci_integ_region_reset_all(void) +{ + return invoke_psci_fn(SIP_FUNC_INTEG_REGION_RESET_ALL, 0, 0, 0); +} + +static int brcmstb_psci_sys_reset(struct notifier_block *nb, + unsigned long action, void *data) +{ + const char *cmd =3D data; + /* + * reset_type[31] =3D 0 (architectural) + * reset_type[30:0] =3D 0 (SYSTEM_WARM_RESET) + * cookie =3D 0 (ignored by the implementation) + */ + uint32_t reboot_type =3D 0; + + if ((action =3D=3D REBOOT_COLD || action =3D=3D REBOOT_WARM || + action =3D=3D REBOOT_SOFT) && + brcmstb_psci_system_reset2_supported) { + if (cmd && !strcmp(cmd, "powercycle")) + reboot_type =3D BIT(31) | 1; + invoke_psci_fn(PSCI_FN_NATIVE(1_1, SYSTEM_RESET2), reboot_type, 0, 0); + } else { + invoke_psci_fn(PSCI_0_2_FN_SYSTEM_RESET, 0, 0, 0); + } + + return NOTIFY_DONE; +} + +static struct notifier_block brcmstb_psci_sys_reset_nb =3D { + .notifier_call =3D brcmstb_psci_sys_reset, + .priority =3D 128, +}; + +void brcmstb_psci_sys_poweroff(void) +{ + invoke_psci_fn(PSCI_0_2_FN_SYSTEM_OFF, 0, 0, 0); +} + +static int psci_features(u32 psci_func_id) +{ + u32 features_func_id; + + switch (ARM_SMCCC_OWNER_NUM(psci_func_id)) { + case ARM_SMCCC_OWNER_SIP: + features_func_id =3D SIP_FUNC_PSCI_FEATURES; + break; + case ARM_SMCCC_OWNER_STANDARD: + features_func_id =3D PSCI_1_0_FN_PSCI_FEATURES; + break; + default: + return PSCI_RET_NOT_SUPPORTED; + } + + return invoke_psci_fn(features_func_id, psci_func_id, 0, 0); +} + +static int brcmstb_psci_enter(suspend_state_t state) +{ + /* Request a SYSTEM level power state with retention */ + u32 pstate =3D 2 << PSCI_0_2_POWER_STATE_AFFL_SHIFT | + !brcmstb_psci_cpu_retention << PSCI_0_2_POWER_STATE_TYPE_SHIFT; + int ret =3D -EINVAL; + + switch (state) { + case PM_SUSPEND_STANDBY: + ret =3D psci_cpu_suspend_enter(pstate); + break; + case PM_SUSPEND_MEM: + ret =3D brcmstb_psci_system_suspend_supported ? + psci_system_suspend_enter(state) : -EINVAL; + break; + } + + return ret; +} + +static int brcmstb_psci_valid(suspend_state_t state) +{ + switch (state) { + case PM_SUSPEND_STANDBY: + return true; + case PM_SUSPEND_MEM: + return brcmstb_psci_system_suspend_supported; + default: + return false; + } +} + +static const struct platform_suspend_ops brcmstb_psci_ops =3D { + .enter =3D brcmstb_psci_enter, + .valid =3D brcmstb_psci_valid, +}; + +static int brcmstb_psci_panic_notify(struct notifier_block *nb, + unsigned long action, void *data) +{ + int ret; + + ret =3D invoke_psci_fn(SIP_FUNC_PANIC_NOTIFY, BRCMSTB_PANIC_MAGIC, 0, 0); + if (ret !=3D PSCI_RET_SUCCESS) + return NOTIFY_BAD; + + return NOTIFY_DONE; +} + +static struct notifier_block brcmstb_psci_nb =3D { + .notifier_call =3D brcmstb_psci_panic_notify, +}; + +static ssize_t brcmstb_psci_version_show(struct kobject *kobj, + struct kobj_attribute *attr, + char *buf) +{ + struct arm_smccc_res res =3D { }; + u32 version; + + if (invoke_psci_fn =3D=3D __invoke_psci_fn_hvc) + arm_smccc_hvc(SIP_FUNC_PSCI_BRCMSTB_VERSION, + 0, 0, 0, 0, 0, 0, 0, &res); + else + arm_smccc_smc(SIP_FUNC_PSCI_BRCMSTB_VERSION, + 0, 0, 0, 0, 0, 0, 0, &res); + + if (res.a0 !=3D PSCI_RET_SUCCESS) + return -EOPNOTSUPP; + + version =3D res.a1; + + return sprintf(buf, "%d.%d.%d.%d\n", + (version >> 24) & 0xff, (version >> 16) & 0xff, + (version >> 8) & 0xff, version & 0xff); +} + +static struct kobj_attribute brcmstb_psci_version_attr =3D + __ATTR(mon_version, 0400, brcmstb_psci_version_show, NULL); + +static ssize_t brcmstb_psci_cpu_retention_show(struct kobject *kobj, + struct kobj_attribute *attr, + char *buf) +{ + return sprintf(buf, "%d\n", brcmstb_psci_cpu_retention); +} + +static ssize_t brcmstb_psci_cpu_retention_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + int ret, val; + + ret =3D kstrtoint(buf, 10, &val); + if (ret < 0) + return ret; + + if (val !=3D 0 && val !=3D 1) + return -EINVAL; + + brcmstb_psci_cpu_retention =3D !!val; + + return count; +} + +static struct kobj_attribute brcmstb_psci_cpu_retention_attr =3D + __ATTR(cpu_retention, 0644, brcmstb_psci_cpu_retention_show, + brcmstb_psci_cpu_retention_store); + +static const struct attribute *brcmstb_psci_attributes[] =3D { + &brcmstb_psci_version_attr.attr, + &brcmstb_psci_cpu_retention_attr.attr, + NULL, +}; + +static int brcmstb_pm_psci_init(void) +{ + unsigned long funcs_id[] =3D { + PSCI_0_2_FN_SYSTEM_OFF, + SIP_FUNC_INTEG_REGION_SET, + SIP_FUNC_INTEG_REGION_DEL, + SIP_FUNC_INTEG_REGION_RESET_ALL, + }; + struct arm_smccc_res res =3D { }; + struct kobject *brcmstb_kobj; + unsigned int i; + int ret; + + switch (arm_smccc_1_1_get_conduit()) { + case SMCCC_CONDUIT_HVC: + invoke_psci_fn =3D __invoke_psci_fn_hvc; + break; + case SMCCC_CONDUIT_SMC: + invoke_psci_fn =3D __invoke_psci_fn_smc; + break; + default: + return -EINVAL; + } + + /* Check the revision of monitor */ + if (invoke_psci_fn =3D=3D __invoke_psci_fn_hvc) + arm_smccc_hvc(SIP_SVC_REVISION, + 0, 0, 0, 0, 0, 0, 0, &res); + else + arm_smccc_smc(SIP_SVC_REVISION, + 0, 0, 0, 0, 0, 0, 0, &res); + + /* Test for our supported features */ + for (i =3D 0; i < ARRAY_SIZE(funcs_id); i++) { + ret =3D psci_features(funcs_id[i]); + if (ret =3D=3D PSCI_RET_NOT_SUPPORTED) { + pr_err("Firmware does not support function 0x%lx\n", + funcs_id[i]); + return -EOPNOTSUPP; + } + } + + ret =3D psci_features(PSCI_FN_NATIVE(1_1, SYSTEM_RESET2)); + if (ret !=3D PSCI_RET_NOT_SUPPORTED) + brcmstb_psci_system_reset2_supported =3D true; + + ret =3D psci_features(PSCI_FN_NATIVE(1_0, SYSTEM_SUSPEND)); + if (ret !=3D PSCI_RET_NOT_SUPPORTED) + brcmstb_psci_system_suspend_supported =3D true; + + ret =3D brcmstb_psci_integ_region_reset_all(); + if (ret !=3D PSCI_RET_SUCCESS) { + pr_err("Error resetting all integrity checking regions\n"); + return -EIO; + } + + if (res.a0 =3D=3D SIP_REVISION_MAJOR && res.a1 < SIP_REVISION_MINOR) { + pr_info("Firmware is too old! Please update\n"); + return -EOPNOTSUPP; + } + + brcmstb_kobj =3D kobject_create_and_add("brcmstb", firmware_kobj); + if (brcmstb_kobj) { + ret =3D sysfs_create_files(brcmstb_kobj, brcmstb_psci_attributes); + if (ret) + return ret; + } + + pm_power_off =3D brcmstb_psci_sys_poweroff; + register_restart_handler(&brcmstb_psci_sys_reset_nb); + suspend_set_ops(&brcmstb_psci_ops); + atomic_notifier_chain_register(&panic_notifier_list, + &brcmstb_psci_nb); + + pr_info("Using PSCI based system PM (full featured)\n"); + + return 0; +} +module_init(brcmstb_pm_psci_init); + +MODULE_AUTHOR("Broadcom"); +MODULE_DESCRIPTION("Broadcom STB PM PSCI operations"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/soc/brcmstb/brcmstb-smccc.h b/include/linux/soc/= brcmstb/brcmstb-smccc.h new file mode 100644 index 000000000000..2863e894e1c7 --- /dev/null +++ b/include/linux/soc/brcmstb/brcmstb-smccc.h @@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __BRCMSTB_SMCCC_H +#define __BRCMSTB_SMCCC_H + +#include +#include + +#ifdef CONFIG_64BIT +#define PSCI_FN_NATIVE(version, name) PSCI_##version##_FN64_##name +#else +#define PSCI_FN_NATIVE(version, name) PSCI_##version##_FN_##name +#endif + +/* Broadcom STB custom SIP function calls */ +#define SIP_FUNC_INTEG_REGION_SET \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + IS_ENABLED(CONFIG_64BIT), \ + ARM_SMCCC_OWNER_SIP, \ + 0) +#define SIP_FUNC_INTEG_REGION_DEL \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + IS_ENABLED(CONFIG_64BIT), \ + ARM_SMCCC_OWNER_SIP, \ + 1) +#define SIP_FUNC_INTEG_REGION_RESET_ALL \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + IS_ENABLED(CONFIG_64BIT), \ + ARM_SMCCC_OWNER_SIP, \ + 2) +#define SIP_FUNC_PANIC_NOTIFY \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + IS_ENABLED(CONFIG_64BIT), \ + ARM_SMCCC_OWNER_SIP, \ + 3) +#define SIP_FUNC_PSCI_FEATURES \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + IS_ENABLED(CONFIG_64BIT), \ + ARM_SMCCC_OWNER_SIP, \ + 4) +#define SIP_FUNC_PSCI_BRCMSTB_VERSION \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + IS_ENABLED(CONFIG_64BIT), \ + ARM_SMCCC_OWNER_SIP, \ + 5) + +#define SIP_SVC_REVISION \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + IS_ENABLED(CONFIG_64BIT), \ + ARM_SMCCC_OWNER_SIP, \ + 0xFF02) + +#define SIP_MIN_REGION_SIZE 4096 +#define SIP_REVISION_MAJOR 0 +#define SIP_REVISION_MINOR 2 + +typedef unsigned long (psci_fn)(unsigned long, unsigned long, + unsigned long, unsigned long); + +static inline unsigned long __invoke_psci_fn_hvc(unsigned long function_id, + unsigned long arg0, + unsigned long arg1, + unsigned long arg2) +{ + struct arm_smccc_res res; + + arm_smccc_hvc(function_id, arg0, arg1, arg2, 0, 0, 0, 0, &res); + + return res.a0; +} + +static inline unsigned long __invoke_psci_fn_smc(unsigned long function_id, + unsigned long arg0, + unsigned long arg1, + unsigned long arg2) +{ + struct arm_smccc_res res; + + arm_smccc_smc(function_id, arg0, arg1, arg2, 0, 0, 0, 0, &res); + + return res.a0; +} + + +#endif /* __BRCMSTB_SMCCC_H */ --=20 2.25.1 From nobody Tue Jun 30 08:15:45 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 524D3C433EF for ; Sat, 22 Jan 2022 03:55:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229641AbiAVDzP (ORCPT ); Fri, 21 Jan 2022 22:55:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232800AbiAVDzC (ORCPT ); Fri, 21 Jan 2022 22:55:02 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6F5EC06173D for ; Fri, 21 Jan 2022 19:55:01 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id o64so10894074pjo.2 for ; Fri, 21 Jan 2022 19:55:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mSHSygtJut5TGIpsbPHquOs8UiVBB7gZ8MMyr0HLxhA=; b=pxTopgDTCq/4/RyR8bgeUrroIY/dn2T2qOjzvEdL1ExK/feeNz42koPIGiLijAbL7r 6bjBgw7ti8sAXuF0dZ53ruqennL2uCcd1wd5VLjcxyG2F1l8gE+NvDUETIAK20q0JUUi Yrs38dxxIX2JscAba0h6gA9zYtSPueLgea6Crv2iwLZWHgTrMp+OqCOZOAgjDv9y7ZCx u4Nwdn/xfMZ4Xois6SwXaqx39YJl9YlQwNQ0MY9zAoAyxAt94aUVKYGwpFdPJ0m/GbTn gWv4jdDtVgjfkZoHEKWR+gPV4WqE1BqkV5KCSw0x669UB125BI1dabFCE+aKQoJd2BUg Qy3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mSHSygtJut5TGIpsbPHquOs8UiVBB7gZ8MMyr0HLxhA=; b=ZX97XeOhKGMjchN4QDkWFwYwaJfiXsPWo75Ot/TAt+J+dN4lCsy7Fn+YjExZfHsaj+ csnLhC8KqXsDxr6bw+SVh2Wbtliem6QgAO43XCqw86TA7h7y+JBGl8W9lU8D50MHSI9v Yvxa6nCUx0w4EUVX7NgzKsUtyWwolWpcNNDOwp5HbH2dX4YJYhduIAkAIXu6PfQ/lQFV Hd6lYih0K/0trnQYN9CR9ydRFs4PKMwkcTt/zhrjnxJ/CgSzDWNVnlPsjnGvA/y54Zsd qtFysXYR53D3CGQ5AJSzDB3lh0N4wVFgR4OKswX9/6Pw8HlKU7W7cp1L47vh6SSq1YPq Kshw== X-Gm-Message-State: AOAM5322AL4mbh2Yqv7HtgxwkNRrLk6iNvhEIRqtW2naUYJtZxHDPjDL YhBQ+gE5skjBlpmaZLMj0QA= X-Google-Smtp-Source: ABdhPJwMh9tdnpgpsp7RJ2vAuQBR9vxQQF4uqg3jTKIf08TidhAM79AiyArX+tO5ELVaO4K4mwizfQ== X-Received: by 2002:a17:902:7844:b0:14a:9cff:66c7 with SMTP id e4-20020a170902784400b0014a9cff66c7mr6639721pln.14.1642823701421; Fri, 21 Jan 2022 19:55:01 -0800 (PST) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id a1sm667255pjm.1.2022.01.21.19.55.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jan 2022 19:55:00 -0800 (PST) From: Florian Fainelli To: linux-arm-kernel@lists.infradead.org Cc: Florian Fainelli , bcm-kernel-feedback-list@broadcom.com (maintainer:BROADCOM BCM7XXX ARM ARCHITECTURE), Mark Rutland , Lorenzo Pieralisi , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 4/4] Documentation: ABI: Document Broadcom STB PSCI firmware files Date: Fri, 21 Jan 2022 19:54:21 -0800 Message-Id: <20220122035421.4086618-5-f.fainelli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220122035421.4086618-1-f.fainelli@gmail.com> References: <20220122035421.4086618-1-f.fainelli@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Document the attributes created by the Broadcom STB PSCI firmware code to allow retrieving the firmware version and the control of the CPU retention upon system suspend entry. Signed-off-by: Florian Fainelli --- Documentation/ABI/testing/sysfs-firmware-brcmstb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-firmware-brcmstb diff --git a/Documentation/ABI/testing/sysfs-firmware-brcmstb b/Documentati= on/ABI/testing/sysfs-firmware-brcmstb new file mode 100644 index 000000000000..5ebd8d0a34be --- /dev/null +++ b/Documentation/ABI/testing/sysfs-firmware-brcmstb @@ -0,0 +1,16 @@ +What: /sys/firmware/brcmstb/mon_version +Date: Jan 2022 +Contact: Florian Fainelli +Description: + Reports the ARM trusted firmware (monitor) version running on + the Broadcom STB platforms under the format: + A.B.C.D + +What: /sys/firmware/brcmstb/cpu_retention +Date: Jan 2022 +Contact: Florian Fainelli +Description: + Allows the toggling of whether S2 standby should be entered + with (default) or without CPU retention. + + Accepted values are 0 or 1. --=20 2.25.1