提交 46728d73 编写于 作者: J Jason Wang 提交者: Pengyuan Zhao

virtio-pci library: report resource address

stable inclusion
from stable-v5.13
commit 9e311bca
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5WXCZ
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=9e311bcad73dc14bd0a736db6ad3d382227e11fe

----------------------------------------------------------------------

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: NJason Wang <jasowang@redhat.com>
Link: https://lore.kernel.org/r/20210415073147.19331-7-jasowang@redhat.comSigned-off-by: NMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: NPengyuan Zhao <zhaopengyuan@hisilicon.com>
上级 d831d8a7
......@@ -423,7 +423,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;
......
......@@ -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;
......
......@@ -13,6 +13,7 @@
* @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
*/
......@@ -20,7 +21,7 @@ void __iomem *vp_modern_map_capability(struct virtio_pci_modern_device *mdev, in
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;
......@@ -88,6 +89,10 @@ void __iomem *vp_modern_map_capability(struct virtio_pci_modern_device *mdev, in
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;
}
EXPORT_SYMBOL_GPL(vp_modern_map_capability);
......@@ -275,12 +280,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;
......@@ -308,7 +313,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 {
......@@ -321,7 +327,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;
}
......@@ -598,11 +605,12 @@ EXPORT_SYMBOL_GPL(vp_modern_get_queue_notify_off);
* 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);
......@@ -617,13 +625,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);
......
......@@ -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;
......@@ -105,9 +107,9 @@ void __iomem *vp_modern_map_capability(struct virtio_pci_modern_device *mdev, in
size_t minlen,
u32 align,
u32 start, u32 size,
size_t *len);
size_t *len, resource_size_t *pa);
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册