blob: 1825dbc331926c84de69e13606f38cf4c80a2bed [file] [log] [blame]
Ben Skeggs6ee73862009-12-11 19:24:15 +10001/*
2 * Copyright (c) 2007-2008 Tungsten Graphics, Inc., Cedar Park, TX., USA,
3 * All Rights Reserved.
4 * Copyright (c) 2009 VMware, Inc., Palo Alto, CA., USA,
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sub license,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
Ben Skeggs4dc28132016-05-20 09:22:55 +100027#include "nouveau_drv.h"
Ben Skeggsebb945a2012-07-20 08:17:34 +100028#include "nouveau_ttm.h"
29#include "nouveau_gem.h"
Ben Skeggs6ee73862009-12-11 19:24:15 +100030
Dave Airlie2036eaa2014-12-16 16:33:09 +100031#include "drm_legacy.h"
Alexandre Courbotb31cf782015-09-04 19:59:34 +090032
33#include <core/tegra.h>
34
Ben Skeggsbc9e7b92012-07-19 17:54:21 +100035static int
36nouveau_vram_manager_init(struct ttm_mem_type_manager *man, unsigned long psize)
37{
Marcin Slusarz897a6e22013-03-02 20:00:31 +010038 struct nouveau_drm *drm = nouveau_bdev(man->bdev);
Ben Skeggsb1e45532015-08-20 14:54:06 +100039 struct nvkm_fb *fb = nvxx_fb(&drm->device);
40 man->priv = fb;
Ben Skeggsbc9e7b92012-07-19 17:54:21 +100041 return 0;
42}
43
44static int
45nouveau_vram_manager_fini(struct ttm_mem_type_manager *man)
46{
Marcin Slusarz897a6e22013-03-02 20:00:31 +010047 man->priv = NULL;
Ben Skeggsbc9e7b92012-07-19 17:54:21 +100048 return 0;
49}
50
51static inline void
Ben Skeggsbe83cd42015-01-14 15:36:34 +100052nvkm_mem_node_cleanup(struct nvkm_mem *node)
Ben Skeggsbc9e7b92012-07-19 17:54:21 +100053{
54 if (node->vma[0].node) {
Ben Skeggsbe83cd42015-01-14 15:36:34 +100055 nvkm_vm_unmap(&node->vma[0]);
56 nvkm_vm_put(&node->vma[0]);
Ben Skeggsbc9e7b92012-07-19 17:54:21 +100057 }
58
59 if (node->vma[1].node) {
Ben Skeggsbe83cd42015-01-14 15:36:34 +100060 nvkm_vm_unmap(&node->vma[1]);
61 nvkm_vm_put(&node->vma[1]);
Ben Skeggsbc9e7b92012-07-19 17:54:21 +100062 }
63}
64
65static void
66nouveau_vram_manager_del(struct ttm_mem_type_manager *man,
67 struct ttm_mem_reg *mem)
68{
Ben Skeggsebb945a2012-07-20 08:17:34 +100069 struct nouveau_drm *drm = nouveau_bdev(man->bdev);
Ben Skeggsd36a99d2015-08-20 14:54:14 +100070 struct nvkm_ram *ram = nvxx_fb(&drm->device)->ram;
Ben Skeggsbe83cd42015-01-14 15:36:34 +100071 nvkm_mem_node_cleanup(mem->mm_node);
Ben Skeggsd36a99d2015-08-20 14:54:14 +100072 ram->func->put(ram, (struct nvkm_mem **)&mem->mm_node);
Ben Skeggsbc9e7b92012-07-19 17:54:21 +100073}
74
75static int
76nouveau_vram_manager_new(struct ttm_mem_type_manager *man,
77 struct ttm_buffer_object *bo,
Christian Königf1217ed2014-08-27 13:16:04 +020078 const struct ttm_place *place,
Ben Skeggsbc9e7b92012-07-19 17:54:21 +100079 struct ttm_mem_reg *mem)
80{
Ben Skeggsebb945a2012-07-20 08:17:34 +100081 struct nouveau_drm *drm = nouveau_bdev(man->bdev);
Ben Skeggsd36a99d2015-08-20 14:54:14 +100082 struct nvkm_ram *ram = nvxx_fb(&drm->device)->ram;
Ben Skeggsbc9e7b92012-07-19 17:54:21 +100083 struct nouveau_bo *nvbo = nouveau_bo(bo);
Ben Skeggsbe83cd42015-01-14 15:36:34 +100084 struct nvkm_mem *node;
Ben Skeggsbc9e7b92012-07-19 17:54:21 +100085 u32 size_nc = 0;
86 int ret;
87
Alexandre Courboteaecf032015-02-20 18:22:59 +090088 if (drm->device.info.ram_size == 0)
89 return -ENOMEM;
90
Ben Skeggsbc9e7b92012-07-19 17:54:21 +100091 if (nvbo->tile_flags & NOUVEAU_GEM_TILE_NONCONTIG)
92 size_nc = 1 << nvbo->page_shift;
93
Ben Skeggsd36a99d2015-08-20 14:54:14 +100094 ret = ram->func->get(ram, mem->num_pages << PAGE_SHIFT,
95 mem->page_alignment << PAGE_SHIFT, size_nc,
96 (nvbo->tile_flags >> 8) & 0x3ff, &node);
Ben Skeggsbc9e7b92012-07-19 17:54:21 +100097 if (ret) {
98 mem->mm_node = NULL;
99 return (ret == -ENOSPC) ? 0 : ret;
100 }
101
102 node->page_shift = nvbo->page_shift;
103
104 mem->mm_node = node;
105 mem->start = node->offset >> PAGE_SHIFT;
106 return 0;
107}
108
Ben Skeggsbc9e7b92012-07-19 17:54:21 +1000109const struct ttm_mem_type_manager_func nouveau_vram_manager = {
110 nouveau_vram_manager_init,
111 nouveau_vram_manager_fini,
112 nouveau_vram_manager_new,
113 nouveau_vram_manager_del,
Ben Skeggsbc9e7b92012-07-19 17:54:21 +1000114};
115
116static int
117nouveau_gart_manager_init(struct ttm_mem_type_manager *man, unsigned long psize)
118{
119 return 0;
120}
121
122static int
123nouveau_gart_manager_fini(struct ttm_mem_type_manager *man)
124{
125 return 0;
126}
127
128static void
129nouveau_gart_manager_del(struct ttm_mem_type_manager *man,
130 struct ttm_mem_reg *mem)
131{
Ben Skeggsbe83cd42015-01-14 15:36:34 +1000132 nvkm_mem_node_cleanup(mem->mm_node);
Ben Skeggsbc9e7b92012-07-19 17:54:21 +1000133 kfree(mem->mm_node);
134 mem->mm_node = NULL;
135}
136
137static int
138nouveau_gart_manager_new(struct ttm_mem_type_manager *man,
139 struct ttm_buffer_object *bo,
Christian Königf1217ed2014-08-27 13:16:04 +0200140 const struct ttm_place *place,
Ben Skeggsbc9e7b92012-07-19 17:54:21 +1000141 struct ttm_mem_reg *mem)
142{
Ben Skeggsde7b7d52013-03-22 12:12:17 +1000143 struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
144 struct nouveau_bo *nvbo = nouveau_bo(bo);
Ben Skeggsbe83cd42015-01-14 15:36:34 +1000145 struct nvkm_mem *node;
Ben Skeggsbc9e7b92012-07-19 17:54:21 +1000146
Ben Skeggsbc9e7b92012-07-19 17:54:21 +1000147 node = kzalloc(sizeof(*node), GFP_KERNEL);
148 if (!node)
149 return -ENOMEM;
Ben Skeggs2e2cfbe2013-11-15 11:56:49 +1000150
Ben Skeggsbc9e7b92012-07-19 17:54:21 +1000151 node->page_shift = 12;
152
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000153 switch (drm->device.info.family) {
Alexandre Courboteb48b122015-07-09 17:15:14 +0900154 case NV_DEVICE_INFO_V0_TNT:
155 case NV_DEVICE_INFO_V0_CELSIUS:
156 case NV_DEVICE_INFO_V0_KELVIN:
157 case NV_DEVICE_INFO_V0_RANKINE:
158 case NV_DEVICE_INFO_V0_CURIE:
159 break;
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000160 case NV_DEVICE_INFO_V0_TESLA:
161 if (drm->device.info.chipset != 0x50)
Ben Skeggsde7b7d52013-03-22 12:12:17 +1000162 node->memtype = (nvbo->tile_flags & 0x7f00) >> 8;
163 break;
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000164 case NV_DEVICE_INFO_V0_FERMI:
165 case NV_DEVICE_INFO_V0_KEPLER:
Alexandre Courboteb48b122015-07-09 17:15:14 +0900166 case NV_DEVICE_INFO_V0_MAXWELL:
Ben Skeggs7f53abd2016-07-09 10:41:01 +1000167 case NV_DEVICE_INFO_V0_PASCAL:
Ben Skeggsde7b7d52013-03-22 12:12:17 +1000168 node->memtype = (nvbo->tile_flags & 0xff00) >> 8;
169 break;
170 default:
Alexandre Courboteb48b122015-07-09 17:15:14 +0900171 NV_WARN(drm, "%s: unhandled family type %x\n", __func__,
172 drm->device.info.family);
Ben Skeggsde7b7d52013-03-22 12:12:17 +1000173 break;
174 }
175
Ben Skeggsbc9e7b92012-07-19 17:54:21 +1000176 mem->mm_node = node;
177 mem->start = 0;
178 return 0;
179}
180
Marcin Slusarz5b8a43a2012-08-19 23:00:00 +0200181static void
Ben Skeggsbc9e7b92012-07-19 17:54:21 +1000182nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
183{
184}
185
186const struct ttm_mem_type_manager_func nouveau_gart_manager = {
187 nouveau_gart_manager_init,
188 nouveau_gart_manager_fini,
189 nouveau_gart_manager_new,
190 nouveau_gart_manager_del,
191 nouveau_gart_manager_debug
192};
193
Ben Skeggsfdb751e2014-08-10 04:10:23 +1000194/*XXX*/
Ben Skeggs5ce3bf32015-01-14 09:57:36 +1000195#include <subdev/mmu/nv04.h>
Ben Skeggsbc9e7b92012-07-19 17:54:21 +1000196static int
197nv04_gart_manager_init(struct ttm_mem_type_manager *man, unsigned long psize)
198{
Ben Skeggsebb945a2012-07-20 08:17:34 +1000199 struct nouveau_drm *drm = nouveau_bdev(man->bdev);
Ben Skeggsbe83cd42015-01-14 15:36:34 +1000200 struct nvkm_mmu *mmu = nvxx_mmu(&drm->device);
Ben Skeggs1f5bffc2015-08-20 14:54:07 +1000201 struct nv04_mmu *priv = (void *)mmu;
Ben Skeggsbe83cd42015-01-14 15:36:34 +1000202 struct nvkm_vm *vm = NULL;
203 nvkm_vm_ref(priv->vm, &vm, NULL);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000204 man->priv = vm;
205 return 0;
Ben Skeggsbc9e7b92012-07-19 17:54:21 +1000206}
207
208static int
209nv04_gart_manager_fini(struct ttm_mem_type_manager *man)
210{
Ben Skeggsbe83cd42015-01-14 15:36:34 +1000211 struct nvkm_vm *vm = man->priv;
212 nvkm_vm_ref(NULL, &vm, NULL);
Ben Skeggsbc9e7b92012-07-19 17:54:21 +1000213 man->priv = NULL;
214 return 0;
215}
216
217static void
218nv04_gart_manager_del(struct ttm_mem_type_manager *man, struct ttm_mem_reg *mem)
219{
Ben Skeggsbe83cd42015-01-14 15:36:34 +1000220 struct nvkm_mem *node = mem->mm_node;
Ben Skeggsbc9e7b92012-07-19 17:54:21 +1000221 if (node->vma[0].node)
Ben Skeggsbe83cd42015-01-14 15:36:34 +1000222 nvkm_vm_put(&node->vma[0]);
Ben Skeggsbc9e7b92012-07-19 17:54:21 +1000223 kfree(mem->mm_node);
224 mem->mm_node = NULL;
225}
226
227static int
228nv04_gart_manager_new(struct ttm_mem_type_manager *man,
229 struct ttm_buffer_object *bo,
Christian Königf1217ed2014-08-27 13:16:04 +0200230 const struct ttm_place *place,
Ben Skeggsbc9e7b92012-07-19 17:54:21 +1000231 struct ttm_mem_reg *mem)
232{
Ben Skeggsbe83cd42015-01-14 15:36:34 +1000233 struct nvkm_mem *node;
Ben Skeggsbc9e7b92012-07-19 17:54:21 +1000234 int ret;
235
236 node = kzalloc(sizeof(*node), GFP_KERNEL);
237 if (!node)
238 return -ENOMEM;
239
240 node->page_shift = 12;
241
Ben Skeggsbe83cd42015-01-14 15:36:34 +1000242 ret = nvkm_vm_get(man->priv, mem->num_pages << 12, node->page_shift,
243 NV_MEM_ACCESS_RW, &node->vma[0]);
Ben Skeggsbc9e7b92012-07-19 17:54:21 +1000244 if (ret) {
245 kfree(node);
246 return ret;
247 }
248
249 mem->mm_node = node;
250 mem->start = node->vma[0].offset >> PAGE_SHIFT;
251 return 0;
252}
253
Marcin Slusarz5b8a43a2012-08-19 23:00:00 +0200254static void
Ben Skeggsbc9e7b92012-07-19 17:54:21 +1000255nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
256{
257}
258
259const struct ttm_mem_type_manager_func nv04_gart_manager = {
260 nv04_gart_manager_init,
261 nv04_gart_manager_fini,
262 nv04_gart_manager_new,
263 nv04_gart_manager_del,
264 nv04_gart_manager_debug
265};
266
Ben Skeggs6ee73862009-12-11 19:24:15 +1000267int
268nouveau_ttm_mmap(struct file *filp, struct vm_area_struct *vma)
269{
270 struct drm_file *file_priv = filp->private_data;
Ben Skeggs77145f12012-07-31 16:16:21 +1000271 struct nouveau_drm *drm = nouveau_drm(file_priv->minor->dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000272
273 if (unlikely(vma->vm_pgoff < DRM_FILE_PAGE_OFFSET))
Dave Airlie2036eaa2014-12-16 16:33:09 +1000274 return drm_legacy_mmap(filp, vma);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000275
Ben Skeggsebb945a2012-07-20 08:17:34 +1000276 return ttm_bo_mmap(filp, vma, &drm->ttm.bdev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000277}
278
279static int
Dave Airlieba4420c2010-03-09 10:56:52 +1000280nouveau_ttm_mem_global_init(struct drm_global_reference *ref)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000281{
282 return ttm_mem_global_init(ref->object);
283}
284
285static void
Dave Airlieba4420c2010-03-09 10:56:52 +1000286nouveau_ttm_mem_global_release(struct drm_global_reference *ref)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000287{
288 ttm_mem_global_release(ref->object);
289}
290
291int
Ben Skeggsebb945a2012-07-20 08:17:34 +1000292nouveau_ttm_global_init(struct nouveau_drm *drm)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000293{
Dave Airlieba4420c2010-03-09 10:56:52 +1000294 struct drm_global_reference *global_ref;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000295 int ret;
296
Ben Skeggsebb945a2012-07-20 08:17:34 +1000297 global_ref = &drm->ttm.mem_global_ref;
Dave Airlieba4420c2010-03-09 10:56:52 +1000298 global_ref->global_type = DRM_GLOBAL_TTM_MEM;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000299 global_ref->size = sizeof(struct ttm_mem_global);
300 global_ref->init = &nouveau_ttm_mem_global_init;
301 global_ref->release = &nouveau_ttm_mem_global_release;
302
Dave Airlieba4420c2010-03-09 10:56:52 +1000303 ret = drm_global_item_ref(global_ref);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000304 if (unlikely(ret != 0)) {
305 DRM_ERROR("Failed setting up TTM memory accounting\n");
Ben Skeggsebb945a2012-07-20 08:17:34 +1000306 drm->ttm.mem_global_ref.release = NULL;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000307 return ret;
308 }
309
Ben Skeggsebb945a2012-07-20 08:17:34 +1000310 drm->ttm.bo_global_ref.mem_glob = global_ref->object;
311 global_ref = &drm->ttm.bo_global_ref.ref;
Dave Airlieba4420c2010-03-09 10:56:52 +1000312 global_ref->global_type = DRM_GLOBAL_TTM_BO;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000313 global_ref->size = sizeof(struct ttm_bo_global);
314 global_ref->init = &ttm_bo_global_init;
315 global_ref->release = &ttm_bo_global_release;
316
Dave Airlieba4420c2010-03-09 10:56:52 +1000317 ret = drm_global_item_ref(global_ref);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000318 if (unlikely(ret != 0)) {
319 DRM_ERROR("Failed setting up TTM BO subsystem\n");
Ben Skeggsebb945a2012-07-20 08:17:34 +1000320 drm_global_item_unref(&drm->ttm.mem_global_ref);
321 drm->ttm.mem_global_ref.release = NULL;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000322 return ret;
323 }
324
325 return 0;
326}
327
328void
Ben Skeggsebb945a2012-07-20 08:17:34 +1000329nouveau_ttm_global_release(struct nouveau_drm *drm)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000330{
Ben Skeggsebb945a2012-07-20 08:17:34 +1000331 if (drm->ttm.mem_global_ref.release == NULL)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000332 return;
333
Ben Skeggsebb945a2012-07-20 08:17:34 +1000334 drm_global_item_unref(&drm->ttm.bo_global_ref.ref);
335 drm_global_item_unref(&drm->ttm.mem_global_ref);
336 drm->ttm.mem_global_ref.release = NULL;
337}
338
339int
340nouveau_ttm_init(struct nouveau_drm *drm)
341{
Ben Skeggs7e8820f2015-08-20 14:54:23 +1000342 struct nvkm_device *device = nvxx_device(&drm->device);
Ben Skeggs340b0e72015-08-20 14:54:23 +1000343 struct nvkm_pci *pci = device->pci;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000344 struct drm_device *dev = drm->dev;
Alexandre Courbot524883b2015-09-04 19:59:33 +0900345 u8 bits;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000346 int ret;
347
Ben Skeggs340b0e72015-08-20 14:54:23 +1000348 if (pci && pci->agp.bridge) {
349 drm->agp.bridge = pci->agp.bridge;
350 drm->agp.base = pci->agp.base;
351 drm->agp.size = pci->agp.size;
352 drm->agp.cma = pci->agp.cma;
353 }
354
Ben Skeggs989aa5b2015-01-12 12:33:37 +1000355 bits = nvxx_mmu(&drm->device)->dma_bits;
Ben Skeggs26c9e8e2015-08-20 14:54:23 +1000356 if (nvxx_device(&drm->device)->func->pci) {
Christoph Hellwig0dcc4a52015-11-10 14:45:39 -0800357 if (drm->agp.bridge)
Alexandre Courbot420b9462014-02-17 15:17:26 +0900358 bits = 32;
Alexandre Courbotb31cf782015-09-04 19:59:34 +0900359 } else if (device->func->tegra) {
360 struct nvkm_device_tegra *tegra = device->func->tegra(device);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000361
Alexandre Courbotb31cf782015-09-04 19:59:34 +0900362 /*
363 * If the platform can use a IOMMU, then the addressable DMA
364 * space is constrained by the IOMMU bit
365 */
366 if (tegra->func->iommu_bit)
367 bits = min(bits, tegra->func->iommu_bit);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000368
Alexandre Courbot420b9462014-02-17 15:17:26 +0900369 }
Ben Skeggsebb945a2012-07-20 08:17:34 +1000370
Alexandre Courbotb31cf782015-09-04 19:59:34 +0900371 ret = dma_set_mask(dev->dev, DMA_BIT_MASK(bits));
Christoph Hellwig0dcc4a52015-11-10 14:45:39 -0800372 if (ret && bits != 32) {
373 bits = 32;
374 ret = dma_set_mask(dev->dev, DMA_BIT_MASK(bits));
375 }
Alexandre Courbotb31cf782015-09-04 19:59:34 +0900376 if (ret)
377 return ret;
378
379 ret = dma_set_coherent_mask(dev->dev, DMA_BIT_MASK(bits));
380 if (ret)
381 dma_set_coherent_mask(dev->dev, DMA_BIT_MASK(32));
382
Ben Skeggsebb945a2012-07-20 08:17:34 +1000383 ret = nouveau_ttm_global_init(drm);
384 if (ret)
385 return ret;
386
387 ret = ttm_bo_device_init(&drm->ttm.bdev,
388 drm->ttm.bo_global_ref.ref.object,
David Herrmann44d847b2013-08-13 19:10:30 +0200389 &nouveau_bo_driver,
390 dev->anon_inode->i_mapping,
391 DRM_FILE_PAGE_OFFSET,
Ben Skeggsebb945a2012-07-20 08:17:34 +1000392 bits <= 32 ? true : false);
393 if (ret) {
394 NV_ERROR(drm, "error initialising bo driver, %d\n", ret);
395 return ret;
396 }
397
398 /* VRAM init */
Ben Skeggsf392ec42014-08-10 04:10:28 +1000399 drm->gem.vram_available = drm->device.info.ram_user;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000400
401 ret = ttm_bo_init_mm(&drm->ttm.bdev, TTM_PL_VRAM,
402 drm->gem.vram_available >> PAGE_SHIFT);
403 if (ret) {
404 NV_ERROR(drm, "VRAM mm init failed, %d\n", ret);
405 return ret;
406 }
407
Ben Skeggs7e8820f2015-08-20 14:54:23 +1000408 drm->ttm.mtrr = arch_phys_wc_add(device->func->resource_addr(device, 1),
409 device->func->resource_size(device, 1));
Ben Skeggsebb945a2012-07-20 08:17:34 +1000410
411 /* GART init */
Ben Skeggs340b0e72015-08-20 14:54:23 +1000412 if (!drm->agp.bridge) {
Ben Skeggs989aa5b2015-01-12 12:33:37 +1000413 drm->gem.gart_available = nvxx_mmu(&drm->device)->limit;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000414 } else {
415 drm->gem.gart_available = drm->agp.size;
416 }
417
418 ret = ttm_bo_init_mm(&drm->ttm.bdev, TTM_PL_TT,
419 drm->gem.gart_available >> PAGE_SHIFT);
420 if (ret) {
421 NV_ERROR(drm, "GART mm init failed, %d\n", ret);
422 return ret;
423 }
424
425 NV_INFO(drm, "VRAM: %d MiB\n", (u32)(drm->gem.vram_available >> 20));
426 NV_INFO(drm, "GART: %d MiB\n", (u32)(drm->gem.gart_available >> 20));
427 return 0;
428}
429
430void
431nouveau_ttm_fini(struct nouveau_drm *drm)
432{
Ben Skeggsebb945a2012-07-20 08:17:34 +1000433 ttm_bo_clean_mm(&drm->ttm.bdev, TTM_PL_VRAM);
434 ttm_bo_clean_mm(&drm->ttm.bdev, TTM_PL_TT);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000435
436 ttm_bo_device_release(&drm->ttm.bdev);
437
438 nouveau_ttm_global_release(drm);
439
Andy Lutomirski247d36d2013-05-13 23:58:41 +0000440 arch_phys_wc_del(drm->ttm.mtrr);
441 drm->ttm.mtrr = 0;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000442}