Home | History | Annotate | Line # | Download | only in radeon
      1  1.3  riastrad /*	$NetBSD: radeon_object.h,v 1.4 2021/12/18 23:45:43 riastradh Exp $	*/
      2  1.3  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright 2008 Advanced Micro Devices, Inc.
      5  1.1  riastrad  * Copyright 2008 Red Hat Inc.
      6  1.1  riastrad  * Copyright 2009 Jerome Glisse.
      7  1.1  riastrad  *
      8  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      9  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
     10  1.1  riastrad  * to deal in the Software without restriction, including without limitation
     11  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     12  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     13  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     14  1.1  riastrad  *
     15  1.1  riastrad  * The above copyright notice and this permission notice shall be included in
     16  1.1  riastrad  * all copies or substantial portions of the Software.
     17  1.1  riastrad  *
     18  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     19  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     20  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     21  1.1  riastrad  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     22  1.1  riastrad  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     23  1.1  riastrad  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     24  1.1  riastrad  * OTHER DEALINGS IN THE SOFTWARE.
     25  1.1  riastrad  *
     26  1.1  riastrad  * Authors: Dave Airlie
     27  1.1  riastrad  *          Alex Deucher
     28  1.1  riastrad  *          Jerome Glisse
     29  1.1  riastrad  */
     30  1.1  riastrad #ifndef __RADEON_OBJECT_H__
     31  1.1  riastrad #define __RADEON_OBJECT_H__
     32  1.1  riastrad 
     33  1.1  riastrad #include <drm/radeon_drm.h>
     34  1.1  riastrad #include "radeon.h"
     35  1.1  riastrad 
     36  1.1  riastrad /**
     37  1.1  riastrad  * radeon_mem_type_to_domain - return domain corresponding to mem_type
     38  1.1  riastrad  * @mem_type:	ttm memory type
     39  1.1  riastrad  *
     40  1.1  riastrad  * Returns corresponding domain of the ttm mem_type
     41  1.1  riastrad  */
     42  1.1  riastrad static inline unsigned radeon_mem_type_to_domain(u32 mem_type)
     43  1.1  riastrad {
     44  1.1  riastrad 	switch (mem_type) {
     45  1.1  riastrad 	case TTM_PL_VRAM:
     46  1.1  riastrad 		return RADEON_GEM_DOMAIN_VRAM;
     47  1.1  riastrad 	case TTM_PL_TT:
     48  1.1  riastrad 		return RADEON_GEM_DOMAIN_GTT;
     49  1.1  riastrad 	case TTM_PL_SYSTEM:
     50  1.1  riastrad 		return RADEON_GEM_DOMAIN_CPU;
     51  1.1  riastrad 	default:
     52  1.1  riastrad 		break;
     53  1.1  riastrad 	}
     54  1.1  riastrad 	return 0;
     55  1.1  riastrad }
     56  1.1  riastrad 
     57  1.1  riastrad /**
     58  1.1  riastrad  * radeon_bo_reserve - reserve bo
     59  1.1  riastrad  * @bo:		bo structure
     60  1.1  riastrad  * @no_intr:	don't return -ERESTARTSYS on pending signal
     61  1.1  riastrad  *
     62  1.1  riastrad  * Returns:
     63  1.1  riastrad  * -ERESTARTSYS: A wait for the buffer to become unreserved was interrupted by
     64  1.1  riastrad  * a signal. Release all buffer reservations and return to user-space.
     65  1.1  riastrad  */
     66  1.1  riastrad static inline int radeon_bo_reserve(struct radeon_bo *bo, bool no_intr)
     67  1.1  riastrad {
     68  1.1  riastrad 	int r;
     69  1.1  riastrad 
     70  1.4  riastrad 	r = ttm_bo_reserve(&bo->tbo, !no_intr, false, NULL);
     71  1.1  riastrad 	if (unlikely(r != 0)) {
     72  1.1  riastrad 		if (r != -ERESTARTSYS)
     73  1.1  riastrad 			dev_err(bo->rdev->dev, "%p reserve failed\n", bo);
     74  1.1  riastrad 		return r;
     75  1.1  riastrad 	}
     76  1.1  riastrad 	return 0;
     77  1.1  riastrad }
     78  1.1  riastrad 
     79  1.1  riastrad static inline void radeon_bo_unreserve(struct radeon_bo *bo)
     80  1.1  riastrad {
     81  1.1  riastrad 	ttm_bo_unreserve(&bo->tbo);
     82  1.1  riastrad }
     83  1.1  riastrad 
     84  1.1  riastrad /**
     85  1.1  riastrad  * radeon_bo_gpu_offset - return GPU offset of bo
     86  1.1  riastrad  * @bo:	radeon object for which we query the offset
     87  1.1  riastrad  *
     88  1.1  riastrad  * Returns current GPU offset of the object.
     89  1.1  riastrad  *
     90  1.1  riastrad  * Note: object should either be pinned or reserved when calling this
     91  1.1  riastrad  * function, it might be useful to add check for this for debugging.
     92  1.1  riastrad  */
     93  1.1  riastrad static inline u64 radeon_bo_gpu_offset(struct radeon_bo *bo)
     94  1.1  riastrad {
     95  1.1  riastrad 	return bo->tbo.offset;
     96  1.1  riastrad }
     97  1.1  riastrad 
     98  1.1  riastrad static inline unsigned long radeon_bo_size(struct radeon_bo *bo)
     99  1.1  riastrad {
    100  1.1  riastrad 	return bo->tbo.num_pages << PAGE_SHIFT;
    101  1.1  riastrad }
    102  1.1  riastrad 
    103  1.1  riastrad static inline unsigned radeon_bo_ngpu_pages(struct radeon_bo *bo)
    104  1.1  riastrad {
    105  1.1  riastrad 	return (bo->tbo.num_pages << PAGE_SHIFT) / RADEON_GPU_PAGE_SIZE;
    106  1.1  riastrad }
    107  1.1  riastrad 
    108  1.1  riastrad static inline unsigned radeon_bo_gpu_page_alignment(struct radeon_bo *bo)
    109  1.1  riastrad {
    110  1.1  riastrad 	return (bo->tbo.mem.page_alignment << PAGE_SHIFT) / RADEON_GPU_PAGE_SIZE;
    111  1.1  riastrad }
    112  1.1  riastrad 
    113  1.1  riastrad /**
    114  1.1  riastrad  * radeon_bo_mmap_offset - return mmap offset of bo
    115  1.1  riastrad  * @bo:	radeon object for which we query the offset
    116  1.1  riastrad  *
    117  1.1  riastrad  * Returns mmap offset of the object.
    118  1.1  riastrad  */
    119  1.1  riastrad static inline u64 radeon_bo_mmap_offset(struct radeon_bo *bo)
    120  1.1  riastrad {
    121  1.4  riastrad 	return drm_vma_node_offset_addr(&bo->tbo.base.vma_node);
    122  1.1  riastrad }
    123  1.1  riastrad 
    124  1.1  riastrad extern int radeon_bo_wait(struct radeon_bo *bo, u32 *mem_type,
    125  1.1  riastrad 			  bool no_wait);
    126  1.1  riastrad 
    127  1.1  riastrad extern int radeon_bo_create(struct radeon_device *rdev,
    128  1.1  riastrad 			    unsigned long size, int byte_align,
    129  1.3  riastrad 			    bool kernel, u32 domain, u32 flags,
    130  1.1  riastrad 			    struct sg_table *sg,
    131  1.4  riastrad 			    struct dma_resv *resv,
    132  1.1  riastrad 			    struct radeon_bo **bo_ptr);
    133  1.1  riastrad extern int radeon_bo_kmap(struct radeon_bo *bo, void **ptr);
    134  1.1  riastrad extern void radeon_bo_kunmap(struct radeon_bo *bo);
    135  1.3  riastrad extern struct radeon_bo *radeon_bo_ref(struct radeon_bo *bo);
    136  1.1  riastrad extern void radeon_bo_unref(struct radeon_bo **bo);
    137  1.1  riastrad extern int radeon_bo_pin(struct radeon_bo *bo, u32 domain, u64 *gpu_addr);
    138  1.1  riastrad extern int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain,
    139  1.1  riastrad 				    u64 max_offset, u64 *gpu_addr);
    140  1.1  riastrad extern int radeon_bo_unpin(struct radeon_bo *bo);
    141  1.1  riastrad extern int radeon_bo_evict_vram(struct radeon_device *rdev);
    142  1.1  riastrad extern void radeon_bo_force_delete(struct radeon_device *rdev);
    143  1.1  riastrad extern int radeon_bo_init(struct radeon_device *rdev);
    144  1.1  riastrad extern void radeon_bo_fini(struct radeon_device *rdev);
    145  1.1  riastrad extern int radeon_bo_list_validate(struct radeon_device *rdev,
    146  1.1  riastrad 				   struct ww_acquire_ctx *ticket,
    147  1.1  riastrad 				   struct list_head *head, int ring);
    148  1.1  riastrad extern int radeon_bo_set_tiling_flags(struct radeon_bo *bo,
    149  1.1  riastrad 				u32 tiling_flags, u32 pitch);
    150  1.1  riastrad extern void radeon_bo_get_tiling_flags(struct radeon_bo *bo,
    151  1.1  riastrad 				u32 *tiling_flags, u32 *pitch);
    152  1.1  riastrad extern int radeon_bo_check_tiling(struct radeon_bo *bo, bool has_moved,
    153  1.1  riastrad 				bool force_drop);
    154  1.1  riastrad extern void radeon_bo_move_notify(struct ttm_buffer_object *bo,
    155  1.4  riastrad 				  bool evict,
    156  1.1  riastrad 				  struct ttm_mem_reg *new_mem);
    157  1.1  riastrad extern int radeon_bo_fault_reserve_notify(struct ttm_buffer_object *bo);
    158  1.1  riastrad extern int radeon_bo_get_surface_reg(struct radeon_bo *bo);
    159  1.3  riastrad extern void radeon_bo_fence(struct radeon_bo *bo, struct radeon_fence *fence,
    160  1.3  riastrad 			    bool shared);
    161  1.1  riastrad 
    162  1.1  riastrad /*
    163  1.1  riastrad  * sub allocation
    164  1.1  riastrad  */
    165  1.1  riastrad 
    166  1.1  riastrad static inline uint64_t radeon_sa_bo_gpu_addr(struct radeon_sa_bo *sa_bo)
    167  1.1  riastrad {
    168  1.1  riastrad 	return sa_bo->manager->gpu_addr + sa_bo->soffset;
    169  1.1  riastrad }
    170  1.1  riastrad 
    171  1.1  riastrad static inline void * radeon_sa_bo_cpu_addr(struct radeon_sa_bo *sa_bo)
    172  1.1  riastrad {
    173  1.2  riastrad 	return (char *)sa_bo->manager->cpu_ptr + sa_bo->soffset;
    174  1.1  riastrad }
    175  1.1  riastrad 
    176  1.1  riastrad extern int radeon_sa_bo_manager_init(struct radeon_device *rdev,
    177  1.1  riastrad 				     struct radeon_sa_manager *sa_manager,
    178  1.3  riastrad 				     unsigned size, u32 align, u32 domain,
    179  1.3  riastrad 				     u32 flags);
    180  1.1  riastrad extern void radeon_sa_bo_manager_fini(struct radeon_device *rdev,
    181  1.1  riastrad 				      struct radeon_sa_manager *sa_manager);
    182  1.1  riastrad extern int radeon_sa_bo_manager_start(struct radeon_device *rdev,
    183  1.1  riastrad 				      struct radeon_sa_manager *sa_manager);
    184  1.1  riastrad extern int radeon_sa_bo_manager_suspend(struct radeon_device *rdev,
    185  1.1  riastrad 					struct radeon_sa_manager *sa_manager);
    186  1.1  riastrad extern int radeon_sa_bo_new(struct radeon_device *rdev,
    187  1.1  riastrad 			    struct radeon_sa_manager *sa_manager,
    188  1.1  riastrad 			    struct radeon_sa_bo **sa_bo,
    189  1.1  riastrad 			    unsigned size, unsigned align);
    190  1.1  riastrad extern void radeon_sa_bo_free(struct radeon_device *rdev,
    191  1.1  riastrad 			      struct radeon_sa_bo **sa_bo,
    192  1.1  riastrad 			      struct radeon_fence *fence);
    193  1.1  riastrad #if defined(CONFIG_DEBUG_FS)
    194  1.1  riastrad extern void radeon_sa_bo_dump_debug_info(struct radeon_sa_manager *sa_manager,
    195  1.1  riastrad 					 struct seq_file *m);
    196  1.1  riastrad #endif
    197  1.1  riastrad 
    198  1.1  riastrad 
    199  1.1  riastrad #endif
    200