Commit 60beeccc authored by Sean Paul's avatar Sean Paul Committed by Heiko Stuebner

drm/rockchip: Don't use atomic constructs for psr

Instead of using timer and spinlocks, use delayed_work and
mutexes for rockchip psr. This allows us to make blocking
calls when enabling/disabling psr (which is sort of important
given we're talking over dpcd to the display).

Cc: Caesar Wang <wxt@rock-chips.com>
Cc: 征增 王 <wzz@rock-chips.com>
Cc: Stéphane Marchesin <marcheu@chromium.org>
Signed-off-by: default avatarSean Paul <seanpaul@chromium.org>
Signed-off-by: default avatarThierry Escande <thierry.escande@collabora.com>
Signed-off-by: default avatarEnric Balletbo i Serra <enric.balletbo@collabora.com>
Signed-off-by: default avatarHeiko Stuebner <heiko@sntech.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20180305222324.5872-3-enric.balletbo@collabora.com
parent 7f3c191b
...@@ -134,7 +134,7 @@ static int rockchip_drm_bind(struct device *dev) ...@@ -134,7 +134,7 @@ static int rockchip_drm_bind(struct device *dev)
drm_dev->dev_private = private; drm_dev->dev_private = private;
INIT_LIST_HEAD(&private->psr_list); INIT_LIST_HEAD(&private->psr_list);
spin_lock_init(&private->psr_list_lock); mutex_init(&private->psr_list_lock);
ret = rockchip_drm_init_iommu(drm_dev); ret = rockchip_drm_init_iommu(drm_dev);
if (ret) if (ret)
......
...@@ -55,7 +55,7 @@ struct rockchip_drm_private { ...@@ -55,7 +55,7 @@ struct rockchip_drm_private {
struct mutex mm_lock; struct mutex mm_lock;
struct drm_mm mm; struct drm_mm mm;
struct list_head psr_list; struct list_head psr_list;
spinlock_t psr_list_lock; struct mutex psr_list_lock;
}; };
int rockchip_drm_dma_attach_device(struct drm_device *drm_dev, int rockchip_drm_dma_attach_device(struct drm_device *drm_dev,
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "rockchip_drm_drv.h" #include "rockchip_drm_drv.h"
#include "rockchip_drm_psr.h" #include "rockchip_drm_psr.h"
#define PSR_FLUSH_TIMEOUT msecs_to_jiffies(100) #define PSR_FLUSH_TIMEOUT_MS 100
enum psr_state { enum psr_state {
PSR_FLUSH, PSR_FLUSH,
...@@ -30,11 +30,11 @@ struct psr_drv { ...@@ -30,11 +30,11 @@ struct psr_drv {
struct list_head list; struct list_head list;
struct drm_encoder *encoder; struct drm_encoder *encoder;
spinlock_t lock; struct mutex lock;
bool active; bool active;
enum psr_state state; enum psr_state state;
struct timer_list flush_timer; struct delayed_work flush_work;
void (*set)(struct drm_encoder *encoder, bool enable); void (*set)(struct drm_encoder *encoder, bool enable);
}; };
...@@ -43,9 +43,8 @@ static struct psr_drv *find_psr_by_crtc(struct drm_crtc *crtc) ...@@ -43,9 +43,8 @@ static struct psr_drv *find_psr_by_crtc(struct drm_crtc *crtc)
{ {
struct rockchip_drm_private *drm_drv = crtc->dev->dev_private; struct rockchip_drm_private *drm_drv = crtc->dev->dev_private;
struct psr_drv *psr; struct psr_drv *psr;
unsigned long flags;
spin_lock_irqsave(&drm_drv->psr_list_lock, flags); mutex_lock(&drm_drv->psr_list_lock);
list_for_each_entry(psr, &drm_drv->psr_list, list) { list_for_each_entry(psr, &drm_drv->psr_list, list) {
if (psr->encoder->crtc == crtc) if (psr->encoder->crtc == crtc)
goto out; goto out;
...@@ -53,7 +52,7 @@ static struct psr_drv *find_psr_by_crtc(struct drm_crtc *crtc) ...@@ -53,7 +52,7 @@ static struct psr_drv *find_psr_by_crtc(struct drm_crtc *crtc)
psr = ERR_PTR(-ENODEV); psr = ERR_PTR(-ENODEV);
out: out:
spin_unlock_irqrestore(&drm_drv->psr_list_lock, flags); mutex_unlock(&drm_drv->psr_list_lock);
return psr; return psr;
} }
...@@ -61,9 +60,8 @@ static struct psr_drv *find_psr_by_encoder(struct drm_encoder *encoder) ...@@ -61,9 +60,8 @@ static struct psr_drv *find_psr_by_encoder(struct drm_encoder *encoder)
{ {
struct rockchip_drm_private *drm_drv = encoder->dev->dev_private; struct rockchip_drm_private *drm_drv = encoder->dev->dev_private;
struct psr_drv *psr; struct psr_drv *psr;
unsigned long flags;
spin_lock_irqsave(&drm_drv->psr_list_lock, flags); mutex_lock(&drm_drv->psr_list_lock);
list_for_each_entry(psr, &drm_drv->psr_list, list) { list_for_each_entry(psr, &drm_drv->psr_list, list) {
if (psr->encoder == encoder) if (psr->encoder == encoder)
goto out; goto out;
...@@ -71,7 +69,7 @@ static struct psr_drv *find_psr_by_encoder(struct drm_encoder *encoder) ...@@ -71,7 +69,7 @@ static struct psr_drv *find_psr_by_encoder(struct drm_encoder *encoder)
psr = ERR_PTR(-ENODEV); psr = ERR_PTR(-ENODEV);
out: out:
spin_unlock_irqrestore(&drm_drv->psr_list_lock, flags); mutex_unlock(&drm_drv->psr_list_lock);
return psr; return psr;
} }
...@@ -112,23 +110,21 @@ static void psr_set_state_locked(struct psr_drv *psr, enum psr_state state) ...@@ -112,23 +110,21 @@ static void psr_set_state_locked(struct psr_drv *psr, enum psr_state state)
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; mutex_lock(&psr->lock);
spin_lock_irqsave(&psr->lock, flags);
psr_set_state_locked(psr, state); psr_set_state_locked(psr, state);
spin_unlock_irqrestore(&psr->lock, flags); mutex_unlock(&psr->lock);
} }
static void psr_flush_handler(struct timer_list *t) static void psr_flush_handler(struct work_struct *work)
{ {
struct psr_drv *psr = from_timer(psr, t, flush_timer); struct psr_drv *psr = container_of(to_delayed_work(work),
unsigned long flags; struct psr_drv, flush_work);
/* If the state has changed since we initiated the flush, do nothing */ /* If the state has changed since we initiated the flush, do nothing */
spin_lock_irqsave(&psr->lock, flags); mutex_lock(&psr->lock);
if (psr->state == PSR_FLUSH) if (psr->state == PSR_FLUSH)
psr_set_state_locked(psr, PSR_ENABLE); psr_set_state_locked(psr, PSR_ENABLE);
spin_unlock_irqrestore(&psr->lock, flags); mutex_unlock(&psr->lock);
} }
/** /**
...@@ -141,14 +137,13 @@ static void psr_flush_handler(struct timer_list *t) ...@@ -141,14 +137,13 @@ static void psr_flush_handler(struct timer_list *t)
int rockchip_drm_psr_activate(struct drm_encoder *encoder) int rockchip_drm_psr_activate(struct drm_encoder *encoder)
{ {
struct psr_drv *psr = find_psr_by_encoder(encoder); struct psr_drv *psr = find_psr_by_encoder(encoder);
unsigned long flags;
if (IS_ERR(psr)) if (IS_ERR(psr))
return PTR_ERR(psr); return PTR_ERR(psr);
spin_lock_irqsave(&psr->lock, flags); mutex_lock(&psr->lock);
psr->active = true; psr->active = true;
spin_unlock_irqrestore(&psr->lock, flags); mutex_unlock(&psr->lock);
return 0; return 0;
} }
...@@ -164,15 +159,14 @@ EXPORT_SYMBOL(rockchip_drm_psr_activate); ...@@ -164,15 +159,14 @@ EXPORT_SYMBOL(rockchip_drm_psr_activate);
int rockchip_drm_psr_deactivate(struct drm_encoder *encoder) int rockchip_drm_psr_deactivate(struct drm_encoder *encoder)
{ {
struct psr_drv *psr = find_psr_by_encoder(encoder); struct psr_drv *psr = find_psr_by_encoder(encoder);
unsigned long flags;
if (IS_ERR(psr)) if (IS_ERR(psr))
return PTR_ERR(psr); return PTR_ERR(psr);
spin_lock_irqsave(&psr->lock, flags); mutex_lock(&psr->lock);
psr->active = false; psr->active = false;
spin_unlock_irqrestore(&psr->lock, flags); mutex_unlock(&psr->lock);
del_timer_sync(&psr->flush_timer); cancel_delayed_work_sync(&psr->flush_work);
return 0; return 0;
} }
...@@ -180,9 +174,8 @@ EXPORT_SYMBOL(rockchip_drm_psr_deactivate); ...@@ -180,9 +174,8 @@ EXPORT_SYMBOL(rockchip_drm_psr_deactivate);
static void rockchip_drm_do_flush(struct psr_drv *psr) static void rockchip_drm_do_flush(struct psr_drv *psr)
{ {
mod_timer(&psr->flush_timer,
round_jiffies_up(jiffies + PSR_FLUSH_TIMEOUT));
psr_set_state(psr, PSR_FLUSH); psr_set_state(psr, PSR_FLUSH);
mod_delayed_work(system_wq, &psr->flush_work, PSR_FLUSH_TIMEOUT_MS);
} }
/** /**
...@@ -219,12 +212,11 @@ void rockchip_drm_psr_flush_all(struct drm_device *dev) ...@@ -219,12 +212,11 @@ void rockchip_drm_psr_flush_all(struct drm_device *dev)
{ {
struct rockchip_drm_private *drm_drv = dev->dev_private; struct rockchip_drm_private *drm_drv = dev->dev_private;
struct psr_drv *psr; struct psr_drv *psr;
unsigned long flags;
spin_lock_irqsave(&drm_drv->psr_list_lock, flags); mutex_lock(&drm_drv->psr_list_lock);
list_for_each_entry(psr, &drm_drv->psr_list, list) list_for_each_entry(psr, &drm_drv->psr_list, list)
rockchip_drm_do_flush(psr); rockchip_drm_do_flush(psr);
spin_unlock_irqrestore(&drm_drv->psr_list_lock, flags); mutex_unlock(&drm_drv->psr_list_lock);
} }
EXPORT_SYMBOL(rockchip_drm_psr_flush_all); EXPORT_SYMBOL(rockchip_drm_psr_flush_all);
...@@ -241,7 +233,6 @@ int rockchip_drm_psr_register(struct drm_encoder *encoder, ...@@ -241,7 +233,6 @@ int rockchip_drm_psr_register(struct drm_encoder *encoder,
{ {
struct rockchip_drm_private *drm_drv = encoder->dev->dev_private; struct rockchip_drm_private *drm_drv = encoder->dev->dev_private;
struct psr_drv *psr; struct psr_drv *psr;
unsigned long flags;
if (!encoder || !psr_set) if (!encoder || !psr_set)
return -EINVAL; return -EINVAL;
...@@ -250,17 +241,17 @@ int rockchip_drm_psr_register(struct drm_encoder *encoder, ...@@ -250,17 +241,17 @@ int rockchip_drm_psr_register(struct drm_encoder *encoder,
if (!psr) if (!psr)
return -ENOMEM; return -ENOMEM;
timer_setup(&psr->flush_timer, psr_flush_handler, 0); INIT_DELAYED_WORK(&psr->flush_work, psr_flush_handler);
spin_lock_init(&psr->lock); mutex_init(&psr->lock);
psr->active = true; psr->active = true;
psr->state = PSR_DISABLE; psr->state = PSR_DISABLE;
psr->encoder = encoder; psr->encoder = encoder;
psr->set = psr_set; psr->set = psr_set;
spin_lock_irqsave(&drm_drv->psr_list_lock, flags); mutex_lock(&drm_drv->psr_list_lock);
list_add_tail(&psr->list, &drm_drv->psr_list); list_add_tail(&psr->list, &drm_drv->psr_list);
spin_unlock_irqrestore(&drm_drv->psr_list_lock, flags); mutex_unlock(&drm_drv->psr_list_lock);
return 0; return 0;
} }
...@@ -278,16 +269,15 @@ void rockchip_drm_psr_unregister(struct drm_encoder *encoder) ...@@ -278,16 +269,15 @@ void rockchip_drm_psr_unregister(struct drm_encoder *encoder)
{ {
struct rockchip_drm_private *drm_drv = encoder->dev->dev_private; struct rockchip_drm_private *drm_drv = encoder->dev->dev_private;
struct psr_drv *psr, *n; struct psr_drv *psr, *n;
unsigned long flags;
spin_lock_irqsave(&drm_drv->psr_list_lock, flags); mutex_lock(&drm_drv->psr_list_lock);
list_for_each_entry_safe(psr, n, &drm_drv->psr_list, list) { list_for_each_entry_safe(psr, n, &drm_drv->psr_list, list) {
if (psr->encoder == encoder) { if (psr->encoder == encoder) {
del_timer(&psr->flush_timer); cancel_delayed_work_sync(&psr->flush_work);
list_del(&psr->list); list_del(&psr->list);
kfree(psr); kfree(psr);
} }
} }
spin_unlock_irqrestore(&drm_drv->psr_list_lock, flags); mutex_unlock(&drm_drv->psr_list_lock);
} }
EXPORT_SYMBOL(rockchip_drm_psr_unregister); EXPORT_SYMBOL(rockchip_drm_psr_unregister);
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