From feffe6774fb3462d7ca0b7f9e2f466551b686dbe Mon Sep 17 00:00:00 2001 From: HeYue Date: Fri, 24 Nov 2023 08:46:36 +0800 Subject: [PATCH 1/3] Add hotplug log Signed-off-by: HeYue --- drm/ResourceManager.cpp | 3 +++ drm/UEventListener.cpp | 4 ++++ hwc2_device/DrmHwcTwo.cpp | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/drm/ResourceManager.cpp b/drm/ResourceManager.cpp index 4c28b17..ec87236 100755 --- a/drm/ResourceManager.cpp +++ b/drm/ResourceManager.cpp @@ -157,6 +157,7 @@ auto ResourceManager::GetTimeMonotonicNs() -> int64_t { #define DRM_MODE_LINK_STATUS_BAD 1 void ResourceManager::UpdateFrontendDisplays() { + ALOGE("--yue-- %s\n", __FUNCTION__); auto ordered_connectors = GetOrderedConnectors(); for (auto *conn : ordered_connectors) { @@ -165,12 +166,14 @@ void ResourceManager::UpdateFrontendDisplays() { bool attached = attached_pipelines_.count(conn) != 0; if (connected != attached) { + ALOGI("%s connector %s", connected ? "Attaching" : "Detaching", conn->GetName().c_str()); if (connected) { auto pipeline = DrmDisplayPipeline::CreatePipeline(*conn); if (pipeline) { + ALOGE("--yue-- beofre BindDisplay\n"); frontend_interface_->BindDisplay(pipeline.get()); attached_pipelines_[conn] = std::move(pipeline); } diff --git a/drm/UEventListener.cpp b/drm/UEventListener.cpp index b56b8e1..3c3bf2b 100644 --- a/drm/UEventListener.cpp +++ b/drm/UEventListener.cpp @@ -41,6 +41,7 @@ int UEventListener::Init() { } void UEventListener::Routine() { + ALOGE("--yue-- %s", __FUNCTION__); while (true) { auto uevent_str = uevent_->ReadNext(); @@ -49,6 +50,9 @@ void UEventListener::Routine() { bool drm_event = uevent_str->find("DEVTYPE=drm_minor") != std::string::npos; bool hotplug_event = uevent_str->find("HOTPLUG=1") != std::string::npos; + if (hotplug_event) { + ALOGE("--yue-- has hotplug event!!!!\n"); + } if (drm_event && hotplug_event) { constexpr useconds_t kDelayAfterUeventUs = 200000; diff --git a/hwc2_device/DrmHwcTwo.cpp b/hwc2_device/DrmHwcTwo.cpp index 5e18592..b3cbf26 100644 --- a/hwc2_device/DrmHwcTwo.cpp +++ b/hwc2_device/DrmHwcTwo.cpp @@ -29,12 +29,14 @@ DrmHwcTwo::DrmHwcTwo() : resource_manager_(this){}; /* Must be called after every display attach/detach cycle */ void DrmHwcTwo::FinalizeDisplayBinding() { + ALOGE("--yue-- %s\n", __FUNCTION__); if (displays_.count(kPrimaryDisplay) == 0) { /* Primary display MUST always exist */ ALOGI("No pipelines available. Creating null-display for headless mode"); displays_[kPrimaryDisplay] = std::make_unique< HwcDisplay>(kPrimaryDisplay, HWC2::DisplayType::Physical, this); /* Initializes null-display */ + ALOGE("--yue-- null-display\n"); displays_[kPrimaryDisplay]->SetPipeline(nullptr); } @@ -45,11 +47,13 @@ void DrmHwcTwo::FinalizeDisplayBinding() { ALOGI("Primary display was disconnected, reattaching '%s' as new primary", pipe->connector->Get()->GetName().c_str()); UnbindDisplay(pipe); + ALOGE("--yue-- Reattach first secondary display \n"); BindDisplay(pipe); } // Finally, send hotplug events to the client for (auto &dhe : deferred_hotplug_events_) { + ALOGE("--yue-- send hotplug events to the client\n"); SendHotplugEventToClient(dhe.first, dhe.second); } deferred_hotplug_events_.clear(); @@ -87,6 +91,7 @@ HwcDisplay * DrmHwcTwo::GetDisplay(DrmDisplayPipeline *pipeline) { } bool DrmHwcTwo::BindDisplay(DrmDisplayPipeline *pipeline) { + ALOGE("--yue-- %s\n", __FUNCTION__); if (display_handles_.count(pipeline) != 0) { ALOGE("%s, pipeline is already used by another display, FIXME!!!: %p", __func__, pipeline); @@ -228,6 +233,7 @@ HWC2::Error DrmHwcTwo::RegisterCallback(int32_t descriptor, void DrmHwcTwo::SendHotplugEventToClient(hwc2_display_t displayid, bool connected) { + ALOGE("--yue-- %s\n", __FUNCTION__); auto &mutex = GetResMan().GetMainLock(); if (mutex.try_lock()) { ALOGE("FIXME!!!: Main mutex must be locked in %s", __func__); @@ -241,9 +247,11 @@ void DrmHwcTwo::SendHotplugEventToClient(hwc2_display_t displayid, * which will cause deadlock . Unlock main mutex to prevent this. */ mutex.unlock(); + ALOGE("--yue-- before hc.first\n"); hc.first(hc.second, displayid, connected == DRM_MODE_CONNECTED ? HWC2_CONNECTION_CONNECTED : HWC2_CONNECTION_DISCONNECTED); + ALOGE("--yue-- connected is %d\n", connected); mutex.lock(); } } From ecf05d9ef8937f96e3c7df767ce545812dabd6b4 Mon Sep 17 00:00:00 2001 From: HeYue Date: Wed, 6 Dec 2023 09:49:01 +0800 Subject: [PATCH 2/3] open card node with ivshmem case Signed-off-by: HeYue --- drm/DrmDevice.cpp | 1 + drm/ResourceManager.cpp | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/drm/DrmDevice.cpp b/drm/DrmDevice.cpp index 0a1f826..2cc468a 100755 --- a/drm/DrmDevice.cpp +++ b/drm/DrmDevice.cpp @@ -166,6 +166,7 @@ auto DrmDevice::Init(const char *path) -> int { property_get("vendor.hwcomposer.planes.num", property, PLANES_MAX_NUM_STRING); planes_num_ = atoi(property) <= 0 ? atoi(PLANES_MAX_NUM_STRING) : atoi(property); ALOGD("The property 'vendor.hwcomposer.planes.num' value is %s", property); + ALOGE("--yue-- plane_res->count_planes is %d\n", plane_res->count_planes); for (uint32_t i = 0; i < plane_res->count_planes; ++i) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) auto plane = DrmPlane::CreateInstance(*this, plane_res->planes[i]); diff --git a/drm/ResourceManager.cpp b/drm/ResourceManager.cpp index ec87236..31656f0 100755 --- a/drm/ResourceManager.cpp +++ b/drm/ResourceManager.cpp @@ -105,10 +105,25 @@ void ResourceManager::Init() { // is SRI-IOV + dGPU, use virtio-gpu(card2) for display if (node_num == 3) { std::ostringstream path; - path << path_pattern << 2; + path << path_pattern << 1; auto dev = DrmDevice::CreateInstance(path.str(), this); - if (dev) { - drms_.emplace_back(std::move(dev)); + if (dev->GetName() == "i915") { //is SRI-IOV + dGPU, use virtio-gpu(card2) for display + std::ostringstream path; + path << path_pattern << 2; + auto dev = DrmDevice::CreateInstance(path.str(), this); + if (dev) { + drms_.emplace_back(std::move(dev)); + } + } else { //is iGPU vf + virtio-gpu + ivshemem, use ivshmem and virtio-gpu + if (dev) { + drms_.emplace_back(std::move(dev)); + } + std::ostringstream path; + path << path_pattern << 2; + auto dev = DrmDevice::CreateInstance(path.str(), this); + if (dev) { + drms_.emplace_back(std::move(dev)); + } } } } From 550c93417f3ba384367a1d017acaa362fdec0474 Mon Sep 17 00:00:00 2001 From: HeYue Date: Fri, 1 Dec 2023 09:53:46 +0800 Subject: [PATCH 3/3] Handle the hotplug event to plugout and plugin When android bootup connect 2 display. Signed-off-by: HeYue --- drm/ResourceManager.cpp | 15 ++++++++++++++- drm/ResourceManager.h | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drm/ResourceManager.cpp b/drm/ResourceManager.cpp index 31656f0..ad5a3b3 100755 --- a/drm/ResourceManager.cpp +++ b/drm/ResourceManager.cpp @@ -180,7 +180,13 @@ void ResourceManager::UpdateFrontendDisplays() { bool connected = conn->IsConnected(); bool attached = attached_pipelines_.count(conn) != 0; - if (connected != attached) { + if ((connected != attached) && (hotplug_event_init || boot_event)) { + + if (boot_event && (!strcmp(conn->GetName().c_str(), "Virtual-2"))) { + ALOGD("yue do not use ivshmem display when bootup\n"); + boot_event = false; + continue; + } ALOGI("%s connector %s", connected ? "Attaching" : "Detaching", conn->GetName().c_str()); @@ -198,6 +204,12 @@ void ResourceManager::UpdateFrontendDisplays() { frontend_interface_->UnbindDisplay(pipeline.get()); attached_pipelines_.erase(conn); } + } else if ((!hotplug_event_init) && (!strcmp(conn->GetName().c_str(), "Virtual-2")) && connected) { + ALOGI("---yue--- Detaching connector %s", conn->GetName().c_str()); + auto &pipeline = attached_pipelines_[conn]; + pipeline->AtomicDisablePipeline(); + frontend_interface_->UnbindDisplay(pipeline.get()); + attached_pipelines_.erase(conn); } else { if (connected) { uint64_t link_status = 0; @@ -224,6 +236,7 @@ void ResourceManager::UpdateFrontendDisplays() { } } } + hotplug_event_init = !hotplug_event_init; frontend_interface_->FinalizeDisplayBinding(); } diff --git a/drm/ResourceManager.h b/drm/ResourceManager.h index bea31fd..c9f2e2b 100644 --- a/drm/ResourceManager.h +++ b/drm/ResourceManager.h @@ -78,6 +78,8 @@ class ResourceManager { PipelineToFrontendBindingInterface *const frontend_interface_; bool initialized_{}; + bool hotplug_event_init = false; + bool boot_event = true; }; } // namespace android