Commit 42a090b8 authored by CK Hu's avatar CK Hu Committed by Chun-Kuang Hu

drm/mediatek: Automatically search unclaimed mtk mutex in mtk_mutex_get()

Moving mutex resource management from client driver to  mutex driver
could prevent client drivers negotiating for resource management.
Signed-off-by: default avatarCK Hu <ck.hu@mediatek.com>
Signed-off-by: default avatarChun-Kuang Hu <chunkuang.hu@kernel.org>
parent 4971593f
...@@ -773,7 +773,7 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev, ...@@ -773,7 +773,7 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
if (!mtk_crtc->ddp_comp) if (!mtk_crtc->ddp_comp)
return -ENOMEM; return -ENOMEM;
mtk_crtc->mutex = mtk_mutex_get(priv->mutex_dev, pipe); mtk_crtc->mutex = mtk_mutex_get(priv->mutex_dev);
if (IS_ERR(mtk_crtc->mutex)) { if (IS_ERR(mtk_crtc->mutex)) {
ret = PTR_ERR(mtk_crtc->mutex); ret = PTR_ERR(mtk_crtc->mutex);
dev_err(dev, "Failed to get mutex: %d\n", ret); dev_err(dev, "Failed to get mutex: %d\n", ret);
......
...@@ -228,18 +228,18 @@ static const struct mtk_mutex_data mt8173_mutex_driver_data = { ...@@ -228,18 +228,18 @@ static const struct mtk_mutex_data mt8173_mutex_driver_data = {
.mutex_sof_reg = MT2701_MUTEX0_SOF0, .mutex_sof_reg = MT2701_MUTEX0_SOF0,
}; };
struct mtk_mutex *mtk_mutex_get(struct device *dev, unsigned int id) struct mtk_mutex *mtk_mutex_get(struct device *dev)
{ {
struct mtk_mutex_ctx *mtx = dev_get_drvdata(dev); struct mtk_mutex_ctx *mtx = dev_get_drvdata(dev);
int i;
if (id >= 10) for (i = 0; i < 10; i++)
return ERR_PTR(-EINVAL); if (!mtx->mutex[i].claimed) {
if (mtx->mutex[id].claimed) mtx->mutex[i].claimed = true;
return ERR_PTR(-EBUSY); return &mtx->mutex[i];
}
mtx->mutex[id].claimed = true;
return &mtx->mutex[id]; return ERR_PTR(-EBUSY);
} }
void mtk_mutex_put(struct mtk_mutex *mutex) void mtk_mutex_put(struct mtk_mutex *mutex)
......
...@@ -10,7 +10,7 @@ struct regmap; ...@@ -10,7 +10,7 @@ struct regmap;
struct device; struct device;
struct mtk_mutex; struct mtk_mutex;
struct mtk_mutex *mtk_mutex_get(struct device *dev, unsigned int id); struct mtk_mutex *mtk_mutex_get(struct device *dev);
int mtk_mutex_prepare(struct mtk_mutex *mutex); int mtk_mutex_prepare(struct mtk_mutex *mutex);
void mtk_mutex_add_comp(struct mtk_mutex *mutex, void mtk_mutex_add_comp(struct mtk_mutex *mutex,
enum mtk_ddp_comp_id id); enum mtk_ddp_comp_id id);
......
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