Skip to content

Commit 485e908

Browse files
yhe39sysopenci
authored andcommitted
Add the function to check virtio features
If it is virtio-gpu with blob, close drv_kms_. use i915 to allocate all buffers. Otherwise use drv_kms_ to allocat scanout non-video buffers. Test Done: 1. Android VM boot without issue. 2. Android display well on QNX. 3. Video playback without issue. Tracked-On: OAM-119826 Signed-off-by: Weifeng Liu <weifeng.liu@intel.com> Signed-off-by: He, Yue <yue.he@intel.com>
1 parent 60e0772 commit 485e908

8 files changed

Lines changed: 97 additions & 18 deletions

File tree

cros_gralloc/cros_gralloc_driver.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,20 @@ cros_gralloc_driver::cros_gralloc_driver()
268268
DRV_INIT(drv_video_, gpu_grp_type, video_idx)
269269
if ((virtio_node_idx != -1) && (virtio_node_idx != renderer_idx))
270270
DRV_INIT(drv_kms_, gpu_grp_type, virtio_node_idx)
271+
if (drv_kms_ && (virtio_node_idx != renderer_idx)) {
272+
bool virtiopic_with_blob = drv_virtpci_with_blob(drv_kms_);
273+
// The virtio pci device with blob feature could import buffers
274+
// from i915, otherwise need use virtio to allocate scanout
275+
// non-video buffers.
276+
if (virtiopic_with_blob) {
277+
drv_logi("virtio gpu device with blob\n");
278+
if ((drv_kms_ != drv_render_) && drv_kms_)
279+
DRV_DESTROY(drv_kms_)
280+
drv_kms_ = drv_render_;
281+
} else {
282+
drv_logi("virtio ivshmem device or no blob\n");
283+
}
284+
}
271285
}
272286

273287
for (int i = 0; i < availabe_node; i++) {

drv.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,3 +833,15 @@ uint32_t drv_get_max_texture_2d_size(struct driver *drv)
833833

834834
return UINT32_MAX;
835835
}
836+
837+
bool drv_virtpci_with_blob(struct driver * drv)
838+
{
839+
bool ret = false;
840+
assert(drv);
841+
assert(drv->backend);
842+
843+
if (drv->backend->virtpci_with_blob) {
844+
ret = drv->backend->virtpci_with_blob(drv);
845+
}
846+
return ret;
847+
}

drv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ int drv_resource_info(struct bo *bo, uint32_t strides[DRV_MAX_PLANES],
251251

252252
uint32_t drv_get_max_texture_2d_size(struct driver *drv);
253253

254+
bool drv_virtpci_with_blob(struct driver * drv);
255+
254256
enum drv_log_level {
255257
DRV_LOGV,
256258
DRV_LOGD,

drv_priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ struct backend {
111111
int (*resource_info)(struct bo *bo, uint32_t strides[DRV_MAX_PLANES],
112112
uint32_t offsets[DRV_MAX_PLANES], uint64_t *format_modifier);
113113
uint32_t (*get_max_texture_2d_size)(struct driver *drv);
114+
bool (*virtpci_with_blob)(struct driver *drv);
114115
};
115116

116117
// clang-format off

external/virtgpu_drm.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,19 @@ struct drm_virtgpu_execbuffer {
8585
#define VIRTGPU_PARAM_CREATE_GUEST_HANDLE 8 /* Host OS handle can be created from guest memory. */
8686
#define VIRTGPU_PARAM_RESOURCE_SYNC 9 /* Synchronization resources */
8787
#define VIRTGPU_PARAM_GUEST_VRAM 10 /* All guest allocations happen via virtgpu dedicated heap. */
88+
#define VIRTGPU_PARAM_QUERY_DEV 11 /* Query the virtio device name. */
89+
90+
#define VIRTGPU_PARAM_3D_FEATURES_BIT (1ull << VIRTGPU_PARAM_3D_FEATURES)
91+
#define VIRTGPU_PARAM_CAPSET_QUERY_FIX_BIT (1ull << VIRTGPU_PARAM_CAPSET_QUERY_FIX)
92+
#define VIRTGPU_PARAM_RESOURCE_BLOB_BIT (1ull << VIRTGPU_PARAM_RESOURCE_BLOB)
93+
#define VIRTGPU_PARAM_HOST_VISIBLE_BIT (1ull << VIRTGPU_PARAM_HOST_VISIBLE)
94+
#define VIRTGPU_PARAM_CROSS_DEVICE_BIT (1ull << VIRTGPU_PARAM_CROSS_DEVICE)
95+
#define VIRTGPU_PARAM_CONTEXT_INIT_BIT (1ull << VIRTGPU_PARAM_CONTEXT_INIT)
96+
#define VIRTGPU_PARAM_SUPPORTED_CAPSET_IDs_BIT (1ull << VIRTGPU_PARAM_SUPPORTED_CAPSET_IDs)
97+
#define VIRTGPU_PARAM_CREATE_GUEST_HANDLE_BIT (1ull << VIRTGPU_PARAM_CREATE_GUEST_HANDLE)
98+
#define VIRTGPU_PARAM_RESOURCE_SYNC_BIT (1ull << VIRTGPU_PARAM_RESOURCE_SYNC)
99+
#define VIRTGPU_PARAM_GUEST_VRAM_BIT (1ull << VIRTGPU_PARAM_GUEST_VRAM)
100+
#define VIRTGPU_PARAM_QUERY_DEV_BIT (1ull << VIRTGPU_PARAM_QUERY_DEV)
88101

89102
struct drm_virtgpu_getparam {
90103
__u64 param;

virtgpu.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,6 @@
1616
#include "util.h"
1717
#include "virtgpu.h"
1818

19-
#define PARAM(x) \
20-
(struct virtgpu_param) \
21-
{ \
22-
x, #x, 0 \
23-
}
24-
25-
struct virtgpu_param params[] = {
26-
PARAM(VIRTGPU_PARAM_3D_FEATURES), PARAM(VIRTGPU_PARAM_CAPSET_QUERY_FIX),
27-
PARAM(VIRTGPU_PARAM_RESOURCE_BLOB), PARAM(VIRTGPU_PARAM_HOST_VISIBLE),
28-
PARAM(VIRTGPU_PARAM_CROSS_DEVICE), PARAM(VIRTGPU_PARAM_CONTEXT_INIT),
29-
PARAM(VIRTGPU_PARAM_SUPPORTED_CAPSET_IDs), PARAM(VIRTGPU_PARAM_CREATE_GUEST_HANDLE),
30-
PARAM(VIRTGPU_PARAM_RESOURCE_SYNC), PARAM(VIRTGPU_PARAM_GUEST_VRAM),
31-
};
32-
3319
extern const struct backend virtgpu_virgl;
3420
extern const struct backend virtgpu_cross_domain;
3521

virtgpu.h

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,32 @@
44
* found in the LICENSE file.
55
*/
66

7+
#ifndef __VIRTGPU_H__
8+
#define __VIRTGPU_H__
9+
10+
#include "drv_priv.h"
11+
#include "external/virtgpu_drm.h"
12+
#include "util.h"
13+
14+
#define PARAM(x) \
15+
(struct virtgpu_param) \
16+
{ \
17+
x, #x, 0 \
18+
}
19+
720
struct virtgpu_param {
8-
uint64_t param;
9-
const char *name;
10-
uint32_t value;
21+
uint64_t param;
22+
const char *name;
23+
uint32_t value;
24+
};
25+
26+
static struct virtgpu_param params[] = {
27+
PARAM(VIRTGPU_PARAM_3D_FEATURES), PARAM(VIRTGPU_PARAM_CAPSET_QUERY_FIX),
28+
PARAM(VIRTGPU_PARAM_RESOURCE_BLOB), PARAM(VIRTGPU_PARAM_HOST_VISIBLE),
29+
PARAM(VIRTGPU_PARAM_CROSS_DEVICE), PARAM(VIRTGPU_PARAM_CONTEXT_INIT),
30+
PARAM(VIRTGPU_PARAM_SUPPORTED_CAPSET_IDs), PARAM(VIRTGPU_PARAM_CREATE_GUEST_HANDLE),
31+
PARAM(VIRTGPU_PARAM_RESOURCE_SYNC), PARAM(VIRTGPU_PARAM_GUEST_VRAM),
32+
PARAM(VIRTGPU_PARAM_QUERY_DEV),
1133
};
1234

1335
enum virtgpu_param_id {
@@ -23,3 +45,5 @@ enum virtgpu_param_id {
2345
param_guest_vram,
2446
param_max,
2547
};
48+
49+
#endif

virtgpu_virgl.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct virgl_priv {
5858
union virgl_caps caps;
5959
int host_gbm_enabled;
6060
atomic_int next_blob_id;
61+
uint64_t dev_feature;
6162
};
6263

6364
static uint32_t translate_format(uint32_t drm_fourcc)
@@ -596,6 +597,26 @@ static int virgl_init(struct driver *drv)
596597

597598
virgl_init_params_and_caps(drv);
598599

600+
struct virgl_priv *prv = (struct virgl_priv *)drv->priv;
601+
602+
prv->dev_feature = 0;
603+
604+
for (uint32_t i = 0; i < ARRAY_SIZE(params); i++) {
605+
struct drm_virtgpu_getparam get_param = { 0 };
606+
607+
get_param.param = params[i].param;
608+
get_param.value = (uint64_t)(uintptr_t)&params[i].value;
609+
int ret = drmIoctl(drv->fd, DRM_IOCTL_VIRTGPU_GETPARAM, &get_param);
610+
if (ret == 0) {
611+
if ((strcmp(params[i].name, "VIRTGPU_PARAM_QUERY_DEV") == 0) && (params[i].value == 1)) {
612+
prv->dev_feature |= VIRTGPU_PARAM_QUERY_DEV_BIT;
613+
}
614+
if ((strcmp(params[i].name, "VIRTGPU_PARAM_RESOURCE_BLOB") == 0) && (params[i].value == 1)) {
615+
prv->dev_feature |= VIRTGPU_PARAM_RESOURCE_BLOB_BIT;
616+
}
617+
}
618+
}
619+
599620
if (params[param_3d].value) {
600621
/* This doesn't mean host can scanout everything, it just means host
601622
* hypervisor can show it. */
@@ -1157,6 +1178,11 @@ static uint32_t virgl_get_max_texture_2d_size(struct driver *drv)
11571178
return VIRGL_2D_MAX_TEXTURE_2D_SIZE;
11581179
}
11591180

1181+
static bool virgl_virtpci_with_blob(struct driver *drv) {
1182+
struct virgl_priv *prv = (struct virgl_priv *)drv->priv;
1183+
return ((prv->dev_feature & VIRTGPU_PARAM_QUERY_DEV_BIT ) && (prv->dev_feature & VIRTGPU_PARAM_RESOURCE_BLOB_BIT));
1184+
}
1185+
11601186
const struct backend virtgpu_virgl = { .name = "virtgpu_virgl",
11611187
.init = virgl_init,
11621188
.close = virgl_close,
@@ -1171,4 +1197,5 @@ const struct backend virtgpu_virgl = { .name = "virtgpu_virgl",
11711197
.resolve_format_and_use_flags =
11721198
virgl_resolve_format_and_use_flags,
11731199
.resource_info = virgl_resource_info,
1174-
.get_max_texture_2d_size = virgl_get_max_texture_2d_size };
1200+
.get_max_texture_2d_size = virgl_get_max_texture_2d_size,
1201+
.virtpci_with_blob = virgl_virtpci_with_blob };

0 commit comments

Comments
 (0)