2 * Copyright 2015 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
22 * Authors: Ben Skeggs <bskeggs@redhat.com>
27 nvkm_ram_init(struct nvkm_ram *ram)
30 return ram->func->init(ram);
35 nvkm_ram_del(struct nvkm_ram **pram)
37 struct nvkm_ram *ram = *pram;
38 if (ram && !WARN_ON(!ram->func)) {
40 *pram = ram->func->dtor(ram);
41 nvkm_mm_fini(&ram->tags);
42 nvkm_mm_fini(&ram->vram);
49 nvkm_ram_ctor(const struct nvkm_ram_func *func, struct nvkm_fb *fb,
50 enum nvkm_ram_type type, u64 size, u32 tags,
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",
66 struct nvkm_subdev *subdev = &fb->subdev;
69 nvkm_info(subdev, "%d MiB %s\n", (int)(size >> 20), name[type]);
75 if (!nvkm_mm_initialised(&ram->vram)) {
76 ret = nvkm_mm_init(&ram->vram, 0, size >> NVKM_RAM_MM_SHIFT, 1);
81 if (!nvkm_mm_initialised(&ram->tags)) {
82 ret = nvkm_mm_init(&ram->tags, 0, tags ? ++tags : 0, 1);
86 nvkm_debug(subdev, "%d compression tags\n", tags);
93 nvkm_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)
97 if (!(*pram = kzalloc(sizeof(**pram), GFP_KERNEL)))
99 return nvkm_ram_ctor(func, fb, type, size, tags, *pram);