From patchwork Thu Apr 25 09:04:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 162834 Delivered-To: patches@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp1671785jan; Thu, 25 Apr 2019 02:04:35 -0700 (PDT) X-Received: by 2002:a2e:9348:: with SMTP id m8mr1511804ljh.23.1556183075523; Thu, 25 Apr 2019 02:04:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556183075; cv=none; d=google.com; s=arc-20160816; b=sWf08vcvZxxjIeepp7DkyNlU0TjIX3+pJHE3cCrwMCmB8T0MnxtrkrKB8RZISMoKuC kzmzUeRRxWwHu6uv6KSvAjdk8wU4ZGvETGh/69Jsx3K8/Lo48UWAC/O4mSOMbdnMGUHm ESSBxwzSv8nodZ/MXP5Ak2WSPlPnm3LNTrzWWZwzzRBEhyko2p6us218Bc7+NWp8kgLF wFJGjwPfZF69LF0Ez2RUNGeEoTfRXNBSY8SNldsvB8P1K8Ftb+hQN9w/GtppV4+XckZ1 wkUYd1Fv0H9gt5bGWUEpZH7Uq8Dol2POTVJTp0+n0dyC5zJOd8FyOro4ZrJU4rL0Hfth Xo2w== 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=+vO/H92ltJAN7Sc2E9gRf3gzSgRQawDyXMnQqUjpfmc=; b=aebBhdYYppeRdFy1uSpHW29w43K70WQVP0JwrWDaKm+39YfHJuKBzC1+vOrbz1oisM E8tF/oNqzCFie6uFSU/+cBdF/QVgp9K6oZHZvjQTcCtL9rp7xpHFLhT9VgWgy9hNoY9r IdONbGj33gKj/SW+qUa3MI7cYMgun3xe7x8X+z6cDxyUG22X9TSjFfOMcNPyT8MXhcdP 0WN1Nxjpr0kuLeYVzcNP1tHG3Ixp2vOjKmk4njW05rhTyKYRh1PFkxpPCLy8UaEpyAlm 2OUbDai7hgJ90o8AQqXMLJ1Rx9rDIdm8I8qthfKRYo2i6Mi/IrxJH+3xmjQIMtHXLVbO tndw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yC5dRReB; 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 15sor4571771lfb.21.2019.04.25.02.04.35 for (Google Transport Security); Thu, 25 Apr 2019 02:04:35 -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=yC5dRReB; 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=+vO/H92ltJAN7Sc2E9gRf3gzSgRQawDyXMnQqUjpfmc=; b=yC5dRReBJJI91/9zHctiDbBK59FaHXwQvaYJBTJebSGUCyuzX/iD6Buf3sCzCASEqs NmeLl71rKWz3ChLuH3k8bRaYGUa9bkODHy531ZOa+0dPu6nMNXfg6d/fMpKJT1VJf0SS igBn8+5X2lfYrp6Y3N2KYQklvlU/tpTdiCLvl78TcSITlhpLRvJ0WVshNKmVCovDJsBY r3K73wXOzmWETpoYQVNMLcSKBlpxpmQ31bh9p14BxZnG0PHtdHILwcx4IjLygixHEQU8 XcFxD9itxPzWX8dF3ZUDS1TuceFbeyme+Mg1cA37EQog0ybfvN9XnIbN3mjxxh7t25wf +Mfw== 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=+vO/H92ltJAN7Sc2E9gRf3gzSgRQawDyXMnQqUjpfmc=; b=nKS9Y4P+unzfx7cDG4TVjGvofdNs5/K94jOaEk0zP+EzNVQETDay2vtcQ7CGbw3FhZ iMdgH9FQrur9ZqoHB5MIh6xmMQs2lsqju07Dm9HPVE+vOVaVjP+kFl5oKwv45RHxy2r+ KYD3fPl4d1GMnQeIb7jFLNqNrZD7i8X5TBzfdHOhzhPohFUuZTyX49JODmG8J0e/gH0z 28m2Fxqo65KcrOl0Rns5D5kiY/uOwkvlhAhhtcBf/UwGyFSuaXZlAorrrm9bNoEkhbBn Bfa6bOSxTz9dTUCe9VlbIIljHfxdiKc4jLXHFaLZB1jucEZctPR5/+ohKDjmX4EuJtxq 7MMQ== X-Gm-Message-State: APjAAAVfTwljb8NqSnG/hKNAXw9ffuUTC6T71tuCfHLk6V2JqfCV0+VV F0gLCetxwNi6bNOyJ/kYIVXC4WU/ X-Google-Smtp-Source: APXvYqzk3cC5yBbK4/5Bi8xvesd2ymcePZ07SfwUeHdRpIavXWYij45EEO0csvL4Ao/ccnoOMwwZSA== X-Received: by 2002:ac2:5088:: with SMTP id f8mr21568780lfm.107.1556183075155; Thu, 25 Apr 2019 02:04:35 -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 v26sm4517353lja.60.2019.04.25.02.04.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Apr 2019 02:04:34 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Ulf Hansson , Daniel Lezcano , "Raju P . L . S . S . S . N" , Stephen Boyd , Tony Lindgren , Kevin Hilman , Lina Iyer , Rajendra Nayak , Viresh Kumar , Niklas Cassel , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 4/4] PM / Domains: Allow to attach a CPU via genpd_dev_pm_attach_by_id|name() Date: Thu, 25 Apr 2019 11:04:13 +0200 Message-Id: <20190425090413.10700-5-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190425090413.10700-1-ulf.hansson@linaro.org> References: <20190425090413.10700-1-ulf.hansson@linaro.org> Attaching a device via genpd_dev_pm_attach_by_id|name() makes genpd to allocate a virtual device that it attaches instead. This leads to a problem in case the base device belongs to a CPU. More precisely, it means genpd_get_cpu() compares against the virtual device, thus it fails to find a matching CPU device. Address this limitation, by passing the base device to genpd_get_cpu() rather than the virtual device. Moreover, to deal with detach correctly from genpd_remove_device(), let's store the CPU number in the struct generic_pm_domain_data, as to be able to clear the corresponding bit in the cpumask for the genpd. Signed-off-by: Ulf Hansson --- drivers/base/power/domain.c | 20 ++++++++++---------- include/linux/pm_domain.h | 1 + 2 files changed, 11 insertions(+), 10 deletions(-) -- 2.17.1 Acked-by: Viresh Kumar diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index da1c99178943..3d899e8abd58 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1499,10 +1499,11 @@ static int genpd_get_cpu(struct generic_pm_domain *genpd, struct device *dev) return -1; } -static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev) +static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, + struct device *base_dev) { struct generic_pm_domain_data *gpd_data; - int ret, cpu; + int ret; dev_dbg(dev, "%s()\n", __func__); @@ -1513,7 +1514,7 @@ static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev) if (IS_ERR(gpd_data)) return PTR_ERR(gpd_data); - cpu = genpd_get_cpu(genpd, dev); + gpd_data->cpu = genpd_get_cpu(genpd, base_dev); ret = genpd->attach_dev ? genpd->attach_dev(genpd, dev) : 0; if (ret) @@ -1521,7 +1522,7 @@ static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev) genpd_lock(genpd); - genpd_set_cpumask(genpd, cpu); + genpd_set_cpumask(genpd, gpd_data->cpu); dev_pm_domain_set(dev, &genpd->domain); genpd->device_count++; @@ -1549,7 +1550,7 @@ int pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev) int ret; mutex_lock(&gpd_list_lock); - ret = genpd_add_device(genpd, dev); + ret = genpd_add_device(genpd, dev, dev); mutex_unlock(&gpd_list_lock); return ret; @@ -1561,14 +1562,13 @@ static int genpd_remove_device(struct generic_pm_domain *genpd, { struct generic_pm_domain_data *gpd_data; struct pm_domain_data *pdd; - int cpu, ret = 0; + int ret = 0; dev_dbg(dev, "%s()\n", __func__); pdd = dev->power.subsys_data->domain_data; gpd_data = to_gpd_data(pdd); dev_pm_qos_remove_notifier(dev, &gpd_data->nb); - cpu = genpd_get_cpu(genpd, dev); genpd_lock(genpd); @@ -1580,7 +1580,7 @@ static int genpd_remove_device(struct generic_pm_domain *genpd, genpd->device_count--; genpd->max_off_time_changed = true; - genpd_clear_cpumask(genpd, cpu); + genpd_clear_cpumask(genpd, gpd_data->cpu); dev_pm_domain_set(dev, NULL); list_del_init(&pdd->list_node); @@ -2256,7 +2256,7 @@ int of_genpd_add_device(struct of_phandle_args *genpdspec, struct device *dev) goto out; } - ret = genpd_add_device(genpd, dev); + ret = genpd_add_device(genpd, dev, dev); out: mutex_unlock(&gpd_list_lock); @@ -2426,7 +2426,7 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev, dev_dbg(dev, "adding to PM domain %s\n", pd->name); - ret = genpd_add_device(pd, dev); + ret = genpd_add_device(pd, dev, base_dev); mutex_unlock(&gpd_list_lock); if (ret < 0) { diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index bc82e74560ee..0e8e356bed6a 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -175,6 +175,7 @@ struct generic_pm_domain_data { struct pm_domain_data base; struct gpd_timing_data td; struct notifier_block nb; + int cpu; unsigned int performance_state; void *data; };