]>
Commit | Line | Data |
---|---|---|
9ce523cc BS |
1 | /* |
2 | * Copyright 2017 Red Hat Inc. | |
3 | * | |
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: | |
10 | * | |
11 | * The above copyright notice and this permission notice shall be included in | |
12 | * all copies or substantial portions of the Software. | |
13 | * | |
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. | |
21 | */ | |
22 | #include "nouveau_mem.h" | |
23 | #include "nouveau_drv.h" | |
24 | #include "nouveau_bo.h" | |
25 | ||
26 | #include <drm/ttm/ttm_bo_driver.h> | |
27 | ||
28 | int | |
29 | nouveau_mem_map(struct nouveau_mem *mem, | |
30 | struct nvkm_vmm *vmm, struct nvkm_vma *vma) | |
31 | { | |
32 | nvkm_vm_map(vma, mem->_mem); | |
33 | return 0; | |
34 | } | |
35 | ||
36 | void | |
37 | nouveau_mem_fini(struct nouveau_mem *mem) | |
38 | { | |
39 | if (mem->vma[1].node) { | |
40 | nvkm_vm_unmap(&mem->vma[1]); | |
41 | nvkm_vm_put(&mem->vma[1]); | |
42 | } | |
43 | if (mem->vma[0].node) { | |
44 | nvkm_vm_unmap(&mem->vma[0]); | |
45 | nvkm_vm_put(&mem->vma[0]); | |
46 | } | |
47 | } | |
48 | ||
49 | int | |
50 | nouveau_mem_host(struct ttm_mem_reg *reg, struct ttm_dma_tt *tt) | |
51 | { | |
52 | struct nouveau_mem *mem = nouveau_mem(reg); | |
53 | struct nouveau_cli *cli = mem->cli; | |
54 | ||
55 | if (mem->kind && cli->device.info.chipset == 0x50) | |
56 | mem->comp = mem->kind = 0; | |
57 | if (mem->comp) { | |
58 | if (cli->device.info.chipset >= 0xc0) | |
59 | mem->kind = gf100_pte_storage_type_map[mem->kind]; | |
60 | mem->comp = 0; | |
61 | } | |
62 | ||
63 | mem->__mem.size = (reg->num_pages << PAGE_SHIFT) >> 12; | |
64 | mem->__mem.memtype = (mem->comp << 7) | mem->kind; | |
65 | if (tt->ttm.sg) mem->__mem.sg = tt->ttm.sg; | |
66 | else mem->__mem.pages = tt->dma_address; | |
67 | mem->_mem = &mem->__mem; | |
68 | mem->mem.page = 12; | |
69 | return 0; | |
70 | } | |
71 | ||
72 | int | |
73 | nouveau_mem_vram(struct ttm_mem_reg *reg, bool contig, u8 page) | |
74 | { | |
75 | struct nouveau_mem *mem = nouveau_mem(reg); | |
76 | struct nvkm_ram *ram = nvxx_fb(&mem->cli->device)->ram; | |
77 | u64 size = ALIGN(reg->num_pages << PAGE_SHIFT, 1 << page); | |
78 | int ret; | |
79 | ||
80 | mem->mem.page = page; | |
81 | ||
82 | ret = ram->func->get(ram, size, 1 << page, contig ? 0 : 1 << page, | |
83 | (mem->comp << 8) | mem->kind, &mem->_mem); | |
84 | if (ret) | |
85 | return ret; | |
86 | ||
87 | reg->start = mem->_mem->offset >> PAGE_SHIFT; | |
88 | return ret; | |
89 | } | |
90 | ||
91 | void | |
92 | nouveau_mem_del(struct ttm_mem_reg *reg) | |
93 | { | |
94 | struct nouveau_mem *mem = nouveau_mem(reg); | |
95 | nouveau_mem_fini(mem); | |
96 | kfree(reg->mm_node); | |
97 | reg->mm_node = NULL; | |
98 | } | |
99 | ||
100 | int | |
101 | nouveau_mem_new(struct nouveau_cli *cli, u8 kind, u8 comp, | |
102 | struct ttm_mem_reg *reg) | |
103 | { | |
104 | struct nouveau_mem *mem; | |
105 | ||
106 | if (!(mem = kzalloc(sizeof(*mem), GFP_KERNEL))) | |
107 | return -ENOMEM; | |
108 | mem->cli = cli; | |
109 | mem->kind = kind; | |
110 | mem->comp = comp; | |
111 | ||
112 | reg->mm_node = mem; | |
113 | return 0; | |
114 | } |