Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Front #45

Open
wants to merge 3 commits into
base: celadon/s/mr0/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions drm/DrmDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
39 changes: 35 additions & 4 deletions drm/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
}
Expand Down Expand Up @@ -157,20 +172,29 @@ 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) {
conn->UpdateModes();
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());

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);
}
Expand All @@ -180,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;
Expand All @@ -206,6 +236,7 @@ void ResourceManager::UpdateFrontendDisplays() {
}
}
}
hotplug_event_init = !hotplug_event_init;
frontend_interface_->FinalizeDisplayBinding();
}

Expand Down
2 changes: 2 additions & 0 deletions drm/ResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class ResourceManager {
PipelineToFrontendBindingInterface *const frontend_interface_;

bool initialized_{};
bool hotplug_event_init = false;
bool boot_event = true;
};
} // namespace android

Expand Down
4 changes: 4 additions & 0 deletions drm/UEventListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ int UEventListener::Init() {
}

void UEventListener::Routine() {
ALOGE("--yue-- %s", __FUNCTION__);
while (true) {
auto uevent_str = uevent_->ReadNext();

Expand All @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions hwc2_device/DrmHwcTwo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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__);
Expand All @@ -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();
}
}
Expand Down
Loading