public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] virtio: Define and use per-architecture "pfn shift" constants
@ 2008-11-06  4:49 Hollis Blanchard
  2008-11-06  4:54 ` Hollis Blanchard
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Hollis Blanchard @ 2008-11-06  4:49 UTC (permalink / raw)
  To: rusty; +Cc: kvm, kvm-ppc, kvm-ia64

# HG changeset patch
# User Hollis Blanchard <hollisb@us.ibm.com>
# Date 1225946980 21600
# Node ID f58566dfe20e841604e1377ff41e9e0501c1cf18
# Parent  f776b102380286dd173a3b89f7dc976140812517
virtio: Define and use per-architecture "pfn shift" constants

Both sides of the virtio interface must agree about how big a pfn really is.
This is particularly an issue on architectures where the page size is
configurable (e.g. PowerPC, IA64) -- the interface must be independent of
PAGE_SHIFT.

This patch should have no functional effect on x86 or ia64, but an ack from the IA64 guys
would be good because I'm not clear on their page size requirements.

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>

diff --git a/arch/ia64/include/asm/virtio.h b/arch/ia64/include/asm/virtio.h
new file mode 100644
--- /dev/null
+++ b/arch/ia64/include/asm/virtio.h
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright IBM Corp. 2008
+ *
+ * Authors: Hollis Blanchard <hollisb@us.ibm.com>
+ */
+
+#ifndef __ASM_VIRTIO_H__
+#define __ASM_VIRTIO_H__
+
+#define VIRTIO_PFN_SHIFT 16
+
+#endif /* __ASM_VIRTIO_H__ */
diff --git a/arch/powerpc/include/asm/virtio.h b/arch/powerpc/include/asm/virtio.h
new file mode 100644
--- /dev/null
+++ b/arch/powerpc/include/asm/virtio.h
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright IBM Corp. 2008
+ *
+ * Authors: Hollis Blanchard <hollisb@us.ibm.com>
+ */
+
+#ifndef __ASM_VIRTIO_H__
+#define __ASM_VIRTIO_H__
+
+#define VIRTIO_PFN_SHIFT 10
+
+#endif /* __ASM_VIRTIO_H__ */
diff --git a/arch/x86/include/asm/virtio.h b/arch/x86/include/asm/virtio.h
new file mode 100644
--- /dev/null
+++ b/arch/x86/include/asm/virtio.h
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright IBM Corp. 2008
+ *
+ * Authors: Hollis Blanchard <hollisb@us.ibm.com>
+ */
+
+#ifndef __ASM_VIRTIO_H__
+#define __ASM_VIRTIO_H__
+
+#define VIRTIO_PFN_SHIFT 12
+
+#endif /* __ASM_VIRTIO_H__ */
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -24,6 +24,8 @@
 #include <linux/virtio_pci.h>
 #include <linux/highmem.h>
 #include <linux/spinlock.h>
+
+#include <asm/virtio.h>
 
 MODULE_AUTHOR("Anthony Liguori <aliguori@us.ibm.com>");
 MODULE_DESCRIPTION("virtio-pci");
@@ -216,6 +218,7 @@ static struct virtqueue *vp_find_vq(stru
 	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
 	struct virtio_pci_vq_info *info;
 	struct virtqueue *vq;
+	unsigned long vring_bytes;
 	unsigned long flags;
 	u16 num;
 	int err;
@@ -237,14 +240,15 @@ static struct virtqueue *vp_find_vq(stru
 	info->queue_index = index;
 	info->num = num;
 
-	info->queue = kzalloc(PAGE_ALIGN(vring_size(num,PAGE_SIZE)), GFP_KERNEL);
+	vring_bytes = PAGE_ALIGN(vring_size(num, VRING_PAGE_SIZE));
+	info->queue = kzalloc(vring_bytes, GFP_KERNEL);
 	if (info->queue == NULL) {
 		err = -ENOMEM;
 		goto out_info;
 	}
 
 	/* activate the queue */
-	iowrite32(virt_to_phys(info->queue) >> PAGE_SHIFT,
+	iowrite32(virt_to_phys(info->queue) >> VIRTIO_PFN_SHIFT,
 		  vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN);
 
 	/* create the vring */
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -292,7 +292,7 @@ struct virtqueue *vring_new_virtqueue(un
 	if (!vq)
 		return NULL;
 
-	vring_init(&vq->vring, num, pages, PAGE_SIZE);
+	vring_init(&vq->vring, num, pages, VRING_PAGE_SIZE);
 	vq->vq.callback = callback;
 	vq->vq.vdev = vdev;
 	vq->vq.vq_ops = &vring_vq_ops;
diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h
--- a/include/linux/virtio_ring.h
+++ b/include/linux/virtio_ring.h
@@ -102,6 +102,8 @@ static inline void vring_init(struct vri
 			    & ~(pagesize - 1));
 }
 
+#define VRING_PAGE_SIZE (1<<12)
+
 static inline unsigned vring_size(unsigned int num, unsigned long pagesize)
 {
 	return ((sizeof(struct vring_desc) * num + sizeof(__u16) * (2 + num)

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-11-06 20:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-06  4:49 [PATCH] virtio: Define and use per-architecture "pfn shift" constants Hollis Blanchard
2008-11-06  4:54 ` Hollis Blanchard
     [not found] ` <f58566dfe20e841604e1.1225946982-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2008-11-06 10:49   ` Mark McLoughlin
2008-11-06 15:50     ` Hollis Blanchard
     [not found]       ` <1225986626.8620.28.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2008-11-06 16:22         ` Anthony Liguori
2008-11-06 20:07   ` Anthony Liguori
2008-11-06 13:59 ` Anthony Liguori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox