2009-12-11 17:24:15 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2006 Ben Skeggs.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
* portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Authors:
|
|
|
|
* Ben Skeggs <darktama@iinet.net.au>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "drmP.h"
|
|
|
|
#include "drm.h"
|
|
|
|
#include "nouveau_drv.h"
|
|
|
|
#include "nouveau_drm.h"
|
2012-05-01 18:48:08 +08:00
|
|
|
#include "nouveau_fifo.h"
|
2010-09-01 13:24:28 +08:00
|
|
|
#include "nouveau_ramht.h"
|
2012-05-01 00:33:43 +08:00
|
|
|
#include "nouveau_software.h"
|
2010-11-15 09:54:21 +08:00
|
|
|
#include "nouveau_vm.h"
|
2009-12-11 17:24:15 +08:00
|
|
|
|
2010-10-20 08:39:35 +08:00
|
|
|
struct nouveau_gpuobj_method {
|
|
|
|
struct list_head head;
|
|
|
|
u32 mthd;
|
|
|
|
int (*exec)(struct nouveau_channel *, u32 class, u32 mthd, u32 data);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nouveau_gpuobj_class {
|
|
|
|
struct list_head head;
|
|
|
|
struct list_head methods;
|
|
|
|
u32 id;
|
|
|
|
u32 engine;
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
nouveau_gpuobj_class_new(struct drm_device *dev, u32 class, u32 engine)
|
|
|
|
{
|
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
|
|
|
struct nouveau_gpuobj_class *oc;
|
|
|
|
|
|
|
|
oc = kzalloc(sizeof(*oc), GFP_KERNEL);
|
|
|
|
if (!oc)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&oc->methods);
|
|
|
|
oc->id = class;
|
|
|
|
oc->engine = engine;
|
|
|
|
list_add(&oc->head, &dev_priv->classes);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nouveau_gpuobj_mthd_new(struct drm_device *dev, u32 class, u32 mthd,
|
|
|
|
int (*exec)(struct nouveau_channel *, u32, u32, u32))
|
|
|
|
{
|
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
|
|
|
struct nouveau_gpuobj_method *om;
|
|
|
|
struct nouveau_gpuobj_class *oc;
|
|
|
|
|
|
|
|
list_for_each_entry(oc, &dev_priv->classes, head) {
|
|
|
|
if (oc->id == class)
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
found:
|
|
|
|
om = kzalloc(sizeof(*om), GFP_KERNEL);
|
|
|
|
if (!om)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
om->mthd = mthd;
|
|
|
|
om->exec = exec;
|
|
|
|
list_add(&om->head, &oc->methods);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nouveau_gpuobj_mthd_call(struct nouveau_channel *chan,
|
|
|
|
u32 class, u32 mthd, u32 data)
|
|
|
|
{
|
|
|
|
struct drm_nouveau_private *dev_priv = chan->dev->dev_private;
|
|
|
|
struct nouveau_gpuobj_method *om;
|
|
|
|
struct nouveau_gpuobj_class *oc;
|
|
|
|
|
|
|
|
list_for_each_entry(oc, &dev_priv->classes, head) {
|
|
|
|
if (oc->id != class)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
list_for_each_entry(om, &oc->methods, head) {
|
|
|
|
if (om->mthd == mthd)
|
|
|
|
return om->exec(chan, class, mthd, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2010-11-03 11:16:18 +08:00
|
|
|
int
|
|
|
|
nouveau_gpuobj_mthd_call2(struct drm_device *dev, int chid,
|
|
|
|
u32 class, u32 mthd, u32 data)
|
|
|
|
{
|
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
2012-05-01 18:48:08 +08:00
|
|
|
struct nouveau_fifo_priv *pfifo = nv_engine(dev, NVOBJ_ENGINE_FIFO);
|
2010-11-03 11:16:18 +08:00
|
|
|
struct nouveau_channel *chan = NULL;
|
|
|
|
unsigned long flags;
|
|
|
|
int ret = -EINVAL;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&dev_priv->channels.lock, flags);
|
2012-05-01 18:48:08 +08:00
|
|
|
if (chid >= 0 && chid < pfifo->channels)
|
2010-11-03 11:16:18 +08:00
|
|
|
chan = dev_priv->channels.ptr[chid];
|
|
|
|
if (chan)
|
|
|
|
ret = nouveau_gpuobj_mthd_call(chan, class, mthd, data);
|
|
|
|
spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-12-11 17:24:15 +08:00
|
|
|
int
|
|
|
|
nouveau_gpuobj_new(struct drm_device *dev, struct nouveau_channel *chan,
|
|
|
|
uint32_t size, int align, uint32_t flags,
|
|
|
|
struct nouveau_gpuobj **gpuobj_ret)
|
|
|
|
{
|
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
2010-11-01 09:45:02 +08:00
|
|
|
struct nouveau_instmem_engine *instmem = &dev_priv->engine.instmem;
|
2009-12-11 17:24:15 +08:00
|
|
|
struct nouveau_gpuobj *gpuobj;
|
2010-09-01 13:24:33 +08:00
|
|
|
struct drm_mm_node *ramin = NULL;
|
2010-11-01 09:45:02 +08:00
|
|
|
int ret, i;
|
2009-12-11 17:24:15 +08:00
|
|
|
|
|
|
|
NV_DEBUG(dev, "ch%d size=%u align=%d flags=0x%08x\n",
|
|
|
|
chan ? chan->id : -1, size, align, flags);
|
|
|
|
|
|
|
|
gpuobj = kzalloc(sizeof(*gpuobj), GFP_KERNEL);
|
|
|
|
if (!gpuobj)
|
|
|
|
return -ENOMEM;
|
|
|
|
NV_DEBUG(dev, "gpuobj %p\n", gpuobj);
|
2010-09-01 13:24:29 +08:00
|
|
|
gpuobj->dev = dev;
|
2009-12-11 17:24:15 +08:00
|
|
|
gpuobj->flags = flags;
|
2010-09-01 13:24:37 +08:00
|
|
|
kref_init(&gpuobj->refcount);
|
2010-09-01 13:24:32 +08:00
|
|
|
gpuobj->size = size;
|
2009-12-11 17:24:15 +08:00
|
|
|
|
2010-09-01 13:24:38 +08:00
|
|
|
spin_lock(&dev_priv->ramin_lock);
|
2009-12-11 17:24:15 +08:00
|
|
|
list_add_tail(&gpuobj->list, &dev_priv->gpuobj_list);
|
2010-09-01 13:24:38 +08:00
|
|
|
spin_unlock(&dev_priv->ramin_lock);
|
2009-12-11 17:24:15 +08:00
|
|
|
|
2011-06-03 12:23:30 +08:00
|
|
|
if (!(flags & NVOBJ_FLAG_VM) && chan) {
|
2010-09-01 13:24:33 +08:00
|
|
|
ramin = drm_mm_search_free(&chan->ramin_heap, size, align, 0);
|
|
|
|
if (ramin)
|
|
|
|
ramin = drm_mm_get_block(ramin, size, align);
|
|
|
|
if (!ramin) {
|
|
|
|
nouveau_gpuobj_ref(NULL, &gpuobj);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2009-12-11 17:24:15 +08:00
|
|
|
|
2010-11-01 09:45:02 +08:00
|
|
|
gpuobj->pinst = chan->ramin->pinst;
|
|
|
|
if (gpuobj->pinst != ~0)
|
|
|
|
gpuobj->pinst += ramin->start;
|
2010-06-01 13:32:24 +08:00
|
|
|
|
2010-11-20 21:42:57 +08:00
|
|
|
gpuobj->cinst = ramin->start;
|
2010-11-01 09:45:02 +08:00
|
|
|
gpuobj->vinst = ramin->start + chan->ramin->vinst;
|
|
|
|
gpuobj->node = ramin;
|
|
|
|
} else {
|
2011-06-03 12:23:30 +08:00
|
|
|
ret = instmem->get(gpuobj, chan, size, align);
|
2009-12-11 17:24:15 +08:00
|
|
|
if (ret) {
|
2010-09-01 13:24:31 +08:00
|
|
|
nouveau_gpuobj_ref(NULL, &gpuobj);
|
2009-12-11 17:24:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2010-09-01 13:24:33 +08:00
|
|
|
|
2010-11-01 09:45:02 +08:00
|
|
|
ret = -ENOSYS;
|
2010-08-27 08:00:25 +08:00
|
|
|
if (!(flags & NVOBJ_FLAG_DONT_MAP))
|
2010-11-01 09:45:02 +08:00
|
|
|
ret = instmem->map(gpuobj);
|
|
|
|
if (ret)
|
2010-09-01 13:24:33 +08:00
|
|
|
gpuobj->pinst = ~0;
|
2010-11-01 09:45:02 +08:00
|
|
|
|
|
|
|
gpuobj->cinst = NVOBJ_CINST_GLOBAL;
|
2010-09-01 13:24:30 +08:00
|
|
|
}
|
|
|
|
|
2009-12-11 17:24:15 +08:00
|
|
|
if (gpuobj->flags & NVOBJ_FLAG_ZERO_ALLOC) {
|
2010-09-01 13:24:32 +08:00
|
|
|
for (i = 0; i < gpuobj->size; i += 4)
|
2010-09-01 13:24:29 +08:00
|
|
|
nv_wo32(gpuobj, i, 0);
|
2010-11-01 09:45:02 +08:00
|
|
|
instmem->flush(dev);
|
2009-12-11 17:24:15 +08:00
|
|
|
}
|
|
|
|
|
2010-09-01 13:24:31 +08:00
|
|
|
|
2009-12-11 17:24:15 +08:00
|
|
|
*gpuobj_ret = gpuobj;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-09-01 13:24:34 +08:00
|
|
|
nouveau_gpuobj_init(struct drm_device *dev)
|
2009-12-11 17:24:15 +08:00
|
|
|
{
|
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
|
|
|
|
|
|
|
NV_DEBUG(dev, "\n");
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&dev_priv->gpuobj_list);
|
2010-10-19 18:06:01 +08:00
|
|
|
INIT_LIST_HEAD(&dev_priv->classes);
|
2010-09-01 13:24:33 +08:00
|
|
|
spin_lock_init(&dev_priv->ramin_lock);
|
|
|
|
dev_priv->ramin_base = ~0;
|
2009-12-11 17:24:15 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nouveau_gpuobj_takedown(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
2010-10-20 08:39:35 +08:00
|
|
|
struct nouveau_gpuobj_method *om, *tm;
|
|
|
|
struct nouveau_gpuobj_class *oc, *tc;
|
2009-12-11 17:24:15 +08:00
|
|
|
|
|
|
|
NV_DEBUG(dev, "\n");
|
|
|
|
|
2010-10-20 08:39:35 +08:00
|
|
|
list_for_each_entry_safe(oc, tc, &dev_priv->classes, head) {
|
|
|
|
list_for_each_entry_safe(om, tm, &oc->methods, head) {
|
|
|
|
list_del(&om->head);
|
|
|
|
kfree(om);
|
|
|
|
}
|
|
|
|
list_del(&oc->head);
|
|
|
|
kfree(oc);
|
|
|
|
}
|
|
|
|
|
2012-05-09 10:47:03 +08:00
|
|
|
WARN_ON(!list_empty(&dev_priv->gpuobj_list));
|
2009-12-11 17:24:15 +08:00
|
|
|
}
|
|
|
|
|
2010-09-01 13:24:39 +08:00
|
|
|
|
2010-09-01 13:24:37 +08:00
|
|
|
static void
|
|
|
|
nouveau_gpuobj_del(struct kref *ref)
|
2009-12-11 17:24:15 +08:00
|
|
|
{
|
2010-09-01 13:24:37 +08:00
|
|
|
struct nouveau_gpuobj *gpuobj =
|
|
|
|
container_of(ref, struct nouveau_gpuobj, refcount);
|
2010-09-01 13:24:31 +08:00
|
|
|
struct drm_device *dev = gpuobj->dev;
|
2009-12-11 17:24:15 +08:00
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
2010-11-01 09:45:02 +08:00
|
|
|
struct nouveau_instmem_engine *instmem = &dev_priv->engine.instmem;
|
2009-12-11 17:24:15 +08:00
|
|
|
int i;
|
|
|
|
|
2010-09-01 13:24:31 +08:00
|
|
|
NV_DEBUG(dev, "gpuobj %p\n", gpuobj);
|
2009-12-11 17:24:15 +08:00
|
|
|
|
2010-11-01 09:45:02 +08:00
|
|
|
if (gpuobj->node && (gpuobj->flags & NVOBJ_FLAG_ZERO_FREE)) {
|
2010-09-01 13:24:32 +08:00
|
|
|
for (i = 0; i < gpuobj->size; i += 4)
|
2010-09-01 13:24:29 +08:00
|
|
|
nv_wo32(gpuobj, i, 0);
|
2010-11-01 09:45:02 +08:00
|
|
|
instmem->flush(dev);
|
2009-12-11 17:24:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gpuobj->dtor)
|
|
|
|
gpuobj->dtor(dev, gpuobj);
|
|
|
|
|
2010-11-01 09:45:02 +08:00
|
|
|
if (gpuobj->cinst == NVOBJ_CINST_GLOBAL) {
|
|
|
|
if (gpuobj->node) {
|
|
|
|
instmem->unmap(gpuobj);
|
|
|
|
instmem->put(gpuobj);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (gpuobj->node) {
|
|
|
|
spin_lock(&dev_priv->ramin_lock);
|
|
|
|
drm_mm_put_block(gpuobj->node);
|
|
|
|
spin_unlock(&dev_priv->ramin_lock);
|
|
|
|
}
|
|
|
|
}
|
2009-12-11 17:24:15 +08:00
|
|
|
|
2010-09-01 13:24:38 +08:00
|
|
|
spin_lock(&dev_priv->ramin_lock);
|
2009-12-11 17:24:15 +08:00
|
|
|
list_del(&gpuobj->list);
|
2010-09-01 13:24:38 +08:00
|
|
|
spin_unlock(&dev_priv->ramin_lock);
|
2009-12-11 17:24:15 +08:00
|
|
|
|
|
|
|
kfree(gpuobj);
|
|
|
|
}
|
|
|
|
|
2010-09-01 13:24:31 +08:00
|
|
|
void
|
|
|
|
nouveau_gpuobj_ref(struct nouveau_gpuobj *ref, struct nouveau_gpuobj **ptr)
|
2009-12-11 17:24:15 +08:00
|
|
|
{
|
2010-09-01 13:24:31 +08:00
|
|
|
if (ref)
|
2010-09-01 13:24:37 +08:00
|
|
|
kref_get(&ref->refcount);
|
2009-12-11 17:24:15 +08:00
|
|
|
|
2010-09-01 13:24:37 +08:00
|
|
|
if (*ptr)
|
|
|
|
kref_put(&(*ptr)->refcount, nouveau_gpuobj_del);
|
2009-12-11 17:24:15 +08:00
|
|
|
|
2010-09-01 13:24:31 +08:00
|
|
|
*ptr = ref;
|
2009-12-11 17:24:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-09-01 13:24:32 +08:00
|
|
|
nouveau_gpuobj_new_fake(struct drm_device *dev, u32 pinst, u64 vinst,
|
|
|
|
u32 size, u32 flags, struct nouveau_gpuobj **pgpuobj)
|
2009-12-11 17:24:15 +08:00
|
|
|
{
|
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
|
|
|
struct nouveau_gpuobj *gpuobj = NULL;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
NV_DEBUG(dev,
|
2010-09-01 13:24:32 +08:00
|
|
|
"pinst=0x%08x vinst=0x%010llx size=0x%08x flags=0x%08x\n",
|
|
|
|
pinst, vinst, size, flags);
|
2009-12-11 17:24:15 +08:00
|
|
|
|
|
|
|
gpuobj = kzalloc(sizeof(*gpuobj), GFP_KERNEL);
|
|
|
|
if (!gpuobj)
|
|
|
|
return -ENOMEM;
|
|
|
|
NV_DEBUG(dev, "gpuobj %p\n", gpuobj);
|
2010-09-01 13:24:29 +08:00
|
|
|
gpuobj->dev = dev;
|
2010-09-01 13:24:32 +08:00
|
|
|
gpuobj->flags = flags;
|
2010-09-01 13:24:37 +08:00
|
|
|
kref_init(&gpuobj->refcount);
|
2010-09-01 13:24:32 +08:00
|
|
|
gpuobj->size = size;
|
|
|
|
gpuobj->pinst = pinst;
|
2010-11-01 09:45:02 +08:00
|
|
|
gpuobj->cinst = NVOBJ_CINST_GLOBAL;
|
2010-09-01 13:24:32 +08:00
|
|
|
gpuobj->vinst = vinst;
|
2010-09-01 13:24:30 +08:00
|
|
|
|
2009-12-11 17:24:15 +08:00
|
|
|
if (gpuobj->flags & NVOBJ_FLAG_ZERO_ALLOC) {
|
2010-09-01 13:24:32 +08:00
|
|
|
for (i = 0; i < gpuobj->size; i += 4)
|
2010-09-01 13:24:29 +08:00
|
|
|
nv_wo32(gpuobj, i, 0);
|
2010-07-08 09:29:10 +08:00
|
|
|
dev_priv->engine.instmem.flush(dev);
|
2009-12-11 17:24:15 +08:00
|
|
|
}
|
|
|
|
|
2010-09-01 13:24:38 +08:00
|
|
|
spin_lock(&dev_priv->ramin_lock);
|
2010-09-01 13:24:32 +08:00
|
|
|
list_add_tail(&gpuobj->list, &dev_priv->gpuobj_list);
|
2010-09-01 13:24:38 +08:00
|
|
|
spin_unlock(&dev_priv->ramin_lock);
|
2010-09-01 13:24:32 +08:00
|
|
|
*pgpuobj = gpuobj;
|
2009-12-11 17:24:15 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-16 09:50:09 +08:00
|
|
|
void
|
|
|
|
nv50_gpuobj_dma_init(struct nouveau_gpuobj *obj, u32 offset, int class,
|
|
|
|
u64 base, u64 size, int target, int access,
|
|
|
|
u32 type, u32 comp)
|
2009-12-11 17:24:15 +08:00
|
|
|
{
|
2010-11-16 09:50:09 +08:00
|
|
|
struct drm_nouveau_private *dev_priv = obj->dev->dev_private;
|
|
|
|
struct nouveau_instmem_engine *pinstmem = &dev_priv->engine.instmem;
|
|
|
|
u32 flags0;
|
2009-12-11 17:24:15 +08:00
|
|
|
|
2010-11-16 09:50:09 +08:00
|
|
|
flags0 = (comp << 29) | (type << 22) | class;
|
|
|
|
flags0 |= 0x00100000;
|
|
|
|
|
|
|
|
switch (access) {
|
|
|
|
case NV_MEM_ACCESS_RO: flags0 |= 0x00040000; break;
|
|
|
|
case NV_MEM_ACCESS_RW:
|
|
|
|
case NV_MEM_ACCESS_WO: flags0 |= 0x00080000; break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-12-11 17:24:15 +08:00
|
|
|
|
|
|
|
switch (target) {
|
2010-11-16 09:50:09 +08:00
|
|
|
case NV_MEM_TARGET_VRAM:
|
|
|
|
flags0 |= 0x00010000;
|
|
|
|
break;
|
|
|
|
case NV_MEM_TARGET_PCI:
|
|
|
|
flags0 |= 0x00020000;
|
|
|
|
break;
|
|
|
|
case NV_MEM_TARGET_PCI_NOSNOOP:
|
|
|
|
flags0 |= 0x00030000;
|
2009-12-11 17:24:15 +08:00
|
|
|
break;
|
2010-11-16 09:50:09 +08:00
|
|
|
case NV_MEM_TARGET_GART:
|
2010-11-16 08:13:05 +08:00
|
|
|
base += dev_priv->gart_info.aper_base;
|
2009-12-11 17:24:15 +08:00
|
|
|
default:
|
2010-11-16 09:50:09 +08:00
|
|
|
flags0 &= ~0x00100000;
|
2009-12-11 17:24:15 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-11-16 09:50:09 +08:00
|
|
|
/* convert to base + limit */
|
|
|
|
size = (base + size) - 1;
|
2009-12-11 17:24:15 +08:00
|
|
|
|
2010-11-16 09:50:09 +08:00
|
|
|
nv_wo32(obj, offset + 0x00, flags0);
|
|
|
|
nv_wo32(obj, offset + 0x04, lower_32_bits(size));
|
|
|
|
nv_wo32(obj, offset + 0x08, lower_32_bits(base));
|
|
|
|
nv_wo32(obj, offset + 0x0c, upper_32_bits(size) << 24 |
|
|
|
|
upper_32_bits(base));
|
|
|
|
nv_wo32(obj, offset + 0x10, 0x00000000);
|
|
|
|
nv_wo32(obj, offset + 0x14, 0x00000000);
|
2009-12-11 17:24:15 +08:00
|
|
|
|
2010-11-16 09:50:09 +08:00
|
|
|
pinstmem->flush(obj->dev);
|
|
|
|
}
|
2009-12-11 17:24:15 +08:00
|
|
|
|
2010-11-16 09:50:09 +08:00
|
|
|
int
|
|
|
|
nv50_gpuobj_dma_new(struct nouveau_channel *chan, int class, u64 base, u64 size,
|
|
|
|
int target, int access, u32 type, u32 comp,
|
|
|
|
struct nouveau_gpuobj **pobj)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = chan->dev;
|
|
|
|
int ret;
|
2009-12-11 17:24:15 +08:00
|
|
|
|
2010-11-26 08:32:22 +08:00
|
|
|
ret = nouveau_gpuobj_new(dev, chan, 24, 16, NVOBJ_FLAG_ZERO_FREE, pobj);
|
2010-11-16 09:50:09 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2009-12-11 17:24:15 +08:00
|
|
|
|
2010-11-16 09:50:09 +08:00
|
|
|
nv50_gpuobj_dma_init(*pobj, 0, class, base, size, target,
|
|
|
|
access, type, comp);
|
2009-12-11 17:24:15 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-11-16 09:50:09 +08:00
|
|
|
nouveau_gpuobj_dma_new(struct nouveau_channel *chan, int class, u64 base,
|
|
|
|
u64 size, int access, int target,
|
|
|
|
struct nouveau_gpuobj **pobj)
|
2009-12-11 17:24:15 +08:00
|
|
|
{
|
2010-11-16 09:50:09 +08:00
|
|
|
struct drm_nouveau_private *dev_priv = chan->dev->dev_private;
|
2009-12-11 17:24:15 +08:00
|
|
|
struct drm_device *dev = chan->dev;
|
2010-11-16 09:50:09 +08:00
|
|
|
struct nouveau_gpuobj *obj;
|
2010-12-08 09:37:12 +08:00
|
|
|
u32 flags0, flags2;
|
2009-12-11 17:24:15 +08:00
|
|
|
int ret;
|
|
|
|
|
2010-11-16 09:50:09 +08:00
|
|
|
if (dev_priv->card_type >= NV_50) {
|
|
|
|
u32 comp = (target == NV_MEM_TARGET_VM) ? NV_MEM_COMP_VM : 0;
|
|
|
|
u32 type = (target == NV_MEM_TARGET_VM) ? NV_MEM_TYPE_VM : 0;
|
|
|
|
|
|
|
|
return nv50_gpuobj_dma_new(chan, class, base, size,
|
|
|
|
target, access, type, comp, pobj);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target == NV_MEM_TARGET_GART) {
|
2011-01-11 12:10:09 +08:00
|
|
|
struct nouveau_gpuobj *gart = dev_priv->gart_info.sg_ctxdma;
|
|
|
|
|
|
|
|
if (dev_priv->gart_info.type == NOUVEAU_GART_PDMA) {
|
|
|
|
if (base == 0) {
|
|
|
|
nouveau_gpuobj_ref(gart, pobj);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
base = nouveau_sgdma_get_physical(dev, base);
|
2010-11-16 09:50:09 +08:00
|
|
|
target = NV_MEM_TARGET_PCI;
|
|
|
|
} else {
|
2011-01-11 12:10:09 +08:00
|
|
|
base += dev_priv->gart_info.aper_base;
|
|
|
|
if (dev_priv->gart_info.type == NOUVEAU_GART_AGP)
|
|
|
|
target = NV_MEM_TARGET_PCI_NOSNOOP;
|
|
|
|
else
|
|
|
|
target = NV_MEM_TARGET_PCI;
|
2009-12-11 17:24:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-16 09:50:09 +08:00
|
|
|
flags0 = class;
|
|
|
|
flags0 |= 0x00003000; /* PT present, PT linear */
|
|
|
|
flags2 = 0;
|
|
|
|
|
|
|
|
switch (target) {
|
|
|
|
case NV_MEM_TARGET_PCI:
|
|
|
|
flags0 |= 0x00020000;
|
|
|
|
break;
|
|
|
|
case NV_MEM_TARGET_PCI_NOSNOOP:
|
|
|
|
flags0 |= 0x00030000;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (access) {
|
|
|
|
case NV_MEM_ACCESS_RO:
|
|
|
|
flags0 |= 0x00004000;
|
|
|
|
break;
|
|
|
|
case NV_MEM_ACCESS_WO:
|
|
|
|
flags0 |= 0x00008000;
|
|
|
|
default:
|
|
|
|
flags2 |= 0x00000002;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
flags0 |= (base & 0x00000fff) << 20;
|
|
|
|
flags2 |= (base & 0xfffff000);
|
|
|
|
|
2010-11-26 08:32:22 +08:00
|
|
|
ret = nouveau_gpuobj_new(dev, chan, 16, 16, NVOBJ_FLAG_ZERO_FREE, &obj);
|
2010-11-16 09:50:09 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
nv_wo32(obj, 0x00, flags0);
|
|
|
|
nv_wo32(obj, 0x04, size - 1);
|
|
|
|
nv_wo32(obj, 0x08, flags2);
|
|
|
|
nv_wo32(obj, 0x0c, flags2);
|
|
|
|
|
|
|
|
obj->engine = NVOBJ_ENGINE_SW;
|
|
|
|
obj->class = class;
|
|
|
|
*pobj = obj;
|
|
|
|
return 0;
|
2009-12-11 17:24:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-11-23 08:10:24 +08:00
|
|
|
nouveau_gpuobj_gr_new(struct nouveau_channel *chan, u32 handle, int class)
|
2009-12-11 17:24:15 +08:00
|
|
|
{
|
2010-10-19 17:57:34 +08:00
|
|
|
struct drm_nouveau_private *dev_priv = chan->dev->dev_private;
|
2009-12-11 17:24:15 +08:00
|
|
|
struct drm_device *dev = chan->dev;
|
2010-10-20 08:39:35 +08:00
|
|
|
struct nouveau_gpuobj_class *oc;
|
2009-12-11 17:24:15 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
NV_DEBUG(dev, "ch%d class=0x%04x\n", chan->id, class);
|
|
|
|
|
2010-10-20 08:39:35 +08:00
|
|
|
list_for_each_entry(oc, &dev_priv->classes, head) {
|
2011-04-01 11:56:05 +08:00
|
|
|
struct nouveau_exec_engine *eng = dev_priv->eng[oc->engine];
|
2010-10-19 17:57:34 +08:00
|
|
|
|
2011-04-01 11:56:05 +08:00
|
|
|
if (oc->id != class)
|
|
|
|
continue;
|
2010-10-19 17:57:34 +08:00
|
|
|
|
2011-04-01 11:56:05 +08:00
|
|
|
if (!chan->engctx[oc->engine]) {
|
|
|
|
ret = eng->context_new(chan, oc->engine);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2011-04-01 07:50:18 +08:00
|
|
|
}
|
2009-12-11 17:24:15 +08:00
|
|
|
|
2011-04-01 11:56:05 +08:00
|
|
|
return eng->object_new(chan, oc->engine, handle, class);
|
2009-12-11 17:24:15 +08:00
|
|
|
}
|
2010-11-23 08:10:24 +08:00
|
|
|
|
2011-04-01 11:56:05 +08:00
|
|
|
return -EINVAL;
|
2009-12-11 17:24:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nouveau_gpuobj_channel_init_pramin(struct nouveau_channel *chan)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = chan->dev;
|
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
|
|
|
uint32_t size;
|
|
|
|
uint32_t base;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
NV_DEBUG(dev, "ch%d\n", chan->id);
|
|
|
|
|
|
|
|
/* Base amount for object storage (4KiB enough?) */
|
2010-10-19 18:06:01 +08:00
|
|
|
size = 0x2000;
|
2009-12-11 17:24:15 +08:00
|
|
|
base = 0;
|
|
|
|
|
|
|
|
if (dev_priv->card_type == NV_50) {
|
|
|
|
/* Various fixed table thingos */
|
|
|
|
size += 0x1400; /* mostly unknown stuff */
|
|
|
|
size += 0x4000; /* vm pd */
|
|
|
|
base = 0x6000;
|
|
|
|
/* RAMHT, not sure about setting size yet, 32KiB to be safe */
|
|
|
|
size += 0x8000;
|
|
|
|
/* RAMFC */
|
|
|
|
size += 0x1000;
|
|
|
|
}
|
|
|
|
|
2010-09-01 13:24:31 +08:00
|
|
|
ret = nouveau_gpuobj_new(dev, NULL, size, 0x1000, 0, &chan->ramin);
|
2009-12-11 17:24:15 +08:00
|
|
|
if (ret) {
|
|
|
|
NV_ERROR(dev, "Error allocating channel PRAMIN: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-11-23 03:58:31 +08:00
|
|
|
ret = drm_mm_init(&chan->ramin_heap, base, size - base);
|
2009-12-11 17:24:15 +08:00
|
|
|
if (ret) {
|
|
|
|
NV_ERROR(dev, "Error creating PRAMIN heap: %d\n", ret);
|
2010-09-01 13:24:31 +08:00
|
|
|
nouveau_gpuobj_ref(NULL, &chan->ramin);
|
2009-12-11 17:24:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-06-08 16:17:41 +08:00
|
|
|
static int
|
|
|
|
nvc0_gpuobj_channel_init(struct nouveau_channel *chan, struct nouveau_vm *vm)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = chan->dev;
|
|
|
|
struct nouveau_gpuobj *pgd = NULL;
|
|
|
|
struct nouveau_vm_pgd *vpgd;
|
2012-05-01 00:34:10 +08:00
|
|
|
int ret;
|
2011-06-08 16:17:41 +08:00
|
|
|
|
|
|
|
ret = nouveau_gpuobj_new(dev, NULL, 4096, 0x1000, 0, &chan->ramin);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* create page directory for this vm if none currently exists,
|
|
|
|
* will be destroyed automagically when last reference to the
|
|
|
|
* vm is removed
|
|
|
|
*/
|
|
|
|
if (list_empty(&vm->pgd_list)) {
|
|
|
|
ret = nouveau_gpuobj_new(dev, NULL, 65536, 0x1000, 0, &pgd);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
nouveau_vm_ref(vm, &chan->vm, pgd);
|
|
|
|
nouveau_gpuobj_ref(NULL, &pgd);
|
|
|
|
|
|
|
|
/* point channel at vm's page directory */
|
|
|
|
vpgd = list_first_entry(&vm->pgd_list, struct nouveau_vm_pgd, head);
|
|
|
|
nv_wo32(chan->ramin, 0x0200, lower_32_bits(vpgd->obj->vinst));
|
|
|
|
nv_wo32(chan->ramin, 0x0204, upper_32_bits(vpgd->obj->vinst));
|
|
|
|
nv_wo32(chan->ramin, 0x0208, 0xffffffff);
|
|
|
|
nv_wo32(chan->ramin, 0x020c, 0x000000ff);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-11 17:24:15 +08:00
|
|
|
int
|
|
|
|
nouveau_gpuobj_channel_init(struct nouveau_channel *chan,
|
|
|
|
uint32_t vram_h, uint32_t tt_h)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = chan->dev;
|
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
2011-06-03 08:20:52 +08:00
|
|
|
struct nouveau_fpriv *fpriv = nouveau_fpriv(chan->file_priv);
|
|
|
|
struct nouveau_vm *vm = fpriv ? fpriv->vm : dev_priv->chan_vm;
|
2009-12-11 17:24:15 +08:00
|
|
|
struct nouveau_gpuobj *vram = NULL, *tt = NULL;
|
2012-05-01 00:34:10 +08:00
|
|
|
int ret;
|
2009-12-11 17:24:15 +08:00
|
|
|
|
|
|
|
NV_DEBUG(dev, "ch%d vram=0x%08x tt=0x%08x\n", chan->id, vram_h, tt_h);
|
2011-07-02 18:28:49 +08:00
|
|
|
if (dev_priv->card_type >= NV_C0)
|
2011-06-08 16:17:41 +08:00
|
|
|
return nvc0_gpuobj_channel_init(chan, vm);
|
2010-11-24 08:15:05 +08:00
|
|
|
|
2010-07-08 11:15:05 +08:00
|
|
|
/* Allocate a chunk of memory for per-channel object storage */
|
|
|
|
ret = nouveau_gpuobj_channel_init_pramin(chan);
|
|
|
|
if (ret) {
|
|
|
|
NV_ERROR(dev, "init pramin\n");
|
|
|
|
return ret;
|
2009-12-11 17:24:15 +08:00
|
|
|
}
|
|
|
|
|
2010-11-24 08:15:05 +08:00
|
|
|
/* NV50 VM
|
2009-12-11 17:24:15 +08:00
|
|
|
* - Allocate per-channel page-directory
|
2010-11-15 09:54:21 +08:00
|
|
|
* - Link with shared channel VM
|
2009-12-11 17:24:15 +08:00
|
|
|
*/
|
2011-06-03 08:20:52 +08:00
|
|
|
if (vm) {
|
2010-09-01 13:24:33 +08:00
|
|
|
u32 pgd_offs = (dev_priv->chipset == 0x50) ? 0x1400 : 0x0200;
|
|
|
|
u64 vm_vinst = chan->ramin->vinst + pgd_offs;
|
|
|
|
u32 vm_pinst = chan->ramin->pinst;
|
2009-12-11 17:24:15 +08:00
|
|
|
|
2010-09-01 13:24:33 +08:00
|
|
|
if (vm_pinst != ~0)
|
|
|
|
vm_pinst += pgd_offs;
|
2009-12-11 17:24:15 +08:00
|
|
|
|
2010-09-01 13:24:33 +08:00
|
|
|
ret = nouveau_gpuobj_new_fake(dev, vm_pinst, vm_vinst, 0x4000,
|
2010-09-01 13:24:31 +08:00
|
|
|
0, &chan->vm_pd);
|
2010-07-08 09:29:10 +08:00
|
|
|
if (ret)
|
2009-12-11 17:24:15 +08:00
|
|
|
return ret;
|
|
|
|
|
2011-06-03 08:20:52 +08:00
|
|
|
nouveau_vm_ref(vm, &chan->vm, chan->vm_pd);
|
2009-12-11 17:24:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* RAMHT */
|
|
|
|
if (dev_priv->card_type < NV_50) {
|
2010-09-01 13:24:31 +08:00
|
|
|
nouveau_ramht_ref(dev_priv->ramht, &chan->ramht, NULL);
|
|
|
|
} else {
|
|
|
|
struct nouveau_gpuobj *ramht = NULL;
|
|
|
|
|
|
|
|
ret = nouveau_gpuobj_new(dev, chan, 0x8000, 16,
|
|
|
|
NVOBJ_FLAG_ZERO_ALLOC, &ramht);
|
2009-12-11 17:24:15 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2010-09-01 13:24:31 +08:00
|
|
|
|
|
|
|
ret = nouveau_ramht_new(dev, ramht, &chan->ramht);
|
|
|
|
nouveau_gpuobj_ref(NULL, &ramht);
|
2009-12-11 17:24:15 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* VRAM ctxdma */
|
|
|
|
if (dev_priv->card_type >= NV_50) {
|
|
|
|
ret = nouveau_gpuobj_dma_new(chan, NV_CLASS_DMA_IN_MEMORY,
|
2010-11-15 09:54:21 +08:00
|
|
|
0, (1ULL << 40), NV_MEM_ACCESS_RW,
|
2010-11-16 09:50:09 +08:00
|
|
|
NV_MEM_TARGET_VM, &vram);
|
2009-12-11 17:24:15 +08:00
|
|
|
if (ret) {
|
|
|
|
NV_ERROR(dev, "Error creating VRAM ctxdma: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ret = nouveau_gpuobj_dma_new(chan, NV_CLASS_DMA_IN_MEMORY,
|
2010-09-01 13:24:31 +08:00
|
|
|
0, dev_priv->fb_available_size,
|
2010-11-16 09:50:09 +08:00
|
|
|
NV_MEM_ACCESS_RW,
|
|
|
|
NV_MEM_TARGET_VRAM, &vram);
|
2009-12-11 17:24:15 +08:00
|
|
|
if (ret) {
|
|
|
|
NV_ERROR(dev, "Error creating VRAM ctxdma: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-01 13:24:31 +08:00
|
|
|
ret = nouveau_ramht_insert(chan, vram_h, vram);
|
|
|
|
nouveau_gpuobj_ref(NULL, &vram);
|
2009-12-11 17:24:15 +08:00
|
|
|
if (ret) {
|
2010-09-01 13:24:31 +08:00
|
|
|
NV_ERROR(dev, "Error adding VRAM ctxdma to RAMHT: %d\n", ret);
|
2009-12-11 17:24:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TT memory ctxdma */
|
|
|
|
if (dev_priv->card_type >= NV_50) {
|
2010-09-01 13:24:31 +08:00
|
|
|
ret = nouveau_gpuobj_dma_new(chan, NV_CLASS_DMA_IN_MEMORY,
|
2010-11-15 09:54:21 +08:00
|
|
|
0, (1ULL << 40), NV_MEM_ACCESS_RW,
|
2010-11-16 09:50:09 +08:00
|
|
|
NV_MEM_TARGET_VM, &tt);
|
2009-12-11 17:24:15 +08:00
|
|
|
} else {
|
2010-11-16 09:50:09 +08:00
|
|
|
ret = nouveau_gpuobj_dma_new(chan, NV_CLASS_DMA_IN_MEMORY,
|
|
|
|
0, dev_priv->gart_info.aper_size,
|
|
|
|
NV_MEM_ACCESS_RW,
|
|
|
|
NV_MEM_TARGET_GART, &tt);
|
2009-12-11 17:24:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
NV_ERROR(dev, "Error creating TT ctxdma: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-09-01 13:24:31 +08:00
|
|
|
ret = nouveau_ramht_insert(chan, tt_h, tt);
|
|
|
|
nouveau_gpuobj_ref(NULL, &tt);
|
2009-12-11 17:24:15 +08:00
|
|
|
if (ret) {
|
2010-09-01 13:24:31 +08:00
|
|
|
NV_ERROR(dev, "Error adding TT ctxdma to RAMHT: %d\n", ret);
|
2009-12-11 17:24:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nouveau_gpuobj_channel_takedown(struct nouveau_channel *chan)
|
|
|
|
{
|
2012-05-01 00:34:10 +08:00
|
|
|
NV_DEBUG(chan->dev, "ch%d\n", chan->id);
|
2009-12-11 17:24:15 +08:00
|
|
|
|
2011-07-11 13:46:01 +08:00
|
|
|
nouveau_vm_ref(NULL, &chan->vm, chan->vm_pd);
|
|
|
|
nouveau_gpuobj_ref(NULL, &chan->vm_pd);
|
|
|
|
|
2011-02-19 00:59:11 +08:00
|
|
|
if (drm_mm_initialized(&chan->ramin_heap))
|
2010-06-01 13:32:24 +08:00
|
|
|
drm_mm_takedown(&chan->ramin_heap);
|
2010-09-01 13:24:31 +08:00
|
|
|
nouveau_gpuobj_ref(NULL, &chan->ramin);
|
2009-12-11 17:24:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nouveau_gpuobj_suspend(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
|
|
|
struct nouveau_gpuobj *gpuobj;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
list_for_each_entry(gpuobj, &dev_priv->gpuobj_list, list) {
|
2010-11-01 09:45:02 +08:00
|
|
|
if (gpuobj->cinst != NVOBJ_CINST_GLOBAL)
|
2009-12-11 17:24:15 +08:00
|
|
|
continue;
|
|
|
|
|
2010-10-25 13:23:59 +08:00
|
|
|
gpuobj->suspend = vmalloc(gpuobj->size);
|
|
|
|
if (!gpuobj->suspend) {
|
2009-12-11 17:24:15 +08:00
|
|
|
nouveau_gpuobj_resume(dev);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2010-09-01 13:24:32 +08:00
|
|
|
for (i = 0; i < gpuobj->size; i += 4)
|
2010-10-25 13:23:59 +08:00
|
|
|
gpuobj->suspend[i/4] = nv_ro32(gpuobj, i);
|
2009-12-11 17:24:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nouveau_gpuobj_resume(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
|
|
|
struct nouveau_gpuobj *gpuobj;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
list_for_each_entry(gpuobj, &dev_priv->gpuobj_list, list) {
|
2010-10-25 13:23:59 +08:00
|
|
|
if (!gpuobj->suspend)
|
2009-12-11 17:24:15 +08:00
|
|
|
continue;
|
|
|
|
|
2010-09-01 13:24:32 +08:00
|
|
|
for (i = 0; i < gpuobj->size; i += 4)
|
2010-10-25 13:23:59 +08:00
|
|
|
nv_wo32(gpuobj, i, gpuobj->suspend[i/4]);
|
|
|
|
|
|
|
|
vfree(gpuobj->suspend);
|
|
|
|
gpuobj->suspend = NULL;
|
2009-12-11 17:24:15 +08:00
|
|
|
}
|
|
|
|
|
2010-10-25 13:23:59 +08:00
|
|
|
dev_priv->engine.instmem.flush(dev);
|
2009-12-11 17:24:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int nouveau_ioctl_grobj_alloc(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
|
|
|
{
|
|
|
|
struct drm_nouveau_grobj_alloc *init = data;
|
|
|
|
struct nouveau_channel *chan;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (init->handle == ~0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2012-05-01 00:33:43 +08:00
|
|
|
/* compatibility with userspace that assumes 506e for all chipsets */
|
|
|
|
if (init->class == 0x506e) {
|
|
|
|
init->class = nouveau_software_class(dev);
|
|
|
|
if (init->class == 0x906e)
|
|
|
|
return 0;
|
|
|
|
} else
|
|
|
|
if (init->class == 0x906e) {
|
|
|
|
NV_ERROR(dev, "906e not supported yet\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2011-06-01 17:18:48 +08:00
|
|
|
chan = nouveau_channel_get(file_priv, init->channel);
|
2010-10-06 14:16:59 +08:00
|
|
|
if (IS_ERR(chan))
|
|
|
|
return PTR_ERR(chan);
|
|
|
|
|
|
|
|
if (nouveau_ramht_find(chan, init->handle)) {
|
|
|
|
ret = -EEXIST;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-12-11 17:24:15 +08:00
|
|
|
|
2010-11-23 08:10:24 +08:00
|
|
|
ret = nouveau_gpuobj_gr_new(chan, init->handle, init->class);
|
2009-12-11 17:24:15 +08:00
|
|
|
if (ret) {
|
|
|
|
NV_ERROR(dev, "Error creating object: %d (%d/0x%08x)\n",
|
|
|
|
ret, init->channel, init->handle);
|
|
|
|
}
|
|
|
|
|
2010-10-06 14:16:59 +08:00
|
|
|
out:
|
|
|
|
nouveau_channel_put(&chan);
|
|
|
|
return ret;
|
2009-12-11 17:24:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int nouveau_ioctl_gpuobj_free(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
|
|
|
{
|
|
|
|
struct drm_nouveau_gpuobj_free *objfree = data;
|
|
|
|
struct nouveau_channel *chan;
|
2010-10-12 08:11:00 +08:00
|
|
|
int ret;
|
2009-12-11 17:24:15 +08:00
|
|
|
|
2011-06-01 17:18:48 +08:00
|
|
|
chan = nouveau_channel_get(file_priv, objfree->channel);
|
2010-10-06 14:16:59 +08:00
|
|
|
if (IS_ERR(chan))
|
|
|
|
return PTR_ERR(chan);
|
2009-12-11 17:24:15 +08:00
|
|
|
|
2010-11-19 06:57:46 +08:00
|
|
|
/* Synchronize with the user channel */
|
|
|
|
nouveau_channel_idle(chan);
|
|
|
|
|
2010-10-12 08:11:00 +08:00
|
|
|
ret = nouveau_ramht_remove(chan, objfree->handle);
|
2010-10-06 14:16:59 +08:00
|
|
|
nouveau_channel_put(&chan);
|
|
|
|
return ret;
|
2009-12-11 17:24:15 +08:00
|
|
|
}
|
2010-09-01 13:24:29 +08:00
|
|
|
|
|
|
|
u32
|
|
|
|
nv_ro32(struct nouveau_gpuobj *gpuobj, u32 offset)
|
|
|
|
{
|
2010-09-01 13:24:33 +08:00
|
|
|
struct drm_nouveau_private *dev_priv = gpuobj->dev->dev_private;
|
|
|
|
struct drm_device *dev = gpuobj->dev;
|
2011-04-06 11:28:35 +08:00
|
|
|
unsigned long flags;
|
2010-09-01 13:24:33 +08:00
|
|
|
|
|
|
|
if (gpuobj->pinst == ~0 || !dev_priv->ramin_available) {
|
|
|
|
u64 ptr = gpuobj->vinst + offset;
|
|
|
|
u32 base = ptr >> 16;
|
|
|
|
u32 val;
|
|
|
|
|
2011-04-06 11:28:35 +08:00
|
|
|
spin_lock_irqsave(&dev_priv->vm_lock, flags);
|
2010-09-01 13:24:33 +08:00
|
|
|
if (dev_priv->ramin_base != base) {
|
|
|
|
dev_priv->ramin_base = base;
|
|
|
|
nv_wr32(dev, 0x001700, dev_priv->ramin_base);
|
|
|
|
}
|
|
|
|
val = nv_rd32(dev, 0x700000 + (ptr & 0xffff));
|
2011-04-06 11:28:35 +08:00
|
|
|
spin_unlock_irqrestore(&dev_priv->vm_lock, flags);
|
2010-09-01 13:24:33 +08:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nv_ri32(dev, gpuobj->pinst + offset);
|
2010-09-01 13:24:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nv_wo32(struct nouveau_gpuobj *gpuobj, u32 offset, u32 val)
|
|
|
|
{
|
2010-09-01 13:24:33 +08:00
|
|
|
struct drm_nouveau_private *dev_priv = gpuobj->dev->dev_private;
|
|
|
|
struct drm_device *dev = gpuobj->dev;
|
2011-04-06 11:28:35 +08:00
|
|
|
unsigned long flags;
|
2010-09-01 13:24:33 +08:00
|
|
|
|
|
|
|
if (gpuobj->pinst == ~0 || !dev_priv->ramin_available) {
|
|
|
|
u64 ptr = gpuobj->vinst + offset;
|
|
|
|
u32 base = ptr >> 16;
|
|
|
|
|
2011-04-06 11:28:35 +08:00
|
|
|
spin_lock_irqsave(&dev_priv->vm_lock, flags);
|
2010-09-01 13:24:33 +08:00
|
|
|
if (dev_priv->ramin_base != base) {
|
|
|
|
dev_priv->ramin_base = base;
|
|
|
|
nv_wr32(dev, 0x001700, dev_priv->ramin_base);
|
|
|
|
}
|
|
|
|
nv_wr32(dev, 0x700000 + (ptr & 0xffff), val);
|
2011-04-06 11:28:35 +08:00
|
|
|
spin_unlock_irqrestore(&dev_priv->vm_lock, flags);
|
2010-09-01 13:24:33 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nv_wi32(dev, gpuobj->pinst + offset, val);
|
2010-09-01 13:24:29 +08:00
|
|
|
}
|