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/if500b.h>
30#include <nvif/if500d.h>
31#include <nvif/unpack.h>
32
33int
34nv50_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 nv50_vmm_map_v0 uvmm = {};
38 union {
39 struct nv50_mem_map_vn vn;
40 struct nv50_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 u64 size = nvkm_memory_size(memory);
45 int ret = -ENOSYS;
46
47 if (!(ret = nvif_unpack(ret, &argv, &argc, args->v0, 0, 0, false))) {
48 uvmm.ro = args->v0.ro;
49 uvmm.kind = args->v0.kind;
50 uvmm.comp = args->v0.comp;
51 } else
52 if (!(ret = nvif_unvers(ret, &argv, &argc, args->vn))) {
53 } else
54 return ret;
55
56 ret = nvkm_vmm_get(bar, 12, size, pvma);
57 if (ret)
58 return ret;
59
60 *paddr = device->func->resource_addr(device, 1) + (*pvma)->addr;
61 *psize = (*pvma)->size;
62 return nvkm_memory_map(memory, 0, bar, *pvma, &uvmm, sizeof(uvmm));
63}
64
65int
66nv50_mem_new(struct nvkm_mmu *mmu, int type, u8 page, u64 size,
67 void *argv, u32 argc, struct nvkm_memory **pmemory)
68{
69 union {
70 struct nv50_mem_vn vn;
71 struct nv50_mem_v0 v0;
72 } *args = argv;
73 int ret = -ENOSYS;
74 bool contig;
75
76 if (!(ret = nvif_unpack(ret, &argv, &argc, args->v0, 0, 0, false))) {
77 type = args->v0.bankswz ? 0x02 : 0x01;
78 contig = args->v0.contig;
79 } else
80 if (!(ret = nvif_unvers(ret, &argv, &argc, args->vn))) {
81 type = 0x01;
82 contig = false;
83 } else
84 return -ENOSYS;
85
86 return nvkm_ram_get(mmu->subdev.device, NVKM_RAM_MM_NORMAL, type,
87 page, size, contig, false, pmemory);
88}
89