Rev 1321 | Rev 1428 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1126 | serge | 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 | |||
1321 | serge | 31 | #include |
32 | #include "radeon.h" |
||
1126 | serge | 33 | |
1321 | serge | 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 |
||
1126 | serge | 39 | */ |
1321 | serge | 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 | } |
||
1126 | serge | 54 | |
1321 | serge | 55 | /** |
56 | * radeon_bo_reserve - reserve bo |
||
57 | * @bo: bo structure |
||
58 | * @no_wait: don't sleep while trying to reserve (return -EBUSY) |
||
59 | * |
||
60 | * Returns: |
||
61 | * -EBUSY: buffer is busy and @no_wait is true |
||
1404 | serge | 62 | * -ERESTARTSYS: A wait for the buffer to become unreserved was interrupted by |
1321 | serge | 63 | * a signal. Release all buffer reservations and return to user-space. |
1404 | serge | 64 | */ |
1126 | serge | 65 | |
1321 | serge | 66 | static inline void radeon_bo_unreserve(struct radeon_bo *bo) |
67 | { |
||
68 | ttm_bo_unreserve(&bo->tbo); |
||
69 | } |
||
1126 | serge | 70 | |
1321 | serge | 71 | /** |
72 | * radeon_bo_gpu_offset - return GPU offset of bo |
||
73 | * @bo: radeon object for which we query the offset |
||
1404 | serge | 74 | * |
1321 | serge | 75 | * Returns current GPU offset of the object. |
1404 | serge | 76 | * |
1321 | serge | 77 | * Note: object should either be pinned or reserved when calling this |
78 | * function, it might be usefull to add check for this for debugging. |
||
1404 | serge | 79 | */ |
1321 | serge | 80 | static inline u64 radeon_bo_gpu_offset(struct radeon_bo *bo) |
81 | { |
||
82 | return bo->tbo.offset; |
||
83 | } |
||
1126 | serge | 84 | |
1321 | serge | 85 | static inline unsigned long radeon_bo_size(struct radeon_bo *bo) |
86 | { |
||
87 | return bo->tbo.num_pages << PAGE_SHIFT; |
||
88 | } |
||
1126 | serge | 89 | |
1321 | serge | 90 | static inline bool radeon_bo_is_reserved(struct radeon_bo *bo) |
91 | { |
||
92 | return !!atomic_read(&bo->tbo.reserved); |
||
93 | } |
||
1126 | serge | 94 | |
1321 | serge | 95 | /** |
96 | * radeon_bo_mmap_offset - return mmap offset of bo |
||
97 | * @bo: radeon object for which we query the offset |
||
1404 | serge | 98 | * |
1321 | serge | 99 | * Returns mmap offset of the object. |
1404 | serge | 100 | * |
1321 | serge | 101 | * Note: addr_space_offset is constant after ttm bo init thus isn't protected |
102 | * by any lock. |
||
1404 | serge | 103 | */ |
1321 | serge | 104 | static inline u64 radeon_bo_mmap_offset(struct radeon_bo *bo) |
105 | { |
||
106 | return bo->tbo.addr_space_offset; |
||
107 | } |
||
1126 | serge | 108 | |
1321 | serge | 109 | static inline int radeon_bo_wait(struct radeon_bo *bo, u32 *mem_type, |
110 | bool no_wait) |
||
1126 | serge | 111 | { |
1321 | serge | 112 | int r; |
1126 | serge | 113 | |
1321 | serge | 114 | r = ttm_bo_reserve(&bo->tbo, true, no_wait, false, 0); |
115 | if (unlikely(r != 0)) { |
||
1404 | serge | 116 | if (r != -ERESTARTSYS) |
1321 | serge | 117 | dev_err(bo->rdev->dev, "%p reserve failed for wait\n", bo); |
118 | return r; |
||
119 | } |
||
120 | spin_lock(&bo->tbo.lock); |
||
121 | if (mem_type) |
||
122 | *mem_type = bo->tbo.mem.mem_type; |
||
123 | if (bo->tbo.sync_obj) |
||
124 | r = ttm_bo_wait(&bo->tbo, true, true, no_wait); |
||
125 | spin_unlock(&bo->tbo.lock); |
||
126 | ttm_bo_unreserve(&bo->tbo); |
||
127 | return r; |
||
128 | } |
||
1126 | serge | 129 | |
1321 | serge | 130 | extern int radeon_bo_create(struct radeon_device *rdev, |
131 | struct drm_gem_object *gobj, unsigned long size, |
||
132 | bool kernel, u32 domain, |
||
133 | struct radeon_bo **bo_ptr); |
||
134 | extern int radeon_bo_kmap(struct radeon_bo *bo, void **ptr); |
||
135 | extern void radeon_bo_kunmap(struct radeon_bo *bo); |
||
136 | extern void radeon_bo_unref(struct radeon_bo **bo); |
||
137 | extern int radeon_bo_pin(struct radeon_bo *bo, u32 domain, u64 *gpu_addr); |
||
138 | extern int radeon_bo_unpin(struct radeon_bo *bo); |
||
139 | extern int radeon_bo_evict_vram(struct radeon_device *rdev); |
||
140 | extern void radeon_bo_force_delete(struct radeon_device *rdev); |
||
141 | extern int radeon_bo_init(struct radeon_device *rdev); |
||
142 | extern void radeon_bo_fini(struct radeon_device *rdev); |
||
143 | extern void radeon_bo_list_add_object(struct radeon_bo_list *lobj, |
||
144 | struct list_head *head); |
||
145 | extern int radeon_bo_list_reserve(struct list_head *head); |
||
146 | extern void radeon_bo_list_unreserve(struct list_head *head); |
||
147 | extern int radeon_bo_list_validate(struct list_head *head, void *fence); |
||
148 | extern void radeon_bo_list_unvalidate(struct list_head *head, void *fence); |
||
149 | extern int radeon_bo_fbdev_mmap(struct radeon_bo *bo, |
||
150 | struct vm_area_struct *vma); |
||
151 | extern int radeon_bo_set_tiling_flags(struct radeon_bo *bo, |
||
152 | u32 tiling_flags, u32 pitch); |
||
153 | extern void radeon_bo_get_tiling_flags(struct radeon_bo *bo, |
||
154 | u32 *tiling_flags, u32 *pitch); |
||
155 | extern int radeon_bo_check_tiling(struct radeon_bo *bo, bool has_moved, |
||
156 | bool force_drop); |
||
157 | extern void radeon_bo_move_notify(struct ttm_buffer_object *bo, |
||
158 | struct ttm_mem_reg *mem); |
||
159 | extern void radeon_bo_fault_reserve_notify(struct ttm_buffer_object *bo); |
||
160 | extern int radeon_bo_get_surface_reg(struct radeon_bo *bo); |
||
1126 | serge | 161 | #endif><> |