From 786dae23c6b9aa369fd37eef78d8dcb02f214f4f Mon Sep 17 00:00:00 2001 From: "He, Yue" Date: Fri, 20 Sep 2024 08:35:13 +0000 Subject: [PATCH] Add support the VM3 screen cast VM3 dgpu passthrough, after probe ivshm, gralloc will deem it as QNX case. Check if the first render node is dGPU and first virtiogpu is ivshm, it is dgpu + ivshm case. Tracked-On: OAM-124710 Signed-off-by: He, Yue --- cros_gralloc/cros_gralloc_driver.cc | 40 +++++++++++++++++------------ drv.c | 12 +++++++++ drv.h | 2 ++ drv_priv.h | 1 + i915.c | 7 +++++ virtgpu_virgl.c | 2 +- 6 files changed, 46 insertions(+), 18 deletions(-) diff --git a/cros_gralloc/cros_gralloc_driver.cc b/cros_gralloc/cros_gralloc_driver.cc index 00747e8..99bcfe9 100644 --- a/cros_gralloc/cros_gralloc_driver.cc +++ b/cros_gralloc/cros_gralloc_driver.cc @@ -310,14 +310,6 @@ cros_gralloc_driver::cros_gralloc_driver() drv_kms_ = drv_render_; } - if (ivshm_node_idx != -1) { - if (!(drv_ivshmem_ = drv_create(node_fd[ivshm_node_idx]))) { - drv_loge("Failed to create driver for the ivshm device with card id %d\n", - ivshm_node_idx); - close(node_fd[ivshm_node_idx]); - } - } - // Init drv DRV_INIT(drv_render_, gpu_grp_type_, renderer_idx) if (video_idx != renderer_idx) @@ -326,25 +318,39 @@ cros_gralloc_driver::cros_gralloc_driver() DRV_INIT(drv_kms_, gpu_grp_type_, virtio_node_idx) if (drv_kms_ && (virtio_node_idx != renderer_idx) && (drv_kms_ != drv_render_)) { bool virtiopic_with_blob = drv_virtpci_with_blob(drv_kms_); - // The virtio pci device with blob feature could import buffers - // from i915, otherwise need use virtio to allocate scanout - // non-video buffers. if (virtiopic_with_blob) { + //igpu SRIOV or dGPU SRIOV case drv_logi("Virtio gpu device with blob\n"); if ((drv_kms_ != drv_render_) && drv_kms_) DRV_DESTROY(drv_kms_) drv_kms_ = drv_render_; + } else if (drv_is_dgpu(drv_video_) && drv_virtgpu_is_ivshm(drv_kms_)){ + //is dgpu passthrough + ivshm case + drv_logi("dGPU with Virtio ivshm\n"); + drv_ivshmem_ = drv_kms_; + drv_kms_ = drv_render_; + if (ivshm_node_idx != -1) { + close(node_fd[ivshm_node_idx]); + ivshm_node_idx = -1; + } } else { - drv_logi("Virtio ivshmem device or no blob\n"); + // is QNX or redhat case + drv_logi("Virtio ivshm or no blob\n"); } } if (ivshm_node_idx != -1) { - DRV_INIT(drv_ivshmem_, gpu_grp_type_, ivshm_node_idx) - if (drv_virtgpu_is_ivshm(drv_ivshmem_)) { - drv_logi("Node is virtio-ivishmem node"); + if (!(drv_ivshmem_ = drv_create(node_fd[ivshm_node_idx]))) { + drv_loge("Failed to create driver for the ivshm device with card id %d\n", + ivshm_node_idx); + close(node_fd[ivshm_node_idx]); } else { - drv_logi("Node is NOT virtio-ivishmem node"); - DRV_DESTROY(drv_ivshmem_) + DRV_INIT(drv_ivshmem_, gpu_grp_type_, ivshm_node_idx) + if (drv_virtgpu_is_ivshm(drv_ivshmem_)) { + drv_logi("Node is virtio-ivishmem node"); + } else { + drv_logi("Node is NOT virtio-ivishmem node"); + DRV_DESTROY(drv_ivshmem_) + } } } } diff --git a/drv.c b/drv.c index 43a430d..fdf2478 100644 --- a/drv.c +++ b/drv.c @@ -857,3 +857,15 @@ bool drv_virtgpu_is_ivshm(struct driver * drv) } return ret; } + +bool drv_is_dgpu(struct driver * drv) +{ + bool ret = false; + assert(drv); + assert(drv->backend); + + if (drv->backend->is_dgpu) { + ret = drv->backend->is_dgpu(drv); + } + return ret; +} diff --git a/drv.h b/drv.h index 834f2d8..3614e2e 100644 --- a/drv.h +++ b/drv.h @@ -254,6 +254,8 @@ bool drv_virtpci_with_blob(struct driver * drv); bool drv_virtgpu_is_ivshm(struct driver * drv); +bool drv_is_dgpu(struct driver * drv); + enum drv_log_level { DRV_LOGV, DRV_LOGD, diff --git a/drv_priv.h b/drv_priv.h index 9a38f49..488bbc3 100644 --- a/drv_priv.h +++ b/drv_priv.h @@ -108,6 +108,7 @@ struct backend { uint32_t (*get_max_texture_2d_size)(struct driver *drv); bool (*virtpci_with_blob)(struct driver *drv); bool (*virtgpu_is_ivshm)(struct driver *drv); + bool (*is_dgpu)(struct driver *drv); }; // clang-format off diff --git a/i915.c b/i915.c index da0008b..159be70 100644 --- a/i915.c +++ b/i915.c @@ -1429,6 +1429,12 @@ static int i915_bo_flush(struct bo *bo, struct mapping *mapping) return 0; } +static bool i915_is_dgpu(struct driver *drv) +{ + struct i915_device *i915 = drv->priv; + return i915->has_local_mem; +} + const struct backend backend_i915 = { .name = "i915", .init = i915_init, @@ -1443,6 +1449,7 @@ const struct backend backend_i915 = { .bo_flush = i915_bo_flush, .resolve_format_and_use_flags = drv_resolve_format_and_use_flags_helper, .num_planes_from_modifier = i915_num_planes_from_modifier, + .is_dgpu = i915_is_dgpu, }; #endif diff --git a/virtgpu_virgl.c b/virtgpu_virgl.c index f969e64..0509d69 100644 --- a/virtgpu_virgl.c +++ b/virtgpu_virgl.c @@ -1185,7 +1185,7 @@ static bool virgl_virtpci_with_blob(struct driver *drv) { static bool virgl_drv_virtgpu_is_ivshm(struct driver *drv) { struct virgl_priv *prv = (struct virgl_priv *)drv->priv; - return !(prv->dev_feature & VIRTGPU_PARAM_QUERY_DEV_BIT); + return (!(prv->dev_feature & VIRTGPU_PARAM_QUERY_DEV_BIT) && (prv->dev_feature & VIRTGPU_PARAM_RESOURCE_BLOB_BIT)); } const struct backend virtgpu_virgl = { .name = "virtgpu_virgl",