From: Jason Wang <jasowang@redhat.com>
To: mst@redhat.com, jasowang@redhat.com
Cc: virtualization@lists.linux-foundation.org,
linux-kernel@vger.kernel.org, elic@nvidia.com
Subject: [PATCH 6/7] virtio-pci library: report resource address
Date: Thu, 15 Apr 2021 03:31:46 -0400 [thread overview]
Message-ID: <20210415073147.19331-7-jasowang@redhat.com> (raw)
In-Reply-To: <20210415073147.19331-1-jasowang@redhat.com>
Sometimes it might be useful to report the capability physical
address. One example is to report the physical address of the doorbell
in order to be mapped by userspace.
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
drivers/vdpa/virtio_pci/vp_vdpa.c | 3 ++-
drivers/virtio/virtio_pci_modern.c | 2 +-
drivers/virtio/virtio_pci_modern_dev.c | 24 +++++++++++++++++-------
include/linux/virtio_pci_modern.h | 4 +++-
4 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c
index 2afc90645660..98205e54d089 100644
--- a/drivers/vdpa/virtio_pci/vp_vdpa.c
+++ b/drivers/vdpa/virtio_pci/vp_vdpa.c
@@ -415,7 +415,8 @@ static int vp_vdpa_probe(struct pci_dev *pdev, const struct pci_device_id *id)
for (i = 0; i < vp_vdpa->queues; i++) {
vp_vdpa->vring[i].irq = VIRTIO_MSI_NO_VECTOR;
- vp_vdpa->vring[i].notify = vp_modern_map_vq_notify(mdev, i);
+ vp_vdpa->vring[i].notify =
+ vp_modern_map_vq_notify(mdev, i, NULL);
if (!vp_vdpa->vring[i].notify) {
dev_warn(&pdev->dev, "Fail to map vq notify %d\n", i);
goto err;
diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c
index 29607d9bd95c..722ea44e7579 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -224,7 +224,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
virtqueue_get_avail_addr(vq),
virtqueue_get_used_addr(vq));
- vq->priv = vp_modern_map_vq_notify(mdev, index);
+ vq->priv = vp_modern_map_vq_notify(mdev, index, NULL);
if (!vq->priv) {
err = -ENOMEM;
goto err_map_notify;
diff --git a/drivers/virtio/virtio_pci_modern_dev.c b/drivers/virtio/virtio_pci_modern_dev.c
index 9c241c9bd920..ae87b3fa8858 100644
--- a/drivers/virtio/virtio_pci_modern_dev.c
+++ b/drivers/virtio/virtio_pci_modern_dev.c
@@ -13,13 +13,14 @@
* @start: start from the capability
* @size: map size
* @len: the length that is actually mapped
+ * @pa: physical address of the capability
*
* Returns the io address of for the part of the capability
*/
static void __iomem *
vp_modern_map_capability(struct virtio_pci_modern_device *mdev, int off,
size_t minlen, u32 align, u32 start, u32 size,
- size_t *len)
+ size_t *len, resource_size_t *pa)
{
struct pci_dev *dev = mdev->pci_dev;
u8 bar;
@@ -87,6 +88,9 @@ vp_modern_map_capability(struct virtio_pci_modern_device *mdev, int off,
dev_err(&dev->dev,
"virtio_pci: unable to map virtio %u@%u on bar %i\n",
length, offset, bar);
+ else if (pa)
+ *pa = pci_resource_start(dev, bar) + offset;
+
return p;
}
@@ -273,12 +277,12 @@ int vp_modern_probe(struct virtio_pci_modern_device *mdev)
mdev->common = vp_modern_map_capability(mdev, common,
sizeof(struct virtio_pci_common_cfg), 4,
0, sizeof(struct virtio_pci_common_cfg),
- NULL);
+ NULL, NULL);
if (!mdev->common)
goto err_map_common;
mdev->isr = vp_modern_map_capability(mdev, isr, sizeof(u8), 1,
0, 1,
- NULL);
+ NULL, NULL);
if (!mdev->isr)
goto err_map_isr;
@@ -306,7 +310,8 @@ int vp_modern_probe(struct virtio_pci_modern_device *mdev)
mdev->notify_base = vp_modern_map_capability(mdev, notify,
2, 2,
0, notify_length,
- &mdev->notify_len);
+ &mdev->notify_len,
+ &mdev->notify_pa);
if (!mdev->notify_base)
goto err_map_notify;
} else {
@@ -319,7 +324,8 @@ int vp_modern_probe(struct virtio_pci_modern_device *mdev)
if (device) {
mdev->device = vp_modern_map_capability(mdev, device, 0, 4,
0, PAGE_SIZE,
- &mdev->device_len);
+ &mdev->device_len,
+ NULL);
if (!mdev->device)
goto err_map_device;
}
@@ -595,11 +601,12 @@ static u16 vp_modern_get_queue_notify_off(struct virtio_pci_modern_device *mdev,
* specific virtqueue
* @mdev: the modern virtio-pci device
* @index: the queue index
+ * @pa: the pointer to the physical address of the nofity area
*
* Returns the address of the notification area
*/
void *vp_modern_map_vq_notify(struct virtio_pci_modern_device *mdev,
- u16 index)
+ u16 index, resource_size_t *pa)
{
u16 off = vp_modern_get_queue_notify_off(mdev, index);
@@ -614,13 +621,16 @@ void *vp_modern_map_vq_notify(struct virtio_pci_modern_device *mdev,
index, mdev->notify_len);
return NULL;
}
+ if (pa)
+ *pa = mdev->notify_pa +
+ off * mdev->notify_offset_multiplier;
return (void __force *)mdev->notify_base +
off * mdev->notify_offset_multiplier;
} else {
return (void __force *)vp_modern_map_capability(mdev,
mdev->notify_map_cap, 2, 2,
off * mdev->notify_offset_multiplier, 2,
- NULL);
+ NULL, pa);
}
}
EXPORT_SYMBOL_GPL(vp_modern_map_vq_notify);
diff --git a/include/linux/virtio_pci_modern.h b/include/linux/virtio_pci_modern.h
index e6e7072413c1..cdfabbefacdf 100644
--- a/include/linux/virtio_pci_modern.h
+++ b/include/linux/virtio_pci_modern.h
@@ -13,6 +13,8 @@ struct virtio_pci_modern_device {
void __iomem *device;
/* Base of vq notifications (non-legacy mode). */
void __iomem *notify_base;
+ /* Physical base of vq notifications */
+ resource_size_t notify_pa;
/* Where to read and clear interrupt */
u8 __iomem *isr;
@@ -100,7 +102,7 @@ u16 vp_modern_get_queue_size(struct virtio_pci_modern_device *mdev,
u16 idx);
u16 vp_modern_get_num_queues(struct virtio_pci_modern_device *mdev);
void *vp_modern_map_vq_notify(struct virtio_pci_modern_device *mdev,
- u16 index);
+ u16 index, resource_size_t *pa);
int vp_modern_probe(struct virtio_pci_modern_device *mdev);
void vp_modern_remove(struct virtio_pci_modern_device *mdev);
#endif
--
2.18.1
next prev parent reply other threads:[~2021-04-15 7:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-15 7:31 [PATCH 0/7] Doorbell mapping support for virito-pci vDPA Jason Wang
2021-04-15 7:31 ` [PATCH 1/7] virtio_pci_modern: introduce helper to map vq notify area Jason Wang
2021-04-21 7:44 ` Eli Cohen
2021-04-15 7:31 ` [PATCH 2/7] virtio-pci library: switch to use vp_modern_map_vq_notify() Jason Wang
2021-04-21 7:44 ` Eli Cohen
2021-04-15 7:31 ` [PATCH 3/7] vp_vdpa: " Jason Wang
2021-04-21 7:45 ` Eli Cohen
2021-04-15 7:31 ` [PATCH 4/7] virtio_pci_modern: hide vp_modern_get_queue_notify_off() Jason Wang
2021-04-21 7:45 ` Eli Cohen
2021-04-15 7:31 ` [PATCH 5/7] virito_pci libray: hide vp_modern_map_capability() Jason Wang
2021-04-21 7:46 ` Eli Cohen
2021-04-15 7:31 ` Jason Wang [this message]
2021-04-15 7:31 ` [PATCH 7/7] vp_vdpa: report doorbell address Jason Wang
2021-04-21 7:46 ` Eli Cohen
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=20210415073147.19331-7-jasowang@redhat.com \
--to=jasowang@redhat.com \
--cc=elic@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=virtualization@lists.linux-foundation.org \
/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