Commit feeb0aec authored by Francisco Jerez's avatar Francisco Jerez Committed by Ben Skeggs

drm/nouveau: Add unlocked variants of nouveau_channel_get/put.

Signed-off-by: default avatarFrancisco Jerez <currojerez@riseup.net>
Signed-off-by: default avatarBen Skeggs <bskeggs@redhat.com>
parent f175b745
...@@ -237,34 +237,40 @@ nouveau_channel_alloc(struct drm_device *dev, struct nouveau_channel **chan_ret, ...@@ -237,34 +237,40 @@ nouveau_channel_alloc(struct drm_device *dev, struct nouveau_channel **chan_ret,
return 0; return 0;
} }
struct nouveau_channel *
nouveau_channel_get_unlocked(struct nouveau_channel *ref)
{
if (likely(ref && atomic_inc_not_zero(&ref->refcount)))
return ref;
return NULL;
}
struct nouveau_channel * struct nouveau_channel *
nouveau_channel_get(struct drm_device *dev, struct drm_file *file_priv, int id) nouveau_channel_get(struct drm_device *dev, struct drm_file *file_priv, int id)
{ {
struct drm_nouveau_private *dev_priv = dev->dev_private; struct drm_nouveau_private *dev_priv = dev->dev_private;
struct nouveau_channel *chan = ERR_PTR(-ENODEV); struct nouveau_channel *chan;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&dev_priv->channels.lock, flags); spin_lock_irqsave(&dev_priv->channels.lock, flags);
chan = dev_priv->channels.ptr[id]; chan = nouveau_channel_get_unlocked(dev_priv->channels.ptr[id]);
if (unlikely(!chan || (file_priv && chan->file_priv != file_priv))) {
spin_unlock_irqrestore(&dev_priv->channels.lock, flags); spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
if (unlikely(!chan))
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
}
if (unlikely(!atomic_inc_not_zero(&chan->refcount))) { if (unlikely(file_priv && chan->file_priv != file_priv)) {
spin_unlock_irqrestore(&dev_priv->channels.lock, flags); nouveau_channel_put_unlocked(&chan);
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
mutex_lock(&chan->mutex); mutex_lock(&chan->mutex);
return chan; return chan;
} }
void void
nouveau_channel_put(struct nouveau_channel **pchan) nouveau_channel_put_unlocked(struct nouveau_channel **pchan)
{ {
struct nouveau_channel *chan = *pchan; struct nouveau_channel *chan = *pchan;
struct drm_device *dev = chan->dev; struct drm_device *dev = chan->dev;
...@@ -274,9 +280,6 @@ nouveau_channel_put(struct nouveau_channel **pchan) ...@@ -274,9 +280,6 @@ nouveau_channel_put(struct nouveau_channel **pchan)
unsigned long flags; unsigned long flags;
int ret; int ret;
/* unlock the channel */
mutex_unlock(&chan->mutex);
/* decrement the refcount, and we're done if there's still refs */ /* decrement the refcount, and we're done if there's still refs */
if (likely(!atomic_dec_and_test(&chan->refcount))) { if (likely(!atomic_dec_and_test(&chan->refcount))) {
*pchan = NULL; *pchan = NULL;
...@@ -348,6 +351,13 @@ nouveau_channel_put(struct nouveau_channel **pchan) ...@@ -348,6 +351,13 @@ nouveau_channel_put(struct nouveau_channel **pchan)
kfree(chan); kfree(chan);
} }
void
nouveau_channel_put(struct nouveau_channel **pchan)
{
mutex_unlock(&(*pchan)->mutex);
nouveau_channel_put_unlocked(pchan);
}
/* cleans up all the fifos from file_priv */ /* cleans up all the fifos from file_priv */
void void
nouveau_channel_cleanup(struct drm_device *dev, struct drm_file *file_priv) nouveau_channel_cleanup(struct drm_device *dev, struct drm_file *file_priv)
......
...@@ -803,7 +803,10 @@ extern int nouveau_channel_alloc(struct drm_device *dev, ...@@ -803,7 +803,10 @@ extern int nouveau_channel_alloc(struct drm_device *dev,
struct drm_file *file_priv, struct drm_file *file_priv,
uint32_t fb_ctxdma, uint32_t tt_ctxdma); uint32_t fb_ctxdma, uint32_t tt_ctxdma);
extern struct nouveau_channel * extern struct nouveau_channel *
nouveau_channel_get_unlocked(struct nouveau_channel *);
extern struct nouveau_channel *
nouveau_channel_get(struct drm_device *, struct drm_file *, int id); nouveau_channel_get(struct drm_device *, struct drm_file *, int id);
extern void nouveau_channel_put_unlocked(struct nouveau_channel **);
extern void nouveau_channel_put(struct nouveau_channel **); extern void nouveau_channel_put(struct nouveau_channel **);
/* nouveau_object.c */ /* nouveau_object.c */
......
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