From patchwork Mon May 13 19:22:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 164062 Delivered-To: patches@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1728532ili; Mon, 13 May 2019 12:23:30 -0700 (PDT) X-Received: by 2002:a2e:9ec6:: with SMTP id h6mr12343388ljk.169.1557775410269; Mon, 13 May 2019 12:23:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557775410; cv=none; d=google.com; s=arc-20160816; b=UeQ/xnMsAVoDROH5qG1GNzTPaeanNQLvOFzEaLJYccq9yjv3UuQ09oAJrs7UuVK9qe N8mCcQiZRnQd5HSo1ZlrkkF9kGyKXNU4EIGJqOuro4FMllYCnw6MothOIi1uu71FPkgw cvoaZTFpAXB3RkofdhDmvQraKwmoZ4lJXZGlOQwCe0f49t6ayOe/Z6+O8K1kXPgZifvh AHUWI898p6rdMBe9ijwjgd3Qlv5kUhZXl5Q8v9CAhsVutmKmKCgd2wRM7V/Q64Cwg6Od j3pnwGkUT60mmQZSixGQnEJv8hf5RS4JMktJen+K5aHYib4/lltqIJkjk9obM3xJCpEW zRiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7mMRJh0gRWk8jRKSu7vpJTGJ6ww/FK+bFoVvoMzjgck=; b=L1TwBIlzJ+3+pWQEAg+3DLsGOOSGO8jC4AO3MdhTTc6YcfXMMkQqeWwt0n/lsSawcE bmJs9K0oHu0FCWrl+0HAToNoVkPgh4yb8VnS8JKpHOClRbK2zlvvMaYl6JXeyJntIUoj zYrLCN9lHejI5mBXq4ZPTsnaGJSs3jF/JMEgEfyLbbwiBQDWI3sLOenpA+MStZz2AVGk cXNERDc63VQe5B8OppAjZKuUFgpMLemqyqZ9ogVb+MCgP4qbswR2nl4ytgnCV3fwad1b uo3LOUWFrElNuU6thoaiIpARV4pXkEysqwoJCZ99zPA/MEn7IR+BmKUDhpcdKzH+4aXy d6iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A5Wrb60x; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id t6sor2987506ljj.15.2019.05.13.12.23.30 for (Google Transport Security); Mon, 13 May 2019 12:23:30 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A5Wrb60x; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7mMRJh0gRWk8jRKSu7vpJTGJ6ww/FK+bFoVvoMzjgck=; b=A5Wrb60xziILjw5xMgQgTTamMl9xJY2MhOSpDPLTAf/3EQCP+lf+7yig/Ph/N48Hs+ 5eISRFo4PakItBUPivivio9sRWxxOcKf9wZko/ylG4GFm+PHhBbtsOQFhs6a2EYmk6cf d08V0bhI77Ip2AT10wAzzGYunJYYv1Xq6bLSZK+0AvF8kKHSnNeeoT7ASAv0aJjZ/uXa pAh3Vd1UJMx+yB0pcoGTGuiTiECq7yRcyQftboHCRgguQn1fjPxSH/PuwhRrzWxMWrOP vkkAGabM1BZQ68YI0gr+vhbHfVr1udpWSAPl8raFY3py7bW24MK4MzWkC91WgHCON7Du frtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7mMRJh0gRWk8jRKSu7vpJTGJ6ww/FK+bFoVvoMzjgck=; b=EXBL3xrugSXTqUuR4SdJ3nx4A8npmGqcJJmg9TwZ3Htkuf2UuX92mLez/z9sKdqbzR 3ZqnjnwI2Nf/VyGrOUjVbzcXM+I6ny4HwfTlU4XwrJnYKszTP7bn/U0mKibNtYev0MlK fSf8A+WEBlpaxD9U9Emv1yrDKhA3f04iqj+UGGzCBQNFtLL/uzrtkV8IdI/2PNgd6JuO H5lCQ0nr8afC5FRaZ1viMxeos+WWJGicoemj3aVi5DHe1mRPxecTeGElM6Fn8RutfEmc z2ZQYAZoHVM8g8QhG39GZObXExLDTVZZmwlHid8eaCroe2ApBDvYPCW9sQXzeOhbQjKq HVXw== X-Gm-Message-State: APjAAAXl3l+d/Jeu06IoOgtfaN1Llweep7MeL4htc2RLhthl7uglytSr afw+DmwbIJ7UGS3OQmFDO2LPZeEe X-Google-Smtp-Source: APXvYqxf9UXPo2PbATF2Ej4O/JEKsCNTcYfsKPhGKIQE6BXSznQnuXwlAcye5xuHinSMJfMHW3VIvg== X-Received: by 2002:a2e:8954:: with SMTP id b20mr4530759ljk.10.1557775409921; Mon, 13 May 2019 12:23:29 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id q21sm3449365lfa.84.2019.05.13.12.23.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2019 12:23:29 -0700 (PDT) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , linux-arm-kernel@lists.infradead.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , "Raju P . L . S . S . S . N" , Amit Kucheria , Bjorn Andersson , Stephen Boyd , Niklas Cassel , Tony Lindgren , Kevin Hilman , Lina Iyer , Viresh Kumar , Vincent Guittot , Geert Uytterhoeven , Souvik Chakravarty , linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Ulf Hansson Subject: [PATCH 13/18] drivers: firmware: psci: Attach the CPU's device to its PM domain Date: Mon, 13 May 2019 21:22:55 +0200 Message-Id: <20190513192300.653-14-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190513192300.653-1-ulf.hansson@linaro.org> References: <20190513192300.653-1-ulf.hansson@linaro.org> In order to allow the CPU to be power managed through a potential PM domain and the corresponding topology, it needs to be attached to it. For that reason, check if the PM domain data structures have been initiated for PSCI and if so, let's try to attach the CPU device to its PM domain. However, before attaching the CPU to its PM domain, we need to check whether the PSCI firmware supports OS initiated mode or not. If that isn't the case, we rely solely on the cpuidle framework to deal with the idle state selection, which means we need to parse DT and convert the hierarchical described domain idle states into regular cpuidle states, hence let's do that. Signed-off-by: Ulf Hansson --- Changes: - Adapt to updated psci_dt_attach_cpu() helper, as it now returns a struct device * instead of an int. - Create a per CPU struct, to store the relevant PSCI cpuidle data. --- drivers/firmware/psci/psci.c | 46 +++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 8 deletions(-) -- 2.17.1 diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index 28745234b53f..54e23d4ed0ea 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -295,7 +295,13 @@ static int __init psci_features(u32 psci_func_id) } #ifdef CONFIG_CPU_IDLE -static DEFINE_PER_CPU_READ_MOSTLY(u32 *, psci_power_state); + +struct psci_cpuidle_data { + u32 *psci_states; + struct device *dev; +}; + +static DEFINE_PER_CPU_READ_MOSTLY(struct psci_cpuidle_data, psci_cpuidle_data); static DEFINE_PER_CPU(u32, domain_state); static bool psci_dt_topology; @@ -332,8 +338,9 @@ static int psci_dt_cpu_init_idle(struct cpuidle_driver *drv, int i, ret = 0, num_state_nodes = drv->state_count - 1; u32 *psci_states; struct device_node *state_node; + struct psci_cpuidle_data *data = per_cpu_ptr(&psci_cpuidle_data, cpu); - psci_states = kcalloc(num_state_nodes, sizeof(*psci_states), + psci_states = kcalloc(CPUIDLE_STATE_MAX, sizeof(*psci_states), GFP_KERNEL); if (!psci_states) return -ENOMEM; @@ -357,8 +364,31 @@ static int psci_dt_cpu_init_idle(struct cpuidle_driver *drv, goto free_mem; } - /* Idle states parsed correctly, initialize per-cpu pointer */ - per_cpu(psci_power_state, cpu) = psci_states; + /* + * If the hierarchical CPU topology is used, let's attach the CPU device + * to its corresponding PM domain. If OSI mode isn't supported, convert + * the additional domain idle states from the hierarchical DT layout + * into regular flattened cpuidle states, as to let cpuidle manage them. + */ + if (psci_dt_topology) { + struct device *dev; + + if (!psci_has_osi_support()) { + ret = psci_dt_pm_domains_parse_states(drv, cpu_node, + psci_states); + if (ret) + goto free_mem; + } + + dev = psci_dt_attach_cpu(cpu); + if (IS_ERR_OR_NULL(dev)) + goto free_mem; + + data->dev = dev; + } + + /* Idle states parsed correctly, store them in the per-cpu struct. */ + data->psci_states = psci_states; return 0; free_mem: @@ -403,8 +433,8 @@ static int __maybe_unused psci_acpi_cpu_init_idle(unsigned int cpu) } psci_states[i] = state; } - /* Idle states parsed correctly, initialize per-cpu pointer */ - per_cpu(psci_power_state, cpu) = psci_states; + /* Idle states parsed correctly, store them in the per-cpu struct. */ + per_cpu(psci_cpuidle_data.psci_states, cpu) = psci_states; return 0; } #else @@ -442,7 +472,7 @@ int psci_cpu_init_idle(struct cpuidle_driver *drv, unsigned int cpu) static int psci_suspend_finisher(unsigned long index) { - u32 *state = __this_cpu_read(psci_power_state); + u32 *state = __this_cpu_read(psci_cpuidle_data.psci_states); u32 composite_state = state[index - 1] | psci_get_domain_state(); return psci_ops.cpu_suspend(composite_state, __pa_symbol(cpu_resume)); @@ -451,7 +481,7 @@ static int psci_suspend_finisher(unsigned long index) int psci_cpu_suspend_enter(unsigned long index) { int ret; - u32 *state = __this_cpu_read(psci_power_state); + u32 *state = __this_cpu_read(psci_cpuidle_data.psci_states); u32 composite_state = state[index - 1] | psci_get_domain_state(); /*