Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 228530
b: refs/heads/master
c: feeb0ae
h: refs/heads/master
v: v3
  • Loading branch information
Francisco Jerez authored and Ben Skeggs committed Dec 3, 2010
1 parent 236ecb3 commit e37687b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: f175b745b50c5c5356e8b3b409b7f38aa44de6bb
refs/heads/master: feeb0aecfb73b5b7699c0a85ba1650e6f9c50be2
36 changes: 23 additions & 13 deletions trunk/drivers/gpu/drm/nouveau/nouveau_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,34 +237,40 @@ nouveau_channel_alloc(struct drm_device *dev, struct nouveau_channel **chan_ret,
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 *
nouveau_channel_get(struct drm_device *dev, struct drm_file *file_priv, int id)
{
struct drm_nouveau_private *dev_priv = dev->dev_private;
struct nouveau_channel *chan = ERR_PTR(-ENODEV);
struct nouveau_channel *chan;
unsigned long 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]);
spin_unlock_irqrestore(&dev_priv->channels.lock, flags);

if (unlikely(!chan || (file_priv && chan->file_priv != file_priv))) {
spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
if (unlikely(!chan))
return ERR_PTR(-EINVAL);
}

if (unlikely(!atomic_inc_not_zero(&chan->refcount))) {
spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
if (unlikely(file_priv && chan->file_priv != file_priv)) {
nouveau_channel_put_unlocked(&chan);
return ERR_PTR(-EINVAL);
}

spin_unlock_irqrestore(&dev_priv->channels.lock, flags);

mutex_lock(&chan->mutex);
return chan;
}

void
nouveau_channel_put(struct nouveau_channel **pchan)
nouveau_channel_put_unlocked(struct nouveau_channel **pchan)
{
struct nouveau_channel *chan = *pchan;
struct drm_device *dev = chan->dev;
Expand All @@ -274,9 +280,6 @@ nouveau_channel_put(struct nouveau_channel **pchan)
unsigned long flags;
int ret;

/* unlock the channel */
mutex_unlock(&chan->mutex);

/* decrement the refcount, and we're done if there's still refs */
if (likely(!atomic_dec_and_test(&chan->refcount))) {
*pchan = NULL;
Expand Down Expand Up @@ -348,6 +351,13 @@ nouveau_channel_put(struct nouveau_channel **pchan)
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 */
void
nouveau_channel_cleanup(struct drm_device *dev, struct drm_file *file_priv)
Expand Down
3 changes: 3 additions & 0 deletions trunk/drivers/gpu/drm/nouveau/nouveau_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,10 @@ extern int nouveau_channel_alloc(struct drm_device *dev,
struct drm_file *file_priv,
uint32_t fb_ctxdma, uint32_t tt_ctxdma);
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);
extern void nouveau_channel_put_unlocked(struct nouveau_channel **);
extern void nouveau_channel_put(struct nouveau_channel **);

/* nouveau_object.c */
Expand Down

0 comments on commit e37687b

Please sign in to comment.