Linux Audio

Check our new training course

Loading...
v5.14.15
 1// SPDX-License-Identifier: MIT
 2#include <linux/pagemap.h>
 3#include <linux/slab.h>
 
 4
 5#include "nouveau_drv.h"
 6#include "nouveau_mem.h"
 7#include "nouveau_ttm.h"
 8#include "nouveau_bo.h"
 9
10struct nouveau_sgdma_be {
11	/* this has to be the first field so populate/unpopulated in
12	 * nouve_bo.c works properly, otherwise have to move them here
13	 */
14	struct ttm_tt ttm;
15	struct nouveau_mem *mem;
16};
17
18void
19nouveau_sgdma_destroy(struct ttm_device *bdev, struct ttm_tt *ttm)
20{
21	struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
22
23	if (ttm) {
24		nouveau_sgdma_unbind(bdev, ttm);
25		ttm_tt_destroy_common(bdev, ttm);
26		ttm_tt_fini(&nvbe->ttm);
27		kfree(nvbe);
28	}
29}
30
31int
32nouveau_sgdma_bind(struct ttm_device *bdev, struct ttm_tt *ttm, struct ttm_resource *reg)
33{
34	struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
35	struct nouveau_drm *drm = nouveau_bdev(bdev);
36	struct nouveau_mem *mem = nouveau_mem(reg);
37	int ret;
38
39	if (nvbe->mem)
40		return 0;
41
42	ret = nouveau_mem_host(reg, &nvbe->ttm);
43	if (ret)
44		return ret;
45
46	if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA) {
47		ret = nouveau_mem_map(mem, &mem->cli->vmm.vmm, &mem->vma[0]);
48		if (ret) {
49			nouveau_mem_fini(mem);
50			return ret;
51		}
52	}
53
54	nvbe->mem = mem;
55	return 0;
56}
57
58void
59nouveau_sgdma_unbind(struct ttm_device *bdev, struct ttm_tt *ttm)
60{
61	struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
62	if (nvbe->mem) {
63		nouveau_mem_fini(nvbe->mem);
64		nvbe->mem = NULL;
65	}
66}
67
68struct ttm_tt *
69nouveau_sgdma_create_ttm(struct ttm_buffer_object *bo, uint32_t page_flags)
70{
71	struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
72	struct nouveau_bo *nvbo = nouveau_bo(bo);
73	struct nouveau_sgdma_be *nvbe;
74	enum ttm_caching caching;
75
76	if (nvbo->force_coherent)
77		caching = ttm_uncached;
78	else if (drm->agp.bridge)
79		caching = ttm_write_combined;
80	else
81		caching = ttm_cached;
82
83	nvbe = kzalloc(sizeof(*nvbe), GFP_KERNEL);
84	if (!nvbe)
85		return NULL;
86
87	if (ttm_sg_tt_init(&nvbe->ttm, bo, page_flags, caching)) {
88		kfree(nvbe);
89		return NULL;
90	}
91	return &nvbe->ttm;
92}
v6.13.7
 1// SPDX-License-Identifier: MIT
 2#include <linux/pagemap.h>
 3#include <linux/slab.h>
 4#include <drm/ttm/ttm_tt.h>
 5
 6#include "nouveau_drv.h"
 7#include "nouveau_mem.h"
 8#include "nouveau_ttm.h"
 9#include "nouveau_bo.h"
10
11struct nouveau_sgdma_be {
12	/* this has to be the first field so populate/unpopulated in
13	 * nouve_bo.c works properly, otherwise have to move them here
14	 */
15	struct ttm_tt ttm;
16	struct nouveau_mem *mem;
17};
18
19void
20nouveau_sgdma_destroy(struct ttm_device *bdev, struct ttm_tt *ttm)
21{
22	struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
23
24	if (ttm) {
 
 
25		ttm_tt_fini(&nvbe->ttm);
26		kfree(nvbe);
27	}
28}
29
30int
31nouveau_sgdma_bind(struct ttm_device *bdev, struct ttm_tt *ttm, struct ttm_resource *reg)
32{
33	struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
34	struct nouveau_drm *drm = nouveau_bdev(bdev);
35	struct nouveau_mem *mem = nouveau_mem(reg);
36	int ret;
37
38	if (nvbe->mem)
39		return 0;
40
41	ret = nouveau_mem_host(reg, &nvbe->ttm);
42	if (ret)
43		return ret;
44
45	if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA) {
46		ret = nouveau_mem_map(mem, &drm->client.vmm.vmm, &mem->vma[0]);
47		if (ret) {
48			nouveau_mem_fini(mem);
49			return ret;
50		}
51	}
52
53	nvbe->mem = mem;
54	return 0;
55}
56
57void
58nouveau_sgdma_unbind(struct ttm_device *bdev, struct ttm_tt *ttm)
59{
60	struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
61	if (nvbe->mem) {
62		nouveau_mem_fini(nvbe->mem);
63		nvbe->mem = NULL;
64	}
65}
66
67struct ttm_tt *
68nouveau_sgdma_create_ttm(struct ttm_buffer_object *bo, uint32_t page_flags)
69{
70	struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
71	struct nouveau_bo *nvbo = nouveau_bo(bo);
72	struct nouveau_sgdma_be *nvbe;
73	enum ttm_caching caching;
74
75	if (nvbo->force_coherent)
76		caching = ttm_uncached;
77	else if (drm->agp.bridge)
78		caching = ttm_write_combined;
79	else
80		caching = ttm_cached;
81
82	nvbe = kzalloc(sizeof(*nvbe), GFP_KERNEL);
83	if (!nvbe)
84		return NULL;
85
86	if (ttm_sg_tt_init(&nvbe->ttm, bo, page_flags, caching)) {
87		kfree(nvbe);
88		return NULL;
89	}
90	return &nvbe->ttm;
91}