[PATCH v8 3/7] powerpc/powernv: autoload nest unit driver module

From: Madhavan Srinivasan
Date: Mon Feb 22 2016 - 22:57:29 EST


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@xxxxxxxxxxxxxx>
Cc: Benjamin Herrenschmidt <benh@xxxxxxxxxxxxxxxxxxx>
Cc: Paul Mackerras <paulus@xxxxxxxxx>
Cc: Anton Blanchard <anton@xxxxxxxxx>
Cc: Daniel Axtens <dja@xxxxxxxxxx>
Cc: Stephane Eranian <eranian@xxxxxxxxxx>
Cc: Sukadev Bhattiprolu <sukadev@xxxxxxxxxxxxxxxxxx>
Signed-off-by: Madhavan Srinivasan <maddy@xxxxxxxxxxxxxxxxxx>
---
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