qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: john cooper <john.cooper@redhat.com>
To: qemu-devel@nongnu.org
Cc: john cooper <john.cooper@third-harmonic.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Rusty Russell <rusty@rustcorp.com.au>,
	Avi Kivity <avi@redhat.com>,
	jens.axboe@oracle.com, Vadim Rozenfeld <vrozenfe@redhat.com>
Subject: [Qemu-devel] [PATCH 2/2] fix virtio_blk serial pci config breakage
Date: Tue, 29 Sep 2009 02:10:15 -0400	[thread overview]
Message-ID: <4AC1A4C7.1090809@redhat.com> (raw)
In-Reply-To: <4AB9AA8E.7060800@third-harmonic.com>

Change virtblk_identify() to pull ATA identify
data from the bar #5 map vs. the pci config
area.  Add minimal support for bar mapping external
to virtio/virtio_pci.c.

Signed-off-by: john cooper <john.cooper@redhat.com>
---

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index aa1a3d5..a1687f3 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -8,6 +8,8 @@
 
 #define PART_BITS 4
 
+#define VBLK_IDENTIFY_BAR 5	/* PCI BAR #5 maps identify/config area */
+
 static int major, index;
 
 struct virtio_blk
@@ -25,6 +27,9 @@ struct virtio_blk
 
 	mempool_t *pool;
 
+	/* maintains mapping of pci bar #5 unique to virtio_blk */
+	void __iomem *identify_ioaddr;
+
 	/* What host tells us, plus 2 for header & tailer. */
 	unsigned int sg_elems;
 
@@ -171,24 +176,30 @@ static void do_virtblk_request(struct request_queue *q)
 		vblk->vq->vq_ops->kick(vblk->vq);
 }
 
-/* return ATA identify data
+/* return ATA identify data if supported by virtio_blk device
  */
 static int virtblk_identify(struct gendisk *disk, void *argp)
 {
 	struct virtio_blk *vblk = disk->private_data;
 	void *opaque;
-	int err = -ENOMEM;
+	int err, i;
+	char *p;
 
+	err = 0;
 	opaque = kmalloc(VIRTIO_BLK_ID_BYTES, GFP_KERNEL);
-	if (!opaque)
+	if (!opaque) {
+		err = -ENOMEM;
 		goto out;
+	}
 
-	err = virtio_config_buf(vblk->vdev, VIRTIO_BLK_F_IDENTIFY,
-		offsetof(struct virtio_blk_config, identify), opaque,
-		VIRTIO_BLK_ID_BYTES);
-
-	if (err)
+	if (!virtio_has_feature(vblk->vdev, VIRTIO_BLK_F_IDENTIFY) ||
+	    !vblk->identify_ioaddr) {
+		err = -ENOENT;
 		goto out_kfree;
+	}
+
+	for (p = opaque, i = 0; i < VIRTIO_BLK_ID_BYTES; ++i)
+		*p++ = ioread8(vblk->identify_ioaddr + i);
 
 	if (copy_to_user(argp, opaque, VIRTIO_BLK_ID_BYTES))
 		err = -EFAULT;
@@ -383,6 +394,9 @@ static int __devinit virtblk_probe(struct virtio_device *vdev)
 	if (!err)
 		blk_queue_logical_block_size(vblk->disk->queue, blk_size);
 
+	vblk->identify_ioaddr = vdev->config->map ?
+		vdev->config->map(vdev, VBLK_IDENTIFY_BAR, 0) : NULL;
+
 	add_disk(vblk->disk);
 	return 0;
 
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
index 248e00e..abc6963 100644
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -561,6 +561,13 @@ static int vp_find_vqs(struct virtio_device *vdev, unsigned nvqs,
 	return err;
 }
 
+/* translate struct virtio_device to struct pci_dev, setup map for bar
+ */
+void __iomem *vp_map(struct virtio_device *vdev, int bar, unsigned long maxlen)
+{
+        return pci_iomap(to_vp_device(vdev)->pci_dev, bar, maxlen);
+}
+
 static struct virtio_config_ops virtio_pci_config_ops = {
 	.get		= vp_get,
 	.set		= vp_set,
@@ -571,6 +578,7 @@ static struct virtio_config_ops virtio_pci_config_ops = {
 	.del_vqs	= vp_del_vqs,
 	.get_features	= vp_get_features,
 	.finalize_features = vp_finalize_features,
+	.map		= vp_map, 
 };
 
 static void virtio_pci_release_dev(struct device *_d)
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index e547e3c..b9b3c62 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -94,6 +94,8 @@ struct virtio_config_ops {
 	void (*del_vqs)(struct virtio_device *);
 	u32 (*get_features)(struct virtio_device *vdev);
 	void (*finalize_features)(struct virtio_device *vdev);
+	void __iomem *(*map)(struct virtio_device *vdev, int bar,
+				    unsigned long maxlen);
 };
 
 /* If driver didn't advertise the feature, it will never appear. */


-- 
john.cooper@redhat.com

  parent reply	other threads:[~2009-09-29  6:16 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-07 18:14 [Qemu-devel] [PATCH] qemu: make virtio-blk PCI compliant by default Michael S. Tsirkin
2009-09-08  7:40 ` [Qemu-devel] " john cooper
2009-09-08  7:58   ` Michael S. Tsirkin
2009-09-21 11:09     ` Rusty Russell
2009-09-21 15:47       ` john cooper
2009-09-22  9:30         ` Avi Kivity
2009-09-22 14:21           ` john cooper
2009-09-22 14:27             ` Avi Kivity
2009-09-22 14:41               ` Michael S. Tsirkin
2009-09-22 14:45                 ` Avi Kivity
2009-09-22 15:09               ` john cooper
2009-09-23  1:59                 ` Anthony Liguori
2009-09-23  4:56                   ` john cooper
2009-09-29  6:09                     ` [Qemu-devel] [PATCH 0/2] fix virtio_blk serial pci config breakage john cooper
2009-09-29  6:58                       ` [Qemu-devel] " Michael S. Tsirkin
2009-09-29  7:22                         ` Avi Kivity
2009-09-29  8:54                           ` Michael S. Tsirkin
2009-09-29  9:16                             ` Avi Kivity
2009-09-29 13:55                             ` Anthony Liguori
2009-09-29 14:06                               ` Michael S. Tsirkin
2009-09-29 14:14                                 ` Anthony Liguori
2009-09-29 16:24                                   ` Avi Kivity
2009-09-29 16:30                                   ` Michael S. Tsirkin
2009-09-29 17:26                                     ` Anthony Liguori
2009-09-29 17:31                                       ` Michael S. Tsirkin
2009-09-29 17:28                               ` Rusty Russell
2009-09-29 17:31                                 ` Anthony Liguori
2009-09-30  1:12                                   ` Rusty Russell
2009-09-30  1:22                                     ` Jamie Lokier
2009-10-05 15:44                                     ` john cooper
2009-09-29 18:44                               ` john cooper
2009-09-29 20:55                                 ` Anthony Liguori
2009-09-30  1:19                                   ` Rusty Russell
2009-09-30  2:17                                     ` Anthony Liguori
2009-09-30 12:00                                       ` Rusty Russell
2009-09-30 18:04                                         ` Jamie Lokier
2009-10-05 15:41                                           ` john cooper
2009-09-30 11:47                                   ` Paul Brook
2009-10-05 15:40                                     ` john cooper
2009-09-29 13:51                       ` Anthony Liguori
2009-09-29 16:22                         ` Avi Kivity
2009-09-29 17:24                           ` Anthony Liguori
2009-09-29  6:09                     ` [Qemu-devel] [PATCH 1/2] " john cooper
2009-09-29  9:01                       ` [Qemu-devel] " Michael S. Tsirkin
2009-10-05 15:47                       ` [Qemu-devel] [PATCH] fix virtio_blk serial pci config breakage, v2 john cooper
2009-10-05 19:54                         ` [Qemu-devel] " Michael S. Tsirkin
2009-10-07  5:49                           ` john cooper
2009-10-07 13:48                             ` Anthony Liguori
2009-10-07 13:52                               ` Michael S. Tsirkin
2009-10-07 13:55                                 ` Anthony Liguori
2009-10-07 15:38                                   ` john cooper
2009-10-05 20:15                         ` Michael S. Tsirkin
2009-10-06 14:23                         ` Anthony Liguori
2009-09-29  6:10                     ` john cooper [this message]
2009-09-29  6:57                       ` [Qemu-devel] Re: [PATCH 2/2] fix virtio_blk serial pci config breakage Michael S. Tsirkin
2009-09-29 17:14                       ` Rusty Russell
2009-09-14 11:39   ` [Qemu-devel] Re: [PATCH] qemu: make virtio-blk PCI compliant by default Michael S. Tsirkin
2009-09-15  7:29     ` john cooper
2009-09-22  5:06     ` Rusty Russell

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=4AC1A4C7.1090809@redhat.com \
    --to=john.cooper@redhat.com \
    --cc=avi@redhat.com \
    --cc=jens.axboe@oracle.com \
    --cc=john.cooper@third-harmonic.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rusty@rustcorp.com.au \
    --cc=vrozenfe@redhat.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).