Linux Audio

Check our new training course

Loading...
v5.4
  1// SPDX-License-Identifier: GPL-2.0 OR MIT
  2/*
  3 * Copyright (c) 2007-2008 Tungsten Graphics, Inc., Cedar Park, TX., USA,
  4 * Copyright (c) 2009 VMware, Inc., Palo Alto, CA., USA,
  5 *
  6 * Permission is hereby granted, free of charge, to any person obtaining a
  7 * copy of this software and associated documentation files (the "Software"),
  8 * to deal in the Software without restriction, including without limitation
  9 * the rights to use, copy, modify, merge, publish, distribute, sub license,
 10 * and/or sell copies of the Software, and to permit persons to whom the
 11 * Software is furnished to do so, subject to the following conditions:
 12 *
 13 * The above copyright notice and this permission notice (including the
 14 * next paragraph) shall be included in all copies or substantial portions
 15 * of the Software.
 16 *
 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 20 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
 21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 23 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 24 */
 
 
 
 
 
 
 25#include "nouveau_drv.h"
 26#include "nouveau_gem.h"
 27#include "nouveau_mem.h"
 28#include "nouveau_ttm.h"
 29
 30#include <drm/drm_legacy.h>
 31
 32#include <core/tegra.h>
 33
 34static int
 35nouveau_manager_init(struct ttm_mem_type_manager *man, unsigned long psize)
 36{
 37	return 0;
 38}
 39
 40static int
 41nouveau_manager_fini(struct ttm_mem_type_manager *man)
 42{
 43	return 0;
 44}
 45
 46static void
 47nouveau_manager_del(struct ttm_mem_type_manager *man, struct ttm_mem_reg *reg)
 
 
 
 48{
 49	nouveau_mem_del(reg);
 50}
 51
 52static void
 53nouveau_manager_debug(struct ttm_mem_type_manager *man,
 54		      struct drm_printer *printer)
 
 
 55{
 
 56}
 57
 58static int
 59nouveau_vram_manager_new(struct ttm_mem_type_manager *man,
 60			 struct ttm_buffer_object *bo,
 61			 const struct ttm_place *place,
 62			 struct ttm_mem_reg *reg)
 63{
 64	struct nouveau_bo *nvbo = nouveau_bo(bo);
 65	struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
 66	struct nouveau_mem *mem;
 67	int ret;
 68
 69	if (drm->client.device.info.ram_size == 0)
 70		return -ENOMEM;
 71
 72	ret = nouveau_mem_new(&drm->master, nvbo->kind, nvbo->comp, reg);
 73	mem = nouveau_mem(reg);
 74	if (ret)
 75		return ret;
 76
 77	ret = nouveau_mem_vram(reg, nvbo->contig, nvbo->page);
 
 
 78	if (ret) {
 79		nouveau_mem_del(reg);
 80		if (ret == -ENOSPC) {
 81			reg->mm_node = NULL;
 82			return 0;
 83		}
 84		return ret;
 85	}
 86
 87	return 0;
 88}
 89
 90const struct ttm_mem_type_manager_func nouveau_vram_manager = {
 91	.init = nouveau_manager_init,
 92	.takedown = nouveau_manager_fini,
 93	.get_node = nouveau_vram_manager_new,
 94	.put_node = nouveau_manager_del,
 95	.debug = nouveau_manager_debug,
 96};
 97
 98static int
 99nouveau_gart_manager_new(struct ttm_mem_type_manager *man,
100			 struct ttm_buffer_object *bo,
101			 const struct ttm_place *place,
102			 struct ttm_mem_reg *reg)
103{
104	struct nouveau_bo *nvbo = nouveau_bo(bo);
105	struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
106	struct nouveau_mem *mem;
107	int ret;
108
109	ret = nouveau_mem_new(&drm->master, nvbo->kind, nvbo->comp, reg);
110	mem = nouveau_mem(reg);
111	if (ret)
112		return ret;
113
114	reg->start = 0;
 
115	return 0;
116}
117
118const struct ttm_mem_type_manager_func nouveau_gart_manager = {
119	.init = nouveau_manager_init,
120	.takedown = nouveau_manager_fini,
121	.get_node = nouveau_gart_manager_new,
122	.put_node = nouveau_manager_del,
123	.debug = nouveau_manager_debug
124};
125
126static int
127nv04_gart_manager_new(struct ttm_mem_type_manager *man,
128		      struct ttm_buffer_object *bo,
129		      const struct ttm_place *place,
130		      struct ttm_mem_reg *reg)
131{
132	struct nouveau_bo *nvbo = nouveau_bo(bo);
133	struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
134	struct nouveau_mem *mem;
135	int ret;
136
137	ret = nouveau_mem_new(&drm->master, nvbo->kind, nvbo->comp, reg);
138	mem = nouveau_mem(reg);
139	if (ret)
140		return ret;
141
 
 
142	ret = nvif_vmm_get(&mem->cli->vmm.vmm, PTES, false, 12, 0,
143			   reg->num_pages << PAGE_SHIFT, &mem->vma[0]);
144	if (ret) {
145		nouveau_mem_del(reg);
146		if (ret == -ENOSPC) {
147			reg->mm_node = NULL;
148			return 0;
149		}
150		return ret;
151	}
152
153	reg->start = mem->vma[0].addr >> PAGE_SHIFT;
154	return 0;
155}
156
157const struct ttm_mem_type_manager_func nv04_gart_manager = {
158	.init = nouveau_manager_init,
159	.takedown = nouveau_manager_fini,
160	.get_node = nv04_gart_manager_new,
161	.put_node = nouveau_manager_del,
162	.debug = nouveau_manager_debug
163};
164
165int
166nouveau_ttm_mmap(struct file *filp, struct vm_area_struct *vma)
167{
168	struct drm_file *file_priv = filp->private_data;
169	struct nouveau_drm *drm = nouveau_drm(file_priv->minor->dev);
170
171	return ttm_bo_mmap(filp, vma, &drm->ttm.bdev);
172}
173
174static int
175nouveau_ttm_init_host(struct nouveau_drm *drm, u8 kind)
176{
177	struct nvif_mmu *mmu = &drm->client.mmu;
178	int typei;
179
180	typei = nvif_mmu_type(mmu, NVIF_MEM_HOST | NVIF_MEM_MAPPABLE |
181					    kind | NVIF_MEM_COHERENT);
182	if (typei < 0)
183		return -ENOSYS;
184
185	drm->ttm.type_host[!!kind] = typei;
186
187	typei = nvif_mmu_type(mmu, NVIF_MEM_HOST | NVIF_MEM_MAPPABLE | kind);
188	if (typei < 0)
189		return -ENOSYS;
190
191	drm->ttm.type_ncoh[!!kind] = typei;
192	return 0;
193}
194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195int
196nouveau_ttm_init(struct nouveau_drm *drm)
197{
198	struct nvkm_device *device = nvxx_device(&drm->client.device);
199	struct nvkm_pci *pci = device->pci;
200	struct nvif_mmu *mmu = &drm->client.mmu;
201	struct drm_device *dev = drm->dev;
202	int typei, ret;
203
204	ret = nouveau_ttm_init_host(drm, 0);
205	if (ret)
206		return ret;
207
208	if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA &&
209	    drm->client.device.info.chipset != 0x50) {
210		ret = nouveau_ttm_init_host(drm, NVIF_MEM_KIND);
211		if (ret)
212			return ret;
213	}
214
215	if (drm->client.device.info.platform != NV_DEVICE_INFO_V0_SOC &&
216	    drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
217		typei = nvif_mmu_type(mmu, NVIF_MEM_VRAM | NVIF_MEM_MAPPABLE |
218					   NVIF_MEM_KIND |
219					   NVIF_MEM_COMP |
220					   NVIF_MEM_DISP);
221		if (typei < 0)
222			return -ENOSYS;
223
224		drm->ttm.type_vram = typei;
225	} else {
226		drm->ttm.type_vram = -1;
227	}
228
229	if (pci && pci->agp.bridge) {
230		drm->agp.bridge = pci->agp.bridge;
231		drm->agp.base = pci->agp.base;
232		drm->agp.size = pci->agp.size;
233		drm->agp.cma = pci->agp.cma;
234	}
235
236	ret = ttm_bo_device_init(&drm->ttm.bdev,
237				  &nouveau_bo_driver,
238				  dev->anon_inode->i_mapping,
239				  drm->client.mmu.dmabits <= 32 ? true : false);
 
 
240	if (ret) {
241		NV_ERROR(drm, "error initialising bo driver, %d\n", ret);
242		return ret;
243	}
244
245	/* VRAM init */
246	drm->gem.vram_available = drm->client.device.info.ram_user;
247
248	arch_io_reserve_memtype_wc(device->func->resource_addr(device, 1),
249				   device->func->resource_size(device, 1));
250
251	ret = ttm_bo_init_mm(&drm->ttm.bdev, TTM_PL_VRAM,
252			      drm->gem.vram_available >> PAGE_SHIFT);
253	if (ret) {
254		NV_ERROR(drm, "VRAM mm init failed, %d\n", ret);
255		return ret;
256	}
257
258	drm->ttm.mtrr = arch_phys_wc_add(device->func->resource_addr(device, 1),
259					 device->func->resource_size(device, 1));
260
261	/* GART init */
262	if (!drm->agp.bridge) {
263		drm->gem.gart_available = drm->client.vmm.vmm.limit;
264	} else {
265		drm->gem.gart_available = drm->agp.size;
266	}
267
268	ret = ttm_bo_init_mm(&drm->ttm.bdev, TTM_PL_TT,
269			      drm->gem.gart_available >> PAGE_SHIFT);
270	if (ret) {
271		NV_ERROR(drm, "GART mm init failed, %d\n", ret);
272		return ret;
273	}
274
 
 
 
275	NV_INFO(drm, "VRAM: %d MiB\n", (u32)(drm->gem.vram_available >> 20));
276	NV_INFO(drm, "GART: %d MiB\n", (u32)(drm->gem.gart_available >> 20));
277	return 0;
278}
279
280void
281nouveau_ttm_fini(struct nouveau_drm *drm)
282{
283	struct nvkm_device *device = nvxx_device(&drm->client.device);
284
285	ttm_bo_clean_mm(&drm->ttm.bdev, TTM_PL_VRAM);
286	ttm_bo_clean_mm(&drm->ttm.bdev, TTM_PL_TT);
287
288	ttm_bo_device_release(&drm->ttm.bdev);
289
290	arch_phys_wc_del(drm->ttm.mtrr);
291	drm->ttm.mtrr = 0;
292	arch_io_free_memtype_wc(device->func->resource_addr(device, 1),
293				device->func->resource_size(device, 1));
294
295}
v6.8
  1// SPDX-License-Identifier: GPL-2.0 OR MIT
  2/*
  3 * Copyright (c) 2007-2008 Tungsten Graphics, Inc., Cedar Park, TX., USA,
  4 * Copyright (c) 2009 VMware, Inc., Palo Alto, CA., USA,
  5 *
  6 * Permission is hereby granted, free of charge, to any person obtaining a
  7 * copy of this software and associated documentation files (the "Software"),
  8 * to deal in the Software without restriction, including without limitation
  9 * the rights to use, copy, modify, merge, publish, distribute, sub license,
 10 * and/or sell copies of the Software, and to permit persons to whom the
 11 * Software is furnished to do so, subject to the following conditions:
 12 *
 13 * The above copyright notice and this permission notice (including the
 14 * next paragraph) shall be included in all copies or substantial portions
 15 * of the Software.
 16 *
 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 20 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
 21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 23 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 24 */
 25
 26#include <linux/limits.h>
 27
 28#include <drm/ttm/ttm_range_manager.h>
 29#include <drm/drm_cache.h>
 30
 31#include "nouveau_drv.h"
 32#include "nouveau_gem.h"
 33#include "nouveau_mem.h"
 34#include "nouveau_ttm.h"
 35
 
 
 36#include <core/tegra.h>
 37
 38static void
 39nouveau_manager_del(struct ttm_resource_manager *man,
 40		    struct ttm_resource *reg)
 
 
 
 
 
 41{
 42	nouveau_mem_del(man, reg);
 43}
 44
 45static bool
 46nouveau_manager_intersects(struct ttm_resource_manager *man,
 47			   struct ttm_resource *res,
 48			   const struct ttm_place *place,
 49			   size_t size)
 50{
 51	return nouveau_mem_intersects(res, place, size);
 52}
 53
 54static bool
 55nouveau_manager_compatible(struct ttm_resource_manager *man,
 56			   struct ttm_resource *res,
 57			   const struct ttm_place *place,
 58			   size_t size)
 59{
 60	return nouveau_mem_compatible(res, place, size);
 61}
 62
 63static int
 64nouveau_vram_manager_new(struct ttm_resource_manager *man,
 65			 struct ttm_buffer_object *bo,
 66			 const struct ttm_place *place,
 67			 struct ttm_resource **res)
 68{
 69	struct nouveau_bo *nvbo = nouveau_bo(bo);
 70	struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
 
 71	int ret;
 72
 73	if (drm->client.device.info.ram_size == 0)
 74		return -ENOMEM;
 75
 76	ret = nouveau_mem_new(&drm->master, nvbo->kind, nvbo->comp, res);
 
 77	if (ret)
 78		return ret;
 79
 80	ttm_resource_init(bo, place, *res);
 81
 82	ret = nouveau_mem_vram(*res, nvbo->contig, nvbo->page);
 83	if (ret) {
 84		nouveau_mem_del(man, *res);
 
 
 
 
 85		return ret;
 86	}
 87
 88	return 0;
 89}
 90
 91const struct ttm_resource_manager_func nouveau_vram_manager = {
 92	.alloc = nouveau_vram_manager_new,
 93	.free = nouveau_manager_del,
 94	.intersects = nouveau_manager_intersects,
 95	.compatible = nouveau_manager_compatible,
 
 96};
 97
 98static int
 99nouveau_gart_manager_new(struct ttm_resource_manager *man,
100			 struct ttm_buffer_object *bo,
101			 const struct ttm_place *place,
102			 struct ttm_resource **res)
103{
104	struct nouveau_bo *nvbo = nouveau_bo(bo);
105	struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
 
106	int ret;
107
108	ret = nouveau_mem_new(&drm->master, nvbo->kind, nvbo->comp, res);
 
109	if (ret)
110		return ret;
111
112	ttm_resource_init(bo, place, *res);
113	(*res)->start = 0;
114	return 0;
115}
116
117const struct ttm_resource_manager_func nouveau_gart_manager = {
118	.alloc = nouveau_gart_manager_new,
119	.free = nouveau_manager_del,
120	.intersects = nouveau_manager_intersects,
121	.compatible = nouveau_manager_compatible,
 
122};
123
124static int
125nv04_gart_manager_new(struct ttm_resource_manager *man,
126		      struct ttm_buffer_object *bo,
127		      const struct ttm_place *place,
128		      struct ttm_resource **res)
129{
130	struct nouveau_bo *nvbo = nouveau_bo(bo);
131	struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
132	struct nouveau_mem *mem;
133	int ret;
134
135	ret = nouveau_mem_new(&drm->master, nvbo->kind, nvbo->comp, res);
 
136	if (ret)
137		return ret;
138
139	mem = nouveau_mem(*res);
140	ttm_resource_init(bo, place, *res);
141	ret = nvif_vmm_get(&mem->cli->vmm.vmm, PTES, false, 12, 0,
142			   (long)(*res)->size, &mem->vma[0]);
143	if (ret) {
144		nouveau_mem_del(man, *res);
 
 
 
 
145		return ret;
146	}
147
148	(*res)->start = mem->vma[0].addr >> PAGE_SHIFT;
149	return 0;
150}
151
152const struct ttm_resource_manager_func nv04_gart_manager = {
153	.alloc = nv04_gart_manager_new,
154	.free = nouveau_manager_del,
155	.intersects = nouveau_manager_intersects,
156	.compatible = nouveau_manager_compatible,
 
157};
158
 
 
 
 
 
 
 
 
 
159static int
160nouveau_ttm_init_host(struct nouveau_drm *drm, u8 kind)
161{
162	struct nvif_mmu *mmu = &drm->client.mmu;
163	int typei;
164
165	typei = nvif_mmu_type(mmu, NVIF_MEM_HOST | NVIF_MEM_MAPPABLE |
166					    kind | NVIF_MEM_COHERENT);
167	if (typei < 0)
168		return -ENOSYS;
169
170	drm->ttm.type_host[!!kind] = typei;
171
172	typei = nvif_mmu_type(mmu, NVIF_MEM_HOST | NVIF_MEM_MAPPABLE | kind);
173	if (typei < 0)
174		return -ENOSYS;
175
176	drm->ttm.type_ncoh[!!kind] = typei;
177	return 0;
178}
179
180static int
181nouveau_ttm_init_vram(struct nouveau_drm *drm)
182{
183	if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
184		struct ttm_resource_manager *man = kzalloc(sizeof(*man), GFP_KERNEL);
185
186		if (!man)
187			return -ENOMEM;
188
189		man->func = &nouveau_vram_manager;
190
191		ttm_resource_manager_init(man, &drm->ttm.bdev,
192					  drm->gem.vram_available >> PAGE_SHIFT);
193		ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_VRAM, man);
194		ttm_resource_manager_set_used(man, true);
195		return 0;
196	} else {
197		return ttm_range_man_init(&drm->ttm.bdev, TTM_PL_VRAM, false,
198					  drm->gem.vram_available >> PAGE_SHIFT);
199	}
200}
201
202static void
203nouveau_ttm_fini_vram(struct nouveau_drm *drm)
204{
205	struct ttm_resource_manager *man = ttm_manager_type(&drm->ttm.bdev, TTM_PL_VRAM);
206
207	if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
208		ttm_resource_manager_set_used(man, false);
209		ttm_resource_manager_evict_all(&drm->ttm.bdev, man);
210		ttm_resource_manager_cleanup(man);
211		ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_VRAM, NULL);
212		kfree(man);
213	} else
214		ttm_range_man_fini(&drm->ttm.bdev, TTM_PL_VRAM);
215}
216
217static int
218nouveau_ttm_init_gtt(struct nouveau_drm *drm)
219{
220	struct ttm_resource_manager *man;
221	unsigned long size_pages = drm->gem.gart_available >> PAGE_SHIFT;
222	const struct ttm_resource_manager_func *func = NULL;
223
224	if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA)
225		func = &nouveau_gart_manager;
226	else if (!drm->agp.bridge)
227		func = &nv04_gart_manager;
228	else
229		return ttm_range_man_init(&drm->ttm.bdev, TTM_PL_TT, true,
230					  size_pages);
231
232	man = kzalloc(sizeof(*man), GFP_KERNEL);
233	if (!man)
234		return -ENOMEM;
235
236	man->func = func;
237	man->use_tt = true;
238	ttm_resource_manager_init(man, &drm->ttm.bdev, size_pages);
239	ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_TT, man);
240	ttm_resource_manager_set_used(man, true);
241	return 0;
242}
243
244static void
245nouveau_ttm_fini_gtt(struct nouveau_drm *drm)
246{
247	struct ttm_resource_manager *man = ttm_manager_type(&drm->ttm.bdev, TTM_PL_TT);
248
249	if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA &&
250	    drm->agp.bridge)
251		ttm_range_man_fini(&drm->ttm.bdev, TTM_PL_TT);
252	else {
253		ttm_resource_manager_set_used(man, false);
254		ttm_resource_manager_evict_all(&drm->ttm.bdev, man);
255		ttm_resource_manager_cleanup(man);
256		ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_TT, NULL);
257		kfree(man);
258	}
259}
260
261int
262nouveau_ttm_init(struct nouveau_drm *drm)
263{
264	struct nvkm_device *device = nvxx_device(&drm->client.device);
265	struct nvkm_pci *pci = device->pci;
266	struct nvif_mmu *mmu = &drm->client.mmu;
267	struct drm_device *dev = drm->dev;
268	int typei, ret;
269
270	ret = nouveau_ttm_init_host(drm, 0);
271	if (ret)
272		return ret;
273
274	if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA &&
275	    drm->client.device.info.chipset != 0x50) {
276		ret = nouveau_ttm_init_host(drm, NVIF_MEM_KIND);
277		if (ret)
278			return ret;
279	}
280
281	if (drm->client.device.info.platform != NV_DEVICE_INFO_V0_SOC &&
282	    drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
283		typei = nvif_mmu_type(mmu, NVIF_MEM_VRAM | NVIF_MEM_MAPPABLE |
284					   NVIF_MEM_KIND |
285					   NVIF_MEM_COMP |
286					   NVIF_MEM_DISP);
287		if (typei < 0)
288			return -ENOSYS;
289
290		drm->ttm.type_vram = typei;
291	} else {
292		drm->ttm.type_vram = -1;
293	}
294
295	if (pci && pci->agp.bridge) {
296		drm->agp.bridge = pci->agp.bridge;
297		drm->agp.base = pci->agp.base;
298		drm->agp.size = pci->agp.size;
299		drm->agp.cma = pci->agp.cma;
300	}
301
302	ret = ttm_device_init(&drm->ttm.bdev, &nouveau_bo_driver, drm->dev->dev,
 
303				  dev->anon_inode->i_mapping,
304				  dev->vma_offset_manager,
305				  drm_need_swiotlb(drm->client.mmu.dmabits),
306				  drm->client.mmu.dmabits <= 32);
307	if (ret) {
308		NV_ERROR(drm, "error initialising bo driver, %d\n", ret);
309		return ret;
310	}
311
312	/* VRAM init */
313	drm->gem.vram_available = drm->client.device.info.ram_user;
314
315	arch_io_reserve_memtype_wc(device->func->resource_addr(device, 1),
316				   device->func->resource_size(device, 1));
317
318	ret = nouveau_ttm_init_vram(drm);
 
319	if (ret) {
320		NV_ERROR(drm, "VRAM mm init failed, %d\n", ret);
321		return ret;
322	}
323
324	drm->ttm.mtrr = arch_phys_wc_add(device->func->resource_addr(device, 1),
325					 device->func->resource_size(device, 1));
326
327	/* GART init */
328	if (!drm->agp.bridge) {
329		drm->gem.gart_available = drm->client.vmm.vmm.limit;
330	} else {
331		drm->gem.gart_available = drm->agp.size;
332	}
333
334	ret = nouveau_ttm_init_gtt(drm);
 
335	if (ret) {
336		NV_ERROR(drm, "GART mm init failed, %d\n", ret);
337		return ret;
338	}
339
340	mutex_init(&drm->ttm.io_reserve_mutex);
341	INIT_LIST_HEAD(&drm->ttm.io_reserve_lru);
342
343	NV_INFO(drm, "VRAM: %d MiB\n", (u32)(drm->gem.vram_available >> 20));
344	NV_INFO(drm, "GART: %d MiB\n", (u32)(drm->gem.gart_available >> 20));
345	return 0;
346}
347
348void
349nouveau_ttm_fini(struct nouveau_drm *drm)
350{
351	struct nvkm_device *device = nvxx_device(&drm->client.device);
352
353	nouveau_ttm_fini_vram(drm);
354	nouveau_ttm_fini_gtt(drm);
355
356	ttm_device_fini(&drm->ttm.bdev);
357
358	arch_phys_wc_del(drm->ttm.mtrr);
359	drm->ttm.mtrr = 0;
360	arch_io_free_memtype_wc(device->func->resource_addr(device, 1),
361				device->func->resource_size(device, 1));
362
363}