1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include "ram.h"
25
26int
27nvkm_ram_init(struct nvkm_ram *ram)
28{
29 if (ram->func->init)
30 return ram->func->init(ram);
31 return 0;
32}
33
34void
35nvkm_ram_del(struct nvkm_ram **pram)
36{
37 struct nvkm_ram *ram = *pram;
38 if (ram && !WARN_ON(!ram->func)) {
39 if (ram->func->dtor)
40 *pram = ram->func->dtor(ram);
41 nvkm_mm_fini(&ram->tags);
42 nvkm_mm_fini(&ram->vram);
43 kfree(*pram);
44 *pram = NULL;
45 }
46}
47
48int
49nvkm_ram_ctor(const struct nvkm_ram_func *func, struct nvkm_fb *fb,
50 enum nvkm_ram_type type, u64 size, u32 tags,
51 struct nvkm_ram *ram)
52{
53 static const char *name[] = {
54 [NVKM_RAM_TYPE_UNKNOWN] = "of unknown memory type",
55 [NVKM_RAM_TYPE_STOLEN ] = "stolen system memory",
56 [NVKM_RAM_TYPE_SGRAM ] = "SGRAM",
57 [NVKM_RAM_TYPE_SDRAM ] = "SDRAM",
58 [NVKM_RAM_TYPE_DDR1 ] = "DDR1",
59 [NVKM_RAM_TYPE_DDR2 ] = "DDR2",
60 [NVKM_RAM_TYPE_DDR3 ] = "DDR3",
61 [NVKM_RAM_TYPE_GDDR2 ] = "GDDR2",
62 [NVKM_RAM_TYPE_GDDR3 ] = "GDDR3",
63 [NVKM_RAM_TYPE_GDDR4 ] = "GDDR4",
64 [NVKM_RAM_TYPE_GDDR5 ] = "GDDR5",
65 };
66 struct nvkm_subdev *subdev = &fb->subdev;
67 int ret;
68
69 nvkm_info(subdev, "%d MiB %s\n", (int)(size >> 20), name[type]);
70 ram->func = func;
71 ram->fb = fb;
72 ram->type = type;
73 ram->size = size;
74
75 if (!nvkm_mm_initialised(&ram->vram)) {
76 ret = nvkm_mm_init(&ram->vram, 0, size >> NVKM_RAM_MM_SHIFT, 1);
77 if (ret)
78 return ret;
79 }
80
81 if (!nvkm_mm_initialised(&ram->tags)) {
82 ret = nvkm_mm_init(&ram->tags, 0, tags ? ++tags : 0, 1);
83 if (ret)
84 return ret;
85
86 nvkm_debug(subdev, "%d compression tags\n", tags);
87 }
88
89 return 0;
90}
91
92int
93nvkm_ram_new_(const struct nvkm_ram_func *func, struct nvkm_fb *fb,
94 enum nvkm_ram_type type, u64 size, u32 tags,
95 struct nvkm_ram **pram)
96{
97 if (!(*pram = kzalloc(sizeof(**pram), GFP_KERNEL)))
98 return -ENOMEM;
99 return nvkm_ram_ctor(func, fb, type, size, tags, *pram);
100}
101