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 X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDC11C76190 for ; Tue, 23 Jul 2019 11:47:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B995021842 for ; Tue, 23 Jul 2019 11:47:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="XHQrWRNW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732093AbfGWLrf (ORCPT ); Tue, 23 Jul 2019 07:47:35 -0400 Received: from mail-vs1-f67.google.com ([209.85.217.67]:35681 "EHLO mail-vs1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732025AbfGWLre (ORCPT ); Tue, 23 Jul 2019 07:47:34 -0400 Received: by mail-vs1-f67.google.com with SMTP id u124so28593716vsu.2 for ; Tue, 23 Jul 2019 04:47:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=geUtppPrfRUg4NfGL34dbIx6S9V8ieUS4VVaIVpw7T8=; b=XHQrWRNWIaq7gVu+WqM3lUbu5At0fR8soQbqJWerzBGj3iq8Jh7FQC7HnYdnsrOw/2 4h/UOI2Ijk7FIguCbMP3BBZ1T4Rh3tPZWKVodUrEvqoPW+kWoqco+yb87JwscfUzvEFs zehINR8WOnJCyVs3GU2GnoHiLBKmYJuKJVoxAOSZnOyBJHjfqTxEd8Z69ehjQ93WugMB ZUw6rrD+qlQUD/hrb9TP3Xpm/L8iW5DfSAW+9zgbQNC12ySW9S83Rpw49/bhMFpjwvqq rwncfnzLh0DIOBSPVbSG0QHW6FSz+tpga99c6gZT3oNQJmKlt+iLpPliZjBAEhXiOfL0 /UDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=geUtppPrfRUg4NfGL34dbIx6S9V8ieUS4VVaIVpw7T8=; b=uNk6uJcs4UU0dUJ/BxcpS87krvqnRLiYeJvwPberKDtuZpGM3IjR4yYBHRBVBrpeEr HvXJXf0B++cYGkCBrdCeKg5A8diSII+Lxtw2RU5bVUaTbBD3rti4wCnyjjqQYhc3xj2l J0E/SUxcJgwGdXc153zhzycwwf/+LaV0l35C/Vtb3A0Uk2hXGvTq856quU8lBAAP60q4 fw477tXr7EV9ZWbegrHbiIXrVELV+aqbIja7aqHxaEwcRbR3XHi1t/SDU+jLv/LWsE9d qDn1C28ctqixGLiIGW4sfgFoL2K9v2pGn/OhxPnaBS9yGFkEXeKiBsfAoe8iAx71db+t IocQ== X-Gm-Message-State: APjAAAWeSruSVpSCWtlFZlgFjBeeku0TXLI2h5fd0w3PBLuaXqvEvLXv LjsZ7YxnOmpiGlLnLmeW8zUzCOQJPGaiEOwJ+JT4cQ== X-Google-Smtp-Source: APXvYqyQ7eltBtSxqPsnhCuQloUKpx1CQdA3jlUrwfbQpQPR8C3fB3pvMyrBd8baT9CeIxn12qkGDoiwZQb6qlcis+s= X-Received: by 2002:a67:ee16:: with SMTP id f22mr46522596vsp.191.1563882453209; Tue, 23 Jul 2019 04:47:33 -0700 (PDT) MIME-Version: 1.0 References: <20190722153745.32446-1-lorenzo.pieralisi@arm.com> <20190722153745.32446-5-lorenzo.pieralisi@arm.com> In-Reply-To: <20190722153745.32446-5-lorenzo.pieralisi@arm.com> From: Ulf Hansson Date: Tue, 23 Jul 2019 13:46:56 +0200 Message-ID: Subject: Re: [PATCH 4/6] ARM: psci: cpuidle: Introduce PSCI CPUidle driver To: Lorenzo Pieralisi Cc: Linux PM , Sudeep Holla , Daniel Lezcano , Mark Rutland , "Rafael J. Wysocki" , Catalin Marinas , Will Deacon , LKML , LAKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [...] > +++ b/drivers/cpuidle/cpuidle-psci.c > @@ -0,0 +1,150 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * PSCI CPU idle driver. > + * > + * Copyright (C) 2019 ARM Ltd. > + * Author: Lorenzo Pieralisi > + */ > + > +#define pr_fmt(fmt) "CPUidle PSCI: " fmt > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include This should go away, right? > + > +#include "dt_idle_states.h" > + > +static int psci_enter_idle_state(struct cpuidle_device *dev, > + struct cpuidle_driver *drv, int idx) > +{ > + return CPU_PM_CPU_IDLE_ENTER(psci_cpu_suspend_enter, idx); > +} > + > +static struct cpuidle_driver psci_idle_driver __initdata = { > + .name = "psci_idle", > + .owner = THIS_MODULE, > + /* > + * PSCI idle states relies on architectural WFI to > + * be represented as state index 0. > + */ > + .states[0] = { > + .enter = psci_enter_idle_state, > + .exit_latency = 1, > + .target_residency = 1, > + .power_usage = UINT_MAX, > + .name = "WFI", > + .desc = "ARM WFI", > + } > +}; > + > +static const struct of_device_id psci_idle_state_match[] __initconst = { > + { .compatible = "arm,idle-state", > + .data = psci_enter_idle_state }, > + { }, > +}; > + > +static int __init psci_idle_init_cpu(int cpu) > +{ > + struct cpuidle_driver *drv; > + struct device_node *cpu_node; > + const char *enable_method; > + int ret = 0; > + > + drv = kmemdup(&psci_idle_driver, sizeof(*drv), GFP_KERNEL); > + if (!drv) > + return -ENOMEM; > + > + drv->cpumask = (struct cpumask *)cpumask_of(cpu); > + > + cpu_node = of_get_cpu_node(cpu, NULL); > + if (!cpu_node) > + return -ENODEV; You should free drv in case of error here (goto out_kfree_drv; etc). > + > + /* > + * Check whether the enable-method for the cpu is PSCI, fail > + * if it is not. > + */ > + enable_method = of_get_property(cpu_node, "enable-method", NULL); > + if (!enable_method || (strcmp(enable_method, "psci"))) > + ret = -ENODEV; > + > + of_node_put(cpu_node); > + if (ret) > + return ret; You should free drv in case of error here (goto out_kfree_drv;). > + > + /* > + * Initialize idle states data, starting at index 1, since > + * by default idle state 0 is the quiescent state reached > + * by the cpu by executing the wfi instruction. > + * > + * If no DT idle states are detected (ret == 0) let the driver > + * initialization fail accordingly since there is no reason to > + * initialize the idle driver if only wfi is supported, the > + * default archictectural back-end already executes wfi > + * on idle entry. > + */ > + ret = dt_init_idle_driver(drv, psci_idle_state_match, 1); > + if (ret <= 0) { > + ret = ret ? : -ENODEV; > + goto out_kfree_drv; > + } > + > + /* > + * Initialize PSCI idle states. > + */ > + ret = psci_cpu_init_idle(cpu); > + if (ret) { > + pr_err("CPU %d failed to PSCI idle\n", cpu); > + goto out_kfree_drv; > + } > + > + ret = cpuidle_register(drv, NULL); > + if (ret) > + goto out_kfree_drv; > + > + return 0; > + > +out_kfree_drv: > + kfree(drv); > + return ret; > +} > + [...] Kind regards Uffe