Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp3304970ybh; Mon, 16 Mar 2020 20:30:55 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtWx4ZIlvTqRy1uVDbfefahlPcDvmzqSrtd9FNqkJiNISNSr5FxZ9OWu3u8FajfgBWGpk54 X-Received: by 2002:a05:6830:1285:: with SMTP id z5mr2030199otp.241.1584415855747; Mon, 16 Mar 2020 20:30:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584415855; cv=none; d=google.com; s=arc-20160816; b=iFN2HAL7a4sRn7DaoJYLExWctHUuK+Y0N8sDlNB/Ss73iLRrRPGqWxLI3gObsMOlx/ y8wKcI2npkI7Hmz2OjT0GcmjRWeEz+KiSXki9gQGw40ziw9lCXFOWgRbXpyXLKiQM63M CryG5bP/4t/nCIi8kUhgJn1ERH1OO6PO03MkqiRTDnF/hrQ+ChiMkyxzxFpnnqMh6cHN H/Y9rMtf5y8g/ZpfqVdbzXPQBjUnSwO1YJc4746t6ofz/mWtvSNY0TzXeXff1RTV6XF3 k6e6Ycs/6US7LPOoWKfekus/4Z/eiSgy6hzHGWzodz/+HsxKTYhxpJ1CHWAMcqQEGmIC Uq8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:to:from:dkim-signature; bh=B8aD1ZlYrv0Z6uKQTIR5YVv8tVoOQbIMQdrTACIRKzU=; b=hKCJcwlPtszRLL/Cgqg2vi0Xw6NhnM6P1jqK/3mBqTW8JFE6g4jNTeGq9L6VhPcWnN ZVE8nE4YlgCx2bOEf2OfcHnTOLbDcYlQ6Jc2SM6CZ281nc9vFRvexdtlAN++mcNsliOR hkpUrdDbu4UOsc/5+6kTEtP3GOip1xEUTioq3aIVKbW9/2QeNap9UlDKIWnOEQ+FHB3c dKKWpr6a7T88Sz0tl4fD72FUus+06c0JN6L22TacdqPLjlLdd80Tnxkb6M1Sk1mxf26S /SDx7te2eqV9ZrlZkbUDged2bUwP/IFMpDg2yhlRJxtVX6b1nhqhbqe1PTkBxaVlNQK2 ADsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=W87B5m7H; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p5si1120317otf.152.2020.03.16.20.30.43; Mon, 16 Mar 2020 20:30:55 -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; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=W87B5m7H; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726838AbgCQDNc (ORCPT + 99 others); Mon, 16 Mar 2020 23:13:32 -0400 Received: from bilbo.ozlabs.org ([203.11.71.1]:51033 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726803AbgCQDNb (ORCPT ); Mon, 16 Mar 2020 23:13:31 -0400 Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 48hJCY0Zyrz9sPR; Tue, 17 Mar 2020 14:13:29 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ellerman.id.au; s=201909; t=1584414809; bh=ezGsF1UeoLbn/OJ/iZaLkSdfEqbF8RmQREJ6TMA/QYo=; h=From:To:Subject:In-Reply-To:References:Date:From; b=W87B5m7Hhhtjv0k2eyuuOmxJycvegwOUDjOcCYG9PYelJBtwKoOQGGcNR2hXNFYDo 7GKZzyDKdb4tyRbGz0+NNKHnwx2Phrry6sOIP7umvhiL57Vnu6djkfHYf5rCaPa+Eu HbapjvBfS2mdE9kJo0UUx0AzgpOcqZjTyJVOkSDjivQlz223yt1djIBsKegGnuyjhG QGmtSrdAe/O8A2TT0XOVEnc90ZnJpuSuwCBxw36vXVAaSL+hE9myqF+AFW60lAc+ke G7R2EbQqc4XmIPrh/j9PDvs1HBKhKGNFpA8cNRvjapmjJZqUolFzRDa7vFybOn2bPI sig7V7ZCRl5NA== From: Michael Ellerman To: Pratik Rajesh Sampat , linux-kernel@vger.kernel.org, linuxppc-dev@ozlabs.org, svaidy@linux.ibm.com, ego@linux.vnet.ibm.com, linuxram@us.ibm.com, pratik.sampat@in.ibm.com, psampat@linux.ibm.com, pratik.r.sampat@gmail.com Subject: Re: [PATCH v4 3/3] powerpc/powernv: Parse device tree, population of SPR support In-Reply-To: <1f5138b5080606804162b0a7cf20c134589b96b1.1581505210.git.psampat@linux.ibm.com> References: <1f5138b5080606804162b0a7cf20c134589b96b1.1581505210.git.psampat@linux.ibm.com> Date: Tue, 17 Mar 2020 14:13:31 +1100 Message-ID: <87tv2nptb8.fsf@mpe.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Pratik Rajesh Sampat writes: > 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. These should be documented in: Documentation/devicetree/bindings/powerpc/opal/power-mgt.txt > diff --git a/arch/powerpc/platforms/powernv/idle.c b/arch/powerpc/platforms/powernv/idle.c > index 97aeb45e897b..27dfadf609e8 100644 > --- a/arch/powerpc/platforms/powernv/idle.c > +++ b/arch/powerpc/platforms/powernv/idle.c > @@ -1436,6 +1436,85 @@ 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; > + u64 bit_pos; > + > + nr_sprns = of_property_count_u64_elems(np, "sprn-bitmask"); > + if (nr_sprns <= 0) > + return rc; Using <= 0 means zero SPRs is treated by success as the caller, is that intended? If so a comment would be appropriate. > + 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; This is basically a hand coded bitmap, see eg. BIT_WORD(), BIT_MASK() etc. I don't think there's an easy way to convert temp_u64 into a proper bitmap, so it's probably not worth doing that. But at least use the macros. > + 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 *sr_np, *ss_np; You never use these concurrently AFAICS, so you could just have a single *np. > + int rc = 0, i; > + > + /* Self restore register population */ > + sr_np = of_find_node_by_path("/ibm,opal/power-mgt/self-restore"); I know the existing idle code uses of_find_node_by_path(), but that's because it's old and crufty. Please don't add new searches by path. You should be searching by compatible. > + if (!sr_np) { > + pr_warn("opal: self restore Node not found"); This warning and the others below will fire on all existing firmware versions, which is not OK. > + } else { > + rc = extract_save_restore_state_dt(sr_np, SELF_RESTORE_TYPE); > + if (rc != 0) > + return rc; > + } > + /* Self save register population */ > + ss_np = of_find_node_by_path("/ibm,opal/power-mgt/self-save"); > + if (!ss_np) { > + pr_warn("opal: self save Node not found"); > + pr_warn("Legacy firmware. Assuming default self-restore support"); > + for (i = 0; i < nr_preferred_sprs; i++) > + preferred_sprs[i].supported_mode &= ~SELF_SAVE_STRICT; > + } else { > + rc = extract_save_restore_state_dt(ss_np, SELF_SAVE_TYPE); > + } > + return rc; You're leaking references on all the device_nodes in here, you need of_node_put() before exiting. > +} cheers