Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp21365779ybl; Mon, 6 Jan 2020 03:13:22 -0800 (PST) X-Google-Smtp-Source: APXvYqzRQdq3ecYlNS4is+8GKBOe+Kdv9/gUtLycUYKwkFspYGqZfGnHoU8hIkp8BD+fpIKFAonx X-Received: by 2002:a9d:6396:: with SMTP id w22mr28402093otk.364.1578309202192; Mon, 06 Jan 2020 03:13:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578309202; cv=none; d=google.com; s=arc-20160816; b=YTjgZw/ATZ31pJyUYyRejsFHp1NzKTBh2p+Gj074hUDTyIkdNWBti7RU6+ejlNjFKD K9RbJETbHSQvlv4tkJdGiSdWyIv2yYaBPkIZ91Is2nFkun+eyk7lK0ZsOLKlpaYT8iib ftTx/117WMQsXmiCfUmVm0UCgBIPX42n45RS8P0N48AEITT8Ww/bwmrLAl603py1oI06 X6Vxk8QCJ4NHZJ8f8uXRPX2mS8CAbCpxG44ZvA9RxfJ4YfWyAVFXGJco6+AbJC4gwTc6 PeKyF4cjBFQcKu9CtTt+2QAkYaZQJC30M2ehAMTLQA8YfxfC5mf7TbmFGsChC0ceUsdy +9kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:date:subject:to:from; bh=ppMSE5MltF2iNC4/UVtreUH1k9wl0tZ1vG50dMWyM4M=; b=dYBZ/LgDv0J2ZIRJcqNzRTYrTPLtfQdzJB9vcXh8kv/zoq3HmSekJpUGUajT9jZZTC mDOo84AQXOcSgwZQPxya7KMEO6PUluo5qxRSLcUvrHoJKBaJtraBQeBCa0SLb4OqNZqu LNMn6pDJ2cULgxTZu5ZJhoPxl1WDC0fKZ8fWUQ9eMVUWy5VwviiNs0/SfZ7J5l2a4qcG am+fApthMti8Wt2UKxHNDf1LmAx0xRVDHlH6woc0p2KR7wuizJ2zlA8MCdjwPMq6QYWU 392qiKeYqY53vs7lihfgBkGr/kUSzGwfQQ2KNb6FeIkz8J9/WtKQMvOEMoBpIWhD/6Kj qpvQ== 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 m4si36256692otn.281.2020.01.06.03.13.09; Mon, 06 Jan 2020 03:13:22 -0800 (PST) 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 S1726677AbgAFLME (ORCPT + 99 others); Mon, 6 Jan 2020 06:12:04 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:40458 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726524AbgAFLL4 (ORCPT ); Mon, 6 Jan 2020 06:11:56 -0500 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 006B2Jr3093809 for ; Mon, 6 Jan 2020 06:11:54 -0500 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0b-001b2d01.pphosted.com with ESMTP id 2xb8s8eub1-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 06 Jan 2020 06:11:54 -0500 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 6 Jan 2020 11:11:52 -0000 Received: from b06avi18626390.portsmouth.uk.ibm.com (9.149.26.192) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 6 Jan 2020 11:11:51 -0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 006BB2KD46727546 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 6 Jan 2020 11:11:02 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C6B6C52063; Mon, 6 Jan 2020 11:11:49 +0000 (GMT) Received: from pratiks-thinkpad.in.ibm.com (unknown [9.124.31.198]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 3B00E52054; Mon, 6 Jan 2020 11:11:48 +0000 (GMT) From: Pratik Rajesh Sampat To: linux-kernel@vger.kernel.org, linuxppc-dev@ozlabs.org, mpe@ellerman.id.au, svaidy@linux.ibm.com, ego@linux.vnet.ibm.com, linuxram@us.ibm.com, psampat@linux.ibm.com, pratik.sampat@in.ibm.com, pratik.r.sampat@gmail.com Subject: [PATCH v2 3/3] powerpc/powernv: Parse device tree, population of SPR support Date: Mon, 6 Jan 2020 16:41:42 +0530 X-Mailer: git-send-email 2.24.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 20010611-0012-0000-0000-0000037ADCCB X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20010611-0013-0000-0000-000021B6F55C Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95,18.0.572 definitions=2020-01-06_04:2020-01-06,2020-01-06 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 malwarescore=0 spamscore=0 clxscore=1015 impostorscore=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=999 adultscore=0 mlxscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1910280000 definitions=main-2001060102 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Parse the device tree for nodes self-save, self-restore and populate support for the preferred SPRs based what was advertised by the device tree. Signed-off-by: Pratik Rajesh Sampat --- arch/powerpc/platforms/powernv/idle.c | 104 ++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/arch/powerpc/platforms/powernv/idle.c b/arch/powerpc/platforms/powernv/idle.c index d67d4d0b169b..e910ff40b7e6 100644 --- a/arch/powerpc/platforms/powernv/idle.c +++ b/arch/powerpc/platforms/powernv/idle.c @@ -1429,6 +1429,107 @@ static void __init pnv_probe_idle_states(void) supported_cpuidle_states |= pnv_idle_states[i].flags; } +/* + * Extracts and populates the self save or restore capabilities + * passed from the device tree node + */ +static int extract_save_restore_state_dt(struct device_node *np, int type) +{ + int nr_sprns = 0, i, bitmask_index; + int rc = 0; + u64 *temp_u64; + const char *state_prop; + u64 bit_pos; + + state_prop = of_get_property(np, "status", NULL); + if (!state_prop) { + pr_warn("opal: failed to find the active value for self save/restore node"); + return -EINVAL; + } + if (strncmp(state_prop, "disabled", 8) == 0) { + /* + * if the feature is not active, strip the preferred_sprs from + * that capability. + */ + if (type == SELF_RESTORE_TYPE) { + for (i = 0; i < nr_preferred_sprs; i++) { + preferred_sprs[i].supported_mode &= + ~SELF_RESTORE_STRICT; + } + } else { + for (i = 0; i < nr_preferred_sprs; i++) { + preferred_sprs[i].supported_mode &= + ~SELF_SAVE_STRICT; + } + } + return 0; + } + nr_sprns = of_property_count_u64_elems(np, "sprn-bitmask"); + if (nr_sprns <= 0) + return rc; + temp_u64 = kcalloc(nr_sprns, sizeof(u64), GFP_KERNEL); + if (of_property_read_u64_array(np, "sprn-bitmask", + temp_u64, nr_sprns)) { + pr_warn("cpuidle-powernv: failed to find registers in DT\n"); + kfree(temp_u64); + return -EINVAL; + } + /* + * Populate acknowledgment of support for the sprs in the global vector + * gotten by the registers supplied by the firmware. + * The registers are in a bitmask, bit index within + * that specifies the SPR + */ + for (i = 0; i < nr_preferred_sprs; i++) { + bitmask_index = preferred_sprs[i].spr / 64; + bit_pos = preferred_sprs[i].spr % 64; + if ((temp_u64[bitmask_index] & (1UL << bit_pos)) == 0) { + if (type == SELF_RESTORE_TYPE) + preferred_sprs[i].supported_mode &= + ~SELF_RESTORE_STRICT; + else + preferred_sprs[i].supported_mode &= + ~SELF_SAVE_STRICT; + continue; + } + if (type == SELF_RESTORE_TYPE) { + preferred_sprs[i].supported_mode |= + SELF_RESTORE_STRICT; + } else { + preferred_sprs[i].supported_mode |= + SELF_SAVE_STRICT; + } + } + + kfree(temp_u64); + return rc; +} + +static int pnv_parse_deepstate_dt(void) +{ + struct device_node *np, *np1; + int rc = 0; + + /* Self restore register population */ + np = of_find_node_by_path("/ibm,opal/power-mgt/self-restore"); + if (!np) { + pr_warn("opal: self restore Node not found"); + } else { + rc = extract_save_restore_state_dt(np, SELF_RESTORE_TYPE); + if (rc != 0) + return rc; + } + /* Self save register population */ + np1 = of_find_node_by_path("/ibm,opal/power-mgt/self-save"); + if (!np1) { + pr_warn("opal: self save Node not found"); + pr_warn("Legacy firmware. Assuming default self-restore support"); + } else { + rc = extract_save_restore_state_dt(np1, SELF_SAVE_TYPE); + } + return rc; +} + /* * This function parses device-tree and populates all the information * into pnv_idle_states structure. It also sets up nr_pnv_idle_states @@ -1577,6 +1678,9 @@ static int __init pnv_init_idle_states(void) return rc; pnv_probe_idle_states(); + rc = pnv_parse_deepstate_dt(); + if (rc) + return rc; if (!cpu_has_feature(CPU_FTR_ARCH_300)) { if (!(supported_cpuidle_states & OPAL_PM_SLEEP_ENABLED_ER1)) { power7_fastsleep_workaround_entry = false; -- 2.24.1