Skip to content

Commit

Permalink
drm/virtio: Ensure framebuffers for dGPU residing in local memory
Browse files Browse the repository at this point in the history
Leverage the new fields in dmabuf attachment to obtained information
about the imported buffers. In atomic check, we must return an error
when the user space is trying to present a framebuffer in system memory
(without DMABUF_ATTACH_FLAG_LMEM being set) on discrete GPU backing
display.

Tracked-On: OAM-129610
Signed-off-by: Weifeng Liu <[email protected]>
  • Loading branch information
phreer committed Feb 24, 2025
1 parent 5f92a9e commit 2a826f4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions drivers/gpu/drm/virtio/virtgpu_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <linux/dma-buf.h>
#include <linux/dma-mapping.h>
#include <linux/moduleparam.h>

Expand Down
23 changes: 22 additions & 1 deletion drivers/gpu/drm/virtio/virtgpu_plane.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <linux/dma-buf.h>

#include <drm/drm_atomic_helper.h>
#include <drm/drm_damage_helper.h>
#include <drm/drm_fourcc.h>
Expand Down Expand Up @@ -264,6 +266,26 @@ static int virtio_gpu_plane_atomic_check(struct drm_plane *plane,
if (IS_ERR(crtc_state))
return PTR_ERR(crtc_state);

/* Ensure lmem objects from i915_ag are attached to dGPU backing CRTC */
if (vgdev->output_cap_mask & (1lu << drm_crtc_index(new_plane_state->crtc))) {
for (int i = 0; i < DRM_FORMAT_MAX_PLANES; ++i) {
struct drm_gem_object *obj = new_plane_state->fb->obj[i];
if (!obj)
break;

if (!obj->import_attach)
return -EINVAL;

if (!(obj->import_attach->flags & DMABUF_ATTACH_FLAG_LMEM)) {
drm_dbg(vgdev->ddev, "cannot use non-i915_ag "
"buffer for crtc %u, driver name %s\n",
drm_crtc_index(new_plane_state->crtc),
obj->dev->driver->name);
return -EINVAL;
}
}
}

if(vgdev->has_scaling && (new_plane_state->fb->format->format != DRM_FORMAT_C8)) {
min_scale = 1;
max_scale = 0x30000-1;
Expand Down Expand Up @@ -322,7 +344,6 @@ static void virtio_gpu_resource_flush(struct drm_plane *plane,
struct virtio_gpu_object *bo;
struct virtio_gpu_object_array *objs = NULL;
struct virtio_gpu_fence *fence = NULL;
int i;

vgfb = to_virtio_gpu_framebuffer(plane->state->fb);
bo = gem_to_virtio_gpu_obj(vgfb->base.obj[0]);
Expand Down
5 changes: 3 additions & 2 deletions drivers/gpu/drm/virtio/virtgpu_prime.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ struct drm_gem_object *virtgpu_gem_prime_import(struct drm_device *dev,
}
spin_unlock(&dma_buf->name_lock);

attach = ____dma_buf_dynamic_attach(dma_buf, attach_dev, NULL, NULL,
p2p);
attach = ____dma_buf_dynamic_attach(dma_buf, attach_dev,
DMA_BUF_DRIVER_TYPE_ID_VIRTIO_GPU,
0, NULL, NULL, p2p);
if (IS_ERR(attach))
return ERR_CAST(attach);

Expand Down

0 comments on commit 2a826f4

Please sign in to comment.