1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include "mem.h"
23
24#include <core/memory.h>
25#include <subdev/bar.h>
26#include <subdev/fb.h>
27
28#include <nvif/class.h>
29#include <nvif/if900b.h>
30#include <nvif/if900d.h>
31#include <nvif/unpack.h>
32
33int
34gf100_mem_map(struct nvkm_mmu *mmu, struct nvkm_memory *memory, void *argv,
35 u32 argc, u64 *paddr, u64 *psize, struct nvkm_vma **pvma)
36{
37 struct gf100_vmm_map_v0 uvmm = {};
38 union {
39 struct gf100_mem_map_vn vn;
40 struct gf100_mem_map_v0 v0;
41 } *args = argv;
42 struct nvkm_device *device = mmu->subdev.device;
43 struct nvkm_vmm *bar = nvkm_bar_bar1_vmm(device);
44 int ret = -ENOSYS;
45
46 if (!(ret = nvif_unpack(ret, &argv, &argc, args->v0, 0, 0, false))) {
47 uvmm.ro = args->v0.ro;
48 uvmm.kind = args->v0.kind;
49 } else
50 if (!(ret = nvif_unvers(ret, &argv, &argc, args->vn))) {
51 } else
52 return ret;
53
54 ret = nvkm_vmm_get(bar, nvkm_memory_page(memory),
55 nvkm_memory_size(memory), pvma);
56 if (ret)
57 return ret;
58
59 ret = nvkm_memory_map(memory, 0, bar, *pvma, &uvmm, sizeof(uvmm));
60 if (ret)
61 return ret;
62
63 *paddr = device->func->resource_addr(device, 1) + (*pvma)->addr;
64 *psize = (*pvma)->size;
65 return 0;
66}
67
68int
69gf100_mem_new(struct nvkm_mmu *mmu, int type, u8 page, u64 size,
70 void *argv, u32 argc, struct nvkm_memory **pmemory)
71{
72 union {
73 struct gf100_mem_vn vn;
74 struct gf100_mem_v0 v0;
75 } *args = argv;
76 int ret = -ENOSYS;
77 bool contig;
78
79 if (!(ret = nvif_unpack(ret, &argv, &argc, args->v0, 0, 0, false))) {
80 contig = args->v0.contig;
81 } else
82 if (!(ret = nvif_unvers(ret, &argv, &argc, args->vn))) {
83 contig = false;
84 } else
85 return ret;
86
87 if (mmu->type[type].type & (NVKM_MEM_DISP | NVKM_MEM_COMP))
88 type = NVKM_RAM_MM_NORMAL;
89 else
90 type = NVKM_RAM_MM_MIXED;
91
92 return nvkm_ram_get(mmu->subdev.device, type, 0x01, page,
93 size, contig, false, pmemory);
94}
95