mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	Anton Blanchard <anton@samba.org>, Daniel Axtens <dja@axtens.net>,
	Stephane Eranian <eranian@google.com>,
	Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Subject: [PATCH v8 3/7] powerpc/powernv: autoload nest unit driver module
Date: Tue, 23 Feb 2016 09:16:34 +0530	[thread overview]
Message-ID: <1456199198-11056-4-git-send-email-maddy@linux.vnet.ibm.com> (raw)
In-Reply-To: <1456199198-11056-1-git-send-email-maddy@linux.vnet.ibm.com>

Device tree parsing of nest units and events are
separated from pmu code and are placed in powernv/
as "opal-nest.c". Makefile is updated to up pick
the file.

Code added to "opal.c" to create a platform device
for the nest unit. Nest device module code with a
probe function to get the nest counter memory address
information for each chip is added in this patch.

"ibm,opal-in-memory-counters" compatible string is
used for autoload device_id match.

Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Anton Blanchard <anton@samba.org>
Cc: Daniel Axtens <dja@axtens.net>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Signed-off-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
---
 arch/powerpc/platforms/powernv/Makefile    |  2 +-
 arch/powerpc/platforms/powernv/opal-nest.c | 97 ++++++++++++++++++++++++++++++
 arch/powerpc/platforms/powernv/opal.c      | 12 ++++
 3 files changed, 110 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/platforms/powernv/opal-nest.c

diff --git a/arch/powerpc/platforms/powernv/Makefile b/arch/powerpc/platforms/powernv/Makefile
index f1516b5ecec9..ffc54cd49656 100644
--- a/arch/powerpc/platforms/powernv/Makefile
+++ b/arch/powerpc/platforms/powernv/Makefile
@@ -2,7 +2,7 @@ obj-y			+= setup.o opal-wrappers.o opal.o opal-async.o idle.o
 obj-y			+= opal-rtc.o opal-nvram.o opal-lpc.o opal-flash.o
 obj-y			+= rng.o opal-elog.o opal-dump.o opal-sysparam.o opal-sensor.o
 obj-y			+= opal-msglog.o opal-hmi.o opal-power.o opal-irqchip.o
-obj-y			+= opal-kmsg.o
+obj-y			+= opal-kmsg.o opal-nest.o
 
 obj-$(CONFIG_SMP)	+= smp.o subcore.o subcore-asm.o
 obj-$(CONFIG_PCI)	+= pci.o pci-p5ioc2.o pci-ioda.o npu-dma.o
diff --git a/arch/powerpc/platforms/powernv/opal-nest.c b/arch/powerpc/platforms/powernv/opal-nest.c
new file mode 100644
index 000000000000..2ca879fdf159
--- /dev/null
+++ b/arch/powerpc/platforms/powernv/opal-nest.c
@@ -0,0 +1,97 @@
+/*
+ * OPAL Nest detection interface driver
+ * Supported on POWERNV platform
+ *
+ * Copyright IBM Corporation 2016
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/miscdevice.h>
+#include <linux/fs.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_platform.h>
+#include <linux/poll.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <asm/opal.h>
+#include <asm/io.h>
+#include <asm/uaccess.h>
+#include <asm/nest-pmu.h>
+
+extern struct perchip_nest_info nest_perchip_info[NEST_MAX_CHIPS];
+
+static int opal_nest_counters_probe(struct platform_device *pdev)
+{
+	struct device_node *child, *parent;
+	struct perchip_nest_info *pcni;
+	u32 idx, range[4], pages;
+	int rc=0, i=0;
+
+	if (!pdev || !pdev->dev.of_node)
+		return -ENODEV;
+
+	/*
+	 * "nest-counters" folder contains two things,
+	 * a) per-chip reserved memory region for Nest PMU Counter data
+	 * b) Support Nest PMU units and their event files
+	 */
+	parent = pdev->dev.of_node;
+	for_each_child_of_node(parent, child) {
+		if (of_property_read_u32(child, "ibm,chip-id", &idx)) {
+			pr_err("opal-nest-counters: device %s missing property\n",
+							child->full_name);
+			return -ENODEV;
+		}
+
+		/*
+		 *"ranges" property will have four u32 cells.
+		 */
+		if (of_property_read_u32_array(child, "ranges", range, 4)) {
+			pr_err("opal-nest-counters: range property value wrong\n");
+			return -1;
+		}
+
+		pcni = &nest_perchip_info[idx];
+		pcni->pbase = range[1];
+		pcni->pbase = pcni->pbase << 32 | range[2];
+		pcni->size = range[3];
+
+		do
+		{
+			pages = PAGE_SIZE * i;
+			pcni->vbase[i++] = (u64)phys_to_virt(pcni->pbase + pages);
+		} while( i < (pcni->size/PAGE_SIZE));
+	}
+
+	return rc;
+}
+
+static const struct of_device_id opal_nest_match[] = {
+	{ .compatible = "ibm,opal-in-memory-counters" },
+	{ },
+};
+
+static struct platform_driver opal_nest_driver = {
+	.driver = {
+		.name           = "opal-nest-counters",
+		.of_match_table = opal_nest_match,
+	},
+	.probe  = opal_nest_counters_probe,
+};
+
+MODULE_DEVICE_TABLE(of, opal_nest_match);
+module_platform_driver(opal_nest_driver);
+MODULE_DESCRIPTION("PowerNV OPAL Nest Counters driver");
+MODULE_LICENSE("GPL");
diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c
index 4e0da5af94a1..60b576d1fc94 100644
--- a/arch/powerpc/platforms/powernv/opal.c
+++ b/arch/powerpc/platforms/powernv/opal.c
@@ -651,6 +651,15 @@ static void opal_i2c_create_devs(void)
 		of_platform_device_create(np, NULL, NULL);
 }
 
+static void opal_nest_create_dev(void)
+{
+	struct device_node *np;
+
+	np = of_find_compatible_node(NULL, NULL, "ibm,opal-in-memory-counters");
+	if (np)
+		of_platform_device_create(np, NULL, NULL);
+}
+
 static int kopald(void *unused)
 {
 	__be64 events;
@@ -717,6 +726,9 @@ static int __init opal_init(void)
 	/* Setup a heatbeat thread if requested by OPAL */
 	opal_init_heartbeat();
 
+	/* Create nest platform devices */
+	opal_nest_create_dev();
+
 	/* Create leds platform devices */
 	leds = of_find_node_by_path("/ibm,opal/leds");
 	if (leds) {
-- 
1.9.1

  parent reply	other threads:[~2016-02-23  3:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-23  3:46 [PATCH v8 0/7] powerpc/powernv: Nest Instrumentation support Madhavan Srinivasan
2016-02-23  3:46 ` [PATCH v8 1/7] powerpc/powernv: Data structure and macros definition Madhavan Srinivasan
2016-02-23  3:46 ` [PATCH v8 2/7] powerpc/powernv: Add OPAL support for Nest PMU Madhavan Srinivasan
2016-02-23  3:46 ` Madhavan Srinivasan [this message]
2016-02-23  3:46 ` [PATCH v8 4/7] powerpc/powernv: detect supported nest units and its events Madhavan Srinivasan
2016-02-23  3:46 ` [PATCH v8 5/7] powerpc/perf: Add event attribute and group to nest pmu Madhavan Srinivasan
2016-02-23  3:46 ` [PATCH v8 6/7] powerpc/perf: generic nest pmu event functions Madhavan Srinivasan
2016-02-23  3:46 ` [PATCH v8 7/7] powerpc/perf: nest pmu cpumask and cpu hotplug support Madhavan Srinivasan
2016-02-29 20:13   ` kbuild test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1456199198-11056-4-git-send-email-maddy@linux.vnet.ibm.com \
    --to=maddy@linux.vnet.ibm.com \
    --cc=anton@samba.org \
    --cc=benh@kernel.crashing.org \
    --cc=dja@axtens.net \
    --cc=eranian@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    --cc=sukadev@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome