Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Advanced Micro Devices, Inc. |
| 3 | * Copyright 2008 Red Hat Inc. |
| 4 | * Copyright 2009 Jerome Glisse. |
| 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, sublicense, |
| 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 shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 22 | * OTHER DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: Dave Airlie |
| 25 | * Alex Deucher |
| 26 | * Jerome Glisse |
| 27 | */ |
| 28 | #ifndef __RADEON_OBJECT_H__ |
| 29 | #define __RADEON_OBJECT_H__ |
| 30 | |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 31 | #include <drm/radeon_drm.h> |
| 32 | #include "radeon.h" |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 33 | |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 34 | /** |
| 35 | * radeon_mem_type_to_domain - return domain corresponding to mem_type |
| 36 | * @mem_type: ttm memory type |
| 37 | * |
| 38 | * Returns corresponding domain of the ttm mem_type |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 39 | */ |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 40 | static inline unsigned radeon_mem_type_to_domain(u32 mem_type) |
| 41 | { |
| 42 | switch (mem_type) { |
| 43 | case TTM_PL_VRAM: |
| 44 | return RADEON_GEM_DOMAIN_VRAM; |
| 45 | case TTM_PL_TT: |
| 46 | return RADEON_GEM_DOMAIN_GTT; |
| 47 | case TTM_PL_SYSTEM: |
| 48 | return RADEON_GEM_DOMAIN_CPU; |
| 49 | default: |
| 50 | break; |
| 51 | } |
| 52 | return 0; |
| 53 | } |
| 54 | |
Andi Kleen | ce580fa | 2011-10-13 16:08:47 -0700 | [diff] [blame] | 55 | int radeon_bo_reserve(struct radeon_bo *bo, bool no_wait); |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 56 | |
| 57 | static inline void radeon_bo_unreserve(struct radeon_bo *bo) |
| 58 | { |
| 59 | ttm_bo_unreserve(&bo->tbo); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * radeon_bo_gpu_offset - return GPU offset of bo |
| 64 | * @bo: radeon object for which we query the offset |
| 65 | * |
| 66 | * Returns current GPU offset of the object. |
| 67 | * |
| 68 | * Note: object should either be pinned or reserved when calling this |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 69 | * function, it might be useful to add check for this for debugging. |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 70 | */ |
| 71 | static inline u64 radeon_bo_gpu_offset(struct radeon_bo *bo) |
| 72 | { |
| 73 | return bo->tbo.offset; |
| 74 | } |
| 75 | |
| 76 | static inline unsigned long radeon_bo_size(struct radeon_bo *bo) |
| 77 | { |
| 78 | return bo->tbo.num_pages << PAGE_SHIFT; |
| 79 | } |
| 80 | |
| 81 | static inline bool radeon_bo_is_reserved(struct radeon_bo *bo) |
| 82 | { |
| 83 | return !!atomic_read(&bo->tbo.reserved); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * radeon_bo_mmap_offset - return mmap offset of bo |
| 88 | * @bo: radeon object for which we query the offset |
| 89 | * |
| 90 | * Returns mmap offset of the object. |
| 91 | * |
| 92 | * Note: addr_space_offset is constant after ttm bo init thus isn't protected |
| 93 | * by any lock. |
| 94 | */ |
| 95 | static inline u64 radeon_bo_mmap_offset(struct radeon_bo *bo) |
| 96 | { |
| 97 | return bo->tbo.addr_space_offset; |
| 98 | } |
| 99 | |
Andi Kleen | ce580fa | 2011-10-13 16:08:47 -0700 | [diff] [blame] | 100 | extern int radeon_bo_wait(struct radeon_bo *bo, u32 *mem_type, |
Dave Airlie | 83f30d0 | 2011-10-27 18:15:10 +0200 | [diff] [blame^] | 101 | bool no_wait); |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 102 | |
| 103 | extern int radeon_bo_create(struct radeon_device *rdev, |
Daniel Vetter | 441921d | 2011-02-18 17:59:16 +0100 | [diff] [blame] | 104 | unsigned long size, int byte_align, |
| 105 | bool kernel, u32 domain, |
| 106 | struct radeon_bo **bo_ptr); |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 107 | extern int radeon_bo_kmap(struct radeon_bo *bo, void **ptr); |
| 108 | extern void radeon_bo_kunmap(struct radeon_bo *bo); |
| 109 | extern void radeon_bo_unref(struct radeon_bo **bo); |
| 110 | extern int radeon_bo_pin(struct radeon_bo *bo, u32 domain, u64 *gpu_addr); |
| 111 | extern int radeon_bo_unpin(struct radeon_bo *bo); |
| 112 | extern int radeon_bo_evict_vram(struct radeon_device *rdev); |
| 113 | extern void radeon_bo_force_delete(struct radeon_device *rdev); |
| 114 | extern int radeon_bo_init(struct radeon_device *rdev); |
| 115 | extern void radeon_bo_fini(struct radeon_device *rdev); |
| 116 | extern void radeon_bo_list_add_object(struct radeon_bo_list *lobj, |
| 117 | struct list_head *head); |
Jerome Glisse | 94429bb | 2010-02-15 21:36:33 +0100 | [diff] [blame] | 118 | extern int radeon_bo_list_validate(struct list_head *head); |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 119 | extern int radeon_bo_fbdev_mmap(struct radeon_bo *bo, |
| 120 | struct vm_area_struct *vma); |
| 121 | extern int radeon_bo_set_tiling_flags(struct radeon_bo *bo, |
| 122 | u32 tiling_flags, u32 pitch); |
| 123 | extern void radeon_bo_get_tiling_flags(struct radeon_bo *bo, |
| 124 | u32 *tiling_flags, u32 *pitch); |
| 125 | extern int radeon_bo_check_tiling(struct radeon_bo *bo, bool has_moved, |
| 126 | bool force_drop); |
| 127 | extern void radeon_bo_move_notify(struct ttm_buffer_object *bo, |
| 128 | struct ttm_mem_reg *mem); |
Jerome Glisse | 0a2d50e | 2010-04-09 14:39:24 +0200 | [diff] [blame] | 129 | extern int radeon_bo_fault_reserve_notify(struct ttm_buffer_object *bo); |
Dave Airlie | 550e2d9 | 2009-12-09 14:15:38 +1000 | [diff] [blame] | 130 | extern int radeon_bo_get_surface_reg(struct radeon_bo *bo); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 131 | #endif |