From mboxrd@z Thu Jan 1 00:00:00 1970 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 309B0C04A68 for ; Wed, 27 Jul 2022 20:59:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230046AbiG0U7e (ORCPT ); Wed, 27 Jul 2022 16:59:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229880AbiG0U7d (ORCPT ); Wed, 27 Jul 2022 16:59:33 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D756C52FF5 for ; Wed, 27 Jul 2022 13:59:32 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id d3so62747pls.4 for ; Wed, 27 Jul 2022 13:59:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=ZoxpMl7G6bYoZ5m7Tt1SczLa19+AUeboacUrN+JX56s=; b=Dmd+fgPFe7LybuV735GcZ80MltZODuHKCRLnw319fFXevygSthcHRNw6WYbbyFZhwe KtnpCskVDwZylktbUWBLZG1fZJimFrLAYER3R9XhQJ+ywX4rp9wdZD8tHdSpwO76HV2v iPFMbakgWSKnkw71OMgOkxrA4yvxndYN6Di5PCgox6o3S4z+D9WxeHLRw2g7ESWeEV/u Fkjz3HAdjuWad8P2V798qk7ZcfxobTltNSsxxEco8JWjVQpq+AYU8diYzb6p9ckoszhT A4SuHGo8JbxJGepNa94I5mG94A/5qRAgiuX4d6a1PDMj1y3v5jfVQx2iZypmUaVN37o6 ParQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=ZoxpMl7G6bYoZ5m7Tt1SczLa19+AUeboacUrN+JX56s=; b=s0eM0vv1hCIANhfdNUAJiNV8T685xzKv5OQVD42APKKN5gCTO0ZOB5zSr4Ejs+U/Iu PrreLEQPmLsWynic8RhzISnMaGJ2zg6yOtt5HVB17Sm8iZPG+Ni7SlaVVx3yPcoN9jeF 1A4uN4U7D+g02RbRqzalLfpJOtRuHSTA8tK7JkWO553iDHsMlXWNz9rgIGx1XUZCHAol lAnHJ4YLg49Z03KG3AphfFyoO/Oow78Uu8Jvi+3TmmLTcG68ASB5YpuDQjZeu85eRMWl CaRVbeoTZbCknC7Co467USRWNYtKiuKJhRNAkxAER18r2iI2FkWfD7cjHtfaQkJUCS91 +D+g== X-Gm-Message-State: AJIora+3qyYBnjs6B2JZeEgjaY8KcgNHVTK3Y7TMl1r7OeNsVxuyKSDl CSOIegr7LrNkbtsnikuFszBgDg== X-Google-Smtp-Source: AGRyM1vIdjlpcPMbI/ld9uwmAspAqTQR4ULQdBaJ1qQJriY1r2lOgSkjl/oheW1dascj9s6oNDhesw== X-Received: by 2002:a17:902:8605:b0:16b:e755:3c6e with SMTP id f5-20020a170902860500b0016be7553c6emr22818025plo.42.1658955572290; Wed, 27 Jul 2022 13:59:32 -0700 (PDT) Received: from ?IPV6:2401:4900:1f3a:5a45:a9cd:d7dd:fd01:73c0? ([2401:4900:1f3a:5a45:a9cd:d7dd:fd01:73c0]) by smtp.gmail.com with ESMTPSA id u18-20020a170902e5d200b0016d93be285asm5119198plf.173.2022.07.27.13.59.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Jul 2022 13:59:31 -0700 (PDT) Message-ID: Date: Thu, 28 Jul 2022 02:29:28 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] firmware/psci: Add debugfs support to ease debugging Content-Language: en-US To: Dmitry Baryshkov Cc: Mark Rutland , Lorenzo Pieralisi , linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org References: <20220727200901.1142557-1-dmitry.baryshkov@linaro.org> From: Bhupesh Sharma In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org On 7/28/22 2:26 AM, Dmitry Baryshkov wrote: > On Wed, 27 Jul 2022 at 23:55, Bhupesh Sharma wrote: >> >> >> >> On 7/28/22 2:23 AM, Dmitry Baryshkov wrote: >>> On Wed, 27 Jul 2022 at 23:15, Bhupesh Sharma wrote: >>>> >>>> Hi Dmitry, >>>> >>>> On 7/28/22 1:39 AM, Dmitry Baryshkov wrote: >>>>> To ease debugging of PSCI supported features, add debugfs file called >>>>> 'psci' describing PSCI and SMC CC versions, enabled features and >>>>> options. >>>>> >>>>> Signed-off-by: Dmitry Baryshkov >>>>> --- >>>>> drivers/firmware/psci/psci.c | 112 ++++++++++++++++++++++++++++++++++- >>>>> include/uapi/linux/psci.h | 9 +++ >>>>> 2 files changed, 120 insertions(+), 1 deletion(-) >>>>> >>>>> diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c >>>>> index b907768eea01..6595cc964635 100644 >>>>> --- a/drivers/firmware/psci/psci.c >>>>> +++ b/drivers/firmware/psci/psci.c >>>>> @@ -9,6 +9,7 @@ >>>>> #include >>>>> #include >>>>> #include >>>>> +#include >>>>> #include >>>>> #include >>>>> #include >>>>> @@ -324,12 +325,121 @@ static void psci_sys_poweroff(void) >>>>> invoke_psci_fn(PSCI_0_2_FN_SYSTEM_OFF, 0, 0, 0); >>>>> } >>>>> >>>>> -static int __init psci_features(u32 psci_func_id) >>>>> +static int psci_features(u32 psci_func_id) >>>> >>>> This change doesn't seem related to the patch $SUBJECT. >>>> Also is it really needed? If yes, probably this should be a separate patch. >>> >>> It is related and I don't think it should be moved to a separate >>> patch. Removing the __init annotation from psci_features() is >>> necessary to allow using psci_features() from psci_debufs_read(), >>> which is definitely not an __init code. Otherwise reading from >>> debugfs/psci would cause null pointer exceptions. >> >> Ok, and what is the behavior with CONFIG_DEBUG_FS = n? >> Does your patch work well in that case? > > Yes. Any particular reasons for the question? Your debugfs changes in this patch are protected with CONFIG_DEBUG_FS, while the __init code change is not. So, IMO its not really needed if CONFIG_DEBUG_FS is set to =n (hence probably needs to be a separate patch). Thanks. >>>>> { >>>>> return invoke_psci_fn(PSCI_1_0_FN_PSCI_FEATURES, >>>>> psci_func_id, 0, 0); >>>>> } >>>>> >>>>> +#ifdef CONFIG_DEBUG_FS >>>>> + >>>>> +#define PSCI_ID(ver, _name) \ >>>>> + { .fn = PSCI_##ver##_FN_##_name, .name = #_name, } >>>>> +#define PSCI_ID_NATIVE(ver, _name) \ >>>>> + { .fn = PSCI_FN_NATIVE(ver, _name), .name = #_name, } >>>>> + >>>>> +/* A table of all optional functions */ >>>>> +static const struct { >>>>> + u32 fn; >>>>> + const char *name; >>>>> +} psci_fn_ids[] = { >>>>> + PSCI_ID_NATIVE(0_2, MIGRATE), >>>>> + PSCI_ID(0_2, MIGRATE_INFO_TYPE), >>>>> + PSCI_ID_NATIVE(0_2, MIGRATE_INFO_UP_CPU), >>>>> + PSCI_ID(1_0, CPU_FREEZE), >>>>> + PSCI_ID_NATIVE(1_0, CPU_DEFAULT_SUSPEND), >>>>> + PSCI_ID_NATIVE(1_0, NODE_HW_STATE), >>>>> + PSCI_ID_NATIVE(1_0, SYSTEM_SUSPEND), >>>>> + PSCI_ID(1_0, SET_SUSPEND_MODE), >>>>> + PSCI_ID_NATIVE(1_0, STAT_RESIDENCY), >>>>> + PSCI_ID_NATIVE(1_0, STAT_COUNT), >>>>> + PSCI_ID_NATIVE(1_1, SYSTEM_RESET2), >>>>> +}; >>>>> + >>>>> +static int psci_debugfs_read(struct seq_file *s, void *data) >>>>> +{ >>>>> + int feature, type, i; >>>>> + u32 ver; >>>>> + >>>>> + ver = psci_ops.get_version(); >>>>> + seq_printf(s, "PSCIv%d.%d\n", >>>>> + PSCI_VERSION_MAJOR(ver), >>>>> + PSCI_VERSION_MINOR(ver)); >>>>> + >>>>> + /* PSCI_FEATURES is available only starting from 1.0 */ >>>>> + if (PSCI_VERSION_MAJOR(ver) < 1) >>>>> + return 0; >>>>> + >>>>> + feature = psci_features(ARM_SMCCC_VERSION_FUNC_ID); >>>>> + if (feature != PSCI_RET_NOT_SUPPORTED) { >>>>> + ver = invoke_psci_fn(ARM_SMCCC_VERSION_FUNC_ID, 0, 0, 0); >>>>> + seq_printf(s, "SMC Calling Convention v%d.%d\n", >>>>> + PSCI_VERSION_MAJOR(ver), >>>>> + PSCI_VERSION_MINOR(ver)); >>>>> + } else { >>>>> + seq_printf(s, "SMC Calling Convention v1.0 is assumed\n"); >>>>> + } >>>>> + >>>>> + feature = psci_features(PSCI_FN_NATIVE(0_2, CPU_SUSPEND)); >>>>> + if (feature < 0) { >>>>> + seq_printf(s, "PSCI_FEATURES(CPU_SUSPEND) error (%d)\n", feature); >>>>> + } else { >>>>> + seq_printf(s, "OSI is %ssupported\n", >>>>> + (feature & BIT(0)) ? "" : "not "); >>>>> + seq_printf(s, "%s StateID format is used\n", >>>>> + (feature & BIT(1)) ? "Extended" : "Original"); >>>>> + } >>>>> + >>>>> + type = psci_ops.migrate_info_type(); >>>>> + if (type == PSCI_0_2_TOS_UP_MIGRATE || >>>>> + type == PSCI_0_2_TOS_UP_NO_MIGRATE) { >>>>> + unsigned long cpuid; >>>>> + >>>>> + seq_printf(s, "Trusted OS %smigrate capable\n", >>>>> + type == PSCI_0_2_TOS_UP_NO_MIGRATE ? "not " : ""); >>>>> + cpuid = psci_migrate_info_up_cpu(); >>>>> + seq_printf(s, "Trusted OS resident on physical CPU 0x%lx (#%d)\n", cpuid, resident_cpu); >>>>> + } else if (type == PSCI_0_2_TOS_MP) { >>>>> + seq_printf(s, "Trusted OS migration not required\n"); >>>>> + } else { >>>>> + if (type != PSCI_RET_NOT_SUPPORTED) >>>>> + seq_printf(s, "MIGRATE_INFO_TYPE returned unknown type (%d)\n", type); >>>>> + } >>>>> + >>>>> + for (i = 0; i < ARRAY_SIZE(psci_fn_ids); i++) { >>>>> + feature = psci_features(psci_fn_ids[i].fn); >>>>> + if (feature == PSCI_RET_NOT_SUPPORTED) >>>>> + continue; >>>>> + if (feature < 0) >>>>> + seq_printf(s, "PSCI_FEATURES(%s) error (%d)\n", psci_fn_ids[i].name, feature); >>>>> + else >>>>> + seq_printf(s, "%s is supported\n", psci_fn_ids[i].name); >>>>> + } >>>>> + >>>>> + return 0; >>>>> +} >>>>> + >>>>> +static int psci_debugfs_open(struct inode *inode, struct file *f) >>>>> +{ >>>>> + return single_open(f, psci_debugfs_read, NULL); >>>>> +} >>>>> + >>>>> +static const struct file_operations psci_debugfs_ops = { >>>>> + .owner = THIS_MODULE, >>>>> + .open = psci_debugfs_open, >>>>> + .release = single_release, >>>>> + .read = seq_read, >>>>> + .llseek = seq_lseek >>>>> +}; >>>>> + >>>>> +static int __init psci_debugfs_init(void) >>>>> +{ >>>>> + return PTR_ERR_OR_ZERO(debugfs_create_file("psci", S_IRUGO, NULL, NULL, >>>>> + &psci_debugfs_ops)); >>>>> +} >>>>> +late_initcall(psci_debugfs_init) >>>>> +#endif >>>>> + >>>>> #ifdef CONFIG_CPU_IDLE >>>>> static int psci_suspend_finisher(unsigned long state) >>>>> { >>>>> diff --git a/include/uapi/linux/psci.h b/include/uapi/linux/psci.h >>>>> index 2bf93c0d6354..f6f0bad5858b 100644 >>>>> --- a/include/uapi/linux/psci.h >>>>> +++ b/include/uapi/linux/psci.h >>>>> @@ -48,11 +48,20 @@ >>>>> #define PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU PSCI_0_2_FN64(7) >>>>> >>>>> #define PSCI_1_0_FN_PSCI_FEATURES PSCI_0_2_FN(10) >>>>> +#define PSCI_1_0_FN_CPU_FREEZE PSCI_0_2_FN(11) >>>>> +#define PSCI_1_0_FN_CPU_DEFAULT_SUSPEND PSCI_0_2_FN(12) >>>>> +#define PSCI_1_0_FN_NODE_HW_STATE PSCI_0_2_FN(13) >>>>> #define PSCI_1_0_FN_SYSTEM_SUSPEND PSCI_0_2_FN(14) >>>>> #define PSCI_1_0_FN_SET_SUSPEND_MODE PSCI_0_2_FN(15) >>>>> +#define PSCI_1_0_FN_STAT_RESIDENCY PSCI_0_2_FN(16) >>>>> +#define PSCI_1_0_FN_STAT_COUNT PSCI_0_2_FN(17) >>>>> #define PSCI_1_1_FN_SYSTEM_RESET2 PSCI_0_2_FN(18) >>>>> >>>>> +#define PSCI_1_0_FN64_CPU_DEFAULT_SUSPEND PSCI_0_2_FN64(12) >>>>> +#define PSCI_1_0_FN64_NODE_HW_STATE PSCI_0_2_FN64(13) >>>>> #define PSCI_1_0_FN64_SYSTEM_SUSPEND PSCI_0_2_FN64(14) >>>>> +#define PSCI_1_0_FN64_STAT_RESIDENCY PSCI_0_2_FN64(16) >>>>> +#define PSCI_1_0_FN64_STAT_COUNT PSCI_0_2_FN64(17) >>>>> #define PSCI_1_1_FN64_SYSTEM_RESET2 PSCI_0_2_FN64(18) >>>>> >>>>> /* PSCI v0.2 power state encoding for CPU_SUSPEND function */ >>> >>> >>> > > > From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0B760C04A68 for ; Wed, 27 Jul 2022 21:00:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=R5QhcbybDMcXjGCFX5lG78Xdc3UFcbfz4uU4HfVi3IA=; b=abEyulazKGpQRG vQcATYvPEo/AKLZxqRDwPxAn8uFc1oCPwDHGTajNsFPPjd4Psd/JQCmunfl9Olzn4yJiKUK3vA8n4 hMfonqbLgwXwEqrSn+D4Go3xwqoCZUigx7Czlr4rcaDD4OBLos2E/xvAmZnkwsplNfxb4Sw8p0KmC fRKDZ/jgUsKO+xCRRbYnGrdkyKYB6sB5R+ntHAC69HIRDXGid2FSwFSl8tR12WSKM0k8g1ETcteqg aTjRN4q3WgiCAldqdu63jwKWL6ZstXdBxHmB6lqvuhtlzBuGAoPG82WuKhwjaTOKJeOw06XZ+O5Xs nb2Ssx35fM9Q7GwMUOwQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oGo83-000EhZ-0e; Wed, 27 Jul 2022 20:59:39 +0000 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oGo7z-000EdD-DN for linux-arm-kernel@lists.infradead.org; Wed, 27 Jul 2022 20:59:37 +0000 Received: by mail-pj1-x1032.google.com with SMTP id f7so226602pjp.0 for ; Wed, 27 Jul 2022 13:59:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=ZoxpMl7G6bYoZ5m7Tt1SczLa19+AUeboacUrN+JX56s=; b=Dmd+fgPFe7LybuV735GcZ80MltZODuHKCRLnw319fFXevygSthcHRNw6WYbbyFZhwe KtnpCskVDwZylktbUWBLZG1fZJimFrLAYER3R9XhQJ+ywX4rp9wdZD8tHdSpwO76HV2v iPFMbakgWSKnkw71OMgOkxrA4yvxndYN6Di5PCgox6o3S4z+D9WxeHLRw2g7ESWeEV/u Fkjz3HAdjuWad8P2V798qk7ZcfxobTltNSsxxEco8JWjVQpq+AYU8diYzb6p9ckoszhT A4SuHGo8JbxJGepNa94I5mG94A/5qRAgiuX4d6a1PDMj1y3v5jfVQx2iZypmUaVN37o6 ParQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=ZoxpMl7G6bYoZ5m7Tt1SczLa19+AUeboacUrN+JX56s=; b=nk9iZzUfS5F8txYGsZV6GNfq6XUvsuBGkr6T0LZOZowushCXlTw8Z4oAj/n6Ru/McD K9KEAk2WajtvBWARVG58J4iGQeCv7vl+OPg+IDq6u5Zcff27gtMYgk4I6KnxByswzzv/ REzWuLvH8lf2rQ7pjC2Ec6QBDgVvxHgea7CM4KsXmkQdrvFE2yjtt/lBNVF5SdPPaQ1k FnXAEzfjF5LdLmQ3HYJBL/JU4rUsug5Sxf1ERnHicInCb0zyp+6VjS+FoKSgwsD/QE9k 4n9HuC5afPKo+4+rRFZkBq1K6fniNkRJoa+tBO3wAZzZzIBbG7kopl74qKyRI3jhsoNQ SN3Q== X-Gm-Message-State: AJIora+T0lLtdBX+sca/XIL/dST2A7i3nh4K+ZGcfsaXLjnG4KpwOcLZ 6h8C9pFbuE170pUn0UW/E6bWjw== X-Google-Smtp-Source: AGRyM1vIdjlpcPMbI/ld9uwmAspAqTQR4ULQdBaJ1qQJriY1r2lOgSkjl/oheW1dascj9s6oNDhesw== X-Received: by 2002:a17:902:8605:b0:16b:e755:3c6e with SMTP id f5-20020a170902860500b0016be7553c6emr22818025plo.42.1658955572290; Wed, 27 Jul 2022 13:59:32 -0700 (PDT) Received: from ?IPV6:2401:4900:1f3a:5a45:a9cd:d7dd:fd01:73c0? ([2401:4900:1f3a:5a45:a9cd:d7dd:fd01:73c0]) by smtp.gmail.com with ESMTPSA id u18-20020a170902e5d200b0016d93be285asm5119198plf.173.2022.07.27.13.59.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Jul 2022 13:59:31 -0700 (PDT) Message-ID: Date: Thu, 28 Jul 2022 02:29:28 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] firmware/psci: Add debugfs support to ease debugging Content-Language: en-US To: Dmitry Baryshkov Cc: Mark Rutland , Lorenzo Pieralisi , linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org References: <20220727200901.1142557-1-dmitry.baryshkov@linaro.org> From: Bhupesh Sharma In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220727_135935_500129_9651562A X-CRM114-Status: GOOD ( 27.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 7/28/22 2:26 AM, Dmitry Baryshkov wrote: > On Wed, 27 Jul 2022 at 23:55, Bhupesh Sharma wrote: >> >> >> >> On 7/28/22 2:23 AM, Dmitry Baryshkov wrote: >>> On Wed, 27 Jul 2022 at 23:15, Bhupesh Sharma wrote: >>>> >>>> Hi Dmitry, >>>> >>>> On 7/28/22 1:39 AM, Dmitry Baryshkov wrote: >>>>> To ease debugging of PSCI supported features, add debugfs file called >>>>> 'psci' describing PSCI and SMC CC versions, enabled features and >>>>> options. >>>>> >>>>> Signed-off-by: Dmitry Baryshkov >>>>> --- >>>>> drivers/firmware/psci/psci.c | 112 ++++++++++++++++++++++++++++++++++- >>>>> include/uapi/linux/psci.h | 9 +++ >>>>> 2 files changed, 120 insertions(+), 1 deletion(-) >>>>> >>>>> diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c >>>>> index b907768eea01..6595cc964635 100644 >>>>> --- a/drivers/firmware/psci/psci.c >>>>> +++ b/drivers/firmware/psci/psci.c >>>>> @@ -9,6 +9,7 @@ >>>>> #include >>>>> #include >>>>> #include >>>>> +#include >>>>> #include >>>>> #include >>>>> #include >>>>> @@ -324,12 +325,121 @@ static void psci_sys_poweroff(void) >>>>> invoke_psci_fn(PSCI_0_2_FN_SYSTEM_OFF, 0, 0, 0); >>>>> } >>>>> >>>>> -static int __init psci_features(u32 psci_func_id) >>>>> +static int psci_features(u32 psci_func_id) >>>> >>>> This change doesn't seem related to the patch $SUBJECT. >>>> Also is it really needed? If yes, probably this should be a separate patch. >>> >>> It is related and I don't think it should be moved to a separate >>> patch. Removing the __init annotation from psci_features() is >>> necessary to allow using psci_features() from psci_debufs_read(), >>> which is definitely not an __init code. Otherwise reading from >>> debugfs/psci would cause null pointer exceptions. >> >> Ok, and what is the behavior with CONFIG_DEBUG_FS = n? >> Does your patch work well in that case? > > Yes. Any particular reasons for the question? Your debugfs changes in this patch are protected with CONFIG_DEBUG_FS, while the __init code change is not. So, IMO its not really needed if CONFIG_DEBUG_FS is set to =n (hence probably needs to be a separate patch). Thanks. >>>>> { >>>>> return invoke_psci_fn(PSCI_1_0_FN_PSCI_FEATURES, >>>>> psci_func_id, 0, 0); >>>>> } >>>>> >>>>> +#ifdef CONFIG_DEBUG_FS >>>>> + >>>>> +#define PSCI_ID(ver, _name) \ >>>>> + { .fn = PSCI_##ver##_FN_##_name, .name = #_name, } >>>>> +#define PSCI_ID_NATIVE(ver, _name) \ >>>>> + { .fn = PSCI_FN_NATIVE(ver, _name), .name = #_name, } >>>>> + >>>>> +/* A table of all optional functions */ >>>>> +static const struct { >>>>> + u32 fn; >>>>> + const char *name; >>>>> +} psci_fn_ids[] = { >>>>> + PSCI_ID_NATIVE(0_2, MIGRATE), >>>>> + PSCI_ID(0_2, MIGRATE_INFO_TYPE), >>>>> + PSCI_ID_NATIVE(0_2, MIGRATE_INFO_UP_CPU), >>>>> + PSCI_ID(1_0, CPU_FREEZE), >>>>> + PSCI_ID_NATIVE(1_0, CPU_DEFAULT_SUSPEND), >>>>> + PSCI_ID_NATIVE(1_0, NODE_HW_STATE), >>>>> + PSCI_ID_NATIVE(1_0, SYSTEM_SUSPEND), >>>>> + PSCI_ID(1_0, SET_SUSPEND_MODE), >>>>> + PSCI_ID_NATIVE(1_0, STAT_RESIDENCY), >>>>> + PSCI_ID_NATIVE(1_0, STAT_COUNT), >>>>> + PSCI_ID_NATIVE(1_1, SYSTEM_RESET2), >>>>> +}; >>>>> + >>>>> +static int psci_debugfs_read(struct seq_file *s, void *data) >>>>> +{ >>>>> + int feature, type, i; >>>>> + u32 ver; >>>>> + >>>>> + ver = psci_ops.get_version(); >>>>> + seq_printf(s, "PSCIv%d.%d\n", >>>>> + PSCI_VERSION_MAJOR(ver), >>>>> + PSCI_VERSION_MINOR(ver)); >>>>> + >>>>> + /* PSCI_FEATURES is available only starting from 1.0 */ >>>>> + if (PSCI_VERSION_MAJOR(ver) < 1) >>>>> + return 0; >>>>> + >>>>> + feature = psci_features(ARM_SMCCC_VERSION_FUNC_ID); >>>>> + if (feature != PSCI_RET_NOT_SUPPORTED) { >>>>> + ver = invoke_psci_fn(ARM_SMCCC_VERSION_FUNC_ID, 0, 0, 0); >>>>> + seq_printf(s, "SMC Calling Convention v%d.%d\n", >>>>> + PSCI_VERSION_MAJOR(ver), >>>>> + PSCI_VERSION_MINOR(ver)); >>>>> + } else { >>>>> + seq_printf(s, "SMC Calling Convention v1.0 is assumed\n"); >>>>> + } >>>>> + >>>>> + feature = psci_features(PSCI_FN_NATIVE(0_2, CPU_SUSPEND)); >>>>> + if (feature < 0) { >>>>> + seq_printf(s, "PSCI_FEATURES(CPU_SUSPEND) error (%d)\n", feature); >>>>> + } else { >>>>> + seq_printf(s, "OSI is %ssupported\n", >>>>> + (feature & BIT(0)) ? "" : "not "); >>>>> + seq_printf(s, "%s StateID format is used\n", >>>>> + (feature & BIT(1)) ? "Extended" : "Original"); >>>>> + } >>>>> + >>>>> + type = psci_ops.migrate_info_type(); >>>>> + if (type == PSCI_0_2_TOS_UP_MIGRATE || >>>>> + type == PSCI_0_2_TOS_UP_NO_MIGRATE) { >>>>> + unsigned long cpuid; >>>>> + >>>>> + seq_printf(s, "Trusted OS %smigrate capable\n", >>>>> + type == PSCI_0_2_TOS_UP_NO_MIGRATE ? "not " : ""); >>>>> + cpuid = psci_migrate_info_up_cpu(); >>>>> + seq_printf(s, "Trusted OS resident on physical CPU 0x%lx (#%d)\n", cpuid, resident_cpu); >>>>> + } else if (type == PSCI_0_2_TOS_MP) { >>>>> + seq_printf(s, "Trusted OS migration not required\n"); >>>>> + } else { >>>>> + if (type != PSCI_RET_NOT_SUPPORTED) >>>>> + seq_printf(s, "MIGRATE_INFO_TYPE returned unknown type (%d)\n", type); >>>>> + } >>>>> + >>>>> + for (i = 0; i < ARRAY_SIZE(psci_fn_ids); i++) { >>>>> + feature = psci_features(psci_fn_ids[i].fn); >>>>> + if (feature == PSCI_RET_NOT_SUPPORTED) >>>>> + continue; >>>>> + if (feature < 0) >>>>> + seq_printf(s, "PSCI_FEATURES(%s) error (%d)\n", psci_fn_ids[i].name, feature); >>>>> + else >>>>> + seq_printf(s, "%s is supported\n", psci_fn_ids[i].name); >>>>> + } >>>>> + >>>>> + return 0; >>>>> +} >>>>> + >>>>> +static int psci_debugfs_open(struct inode *inode, struct file *f) >>>>> +{ >>>>> + return single_open(f, psci_debugfs_read, NULL); >>>>> +} >>>>> + >>>>> +static const struct file_operations psci_debugfs_ops = { >>>>> + .owner = THIS_MODULE, >>>>> + .open = psci_debugfs_open, >>>>> + .release = single_release, >>>>> + .read = seq_read, >>>>> + .llseek = seq_lseek >>>>> +}; >>>>> + >>>>> +static int __init psci_debugfs_init(void) >>>>> +{ >>>>> + return PTR_ERR_OR_ZERO(debugfs_create_file("psci", S_IRUGO, NULL, NULL, >>>>> + &psci_debugfs_ops)); >>>>> +} >>>>> +late_initcall(psci_debugfs_init) >>>>> +#endif >>>>> + >>>>> #ifdef CONFIG_CPU_IDLE >>>>> static int psci_suspend_finisher(unsigned long state) >>>>> { >>>>> diff --git a/include/uapi/linux/psci.h b/include/uapi/linux/psci.h >>>>> index 2bf93c0d6354..f6f0bad5858b 100644 >>>>> --- a/include/uapi/linux/psci.h >>>>> +++ b/include/uapi/linux/psci.h >>>>> @@ -48,11 +48,20 @@ >>>>> #define PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU PSCI_0_2_FN64(7) >>>>> >>>>> #define PSCI_1_0_FN_PSCI_FEATURES PSCI_0_2_FN(10) >>>>> +#define PSCI_1_0_FN_CPU_FREEZE PSCI_0_2_FN(11) >>>>> +#define PSCI_1_0_FN_CPU_DEFAULT_SUSPEND PSCI_0_2_FN(12) >>>>> +#define PSCI_1_0_FN_NODE_HW_STATE PSCI_0_2_FN(13) >>>>> #define PSCI_1_0_FN_SYSTEM_SUSPEND PSCI_0_2_FN(14) >>>>> #define PSCI_1_0_FN_SET_SUSPEND_MODE PSCI_0_2_FN(15) >>>>> +#define PSCI_1_0_FN_STAT_RESIDENCY PSCI_0_2_FN(16) >>>>> +#define PSCI_1_0_FN_STAT_COUNT PSCI_0_2_FN(17) >>>>> #define PSCI_1_1_FN_SYSTEM_RESET2 PSCI_0_2_FN(18) >>>>> >>>>> +#define PSCI_1_0_FN64_CPU_DEFAULT_SUSPEND PSCI_0_2_FN64(12) >>>>> +#define PSCI_1_0_FN64_NODE_HW_STATE PSCI_0_2_FN64(13) >>>>> #define PSCI_1_0_FN64_SYSTEM_SUSPEND PSCI_0_2_FN64(14) >>>>> +#define PSCI_1_0_FN64_STAT_RESIDENCY PSCI_0_2_FN64(16) >>>>> +#define PSCI_1_0_FN64_STAT_COUNT PSCI_0_2_FN64(17) >>>>> #define PSCI_1_1_FN64_SYSTEM_RESET2 PSCI_0_2_FN64(18) >>>>> >>>>> /* PSCI v0.2 power state encoding for CPU_SUSPEND function */ >>> >>> >>> > > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel