Skip to content

Commit

Permalink
drm/virtio: Ensure lmem objects are used for dGPU backing CRTC
Browse files Browse the repository at this point in the history
Use atomic check hook to ensure the framebuffers we are going to set
satisfy the requirement for dGPU.

Tracked-On: OAM-129610
Signed-off-by: Weifeng Liu <[email protected]>
  • Loading branch information
phreer committed Jan 22, 2025
1 parent 724697d commit 73bd572
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions 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 @@ -237,13 +239,26 @@ static int virtio_gpu_check_plane_scaling(struct drm_plane_state *state,
return 0;
}

#define I915_AG_DMABUF_ATTACHMENT_CURRENT_VERSION (1)
#define I915_AG_DMABUF_ATTACHMENT_LMEM (1lu << 0)

struct i915_ag_dmabuf_attachment_priv {
uint32_t version;
union {
struct {
uint32_t flags;
} v1;
} shared;
};

static int virtio_gpu_plane_atomic_check(struct drm_plane *plane,
struct drm_atomic_state *state)
{
struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
plane);
struct drm_device *dev = plane->dev;
struct virtio_gpu_device *vgdev = dev->dev_private;
struct i915_ag_dmabuf_attachment_priv *i915_priv = NULL;
bool is_cursor = 1;
struct virtio_gpu_output *output = NULL;
output = drm_crtc_to_virtio_gpu_output(new_plane_state->crtc);
Expand All @@ -264,6 +279,44 @@ 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;

#define I915_AG_MODULE_NAME "i915_ag"
if (strncmp(obj->import_attach->dmabuf->exp_name, I915_AG_MODULE_NAME,
strlen(I915_AG_MODULE_NAME)) != 0) {
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;
}
#undef I915_AG_MODULE_NAME

i915_priv = obj->import_attach->priv;
if (!i915_priv) {
drm_dbg(vgdev->ddev, "unsupported i915_ag dmabuf attachment\n");
return -EINVAL;
}
if (i915_priv->version != I915_AG_DMABUF_ATTACHMENT_CURRENT_VERSION) {
drm_dbg(vgdev->ddev, "unsupported i915_ag dmabuf attachment "
"version %u\n", i915_priv->version);
return -EINVAL;
}
if (!(i915_priv->shared.v1.flags & I915_AG_DMABUF_ATTACHMENT_LMEM)) {
drm_dbg(vgdev->ddev, "not local memory from i915_ag\n");
return -EINVAL;
}
}
}

if(vgdev->has_scaling && (new_plane_state->fb->format->format != DRM_FORMAT_C8)) {
min_scale = 1;
max_scale = 0x30000-1;
Expand Down

0 comments on commit 73bd572

Please sign in to comment.