[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/3] drm/virtio: Implement device_attach
- To: David Airlie <airlied@xxxxxxxxxx>, Gerd Hoffmann <kraxel@xxxxxxxxxx>, Gurchetan Singh <gurchetansingh@xxxxxxxxxxxx>, Chia-I Wu <olvaffe@xxxxxxxxx>, <dri-devel@xxxxxxxxxxxxxxxxxxxxx>, <virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- From: Julia Zhang <julia.zhang@xxxxxxx>
- Date: Sat, 7 Dec 2024 18:50:26 +0800
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4ZkFtwcnYM2i/536XZMFv1NpvRLzNT6/8HZOgNw9APU=; b=IYYvzvc5qsR9GbQ0hGPfhNvHnebbOO5yTGBEPN1VZOqoGS8Nxw21XxNAmaVy+BqHlA6qnRCyMe9DD0z0cPEZaPrryUtEXUkdQKc9F6XFQDuVrWMSjcEuiZ0ykCxuN7oFd8au6/JPasHHzVXmzD8+NqNUzqyLBa7ZgBE9jshWQlwatA6jQIYYy/PYcq8t53Xijkx5vAOXR8w+EsSTAFDBARV+43DTHIvhGsXt5/WE8EvQUcERDuvuwhZCeJ7zJi2hgzpf2IKrb24sgdsNYiySnnbGoiATWBjgcssBQua9RHnhbgwQ556/ZX4RZGb7jgcA36C2v5sij/JiQWeJhPU+uQ==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=p0ySH/xYkkF4lPN3bgTVsYZ/pjYLaN59aqVfBy34DJt1UJSAoe8lZpePXZAyZP3ZLtJIYACtJUgLf8Fd/SjiMjS4f4Cdw2+FQQ910r7hW2Mt1JAyYUyk3T+UI8HXxCfxMcddWP9wow/NpfGHPSXjIhG7IfEcTp16U4TpVL2vnnEsyP2AJH5ifTJSDloLYdzJ5mRWwC2ZE7xe2Xw4TLCLp6mWdW9fU19CcMXiUfgd23fykpya5J60X+y6lGkjcsKDXe0S+UGXIUDgdNajOWiEV3/KzA3JmpMkV9rNdd7+uInd0yLOckylnhr4Nc+nOytaKLTIm2I965pHpas5qoHoGA==
- Cc: Alex Deucher <alexander.deucher@xxxxxxx>, Christian König <christian.koenig@xxxxxxx>, Daniel Vetter <daniel@xxxxxxxx>, Chen Jiqian <Jiqian.Chen@xxxxxxx>, Huang Rui <ray.huang@xxxxxxx>, Penny Zheng <penny.zheng@xxxxxxx>, Zhu Lingshan <Lingshan.Zhu@xxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Paul Durrant <paul@xxxxxxx>, Julia Zhang <julia.zhang@xxxxxxx>
- Delivery-date: Sat, 07 Dec 2024 10:53:55 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
As vram objects may be imported by other gpu drivers, peer2peer flag
should be checked in dma_buf_ops->attach(). This reimplement virtio gpu
dma_buf_ops->attach by adding a device_attach() function for virtio gpu.
This function will get pci_p2pdma_distance and check attach->peer2peer
before calling drm_gem_map_attach().
Signed-off-by: Julia Zhang <julia.zhang@xxxxxxx>
---
drivers/gpu/drm/virtio/virtgpu_prime.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/virtio/virtgpu_prime.c
b/drivers/gpu/drm/virtio/virtgpu_prime.c
index 4960620eba02..4f6bce79e10e 100644
--- a/drivers/gpu/drm/virtio/virtgpu_prime.c
+++ b/drivers/gpu/drm/virtio/virtgpu_prime.c
@@ -116,6 +116,18 @@ static int virtgpu_get_p2pdma_distance(struct dma_buf
*dma_buf,
return 0;
}
+static int virtgpu_gem_device_attach(struct dma_buf *dma_buf,
+ struct dma_buf_attachment *attach)
+{
+ int ret = virtgpu_get_p2pdma_distance(dma_buf, attach);
+ if (ret)
+ return ret;
+ if (!attach->peer2peer)
+ return -EBUSY;
+
+ return drm_gem_map_attach(dma_buf, attach);
+}
+
static const struct virtio_dma_buf_ops virtgpu_dmabuf_ops = {
.ops = {
.cache_sgt_mapping = true,
@@ -128,7 +140,7 @@ static const struct virtio_dma_buf_ops virtgpu_dmabuf_ops =
{
.vmap = drm_gem_dmabuf_vmap,
.vunmap = drm_gem_dmabuf_vunmap,
},
- .device_attach = drm_gem_map_attach,
+ .device_attach = virtgpu_gem_device_attach,
.get_uuid = virtgpu_virtio_get_uuid,
};
--
2.34.1
|