Commit cff5c133 authored by Ben Skeggs's avatar Ben Skeggs

drm/nouveau: add more fine-grained locking to channel list + structures

Signed-off-by: default avatarBen Skeggs <bskeggs@redhat.com>
parent 6a6b73f2
This diff is collapsed.
...@@ -195,9 +195,8 @@ nouveau_pci_suspend(struct pci_dev *pdev, pm_message_t pm_state) ...@@ -195,9 +195,8 @@ nouveau_pci_suspend(struct pci_dev *pdev, pm_message_t pm_state)
for (i = 0; i < pfifo->channels; i++) { for (i = 0; i < pfifo->channels; i++) {
struct nouveau_fence *fence = NULL; struct nouveau_fence *fence = NULL;
chan = dev_priv->fifos[i]; chan = dev_priv->channels.ptr[i];
if (!chan || (dev_priv->card_type >= NV_50 && if (!chan || !chan->pushbuf_bo)
chan == dev_priv->fifos[0]))
continue; continue;
ret = nouveau_fence_new(chan, &fence, true); ret = nouveau_fence_new(chan, &fence, true);
...@@ -313,7 +312,7 @@ nouveau_pci_resume(struct pci_dev *pdev) ...@@ -313,7 +312,7 @@ nouveau_pci_resume(struct pci_dev *pdev)
int j; int j;
for (i = 0; i < dev_priv->engine.fifo.channels; i++) { for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
chan = dev_priv->fifos[i]; chan = dev_priv->channels.ptr[i];
if (!chan || !chan->pushbuf_bo) if (!chan || !chan->pushbuf_bo)
continue; continue;
......
...@@ -166,6 +166,7 @@ struct nouveau_channel { ...@@ -166,6 +166,7 @@ struct nouveau_channel {
struct drm_device *dev; struct drm_device *dev;
int id; int id;
atomic_t refcount;
struct mutex mutex; struct mutex mutex;
/* owner of this fifo */ /* owner of this fifo */
...@@ -607,8 +608,10 @@ struct drm_nouveau_private { ...@@ -607,8 +608,10 @@ struct drm_nouveau_private {
struct nouveau_bo *bo; struct nouveau_bo *bo;
} fence; } fence;
int fifo_alloc_count; struct {
struct nouveau_channel *fifos[NOUVEAU_MAX_CHANNEL_NR]; spinlock_t lock;
struct nouveau_channel *ptr[NOUVEAU_MAX_CHANNEL_NR];
} channels;
struct nouveau_engine engine; struct nouveau_engine engine;
struct nouveau_channel *channel; struct nouveau_channel *channel;
...@@ -721,16 +724,6 @@ nouveau_bo_ref(struct nouveau_bo *ref, struct nouveau_bo **pnvbo) ...@@ -721,16 +724,6 @@ nouveau_bo_ref(struct nouveau_bo *ref, struct nouveau_bo **pnvbo)
return 0; return 0;
} }
#define NOUVEAU_GET_USER_CHANNEL_WITH_RETURN(id, cl, ch) do { \
struct drm_nouveau_private *nv = dev->dev_private; \
if (!nouveau_channel_owner(dev, (cl), (id))) { \
NV_ERROR(dev, "pid %d doesn't own channel %d\n", \
DRM_CURRENTPID, (id)); \
return -EPERM; \
} \
(ch) = nv->fifos[(id)]; \
} while (0)
/* nouveau_drv.c */ /* nouveau_drv.c */
extern int nouveau_agpmode; extern int nouveau_agpmode;
extern int nouveau_duallink; extern int nouveau_duallink;
...@@ -805,13 +798,13 @@ extern int nouveau_ioctl_notifier_free(struct drm_device *, void *data, ...@@ -805,13 +798,13 @@ extern int nouveau_ioctl_notifier_free(struct drm_device *, void *data,
extern struct drm_ioctl_desc nouveau_ioctls[]; extern struct drm_ioctl_desc nouveau_ioctls[];
extern int nouveau_max_ioctl; extern int nouveau_max_ioctl;
extern void nouveau_channel_cleanup(struct drm_device *, struct drm_file *); extern void nouveau_channel_cleanup(struct drm_device *, struct drm_file *);
extern int nouveau_channel_owner(struct drm_device *, struct drm_file *,
int channel);
extern int nouveau_channel_alloc(struct drm_device *dev, extern int nouveau_channel_alloc(struct drm_device *dev,
struct nouveau_channel **chan, struct nouveau_channel **chan,
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 void nouveau_channel_free(struct nouveau_channel *); extern struct nouveau_channel *
nouveau_channel_get(struct drm_device *, struct drm_file *, int id);
extern void nouveau_channel_put(struct nouveau_channel **);
/* nouveau_object.c */ /* nouveau_object.c */
extern int nouveau_gpuobj_early_init(struct drm_device *); extern int nouveau_gpuobj_early_init(struct drm_device *);
......
...@@ -393,8 +393,18 @@ nouveau_fence_sync(struct nouveau_fence *fence, ...@@ -393,8 +393,18 @@ nouveau_fence_sync(struct nouveau_fence *fence,
return nouveau_fence_wait(fence, NULL, false, false); return nouveau_fence_wait(fence, NULL, false, false);
} }
/* try to take wchan's mutex, if we can't take it right away
* we have to fallback to software sync to prevent locking
* order issues
*/
if (!mutex_trylock(&wchan->mutex)) {
free_semaphore(&sema->ref);
return nouveau_fence_wait(fence, NULL, false, false);
}
/* Make wchan wait until it gets signalled */ /* Make wchan wait until it gets signalled */
ret = emit_semaphore(wchan, NV_SW_SEMAPHORE_ACQUIRE, sema); ret = emit_semaphore(wchan, NV_SW_SEMAPHORE_ACQUIRE, sema);
mutex_unlock(&wchan->mutex);
if (ret) if (ret)
goto out; goto out;
......
...@@ -146,11 +146,6 @@ nouveau_gem_ioctl_new(struct drm_device *dev, void *data, ...@@ -146,11 +146,6 @@ nouveau_gem_ioctl_new(struct drm_device *dev, void *data,
if (unlikely(dev_priv->ttm.bdev.dev_mapping == NULL)) if (unlikely(dev_priv->ttm.bdev.dev_mapping == NULL))
dev_priv->ttm.bdev.dev_mapping = dev_priv->dev->dev_mapping; dev_priv->ttm.bdev.dev_mapping = dev_priv->dev->dev_mapping;
if (req->channel_hint) {
NOUVEAU_GET_USER_CHANNEL_WITH_RETURN(req->channel_hint,
file_priv, chan);
}
if (req->info.domain & NOUVEAU_GEM_DOMAIN_VRAM) if (req->info.domain & NOUVEAU_GEM_DOMAIN_VRAM)
flags |= TTM_PL_FLAG_VRAM; flags |= TTM_PL_FLAG_VRAM;
if (req->info.domain & NOUVEAU_GEM_DOMAIN_GART) if (req->info.domain & NOUVEAU_GEM_DOMAIN_GART)
...@@ -161,10 +156,18 @@ nouveau_gem_ioctl_new(struct drm_device *dev, void *data, ...@@ -161,10 +156,18 @@ nouveau_gem_ioctl_new(struct drm_device *dev, void *data,
if (!nouveau_gem_tile_flags_valid(dev, req->info.tile_flags)) if (!nouveau_gem_tile_flags_valid(dev, req->info.tile_flags))
return -EINVAL; return -EINVAL;
if (req->channel_hint) {
chan = nouveau_channel_get(dev, file_priv, req->channel_hint);
if (IS_ERR(chan))
return PTR_ERR(chan);
}
ret = nouveau_gem_new(dev, chan, req->info.size, req->align, flags, ret = nouveau_gem_new(dev, chan, req->info.size, req->align, flags,
req->info.tile_mode, req->info.tile_flags, false, req->info.tile_mode, req->info.tile_flags, false,
(req->info.domain & NOUVEAU_GEM_DOMAIN_MAPPABLE), (req->info.domain & NOUVEAU_GEM_DOMAIN_MAPPABLE),
&nvbo); &nvbo);
if (chan)
nouveau_channel_put(&chan);
if (ret) if (ret)
return ret; return ret;
...@@ -341,9 +344,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv, ...@@ -341,9 +344,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
return -EINVAL; return -EINVAL;
} }
mutex_unlock(&drm_global_mutex);
ret = ttm_bo_wait_cpu(&nvbo->bo, false); ret = ttm_bo_wait_cpu(&nvbo->bo, false);
mutex_lock(&drm_global_mutex);
if (ret) { if (ret) {
NV_ERROR(dev, "fail wait_cpu\n"); NV_ERROR(dev, "fail wait_cpu\n");
return ret; return ret;
...@@ -585,7 +586,9 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data, ...@@ -585,7 +586,9 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
struct nouveau_fence *fence = NULL; struct nouveau_fence *fence = NULL;
int i, j, ret = 0, do_reloc = 0; int i, j, ret = 0, do_reloc = 0;
NOUVEAU_GET_USER_CHANNEL_WITH_RETURN(req->channel, file_priv, chan); chan = nouveau_channel_get(dev, file_priv, req->channel);
if (IS_ERR(chan))
return PTR_ERR(chan);
req->vram_available = dev_priv->fb_aper_free; req->vram_available = dev_priv->fb_aper_free;
req->gart_available = dev_priv->gart_info.aper_free; req->gart_available = dev_priv->gart_info.aper_free;
...@@ -595,28 +598,34 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data, ...@@ -595,28 +598,34 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
if (unlikely(req->nr_push > NOUVEAU_GEM_MAX_PUSH)) { if (unlikely(req->nr_push > NOUVEAU_GEM_MAX_PUSH)) {
NV_ERROR(dev, "pushbuf push count exceeds limit: %d max %d\n", NV_ERROR(dev, "pushbuf push count exceeds limit: %d max %d\n",
req->nr_push, NOUVEAU_GEM_MAX_PUSH); req->nr_push, NOUVEAU_GEM_MAX_PUSH);
nouveau_channel_put(&chan);
return -EINVAL; return -EINVAL;
} }
if (unlikely(req->nr_buffers > NOUVEAU_GEM_MAX_BUFFERS)) { if (unlikely(req->nr_buffers > NOUVEAU_GEM_MAX_BUFFERS)) {
NV_ERROR(dev, "pushbuf bo count exceeds limit: %d max %d\n", NV_ERROR(dev, "pushbuf bo count exceeds limit: %d max %d\n",
req->nr_buffers, NOUVEAU_GEM_MAX_BUFFERS); req->nr_buffers, NOUVEAU_GEM_MAX_BUFFERS);
nouveau_channel_put(&chan);
return -EINVAL; return -EINVAL;
} }
if (unlikely(req->nr_relocs > NOUVEAU_GEM_MAX_RELOCS)) { if (unlikely(req->nr_relocs > NOUVEAU_GEM_MAX_RELOCS)) {
NV_ERROR(dev, "pushbuf reloc count exceeds limit: %d max %d\n", NV_ERROR(dev, "pushbuf reloc count exceeds limit: %d max %d\n",
req->nr_relocs, NOUVEAU_GEM_MAX_RELOCS); req->nr_relocs, NOUVEAU_GEM_MAX_RELOCS);
nouveau_channel_put(&chan);
return -EINVAL; return -EINVAL;
} }
push = u_memcpya(req->push, req->nr_push, sizeof(*push)); push = u_memcpya(req->push, req->nr_push, sizeof(*push));
if (IS_ERR(push)) if (IS_ERR(push)) {
nouveau_channel_put(&chan);
return PTR_ERR(push); return PTR_ERR(push);
}
bo = u_memcpya(req->buffers, req->nr_buffers, sizeof(*bo)); bo = u_memcpya(req->buffers, req->nr_buffers, sizeof(*bo));
if (IS_ERR(bo)) { if (IS_ERR(bo)) {
kfree(push); kfree(push);
nouveau_channel_put(&chan);
return PTR_ERR(bo); return PTR_ERR(bo);
} }
...@@ -750,6 +759,7 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data, ...@@ -750,6 +759,7 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
req->suffix1 = 0x00000000; req->suffix1 = 0x00000000;
} }
nouveau_channel_put(&chan);
return ret; return ret;
} }
......
...@@ -113,15 +113,17 @@ nouveau_fifo_swmthd(struct drm_device *dev, u32 chid, u32 addr, u32 data) ...@@ -113,15 +113,17 @@ nouveau_fifo_swmthd(struct drm_device *dev, u32 chid, u32 addr, u32 data)
struct drm_nouveau_private *dev_priv = dev->dev_private; struct drm_nouveau_private *dev_priv = dev->dev_private;
struct nouveau_channel *chan = NULL; struct nouveau_channel *chan = NULL;
struct nouveau_gpuobj *obj; struct nouveau_gpuobj *obj;
unsigned long flags;
const int subc = (addr >> 13) & 0x7; const int subc = (addr >> 13) & 0x7;
const int mthd = addr & 0x1ffc; const int mthd = addr & 0x1ffc;
bool handled = false; bool handled = false;
u32 engine; u32 engine;
spin_lock_irqsave(&dev_priv->channels.lock, flags);
if (likely(chid >= 0 && chid < dev_priv->engine.fifo.channels)) if (likely(chid >= 0 && chid < dev_priv->engine.fifo.channels))
chan = dev_priv->fifos[chid]; chan = dev_priv->channels.ptr[chid];
if (unlikely(!chan)) if (unlikely(!chan))
return false; goto out;
switch (mthd) { switch (mthd) {
case 0x0000: /* bind object to subchannel */ case 0x0000: /* bind object to subchannel */
...@@ -146,6 +148,8 @@ nouveau_fifo_swmthd(struct drm_device *dev, u32 chid, u32 addr, u32 data) ...@@ -146,6 +148,8 @@ nouveau_fifo_swmthd(struct drm_device *dev, u32 chid, u32 addr, u32 data)
break; break;
} }
out:
spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
return handled; return handled;
} }
...@@ -398,6 +402,8 @@ static int ...@@ -398,6 +402,8 @@ static int
nouveau_graph_chid_from_grctx(struct drm_device *dev) nouveau_graph_chid_from_grctx(struct drm_device *dev)
{ {
struct drm_nouveau_private *dev_priv = dev->dev_private; struct drm_nouveau_private *dev_priv = dev->dev_private;
struct nouveau_channel *chan;
unsigned long flags;
uint32_t inst; uint32_t inst;
int i; int i;
...@@ -407,27 +413,29 @@ nouveau_graph_chid_from_grctx(struct drm_device *dev) ...@@ -407,27 +413,29 @@ nouveau_graph_chid_from_grctx(struct drm_device *dev)
if (dev_priv->card_type < NV_50) { if (dev_priv->card_type < NV_50) {
inst = (nv_rd32(dev, 0x40032c) & 0xfffff) << 4; inst = (nv_rd32(dev, 0x40032c) & 0xfffff) << 4;
spin_lock_irqsave(&dev_priv->channels.lock, flags);
for (i = 0; i < dev_priv->engine.fifo.channels; i++) { for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
struct nouveau_channel *chan = dev_priv->fifos[i]; chan = dev_priv->channels.ptr[i];
if (!chan || !chan->ramin_grctx) if (!chan || !chan->ramin_grctx)
continue; continue;
if (inst == chan->ramin_grctx->pinst) if (inst == chan->ramin_grctx->pinst)
break; break;
} }
spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
} else { } else {
inst = (nv_rd32(dev, 0x40032c) & 0xfffff) << 12; inst = (nv_rd32(dev, 0x40032c) & 0xfffff) << 12;
spin_lock_irqsave(&dev_priv->channels.lock, flags);
for (i = 0; i < dev_priv->engine.fifo.channels; i++) { for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
struct nouveau_channel *chan = dev_priv->fifos[i]; chan = dev_priv->channels.ptr[i];
if (!chan || !chan->ramin) if (!chan || !chan->ramin)
continue; continue;
if (inst == chan->ramin->vinst) if (inst == chan->ramin->vinst)
break; break;
} }
spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
} }
...@@ -449,7 +457,8 @@ nouveau_graph_trapped_channel(struct drm_device *dev, int *channel_ret) ...@@ -449,7 +457,8 @@ nouveau_graph_trapped_channel(struct drm_device *dev, int *channel_ret)
else else
channel = nouveau_graph_chid_from_grctx(dev); channel = nouveau_graph_chid_from_grctx(dev);
if (channel >= engine->fifo.channels || !dev_priv->fifos[channel]) { if (channel >= engine->fifo.channels ||
!dev_priv->channels.ptr[channel]) {
NV_ERROR(dev, "AIII, invalid/inactive channel id %d\n", channel); NV_ERROR(dev, "AIII, invalid/inactive channel id %d\n", channel);
return -EINVAL; return -EINVAL;
} }
...@@ -532,14 +541,19 @@ nouveau_pgraph_intr_swmthd(struct drm_device *dev, ...@@ -532,14 +541,19 @@ nouveau_pgraph_intr_swmthd(struct drm_device *dev,
struct nouveau_pgraph_trap *trap) struct nouveau_pgraph_trap *trap)
{ {
struct drm_nouveau_private *dev_priv = dev->dev_private; struct drm_nouveau_private *dev_priv = dev->dev_private;
unsigned long flags;
int ret = -EINVAL;
if (trap->channel < 0 || spin_lock_irqsave(&dev_priv->channels.lock, flags);
trap->channel >= dev_priv->engine.fifo.channels || if (trap->channel > 0 &&
!dev_priv->fifos[trap->channel]) trap->channel < dev_priv->engine.fifo.channels &&
return -ENODEV; dev_priv->channels.ptr[trap->channel]) {
ret = nouveau_call_method(dev_priv->channels.ptr[trap->channel],
return nouveau_call_method(dev_priv->fifos[trap->channel],
trap->class, trap->mthd, trap->data); trap->class, trap->mthd, trap->data);
}
spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
return ret;
} }
static inline void static inline void
......
...@@ -185,11 +185,11 @@ nouveau_ioctl_notifier_alloc(struct drm_device *dev, void *data, ...@@ -185,11 +185,11 @@ nouveau_ioctl_notifier_alloc(struct drm_device *dev, void *data,
struct nouveau_channel *chan; struct nouveau_channel *chan;
int ret; int ret;
NOUVEAU_GET_USER_CHANNEL_WITH_RETURN(na->channel, file_priv, chan); chan = nouveau_channel_get(dev, file_priv, na->channel);
if (IS_ERR(chan))
return PTR_ERR(chan);
ret = nouveau_notifier_alloc(chan, na->handle, na->size, &na->offset); ret = nouveau_notifier_alloc(chan, na->handle, na->size, &na->offset);
if (ret) nouveau_channel_put(&chan);
return ret; return ret;
return 0;
} }
...@@ -876,8 +876,6 @@ int nouveau_ioctl_grobj_alloc(struct drm_device *dev, void *data, ...@@ -876,8 +876,6 @@ int nouveau_ioctl_grobj_alloc(struct drm_device *dev, void *data,
struct nouveau_channel *chan; struct nouveau_channel *chan;
int ret; int ret;
NOUVEAU_GET_USER_CHANNEL_WITH_RETURN(init->channel, file_priv, chan);
if (init->handle == ~0) if (init->handle == ~0)
return -EINVAL; return -EINVAL;
...@@ -893,8 +891,14 @@ int nouveau_ioctl_grobj_alloc(struct drm_device *dev, void *data, ...@@ -893,8 +891,14 @@ int nouveau_ioctl_grobj_alloc(struct drm_device *dev, void *data,
return -EPERM; return -EPERM;
} }
if (nouveau_ramht_find(chan, init->handle)) chan = nouveau_channel_get(dev, file_priv, init->channel);
return -EEXIST; if (IS_ERR(chan))
return PTR_ERR(chan);
if (nouveau_ramht_find(chan, init->handle)) {
ret = -EEXIST;
goto out;
}
if (!grc->software) if (!grc->software)
ret = nouveau_gpuobj_gr_new(chan, grc->id, &gr); ret = nouveau_gpuobj_gr_new(chan, grc->id, &gr);
...@@ -903,7 +907,7 @@ int nouveau_ioctl_grobj_alloc(struct drm_device *dev, void *data, ...@@ -903,7 +907,7 @@ int nouveau_ioctl_grobj_alloc(struct drm_device *dev, void *data,
if (ret) { if (ret) {
NV_ERROR(dev, "Error creating object: %d (%d/0x%08x)\n", NV_ERROR(dev, "Error creating object: %d (%d/0x%08x)\n",
ret, init->channel, init->handle); ret, init->channel, init->handle);
return ret; goto out;
} }
ret = nouveau_ramht_insert(chan, init->handle, gr); ret = nouveau_ramht_insert(chan, init->handle, gr);
...@@ -911,10 +915,11 @@ int nouveau_ioctl_grobj_alloc(struct drm_device *dev, void *data, ...@@ -911,10 +915,11 @@ int nouveau_ioctl_grobj_alloc(struct drm_device *dev, void *data,
if (ret) { if (ret) {
NV_ERROR(dev, "Error referencing object: %d (%d/0x%08x)\n", NV_ERROR(dev, "Error referencing object: %d (%d/0x%08x)\n",
ret, init->channel, init->handle); ret, init->channel, init->handle);
return ret;
} }
return 0; out:
nouveau_channel_put(&chan);
return ret;
} }
int nouveau_ioctl_gpuobj_free(struct drm_device *dev, void *data, int nouveau_ioctl_gpuobj_free(struct drm_device *dev, void *data,
...@@ -923,15 +928,20 @@ int nouveau_ioctl_gpuobj_free(struct drm_device *dev, void *data, ...@@ -923,15 +928,20 @@ int nouveau_ioctl_gpuobj_free(struct drm_device *dev, void *data,
struct drm_nouveau_gpuobj_free *objfree = data; struct drm_nouveau_gpuobj_free *objfree = data;
struct nouveau_gpuobj *gpuobj; struct nouveau_gpuobj *gpuobj;
struct nouveau_channel *chan; struct nouveau_channel *chan;
int ret = -ENOENT;
NOUVEAU_GET_USER_CHANNEL_WITH_RETURN(objfree->channel, file_priv, chan); chan = nouveau_channel_get(dev, file_priv, objfree->channel);
if (IS_ERR(chan))
return PTR_ERR(chan);
gpuobj = nouveau_ramht_find(chan, objfree->handle); gpuobj = nouveau_ramht_find(chan, objfree->handle);
if (!gpuobj) if (gpuobj) {
return -ENOENT;
nouveau_ramht_remove(chan, objfree->handle); nouveau_ramht_remove(chan, objfree->handle);
return 0; ret = 0;
}
nouveau_channel_put(&chan);
return ret;
} }
u32 u32
......
...@@ -516,11 +516,11 @@ nouveau_card_init_channel(struct drm_device *dev) ...@@ -516,11 +516,11 @@ nouveau_card_init_channel(struct drm_device *dev)
if (ret) if (ret)
goto out_err; goto out_err;
mutex_unlock(&dev_priv->channel->mutex);
return 0; return 0;
out_err: out_err:
nouveau_channel_free(dev_priv->channel); nouveau_channel_put(&dev_priv->channel);
dev_priv->channel = NULL;
return ret; return ret;
} }
...@@ -567,6 +567,7 @@ nouveau_card_init(struct drm_device *dev) ...@@ -567,6 +567,7 @@ nouveau_card_init(struct drm_device *dev)
if (ret) if (ret)
goto out; goto out;
engine = &dev_priv->engine; engine = &dev_priv->engine;
spin_lock_init(&dev_priv->channels.lock);
spin_lock_init(&dev_priv->context_switch_lock); spin_lock_init(&dev_priv->context_switch_lock);
/* Make the CRTCs and I2C buses accessible */ /* Make the CRTCs and I2C buses accessible */
...@@ -713,8 +714,7 @@ static void nouveau_card_takedown(struct drm_device *dev) ...@@ -713,8 +714,7 @@ static void nouveau_card_takedown(struct drm_device *dev)
if (!engine->graph.accel_blocked) { if (!engine->graph.accel_blocked) {
nouveau_fence_fini(dev); nouveau_fence_fini(dev);
nouveau_channel_free(dev_priv->channel); nouveau_channel_put(&dev_priv->channel);
dev_priv->channel = NULL;
} }
if (!nouveau_noaccel) { if (!nouveau_noaccel) {
......
...@@ -208,7 +208,7 @@ nv04_fifo_unload_context(struct drm_device *dev) ...@@ -208,7 +208,7 @@ nv04_fifo_unload_context(struct drm_device *dev)
if (chid < 0 || chid >= dev_priv->engine.fifo.channels) if (chid < 0 || chid >= dev_priv->engine.fifo.channels)
return 0; return 0;
chan = dev_priv->fifos[chid]; chan = dev_priv->channels.ptr[chid];
if (!chan) { if (!chan) {
NV_ERROR(dev, "Inactive channel on PFIFO: %d\n", chid); NV_ERROR(dev, "Inactive channel on PFIFO: %d\n", chid);
return -EINVAL; return -EINVAL;
...@@ -289,7 +289,7 @@ nv04_fifo_init(struct drm_device *dev) ...@@ -289,7 +289,7 @@ nv04_fifo_init(struct drm_device *dev)
pfifo->reassign(dev, true); pfifo->reassign(dev, true);
for (i = 0; i < dev_priv->engine.fifo.channels; i++) { for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
if (dev_priv->fifos[i]) { if (dev_priv->channels.ptr[i]) {
uint32_t mode = nv_rd32(dev, NV04_PFIFO_MODE); uint32_t mode = nv_rd32(dev, NV04_PFIFO_MODE);
nv_wr32(dev, NV04_PFIFO_MODE, mode | (1 << i)); nv_wr32(dev, NV04_PFIFO_MODE, mode | (1 << i));
} }
......
...@@ -357,7 +357,7 @@ nv04_graph_channel(struct drm_device *dev) ...@@ -357,7 +357,7 @@ nv04_graph_channel(struct drm_device *dev)
if (chid >= dev_priv->engine.fifo.channels) if (chid >= dev_priv->engine.fifo.channels)
return NULL; return NULL;
return dev_priv->fifos[chid]; return dev_priv->channels.ptr[chid];
} }
void void
...@@ -376,7 +376,7 @@ nv04_graph_context_switch(struct drm_device *dev) ...@@ -376,7 +376,7 @@ nv04_graph_context_switch(struct drm_device *dev)
/* Load context for next channel */ /* Load context for next channel */
chid = dev_priv->engine.fifo.channel_id(dev); chid = dev_priv->engine.fifo.channel_id(dev);
chan = dev_priv->fifos[chid]; chan = dev_priv->channels.ptr[chid];
if (chan) if (chan)
nv04_graph_load_context(chan); nv04_graph_load_context(chan);
......
...@@ -241,7 +241,7 @@ nv10_fifo_init(struct drm_device *dev) ...@@ -241,7 +241,7 @@ nv10_fifo_init(struct drm_device *dev)
pfifo->reassign(dev, true); pfifo->reassign(dev, true);
for (i = 0; i < dev_priv->engine.fifo.channels; i++) { for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
if (dev_priv->fifos[i]) { if (dev_priv->channels.ptr[i]) {
uint32_t mode = nv_rd32(dev, NV04_PFIFO_MODE); uint32_t mode = nv_rd32(dev, NV04_PFIFO_MODE);
nv_wr32(dev, NV04_PFIFO_MODE, mode | (1 << i)); nv_wr32(dev, NV04_PFIFO_MODE, mode | (1 << i));
} }
......
...@@ -802,7 +802,7 @@ nv10_graph_context_switch(struct drm_device *dev) ...@@ -802,7 +802,7 @@ nv10_graph_context_switch(struct drm_device *dev)
/* Load context for next channel */ /* Load context for next channel */
chid = (nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR) >> 20) & 0x1f; chid = (nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR) >> 20) & 0x1f;
chan = dev_priv->fifos[chid]; chan = dev_priv->channels.ptr[chid];
if (chan && chan->pgraph_ctx) if (chan && chan->pgraph_ctx)
nv10_graph_load_context(chan); nv10_graph_load_context(chan);
...@@ -833,7 +833,7 @@ nv10_graph_channel(struct drm_device *dev) ...@@ -833,7 +833,7 @@ nv10_graph_channel(struct drm_device *dev)
if (chid >= dev_priv->engine.fifo.channels) if (chid >= dev_priv->engine.fifo.channels)
return NULL; return NULL;
return dev_priv->fifos[chid]; return dev_priv->channels.ptr[chid];
} }
int nv10_graph_create_context(struct nouveau_channel *chan) int nv10_graph_create_context(struct nouveau_channel *chan)
......
...@@ -301,7 +301,7 @@ nv40_fifo_init(struct drm_device *dev) ...@@ -301,7 +301,7 @@ nv40_fifo_init(struct drm_device *dev)
pfifo->reassign(dev, true); pfifo->reassign(dev, true);
for (i = 0; i < dev_priv->engine.fifo.channels; i++) { for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
if (dev_priv->fifos[i]) { if (dev_priv->channels.ptr[i]) {
uint32_t mode = nv_rd32(dev, NV04_PFIFO_MODE); uint32_t mode = nv_rd32(dev, NV04_PFIFO_MODE);
nv_wr32(dev, NV04_PFIFO_MODE, mode | (1 << i)); nv_wr32(dev, NV04_PFIFO_MODE, mode | (1 << i));
} }
......
...@@ -42,7 +42,7 @@ nv40_graph_channel(struct drm_device *dev) ...@@ -42,7 +42,7 @@ nv40_graph_channel(struct drm_device *dev)
inst = (inst & NV40_PGRAPH_CTXCTL_CUR_INSTANCE) << 4; inst = (inst & NV40_PGRAPH_CTXCTL_CUR_INSTANCE) << 4;
for (i = 0; i < dev_priv->engine.fifo.channels; i++) { for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
struct nouveau_channel *chan = dev_priv->fifos[i]; struct nouveau_channel *chan = dev_priv->channels.ptr[i];
if (chan && chan->ramin_grctx && if (chan && chan->ramin_grctx &&
chan->ramin_grctx->pinst == inst) chan->ramin_grctx->pinst == inst)
......
...@@ -42,6 +42,7 @@ void ...@@ -42,6 +42,7 @@ void
nv50_fb_vm_trap(struct drm_device *dev, int display, const char *name) nv50_fb_vm_trap(struct drm_device *dev, int display, const char *name)
{ {
struct drm_nouveau_private *dev_priv = dev->dev_private; struct drm_nouveau_private *dev_priv = dev->dev_private;
unsigned long flags;
u32 trap[6], idx, chinst; u32 trap[6], idx, chinst;
int i, ch; int i, ch;
...@@ -60,8 +61,10 @@ nv50_fb_vm_trap(struct drm_device *dev, int display, const char *name) ...@@ -60,8 +61,10 @@ nv50_fb_vm_trap(struct drm_device *dev, int display, const char *name)
return; return;
chinst = (trap[2] << 16) | trap[1]; chinst = (trap[2] << 16) | trap[1];
spin_lock_irqsave(&dev_priv->channels.lock, flags);
for (ch = 0; ch < dev_priv->engine.fifo.channels; ch++) { for (ch = 0; ch < dev_priv->engine.fifo.channels; ch++) {
struct nouveau_channel *chan = dev_priv->fifos[ch]; struct nouveau_channel *chan = dev_priv->channels.ptr[ch];
if (!chan || !chan->ramin) if (!chan || !chan->ramin)
continue; continue;
...@@ -69,6 +72,7 @@ nv50_fb_vm_trap(struct drm_device *dev, int display, const char *name) ...@@ -69,6 +72,7 @@ nv50_fb_vm_trap(struct drm_device *dev, int display, const char *name)
if (chinst == chan->ramin->vinst >> 12) if (chinst == chan->ramin->vinst >> 12)
break; break;
} }
spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
NV_INFO(dev, "%s - VM: Trapped %s at %02x%04x%04x status %08x " NV_INFO(dev, "%s - VM: Trapped %s at %02x%04x%04x status %08x "
"channel %d (0x%08x)\n", "channel %d (0x%08x)\n",
......
...@@ -44,7 +44,8 @@ nv50_fifo_playlist_update(struct drm_device *dev) ...@@ -44,7 +44,8 @@ nv50_fifo_playlist_update(struct drm_device *dev)
/* We never schedule channel 0 or 127 */ /* We never schedule channel 0 or 127 */
for (i = 1, nr = 0; i < 127; i++) { for (i = 1, nr = 0; i < 127; i++) {
if (dev_priv->fifos[i] && dev_priv->fifos[i]->ramfc) { if (dev_priv->channels.ptr[i] &&
dev_priv->channels.ptr[i]->ramfc) {
nv_wo32(cur, (nr * 4), i); nv_wo32(cur, (nr * 4), i);
nr++; nr++;
} }
...@@ -60,7 +61,7 @@ static void ...@@ -60,7 +61,7 @@ static void
nv50_fifo_channel_enable(struct drm_device *dev, int channel) nv50_fifo_channel_enable(struct drm_device *dev, int channel)
{ {
struct drm_nouveau_private *dev_priv = dev->dev_private; struct drm_nouveau_private *dev_priv = dev->dev_private;
struct nouveau_channel *chan = dev_priv->fifos[channel]; struct nouveau_channel *chan = dev_priv->channels.ptr[channel];
uint32_t inst; uint32_t inst;
NV_DEBUG(dev, "ch%d\n", channel); NV_DEBUG(dev, "ch%d\n", channel);
...@@ -118,7 +119,7 @@ nv50_fifo_init_context_table(struct drm_device *dev) ...@@ -118,7 +119,7 @@ nv50_fifo_init_context_table(struct drm_device *dev)
NV_DEBUG(dev, "\n"); NV_DEBUG(dev, "\n");
for (i = 0; i < NV50_PFIFO_CTX_TABLE__SIZE; i++) { for (i = 0; i < NV50_PFIFO_CTX_TABLE__SIZE; i++) {
if (dev_priv->fifos[i]) if (dev_priv->channels.ptr[i])
nv50_fifo_channel_enable(dev, i); nv50_fifo_channel_enable(dev, i);
else else
nv50_fifo_channel_disable(dev, i); nv50_fifo_channel_disable(dev, i);
...@@ -392,7 +393,7 @@ nv50_fifo_unload_context(struct drm_device *dev) ...@@ -392,7 +393,7 @@ nv50_fifo_unload_context(struct drm_device *dev)
if (chid < 1 || chid >= dev_priv->engine.fifo.channels - 1) if (chid < 1 || chid >= dev_priv->engine.fifo.channels - 1)
return 0; return 0;
chan = dev_priv->fifos[chid]; chan = dev_priv->channels.ptr[chid];
if (!chan) { if (!chan) {
NV_ERROR(dev, "Inactive channel on PFIFO: %d\n", chid); NV_ERROR(dev, "Inactive channel on PFIFO: %d\n", chid);
return -EINVAL; return -EINVAL;
......
...@@ -190,7 +190,7 @@ nv50_graph_channel(struct drm_device *dev) ...@@ -190,7 +190,7 @@ nv50_graph_channel(struct drm_device *dev)
inst = (inst & NV50_PGRAPH_CTXCTL_CUR_INSTANCE) << 12; inst = (inst & NV50_PGRAPH_CTXCTL_CUR_INSTANCE) << 12;
for (i = 0; i < dev_priv->engine.fifo.channels; i++) { for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
struct nouveau_channel *chan = dev_priv->fifos[i]; struct nouveau_channel *chan = dev_priv->channels.ptr[i];
if (chan && chan->ramin && chan->ramin->vinst == inst) if (chan && chan->ramin && chan->ramin->vinst == inst)
return chan; return chan;
......
...@@ -131,10 +131,10 @@ nv50_instmem_init(struct drm_device *dev) ...@@ -131,10 +131,10 @@ nv50_instmem_init(struct drm_device *dev)
} }
/* we need a channel to plug into the hw to control the BARs */ /* we need a channel to plug into the hw to control the BARs */
ret = nv50_channel_new(dev, 128*1024, &dev_priv->fifos[0]); ret = nv50_channel_new(dev, 128*1024, &dev_priv->channels.ptr[0]);
if (ret) if (ret)
return ret; return ret;
chan = dev_priv->fifos[127] = dev_priv->fifos[0]; chan = dev_priv->channels.ptr[127] = dev_priv->channels.ptr[0];
/* allocate page table for PRAMIN BAR */ /* allocate page table for PRAMIN BAR */
ret = nouveau_gpuobj_new(dev, chan, (dev_priv->ramin_size >> 12) * 8, ret = nouveau_gpuobj_new(dev, chan, (dev_priv->ramin_size >> 12) * 8,
...@@ -240,7 +240,7 @@ nv50_instmem_takedown(struct drm_device *dev) ...@@ -240,7 +240,7 @@ nv50_instmem_takedown(struct drm_device *dev)
{ {
struct drm_nouveau_private *dev_priv = dev->dev_private; struct drm_nouveau_private *dev_priv = dev->dev_private;
struct nv50_instmem_priv *priv = dev_priv->engine.instmem.priv; struct nv50_instmem_priv *priv = dev_priv->engine.instmem.priv;
struct nouveau_channel *chan = dev_priv->fifos[0]; struct nouveau_channel *chan = dev_priv->channels.ptr[0];
int i; int i;
NV_DEBUG(dev, "\n"); NV_DEBUG(dev, "\n");
...@@ -264,8 +264,8 @@ nv50_instmem_takedown(struct drm_device *dev) ...@@ -264,8 +264,8 @@ nv50_instmem_takedown(struct drm_device *dev)
nouveau_gpuobj_ref(NULL, &chan->vm_vram_pt[i]); nouveau_gpuobj_ref(NULL, &chan->vm_vram_pt[i]);
dev_priv->vm_vram_pt_nr = 0; dev_priv->vm_vram_pt_nr = 0;
nv50_channel_del(&dev_priv->fifos[0]); nv50_channel_del(&dev_priv->channels.ptr[0]);
dev_priv->fifos[127] = NULL; dev_priv->channels.ptr[127] = NULL;
} }
dev_priv->engine.instmem.priv = NULL; dev_priv->engine.instmem.priv = NULL;
...@@ -276,7 +276,7 @@ int ...@@ -276,7 +276,7 @@ int
nv50_instmem_suspend(struct drm_device *dev) nv50_instmem_suspend(struct drm_device *dev)
{ {
struct drm_nouveau_private *dev_priv = dev->dev_private; struct drm_nouveau_private *dev_priv = dev->dev_private;
struct nouveau_channel *chan = dev_priv->fifos[0]; struct nouveau_channel *chan = dev_priv->channels.ptr[0];
struct nouveau_gpuobj *ramin = chan->ramin; struct nouveau_gpuobj *ramin = chan->ramin;
int i; int i;
...@@ -294,7 +294,7 @@ nv50_instmem_resume(struct drm_device *dev) ...@@ -294,7 +294,7 @@ nv50_instmem_resume(struct drm_device *dev)
{ {
struct drm_nouveau_private *dev_priv = dev->dev_private; struct drm_nouveau_private *dev_priv = dev->dev_private;
struct nv50_instmem_priv *priv = dev_priv->engine.instmem.priv; struct nv50_instmem_priv *priv = dev_priv->engine.instmem.priv;
struct nouveau_channel *chan = dev_priv->fifos[0]; struct nouveau_channel *chan = dev_priv->channels.ptr[0];
struct nouveau_gpuobj *ramin = chan->ramin; struct nouveau_gpuobj *ramin = chan->ramin;
int i; int i;
......
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