Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp139330imm; Wed, 30 May 2018 19:54:05 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLsn7ctWDoUGqaBowiFyg/hajpvg7JnPpEtDlBZT8uf6/l6GLk2cott3YACVPuamWm0HI6a X-Received: by 2002:a17:902:145:: with SMTP id 63-v6mr5251859plb.332.1527735245592; Wed, 30 May 2018 19:54:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527735245; cv=none; d=google.com; s=arc-20160816; b=Fi8KCKpCYFSMmTgbRwCTZmqT1NSGy1t8HQA6ToSsNed7gMogmVju0F9mRrC7SvxIC7 0Ln3Ycq4g6/0/RrPaznOOt27SsKGuH8Q8v9KziLdUdK+IxeYXyFxZbbG5AFsi0WZ3svd OgSMn3yoe8ftHqQVkgpIyvqzVqeZtn74esfvSAR96SfHe4mZySp8XmaEEV2iBHQjFATQ 0Q0VozVeEKk5PeYiTCl8U2QqXlfYptWACpVNNscw4xKFSixbGp51v2nA4UBueBehQfLi 0dAfn/MQV0ZedonIyNCQiujpfJEZ8JiT2Toz2pUMCL36A8WP4jLX1+AkjG1iaqFhdCd2 lHYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=IvfjH1ORQDM+DmMsmCv+yF8YdktmndG5mwmt5jZX95I=; b=O0It/NNBdMkvrgfxUYnO+l0+BUk3aDE4acBOETPg4Z7Y7R0KGcinqwrWxxnPT2CD/T ir6iOwOSeDEkuOTa1KWvzrqODI4vbKTKhm/vsF6Z4h7UiOy2OadPUnL7E5PQL7+YMSYe nnwajIU5DcB2HkcvxVZO/n5co5oSi+YSLK+A8n5jBpvdGJZ6ZmC7GAl2Pp34Nd4H4uN0 LBz+fjgPzj/CPTpogEmOk7LY/6nPlqhGgYa8bkBp+8wtAS8+US0HgxUI4NpSVtKisJMi oSLn+Fzwp0O8IZTRnZJnCaX0jGBdysTdbmCwktQcR9QzazMCU/Ag45+t1p+0lgImjhvD iWLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s192-v6si13188485pgc.607.2018.05.30.19.53.51; Wed, 30 May 2018 19:54:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932700AbeEaCxT (ORCPT + 99 others); Wed, 30 May 2018 22:53:19 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:57990 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932658AbeEaCxQ (ORCPT ); Wed, 30 May 2018 22:53:16 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4V2qfNu068338 for ; Wed, 30 May 2018 22:53:16 -0400 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ja5g95yrd-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 30 May 2018 22:53:15 -0400 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 31 May 2018 03:53:13 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 31 May 2018 03:53:11 +0100 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4V2r9Yn20906150 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 31 May 2018 02:53:10 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 77BCA4204D; Thu, 31 May 2018 03:43:40 +0100 (BST) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 113A442047; Thu, 31 May 2018 03:43:38 +0100 (BST) Received: from aksadiga.ibm (unknown [9.195.43.157]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 31 May 2018 03:43:37 +0100 (BST) From: Akshay Adiga To: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: stewart@linux.vnet.ibm.com, svaidy@linux.vnet.ibm.com, ego@linux.vnet.ibm.com, mpe@ellerman.id.au, Akshay Adiga Subject: [PATCH] [SCHEME 1] Add support for new idle device tree format Date: Thu, 31 May 2018 08:23:04 +0530 X-Mailer: git-send-email 2.5.5 X-TM-AS-GCONF: 00 x-cbid: 18053102-4275-0000-0000-0000028816A9 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18053102-4276-0000-0000-0000378F17A1 Message-Id: <1527735184-24465-1-git-send-email-akshay.adiga@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-05-30_10:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1805310029 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds support for new device-tree format for idle state description. Previously if a older kernel runs on a newer firmware, it may enable all available states irrespective of its capability of handling it. New device tree format adds a compatible flag, so that only kernel which has the capability to handle the version of stop state will enable it. Older kernel will still see stop0 and stop0_lite in older format and we will depricate it after some time. Idea is to bump up the version in firmware if we find a bug or regression in stop states. A fix will be provided in linux which would now know about the bumped up version of stop states, where as kernel without fixes would ignore the states. New idle state device tree format : power-mgt { ... ibm,enabled-stop-levels = <0xec000000>; ibm,cpu-idle-state-psscr-mask = <0x0 0x3003ff 0x0 0x3003ff>; ibm,cpu-idle-state-latencies-ns = <0x3e8 0x7d0>; ibm,cpu-idle-state-psscr = <0x0 0x330 0x0 0x300330>; ibm,cpu-idle-state-flags = <0x100000 0x101000>; ibm,cpu-idle-state-residency-ns = <0x2710 0x4e20>; ibm,idle-states { phandle = <0xff>; stop4 { flags = <0x207000>; compatible = "ibm,cpuidle-state-v1"; psscr-mask = <0x0 0x3003ff>; handle = <0x102>; latency-ns = <0x186a0>; residency-ns = <0x989680>; psscr = <0x0 0x300374>; }; ... stop11 { ... compatible = "ibm,cpuoffline-state-v1"; ... }; }; Signed-off-by: Akshay Adiga --- arch/powerpc/platforms/powernv/idle.c | 70 ++++++++++++++++++++++++++++++----- drivers/cpuidle/cpuidle-powernv.c | 26 ++++++++++++- 2 files changed, 85 insertions(+), 11 deletions(-) diff --git a/arch/powerpc/platforms/powernv/idle.c b/arch/powerpc/platforms/powernv/idle.c index 1f12ab1..074381d 100644 --- a/arch/powerpc/platforms/powernv/idle.c +++ b/arch/powerpc/platforms/powernv/idle.c @@ -623,17 +623,19 @@ int validate_psscr_val_mask(u64 *psscr_val, u64 *psscr_mask, u32 flags) * Returns 0 on success */ static int __init pnv_power9_idle_init(struct device_node *np, u32 *flags, - int dt_idle_states) + int dt_idle_states, int additional_states) { u64 *psscr_val = NULL; u64 *psscr_mask = NULL; u32 *residency_ns = NULL; u64 max_residency_ns = 0; - int rc = 0, i; - - psscr_val = kcalloc(dt_idle_states, sizeof(*psscr_val), GFP_KERNEL); - psscr_mask = kcalloc(dt_idle_states, sizeof(*psscr_mask), GFP_KERNEL); - residency_ns = kcalloc(dt_idle_states, sizeof(*residency_ns), + int rc = 0, i, orig_dt_idle_states; + struct device_node *dt_node; + orig_dt_idle_states = dt_idle_states; + /* TODO: remove ugliness of using additional_states count*/ + psscr_val = kcalloc(dt_idle_states+additional_states, sizeof(*psscr_val), GFP_KERNEL); + psscr_mask = kcalloc(dt_idle_states+additional_states, sizeof(*psscr_mask), GFP_KERNEL); + residency_ns = kcalloc(dt_idle_states+additional_states, sizeof(*residency_ns), GFP_KERNEL); if (!psscr_val || !psscr_mask || !residency_ns) { @@ -664,7 +666,37 @@ static int __init pnv_power9_idle_init(struct device_node *np, u32 *flags, rc = -1; goto out; } + for_each_compatible_node( dt_node, NULL, "ibm,cpuoffline-state_v1" ) { + printk("Found a state\n"); + rc = of_property_read_u32(dt_node, "residency-ns" , &(residency_ns[dt_idle_states])); + if (rc) + printk("error reading residency rc= %d\n",rc); + rc = of_property_read_u64(dt_node, "psscr-mask" , &(psscr_mask[dt_idle_states])); + if (rc) + printk("error reading psscr-mask rc= %d\n",rc); + rc = of_property_read_u64(dt_node, "psscr" , &(psscr_val[dt_idle_states])); + if (rc) + printk("error reading psscr rc= %d\n",rc); + dt_idle_states++; + } + /* Fall back if no cpuoffline state found */ + if ( orig_dt_idle_states == dt_idle_states) { + for_each_compatible_node( dt_node, NULL, "ibm,cpuidle-state_v1" ) { + printk("Found a state\n"); + rc = of_property_read_u32(dt_node, "residency-ns" , &(residency_ns[dt_idle_states])); + if (rc) + printk("error reading residency rc= %d\n",rc); + rc = of_property_read_u64(dt_node, "psscr-mask" , &(psscr_mask[dt_idle_states])); + if (rc) + printk("error reading psscr-mask rc= %d\n",rc); + rc = of_property_read_u64(dt_node, "psscr" , &(psscr_val[dt_idle_states])); + if (rc) + printk("error reading psscr rc= %d\n",rc); + dt_idle_states++; + } + } + /* * Set pnv_first_deep_stop_state, pnv_deepest_stop_psscr_{val,mask}, * and the pnv_default_stop_{val,mask}. @@ -740,10 +772,11 @@ static int __init pnv_power9_idle_init(struct device_node *np, u32 *flags, */ static void __init pnv_probe_idle_states(void) { - struct device_node *np; + struct device_node *np,*dt_node; int dt_idle_states; u32 *flags = NULL; - int i; + int i,rc; + int additional_states=0; np = of_find_node_by_path("/ibm,opal/power-mgt"); if (!np) { @@ -765,12 +798,29 @@ static void __init pnv_probe_idle_states(void) goto out; } + + for_each_compatible_node( dt_node, NULL, "ibm,cpuidle-state-v1" ) { + + i = dt_idle_states + additional_states; + rc = of_property_read_u32(dt_node, "flags" , &(flags[i])); + if (rc) + printk("error reading flags rc= %d\n",rc); + additional_states++; + } + for_each_compatible_node( dt_node, NULL, "ibm,cpuoffline-state-v1" ) { + + i = dt_idle_states + additional_states; + rc = of_property_read_u32(dt_node, "flags" , &(flags[i])); + if (rc) + printk("error reading flags rc= %d\n",rc); + additional_states++; + } if (cpu_has_feature(CPU_FTR_ARCH_300)) { - if (pnv_power9_idle_init(np, flags, dt_idle_states)) + if (pnv_power9_idle_init(np, flags, dt_idle_states,additional_states)) goto out; } - for (i = 0; i < dt_idle_states; i++) + for (i = 0; i < dt_idle_states+additional_states; i++) supported_cpuidle_states |= flags[i]; out: diff --git a/drivers/cpuidle/cpuidle-powernv.c b/drivers/cpuidle/cpuidle-powernv.c index 1a8234e..e06181f 100644 --- a/drivers/cpuidle/cpuidle-powernv.c +++ b/drivers/cpuidle/cpuidle-powernv.c @@ -241,7 +241,7 @@ static inline int validate_dt_prop_sizes(const char *prop1, int prop1_len, extern u32 pnv_get_supported_cpuidle_states(void); static int powernv_add_idle_states(void) { - struct device_node *power_mgt; + struct device_node *power_mgt,*dt_node; int nr_idle_states = 1; /* Snooze */ int dt_idle_states, count; u32 latency_ns[CPUIDLE_STATE_MAX]; @@ -365,6 +365,30 @@ static int powernv_add_idle_states(void) residency_ns, dt_idle_states); } + /* Support new dt format for idle states */ + for_each_compatible_node( dt_node, NULL, "ibm,cpuidle-state-v1" ) { + printk("Found a state\n"); + rc = of_property_read_string(dt_node, "name" , &(names[dt_idle_states])); + if (rc) + printk("error reading names rc= %d\n",rc); + rc = of_property_read_u32(dt_node, "residency-ns" , &(residency_ns[dt_idle_states])); + if (rc) + printk("error reading residency rc= %d\n",rc); + rc = of_property_read_u32(dt_node, "latency-ns" , &(latency_ns[dt_idle_states])); + if (rc) + printk("error reading latency rc= %d\n",rc); + rc = of_property_read_u32(dt_node, "flags" , &(flags[dt_idle_states])); + if (rc) + printk("error reading flags rc= %d\n",rc); + rc = of_property_read_u64(dt_node, "psscr-mask" , &(psscr_mask[dt_idle_states])); + if (rc) + printk("error reading psscr-mask rc= %d\n",rc); + rc = of_property_read_u64(dt_node, "psscr" , &(psscr_val[dt_idle_states])); + if (rc) + printk("error reading psscr rc= %d\n",rc); + dt_idle_states++; + } + for (i = 0; i < dt_idle_states; i++) { unsigned int exit_latency, target_residency; bool stops_timebase = false; -- 2.5.5