From 2d17974a414e6e58d795b7b1370aedbc9bafdad8 Mon Sep 17 00:00:00 2001 From: Saurabh Shah Date: Mon, 5 Feb 2018 15:51:53 -0800 Subject: [PATCH] sdm: Add support for secondary vsync Add support for enabling secondary vsync Change-Id: Ia2231a19292314513d613efbb6953b1943530af0 CRs-fixed: 2184506 --- libdrmutils/drm_interface.h | 3 ++- sdm/libs/core/drm/hw_device_drm.cpp | 5 ++-- sdm/libs/core/drm/hw_events_drm.cpp | 42 +++++++++++++---------------- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/libdrmutils/drm_interface.h b/libdrmutils/drm_interface.h index 97660ea9..c25832c0 100644 --- a/libdrmutils/drm_interface.h +++ b/libdrmutils/drm_interface.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2017, The Linux Foundation. All rights reserved. +* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -498,6 +498,7 @@ struct DRMConnectorInfo { struct DRMDisplayToken { uint32_t conn_id; uint32_t crtc_id; + uint32_t crtc_index; }; enum DRMPPFeatureID { diff --git a/sdm/libs/core/drm/hw_device_drm.cpp b/sdm/libs/core/drm/hw_device_drm.cpp index c734f4cd..791eaa32 100644 --- a/sdm/libs/core/drm/hw_device_drm.cpp +++ b/sdm/libs/core/drm/hw_device_drm.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2017, The Linux Foundation. All rights reserved. +* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -1484,8 +1484,7 @@ DisplayError HWDeviceDRM::GetMixerAttributes(HWMixerAttributes *mixer_attributes } void HWDeviceDRM::GetDRMDisplayToken(sde_drm::DRMDisplayToken *token) const { - token->conn_id = token_.conn_id; - token->crtc_id = token_.crtc_id; + *token = token_; } void HWDeviceDRM::UpdateMixerAttributes() { diff --git a/sdm/libs/core/drm/hw_events_drm.cpp b/sdm/libs/core/drm/hw_events_drm.cpp index 86a3f544..4d1eea9a 100644 --- a/sdm/libs/core/drm/hw_events_drm.cpp +++ b/sdm/libs/core/drm/hw_events_drm.cpp @@ -64,19 +64,18 @@ DisplayError HWEventsDRM::InitializePollFd() { switch (event_data.event_type) { case HWEvent::VSYNC: { - if (!is_primary_) { - // TODO(user): Once secondary support is added, use a different fd by calling drmOpen - break; - } - poll_fds_[i].events = POLLIN | POLLPRI | POLLERR; - DRMMaster *master = nullptr; - int ret = DRMMaster::GetInstance(&master); - if (ret < 0) { - DLOGE("Failed to acquire DRMMaster instance"); - return kErrorNotSupported; + if (is_primary_) { + DRMMaster *master = nullptr; + int ret = DRMMaster::GetInstance(&master); + if (ret < 0) { + DLOGE("Failed to acquire DRMMaster instance"); + return kErrorNotSupported; + } + master->GetHandle(&poll_fds_[i].fd); + } else { + poll_fds_[i].fd = drmOpen("msm_drm", nullptr); } - master->GetHandle(&poll_fds_[i].fd); vsync_index_ = i; } break; case HWEvent::EXIT: { @@ -197,11 +196,8 @@ DisplayError HWEventsDRM::Init(int display_type, HWEventHandler *event_handler, return kErrorResources; } - if (is_primary_) { - RegisterVSync(); - vsync_registered_ = true; - } - + RegisterVSync(); + vsync_registered_ = true; RegisterPanelDead(true); RegisterIdleNotify(true); RegisterIdlePowerCollapse(true); @@ -226,9 +222,6 @@ DisplayError HWEventsDRM::SetEventState(HWEvent event, bool enable, void *arg) { switch (event) { case HWEvent::VSYNC: { std::lock_guard lock(vsync_mutex_); - if (!is_primary_) { - break; - } vsync_enabled_ = enable; if (vsync_enabled_ && !vsync_registered_) { RegisterVSync(); @@ -261,7 +254,9 @@ DisplayError HWEventsDRM::CloseFds() { for (uint32_t i = 0; i < event_data_list_.size(); i++) { switch (event_data_list_[i].event_type) { case HWEvent::VSYNC: - // TODO(user): close for secondary + if (!is_primary_) { + Sys::close_(poll_fds_[i].fd); + } poll_fds_[i].fd = -1; break; case HWEvent::EXIT: @@ -347,9 +342,10 @@ void *HWEventsDRM::DisplayEventHandler() { } DisplayError HWEventsDRM::RegisterVSync() { - // TODO(user): For secondary use DRM_VBLANK_HIGH_CRTC_MASK and DRM_VBLANK_HIGH_CRTC_SHIFT - drmVBlank vblank{}; - vblank.request.type = (drmVBlankSeqType)(DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT); + drmVBlank vblank {}; + uint32_t high_crtc = token_.crtc_index << DRM_VBLANK_HIGH_CRTC_SHIFT; + vblank.request.type = (drmVBlankSeqType)(DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT | + (high_crtc & DRM_VBLANK_HIGH_CRTC_MASK)); vblank.request.sequence = 1; // DRM hack to pass in context to unused field signal. Driver will write this to the node being // polled on, and will be read as part of drm event handling and sent to handler