Commit eec85347 authored by Sean Paul's avatar Sean Paul

drm/rockchip: Use a spinlock to protect psr state

The handling of psr state is racey, shore that up with
a per-psr driver lock.
Reviewed-by: default avatarYakir Yang <ykk@rock-chips.com>
Signed-off-by: default avatarSean Paul <seanpaul@chromium.org>
parent 23c0f3dc
...@@ -30,6 +30,7 @@ struct psr_drv { ...@@ -30,6 +30,7 @@ struct psr_drv {
struct list_head list; struct list_head list;
struct drm_encoder *encoder; struct drm_encoder *encoder;
spinlock_t lock;
enum psr_state state; enum psr_state state;
struct timer_list flush_timer; struct timer_list flush_timer;
...@@ -55,7 +56,7 @@ static struct psr_drv *find_psr_by_crtc(struct drm_crtc *crtc) ...@@ -55,7 +56,7 @@ static struct psr_drv *find_psr_by_crtc(struct drm_crtc *crtc)
return psr; return psr;
} }
static void psr_set_state(struct psr_drv *psr, enum psr_state state) static void psr_set_state_locked(struct psr_drv *psr, enum psr_state state)
{ {
/* /*
* Allowed finite state machine: * Allowed finite state machine:
...@@ -75,7 +76,6 @@ static void psr_set_state(struct psr_drv *psr, enum psr_state state) ...@@ -75,7 +76,6 @@ static void psr_set_state(struct psr_drv *psr, enum psr_state state)
if (state == PSR_FLUSH && psr->state == PSR_DISABLE) if (state == PSR_FLUSH && psr->state == PSR_DISABLE)
return; return;
/* Only wrote in this work, no need lock protection */
psr->state = state; psr->state = state;
/* Allow but no need hardware change, just need assign the state */ /* Allow but no need hardware change, just need assign the state */
...@@ -95,18 +95,28 @@ static void psr_set_state(struct psr_drv *psr, enum psr_state state) ...@@ -95,18 +95,28 @@ static void psr_set_state(struct psr_drv *psr, enum psr_state state)
} }
} }
static void psr_set_state(struct psr_drv *psr, enum psr_state state)
{
unsigned long flags;
spin_lock_irqsave(&psr->lock, flags);
psr_set_state_locked(psr, state);
spin_unlock_irqrestore(&psr->lock, flags);
}
static void psr_flush_handler(unsigned long data) static void psr_flush_handler(unsigned long data)
{ {
struct psr_drv *psr = (struct psr_drv *)data; struct psr_drv *psr = (struct psr_drv *)data;
unsigned long flags;
if (!psr) if (!psr)
return; return;
/* State changed between flush time, then keep it */ /* State changed between flush time, then keep it */
if (psr->state != PSR_FLUSH) spin_lock_irqsave(&psr->lock, flags);
return; if (psr->state == PSR_FLUSH)
psr_set_state_locked(psr, PSR_ENABLE);
psr_set_state(psr, PSR_ENABLE); spin_unlock_irqrestore(&psr->lock, flags);
} }
/** /**
...@@ -167,9 +177,6 @@ void rockchip_drm_psr_flush(struct drm_device *dev) ...@@ -167,9 +177,6 @@ void rockchip_drm_psr_flush(struct drm_device *dev)
spin_lock_irqsave(&drm_drv->psr_list_lock, flags); spin_lock_irqsave(&drm_drv->psr_list_lock, flags);
list_for_each_entry(psr, &drm_drv->psr_list, list) { list_for_each_entry(psr, &drm_drv->psr_list, list) {
if (psr->state == PSR_DISABLE)
continue;
mod_timer(&psr->flush_timer, mod_timer(&psr->flush_timer,
round_jiffies_up(jiffies + PSR_FLUSH_TIMEOUT)); round_jiffies_up(jiffies + PSR_FLUSH_TIMEOUT));
...@@ -202,6 +209,7 @@ int rockchip_drm_psr_register(struct drm_encoder *encoder, ...@@ -202,6 +209,7 @@ int rockchip_drm_psr_register(struct drm_encoder *encoder,
return -ENOMEM; return -ENOMEM;
setup_timer(&psr->flush_timer, psr_flush_handler, (unsigned long)psr); setup_timer(&psr->flush_timer, psr_flush_handler, (unsigned long)psr);
spin_lock_init(&psr->lock);
psr->state = PSR_DISABLE; psr->state = PSR_DISABLE;
psr->encoder = encoder; psr->encoder = encoder;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment