Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp453936imm; Tue, 22 May 2018 23:12:58 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpIvcGP5M7KDR2tAzlTGoW+IfV5eugE5IhZD0tSnXWQtqnACpTPpbFJ42raTL8vi8ELJ8HT X-Received: by 2002:a17:902:3a5:: with SMTP id d34-v6mr1616896pld.103.1527055978779; Tue, 22 May 2018 23:12:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527055978; cv=none; d=google.com; s=arc-20160816; b=vU8XhrozgQimN5bpFLebK3OXo/qkA2TuHZ5YrK+OIczyDMKoJtJPz/WWRABAB9PnNg Mm75BL/NFDSZCJ/2M80fT1uUupXWknzFLl0Gb6zcrGG2Qz1iA397BNzasZBKcWkdQMY5 feb0zBMY/ktwnVe2dCf5O7+1Hb+0cq7XNR3fob3hx541YrLoPRhGuawtls9O+orGzuch n8Vs1ARr3hOMXkmDQKu/w6cBVp70hW8yMB8rwhA6m+mOLWrW3FpzeHsdZ+CZEVpw/OXv 7TnBXM5fJutVpEkRukra8aDqIzqEJhOSWGML7C1J17DRynZyWuJfW8S0eyGqeUaiAFo3 fJlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=tlthKllUTdhBokjd3o2f/gsjmqPvYm8PdZPPArWTdW8=; b=Xc+G3YUN6uRForS9rMiui6Af3yXQgpCkAcj79M+3nBgYC+4ooX2r0ZA2kwZKbbz9F3 k0LkBd3jtjF9gd9lya2tmBR4OWa2jkUjjg8NXsBH3jovc2xe+rX5NFrQ2i89v3aoSdjW bW1JoniFHZ1QzkKTplYG8CHGnZm73Tb2P2faiYjjA8h0YTX3SJYRE+35g0Mamn0CdgTq ccY774RKPUWYLC448rNsemCgKPpqYMsxQP+jQdAmA7cRIwk6/TWMTaW0sJpNUsJRKzhl N89NiD+Kc3YKmSmE75e79MGziRQ+e4a3twK4kuPAVw/HlymFi1veUDFzT3X35o0KLgUO OLDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A0XAXz2y; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y62-v6si18430003pfg.246.2018.05.22.23.12.42; Tue, 22 May 2018 23:12:58 -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=@linaro.org header.s=google header.b=A0XAXz2y; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753996AbeEWGMb (ORCPT + 99 others); Wed, 23 May 2018 02:12:31 -0400 Received: from mail-it0-f66.google.com ([209.85.214.66]:53836 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753932AbeEWGM3 (ORCPT ); Wed, 23 May 2018 02:12:29 -0400 Received: by mail-it0-f66.google.com with SMTP id n64-v6so2972713itb.3 for ; Tue, 22 May 2018 23:12:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=tlthKllUTdhBokjd3o2f/gsjmqPvYm8PdZPPArWTdW8=; b=A0XAXz2yzkswVliLak48HAHF/S98I4tUAWBh1HlB2rH6hNewPk5Jwj2dDt4RtkGt60 KOj0ve3w6EQ8xpGtbaXXADZx/LpKuXNK+aIKBHELWzmBPwbPgVS+6SdTq2510KjLCEWH /iNGUVx4VPGE9Vnvmt5Yuo+OBkVat8e9wa94Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=tlthKllUTdhBokjd3o2f/gsjmqPvYm8PdZPPArWTdW8=; b=maxQQkoq2Z1RFfa/bNKEKQEnkOhbJkLeY5afhViUlhm0tXr5dDpg+a3Y6+MQ5uUTmy kwLiwL9SjqAzrMB+EXuyijbjOXgowHj/npNTKi+6RjuGsW1jaW4lI2UNZ2v6hWoA12m7 tPJBZH8tck3RHEtidD9T3KBk5ZqPLqnvGjOYwAFYI16jAJ291Qq9nP7Vx4fImwguaInq wtKEix3sMCP6gMHGliztsnHMmbUyhrnTQ1ARNFS9gtQtLuzTKPWwRlt8zw2823DuDyAy RGcJtIM4hnO6FqZFAbHOVWXwLvZfJFvt03avsxSm0vjBhJkr/jbEJ//dtJHy//4xRuj0 ni0g== X-Gm-Message-State: ALKqPwervfvgX/9vuCg7kBCjYzLP6nkg9GHQx5K+eGf6tF51rbr/DqND 4I4hflgk8VQqaJcNNKn1b7c+B2AstnZ9GpfclZQBfg== X-Received: by 2002:a24:248f:: with SMTP id f137-v6mr3806235ita.55.1527055948219; Tue, 22 May 2018 23:12:28 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a02:7353:0:0:0:0:0 with HTTP; Tue, 22 May 2018 23:12:27 -0700 (PDT) In-Reply-To: <51f7de26-579a-8b9e-4e79-f4eee923ab38@codeaurora.org> References: <1526639490-12167-1-git-send-email-ulf.hansson@linaro.org> <1526639490-12167-9-git-send-email-ulf.hansson@linaro.org> <5a79d3a2-d090-645b-da69-524b7e7a4d90@nvidia.com> <51f7de26-579a-8b9e-4e79-f4eee923ab38@codeaurora.org> From: Ulf Hansson Date: Wed, 23 May 2018 08:12:27 +0200 Message-ID: Subject: Re: [PATCH 8/9] PM / Domains: Add support for multi PM domains per device to genpd To: Rajendra Nayak , Jon Hunter Cc: Geert Uytterhoeven , Linux PM , Greg Kroah-Hartman , Kevin Hilman , "Rafael J . Wysocki" , Linux Kernel Mailing List , Todor Tomov , Viresh Kumar , linux-tegra@vger.kernel.org, Vincent Guittot , Linux ARM 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 Rajendra, Jon, On 23 May 2018 at 06:51, Rajendra Nayak wrote: > > > On 05/23/2018 02:25 AM, Jon Hunter wrote: >> >> On 22/05/18 15:47, Ulf Hansson wrote: >>> [...] >>> >>>>> >>>>> +/** >>>>> + * genpd_dev_pm_attach_by_id() - Attach a device to one of its PM domain. >>>>> + * @dev: Device to attach. >>>>> + * @index: The index of the PM domain. >>>>> + * >>>>> + * Parse device's OF node to find a PM domain specifier at the provided @index. >>>>> + * If such is found, allocates a new device and attaches it to retrieved >>>>> + * pm_domain ops. >>>>> + * >>>>> + * Returns the allocated device if successfully attached PM domain, NULL when >>>>> + * the device don't need a PM domain or have a single PM domain, else PTR_ERR() >>>>> + * in case of failures. Note that if a power-domain exists for the device, but >>>>> + * cannot be found or turned on, then return PTR_ERR(-EPROBE_DEFER) to ensure >>>>> + * that the device is not probed and to re-try again later. >>>>> + */ >>>>> +struct device *genpd_dev_pm_attach_by_id(struct device *dev, >>>>> + unsigned int index) >>>>> +{ >>>>> + struct device *genpd_dev; >>>>> + int num_domains; >>>>> + int ret; >>>>> + >>>>> + if (!dev->of_node) >>>>> + return NULL; >>>>> + >>>>> + /* Deal only with devices using multiple PM domains. */ >>>>> + num_domains = of_count_phandle_with_args(dev->of_node, "power-domains", >>>>> + "#power-domain-cells"); >>>>> + if (num_domains < 2 || index >= num_domains) >>>>> + return NULL; >>>>> + >>>>> + /* Allocate and register device on the genpd bus. */ >>>>> + genpd_dev = kzalloc(sizeof(*genpd_dev), GFP_KERNEL); >>>>> + if (!genpd_dev) >>>>> + return ERR_PTR(-ENOMEM); >>>>> + >>>>> + dev_set_name(genpd_dev, "genpd:%u:%s", index, dev_name(dev)); >>>>> + genpd_dev->bus = &genpd_bus_type; >>>>> + genpd_dev->release = genpd_release_dev; >>>>> + >>>>> + ret = device_register(genpd_dev); >>>>> + if (ret) { >>>>> + kfree(genpd_dev); >>>>> + return ERR_PTR(ret); >>>>> + } >>>>> + >>>>> + /* Try to attach the device to the PM domain at the specified index. */ >>>>> + ret = __genpd_dev_pm_attach(genpd_dev, dev->of_node, index); >>>>> + if (ret < 1) { >>>>> + device_unregister(genpd_dev); >>>>> + return ret ? ERR_PTR(ret) : NULL; >>>>> + } >>>>> + >>>>> + pm_runtime_set_active(genpd_dev); >>>>> + pm_runtime_enable(genpd_dev); >>>>> + >>>>> + return genpd_dev; >>>>> +} >>>>> +EXPORT_SYMBOL_GPL(genpd_dev_pm_attach_by_id); >>>> >>>> Thanks for sending this. Believe it or not this has still been on my to-do list >>>> and so we definitely need a solution for Tegra. >>>> >>>> Looking at the above it appears that additional power-domains exposed as devices >>>> to the client device. So I assume that this means that the drivers for devices >>>> with multiple power-domains will need to call RPM APIs for each of these >>>> additional power-domains. Is that correct? >>> >>> They can, but should not! >>> >>> Instead, the driver shall use device_link_add() and device_link_del(), >>> dynamically, depending on what PM domain that their original device >>> needs for the current running use case. >>> >>> In that way, they keep existing runtime PM deployment, operating on >>> its original device. >> >> OK, sounds good. Any reason why the linking cannot be handled by the above API? Is there a use-case where you would not want it linked? > > I am guessing the linking is what would give the driver the ability to decide which subset of powerdomains it actually wants to control > at any point using runtime PM. If we have cases wherein the driver would want to turn on/off _all_ its associated powerdomains _always_ > then a default linking of all would help. First, I think we need to decide on *where* the linking should be done, not at both places, as that would just mess up synchronization of who is responsible for calling the device_link_del() at detach. Second, It would in principle be fine to call device_link_add() and device_link_del() as a part of the attach/detach APIs. However, there is a downside to such solution, which would be that the driver then needs call the detach API, just to do device_link_del(). Of course then it would also needs to call the attach API later if/when needed. Doing this adds unnecessary overhead - comparing to just let the driver call device_link_add|del() when needed. On the upside, yes, it would put less burden on the drivers as it then only needs to care about using one set of functions. Which solution do you prefer? Kind regards Uffe