2009-12-11 19:24:15 +10:00
|
|
|
#include <linux/pagemap.h>
|
2010-03-24 17:04:11 +09:00
|
|
|
#include <linux/slab.h>
|
2009-12-11 19:24:15 +10:00
|
|
|
|
2016-05-20 09:22:55 +10:00
|
|
|
#include "nouveau_drv.h"
|
2012-07-20 08:17:34 +10:00
|
|
|
#include "nouveau_ttm.h"
|
2009-12-11 19:24:15 +10:00
|
|
|
|
|
|
|
|
struct nouveau_sgdma_be {
|
2011-11-09 17:15:26 -05:00
|
|
|
/* this has to be the first field so populate/unpopulated in
|
|
|
|
|
* nouve_bo.c works properly, otherwise have to move them here
|
|
|
|
|
*/
|
|
|
|
|
struct ttm_dma_tt ttm;
|
2015-01-14 15:36:34 +10:00
|
|
|
struct nvkm_mem *node;
|
2009-12-11 19:24:15 +10:00
|
|
|
};
|
|
|
|
|
|
2011-01-10 16:24:00 +10:00
|
|
|
static void
|
2011-11-01 20:46:13 -04:00
|
|
|
nouveau_sgdma_destroy(struct ttm_tt *ttm)
|
2011-01-10 16:24:00 +10:00
|
|
|
{
|
2011-11-01 20:46:13 -04:00
|
|
|
struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
|
2011-01-10 16:24:00 +10:00
|
|
|
|
2011-11-01 20:46:13 -04:00
|
|
|
if (ttm) {
|
2011-11-09 17:15:26 -05:00
|
|
|
ttm_dma_tt_fini(&nvbe->ttm);
|
2011-11-01 20:46:13 -04:00
|
|
|
kfree(nvbe);
|
2011-01-10 16:24:00 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-11 19:24:15 +10:00
|
|
|
static int
|
2011-11-01 20:46:13 -04:00
|
|
|
nv04_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *mem)
|
2009-12-11 19:24:15 +10:00
|
|
|
{
|
2011-11-01 20:46:13 -04:00
|
|
|
struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
|
2015-01-14 15:36:34 +10:00
|
|
|
struct nvkm_mem *node = mem->mm_node;
|
2009-12-11 19:24:15 +10:00
|
|
|
|
2012-07-14 19:09:17 +10:00
|
|
|
if (ttm->sg) {
|
2013-11-15 11:56:49 +10:00
|
|
|
node->sg = ttm->sg;
|
|
|
|
|
node->pages = NULL;
|
2012-07-14 19:09:17 +10:00
|
|
|
} else {
|
2013-11-15 11:56:49 +10:00
|
|
|
node->sg = NULL;
|
2012-07-14 19:09:17 +10:00
|
|
|
node->pages = nvbe->ttm.dma_address;
|
2009-12-11 19:24:15 +10:00
|
|
|
}
|
2013-11-15 11:56:49 +10:00
|
|
|
node->size = (mem->num_pages << PAGE_SHIFT) >> 12;
|
2009-12-11 19:24:15 +10:00
|
|
|
|
2015-01-14 15:36:34 +10:00
|
|
|
nvkm_vm_map(&node->vma[0], node);
|
2012-07-14 19:09:17 +10:00
|
|
|
nvbe->node = node;
|
2009-12-11 19:24:15 +10:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2011-11-01 20:46:13 -04:00
|
|
|
nv04_sgdma_unbind(struct ttm_tt *ttm)
|
2009-12-11 19:24:15 +10:00
|
|
|
{
|
2011-11-01 20:46:13 -04:00
|
|
|
struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
|
2015-01-14 15:36:34 +10:00
|
|
|
nvkm_vm_unmap(&nvbe->node->vma[0]);
|
2009-12-11 19:24:15 +10:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-10 16:24:00 +10:00
|
|
|
static struct ttm_backend_func nv04_sgdma_backend = {
|
|
|
|
|
.bind = nv04_sgdma_bind,
|
|
|
|
|
.unbind = nv04_sgdma_unbind,
|
|
|
|
|
.destroy = nouveau_sgdma_destroy
|
|
|
|
|
};
|
2009-12-11 19:24:15 +10:00
|
|
|
|
2010-11-16 10:13:05 +10:00
|
|
|
static int
|
2011-11-01 20:46:13 -04:00
|
|
|
nv50_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *mem)
|
2010-11-16 10:13:05 +10:00
|
|
|
{
|
2011-11-09 17:15:26 -05:00
|
|
|
struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
|
2015-01-14 15:36:34 +10:00
|
|
|
struct nvkm_mem *node = mem->mm_node;
|
2011-11-01 20:46:13 -04:00
|
|
|
|
2011-02-10 12:59:51 +10:00
|
|
|
/* noop: bound in move_notify() */
|
2012-04-02 11:53:06 +01:00
|
|
|
if (ttm->sg) {
|
2013-11-15 11:56:49 +10:00
|
|
|
node->sg = ttm->sg;
|
|
|
|
|
node->pages = NULL;
|
|
|
|
|
} else {
|
|
|
|
|
node->sg = NULL;
|
2012-04-02 11:53:06 +01:00
|
|
|
node->pages = nvbe->ttm.dma_address;
|
2013-11-15 11:56:49 +10:00
|
|
|
}
|
|
|
|
|
node->size = (mem->num_pages << PAGE_SHIFT) >> 12;
|
2010-11-16 10:13:05 +10:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2011-11-01 20:46:13 -04:00
|
|
|
nv50_sgdma_unbind(struct ttm_tt *ttm)
|
2010-11-16 10:13:05 +10:00
|
|
|
{
|
2011-02-10 12:59:51 +10:00
|
|
|
/* noop: unbound in move_notify() */
|
2010-11-16 10:13:05 +10:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct ttm_backend_func nv50_sgdma_backend = {
|
|
|
|
|
.bind = nv50_sgdma_bind,
|
|
|
|
|
.unbind = nv50_sgdma_unbind,
|
|
|
|
|
.destroy = nouveau_sgdma_destroy
|
|
|
|
|
};
|
|
|
|
|
|
2011-11-01 20:46:13 -04:00
|
|
|
struct ttm_tt *
|
|
|
|
|
nouveau_sgdma_create_ttm(struct ttm_bo_device *bdev,
|
|
|
|
|
unsigned long size, uint32_t page_flags,
|
|
|
|
|
struct page *dummy_read_page)
|
2009-12-11 19:24:15 +10:00
|
|
|
{
|
2012-07-20 08:17:34 +10:00
|
|
|
struct nouveau_drm *drm = nouveau_bdev(bdev);
|
2009-12-11 19:24:15 +10:00
|
|
|
struct nouveau_sgdma_be *nvbe;
|
|
|
|
|
|
|
|
|
|
nvbe = kzalloc(sizeof(*nvbe), GFP_KERNEL);
|
|
|
|
|
if (!nvbe)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2014-08-10 04:10:22 +10:00
|
|
|
if (drm->device.info.family < NV_DEVICE_INFO_V0_TESLA)
|
2012-07-20 08:17:34 +10:00
|
|
|
nvbe->ttm.ttm.func = &nv04_sgdma_backend;
|
|
|
|
|
else
|
|
|
|
|
nvbe->ttm.ttm.func = &nv50_sgdma_backend;
|
2009-12-11 19:24:15 +10:00
|
|
|
|
2013-09-17 14:13:32 +10:00
|
|
|
if (ttm_dma_tt_init(&nvbe->ttm, bdev, size, page_flags, dummy_read_page))
|
2014-12-11 04:07:20 +09:00
|
|
|
/*
|
|
|
|
|
* A failing ttm_dma_tt_init() will call ttm_tt_destroy()
|
|
|
|
|
* and thus our nouveau_sgdma_destroy() hook, so we don't need
|
|
|
|
|
* to free nvbe here.
|
|
|
|
|
*/
|
2011-11-01 20:46:13 -04:00
|
|
|
return NULL;
|
2011-11-09 17:15:26 -05:00
|
|
|
return &nvbe->ttm.ttm;
|
2009-12-11 19:24:15 +10:00
|
|
|
}
|