linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
To: Michael Ellerman <mpe@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	michael.neuling@au1.ibm.com, stewart@linux.vnet.ibm.com,
	hbabu@us.ibm.com, linuxppc-dev@ozlabs.org
Subject: [RFC PATCH 02/11] VAS: Define vas_dev_init() and vas_dev_exit()
Date: Fri, 11 Nov 2016 09:02:47 -0800	[thread overview]
Message-ID: <1478883776-11121-3-git-send-email-sukadev@linux.vnet.ibm.com> (raw)
In-Reply-To: <1478883776-11121-1-git-send-email-sukadev@linux.vnet.ibm.com>

Define functions to initialize/terminate the VAS device driver.
These functions will configure the hardware in a follow on patch.

Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
---
 drivers/misc/Kconfig            |   1 +
 drivers/misc/Makefile           |   1 +
 drivers/misc/vas/Kconfig        |  19 +++++++
 drivers/misc/vas/Makefile       |   3 ++
 drivers/misc/vas/vas-internal.h |   5 ++
 drivers/misc/vas/vas-window.c   |  19 +++++++
 drivers/misc/vas/vas.c          | 113 ++++++++++++++++++++++++++++++++++++++++
 7 files changed, 161 insertions(+)
 create mode 100644 drivers/misc/vas/Kconfig
 create mode 100644 drivers/misc/vas/Makefile
 create mode 100644 drivers/misc/vas/vas-window.c
 create mode 100644 drivers/misc/vas/vas.c

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index d002528..d9a8cf0 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -806,4 +806,5 @@ source "drivers/misc/mic/Kconfig"
 source "drivers/misc/genwqe/Kconfig"
 source "drivers/misc/echo/Kconfig"
 source "drivers/misc/cxl/Kconfig"
+source "drivers/misc/vas/Kconfig"
 endmenu
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index fb32516..aa5947b 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -55,6 +55,7 @@ obj-$(CONFIG_GENWQE)		+= genwqe/
 obj-$(CONFIG_ECHO)		+= echo/
 obj-$(CONFIG_VEXPRESS_SYSCFG)	+= vexpress-syscfg.o
 obj-$(CONFIG_CXL_BASE)		+= cxl/
+obj-$(CONFIG_VAS)		+= vas/
 obj-$(CONFIG_PANEL)             += panel.o
 
 lkdtm-$(CONFIG_LKDTM)		+= lkdtm_core.o
diff --git a/drivers/misc/vas/Kconfig b/drivers/misc/vas/Kconfig
new file mode 100644
index 0000000..f02b887
--- /dev/null
+++ b/drivers/misc/vas/Kconfig
@@ -0,0 +1,19 @@
+#
+# IBM Virtual Accelarator Switchboard (VAS) compatible devices
+#depends on PPC_POWERNV && PCI_MSI && EEH
+#
+
+config VAS
+	tristate "Support for IBM Virtual Accelerator Switchboard (VAS)"
+	default n
+	help
+	  Select this option to enable driver support for IBM Virtual
+	  Accelerator Switchboard (VAS).
+	  VAS allows accelerators in co processors like NX-842 to be
+	  directly available to a user process.  This driver enables
+	  userspace programs to access these accelerators via
+	  /dev/vas/vas-nxM.N devices.
+
+	  VAS adapters are found in POWER9 based systems.
+
+	  If unsure, say N.
diff --git a/drivers/misc/vas/Makefile b/drivers/misc/vas/Makefile
new file mode 100644
index 0000000..7dd7139
--- /dev/null
+++ b/drivers/misc/vas/Makefile
@@ -0,0 +1,3 @@
+ccflags-y			:= $(call cc-disable-warning, unused-const-variable)
+ccflags-$(CONFIG_PPC_WERROR)	+= -Werror
+obj-$(CONFIG_VAS)		+= vas.o vas-window.o
diff --git a/drivers/misc/vas/vas-internal.h b/drivers/misc/vas/vas-internal.h
index f91fd66..282513b 100644
--- a/drivers/misc/vas/vas-internal.h
+++ b/drivers/misc/vas/vas-internal.h
@@ -362,4 +362,9 @@ struct vas_winctx {
 	enum vas_notify_after_count notify_after_count;
 };
 
+extern int vas_initialized;
+
+extern int vas_window_reset(struct vas_instance *vinst, int winid);
+extern struct vas_instance *find_vas_instance(int node, int chip);
+
 #endif
diff --git a/drivers/misc/vas/vas-window.c b/drivers/misc/vas/vas-window.c
new file mode 100644
index 0000000..468f3bf
--- /dev/null
+++ b/drivers/misc/vas/vas-window.c
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2016 IBM Corp.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/types.h>
+#include <linux/mutex.h>
+#include <asm/vas.h>
+#include "vas-internal.h"
+
+/* stub for now */
+int vas_window_reset(struct vas_instance *vinst, int winid)
+{
+	return 0;
+}
diff --git a/drivers/misc/vas/vas.c b/drivers/misc/vas/vas.c
new file mode 100644
index 0000000..51f9c70
--- /dev/null
+++ b/drivers/misc/vas/vas.c
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2016 IBM Corp.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/export.h>
+#include <linux/types.h>
+#include <linux/slab.h>
+#include <linux/io.h>
+#include <asm/vas.h>
+#include "vas-internal.h"
+
+int vas_initialized;
+struct vas_instance *vas_instances;
+
+static void init_vas_chip(struct vas_instance *vinst)
+{
+	int i;
+
+	for (i = 0; i < VAS_MAX_WINDOWS_PER_CHIP; i++)
+		vas_window_reset(vinst, i);
+}
+
+/*
+ * Although this is read/used multiple times, it is written to only
+ * during initialization.
+ */
+struct vas_instance *find_vas_instance(int node, int chip)
+{
+	int i = node * VAS_MAX_CHIPS_PER_NODE + chip;
+
+	return &vas_instances[i];
+}
+
+static void init_vas_instance(int node, int chip)
+{
+	struct vas_instance *vinst;
+
+	vinst = find_vas_instance(node, chip);
+
+	ida_init(&vinst->ida);
+
+	vinst->node = node;
+	vinst->chip = chip;
+	mutex_init(&vinst->mutex);
+
+	init_vas_chip(vinst);
+}
+
+int vas_init(void)
+{
+	int n, c;
+
+	vas_instances = kmalloc_array(VAS_MAX_NODES * VAS_MAX_CHIPS_PER_NODE,
+				sizeof(struct vas_instance), GFP_KERNEL);
+	if (!vas_instances)
+		return -ENOMEM;
+
+	/*
+	 * TODO: Get node-id and chip id from device tree?
+	 */
+	for (n = 0; n < VAS_MAX_NODES; n++) {
+		for (c = 0; c < VAS_MAX_CHIPS_PER_NODE; c++)
+			init_vas_instance(n, c);
+	}
+
+	vas_initialized = 1;
+
+	return 0;
+}
+
+void vas_exit(void)
+{
+	vas_initialized = 0;
+	kfree(vas_instances);
+}
+
+/*
+ * We will have a device driver for user space access to VAS.
+ * But for now this is just a wrapper to vas_init()
+ */
+int __init vas_dev_init(void)
+{
+	int rc;
+
+	rc = vas_init();
+	if (rc)
+		return rc;
+
+	vas_initialized = 1;
+
+	pr_err("VAS: initialized\n");
+
+	return 0;
+}
+
+void __init vas_dev_exit(void)
+{
+	pr_err("VAS: exiting\n");
+	vas_exit();
+}
+
+module_init(vas_dev_init);
+module_exit(vas_dev_exit);
+MODULE_DESCRIPTION("IBM Virtual Accelerator Switchboard");
+MODULE_AUTHOR("Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>");
+MODULE_LICENSE("GPL");
-- 
1.8.3.1

  parent reply	other threads:[~2016-11-11 17:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-11 17:02 [RFC PATCH 00/11] Enable VAS Sukadev Bhattiprolu
2016-11-11 17:02 ` [RFC PATCH 01/11] VAS: Define macros and register fields Sukadev Bhattiprolu
2016-11-11 17:02 ` Sukadev Bhattiprolu [this message]
2016-11-11 17:02 ` [RFC PATCH 03/11] VAS: Define helpers for access MMIO regions Sukadev Bhattiprolu
2016-11-11 17:02 ` [RFC PATCH 04/11] VAS: Define helpers to init window context Sukadev Bhattiprolu
2016-11-11 17:02 ` [RFC PATCH 05/11] VAS: Define helpers to alloc/free windows Sukadev Bhattiprolu
2016-11-11 17:02 ` [RFC PATCH 06/11] VAS: Define vas_rx_win_open() and vas_win_close() Sukadev Bhattiprolu
2016-11-11 17:02 ` [RFC PATCH 07/11] VAS: Define vas_tx_win_open() Sukadev Bhattiprolu
2016-11-11 17:02 ` [RFC PATCH 08/11] VAS: Define vas_copy_crb() and vas_paste_crb() Sukadev Bhattiprolu
2016-11-11 17:02 ` [RFC PATCH 09/11] VAS: Define/use vas_print_regs() Sukadev Bhattiprolu
2016-11-11 17:02 ` [RFC PATCH 10/11] VAS: Create a thread to monitor fault-window Sukadev Bhattiprolu
2016-11-11 17:02 ` [RFC PATCH 11/11] VAS: Define/use interface to setup irq handling Sukadev Bhattiprolu

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=1478883776-11121-3-git-send-email-sukadev@linux.vnet.ibm.com \
    --to=sukadev@linux.vnet.ibm.com \
    --cc=benh@kernel.crashing.org \
    --cc=hbabu@us.ibm.com \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=michael.neuling@au1.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=stewart@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;
as well as URLs for NNTP newsgroup(s).