From patchwork Mon Aug 10 06:32:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 52139 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by patches.linaro.org (Postfix) with ESMTPS id 55C3222919 for ; Mon, 10 Aug 2015 06:34:22 +0000 (UTC) Received: by lbsm2 with SMTP id m2sf22046395lbs.1 for ; Sun, 09 Aug 2015 23:34:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=4Ib6R8K2+rMfJq3MaRuX4YLDiXMObVKPB1eTAFJKWSs=; b=WSQ/kWUFZf1kTXJLMhxk2imdExp3uN9fuAKAjfLdH7qvRsBwWP1zdNWJEddj8oW8IP lY9bqDHgwk0DVQMXBEqPGT2X2ZdINMc7TXa/qFXZyc6CxfS9lVZDNq2UdL4RkhyYtcAb i//6CyD8ktjUSBSBP4euNw4UrUPCsykG2AH7uCYuN3J8CwJizVyIwLpBId6zX/IDSUmx KLsKF8trTS+Rrpy1Cf5iVVd19zRZQKN7Qp50Q7pT7jXRZWGs6wRwIDwgb8wr+M+EYzhk a7zg5CXz0wu3D6pUwT7ZbvaYsX8VI8APS9C2amOsPpmAL5IFV0v0Mfdme+oqJKtU/w55 Z4NQ== X-Gm-Message-State: ALoCoQlKJoX7oCOjvTaKMj4ubWE5BzLQFejHyUsNf9XfIgUWQCHRebW64aCi14piIvLO4KLHw46O X-Received: by 10.112.170.67 with SMTP id ak3mr4279727lbc.6.1439188461295; Sun, 09 Aug 2015 23:34:21 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.129 with SMTP id s1ls730510las.11.gmail; Sun, 09 Aug 2015 23:34:21 -0700 (PDT) X-Received: by 10.152.115.165 with SMTP id jp5mr19252727lab.102.1439188460973; Sun, 09 Aug 2015 23:34:20 -0700 (PDT) Received: from mail-lb0-f177.google.com (mail-lb0-f177.google.com. [209.85.217.177]) by mx.google.com with ESMTPS id s9si10121241lal.150.2015.08.09.23.34.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Aug 2015 23:34:20 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) client-ip=209.85.217.177; Received: by lbbsx3 with SMTP id sx3so5820920lbb.0 for ; Sun, 09 Aug 2015 23:34:20 -0700 (PDT) X-Received: by 10.152.26.163 with SMTP id m3mr18775354lag.86.1439188460823; Sun, 09 Aug 2015 23:34:20 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.7.198 with SMTP id l6csp1747047lba; Sun, 9 Aug 2015 23:34:19 -0700 (PDT) X-Received: by 10.68.117.173 with SMTP id kf13mr41128222pbb.96.1439188458676; Sun, 09 Aug 2015 23:34:18 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v3si31608152pdn.106.2015.08.09.23.34.17; Sun, 09 Aug 2015 23:34:18 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754644AbbHJGeQ (ORCPT + 28 others); Mon, 10 Aug 2015 02:34:16 -0400 Received: from mail-pa0-f41.google.com ([209.85.220.41]:33627 "EHLO mail-pa0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754564AbbHJGeO (ORCPT ); Mon, 10 Aug 2015 02:34:14 -0400 Received: by pabyb7 with SMTP id yb7so99582738pab.0 for ; Sun, 09 Aug 2015 23:34:13 -0700 (PDT) X-Received: by 10.68.224.162 with SMTP id rd2mr41248752pbc.33.1439188453618; Sun, 09 Aug 2015 23:34:13 -0700 (PDT) Received: from localhost ([223.227.137.11]) by smtp.gmail.com with ESMTPSA id c8sm18562802pdj.59.2015.08.09.23.34.08 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 09 Aug 2015 23:34:13 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , nm@ti.com, sboyd@codeaurora.org Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, khilman@linaro.org, Viresh Kumar , Bartlomiej Zolnierkiewicz , Dmitry Torokhov , Greg Kroah-Hartman , Len Brown , linux-kernel@vger.kernel.org (open list), Pavel Machek Subject: [PATCH 6/6] PM / OPP: Add debugfs support Date: Mon, 10 Aug 2015 12:02:02 +0530 Message-Id: <8a238dcc3bdef28aa9fc3f68787a84449c6ff17a.1439187821.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.4.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch adds debugfs support to OPP layer to export OPPs and their properties for all the devices. This creates a top level directory: /sys/kernel/debug/opp and then device specific directories (based on device names) inside it. For example: 'cpu0', 'cpu1', etc.. If multiple devices share the OPP table, then the real directory is created only for the first device. For all others, links are created to the real directory. Inside the device specific directory, a separate directory is created for each OPP. And within that files per opp property. Signed-off-by: Viresh Kumar --- drivers/base/power/opp/Makefile | 1 + drivers/base/power/opp/core.c | 15 ++++ drivers/base/power/opp/debugfs.c | 165 +++++++++++++++++++++++++++++++++++++++ drivers/base/power/opp/opp.h | 36 +++++++++ 4 files changed, 217 insertions(+) create mode 100644 drivers/base/power/opp/debugfs.c diff --git a/drivers/base/power/opp/Makefile b/drivers/base/power/opp/Makefile index 33c1e18c41a4..19837ef04d8e 100644 --- a/drivers/base/power/opp/Makefile +++ b/drivers/base/power/opp/Makefile @@ -1,2 +1,3 @@ ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG obj-y += core.o cpu.o +obj-$(CONFIG_DEBUG_FS) += debugfs.o diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index b1f72b4cad24..84b084f60d60 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -429,6 +429,7 @@ static void _kfree_list_dev_rcu(struct rcu_head *head) static void _remove_list_dev(struct device_list_opp *list_dev, struct device_opp *dev_opp) { + opp_debug_unregister(list_dev, dev_opp); list_del(&list_dev->node); call_srcu(&dev_opp->srcu_head.srcu, &list_dev->rcu_head, _kfree_list_dev_rcu); @@ -438,6 +439,7 @@ struct device_list_opp *_add_list_dev(const struct device *dev, struct device_opp *dev_opp) { struct device_list_opp *list_dev; + int ret; list_dev = kzalloc(sizeof(*list_dev), GFP_KERNEL); if (!list_dev) @@ -447,6 +449,12 @@ struct device_list_opp *_add_list_dev(const struct device *dev, list_dev->dev = dev; list_add_rcu(&list_dev->node, &dev_opp->dev_list); + /* Create debugfs entries for the dev_opp */ + ret = opp_debug_register(list_dev, dev_opp); + if (ret) + dev_err(dev, "%s: Failed to register opp debugfs (%d)\n", + __func__, ret); + return list_dev; } @@ -562,6 +570,7 @@ static void _opp_remove(struct device_opp *dev_opp, */ if (notify) srcu_notifier_call_chain(&dev_opp->srcu_head, OPP_EVENT_REMOVE, opp); + opp_debug_remove_one(opp); list_del_rcu(&opp->node); call_srcu(&dev_opp->srcu_head.srcu, &opp->rcu_head, _kfree_opp_rcu); @@ -639,6 +648,7 @@ static int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, { struct dev_pm_opp *opp; struct list_head *head = &dev_opp->opp_list; + int ret; /* * Insert new OPP in order of increasing frequency and discard if @@ -669,6 +679,11 @@ static int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, new_opp->dev_opp = dev_opp; list_add_rcu(&new_opp->node, head); + ret = opp_debug_create_one(new_opp, dev_opp->dentry); + if (ret) + dev_err(dev, "%s: Failed to register opp to debugfs (%d)\n", + __func__, ret); + return 0; } diff --git a/drivers/base/power/opp/debugfs.c b/drivers/base/power/opp/debugfs.c new file mode 100644 index 000000000000..d4e18eac8278 --- /dev/null +++ b/drivers/base/power/opp/debugfs.c @@ -0,0 +1,165 @@ +/* + * Generic OPP debugfs interface + * + * Copyright (C) 2015-2016 Viresh Kumar + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include + +#include "opp.h" + +static struct dentry *rootdir; + +void opp_debug_remove_one(struct dev_pm_opp *opp) +{ + debugfs_remove_recursive(opp->dentry); +} + +int opp_debug_create_one(struct dev_pm_opp *opp, struct dentry *pdentry) +{ + struct dentry *d; + char name[15]; + + /* Rate is unique to each OPP, use it to give opp-name */ + sprintf(name, "opp:%lu", opp->rate); + + /* Create per-opp directory */ + d = debugfs_create_dir(name, pdentry); + if (!d) + return -ENOMEM; + + if (!debugfs_create_bool("available", S_IRUGO, d, + (u32 *)&opp->available)) + return -ENOMEM; + + if (!debugfs_create_bool("dynamic", S_IRUGO, d, (u32 *)&opp->dynamic)) + return -ENOMEM; + + if (!debugfs_create_bool("turbo", S_IRUGO, d, (u32 *)&opp->turbo)) + return -ENOMEM; + + if (!debugfs_create_u32("rate_hz", S_IRUGO, d, (u32 *)&opp->rate)) + return -ENOMEM; + + if (!debugfs_create_u32("u_volt_target", S_IRUGO, d, + (u32 *)&opp->u_volt)) + return -ENOMEM; + + if (!debugfs_create_u32("u_volt_min", S_IRUGO, d, + (u32 *)&opp->u_volt_min)) + return -ENOMEM; + + if (!debugfs_create_u32("u_volt_max", S_IRUGO, d, + (u32 *)&opp->u_volt_max)) + return -ENOMEM; + + if (!debugfs_create_u32("u_amp", S_IRUGO, d, (u32 *)&opp->u_amp)) + return -ENOMEM; + + if (!debugfs_create_u32("clock_latency_ns", S_IRUGO, d, + (u32 *)&opp->clock_latency_ns)) + return -ENOMEM; + + opp->dentry = d; + return 0; +} + +static int device_opp_debug_create_dir(struct device_list_opp *list_dev, + struct device_opp *dev_opp) +{ + const struct device *dev = list_dev->dev; + struct dentry *d = NULL; + + /* Create device specific directory */ + d = debugfs_create_dir(dev_name(dev), rootdir); + if (!d) { + dev_err(dev, "%s: Failed to create debugfs dir\n", __func__); + return -ENOMEM; + } + + list_dev->dentry = d; + dev_opp->dentry = d; + dev_opp->debugfs_dev = dev; + + return 0; +} + +static int device_opp_debug_create_link(struct device_list_opp *list_dev, + struct device_opp *dev_opp) +{ + const struct device *dev = list_dev->dev; + struct dentry *d = NULL; + + /* Create device specific directory link */ + d = debugfs_create_symlink(dev_name(dev), rootdir, + dev_name(dev_opp->debugfs_dev)); + if (!d) { + dev_err(dev, "%s: Failed to create link\n", __func__); + return -ENOMEM; + } + + list_dev->dentry = d; + + return 0; +} + +/** + * opp_debug_register - add a device opp node to the debugfs 'opp' directory + * @list_dev: list-dev pointer for device + * @dev_opp: the device-opp being added + * + * Dynamically adds device specific directory in debugfs 'opp' directory. If the + * device-opp is shared with other devices, then links will be created for all + * devices except the first. + * + * Return: 0 on success, otherwise negative error. + */ +int opp_debug_register(struct device_list_opp *list_dev, + struct device_opp *dev_opp) +{ + if (!rootdir) { + pr_debug("%s: Uninitialized rootdir\n", __func__); + return -EINVAL; + } + + if (dev_opp->dentry) + return device_opp_debug_create_link(list_dev, dev_opp); + + return device_opp_debug_create_dir(list_dev, dev_opp); +} + +/** + * opp_debug_unregister - remove a device opp node from debugfs opp directory + * @list_dev: list-dev pointer for device + * @dev_opp: the device-opp being removed + * + * Dynamically removes device specific directory from debugfs 'opp' directory. + */ +void opp_debug_unregister(struct device_list_opp *list_dev, + struct device_opp *dev_opp) +{ + debugfs_remove_recursive(list_dev->dentry); + if (list_dev->dentry == dev_opp->dentry) + dev_opp->dentry = NULL; + list_dev->dentry = NULL; +} + +static int __init opp_debug_init(void) +{ + /* Create /sys/kernel/debug/opp directory */ + rootdir = debugfs_create_dir("opp", NULL); + if (!rootdir) { + pr_err("%s: Failed to create root directory\n", __func__); + return -ENOMEM; + } + + return 0; +} +core_initcall(opp_debug_init); diff --git a/drivers/base/power/opp/opp.h b/drivers/base/power/opp/opp.h index dcb38f78dae4..8eb6a9a098a1 100644 --- a/drivers/base/power/opp/opp.h +++ b/drivers/base/power/opp/opp.h @@ -60,6 +60,7 @@ * @dev_opp: points back to the device_opp struct this opp belongs to * @rcu_head: RCU callback head used for deferred freeing * @np: OPP's device node. + * @dentry: debugfs dentry pointer (per opp) * * This structure stores the OPP information for a given device. */ @@ -81,6 +82,9 @@ struct dev_pm_opp { struct rcu_head rcu_head; struct device_node *np; + + /* debugfs */ + struct dentry *dentry; }; /** @@ -88,6 +92,7 @@ struct dev_pm_opp { * @node: list node * @dev: device to which the struct object belongs * @rcu_head: RCU callback head used for deferred freeing + * @dentry: debugfs dentry pointer (per device) * * This is an internal data structure maintaining the list of devices that are * managed by 'struct device_opp'. @@ -96,6 +101,9 @@ struct device_list_opp { struct list_head node; const struct device *dev; struct rcu_head rcu_head; + + /* debugfs */ + struct dentry *dentry; }; /** @@ -111,6 +119,8 @@ struct device_list_opp { * @opp_list: list of opps * @np: struct device_node pointer for opp's DT node. * @shared_opp: OPP is shared between multiple devices. + * @dentry: debugfs dentry pointer of the real device directory (not links). + * @debugfs_dev: Pointer to device for which the real directory was created. * * This is an internal data structure maintaining the link to opps attached to * a device. This structure is not meant to be shared to users as it is @@ -132,6 +142,10 @@ struct device_opp { unsigned long clock_latency_ns_max; bool shared_opp; struct dev_pm_opp *suspend_opp; + + /* debugfs */ + struct dentry *dentry; + const struct device *debugfs_dev; }; /* Routines internal to opp core */ @@ -140,4 +154,26 @@ struct device_list_opp *_add_list_dev(const struct device *dev, struct device_opp *dev_opp); struct device_node *_of_get_opp_desc_node(struct device *dev); +#ifdef CONFIG_DEBUG_FS +void opp_debug_remove_one(struct dev_pm_opp *opp); +int opp_debug_create_one(struct dev_pm_opp *opp, struct dentry *pdentry); +int opp_debug_register(struct device_list_opp *list_dev, + struct device_opp *dev_opp); +void opp_debug_unregister(struct device_list_opp *list_dev, + struct device_opp *dev_opp); +#else +static inline void opp_debug_remove_one(struct dev_pm_opp *opp) {} + +static inline int opp_debug_create_one(struct dev_pm_opp *opp, + struct dentry *pdentry) +{ return 0; } +static inline int opp_debug_register(struct device_list_opp *list_dev, + struct device_opp *dev_opp) +{ return 0; } + +static inline void opp_debug_unregister(struct device_list_opp *list_dev, + struct device_opp *dev_opp) +{ } +#endif /* DEBUG_FS */ + #endif /* __DRIVER_OPP_H__ */