From 7fa332360f05634381f874ef610d1a052f5a891c Mon Sep 17 00:00:00 2001 From: Mayank Chopra Date: Thu, 4 Oct 2012 20:29:52 +0530 Subject: [PATCH] msm_fb: display: Make sysfs read request interruptible Change blocking sysfs read request to be interruptible and protect vsync timestamp value to prevent corruption. Change-Id: I510d84134b0ab70d17729e8c53c91fa926035142 Signed-off-by: Mayank Chopra Conflicts: drivers/video/msm/mdp4_overlay_dsi_cmd.c drivers/video/msm/mdp4_overlay_dsi_video.c Signed-off-by: Siddhartha Agrawal --- drivers/video/msm/mdp4_overlay_dsi_cmd.c | 10 +++++++--- drivers/video/msm/mdp4_overlay_dsi_video.c | 11 ++++++++--- drivers/video/msm/mdp4_overlay_dtv.c | 15 +++++++++++---- drivers/video/msm/mdp4_overlay_lcdc.c | 15 +++++++++++---- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/drivers/video/msm/mdp4_overlay_dsi_cmd.c b/drivers/video/msm/mdp4_overlay_dsi_cmd.c index 02e53f7498cf..0bcd79dc262f 100644 --- a/drivers/video/msm/mdp4_overlay_dsi_cmd.c +++ b/drivers/video/msm/mdp4_overlay_dsi_cmd.c @@ -513,9 +513,9 @@ static void primary_rdptr_isr(int cndx) pr_debug("%s: ISR, tick=%d pan=%d cpu=%d\n", __func__, vctrl->expire_tick, vctrl->pan_display, smp_processor_id()); vctrl->rdptr_intr_tot++; - vctrl->vsync_time = ktime_get(); spin_lock(&vctrl->spin_lock); + vctrl->vsync_time = ktime_get(); complete_all(&vctrl->vsync_comp); vctrl->wait_vsync_cnt = 0; @@ -655,6 +655,7 @@ static ssize_t vsync_show_event(struct device *dev, struct vsycn_ctrl *vctrl; ssize_t ret = 0; unsigned long flags; + u64 vsync_tick; cndx = 0; vctrl = &vsync_ctrl_db[0]; @@ -672,8 +673,11 @@ static ssize_t vsync_show_event(struct device *dev, if (ret < 0) return ret; - ret = snprintf(buf, PAGE_SIZE, "VSYNC=%llu", - ktime_to_ns(vctrl->vsync_time)); + spin_lock_irqsave(&vctrl->spin_lock, flags); + vsync_tick = ktime_to_ns(vctrl->vsync_time); + spin_unlock_irqrestore(&vctrl->spin_lock, flags); + + ret = snprintf(buf, PAGE_SIZE, "VSYNC=%llu", vsync_tick); buf[strlen(buf) + 1] = '\0'; return ret; } diff --git a/drivers/video/msm/mdp4_overlay_dsi_video.c b/drivers/video/msm/mdp4_overlay_dsi_video.c index c4c9045531a2..442959dc497d 100644 --- a/drivers/video/msm/mdp4_overlay_dsi_video.c +++ b/drivers/video/msm/mdp4_overlay_dsi_video.c @@ -381,6 +381,7 @@ static ssize_t vsync_show_event(struct device *dev, struct vsycn_ctrl *vctrl; ssize_t ret = 0; unsigned long flags; + u64 vsync_tick; cndx = 0; vctrl = &vsync_ctrl_db[0]; @@ -398,8 +399,11 @@ static ssize_t vsync_show_event(struct device *dev, if (ret < 0) return ret; - ret = snprintf(buf, PAGE_SIZE, "VSYNC=%llu", - ktime_to_ns(vctrl->vsync_time)); + spin_lock_irqsave(&vctrl->spin_lock, flags); + vsync_tick = ktime_to_ns(vctrl->vsync_time); + spin_unlock_irqrestore(&vctrl->spin_lock, flags); + + ret = snprintf(buf, PAGE_SIZE, "VSYNC=%llu", vsync_tick); buf[strlen(buf) + 1] = '\0'; return ret; } @@ -937,9 +941,10 @@ void mdp4_primary_vsync_dsi_video(void) cndx = 0; vctrl = &vsync_ctrl_db[cndx]; pr_debug("%s: cpu=%d\n", __func__, smp_processor_id()); - vctrl->vsync_time = ktime_get(); spin_lock(&vctrl->spin_lock); + vctrl->vsync_time = ktime_get(); + if (vctrl->wait_vsync_cnt) { complete_all(&vctrl->vsync_comp); vctrl->wait_vsync_cnt = 0; diff --git a/drivers/video/msm/mdp4_overlay_dtv.c b/drivers/video/msm/mdp4_overlay_dtv.c index 15e45bbfd390..c5fc201bf8d7 100644 --- a/drivers/video/msm/mdp4_overlay_dtv.c +++ b/drivers/video/msm/mdp4_overlay_dtv.c @@ -322,6 +322,7 @@ static ssize_t vsync_show_event(struct device *dev, struct vsycn_ctrl *vctrl; ssize_t ret = 0; unsigned long flags; + u64 vsync_tick; cndx = 0; vctrl = &vsync_ctrl_db[0]; @@ -336,10 +337,15 @@ static ssize_t vsync_show_event(struct device *dev, INIT_COMPLETION(vctrl->vsync_comp); vctrl->wait_vsync_cnt++; spin_unlock_irqrestore(&vctrl->spin_lock, flags); - wait_for_completion(&vctrl->vsync_comp); + ret = wait_for_completion_interruptible(&vctrl->vsync_comp); + if (ret) + return ret; - ret = snprintf(buf, PAGE_SIZE, "VSYNC=%llu", - ktime_to_ns(vctrl->vsync_time)); + spin_lock_irqsave(&vctrl->spin_lock, flags); + vsync_tick = ktime_to_ns(vctrl->vsync_time); + spin_unlock_irqrestore(&vctrl->spin_lock, flags); + + ret = snprintf(buf, PAGE_SIZE, "VSYNC=%llu", vsync_tick); buf[strlen(buf) + 1] = '\0'; return ret; } @@ -861,9 +867,10 @@ void mdp4_external_vsync_dtv(void) cndx = 0; vctrl = &vsync_ctrl_db[cndx]; pr_debug("%s: cpu=%d\n", __func__, smp_processor_id()); - vctrl->vsync_time = ktime_get(); spin_lock(&vctrl->spin_lock); + vctrl->vsync_time = ktime_get(); + if (vctrl->wait_vsync_cnt) { complete_all(&vctrl->vsync_comp); vctrl->wait_vsync_cnt = 0; diff --git a/drivers/video/msm/mdp4_overlay_lcdc.c b/drivers/video/msm/mdp4_overlay_lcdc.c index 393b5aafc0f8..63a87eecb144 100644 --- a/drivers/video/msm/mdp4_overlay_lcdc.c +++ b/drivers/video/msm/mdp4_overlay_lcdc.c @@ -366,6 +366,7 @@ static ssize_t vsync_show_event(struct device *dev, struct vsycn_ctrl *vctrl; ssize_t ret = 0; unsigned long flags; + u64 vsync_tick; cndx = 0; vctrl = &vsync_ctrl_db[0]; @@ -379,10 +380,15 @@ static ssize_t vsync_show_event(struct device *dev, INIT_COMPLETION(vctrl->vsync_comp); vctrl->wait_vsync_cnt++; spin_unlock_irqrestore(&vctrl->spin_lock, flags); - wait_for_completion(&vctrl->vsync_comp); + ret = wait_for_completion_interruptible(&vctrl->vsync_comp); + if (ret) + return ret; - ret = snprintf(buf, PAGE_SIZE, "VSYNC=%llu", - ktime_to_ns(vctrl->vsync_time)); + spin_lock_irqsave(&vctrl->spin_lock, flags); + vsync_tick = ktime_to_ns(vctrl->vsync_time); + spin_unlock_irqrestore(&vctrl->spin_lock, flags); + + ret = snprintf(buf, PAGE_SIZE, "VSYNC=%llu", vsync_tick); buf[strlen(buf) + 1] = '\0'; return ret; } @@ -811,9 +817,10 @@ void mdp4_primary_vsync_lcdc(void) cndx = 0; vctrl = &vsync_ctrl_db[cndx]; pr_debug("%s: cpu=%d\n", __func__, smp_processor_id()); - vctrl->vsync_time = ktime_get(); spin_lock(&vctrl->spin_lock); + vctrl->vsync_time = ktime_get(); + if (vctrl->wait_vsync_cnt) { complete_all(&vctrl->vsync_comp); vctrl->wait_vsync_cnt = 0;