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,
apopple@au1.ibm.com, hbabu@us.ibm.com, oohall@gmail.com,
bsingharora@gmail.com, linuxppc-dev@ozlabs.org,
<linux-kernel@vger.kernel.org>
Subject: [PATCH v4 05/11] VAS: Define helpers for access MMIO regions
Date: Thu, 30 Mar 2017 22:13:38 -0700 [thread overview]
Message-ID: <1490937224-29149-6-git-send-email-sukadev@linux.vnet.ibm.com> (raw)
In-Reply-To: <1490937224-29149-1-git-send-email-sukadev@linux.vnet.ibm.com>
Define some helper functions to access the MMIO regions. We use these
in a follow-on patches to read/write VAS hardware registers. These
helpers are also used to later issue 'paste' instructions to submit
requests to the NX hardware engines.
Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
---
Changelog [v3]:
- Minor reorg/cleanup of map/unmap functions
Changelog [v2]:
- Get HVWC, UWC and paste addresses from window->vinst (i.e DT)
rather than kernel macros.
---
arch/powerpc/platforms/powernv/vas-window.c | 126 ++++++++++++++++++++++++++++
1 file changed, 126 insertions(+)
diff --git a/arch/powerpc/platforms/powernv/vas-window.c b/arch/powerpc/platforms/powernv/vas-window.c
index 6156fbe..ec084d2 100644
--- a/arch/powerpc/platforms/powernv/vas-window.c
+++ b/arch/powerpc/platforms/powernv/vas-window.c
@@ -9,9 +9,135 @@
#include <linux/types.h>
#include <linux/mutex.h>
+#include <linux/slab.h>
+#include <linux/io.h>
#include "vas.h"
+/*
+ * Compute the paste address region for the window @window using the
+ * ->win_base_addr and ->win_id_shift we got from device tree.
+ */
+void compute_paste_address(struct vas_window *window, uint64_t *addr, int *len)
+{
+ uint64_t base, shift;
+ int winid;
+
+ base = window->vinst->win_base_addr;
+ shift = window->vinst->win_id_shift;
+ winid = window->winid;
+
+ *addr = base + (winid << shift);
+ *len = PAGE_SIZE;
+
+ pr_debug("Txwin #%d: Paste addr 0x%llx\n", winid, *addr);
+}
+
+static inline void get_hvwc_mmio_bar(struct vas_window *window,
+ uint64_t *start, int *len)
+{
+ uint64_t pbaddr;
+
+ pbaddr = window->vinst->hvwc_bar_start;
+ *start = pbaddr + window->winid * VAS_HVWC_SIZE;
+ *len = VAS_HVWC_SIZE;
+}
+
+static inline void get_uwc_mmio_bar(struct vas_window *window,
+ uint64_t *start, int *len)
+{
+ uint64_t pbaddr;
+
+ pbaddr = window->vinst->uwc_bar_start;
+ *start = pbaddr + window->winid * VAS_UWC_SIZE;
+ *len = VAS_UWC_SIZE;
+}
+
+static void *map_mmio_region(char *name, uint64_t start, int len)
+{
+ void *map;
+
+ if (!request_mem_region(start, len, name)) {
+ pr_devel("%s(): request_mem_region(0x%llx, %d) failed\n",
+ __func__, start, len);
+ return NULL;
+ }
+
+ map = __ioremap(start, len, pgprot_val(pgprot_cached(__pgprot(0))));
+ if (!map) {
+ pr_devel("%s(): ioremap(0x%llx, %d) failed\n", __func__, start,
+ len);
+ return NULL;
+ }
+
+ return map;
+}
+
+/*
+ * Unmap the MMIO regions for a window.
+ */
+static void unmap_wc_paste_kaddr(struct vas_window *window)
+{
+ int len;
+ uint64_t busaddr_start;
+
+ if (window->paste_kaddr) {
+ iounmap(window->paste_kaddr);
+ compute_paste_address(window, &busaddr_start, &len);
+ release_mem_region((phys_addr_t)busaddr_start, len);
+ window->paste_kaddr = NULL;
+ }
+
+}
+
+static void unmap_wc_mmio_bars(struct vas_window *window)
+{
+ int len;
+ uint64_t busaddr_start;
+
+ unmap_wc_paste_kaddr(window);
+
+ if (window->hvwc_map) {
+ iounmap(window->hvwc_map);
+ get_hvwc_mmio_bar(window, &busaddr_start, &len);
+ release_mem_region((phys_addr_t)busaddr_start, len);
+ window->hvwc_map = NULL;
+ }
+
+ if (window->uwc_map) {
+ iounmap(window->uwc_map);
+ get_uwc_mmio_bar(window, &busaddr_start, &len);
+ release_mem_region((phys_addr_t)busaddr_start, len);
+ window->uwc_map = NULL;
+ }
+}
+
+/*
+ * Find the Hypervisor Window Context (HVWC) MMIO Base Address Region and the
+ * OS/User Window Context (UWC) MMIO Base Address Region for the given window.
+ * Map these bus addresses and save the mapped kernel addresses in @window.
+ */
+int map_wc_mmio_bars(struct vas_window *window)
+{
+ int len;
+ uint64_t start;
+
+ window->paste_kaddr = window->hvwc_map = window->uwc_map = NULL;
+
+ get_hvwc_mmio_bar(window, &start, &len);
+ window->hvwc_map = map_mmio_region("HVWCM_Window", start, len);
+
+ get_uwc_mmio_bar(window, &start, &len);
+ window->uwc_map = map_mmio_region("UWCM_Window", start, len);
+
+ if (!window->hvwc_map || !window->uwc_map) {
+ unmap_wc_mmio_bars(window);
+ return -1;
+ }
+
+ return 0;
+}
+
/* stub for now */
int vas_win_close(struct vas_window *window)
{
--
2.7.4
next prev parent reply other threads:[~2017-03-31 5:14 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-31 5:13 [PATCH v4 00/11] Enable VAS Sukadev Bhattiprolu
2017-03-31 5:13 ` [PATCH v4 01/11] Add Power9 PVR Sukadev Bhattiprolu
2017-03-31 5:13 ` [PATCH v4 02/11] VAS: Define macros, register fields and structures Sukadev Bhattiprolu
2017-04-04 17:17 ` Sukadev Bhattiprolu
2017-03-31 5:13 ` [PATCH v4 03/11] Move GET_FIELD/SET_FIELD to vas.h Sukadev Bhattiprolu
2017-03-31 5:13 ` [PATCH v4 04/11] VAS: Define vas_init() and vas_exit() Sukadev Bhattiprolu
2017-04-02 20:23 ` kbuild test robot
2017-04-04 17:20 ` Sukadev Bhattiprolu
2017-04-24 6:18 ` Benjamin Herrenschmidt
2017-04-24 6:25 ` Benjamin Herrenschmidt
2017-04-24 20:32 ` Tyrel Datwyler
2017-05-25 5:29 ` Sukadev Bhattiprolu
2017-03-31 5:13 ` Sukadev Bhattiprolu [this message]
2017-04-24 6:28 ` [PATCH v4 05/11] VAS: Define helpers for access MMIO regions Benjamin Herrenschmidt
2017-04-24 17:25 ` Sukadev Bhattiprolu
2017-04-24 23:19 ` Benjamin Herrenschmidt
2017-03-31 5:13 ` [PATCH v4 06/11] VAS: Define helpers to init window context Sukadev Bhattiprolu
2017-03-31 5:13 ` [PATCH v4 07/11] VAS: Define helpers to alloc/free windows Sukadev Bhattiprolu
2017-03-31 5:13 ` [PATCH v4 08/11] VAS: Define vas_rx_win_open() interface Sukadev Bhattiprolu
2017-03-31 5:13 ` [PATCH v4 09/11] VAS: Define vas_win_close() interface Sukadev Bhattiprolu
2017-03-31 5:13 ` [PATCH v4 10/11] VAS: Define vas_tx_win_open() Sukadev Bhattiprolu
2017-03-31 5:13 ` [PATCH v4 11/11] VAS: Define copy/paste interfaces 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=1490937224-29149-6-git-send-email-sukadev@linux.vnet.ibm.com \
--to=sukadev@linux.vnet.ibm.com \
--cc=apopple@au1.ibm.com \
--cc=benh@kernel.crashing.org \
--cc=bsingharora@gmail.com \
--cc=hbabu@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@ozlabs.org \
--cc=michael.neuling@au1.ibm.com \
--cc=mpe@ellerman.id.au \
--cc=oohall@gmail.com \
--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).