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
29 * Thomas Hellstrom <thomas-at-tungstengraphics-dot-com>
32 #include <linux/list.h>
33 #include <linux/slab.h>
34 #include <linux/dma-buf.h>
36 #include <drm/amdgpu_drm.h>
37 #include <drm/drm_cache.h>
39 #include "amdgpu_trace.h"
40 #include "amdgpu_amdkfd.h"
45 * This defines the interfaces to operate on an &amdgpu_bo buffer object which
46 * represents memory used by driver (VRAM, system memory, etc.). The driver
47 * provides DRM/GEM APIs to userspace. DRM/GEM APIs then use these interfaces
48 * to create/destroy/set buffer object which are then managed by the kernel TTM
50 * The interfaces are also used internally by kernel clients, including gfx,
51 * uvd, etc. for kernel managed allocations used by the GPU.
56 * amdgpu_bo_subtract_pin_size - Remove BO from pin_size accounting
58 * @bo: &amdgpu_bo buffer object
60 * This function is called when a BO stops being pinned, and updates the
61 * &amdgpu_device pin_size values accordingly.
63 static void amdgpu_bo_subtract_pin_size(struct amdgpu_bo *bo)
65 struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
67 if (bo->tbo.mem.mem_type == TTM_PL_VRAM) {
68 atomic64_sub(amdgpu_bo_size(bo), &adev->vram_pin_size);
69 atomic64_sub(amdgpu_vram_mgr_bo_visible_size(bo),
70 &adev->visible_pin_size);
71 } else if (bo->tbo.mem.mem_type == TTM_PL_TT) {
72 atomic64_sub(amdgpu_bo_size(bo), &adev->gart_pin_size);
76 static void amdgpu_bo_destroy(struct ttm_buffer_object *tbo)
78 struct amdgpu_device *adev = amdgpu_ttm_adev(tbo->bdev);
79 struct amdgpu_bo *bo = ttm_to_amdgpu_bo(tbo);
80 struct amdgpu_bo_user *ubo;
82 if (bo->tbo.pin_count > 0)
83 amdgpu_bo_subtract_pin_size(bo);
87 if (bo->tbo.base.import_attach)
88 drm_prime_gem_destroy(&bo->tbo.base, bo->tbo.sg);
89 drm_gem_object_release(&bo->tbo.base);
90 /* in case amdgpu_device_recover_vram got NULL of bo->parent */
91 if (!list_empty(&bo->shadow_list)) {
92 mutex_lock(&adev->shadow_list_lock);
93 list_del_init(&bo->shadow_list);
94 mutex_unlock(&adev->shadow_list_lock);
96 amdgpu_bo_unref(&bo->parent);
98 if (bo->tbo.type == ttm_bo_type_device) {
99 ubo = to_amdgpu_bo_user(bo);
100 kfree(ubo->metadata);
107 * amdgpu_bo_is_amdgpu_bo - check if the buffer object is an &amdgpu_bo
108 * @bo: buffer object to be checked
110 * Uses destroy function associated with the object to determine if this is
114 * true if the object belongs to &amdgpu_bo, false if not.
116 bool amdgpu_bo_is_amdgpu_bo(struct ttm_buffer_object *bo)
118 if (bo->destroy == &amdgpu_bo_destroy)
124 * amdgpu_bo_placement_from_domain - set buffer's placement
125 * @abo: &amdgpu_bo buffer object whose placement is to be set
126 * @domain: requested domain
128 * Sets buffer's placement according to requested domain and the buffer's
131 void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain)
133 struct amdgpu_device *adev = amdgpu_ttm_adev(abo->tbo.bdev);
134 struct ttm_placement *placement = &abo->placement;
135 struct ttm_place *places = abo->placements;
136 u64 flags = abo->flags;
139 if (domain & AMDGPU_GEM_DOMAIN_VRAM) {
140 unsigned visible_pfn = adev->gmc.visible_vram_size >> PAGE_SHIFT;
144 places[c].mem_type = TTM_PL_VRAM;
147 if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED)
148 places[c].lpfn = visible_pfn;
150 places[c].flags |= TTM_PL_FLAG_TOPDOWN;
152 if (flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS)
153 places[c].flags |= TTM_PL_FLAG_CONTIGUOUS;
157 if (domain & AMDGPU_GEM_DOMAIN_GTT) {
160 places[c].mem_type = TTM_PL_TT;
165 if (domain & AMDGPU_GEM_DOMAIN_CPU) {
168 places[c].mem_type = TTM_PL_SYSTEM;
173 if (domain & AMDGPU_GEM_DOMAIN_GDS) {
176 places[c].mem_type = AMDGPU_PL_GDS;
181 if (domain & AMDGPU_GEM_DOMAIN_GWS) {
184 places[c].mem_type = AMDGPU_PL_GWS;
189 if (domain & AMDGPU_GEM_DOMAIN_OA) {
192 places[c].mem_type = AMDGPU_PL_OA;
200 places[c].mem_type = TTM_PL_SYSTEM;
205 BUG_ON(c >= AMDGPU_BO_MAX_PLACEMENTS);
207 placement->num_placement = c;
208 placement->placement = places;
210 placement->num_busy_placement = c;
211 placement->busy_placement = places;
215 * amdgpu_bo_create_reserved - create reserved BO for kernel use
217 * @adev: amdgpu device object
218 * @size: size for the new BO
219 * @align: alignment for the new BO
220 * @domain: where to place it
221 * @bo_ptr: used to initialize BOs in structures
222 * @gpu_addr: GPU addr of the pinned BO
223 * @cpu_addr: optional CPU address mapping
225 * Allocates and pins a BO for kernel internal use, and returns it still
228 * Note: For bo_ptr new BO is only created if bo_ptr points to NULL.
231 * 0 on success, negative error code otherwise.
233 int amdgpu_bo_create_reserved(struct amdgpu_device *adev,
234 unsigned long size, int align,
235 u32 domain, struct amdgpu_bo **bo_ptr,
236 u64 *gpu_addr, void **cpu_addr)
238 struct amdgpu_bo_param bp;
243 amdgpu_bo_unref(bo_ptr);
247 memset(&bp, 0, sizeof(bp));
249 bp.byte_align = align;
251 bp.flags = cpu_addr ? AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED
252 : AMDGPU_GEM_CREATE_NO_CPU_ACCESS;
253 bp.flags |= AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS;
254 bp.type = ttm_bo_type_kernel;
256 bp.bo_ptr_size = sizeof(struct amdgpu_bo);
259 r = amdgpu_bo_create(adev, &bp, bo_ptr);
261 dev_err(adev->dev, "(%d) failed to allocate kernel bo\n",
268 r = amdgpu_bo_reserve(*bo_ptr, false);
270 dev_err(adev->dev, "(%d) failed to reserve kernel bo\n", r);
274 r = amdgpu_bo_pin(*bo_ptr, domain);
276 dev_err(adev->dev, "(%d) kernel bo pin failed\n", r);
277 goto error_unreserve;
280 r = amdgpu_ttm_alloc_gart(&(*bo_ptr)->tbo);
282 dev_err(adev->dev, "%p bind failed\n", *bo_ptr);
287 *gpu_addr = amdgpu_bo_gpu_offset(*bo_ptr);
290 r = amdgpu_bo_kmap(*bo_ptr, cpu_addr);
292 dev_err(adev->dev, "(%d) kernel bo map failed\n", r);
300 amdgpu_bo_unpin(*bo_ptr);
302 amdgpu_bo_unreserve(*bo_ptr);
306 amdgpu_bo_unref(bo_ptr);
312 * amdgpu_bo_create_kernel - create BO for kernel use
314 * @adev: amdgpu device object
315 * @size: size for the new BO
316 * @align: alignment for the new BO
317 * @domain: where to place it
318 * @bo_ptr: used to initialize BOs in structures
319 * @gpu_addr: GPU addr of the pinned BO
320 * @cpu_addr: optional CPU address mapping
322 * Allocates and pins a BO for kernel internal use.
324 * Note: For bo_ptr new BO is only created if bo_ptr points to NULL.
327 * 0 on success, negative error code otherwise.
329 int amdgpu_bo_create_kernel(struct amdgpu_device *adev,
330 unsigned long size, int align,
331 u32 domain, struct amdgpu_bo **bo_ptr,
332 u64 *gpu_addr, void **cpu_addr)
336 r = amdgpu_bo_create_reserved(adev, size, align, domain, bo_ptr,
343 amdgpu_bo_unreserve(*bo_ptr);
349 * amdgpu_bo_create_kernel_at - create BO for kernel use at specific location
351 * @adev: amdgpu device object
352 * @offset: offset of the BO
353 * @size: size of the BO
354 * @domain: where to place it
355 * @bo_ptr: used to initialize BOs in structures
356 * @cpu_addr: optional CPU address mapping
358 * Creates a kernel BO at a specific offset in the address space of the domain.
361 * 0 on success, negative error code otherwise.
363 int amdgpu_bo_create_kernel_at(struct amdgpu_device *adev,
364 uint64_t offset, uint64_t size, uint32_t domain,
365 struct amdgpu_bo **bo_ptr, void **cpu_addr)
367 struct ttm_operation_ctx ctx = { false, false };
372 size = ALIGN(size, PAGE_SIZE);
374 r = amdgpu_bo_create_reserved(adev, size, PAGE_SIZE, domain, bo_ptr,
379 if ((*bo_ptr) == NULL)
383 * Remove the original mem node and create a new one at the request
387 amdgpu_bo_kunmap(*bo_ptr);
389 ttm_resource_free(&(*bo_ptr)->tbo, &(*bo_ptr)->tbo.mem);
391 for (i = 0; i < (*bo_ptr)->placement.num_placement; ++i) {
392 (*bo_ptr)->placements[i].fpfn = offset >> PAGE_SHIFT;
393 (*bo_ptr)->placements[i].lpfn = (offset + size) >> PAGE_SHIFT;
395 r = ttm_bo_mem_space(&(*bo_ptr)->tbo, &(*bo_ptr)->placement,
396 &(*bo_ptr)->tbo.mem, &ctx);
401 r = amdgpu_bo_kmap(*bo_ptr, cpu_addr);
406 amdgpu_bo_unreserve(*bo_ptr);
410 amdgpu_bo_unreserve(*bo_ptr);
411 amdgpu_bo_unref(bo_ptr);
416 * amdgpu_bo_free_kernel - free BO for kernel use
418 * @bo: amdgpu BO to free
419 * @gpu_addr: pointer to where the BO's GPU memory space address was stored
420 * @cpu_addr: pointer to where the BO's CPU memory space address was stored
422 * unmaps and unpin a BO for kernel internal use.
424 void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr,
430 if (likely(amdgpu_bo_reserve(*bo, true) == 0)) {
432 amdgpu_bo_kunmap(*bo);
434 amdgpu_bo_unpin(*bo);
435 amdgpu_bo_unreserve(*bo);
446 /* Validate bo size is bit bigger then the request domain */
447 static bool amdgpu_bo_validate_size(struct amdgpu_device *adev,
448 unsigned long size, u32 domain)
450 struct ttm_resource_manager *man = NULL;
453 * If GTT is part of requested domains the check must succeed to
454 * allow fall back to GTT
456 if (domain & AMDGPU_GEM_DOMAIN_GTT) {
457 man = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT);
459 if (size < (man->size << PAGE_SHIFT))
465 if (domain & AMDGPU_GEM_DOMAIN_VRAM) {
466 man = ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM);
468 if (size < (man->size << PAGE_SHIFT))
475 /* TODO add more domains checks, such as AMDGPU_GEM_DOMAIN_CPU */
479 DRM_DEBUG("BO size %lu > total memory in domain: %llu\n", size,
480 man->size << PAGE_SHIFT);
484 bool amdgpu_bo_support_uswc(u64 bo_flags)
488 /* XXX: Write-combined CPU mappings of GTT seem broken on 32-bit
489 * See https://bugs.freedesktop.org/show_bug.cgi?id=84627
492 #elif defined(CONFIG_X86) && !defined(CONFIG_X86_PAT)
493 /* Don't try to enable write-combining when it can't work, or things
495 * See https://bugs.freedesktop.org/show_bug.cgi?id=88758
498 #ifndef CONFIG_COMPILE_TEST
499 #warning Please enable CONFIG_MTRR and CONFIG_X86_PAT for better performance \
500 thanks to write-combining
503 if (bo_flags & AMDGPU_GEM_CREATE_CPU_GTT_USWC)
504 DRM_INFO_ONCE("Please enable CONFIG_MTRR and CONFIG_X86_PAT for "
505 "better performance thanks to write-combining\n");
508 /* For architectures that don't support WC memory,
509 * mask out the WC flag from the BO
511 if (!drm_arch_can_wc_memory())
518 static int amdgpu_bo_do_create(struct amdgpu_device *adev,
519 struct amdgpu_bo_param *bp,
520 struct amdgpu_bo **bo_ptr)
522 struct ttm_operation_ctx ctx = {
523 .interruptible = (bp->type != ttm_bo_type_kernel),
524 .no_wait_gpu = bp->no_wait_gpu,
525 /* We opt to avoid OOM on system pages allocations */
526 .gfp_retry_mayfail = true,
527 .allow_res_evict = bp->type != ttm_bo_type_kernel,
530 struct amdgpu_bo *bo;
531 unsigned long page_align, size = bp->size;
534 /* Note that GDS/GWS/OA allocates 1 page per byte/resource. */
535 if (bp->domain & (AMDGPU_GEM_DOMAIN_GWS | AMDGPU_GEM_DOMAIN_OA)) {
536 /* GWS and OA don't need any alignment. */
537 page_align = bp->byte_align;
539 } else if (bp->domain & AMDGPU_GEM_DOMAIN_GDS) {
540 /* Both size and alignment must be a multiple of 4. */
541 page_align = ALIGN(bp->byte_align, 4);
542 size = ALIGN(size, 4) << PAGE_SHIFT;
544 /* Memory should be aligned at least to a page size. */
545 page_align = ALIGN(bp->byte_align, PAGE_SIZE) >> PAGE_SHIFT;
546 size = ALIGN(size, PAGE_SIZE);
549 if (!amdgpu_bo_validate_size(adev, size, bp->domain))
552 BUG_ON(bp->bo_ptr_size < sizeof(struct amdgpu_bo));
555 bo = kzalloc(bp->bo_ptr_size, GFP_KERNEL);
558 drm_gem_private_object_init(adev_to_drm(adev), &bo->tbo.base, size);
559 INIT_LIST_HEAD(&bo->shadow_list);
561 bo->preferred_domains = bp->preferred_domain ? bp->preferred_domain :
563 bo->allowed_domains = bo->preferred_domains;
564 if (bp->type != ttm_bo_type_kernel &&
565 bo->allowed_domains == AMDGPU_GEM_DOMAIN_VRAM)
566 bo->allowed_domains |= AMDGPU_GEM_DOMAIN_GTT;
568 bo->flags = bp->flags;
570 if (!amdgpu_bo_support_uswc(bo->flags))
571 bo->flags &= ~AMDGPU_GEM_CREATE_CPU_GTT_USWC;
573 bo->tbo.bdev = &adev->mman.bdev;
574 if (bp->domain & (AMDGPU_GEM_DOMAIN_GWS | AMDGPU_GEM_DOMAIN_OA |
575 AMDGPU_GEM_DOMAIN_GDS))
576 amdgpu_bo_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_CPU);
578 amdgpu_bo_placement_from_domain(bo, bp->domain);
579 if (bp->type == ttm_bo_type_kernel)
580 bo->tbo.priority = 1;
582 r = ttm_bo_init_reserved(&adev->mman.bdev, &bo->tbo, size, bp->type,
583 &bo->placement, page_align, &ctx, NULL,
584 bp->resv, &amdgpu_bo_destroy);
585 if (unlikely(r != 0))
588 if (!amdgpu_gmc_vram_full_visible(&adev->gmc) &&
589 bo->tbo.mem.mem_type == TTM_PL_VRAM &&
590 bo->tbo.mem.start < adev->gmc.visible_vram_size >> PAGE_SHIFT)
591 amdgpu_cs_report_moved_bytes(adev, ctx.bytes_moved,
594 amdgpu_cs_report_moved_bytes(adev, ctx.bytes_moved, 0);
596 if (bp->flags & AMDGPU_GEM_CREATE_VRAM_CLEARED &&
597 bo->tbo.mem.mem_type == TTM_PL_VRAM) {
598 struct dma_fence *fence;
600 r = amdgpu_fill_buffer(bo, 0, bo->tbo.base.resv, &fence);
604 amdgpu_bo_fence(bo, fence, false);
605 dma_fence_put(bo->tbo.moving);
606 bo->tbo.moving = dma_fence_get(fence);
607 dma_fence_put(fence);
610 amdgpu_bo_unreserve(bo);
613 trace_amdgpu_bo_create(bo);
615 /* Treat CPU_ACCESS_REQUIRED only as a hint if given by UMD */
616 if (bp->type == ttm_bo_type_device)
617 bo->flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
623 dma_resv_unlock(bo->tbo.base.resv);
624 amdgpu_bo_unref(&bo);
628 static int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
630 struct amdgpu_bo *bo)
632 struct amdgpu_bo_param bp;
638 memset(&bp, 0, sizeof(bp));
640 bp.domain = AMDGPU_GEM_DOMAIN_GTT;
641 bp.flags = AMDGPU_GEM_CREATE_CPU_GTT_USWC |
642 AMDGPU_GEM_CREATE_SHADOW;
643 bp.type = ttm_bo_type_kernel;
644 bp.resv = bo->tbo.base.resv;
645 bp.bo_ptr_size = sizeof(struct amdgpu_bo);
647 r = amdgpu_bo_do_create(adev, &bp, &bo->shadow);
649 bo->shadow->parent = amdgpu_bo_ref(bo);
650 mutex_lock(&adev->shadow_list_lock);
651 list_add_tail(&bo->shadow->shadow_list, &adev->shadow_list);
652 mutex_unlock(&adev->shadow_list_lock);
659 * amdgpu_bo_create - create an &amdgpu_bo buffer object
660 * @adev: amdgpu device object
661 * @bp: parameters to be used for the buffer object
662 * @bo_ptr: pointer to the buffer object pointer
664 * Creates an &amdgpu_bo buffer object; and if requested, also creates a
666 * Shadow object is used to backup the original buffer object, and is always
670 * 0 for success or a negative error code on failure.
672 int amdgpu_bo_create(struct amdgpu_device *adev,
673 struct amdgpu_bo_param *bp,
674 struct amdgpu_bo **bo_ptr)
676 u64 flags = bp->flags;
679 bp->flags = bp->flags & ~AMDGPU_GEM_CREATE_SHADOW;
681 r = amdgpu_bo_do_create(adev, bp, bo_ptr);
685 if ((flags & AMDGPU_GEM_CREATE_SHADOW) && !(adev->flags & AMD_IS_APU)) {
687 WARN_ON(dma_resv_lock((*bo_ptr)->tbo.base.resv,
690 r = amdgpu_bo_create_shadow(adev, bp->size, *bo_ptr);
693 dma_resv_unlock((*bo_ptr)->tbo.base.resv);
696 amdgpu_bo_unref(bo_ptr);
703 * amdgpu_bo_create_user - create an &amdgpu_bo_user buffer object
704 * @adev: amdgpu device object
705 * @bp: parameters to be used for the buffer object
706 * @ubo_ptr: pointer to the buffer object pointer
708 * Create a BO to be used by user application;
711 * 0 for success or a negative error code on failure.
714 int amdgpu_bo_create_user(struct amdgpu_device *adev,
715 struct amdgpu_bo_param *bp,
716 struct amdgpu_bo_user **ubo_ptr)
718 struct amdgpu_bo *bo_ptr;
721 bp->flags = bp->flags & ~AMDGPU_GEM_CREATE_SHADOW;
722 bp->bo_ptr_size = sizeof(struct amdgpu_bo_user);
723 r = amdgpu_bo_do_create(adev, bp, &bo_ptr);
727 *ubo_ptr = to_amdgpu_bo_user(bo_ptr);
731 * amdgpu_bo_validate - validate an &amdgpu_bo buffer object
732 * @bo: pointer to the buffer object
734 * Sets placement according to domain; and changes placement and caching
735 * policy of the buffer object according to the placement.
736 * This is used for validating shadow bos. It calls ttm_bo_validate() to
737 * make sure the buffer is resident where it needs to be.
740 * 0 for success or a negative error code on failure.
742 int amdgpu_bo_validate(struct amdgpu_bo *bo)
744 struct ttm_operation_ctx ctx = { false, false };
748 if (bo->tbo.pin_count)
751 domain = bo->preferred_domains;
754 amdgpu_bo_placement_from_domain(bo, domain);
755 r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
756 if (unlikely(r == -ENOMEM) && domain != bo->allowed_domains) {
757 domain = bo->allowed_domains;
765 * amdgpu_bo_restore_shadow - restore an &amdgpu_bo shadow
767 * @shadow: &amdgpu_bo shadow to be restored
768 * @fence: dma_fence associated with the operation
770 * Copies a buffer object's shadow content back to the object.
771 * This is used for recovering a buffer from its shadow in case of a gpu
772 * reset where vram context may be lost.
775 * 0 for success or a negative error code on failure.
777 int amdgpu_bo_restore_shadow(struct amdgpu_bo *shadow, struct dma_fence **fence)
780 struct amdgpu_device *adev = amdgpu_ttm_adev(shadow->tbo.bdev);
781 struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring;
782 uint64_t shadow_addr, parent_addr;
784 shadow_addr = amdgpu_bo_gpu_offset(shadow);
785 parent_addr = amdgpu_bo_gpu_offset(shadow->parent);
787 return amdgpu_copy_buffer(ring, shadow_addr, parent_addr,
788 amdgpu_bo_size(shadow), NULL, fence,
793 * amdgpu_bo_kmap - map an &amdgpu_bo buffer object
794 * @bo: &amdgpu_bo buffer object to be mapped
795 * @ptr: kernel virtual address to be returned
797 * Calls ttm_bo_kmap() to set up the kernel virtual mapping; calls
798 * amdgpu_bo_kptr() to get the kernel virtual address.
801 * 0 for success or a negative error code on failure.
803 int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr)
808 if (bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS)
811 kptr = amdgpu_bo_kptr(bo);
818 r = dma_resv_wait_timeout_rcu(bo->tbo.base.resv, false, false,
819 MAX_SCHEDULE_TIMEOUT);
823 r = ttm_bo_kmap(&bo->tbo, 0, bo->tbo.mem.num_pages, &bo->kmap);
828 *ptr = amdgpu_bo_kptr(bo);
834 * amdgpu_bo_kptr - returns a kernel virtual address of the buffer object
835 * @bo: &amdgpu_bo buffer object
837 * Calls ttm_kmap_obj_virtual() to get the kernel virtual address
840 * the virtual address of a buffer object area.
842 void *amdgpu_bo_kptr(struct amdgpu_bo *bo)
846 return ttm_kmap_obj_virtual(&bo->kmap, &is_iomem);
850 * amdgpu_bo_kunmap - unmap an &amdgpu_bo buffer object
851 * @bo: &amdgpu_bo buffer object to be unmapped
853 * Unmaps a kernel map set up by amdgpu_bo_kmap().
855 void amdgpu_bo_kunmap(struct amdgpu_bo *bo)
858 ttm_bo_kunmap(&bo->kmap);
862 * amdgpu_bo_ref - reference an &amdgpu_bo buffer object
863 * @bo: &amdgpu_bo buffer object
865 * References the contained &ttm_buffer_object.
868 * a refcounted pointer to the &amdgpu_bo buffer object.
870 struct amdgpu_bo *amdgpu_bo_ref(struct amdgpu_bo *bo)
875 ttm_bo_get(&bo->tbo);
880 * amdgpu_bo_unref - unreference an &amdgpu_bo buffer object
881 * @bo: &amdgpu_bo buffer object
883 * Unreferences the contained &ttm_buffer_object and clear the pointer
885 void amdgpu_bo_unref(struct amdgpu_bo **bo)
887 struct ttm_buffer_object *tbo;
898 * amdgpu_bo_pin_restricted - pin an &amdgpu_bo buffer object
899 * @bo: &amdgpu_bo buffer object to be pinned
900 * @domain: domain to be pinned to
901 * @min_offset: the start of requested address range
902 * @max_offset: the end of requested address range
904 * Pins the buffer object according to requested domain and address range. If
905 * the memory is unbound gart memory, binds the pages into gart table. Adjusts
906 * pin_count and pin_size accordingly.
908 * Pinning means to lock pages in memory along with keeping them at a fixed
909 * offset. It is required when a buffer can not be moved, for example, when
910 * a display buffer is being scanned out.
912 * Compared with amdgpu_bo_pin(), this function gives more flexibility on
913 * where to pin a buffer if there are specific restrictions on where a buffer
917 * 0 for success or a negative error code on failure.
919 int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,
920 u64 min_offset, u64 max_offset)
922 struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
923 struct ttm_operation_ctx ctx = { false, false };
926 if (amdgpu_ttm_tt_get_usermm(bo->tbo.ttm))
929 if (WARN_ON_ONCE(min_offset > max_offset))
932 /* A shared bo cannot be migrated to VRAM */
933 if (bo->prime_shared_count || bo->tbo.base.import_attach) {
934 if (domain & AMDGPU_GEM_DOMAIN_GTT)
935 domain = AMDGPU_GEM_DOMAIN_GTT;
940 /* This assumes only APU display buffers are pinned with (VRAM|GTT).
941 * See function amdgpu_display_supported_domains()
943 domain = amdgpu_bo_get_preferred_pin_domain(adev, domain);
945 if (bo->tbo.pin_count) {
946 uint32_t mem_type = bo->tbo.mem.mem_type;
947 uint32_t mem_flags = bo->tbo.mem.placement;
949 if (!(domain & amdgpu_mem_type_to_domain(mem_type)))
952 if ((mem_type == TTM_PL_VRAM) &&
953 (bo->flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS) &&
954 !(mem_flags & TTM_PL_FLAG_CONTIGUOUS))
957 ttm_bo_pin(&bo->tbo);
959 if (max_offset != 0) {
960 u64 domain_start = amdgpu_ttm_domain_start(adev,
962 WARN_ON_ONCE(max_offset <
963 (amdgpu_bo_gpu_offset(bo) - domain_start));
969 if (bo->tbo.base.import_attach)
970 dma_buf_pin(bo->tbo.base.import_attach);
972 /* force to pin into visible video ram */
973 if (!(bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS))
974 bo->flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
975 amdgpu_bo_placement_from_domain(bo, domain);
976 for (i = 0; i < bo->placement.num_placement; i++) {
979 fpfn = min_offset >> PAGE_SHIFT;
980 lpfn = max_offset >> PAGE_SHIFT;
982 if (fpfn > bo->placements[i].fpfn)
983 bo->placements[i].fpfn = fpfn;
984 if (!bo->placements[i].lpfn ||
985 (lpfn && lpfn < bo->placements[i].lpfn))
986 bo->placements[i].lpfn = lpfn;
989 r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
991 dev_err(adev->dev, "%p pin failed\n", bo);
995 ttm_bo_pin(&bo->tbo);
997 domain = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type);
998 if (domain == AMDGPU_GEM_DOMAIN_VRAM) {
999 atomic64_add(amdgpu_bo_size(bo), &adev->vram_pin_size);
1000 atomic64_add(amdgpu_vram_mgr_bo_visible_size(bo),
1001 &adev->visible_pin_size);
1002 } else if (domain == AMDGPU_GEM_DOMAIN_GTT) {
1003 atomic64_add(amdgpu_bo_size(bo), &adev->gart_pin_size);
1011 * amdgpu_bo_pin - pin an &amdgpu_bo buffer object
1012 * @bo: &amdgpu_bo buffer object to be pinned
1013 * @domain: domain to be pinned to
1015 * A simple wrapper to amdgpu_bo_pin_restricted().
1016 * Provides a simpler API for buffers that do not have any strict restrictions
1017 * on where a buffer must be located.
1020 * 0 for success or a negative error code on failure.
1022 int amdgpu_bo_pin(struct amdgpu_bo *bo, u32 domain)
1024 bo->flags |= AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS;
1025 return amdgpu_bo_pin_restricted(bo, domain, 0, 0);
1029 * amdgpu_bo_unpin - unpin an &amdgpu_bo buffer object
1030 * @bo: &amdgpu_bo buffer object to be unpinned
1032 * Decreases the pin_count, and clears the flags if pin_count reaches 0.
1033 * Changes placement and pin size accordingly.
1036 * 0 for success or a negative error code on failure.
1038 void amdgpu_bo_unpin(struct amdgpu_bo *bo)
1040 ttm_bo_unpin(&bo->tbo);
1041 if (bo->tbo.pin_count)
1044 amdgpu_bo_subtract_pin_size(bo);
1046 if (bo->tbo.base.import_attach)
1047 dma_buf_unpin(bo->tbo.base.import_attach);
1051 * amdgpu_bo_evict_vram - evict VRAM buffers
1052 * @adev: amdgpu device object
1054 * Evicts all VRAM buffers on the lru list of the memory type.
1055 * Mainly used for evicting vram at suspend time.
1058 * 0 for success or a negative error code on failure.
1060 int amdgpu_bo_evict_vram(struct amdgpu_device *adev)
1062 struct ttm_resource_manager *man;
1064 if (adev->in_s3 && (adev->flags & AMD_IS_APU)) {
1065 /* No need to evict vram on APUs for suspend to ram */
1069 man = ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM);
1070 return ttm_resource_manager_evict_all(&adev->mman.bdev, man);
1073 static const char *amdgpu_vram_names[] = {
1088 * amdgpu_bo_init - initialize memory manager
1089 * @adev: amdgpu device object
1091 * Calls amdgpu_ttm_init() to initialize amdgpu memory manager.
1094 * 0 for success or a negative error code on failure.
1096 int amdgpu_bo_init(struct amdgpu_device *adev)
1098 /* On A+A platform, VRAM can be mapped as WB */
1099 if (!adev->gmc.xgmi.connected_to_cpu) {
1100 /* reserve PAT memory space to WC for VRAM */
1101 arch_io_reserve_memtype_wc(adev->gmc.aper_base,
1102 adev->gmc.aper_size);
1104 /* Add an MTRR for the VRAM */
1105 adev->gmc.vram_mtrr = arch_phys_wc_add(adev->gmc.aper_base,
1106 adev->gmc.aper_size);
1109 DRM_INFO("Detected VRAM RAM=%lluM, BAR=%lluM\n",
1110 adev->gmc.mc_vram_size >> 20,
1111 (unsigned long long)adev->gmc.aper_size >> 20);
1112 DRM_INFO("RAM width %dbits %s\n",
1113 adev->gmc.vram_width, amdgpu_vram_names[adev->gmc.vram_type]);
1114 return amdgpu_ttm_init(adev);
1118 * amdgpu_bo_fini - tear down memory manager
1119 * @adev: amdgpu device object
1121 * Reverses amdgpu_bo_init() to tear down memory manager.
1123 void amdgpu_bo_fini(struct amdgpu_device *adev)
1125 amdgpu_ttm_fini(adev);
1126 if (!adev->gmc.xgmi.connected_to_cpu) {
1127 arch_phys_wc_del(adev->gmc.vram_mtrr);
1128 arch_io_free_memtype_wc(adev->gmc.aper_base, adev->gmc.aper_size);
1133 * amdgpu_bo_fbdev_mmap - mmap fbdev memory
1134 * @bo: &amdgpu_bo buffer object
1135 * @vma: vma as input from the fbdev mmap method
1137 * Calls ttm_fbdev_mmap() to mmap fbdev memory if it is backed by a bo.
1140 * 0 for success or a negative error code on failure.
1142 int amdgpu_bo_fbdev_mmap(struct amdgpu_bo *bo,
1143 struct vm_area_struct *vma)
1145 if (vma->vm_pgoff != 0)
1148 return ttm_bo_mmap_obj(vma, &bo->tbo);
1152 * amdgpu_bo_set_tiling_flags - set tiling flags
1153 * @bo: &amdgpu_bo buffer object
1154 * @tiling_flags: new flags
1156 * Sets buffer object's tiling flags with the new one. Used by GEM ioctl or
1157 * kernel driver to set the tiling flags on a buffer.
1160 * 0 for success or a negative error code on failure.
1162 int amdgpu_bo_set_tiling_flags(struct amdgpu_bo *bo, u64 tiling_flags)
1164 struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
1165 struct amdgpu_bo_user *ubo;
1167 BUG_ON(bo->tbo.type != ttm_bo_type_device);
1168 if (adev->family <= AMDGPU_FAMILY_CZ &&
1169 AMDGPU_TILING_GET(tiling_flags, TILE_SPLIT) > 6)
1172 ubo = to_amdgpu_bo_user(bo);
1173 ubo->tiling_flags = tiling_flags;
1178 * amdgpu_bo_get_tiling_flags - get tiling flags
1179 * @bo: &amdgpu_bo buffer object
1180 * @tiling_flags: returned flags
1182 * Gets buffer object's tiling flags. Used by GEM ioctl or kernel driver to
1183 * set the tiling flags on a buffer.
1185 void amdgpu_bo_get_tiling_flags(struct amdgpu_bo *bo, u64 *tiling_flags)
1187 struct amdgpu_bo_user *ubo;
1189 BUG_ON(bo->tbo.type != ttm_bo_type_device);
1190 dma_resv_assert_held(bo->tbo.base.resv);
1191 ubo = to_amdgpu_bo_user(bo);
1194 *tiling_flags = ubo->tiling_flags;
1198 * amdgpu_bo_set_metadata - set metadata
1199 * @bo: &amdgpu_bo buffer object
1200 * @metadata: new metadata
1201 * @metadata_size: size of the new metadata
1202 * @flags: flags of the new metadata
1204 * Sets buffer object's metadata, its size and flags.
1205 * Used via GEM ioctl.
1208 * 0 for success or a negative error code on failure.
1210 int amdgpu_bo_set_metadata (struct amdgpu_bo *bo, void *metadata,
1211 uint32_t metadata_size, uint64_t flags)
1213 struct amdgpu_bo_user *ubo;
1216 BUG_ON(bo->tbo.type != ttm_bo_type_device);
1217 ubo = to_amdgpu_bo_user(bo);
1218 if (!metadata_size) {
1219 if (ubo->metadata_size) {
1220 kfree(ubo->metadata);
1221 ubo->metadata = NULL;
1222 ubo->metadata_size = 0;
1227 if (metadata == NULL)
1230 buffer = kmemdup(metadata, metadata_size, GFP_KERNEL);
1234 kfree(ubo->metadata);
1235 ubo->metadata_flags = flags;
1236 ubo->metadata = buffer;
1237 ubo->metadata_size = metadata_size;
1243 * amdgpu_bo_get_metadata - get metadata
1244 * @bo: &amdgpu_bo buffer object
1245 * @buffer: returned metadata
1246 * @buffer_size: size of the buffer
1247 * @metadata_size: size of the returned metadata
1248 * @flags: flags of the returned metadata
1250 * Gets buffer object's metadata, its size and flags. buffer_size shall not be
1251 * less than metadata_size.
1252 * Used via GEM ioctl.
1255 * 0 for success or a negative error code on failure.
1257 int amdgpu_bo_get_metadata(struct amdgpu_bo *bo, void *buffer,
1258 size_t buffer_size, uint32_t *metadata_size,
1261 struct amdgpu_bo_user *ubo;
1263 if (!buffer && !metadata_size)
1266 BUG_ON(bo->tbo.type != ttm_bo_type_device);
1267 ubo = to_amdgpu_bo_user(bo);
1269 if (buffer_size < ubo->metadata_size)
1272 if (ubo->metadata_size)
1273 memcpy(buffer, ubo->metadata, ubo->metadata_size);
1277 *metadata_size = ubo->metadata_size;
1279 *flags = ubo->metadata_flags;
1285 * amdgpu_bo_move_notify - notification about a memory move
1286 * @bo: pointer to a buffer object
1287 * @evict: if this move is evicting the buffer from the graphics address space
1288 * @new_mem: new information of the bufer object
1290 * Marks the corresponding &amdgpu_bo buffer object as invalid, also performs
1292 * TTM driver callback which is called when ttm moves a buffer.
1294 void amdgpu_bo_move_notify(struct ttm_buffer_object *bo,
1296 struct ttm_resource *new_mem)
1298 struct amdgpu_device *adev = amdgpu_ttm_adev(bo->bdev);
1299 struct amdgpu_bo *abo;
1300 struct ttm_resource *old_mem = &bo->mem;
1302 if (!amdgpu_bo_is_amdgpu_bo(bo))
1305 abo = ttm_to_amdgpu_bo(bo);
1306 amdgpu_vm_bo_invalidate(adev, abo, evict);
1308 amdgpu_bo_kunmap(abo);
1310 if (abo->tbo.base.dma_buf && !abo->tbo.base.import_attach &&
1311 bo->mem.mem_type != TTM_PL_SYSTEM)
1312 dma_buf_move_notify(abo->tbo.base.dma_buf);
1314 /* remember the eviction */
1316 atomic64_inc(&adev->num_evictions);
1318 /* update statistics */
1322 /* move_notify is called before move happens */
1323 trace_amdgpu_bo_move(abo, new_mem->mem_type, old_mem->mem_type);
1327 * amdgpu_bo_release_notify - notification about a BO being released
1328 * @bo: pointer to a buffer object
1330 * Wipes VRAM buffers whose contents should not be leaked before the
1331 * memory is released.
1333 void amdgpu_bo_release_notify(struct ttm_buffer_object *bo)
1335 struct dma_fence *fence = NULL;
1336 struct amdgpu_bo *abo;
1339 if (!amdgpu_bo_is_amdgpu_bo(bo))
1342 abo = ttm_to_amdgpu_bo(bo);
1345 amdgpu_amdkfd_unreserve_memory_limit(abo);
1347 /* We only remove the fence if the resv has individualized. */
1348 WARN_ON_ONCE(bo->type == ttm_bo_type_kernel
1349 && bo->base.resv != &bo->base._resv);
1350 if (bo->base.resv == &bo->base._resv)
1351 amdgpu_amdkfd_remove_fence_on_pt_pd_bos(abo);
1353 if (bo->mem.mem_type != TTM_PL_VRAM || !bo->mem.mm_node ||
1354 !(abo->flags & AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE))
1357 dma_resv_lock(bo->base.resv, NULL);
1359 r = amdgpu_fill_buffer(abo, AMDGPU_POISON, bo->base.resv, &fence);
1361 amdgpu_bo_fence(abo, fence, false);
1362 dma_fence_put(fence);
1365 dma_resv_unlock(bo->base.resv);
1369 * amdgpu_bo_fault_reserve_notify - notification about a memory fault
1370 * @bo: pointer to a buffer object
1372 * Notifies the driver we are taking a fault on this BO and have reserved it,
1373 * also performs bookkeeping.
1374 * TTM driver callback for dealing with vm faults.
1377 * 0 for success or a negative error code on failure.
1379 vm_fault_t amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
1381 struct amdgpu_device *adev = amdgpu_ttm_adev(bo->bdev);
1382 struct ttm_operation_ctx ctx = { false, false };
1383 struct amdgpu_bo *abo = ttm_to_amdgpu_bo(bo);
1384 unsigned long offset, size;
1387 /* Remember that this BO was accessed by the CPU */
1388 abo->flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
1390 if (bo->mem.mem_type != TTM_PL_VRAM)
1393 size = bo->mem.num_pages << PAGE_SHIFT;
1394 offset = bo->mem.start << PAGE_SHIFT;
1395 if ((offset + size) <= adev->gmc.visible_vram_size)
1398 /* Can't move a pinned BO to visible VRAM */
1399 if (abo->tbo.pin_count > 0)
1400 return VM_FAULT_SIGBUS;
1402 /* hurrah the memory is not visible ! */
1403 atomic64_inc(&adev->num_vram_cpu_page_faults);
1404 amdgpu_bo_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_VRAM |
1405 AMDGPU_GEM_DOMAIN_GTT);
1407 /* Avoid costly evictions; only set GTT as a busy placement */
1408 abo->placement.num_busy_placement = 1;
1409 abo->placement.busy_placement = &abo->placements[1];
1411 r = ttm_bo_validate(bo, &abo->placement, &ctx);
1412 if (unlikely(r == -EBUSY || r == -ERESTARTSYS))
1413 return VM_FAULT_NOPAGE;
1414 else if (unlikely(r))
1415 return VM_FAULT_SIGBUS;
1417 offset = bo->mem.start << PAGE_SHIFT;
1418 /* this should never happen */
1419 if (bo->mem.mem_type == TTM_PL_VRAM &&
1420 (offset + size) > adev->gmc.visible_vram_size)
1421 return VM_FAULT_SIGBUS;
1423 ttm_bo_move_to_lru_tail_unlocked(bo);
1428 * amdgpu_bo_fence - add fence to buffer object
1430 * @bo: buffer object in question
1431 * @fence: fence to add
1432 * @shared: true if fence should be added shared
1435 void amdgpu_bo_fence(struct amdgpu_bo *bo, struct dma_fence *fence,
1438 struct dma_resv *resv = bo->tbo.base.resv;
1441 dma_resv_add_shared_fence(resv, fence);
1443 dma_resv_add_excl_fence(resv, fence);
1447 * amdgpu_bo_sync_wait_resv - Wait for BO reservation fences
1449 * @adev: amdgpu device pointer
1450 * @resv: reservation object to sync to
1451 * @sync_mode: synchronization mode
1452 * @owner: fence owner
1453 * @intr: Whether the wait is interruptible
1455 * Extract the fences from the reservation object and waits for them to finish.
1458 * 0 on success, errno otherwise.
1460 int amdgpu_bo_sync_wait_resv(struct amdgpu_device *adev, struct dma_resv *resv,
1461 enum amdgpu_sync_mode sync_mode, void *owner,
1464 struct amdgpu_sync sync;
1467 amdgpu_sync_create(&sync);
1468 amdgpu_sync_resv(adev, &sync, resv, sync_mode, owner);
1469 r = amdgpu_sync_wait(&sync, intr);
1470 amdgpu_sync_free(&sync);
1475 * amdgpu_bo_sync_wait - Wrapper for amdgpu_bo_sync_wait_resv
1476 * @bo: buffer object to wait for
1477 * @owner: fence owner
1478 * @intr: Whether the wait is interruptible
1480 * Wrapper to wait for fences in a BO.
1482 * 0 on success, errno otherwise.
1484 int amdgpu_bo_sync_wait(struct amdgpu_bo *bo, void *owner, bool intr)
1486 struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
1488 return amdgpu_bo_sync_wait_resv(adev, bo->tbo.base.resv,
1489 AMDGPU_SYNC_NE_OWNER, owner, intr);
1493 * amdgpu_bo_gpu_offset - return GPU offset of bo
1494 * @bo: amdgpu object for which we query the offset
1496 * Note: object should either be pinned or reserved when calling this
1497 * function, it might be useful to add check for this for debugging.
1500 * current GPU offset of the object.
1502 u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo)
1504 WARN_ON_ONCE(bo->tbo.mem.mem_type == TTM_PL_SYSTEM);
1505 WARN_ON_ONCE(!dma_resv_is_locked(bo->tbo.base.resv) &&
1506 !bo->tbo.pin_count && bo->tbo.type != ttm_bo_type_kernel);
1507 WARN_ON_ONCE(bo->tbo.mem.start == AMDGPU_BO_INVALID_OFFSET);
1508 WARN_ON_ONCE(bo->tbo.mem.mem_type == TTM_PL_VRAM &&
1509 !(bo->flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS));
1511 return amdgpu_bo_gpu_offset_no_check(bo);
1515 * amdgpu_bo_gpu_offset_no_check - return GPU offset of bo
1516 * @bo: amdgpu object for which we query the offset
1519 * current GPU offset of the object without raising warnings.
1521 u64 amdgpu_bo_gpu_offset_no_check(struct amdgpu_bo *bo)
1523 struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
1526 offset = (bo->tbo.mem.start << PAGE_SHIFT) +
1527 amdgpu_ttm_domain_start(adev, bo->tbo.mem.mem_type);
1529 return amdgpu_gmc_sign_extend(offset);
1533 * amdgpu_bo_get_preferred_pin_domain - get preferred domain for scanout
1534 * @adev: amdgpu device object
1535 * @domain: allowed :ref:`memory domains <amdgpu_memory_domains>`
1538 * Which of the allowed domains is preferred for pinning the BO for scanout.
1540 uint32_t amdgpu_bo_get_preferred_pin_domain(struct amdgpu_device *adev,
1543 if (domain == (AMDGPU_GEM_DOMAIN_VRAM | AMDGPU_GEM_DOMAIN_GTT)) {
1544 domain = AMDGPU_GEM_DOMAIN_VRAM;
1545 if (adev->gmc.real_vram_size <= AMDGPU_SG_THRESHOLD)
1546 domain = AMDGPU_GEM_DOMAIN_GTT;
1551 #if defined(CONFIG_DEBUG_FS)
1552 #define amdgpu_bo_print_flag(m, bo, flag) \
1554 if (bo->flags & (AMDGPU_GEM_CREATE_ ## flag)) { \
1555 seq_printf((m), " " #flag); \
1560 * amdgpu_bo_print_info - print BO info in debugfs file
1562 * @id: Index or Id of the BO
1563 * @bo: Requested BO for printing info
1566 * Print BO information in debugfs file
1569 * Size of the BO in bytes.
1571 u64 amdgpu_bo_print_info(int id, struct amdgpu_bo *bo, struct seq_file *m)
1573 struct dma_buf_attachment *attachment;
1574 struct dma_buf *dma_buf;
1575 unsigned int domain;
1576 const char *placement;
1577 unsigned int pin_count;
1580 domain = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type);
1582 case AMDGPU_GEM_DOMAIN_VRAM:
1585 case AMDGPU_GEM_DOMAIN_GTT:
1588 case AMDGPU_GEM_DOMAIN_CPU:
1594 size = amdgpu_bo_size(bo);
1595 seq_printf(m, "\t\t0x%08x: %12lld byte %s",
1596 id, size, placement);
1598 pin_count = READ_ONCE(bo->tbo.pin_count);
1600 seq_printf(m, " pin count %d", pin_count);
1602 dma_buf = READ_ONCE(bo->tbo.base.dma_buf);
1603 attachment = READ_ONCE(bo->tbo.base.import_attach);
1606 seq_printf(m, " imported from %p", dma_buf);
1608 seq_printf(m, " exported as %p", dma_buf);
1610 amdgpu_bo_print_flag(m, bo, CPU_ACCESS_REQUIRED);
1611 amdgpu_bo_print_flag(m, bo, NO_CPU_ACCESS);
1612 amdgpu_bo_print_flag(m, bo, CPU_GTT_USWC);
1613 amdgpu_bo_print_flag(m, bo, VRAM_CLEARED);
1614 amdgpu_bo_print_flag(m, bo, SHADOW);
1615 amdgpu_bo_print_flag(m, bo, VRAM_CONTIGUOUS);
1616 amdgpu_bo_print_flag(m, bo, VM_ALWAYS_VALID);
1617 amdgpu_bo_print_flag(m, bo, EXPLICIT_SYNC);