All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hollis Blanchard <hollisb@us.ibm.com>
To: Keir Fraser <keir.fraser@xensource.com>
Cc: xen-devel@lists.xensource.com, xen-ppc-devel@lists.xensource.com
Subject: [PATCH 3 of 6] [XEN][LINUX] Add architecture-generic xencomm infrastructure
Date: Thu, 05 Jul 2007 16:08:42 -0500	[thread overview]
Message-ID: <e2681868041e35f127ee.1183669722@localhost> (raw)
In-Reply-To: <patchbomb.1183669719@localhost>

4 files changed, 247 insertions(+)
drivers/xen/Kconfig        |    3 
drivers/xen/core/Makefile  |    1 
drivers/xen/core/xencomm.c |  192 ++++++++++++++++++++++++++++++++++++++++++++
include/xen/xencomm.h      |   51 +++++++++++


# HG changeset patch
# User Hollis Blanchard <hollisb@us.ibm.com>
# Date 1183669278 18000
# Node ID e2681868041e35f127ee6cb5111317c3a96505e8
# Parent  001c42f8079ec50c0b213049a86db173a928652b
[XEN][LINUX] Add architecture-generic xencomm infrastructure.
Xencomm is the mechanism by which userspace can pass virtual addresses to Xen
on architectures that cannot perform page table walks in software, including
PowerPC and IA64.
Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>

diff -r 001c42f8079e -r e2681868041e drivers/xen/Kconfig
--- a/drivers/xen/Kconfig	Thu Jul 05 16:01:18 2007 -0500
+++ b/drivers/xen/Kconfig	Thu Jul 05 16:01:18 2007 -0500
@@ -278,4 +278,7 @@ config XEN_BALLOON
 	bool
 	default y
 
+config XEN_XENCOMM
+	bool
+
 endif
diff -r 001c42f8079e -r e2681868041e drivers/xen/core/Makefile
--- a/drivers/xen/core/Makefile	Thu Jul 05 16:01:18 2007 -0500
+++ b/drivers/xen/core/Makefile	Thu Jul 05 16:01:18 2007 -0500
@@ -10,3 +10,4 @@ obj-$(CONFIG_XEN_SYSFS)		+= xen_sysfs.o
 obj-$(CONFIG_XEN_SYSFS)		+= xen_sysfs.o
 obj-$(CONFIG_XEN_SMPBOOT)	+= smpboot.o
 obj-$(CONFIG_KEXEC)		+= machine_kexec.o
+obj-$(CONFIG_XEN_XENCOMM)		+= xencomm.o
diff -r 001c42f8079e -r e2681868041e drivers/xen/core/xencomm.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/drivers/xen/core/xencomm.c	Thu Jul 05 16:01:18 2007 -0500
@@ -0,0 +1,192 @@
+/*
+ * 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.
+ * 
+ * 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.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *
+ * Copyright (C) IBM Corp. 2006
+ *
+ * Authors: Hollis Blanchard <hollisb@us.ibm.com>
+ */
+
+#include <linux/gfp.h>
+#include <linux/mm.h>
+#include <asm/page.h>
+#include <xen/xencomm.h>
+#include <xen/interface/xen.h>
+
+static int xencomm_init(struct xencomm_desc *desc,
+			void *buffer, unsigned long bytes)
+{
+	unsigned long recorded = 0;
+	int i = 0;
+
+	while ((recorded < bytes) && (i < desc->nr_addrs)) {
+		unsigned long vaddr = (unsigned long)buffer + recorded;
+		unsigned long paddr;
+		int offset;
+		int chunksz;
+
+		offset = vaddr % PAGE_SIZE; /* handle partial pages */
+		chunksz = min(PAGE_SIZE - offset, bytes - recorded);
+
+		paddr = xencomm_vtop(vaddr);
+		if (paddr == ~0UL) {
+			printk("%s: couldn't translate vaddr %lx\n",
+			       __func__, vaddr);
+			return -EINVAL;
+		}
+
+		desc->address[i++] = paddr;
+		recorded += chunksz;
+	}
+
+	if (recorded < bytes) {
+		printk("%s: could only translate %ld of %ld bytes\n",
+		       __func__, recorded, bytes);
+		return -ENOSPC;
+	}
+
+	/* mark remaining addresses invalid (just for safety) */
+	while (i < desc->nr_addrs)
+		desc->address[i++] = XENCOMM_INVALID;
+
+	desc->magic = XENCOMM_MAGIC;
+
+	return 0;
+}
+
+/* XXX use slab allocator */
+static struct xencomm_desc *xencomm_alloc(gfp_t gfp_mask)
+{
+	struct xencomm_desc *desc;
+
+	desc = (struct xencomm_desc *)__get_free_page(gfp_mask);
+	if (desc == NULL)
+		return NULL;
+
+	desc->nr_addrs = (PAGE_SIZE - sizeof(struct xencomm_desc)) /
+			sizeof(*desc->address);
+
+	return desc;
+}
+
+void xencomm_free(void *desc)
+{
+	if (desc && !((ulong)desc & XENCOMM_INLINE_FLAG))
+		free_page((unsigned long)__va(desc));
+}
+
+static int xencomm_create(void *buffer, unsigned long bytes, struct xencomm_desc **ret, gfp_t gfp_mask)
+{
+	struct xencomm_desc *desc;
+	int rc;
+
+	pr_debug("%s: %p[%ld]\n", __func__, buffer, bytes);
+
+	if (bytes == 0) {
+		/* don't create a descriptor; Xen recognizes NULL. */
+		BUG_ON(buffer != NULL);
+		*ret = NULL;
+		return 0;
+	}
+
+	BUG_ON(buffer == NULL); /* 'bytes' is non-zero */
+
+	desc = xencomm_alloc(gfp_mask);
+	if (!desc) {
+		printk("%s failure\n", "xencomm_alloc");
+		return -ENOMEM;
+	}
+
+	rc = xencomm_init(desc, buffer, bytes);
+	if (rc) {
+		printk("%s failure: %d\n", "xencomm_init", rc);
+		xencomm_free(desc);
+		return rc;
+	}
+
+	*ret = desc;
+	return 0;
+}
+
+/* check if memory address is within VMALLOC region  */
+static int is_phys_contiguous(unsigned long addr)
+{
+	if (!is_kernel_addr(addr))
+		return 0;
+
+	return (addr < VMALLOC_START) || (addr >= VMALLOC_END);
+}
+
+static void *xencomm_create_inline(void *ptr)
+{
+	unsigned long paddr;
+
+	BUG_ON(!is_phys_contiguous((unsigned long)ptr));
+
+	paddr = (unsigned long)xencomm_pa(ptr);
+	BUG_ON(paddr & XENCOMM_INLINE_FLAG);
+	return (void *)(paddr | XENCOMM_INLINE_FLAG);
+}
+
+/* "mini" routine, for stack-based communications: */
+static int xencomm_create_mini(void *buffer,
+	unsigned long bytes, struct xencomm_mini *xc_desc,
+	struct xencomm_desc **ret)
+{
+	int rc = 0;
+	struct xencomm_desc *desc;
+
+	desc = (void *)xc_desc; 
+
+	desc->nr_addrs = XENCOMM_MINI_ADDRS;
+
+	if (!(rc = xencomm_init(desc, buffer, bytes)))
+		*ret = desc;
+
+	return rc;
+}
+
+void *xencomm_map(void *ptr, unsigned long bytes)
+{
+	int rc;
+	struct xencomm_desc *desc;
+
+	if (is_phys_contiguous((unsigned long)ptr))
+		return xencomm_create_inline(ptr);
+
+	rc = xencomm_create(ptr, bytes, &desc, GFP_KERNEL);
+
+	if (rc || desc == NULL)
+		return NULL;
+
+	return (void *)__pa(desc);
+}
+
+void *__xencomm_map_no_alloc(void *ptr, unsigned long bytes, 
+			struct xencomm_mini *xc_desc)
+{
+	int rc;
+	struct xencomm_desc *desc = NULL;
+
+	if (is_phys_contiguous((unsigned long)ptr))
+		return xencomm_create_inline(ptr);
+
+	rc = xencomm_create_mini(ptr, bytes, xc_desc,
+				&desc);
+
+	if (rc)
+		return NULL;
+ 
+	return (void *)__pa(desc);
+}
diff -r 001c42f8079e -r e2681868041e include/xen/xencomm.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/xen/xencomm.h	Thu Jul 05 16:01:18 2007 -0500
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ * 
+ * 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.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *
+ * Copyright (C) IBM Corp. 2006
+ *
+ * Authors: Hollis Blanchard <hollisb@us.ibm.com>
+ *          Jerone Young <jyoung5@us.ibm.com>
+ */
+
+#ifndef _LINUX_XENCOMM_H_
+#define _LINUX_XENCOMM_H_
+
+#include <xen/interface/xencomm.h>
+
+#define XENCOMM_MINI_ADDRS 3
+struct xencomm_mini {
+	struct xencomm_desc _desc;
+	uint64_t address[XENCOMM_MINI_ADDRS];
+};
+
+extern void xencomm_free(void *desc);
+extern void *xencomm_map(void *ptr, unsigned long bytes);
+extern void *__xencomm_map_no_alloc(void *ptr, unsigned long bytes, 
+				struct xencomm_mini *xc_area);
+
+#define xencomm_map_no_alloc(ptr, bytes) \
+	({struct xencomm_mini xc_desc\
+		__attribute__((__aligned__(sizeof(struct xencomm_mini))));\
+		__xencomm_map_no_alloc(ptr, bytes, &xc_desc);})
+
+/* provided by architecture code: */
+extern unsigned long xencomm_vtop(unsigned long vaddr);
+
+static inline void *xencomm_pa(void *ptr)
+{
+	return (void *)xencomm_vtop((unsigned long)ptr);
+}
+
+#endif /* _LINUX_XENCOMM_H_ */

  parent reply	other threads:[~2007-07-05 21:08 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-05 21:08 [PATCH 0 of 6] PowerPC Linux patches Hollis Blanchard
2007-07-05 21:08 ` [PATCH 1 of 6] [XEN][LINUX] Add Kconfig option for the balloon driver Hollis Blanchard
2007-07-05 21:08 ` [PATCH 2 of 6] [XEN][LINUX] Create Xen-specific interface for xlate_dev_mem_* Hollis Blanchard
2007-07-05 21:08 ` Hollis Blanchard [this message]
2007-07-05 21:29   ` [PATCH 3 of 6] [XEN][LINUX] Add architecture-generic xencomm infrastructure Keir Fraser
2007-07-05 21:35     ` [XenPPC] " Hollis Blanchard
2007-07-05 21:44       ` Keir Fraser
2007-07-05 21:52         ` Hollis Blanchard
2007-07-05 21:08 ` [PATCH 4 of 6] [XEN][LINUX] #ifdef x86-specific alloc_vm_area() Hollis Blanchard
2007-07-05 21:38   ` Keir Fraser
2007-07-05 21:08 ` [PATCH 5 of 6] [XEN][LINUX] Refactor grant table allocation into arch-specific code Hollis Blanchard
2007-07-05 21:08 ` [PATCH 6 of 6] [XEN][LINUX] Add 32-bit privcmd ioctl conversion for 64-bit kernels Hollis Blanchard
2007-07-05 21:35   ` Keir Fraser
2007-07-05 21:41 ` [PATCH 0 of 6] PowerPC Linux patches Keir Fraser
2007-07-05 21:54   ` [XenPPC] " Hollis Blanchard
  -- strict thread matches above, loose matches on Subject: below --
2007-07-05 22:27 [PATCH 0 of 6] PowerPC Linux patches, rev 2 Hollis Blanchard
2007-07-05 22:27 ` [PATCH 3 of 6] [XEN][LINUX] Add architecture-generic xencomm infrastructure Hollis Blanchard

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=e2681868041e35f127ee.1183669722@localhost \
    --to=hollisb@us.ibm.com \
    --cc=keir.fraser@xensource.com \
    --cc=xen-devel@lists.xensource.com \
    --cc=xen-ppc-devel@lists.xensource.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.