mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-23 02:54:32 +08:00
8af8a109b3
Rename ttm_bo_device to ttm_device. Rename ttm_bo_driver to ttm_device_funcs. Rename ttm_bo_global to ttm_global. Move global and device related functions to ttm_device.[ch]. No functional change. Signed-off-by: Christian König <christian.koenig@amd.com> Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: https://patchwork.freedesktop.org/patch/415222/
93 lines
2.0 KiB
C
93 lines
2.0 KiB
C
// SPDX-License-Identifier: MIT
|
|
#include <linux/pagemap.h>
|
|
#include <linux/slab.h>
|
|
|
|
#include "nouveau_drv.h"
|
|
#include "nouveau_mem.h"
|
|
#include "nouveau_ttm.h"
|
|
#include "nouveau_bo.h"
|
|
|
|
struct nouveau_sgdma_be {
|
|
/* this has to be the first field so populate/unpopulated in
|
|
* nouve_bo.c works properly, otherwise have to move them here
|
|
*/
|
|
struct ttm_tt ttm;
|
|
struct nouveau_mem *mem;
|
|
};
|
|
|
|
void
|
|
nouveau_sgdma_destroy(struct ttm_device *bdev, struct ttm_tt *ttm)
|
|
{
|
|
struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
|
|
|
|
if (ttm) {
|
|
nouveau_sgdma_unbind(bdev, ttm);
|
|
ttm_tt_destroy_common(bdev, ttm);
|
|
ttm_tt_fini(&nvbe->ttm);
|
|
kfree(nvbe);
|
|
}
|
|
}
|
|
|
|
int
|
|
nouveau_sgdma_bind(struct ttm_device *bdev, struct ttm_tt *ttm, struct ttm_resource *reg)
|
|
{
|
|
struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
|
|
struct nouveau_drm *drm = nouveau_bdev(bdev);
|
|
struct nouveau_mem *mem = nouveau_mem(reg);
|
|
int ret;
|
|
|
|
if (nvbe->mem)
|
|
return 0;
|
|
|
|
ret = nouveau_mem_host(reg, &nvbe->ttm);
|
|
if (ret)
|
|
return ret;
|
|
|
|
if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA) {
|
|
ret = nouveau_mem_map(mem, &mem->cli->vmm.vmm, &mem->vma[0]);
|
|
if (ret) {
|
|
nouveau_mem_fini(mem);
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
nvbe->mem = mem;
|
|
return 0;
|
|
}
|
|
|
|
void
|
|
nouveau_sgdma_unbind(struct ttm_device *bdev, struct ttm_tt *ttm)
|
|
{
|
|
struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
|
|
if (nvbe->mem) {
|
|
nouveau_mem_fini(nvbe->mem);
|
|
nvbe->mem = NULL;
|
|
}
|
|
}
|
|
|
|
struct ttm_tt *
|
|
nouveau_sgdma_create_ttm(struct ttm_buffer_object *bo, uint32_t page_flags)
|
|
{
|
|
struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
|
|
struct nouveau_bo *nvbo = nouveau_bo(bo);
|
|
struct nouveau_sgdma_be *nvbe;
|
|
enum ttm_caching caching;
|
|
|
|
if (nvbo->force_coherent)
|
|
caching = ttm_uncached;
|
|
else if (drm->agp.bridge)
|
|
caching = ttm_write_combined;
|
|
else
|
|
caching = ttm_cached;
|
|
|
|
nvbe = kzalloc(sizeof(*nvbe), GFP_KERNEL);
|
|
if (!nvbe)
|
|
return NULL;
|
|
|
|
if (ttm_sg_tt_init(&nvbe->ttm, bo, page_flags, caching)) {
|
|
kfree(nvbe);
|
|
return NULL;
|
|
}
|
|
return &nvbe->ttm;
|
|
}
|