2 * Copyright 2009 Jerome Glisse.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
16 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
17 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
19 * USE OR OTHER DEALINGS IN THE SOFTWARE.
21 * The above copyright notice and this permission notice (including the
22 * next paragraph) shall be included in all copies or substantial portions
28 * Jerome Glisse <glisse@freedesktop.org>
29 * Thomas Hellstrom <thomas-at-tungstengraphics-dot-com>
32 #include <ttm/ttm_bo_api.h>
33 #include <ttm/ttm_bo_driver.h>
34 #include <ttm/ttm_placement.h>
35 #include <ttm/ttm_module.h>
36 #include <ttm/ttm_page_alloc.h>
38 #include <drm/radeon_drm.h>
39 #include <linux/seq_file.h>
40 #include <linux/slab.h>
41 #include "radeon_reg.h"
44 #define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
46 static int radeon_ttm_debugfs_init(struct radeon_device
*rdev
);
48 static struct radeon_device
*radeon_get_rdev(struct ttm_bo_device
*bdev
)
50 struct radeon_mman
*mman
;
51 struct radeon_device
*rdev
;
53 mman
= container_of(bdev
, struct radeon_mman
, bdev
);
54 rdev
= container_of(mman
, struct radeon_device
, mman
);
62 static int radeon_ttm_mem_global_init(struct drm_global_reference
*ref
)
64 return ttm_mem_global_init(ref
->object
);
67 static void radeon_ttm_mem_global_release(struct drm_global_reference
*ref
)
69 ttm_mem_global_release(ref
->object
);
72 static int radeon_ttm_global_init(struct radeon_device
*rdev
)
74 struct drm_global_reference
*global_ref
;
77 rdev
->mman
.mem_global_referenced
= false;
78 global_ref
= &rdev
->mman
.mem_global_ref
;
79 global_ref
->global_type
= DRM_GLOBAL_TTM_MEM
;
80 global_ref
->size
= sizeof(struct ttm_mem_global
);
81 global_ref
->init
= &radeon_ttm_mem_global_init
;
82 global_ref
->release
= &radeon_ttm_mem_global_release
;
83 r
= drm_global_item_ref(global_ref
);
85 DRM_ERROR("Failed setting up TTM memory accounting "
90 rdev
->mman
.bo_global_ref
.mem_glob
=
91 rdev
->mman
.mem_global_ref
.object
;
92 global_ref
= &rdev
->mman
.bo_global_ref
.ref
;
93 global_ref
->global_type
= DRM_GLOBAL_TTM_BO
;
94 global_ref
->size
= sizeof(struct ttm_bo_global
);
95 global_ref
->init
= &ttm_bo_global_init
;
96 global_ref
->release
= &ttm_bo_global_release
;
97 r
= drm_global_item_ref(global_ref
);
99 DRM_ERROR("Failed setting up TTM BO subsystem.\n");
100 drm_global_item_unref(&rdev
->mman
.mem_global_ref
);
104 rdev
->mman
.mem_global_referenced
= true;
108 static void radeon_ttm_global_fini(struct radeon_device
*rdev
)
110 if (rdev
->mman
.mem_global_referenced
) {
111 drm_global_item_unref(&rdev
->mman
.bo_global_ref
.ref
);
112 drm_global_item_unref(&rdev
->mman
.mem_global_ref
);
113 rdev
->mman
.mem_global_referenced
= false;
117 struct ttm_backend
*radeon_ttm_backend_create(struct radeon_device
*rdev
);
119 static struct ttm_backend
*
120 radeon_create_ttm_backend_entry(struct ttm_bo_device
*bdev
)
122 struct radeon_device
*rdev
;
124 rdev
= radeon_get_rdev(bdev
);
126 if (rdev
->flags
& RADEON_IS_AGP
) {
127 return ttm_agp_backend_init(bdev
, rdev
->ddev
->agp
->bridge
);
131 return radeon_ttm_backend_create(rdev
);
135 static int radeon_invalidate_caches(struct ttm_bo_device
*bdev
, uint32_t flags
)
140 static int radeon_init_mem_type(struct ttm_bo_device
*bdev
, uint32_t type
,
141 struct ttm_mem_type_manager
*man
)
143 struct radeon_device
*rdev
;
145 rdev
= radeon_get_rdev(bdev
);
150 man
->flags
= TTM_MEMTYPE_FLAG_MAPPABLE
;
151 man
->available_caching
= TTM_PL_MASK_CACHING
;
152 man
->default_caching
= TTM_PL_FLAG_CACHED
;
155 man
->func
= &ttm_bo_manager_func
;
156 man
->gpu_offset
= rdev
->mc
.gtt_start
;
157 man
->available_caching
= TTM_PL_MASK_CACHING
;
158 man
->default_caching
= TTM_PL_FLAG_CACHED
;
159 man
->flags
= TTM_MEMTYPE_FLAG_MAPPABLE
| TTM_MEMTYPE_FLAG_CMA
;
161 if (rdev
->flags
& RADEON_IS_AGP
) {
162 if (!(drm_core_has_AGP(rdev
->ddev
) && rdev
->ddev
->agp
)) {
163 DRM_ERROR("AGP is not enabled for memory type %u\n",
167 if (!rdev
->ddev
->agp
->cant_use_aperture
)
168 man
->flags
= TTM_MEMTYPE_FLAG_MAPPABLE
;
169 man
->available_caching
= TTM_PL_FLAG_UNCACHED
|
171 man
->default_caching
= TTM_PL_FLAG_WC
;
176 /* "On-card" video ram */
177 man
->func
= &ttm_bo_manager_func
;
178 man
->gpu_offset
= rdev
->mc
.vram_start
;
179 man
->flags
= TTM_MEMTYPE_FLAG_FIXED
|
180 TTM_MEMTYPE_FLAG_MAPPABLE
;
181 man
->available_caching
= TTM_PL_FLAG_UNCACHED
| TTM_PL_FLAG_WC
;
182 man
->default_caching
= TTM_PL_FLAG_WC
;
185 DRM_ERROR("Unsupported memory type %u\n", (unsigned)type
);
191 static void radeon_evict_flags(struct ttm_buffer_object
*bo
,
192 struct ttm_placement
*placement
)
194 struct radeon_bo
*rbo
;
195 static u32 placements
= TTM_PL_MASK_CACHING
| TTM_PL_FLAG_SYSTEM
;
197 if (!radeon_ttm_bo_is_radeon_bo(bo
)) {
200 placement
->placement
= &placements
;
201 placement
->busy_placement
= &placements
;
202 placement
->num_placement
= 1;
203 placement
->num_busy_placement
= 1;
206 rbo
= container_of(bo
, struct radeon_bo
, tbo
);
207 switch (bo
->mem
.mem_type
) {
209 if (rbo
->rdev
->cp
.ready
== false)
210 radeon_ttm_placement_from_domain(rbo
, RADEON_GEM_DOMAIN_CPU
);
212 radeon_ttm_placement_from_domain(rbo
, RADEON_GEM_DOMAIN_GTT
);
216 radeon_ttm_placement_from_domain(rbo
, RADEON_GEM_DOMAIN_CPU
);
218 *placement
= rbo
->placement
;
221 static int radeon_verify_access(struct ttm_buffer_object
*bo
, struct file
*filp
)
226 static void radeon_move_null(struct ttm_buffer_object
*bo
,
227 struct ttm_mem_reg
*new_mem
)
229 struct ttm_mem_reg
*old_mem
= &bo
->mem
;
231 BUG_ON(old_mem
->mm_node
!= NULL
);
233 new_mem
->mm_node
= NULL
;
236 static int radeon_move_blit(struct ttm_buffer_object
*bo
,
237 bool evict
, int no_wait_reserve
, bool no_wait_gpu
,
238 struct ttm_mem_reg
*new_mem
,
239 struct ttm_mem_reg
*old_mem
)
241 struct radeon_device
*rdev
;
242 uint64_t old_start
, new_start
;
243 struct radeon_fence
*fence
;
246 rdev
= radeon_get_rdev(bo
->bdev
);
247 r
= radeon_fence_create(rdev
, &fence
);
251 old_start
= old_mem
->start
<< PAGE_SHIFT
;
252 new_start
= new_mem
->start
<< PAGE_SHIFT
;
254 switch (old_mem
->mem_type
) {
256 old_start
+= rdev
->mc
.vram_start
;
259 old_start
+= rdev
->mc
.gtt_start
;
262 DRM_ERROR("Unknown placement %d\n", old_mem
->mem_type
);
265 switch (new_mem
->mem_type
) {
267 new_start
+= rdev
->mc
.vram_start
;
270 new_start
+= rdev
->mc
.gtt_start
;
273 DRM_ERROR("Unknown placement %d\n", old_mem
->mem_type
);
276 if (!rdev
->cp
.ready
) {
277 DRM_ERROR("Trying to move memory with CP turned off.\n");
280 r
= radeon_copy(rdev
, old_start
, new_start
, new_mem
->num_pages
, fence
);
281 /* FIXME: handle copy error */
282 r
= ttm_bo_move_accel_cleanup(bo
, (void *)fence
, NULL
,
283 evict
, no_wait_reserve
, no_wait_gpu
, new_mem
);
284 radeon_fence_unref(&fence
);
288 static int radeon_move_vram_ram(struct ttm_buffer_object
*bo
,
289 bool evict
, bool interruptible
,
290 bool no_wait_reserve
, bool no_wait_gpu
,
291 struct ttm_mem_reg
*new_mem
)
293 struct radeon_device
*rdev
;
294 struct ttm_mem_reg
*old_mem
= &bo
->mem
;
295 struct ttm_mem_reg tmp_mem
;
297 struct ttm_placement placement
;
300 rdev
= radeon_get_rdev(bo
->bdev
);
302 tmp_mem
.mm_node
= NULL
;
305 placement
.num_placement
= 1;
306 placement
.placement
= &placements
;
307 placement
.num_busy_placement
= 1;
308 placement
.busy_placement
= &placements
;
309 placements
= TTM_PL_MASK_CACHING
| TTM_PL_FLAG_TT
;
310 r
= ttm_bo_mem_space(bo
, &placement
, &tmp_mem
,
311 interruptible
, no_wait_reserve
, no_wait_gpu
);
316 r
= ttm_tt_set_placement_caching(bo
->ttm
, tmp_mem
.placement
);
321 r
= ttm_tt_bind(bo
->ttm
, &tmp_mem
);
325 r
= radeon_move_blit(bo
, true, no_wait_reserve
, no_wait_gpu
, &tmp_mem
, old_mem
);
329 r
= ttm_bo_move_ttm(bo
, true, no_wait_reserve
, no_wait_gpu
, new_mem
);
331 ttm_bo_mem_put(bo
, &tmp_mem
);
335 static int radeon_move_ram_vram(struct ttm_buffer_object
*bo
,
336 bool evict
, bool interruptible
,
337 bool no_wait_reserve
, bool no_wait_gpu
,
338 struct ttm_mem_reg
*new_mem
)
340 struct radeon_device
*rdev
;
341 struct ttm_mem_reg
*old_mem
= &bo
->mem
;
342 struct ttm_mem_reg tmp_mem
;
343 struct ttm_placement placement
;
347 rdev
= radeon_get_rdev(bo
->bdev
);
349 tmp_mem
.mm_node
= NULL
;
352 placement
.num_placement
= 1;
353 placement
.placement
= &placements
;
354 placement
.num_busy_placement
= 1;
355 placement
.busy_placement
= &placements
;
356 placements
= TTM_PL_MASK_CACHING
| TTM_PL_FLAG_TT
;
357 r
= ttm_bo_mem_space(bo
, &placement
, &tmp_mem
, interruptible
, no_wait_reserve
, no_wait_gpu
);
361 r
= ttm_bo_move_ttm(bo
, true, no_wait_reserve
, no_wait_gpu
, &tmp_mem
);
365 r
= radeon_move_blit(bo
, true, no_wait_reserve
, no_wait_gpu
, new_mem
, old_mem
);
370 ttm_bo_mem_put(bo
, &tmp_mem
);
374 static int radeon_bo_move(struct ttm_buffer_object
*bo
,
375 bool evict
, bool interruptible
,
376 bool no_wait_reserve
, bool no_wait_gpu
,
377 struct ttm_mem_reg
*new_mem
)
379 struct radeon_device
*rdev
;
380 struct ttm_mem_reg
*old_mem
= &bo
->mem
;
383 rdev
= radeon_get_rdev(bo
->bdev
);
384 if (old_mem
->mem_type
== TTM_PL_SYSTEM
&& bo
->ttm
== NULL
) {
385 radeon_move_null(bo
, new_mem
);
388 if ((old_mem
->mem_type
== TTM_PL_TT
&&
389 new_mem
->mem_type
== TTM_PL_SYSTEM
) ||
390 (old_mem
->mem_type
== TTM_PL_SYSTEM
&&
391 new_mem
->mem_type
== TTM_PL_TT
)) {
393 radeon_move_null(bo
, new_mem
);
396 if (!rdev
->cp
.ready
|| rdev
->asic
->copy
== NULL
) {
401 if (old_mem
->mem_type
== TTM_PL_VRAM
&&
402 new_mem
->mem_type
== TTM_PL_SYSTEM
) {
403 r
= radeon_move_vram_ram(bo
, evict
, interruptible
,
404 no_wait_reserve
, no_wait_gpu
, new_mem
);
405 } else if (old_mem
->mem_type
== TTM_PL_SYSTEM
&&
406 new_mem
->mem_type
== TTM_PL_VRAM
) {
407 r
= radeon_move_ram_vram(bo
, evict
, interruptible
,
408 no_wait_reserve
, no_wait_gpu
, new_mem
);
410 r
= radeon_move_blit(bo
, evict
, no_wait_reserve
, no_wait_gpu
, new_mem
, old_mem
);
415 r
= ttm_bo_move_memcpy(bo
, evict
, no_wait_reserve
, no_wait_gpu
, new_mem
);
420 static int radeon_ttm_io_mem_reserve(struct ttm_bo_device
*bdev
, struct ttm_mem_reg
*mem
)
422 struct ttm_mem_type_manager
*man
= &bdev
->man
[mem
->mem_type
];
423 struct radeon_device
*rdev
= radeon_get_rdev(bdev
);
425 mem
->bus
.addr
= NULL
;
427 mem
->bus
.size
= mem
->num_pages
<< PAGE_SHIFT
;
429 mem
->bus
.is_iomem
= false;
430 if (!(man
->flags
& TTM_MEMTYPE_FLAG_MAPPABLE
))
432 switch (mem
->mem_type
) {
438 if (rdev
->flags
& RADEON_IS_AGP
) {
439 /* RADEON_IS_AGP is set only if AGP is active */
440 mem
->bus
.offset
= mem
->start
<< PAGE_SHIFT
;
441 mem
->bus
.base
= rdev
->mc
.agp_base
;
442 mem
->bus
.is_iomem
= !rdev
->ddev
->agp
->cant_use_aperture
;
447 mem
->bus
.offset
= mem
->start
<< PAGE_SHIFT
;
448 /* check if it's visible */
449 if ((mem
->bus
.offset
+ mem
->bus
.size
) > rdev
->mc
.visible_vram_size
)
451 mem
->bus
.base
= rdev
->mc
.aper_base
;
452 mem
->bus
.is_iomem
= true;
455 * Alpha: use bus.addr to hold the ioremap() return,
456 * so we can modify bus.base below.
458 if (mem
->placement
& TTM_PL_FLAG_WC
)
460 ioremap_wc(mem
->bus
.base
+ mem
->bus
.offset
,
464 ioremap_nocache(mem
->bus
.base
+ mem
->bus
.offset
,
468 * Alpha: Use just the bus offset plus
469 * the hose/domain memory base for bus.base.
470 * It then can be used to build PTEs for VRAM
471 * access, as done in ttm_bo_vm_fault().
473 mem
->bus
.base
= (mem
->bus
.base
& 0x0ffffffffUL
) +
474 rdev
->ddev
->hose
->dense_mem_base
;
483 static void radeon_ttm_io_mem_free(struct ttm_bo_device
*bdev
, struct ttm_mem_reg
*mem
)
487 static int radeon_sync_obj_wait(void *sync_obj
, void *sync_arg
,
488 bool lazy
, bool interruptible
)
490 return radeon_fence_wait((struct radeon_fence
*)sync_obj
, interruptible
);
493 static int radeon_sync_obj_flush(void *sync_obj
, void *sync_arg
)
498 static void radeon_sync_obj_unref(void **sync_obj
)
500 radeon_fence_unref((struct radeon_fence
**)sync_obj
);
503 static void *radeon_sync_obj_ref(void *sync_obj
)
505 return radeon_fence_ref((struct radeon_fence
*)sync_obj
);
508 static bool radeon_sync_obj_signaled(void *sync_obj
, void *sync_arg
)
510 return radeon_fence_signaled((struct radeon_fence
*)sync_obj
);
513 static struct ttm_bo_driver radeon_bo_driver
= {
514 .create_ttm_backend_entry
= &radeon_create_ttm_backend_entry
,
515 .invalidate_caches
= &radeon_invalidate_caches
,
516 .init_mem_type
= &radeon_init_mem_type
,
517 .evict_flags
= &radeon_evict_flags
,
518 .move
= &radeon_bo_move
,
519 .verify_access
= &radeon_verify_access
,
520 .sync_obj_signaled
= &radeon_sync_obj_signaled
,
521 .sync_obj_wait
= &radeon_sync_obj_wait
,
522 .sync_obj_flush
= &radeon_sync_obj_flush
,
523 .sync_obj_unref
= &radeon_sync_obj_unref
,
524 .sync_obj_ref
= &radeon_sync_obj_ref
,
525 .move_notify
= &radeon_bo_move_notify
,
526 .fault_reserve_notify
= &radeon_bo_fault_reserve_notify
,
527 .io_mem_reserve
= &radeon_ttm_io_mem_reserve
,
528 .io_mem_free
= &radeon_ttm_io_mem_free
,
531 int radeon_ttm_init(struct radeon_device
*rdev
)
535 r
= radeon_ttm_global_init(rdev
);
539 /* No others user of address space so set it to 0 */
540 r
= ttm_bo_device_init(&rdev
->mman
.bdev
,
541 rdev
->mman
.bo_global_ref
.ref
.object
,
542 &radeon_bo_driver
, DRM_FILE_PAGE_OFFSET
,
545 DRM_ERROR("failed initializing buffer object driver(%d).\n", r
);
548 rdev
->mman
.initialized
= true;
549 r
= ttm_bo_init_mm(&rdev
->mman
.bdev
, TTM_PL_VRAM
,
550 rdev
->mc
.real_vram_size
>> PAGE_SHIFT
);
552 DRM_ERROR("Failed initializing VRAM heap.\n");
555 r
= radeon_bo_create(rdev
, 256 * 1024, PAGE_SIZE
, true,
556 RADEON_GEM_DOMAIN_VRAM
,
557 &rdev
->stollen_vga_memory
);
561 r
= radeon_bo_reserve(rdev
->stollen_vga_memory
, false);
564 r
= radeon_bo_pin(rdev
->stollen_vga_memory
, RADEON_GEM_DOMAIN_VRAM
, NULL
);
565 radeon_bo_unreserve(rdev
->stollen_vga_memory
);
567 radeon_bo_unref(&rdev
->stollen_vga_memory
);
570 DRM_INFO("radeon: %uM of VRAM memory ready\n",
571 (unsigned)rdev
->mc
.real_vram_size
/ (1024 * 1024));
572 r
= ttm_bo_init_mm(&rdev
->mman
.bdev
, TTM_PL_TT
,
573 rdev
->mc
.gtt_size
>> PAGE_SHIFT
);
575 DRM_ERROR("Failed initializing GTT heap.\n");
578 DRM_INFO("radeon: %uM of GTT memory ready.\n",
579 (unsigned)(rdev
->mc
.gtt_size
/ (1024 * 1024)));
580 if (unlikely(rdev
->mman
.bdev
.dev_mapping
== NULL
)) {
581 rdev
->mman
.bdev
.dev_mapping
= rdev
->ddev
->dev_mapping
;
584 r
= radeon_ttm_debugfs_init(rdev
);
586 DRM_ERROR("Failed to init debugfs\n");
592 void radeon_ttm_fini(struct radeon_device
*rdev
)
596 if (!rdev
->mman
.initialized
)
598 if (rdev
->stollen_vga_memory
) {
599 r
= radeon_bo_reserve(rdev
->stollen_vga_memory
, false);
601 radeon_bo_unpin(rdev
->stollen_vga_memory
);
602 radeon_bo_unreserve(rdev
->stollen_vga_memory
);
604 radeon_bo_unref(&rdev
->stollen_vga_memory
);
606 ttm_bo_clean_mm(&rdev
->mman
.bdev
, TTM_PL_VRAM
);
607 ttm_bo_clean_mm(&rdev
->mman
.bdev
, TTM_PL_TT
);
608 ttm_bo_device_release(&rdev
->mman
.bdev
);
609 radeon_gart_fini(rdev
);
610 radeon_ttm_global_fini(rdev
);
611 rdev
->mman
.initialized
= false;
612 DRM_INFO("radeon: ttm finalized\n");
615 /* this should only be called at bootup or when userspace
617 void radeon_ttm_set_active_vram_size(struct radeon_device
*rdev
, u64 size
)
619 struct ttm_mem_type_manager
*man
;
621 if (!rdev
->mman
.initialized
)
624 man
= &rdev
->mman
.bdev
.man
[TTM_PL_VRAM
];
625 /* this just adjusts TTM size idea, which sets lpfn to the correct value */
626 man
->size
= size
>> PAGE_SHIFT
;
629 static struct vm_operations_struct radeon_ttm_vm_ops
;
630 static const struct vm_operations_struct
*ttm_vm_ops
= NULL
;
632 static int radeon_ttm_fault(struct vm_area_struct
*vma
, struct vm_fault
*vmf
)
634 struct ttm_buffer_object
*bo
;
635 struct radeon_device
*rdev
;
638 bo
= (struct ttm_buffer_object
*)vma
->vm_private_data
;
640 return VM_FAULT_NOPAGE
;
642 rdev
= radeon_get_rdev(bo
->bdev
);
643 mutex_lock(&rdev
->vram_mutex
);
644 r
= ttm_vm_ops
->fault(vma
, vmf
);
645 mutex_unlock(&rdev
->vram_mutex
);
649 int radeon_mmap(struct file
*filp
, struct vm_area_struct
*vma
)
651 struct drm_file
*file_priv
;
652 struct radeon_device
*rdev
;
655 if (unlikely(vma
->vm_pgoff
< DRM_FILE_PAGE_OFFSET
)) {
656 return drm_mmap(filp
, vma
);
659 file_priv
= filp
->private_data
;
660 rdev
= file_priv
->minor
->dev
->dev_private
;
664 r
= ttm_bo_mmap(filp
, vma
, &rdev
->mman
.bdev
);
665 if (unlikely(r
!= 0)) {
668 if (unlikely(ttm_vm_ops
== NULL
)) {
669 ttm_vm_ops
= vma
->vm_ops
;
670 radeon_ttm_vm_ops
= *ttm_vm_ops
;
671 radeon_ttm_vm_ops
.fault
= &radeon_ttm_fault
;
673 vma
->vm_ops
= &radeon_ttm_vm_ops
;
679 * TTM backend functions.
681 struct radeon_ttm_backend
{
682 struct ttm_backend backend
;
683 struct radeon_device
*rdev
;
684 unsigned long num_pages
;
686 struct page
*dummy_read_page
;
687 dma_addr_t
*dma_addrs
;
693 static int radeon_ttm_backend_populate(struct ttm_backend
*backend
,
694 unsigned long num_pages
,
696 struct page
*dummy_read_page
,
697 dma_addr_t
*dma_addrs
)
699 struct radeon_ttm_backend
*gtt
;
701 gtt
= container_of(backend
, struct radeon_ttm_backend
, backend
);
703 gtt
->dma_addrs
= dma_addrs
;
704 gtt
->num_pages
= num_pages
;
705 gtt
->dummy_read_page
= dummy_read_page
;
706 gtt
->populated
= true;
710 static void radeon_ttm_backend_clear(struct ttm_backend
*backend
)
712 struct radeon_ttm_backend
*gtt
;
714 gtt
= container_of(backend
, struct radeon_ttm_backend
, backend
);
716 gtt
->dma_addrs
= NULL
;
718 gtt
->dummy_read_page
= NULL
;
719 gtt
->populated
= false;
724 static int radeon_ttm_backend_bind(struct ttm_backend
*backend
,
725 struct ttm_mem_reg
*bo_mem
)
727 struct radeon_ttm_backend
*gtt
;
730 gtt
= container_of(backend
, struct radeon_ttm_backend
, backend
);
731 gtt
->offset
= bo_mem
->start
<< PAGE_SHIFT
;
732 if (!gtt
->num_pages
) {
733 WARN(1, "nothing to bind %lu pages for mreg %p back %p!\n",
734 gtt
->num_pages
, bo_mem
, backend
);
736 r
= radeon_gart_bind(gtt
->rdev
, gtt
->offset
,
737 gtt
->num_pages
, gtt
->pages
, gtt
->dma_addrs
);
739 DRM_ERROR("failed to bind %lu pages at 0x%08X\n",
740 gtt
->num_pages
, gtt
->offset
);
747 static int radeon_ttm_backend_unbind(struct ttm_backend
*backend
)
749 struct radeon_ttm_backend
*gtt
;
751 gtt
= container_of(backend
, struct radeon_ttm_backend
, backend
);
752 radeon_gart_unbind(gtt
->rdev
, gtt
->offset
, gtt
->num_pages
);
757 static void radeon_ttm_backend_destroy(struct ttm_backend
*backend
)
759 struct radeon_ttm_backend
*gtt
;
761 gtt
= container_of(backend
, struct radeon_ttm_backend
, backend
);
763 radeon_ttm_backend_unbind(backend
);
768 static struct ttm_backend_func radeon_backend_func
= {
769 .populate
= &radeon_ttm_backend_populate
,
770 .clear
= &radeon_ttm_backend_clear
,
771 .bind
= &radeon_ttm_backend_bind
,
772 .unbind
= &radeon_ttm_backend_unbind
,
773 .destroy
= &radeon_ttm_backend_destroy
,
776 struct ttm_backend
*radeon_ttm_backend_create(struct radeon_device
*rdev
)
778 struct radeon_ttm_backend
*gtt
;
780 gtt
= kzalloc(sizeof(struct radeon_ttm_backend
), GFP_KERNEL
);
784 gtt
->backend
.bdev
= &rdev
->mman
.bdev
;
785 gtt
->backend
.flags
= 0;
786 gtt
->backend
.func
= &radeon_backend_func
;
790 gtt
->dummy_read_page
= NULL
;
791 gtt
->populated
= false;
793 return >t
->backend
;
796 #define RADEON_DEBUGFS_MEM_TYPES 2
798 #if defined(CONFIG_DEBUG_FS)
799 static int radeon_mm_dump_table(struct seq_file
*m
, void *data
)
801 struct drm_info_node
*node
= (struct drm_info_node
*)m
->private;
802 struct drm_mm
*mm
= (struct drm_mm
*)node
->info_ent
->data
;
803 struct drm_device
*dev
= node
->minor
->dev
;
804 struct radeon_device
*rdev
= dev
->dev_private
;
806 struct ttm_bo_global
*glob
= rdev
->mman
.bdev
.glob
;
808 spin_lock(&glob
->lru_lock
);
809 ret
= drm_mm_dump_table(m
, mm
);
810 spin_unlock(&glob
->lru_lock
);
815 static int radeon_ttm_debugfs_init(struct radeon_device
*rdev
)
817 #if defined(CONFIG_DEBUG_FS)
818 static struct drm_info_list radeon_mem_types_list
[RADEON_DEBUGFS_MEM_TYPES
+1];
819 static char radeon_mem_types_names
[RADEON_DEBUGFS_MEM_TYPES
+1][32];
822 for (i
= 0; i
< RADEON_DEBUGFS_MEM_TYPES
; i
++) {
824 sprintf(radeon_mem_types_names
[i
], "radeon_vram_mm");
826 sprintf(radeon_mem_types_names
[i
], "radeon_gtt_mm");
827 radeon_mem_types_list
[i
].name
= radeon_mem_types_names
[i
];
828 radeon_mem_types_list
[i
].show
= &radeon_mm_dump_table
;
829 radeon_mem_types_list
[i
].driver_features
= 0;
831 radeon_mem_types_list
[i
].data
= rdev
->mman
.bdev
.man
[TTM_PL_VRAM
].priv
;
833 radeon_mem_types_list
[i
].data
= rdev
->mman
.bdev
.man
[TTM_PL_TT
].priv
;
836 /* Add ttm page pool to debugfs */
837 sprintf(radeon_mem_types_names
[i
], "ttm_page_pool");
838 radeon_mem_types_list
[i
].name
= radeon_mem_types_names
[i
];
839 radeon_mem_types_list
[i
].show
= &ttm_page_alloc_debugfs
;
840 radeon_mem_types_list
[i
].driver_features
= 0;
841 radeon_mem_types_list
[i
].data
= NULL
;
842 return radeon_debugfs_add_files(rdev
, radeon_mem_types_list
, RADEON_DEBUGFS_MEM_TYPES
+1);