Skip to content

Commit 60e0772

Browse files
yhe39sysopenci
authored andcommitted
Add the drv_kms_ back
So far in the following two scenario, need use virtio to allocat scanout buffer, otherwise Android boot with black screen. 1. On qnx, the virtio is ivshmem, it has blob feature. But ivshm and i915 memory are in different region, ivshm couldn't import i915 memory. 2. On redhat, the virtio is virtio-gpu, it do not have blob on kernel 6.8. The virtio couldn't import buffer from i915 although they are in the same memroy region. 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: He, Yue <yue.he@intel.com>
1 parent 86218b9 commit 60e0772

3 files changed

Lines changed: 31 additions & 3 deletions

File tree

cros_gralloc/cros_gralloc_driver.cc

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ cros_gralloc_driver::cros_gralloc_driver()
145145
// destroy drivers if exist before re-initializing them
146146
if (drv_video_ != drv_render_)
147147
DRV_DESTROY(drv_video_)
148+
if (drv_kms_ != drv_render_)
149+
DRV_DESTROY(drv_kms_)
148150
DRV_DESTROY(drv_render_)
149151

150152
for (uint32_t i = min_render_node; i < max_render_node; i++) {
@@ -248,15 +250,29 @@ cros_gralloc_driver::cros_gralloc_driver()
248250
video_idx);
249251
}
250252

253+
if ((virtio_node_idx != -1) && (virtio_node_idx != renderer_idx)) {
254+
drv_kms_ = drv_create(node_fd[virtio_node_idx]);
255+
if (!drv_kms_) {
256+
drv_loge("Failed to create driver for the virtio-gpu device with card id %d\n",
257+
virtio_node_idx);
258+
close(node_fd[virtio_node_idx]);
259+
drv_kms_ = drv_render_;
260+
}
261+
} else {
262+
drv_kms_ = drv_render_;
263+
}
264+
251265
// Init drv
252266
DRV_INIT(drv_render_, gpu_grp_type, renderer_idx)
253267
if (video_idx != renderer_idx)
254268
DRV_INIT(drv_video_, gpu_grp_type, video_idx)
269+
if ((virtio_node_idx != -1) && (virtio_node_idx != renderer_idx))
270+
DRV_INIT(drv_kms_, gpu_grp_type, virtio_node_idx)
255271
}
256272

257273
for (int i = 0; i < availabe_node; i++) {
258274
free(node_name[i]);
259-
if ((i != renderer_idx) && (i != video_idx)) {
275+
if ((i != renderer_idx) && (i != video_idx) && (i != virtio_node_idx)) {
260276
close(node_fd[i]);
261277
}
262278
}
@@ -269,6 +285,8 @@ cros_gralloc_driver::~cros_gralloc_driver()
269285

270286
if (drv_video_ != drv_render_)
271287
DRV_DESTROY(drv_video_)
288+
if (drv_kms_ != drv_render_)
289+
DRV_DESTROY(drv_kms_)
272290
DRV_DESTROY(drv_render_)
273291
}
274292

@@ -299,6 +317,9 @@ bool cros_gralloc_driver::get_resolved_format_and_use_flags(
299317
struct combination *combo;
300318

301319
struct driver *drv = is_video_format(descriptor) ? drv_video_ : drv_render_;
320+
if ((descriptor->use_flags & BO_USE_SCANOUT) && !(is_video_format(descriptor)))
321+
drv = drv_kms_;
322+
302323
if (mt8183_camera_quirk_ && (descriptor->use_flags & BO_USE_CAMERA_READ) &&
303324
!(descriptor->use_flags & BO_USE_SCANOUT) &&
304325
descriptor->drm_format == DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED) {
@@ -342,6 +363,8 @@ bool cros_gralloc_driver::is_supported(const struct cros_gralloc_buffer_descript
342363
uint32_t resolved_format;
343364
uint64_t resolved_use_flags;
344365
struct driver *drv = is_video_format(descriptor) ? drv_video_ : drv_render_;
366+
if ((descriptor->use_flags & BO_USE_SCANOUT) && !(is_video_format(descriptor)))
367+
drv = drv_kms_;
345368
uint32_t max_texture_size = drv_get_max_texture_2d_size(drv);
346369
if (!get_resolved_format_and_use_flags(descriptor, &resolved_format, &resolved_use_flags))
347370
return false;
@@ -391,6 +414,9 @@ int32_t cros_gralloc_driver::allocate(const struct cros_gralloc_buffer_descripto
391414
struct driver *drv;
392415

393416
drv = is_video_format(descriptor) ? drv_video_ : drv_render_;
417+
if ((descriptor->use_flags & BO_USE_SCANOUT) && (!is_video_format(descriptor))) {
418+
drv = drv_kms_;
419+
}
394420

395421
if (!get_resolved_format_and_use_flags(descriptor, &resolved_format, &resolved_use_flags)) {
396422
ALOGE("Failed to resolve format and use_flags.");
@@ -454,7 +480,6 @@ int32_t cros_gralloc_driver::allocate(const struct cros_gralloc_buffer_descripto
454480
hnd->fds[i] = -1;
455481

456482
hnd->num_planes = num_planes;
457-
hnd->from_kms = false; // not used, just set a default value. keep this member to be backward compatible.
458483
for (size_t plane = 0; plane < num_planes; plane++) {
459484
ret = drv_bo_get_plane_fd(bo, plane);
460485
if (ret < 0)
@@ -546,6 +571,8 @@ int32_t cros_gralloc_driver::retain(buffer_handle_t handle)
546571
.use_flags = hnd->use_flags,
547572
};
548573
drv = is_video_format(&descriptor) ? drv_video_ : drv_render_;
574+
if ((hnd->use_flags & BO_USE_SCANOUT) && (!is_video_format(&descriptor)))
575+
drv = drv_kms_;
549576

550577
auto hnd_it = handles_.find(hnd);
551578
if (hnd_it != handles_.end()) {

cros_gralloc/cros_gralloc_driver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class cros_gralloc_driver
8888
// otherwise they may be the same node.
8989
struct driver *drv_render_ = nullptr;
9090
struct driver *drv_video_ = nullptr;
91+
// the drv_kms_ is used to allocate scanout non-video buffer.
92+
struct driver *drv_kms_ = nullptr;
9193
std::mutex mutex_;
9294
std::unordered_map<uint32_t, std::unique_ptr<cros_gralloc_buffer>> buffers_;
9395
std::unordered_map<cros_gralloc_handle_t, cros_gralloc_imported_handle_info> handles_;

cros_gralloc/cros_gralloc_handle.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ struct cros_gralloc_handle : public native_handle_t {
2626
uint32_t strides[DRV_MAX_PLANES];
2727
uint32_t offsets[DRV_MAX_PLANES];
2828
uint32_t sizes[DRV_MAX_PLANES];
29-
bool from_kms;
3029
uint32_t id;
3130
uint32_t width;
3231
uint32_t height;

0 commit comments

Comments
 (0)