blob: 7296c67389e3e0c155f5fb4ad4347a24698573eb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
/*
* Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <nvgpu/kmem.h>
#include <nvgpu/nvgpu_mem.h>
#include "gk20a/gk20a.h"
struct nvgpu_mem_sgl *nvgpu_mem_sgl_next(struct nvgpu_mem_sgl *sgl)
{
return sgl->next;
}
u64 nvgpu_mem_sgl_phys(struct nvgpu_mem_sgl *sgl)
{
return sgl->phys;
}
u64 nvgpu_mem_sgl_dma(struct nvgpu_mem_sgl *sgl)
{
return sgl->dma;
}
u64 nvgpu_mem_sgl_length(struct nvgpu_mem_sgl *sgl)
{
return sgl->length;
}
/*
* This builds a GPU address for the %sgl based on whether an IOMMU is present
* or not. It also handles turning the physical address into the true GPU
* physical address that should be programmed into the page tables.
*/
u64 nvgpu_mem_sgl_gpu_addr(struct gk20a *g, struct nvgpu_mem_sgl *sgl,
struct nvgpu_gmmu_attrs *attrs)
{
if (nvgpu_mem_sgl_dma(sgl) == 0)
return g->ops.mm.gpu_phys_addr(g, attrs,
nvgpu_mem_sgl_phys(sgl));
if (nvgpu_mem_sgl_dma(sgl) == DMA_ERROR_CODE)
return 0;
return gk20a_mm_smmu_vaddr_translate(g, nvgpu_mem_sgl_dma(sgl));
}
void nvgpu_mem_sgl_free(struct gk20a *g, struct nvgpu_mem_sgl *sgl)
{
struct nvgpu_mem_sgl *next;
/*
* Free each of the elements. We expect each element to have been
* nvgpu_k[mz]alloc()ed.
*/
while (sgl) {
next = nvgpu_mem_sgl_next(sgl);
nvgpu_kfree(g, sgl);
sgl = next;
}
}
|