18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright © 2016 Intel Corporation 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the next 128c2ecf20Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 138c2ecf20Sopenharmony_ci * Software. 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 168c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 178c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 188c2ecf20Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 198c2ecf20Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 208c2ecf20Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 218c2ecf20Sopenharmony_ci * IN THE SOFTWARE. 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci */ 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#ifndef __I915_VMA_H__ 268c2ecf20Sopenharmony_ci#define __I915_VMA_H__ 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#include <linux/io-mapping.h> 298c2ecf20Sopenharmony_ci#include <linux/rbtree.h> 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#include <drm/drm_mm.h> 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#include "gt/intel_ggtt_fencing.h" 348c2ecf20Sopenharmony_ci#include "gem/i915_gem_object.h" 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#include "i915_gem_gtt.h" 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#include "i915_active.h" 398c2ecf20Sopenharmony_ci#include "i915_request.h" 408c2ecf20Sopenharmony_ci#include "i915_vma_types.h" 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_cistruct i915_vma * 438c2ecf20Sopenharmony_cii915_vma_instance(struct drm_i915_gem_object *obj, 448c2ecf20Sopenharmony_ci struct i915_address_space *vm, 458c2ecf20Sopenharmony_ci const struct i915_ggtt_view *view); 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_civoid i915_vma_unpin_and_release(struct i915_vma **p_vma, unsigned int flags); 488c2ecf20Sopenharmony_ci#define I915_VMA_RELEASE_MAP BIT(0) 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_cistatic inline bool i915_vma_is_active(const struct i915_vma *vma) 518c2ecf20Sopenharmony_ci{ 528c2ecf20Sopenharmony_ci return !i915_active_is_idle(&vma->active); 538c2ecf20Sopenharmony_ci} 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ciint __must_check __i915_vma_move_to_active(struct i915_vma *vma, 568c2ecf20Sopenharmony_ci struct i915_request *rq); 578c2ecf20Sopenharmony_ciint __must_check i915_vma_move_to_active(struct i915_vma *vma, 588c2ecf20Sopenharmony_ci struct i915_request *rq, 598c2ecf20Sopenharmony_ci unsigned int flags); 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci#define __i915_vma_flags(v) ((unsigned long *)&(v)->flags.counter) 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_cistatic inline bool i915_vma_is_ggtt(const struct i915_vma *vma) 648c2ecf20Sopenharmony_ci{ 658c2ecf20Sopenharmony_ci return test_bit(I915_VMA_GGTT_BIT, __i915_vma_flags(vma)); 668c2ecf20Sopenharmony_ci} 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_cistatic inline bool i915_vma_has_ggtt_write(const struct i915_vma *vma) 698c2ecf20Sopenharmony_ci{ 708c2ecf20Sopenharmony_ci return test_bit(I915_VMA_GGTT_WRITE_BIT, __i915_vma_flags(vma)); 718c2ecf20Sopenharmony_ci} 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_cistatic inline void i915_vma_set_ggtt_write(struct i915_vma *vma) 748c2ecf20Sopenharmony_ci{ 758c2ecf20Sopenharmony_ci GEM_BUG_ON(!i915_vma_is_ggtt(vma)); 768c2ecf20Sopenharmony_ci set_bit(I915_VMA_GGTT_WRITE_BIT, __i915_vma_flags(vma)); 778c2ecf20Sopenharmony_ci} 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_cistatic inline bool i915_vma_unset_ggtt_write(struct i915_vma *vma) 808c2ecf20Sopenharmony_ci{ 818c2ecf20Sopenharmony_ci return test_and_clear_bit(I915_VMA_GGTT_WRITE_BIT, 828c2ecf20Sopenharmony_ci __i915_vma_flags(vma)); 838c2ecf20Sopenharmony_ci} 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_civoid i915_vma_flush_writes(struct i915_vma *vma); 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_cistatic inline bool i915_vma_is_map_and_fenceable(const struct i915_vma *vma) 888c2ecf20Sopenharmony_ci{ 898c2ecf20Sopenharmony_ci return test_bit(I915_VMA_CAN_FENCE_BIT, __i915_vma_flags(vma)); 908c2ecf20Sopenharmony_ci} 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_cistatic inline bool i915_vma_set_userfault(struct i915_vma *vma) 938c2ecf20Sopenharmony_ci{ 948c2ecf20Sopenharmony_ci GEM_BUG_ON(!i915_vma_is_map_and_fenceable(vma)); 958c2ecf20Sopenharmony_ci return test_and_set_bit(I915_VMA_USERFAULT_BIT, __i915_vma_flags(vma)); 968c2ecf20Sopenharmony_ci} 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_cistatic inline void i915_vma_unset_userfault(struct i915_vma *vma) 998c2ecf20Sopenharmony_ci{ 1008c2ecf20Sopenharmony_ci return clear_bit(I915_VMA_USERFAULT_BIT, __i915_vma_flags(vma)); 1018c2ecf20Sopenharmony_ci} 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_cistatic inline bool i915_vma_has_userfault(const struct i915_vma *vma) 1048c2ecf20Sopenharmony_ci{ 1058c2ecf20Sopenharmony_ci return test_bit(I915_VMA_USERFAULT_BIT, __i915_vma_flags(vma)); 1068c2ecf20Sopenharmony_ci} 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_cistatic inline bool i915_vma_is_closed(const struct i915_vma *vma) 1098c2ecf20Sopenharmony_ci{ 1108c2ecf20Sopenharmony_ci return !list_empty(&vma->closed_link); 1118c2ecf20Sopenharmony_ci} 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_cistatic inline u32 i915_ggtt_offset(const struct i915_vma *vma) 1148c2ecf20Sopenharmony_ci{ 1158c2ecf20Sopenharmony_ci GEM_BUG_ON(!i915_vma_is_ggtt(vma)); 1168c2ecf20Sopenharmony_ci GEM_BUG_ON(!drm_mm_node_allocated(&vma->node)); 1178c2ecf20Sopenharmony_ci GEM_BUG_ON(upper_32_bits(vma->node.start)); 1188c2ecf20Sopenharmony_ci GEM_BUG_ON(upper_32_bits(vma->node.start + vma->node.size - 1)); 1198c2ecf20Sopenharmony_ci return lower_32_bits(vma->node.start); 1208c2ecf20Sopenharmony_ci} 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_cistatic inline u32 i915_ggtt_pin_bias(struct i915_vma *vma) 1238c2ecf20Sopenharmony_ci{ 1248c2ecf20Sopenharmony_ci return i915_vm_to_ggtt(vma->vm)->pin_bias; 1258c2ecf20Sopenharmony_ci} 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_cistatic inline struct i915_vma *i915_vma_get(struct i915_vma *vma) 1288c2ecf20Sopenharmony_ci{ 1298c2ecf20Sopenharmony_ci i915_gem_object_get(vma->obj); 1308c2ecf20Sopenharmony_ci return vma; 1318c2ecf20Sopenharmony_ci} 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_cistatic inline struct i915_vma *i915_vma_tryget(struct i915_vma *vma) 1348c2ecf20Sopenharmony_ci{ 1358c2ecf20Sopenharmony_ci if (likely(kref_get_unless_zero(&vma->obj->base.refcount))) 1368c2ecf20Sopenharmony_ci return vma; 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci return NULL; 1398c2ecf20Sopenharmony_ci} 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_cistatic inline void i915_vma_put(struct i915_vma *vma) 1428c2ecf20Sopenharmony_ci{ 1438c2ecf20Sopenharmony_ci i915_gem_object_put(vma->obj); 1448c2ecf20Sopenharmony_ci} 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_cistatic __always_inline ptrdiff_t ptrdiff(const void *a, const void *b) 1478c2ecf20Sopenharmony_ci{ 1488c2ecf20Sopenharmony_ci return a - b; 1498c2ecf20Sopenharmony_ci} 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_cistatic inline long 1528c2ecf20Sopenharmony_cii915_vma_compare(struct i915_vma *vma, 1538c2ecf20Sopenharmony_ci struct i915_address_space *vm, 1548c2ecf20Sopenharmony_ci const struct i915_ggtt_view *view) 1558c2ecf20Sopenharmony_ci{ 1568c2ecf20Sopenharmony_ci ptrdiff_t cmp; 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci GEM_BUG_ON(view && !i915_is_ggtt(vm)); 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci cmp = ptrdiff(vma->vm, vm); 1618c2ecf20Sopenharmony_ci if (cmp) 1628c2ecf20Sopenharmony_ci return cmp; 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci BUILD_BUG_ON(I915_GGTT_VIEW_NORMAL != 0); 1658c2ecf20Sopenharmony_ci cmp = vma->ggtt_view.type; 1668c2ecf20Sopenharmony_ci if (!view) 1678c2ecf20Sopenharmony_ci return cmp; 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci cmp -= view->type; 1708c2ecf20Sopenharmony_ci if (cmp) 1718c2ecf20Sopenharmony_ci return cmp; 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci assert_i915_gem_gtt_types(); 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci /* ggtt_view.type also encodes its size so that we both distinguish 1768c2ecf20Sopenharmony_ci * different views using it as a "type" and also use a compact (no 1778c2ecf20Sopenharmony_ci * accessing of uninitialised padding bytes) memcmp without storing 1788c2ecf20Sopenharmony_ci * an extra parameter or adding more code. 1798c2ecf20Sopenharmony_ci * 1808c2ecf20Sopenharmony_ci * To ensure that the memcmp is valid for all branches of the union, 1818c2ecf20Sopenharmony_ci * even though the code looks like it is just comparing one branch, 1828c2ecf20Sopenharmony_ci * we assert above that all branches have the same address, and that 1838c2ecf20Sopenharmony_ci * each branch has a unique type/size. 1848c2ecf20Sopenharmony_ci */ 1858c2ecf20Sopenharmony_ci BUILD_BUG_ON(I915_GGTT_VIEW_NORMAL >= I915_GGTT_VIEW_PARTIAL); 1868c2ecf20Sopenharmony_ci BUILD_BUG_ON(I915_GGTT_VIEW_PARTIAL >= I915_GGTT_VIEW_ROTATED); 1878c2ecf20Sopenharmony_ci BUILD_BUG_ON(I915_GGTT_VIEW_ROTATED >= I915_GGTT_VIEW_REMAPPED); 1888c2ecf20Sopenharmony_ci BUILD_BUG_ON(offsetof(typeof(*view), rotated) != 1898c2ecf20Sopenharmony_ci offsetof(typeof(*view), partial)); 1908c2ecf20Sopenharmony_ci BUILD_BUG_ON(offsetof(typeof(*view), rotated) != 1918c2ecf20Sopenharmony_ci offsetof(typeof(*view), remapped)); 1928c2ecf20Sopenharmony_ci return memcmp(&vma->ggtt_view.partial, &view->partial, view->type); 1938c2ecf20Sopenharmony_ci} 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_cistruct i915_vma_work *i915_vma_work(void); 1968c2ecf20Sopenharmony_ciint i915_vma_bind(struct i915_vma *vma, 1978c2ecf20Sopenharmony_ci enum i915_cache_level cache_level, 1988c2ecf20Sopenharmony_ci u32 flags, 1998c2ecf20Sopenharmony_ci struct i915_vma_work *work); 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_cibool i915_gem_valid_gtt_space(struct i915_vma *vma, unsigned long color); 2028c2ecf20Sopenharmony_cibool i915_vma_misplaced(const struct i915_vma *vma, 2038c2ecf20Sopenharmony_ci u64 size, u64 alignment, u64 flags); 2048c2ecf20Sopenharmony_civoid __i915_vma_set_map_and_fenceable(struct i915_vma *vma); 2058c2ecf20Sopenharmony_civoid i915_vma_revoke_mmap(struct i915_vma *vma); 2068c2ecf20Sopenharmony_civoid __i915_vma_evict(struct i915_vma *vma); 2078c2ecf20Sopenharmony_ciint __i915_vma_unbind(struct i915_vma *vma); 2088c2ecf20Sopenharmony_ciint __must_check i915_vma_unbind(struct i915_vma *vma); 2098c2ecf20Sopenharmony_civoid i915_vma_unlink_ctx(struct i915_vma *vma); 2108c2ecf20Sopenharmony_civoid i915_vma_close(struct i915_vma *vma); 2118c2ecf20Sopenharmony_civoid i915_vma_reopen(struct i915_vma *vma); 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_cistatic inline struct i915_vma *__i915_vma_get(struct i915_vma *vma) 2148c2ecf20Sopenharmony_ci{ 2158c2ecf20Sopenharmony_ci if (kref_get_unless_zero(&vma->ref)) 2168c2ecf20Sopenharmony_ci return vma; 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci return NULL; 2198c2ecf20Sopenharmony_ci} 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_civoid i915_vma_release(struct kref *ref); 2228c2ecf20Sopenharmony_cistatic inline void __i915_vma_put(struct i915_vma *vma) 2238c2ecf20Sopenharmony_ci{ 2248c2ecf20Sopenharmony_ci kref_put(&vma->ref, i915_vma_release); 2258c2ecf20Sopenharmony_ci} 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci#define assert_vma_held(vma) dma_resv_assert_held((vma)->resv) 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_cistatic inline void i915_vma_lock(struct i915_vma *vma) 2308c2ecf20Sopenharmony_ci{ 2318c2ecf20Sopenharmony_ci dma_resv_lock(vma->resv, NULL); 2328c2ecf20Sopenharmony_ci} 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_cistatic inline void i915_vma_unlock(struct i915_vma *vma) 2358c2ecf20Sopenharmony_ci{ 2368c2ecf20Sopenharmony_ci dma_resv_unlock(vma->resv); 2378c2ecf20Sopenharmony_ci} 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ciint __must_check 2408c2ecf20Sopenharmony_cii915_vma_pin_ww(struct i915_vma *vma, struct i915_gem_ww_ctx *ww, 2418c2ecf20Sopenharmony_ci u64 size, u64 alignment, u64 flags); 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_cistatic inline int __must_check 2448c2ecf20Sopenharmony_cii915_vma_pin(struct i915_vma *vma, u64 size, u64 alignment, u64 flags) 2458c2ecf20Sopenharmony_ci{ 2468c2ecf20Sopenharmony_ci return i915_vma_pin_ww(vma, NULL, size, alignment, flags); 2478c2ecf20Sopenharmony_ci} 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ciint i915_ggtt_pin(struct i915_vma *vma, struct i915_gem_ww_ctx *ww, 2508c2ecf20Sopenharmony_ci u32 align, unsigned int flags); 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_cistatic inline int i915_vma_pin_count(const struct i915_vma *vma) 2538c2ecf20Sopenharmony_ci{ 2548c2ecf20Sopenharmony_ci return atomic_read(&vma->flags) & I915_VMA_PIN_MASK; 2558c2ecf20Sopenharmony_ci} 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_cistatic inline bool i915_vma_is_pinned(const struct i915_vma *vma) 2588c2ecf20Sopenharmony_ci{ 2598c2ecf20Sopenharmony_ci return i915_vma_pin_count(vma); 2608c2ecf20Sopenharmony_ci} 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_cistatic inline void __i915_vma_pin(struct i915_vma *vma) 2638c2ecf20Sopenharmony_ci{ 2648c2ecf20Sopenharmony_ci atomic_inc(&vma->flags); 2658c2ecf20Sopenharmony_ci GEM_BUG_ON(!i915_vma_is_pinned(vma)); 2668c2ecf20Sopenharmony_ci} 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_cistatic inline void __i915_vma_unpin(struct i915_vma *vma) 2698c2ecf20Sopenharmony_ci{ 2708c2ecf20Sopenharmony_ci GEM_BUG_ON(!i915_vma_is_pinned(vma)); 2718c2ecf20Sopenharmony_ci atomic_dec(&vma->flags); 2728c2ecf20Sopenharmony_ci} 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_cistatic inline void i915_vma_unpin(struct i915_vma *vma) 2758c2ecf20Sopenharmony_ci{ 2768c2ecf20Sopenharmony_ci GEM_BUG_ON(!drm_mm_node_allocated(&vma->node)); 2778c2ecf20Sopenharmony_ci __i915_vma_unpin(vma); 2788c2ecf20Sopenharmony_ci} 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_cistatic inline bool i915_vma_is_bound(const struct i915_vma *vma, 2818c2ecf20Sopenharmony_ci unsigned int where) 2828c2ecf20Sopenharmony_ci{ 2838c2ecf20Sopenharmony_ci return atomic_read(&vma->flags) & where; 2848c2ecf20Sopenharmony_ci} 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_cistatic inline bool i915_node_color_differs(const struct drm_mm_node *node, 2878c2ecf20Sopenharmony_ci unsigned long color) 2888c2ecf20Sopenharmony_ci{ 2898c2ecf20Sopenharmony_ci return drm_mm_node_allocated(node) && node->color != color; 2908c2ecf20Sopenharmony_ci} 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci/** 2938c2ecf20Sopenharmony_ci * i915_vma_pin_iomap - calls ioremap_wc to map the GGTT VMA via the aperture 2948c2ecf20Sopenharmony_ci * @vma: VMA to iomap 2958c2ecf20Sopenharmony_ci * 2968c2ecf20Sopenharmony_ci * The passed in VMA has to be pinned in the global GTT mappable region. 2978c2ecf20Sopenharmony_ci * An extra pinning of the VMA is acquired for the return iomapping, 2988c2ecf20Sopenharmony_ci * the caller must call i915_vma_unpin_iomap to relinquish the pinning 2998c2ecf20Sopenharmony_ci * after the iomapping is no longer required. 3008c2ecf20Sopenharmony_ci * 3018c2ecf20Sopenharmony_ci * Returns a valid iomapped pointer or ERR_PTR. 3028c2ecf20Sopenharmony_ci */ 3038c2ecf20Sopenharmony_civoid __iomem *i915_vma_pin_iomap(struct i915_vma *vma); 3048c2ecf20Sopenharmony_ci#define IO_ERR_PTR(x) ((void __iomem *)ERR_PTR(x)) 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci/** 3078c2ecf20Sopenharmony_ci * i915_vma_unpin_iomap - unpins the mapping returned from i915_vma_iomap 3088c2ecf20Sopenharmony_ci * @vma: VMA to unpin 3098c2ecf20Sopenharmony_ci * 3108c2ecf20Sopenharmony_ci * Unpins the previously iomapped VMA from i915_vma_pin_iomap(). 3118c2ecf20Sopenharmony_ci * 3128c2ecf20Sopenharmony_ci * This function is only valid to be called on a VMA previously 3138c2ecf20Sopenharmony_ci * iomapped by the caller with i915_vma_pin_iomap(). 3148c2ecf20Sopenharmony_ci */ 3158c2ecf20Sopenharmony_civoid i915_vma_unpin_iomap(struct i915_vma *vma); 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_cistatic inline struct page *i915_vma_first_page(struct i915_vma *vma) 3188c2ecf20Sopenharmony_ci{ 3198c2ecf20Sopenharmony_ci GEM_BUG_ON(!vma->pages); 3208c2ecf20Sopenharmony_ci return sg_page(vma->pages->sgl); 3218c2ecf20Sopenharmony_ci} 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_ci/** 3248c2ecf20Sopenharmony_ci * i915_vma_pin_fence - pin fencing state 3258c2ecf20Sopenharmony_ci * @vma: vma to pin fencing for 3268c2ecf20Sopenharmony_ci * 3278c2ecf20Sopenharmony_ci * This pins the fencing state (whether tiled or untiled) to make sure the 3288c2ecf20Sopenharmony_ci * vma (and its object) is ready to be used as a scanout target. Fencing 3298c2ecf20Sopenharmony_ci * status must be synchronize first by calling i915_vma_get_fence(): 3308c2ecf20Sopenharmony_ci * 3318c2ecf20Sopenharmony_ci * The resulting fence pin reference must be released again with 3328c2ecf20Sopenharmony_ci * i915_vma_unpin_fence(). 3338c2ecf20Sopenharmony_ci * 3348c2ecf20Sopenharmony_ci * Returns: 3358c2ecf20Sopenharmony_ci * 3368c2ecf20Sopenharmony_ci * True if the vma has a fence, false otherwise. 3378c2ecf20Sopenharmony_ci */ 3388c2ecf20Sopenharmony_ciint __must_check i915_vma_pin_fence(struct i915_vma *vma); 3398c2ecf20Sopenharmony_civoid i915_vma_revoke_fence(struct i915_vma *vma); 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_ciint __i915_vma_pin_fence(struct i915_vma *vma); 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_cistatic inline void __i915_vma_unpin_fence(struct i915_vma *vma) 3448c2ecf20Sopenharmony_ci{ 3458c2ecf20Sopenharmony_ci GEM_BUG_ON(atomic_read(&vma->fence->pin_count) <= 0); 3468c2ecf20Sopenharmony_ci atomic_dec(&vma->fence->pin_count); 3478c2ecf20Sopenharmony_ci} 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_ci/** 3508c2ecf20Sopenharmony_ci * i915_vma_unpin_fence - unpin fencing state 3518c2ecf20Sopenharmony_ci * @vma: vma to unpin fencing for 3528c2ecf20Sopenharmony_ci * 3538c2ecf20Sopenharmony_ci * This releases the fence pin reference acquired through 3548c2ecf20Sopenharmony_ci * i915_vma_pin_fence. It will handle both objects with and without an 3558c2ecf20Sopenharmony_ci * attached fence correctly, callers do not need to distinguish this. 3568c2ecf20Sopenharmony_ci */ 3578c2ecf20Sopenharmony_cistatic inline void 3588c2ecf20Sopenharmony_cii915_vma_unpin_fence(struct i915_vma *vma) 3598c2ecf20Sopenharmony_ci{ 3608c2ecf20Sopenharmony_ci if (vma->fence) 3618c2ecf20Sopenharmony_ci __i915_vma_unpin_fence(vma); 3628c2ecf20Sopenharmony_ci} 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_civoid i915_vma_parked(struct intel_gt *gt); 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ci#define for_each_until(cond) if (cond) break; else 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci/** 3698c2ecf20Sopenharmony_ci * for_each_ggtt_vma - Iterate over the GGTT VMA belonging to an object. 3708c2ecf20Sopenharmony_ci * @V: the #i915_vma iterator 3718c2ecf20Sopenharmony_ci * @OBJ: the #drm_i915_gem_object 3728c2ecf20Sopenharmony_ci * 3738c2ecf20Sopenharmony_ci * GGTT VMA are placed at the being of the object's vma_list, see 3748c2ecf20Sopenharmony_ci * vma_create(), so we can stop our walk as soon as we see a ppgtt VMA, 3758c2ecf20Sopenharmony_ci * or the list is empty ofc. 3768c2ecf20Sopenharmony_ci */ 3778c2ecf20Sopenharmony_ci#define for_each_ggtt_vma(V, OBJ) \ 3788c2ecf20Sopenharmony_ci list_for_each_entry(V, &(OBJ)->vma.list, obj_link) \ 3798c2ecf20Sopenharmony_ci for_each_until(!i915_vma_is_ggtt(V)) 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_cistruct i915_vma *i915_vma_alloc(void); 3828c2ecf20Sopenharmony_civoid i915_vma_free(struct i915_vma *vma); 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_cistruct i915_vma *i915_vma_make_unshrinkable(struct i915_vma *vma); 3858c2ecf20Sopenharmony_civoid i915_vma_make_shrinkable(struct i915_vma *vma); 3868c2ecf20Sopenharmony_civoid i915_vma_make_purgeable(struct i915_vma *vma); 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ciint i915_vma_wait_for_bind(struct i915_vma *vma); 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_cistatic inline int i915_vma_sync(struct i915_vma *vma) 3918c2ecf20Sopenharmony_ci{ 3928c2ecf20Sopenharmony_ci /* Wait for the asynchronous bindings and pending GPU reads */ 3938c2ecf20Sopenharmony_ci return i915_active_wait(&vma->active); 3948c2ecf20Sopenharmony_ci} 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci#endif 397