Skip to content

Commit

Permalink
Add the function to check virtio features
Browse files Browse the repository at this point in the history
If virtio-gpu with blob feature, close drv_kms_.

Signed-off-by: He, Yue <yue.he@intel.com>
  • Loading branch information
yhe39 committed Aug 9, 2024
1 parent a3c4d12 commit 52724c1
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 1 deletion.
14 changes: 14 additions & 0 deletions cros_gralloc/cros_gralloc_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,20 @@ cros_gralloc_driver::cros_gralloc_driver()
close(fd);
drv_kms_ = nullptr;
}
if (drv_kms_) {
bool virtiogpu_with_blob = drv_query_dev_feature(drv_kms_);
if (virtiogpu_with_blob) {
drv_logi("virtio gpu device with blob\n");
if (drv_kms_) {
int fd = drv_get_fd(drv_kms_);
drv_destroy(drv_kms_);
drv_kms_ = drv_render_;
close(fd);
}
} else {
drv_logi("virtio ivshmem device or no blob\n");
}
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,3 +833,15 @@ uint32_t drv_get_max_texture_2d_size(struct driver *drv)

return UINT32_MAX;
}

bool drv_query_dev_feature(struct driver * drv)
{
bool ret = false;
assert(drv);
assert(drv->backend);

if (drv->backend->query_dev_feature) {
ret = drv->backend->query_dev_feature();
}
return ret;
}
2 changes: 2 additions & 0 deletions drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ int drv_resource_info(struct bo *bo, uint32_t strides[DRV_MAX_PLANES],

uint32_t drv_get_max_texture_2d_size(struct driver *drv);

bool drv_query_dev_feature(struct driver * drv);

enum drv_log_level {
DRV_LOGV,
DRV_LOGD,
Expand Down
1 change: 1 addition & 0 deletions drv_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ struct backend {
int (*resource_info)(struct bo *bo, uint32_t strides[DRV_MAX_PLANES],
uint32_t offsets[DRV_MAX_PLANES], uint64_t *format_modifier);
uint32_t (*get_max_texture_2d_size)(struct driver *drv);
bool (*query_dev_feature)();
};

// clang-format off
Expand Down
1 change: 1 addition & 0 deletions external/virtgpu_drm.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ struct drm_virtgpu_execbuffer {
#define VIRTGPU_PARAM_CREATE_GUEST_HANDLE 8 /* Host OS handle can be created from guest memory. */
#define VIRTGPU_PARAM_RESOURCE_SYNC 9 /* Synchronization resources */
#define VIRTGPU_PARAM_GUEST_VRAM 10 /* All guest allocations happen via virtgpu dedicated heap. */
#define VIRTGPU_PARAM_QUERY_DEV 11 /* Query the virtio device name. */

struct drm_virtgpu_getparam {
__u64 param;
Expand Down
11 changes: 11 additions & 0 deletions virtgpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ struct virtgpu_param params[] = {
PARAM(VIRTGPU_PARAM_CROSS_DEVICE), PARAM(VIRTGPU_PARAM_CONTEXT_INIT),
PARAM(VIRTGPU_PARAM_SUPPORTED_CAPSET_IDs), PARAM(VIRTGPU_PARAM_CREATE_GUEST_HANDLE),
PARAM(VIRTGPU_PARAM_RESOURCE_SYNC), PARAM(VIRTGPU_PARAM_GUEST_VRAM),
PARAM(VIRTGPU_PARAM_QUERY_DEV),
};

extern const struct backend virtgpu_virgl;
extern const struct backend virtgpu_cross_domain;

int dev_feature = 0;

static int virtgpu_init(struct driver *drv)
{
int ret = 0;
Expand All @@ -49,6 +52,14 @@ static int virtgpu_init(struct driver *drv)
int ret = drmIoctl(drv->fd, DRM_IOCTL_VIRTGPU_GETPARAM, &get_param);
if (ret)
drv_logi("virtgpu backend not enabling %s\n", params[i].name);
if (ret == 0) {
if (strcmp(params[i].name, "VIRTGPU_PARAM_QUERY_DEV") == 0) {
dev_feature += params[i].value;
}
if (strcmp(params[i].name, "VIRTGPU_PARAM_RESOURCE_BLOB") == 0) {
dev_feature += params[i].value;
}
}
}

for (uint32_t i = 0; i < ARRAY_SIZE(virtgpu_backends); i++) {
Expand Down
2 changes: 2 additions & 0 deletions virtgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ enum virtgpu_param_id {
param_guest_vram,
param_max,
};

extern int dev_feature;
7 changes: 6 additions & 1 deletion virtgpu_virgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,10 @@ static uint32_t virgl_get_max_texture_2d_size(struct driver *drv)
return VIRGL_2D_MAX_TEXTURE_2D_SIZE;
}

static bool virgl_query_dev_feature() {
return (dev_feature == 2);
}

const struct backend virtgpu_virgl = { .name = "virtgpu_virgl",
.init = virgl_init,
.close = virgl_close,
Expand All @@ -1171,4 +1175,5 @@ const struct backend virtgpu_virgl = { .name = "virtgpu_virgl",
.resolve_format_and_use_flags =
virgl_resolve_format_and_use_flags,
.resource_info = virgl_resource_info,
.get_max_texture_2d_size = virgl_get_max_texture_2d_size };
.get_max_texture_2d_size = virgl_get_max_texture_2d_size,
.query_dev_feature = virgl_query_dev_feature };

0 comments on commit 52724c1

Please sign in to comment.