1 1.2 riastrad /* $NetBSD: qxl_object.h,v 1.3 2021/12/18 23:45:42 riastradh Exp $ */ 2 1.2 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright 2013 Red Hat Inc. 5 1.1 riastrad * 6 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 7 1.1 riastrad * copy of this software and associated documentation files (the "Software"), 8 1.1 riastrad * to deal in the Software without restriction, including without limitation 9 1.1 riastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 1.1 riastrad * and/or sell copies of the Software, and to permit persons to whom the 11 1.1 riastrad * Software is furnished to do so, subject to the following conditions: 12 1.1 riastrad * 13 1.1 riastrad * The above copyright notice and this permission notice shall be included in 14 1.1 riastrad * all copies or substantial portions of the Software. 15 1.1 riastrad * 16 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 1.1 riastrad * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 1.1 riastrad * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 1.1 riastrad * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 1.1 riastrad * OTHER DEALINGS IN THE SOFTWARE. 23 1.1 riastrad * 24 1.1 riastrad * Authors: Dave Airlie 25 1.1 riastrad * Alon Levy 26 1.1 riastrad */ 27 1.1 riastrad #ifndef QXL_OBJECT_H 28 1.1 riastrad #define QXL_OBJECT_H 29 1.1 riastrad 30 1.1 riastrad #include "qxl_drv.h" 31 1.1 riastrad 32 1.1 riastrad static inline int qxl_bo_reserve(struct qxl_bo *bo, bool no_wait) 33 1.1 riastrad { 34 1.1 riastrad int r; 35 1.1 riastrad 36 1.3 riastrad r = ttm_bo_reserve(&bo->tbo, true, no_wait, NULL); 37 1.1 riastrad if (unlikely(r != 0)) { 38 1.1 riastrad if (r != -ERESTARTSYS) { 39 1.3 riastrad struct drm_device *ddev = bo->tbo.base.dev; 40 1.3 riastrad 41 1.3 riastrad dev_err(ddev->dev, "%p reserve failed\n", bo); 42 1.1 riastrad } 43 1.1 riastrad return r; 44 1.1 riastrad } 45 1.1 riastrad return 0; 46 1.1 riastrad } 47 1.1 riastrad 48 1.1 riastrad static inline void qxl_bo_unreserve(struct qxl_bo *bo) 49 1.1 riastrad { 50 1.1 riastrad ttm_bo_unreserve(&bo->tbo); 51 1.1 riastrad } 52 1.1 riastrad 53 1.1 riastrad static inline u64 qxl_bo_gpu_offset(struct qxl_bo *bo) 54 1.1 riastrad { 55 1.1 riastrad return bo->tbo.offset; 56 1.1 riastrad } 57 1.1 riastrad 58 1.1 riastrad static inline unsigned long qxl_bo_size(struct qxl_bo *bo) 59 1.1 riastrad { 60 1.1 riastrad return bo->tbo.num_pages << PAGE_SHIFT; 61 1.1 riastrad } 62 1.1 riastrad 63 1.1 riastrad static inline u64 qxl_bo_mmap_offset(struct qxl_bo *bo) 64 1.1 riastrad { 65 1.3 riastrad return drm_vma_node_offset_addr(&bo->tbo.base.vma_node); 66 1.1 riastrad } 67 1.1 riastrad 68 1.1 riastrad static inline int qxl_bo_wait(struct qxl_bo *bo, u32 *mem_type, 69 1.1 riastrad bool no_wait) 70 1.1 riastrad { 71 1.1 riastrad int r; 72 1.1 riastrad 73 1.3 riastrad r = ttm_bo_reserve(&bo->tbo, true, no_wait, NULL); 74 1.1 riastrad if (unlikely(r != 0)) { 75 1.1 riastrad if (r != -ERESTARTSYS) { 76 1.3 riastrad struct drm_device *ddev = bo->tbo.base.dev; 77 1.3 riastrad 78 1.3 riastrad dev_err(ddev->dev, "%p reserve failed for wait\n", 79 1.1 riastrad bo); 80 1.1 riastrad } 81 1.1 riastrad return r; 82 1.1 riastrad } 83 1.1 riastrad if (mem_type) 84 1.1 riastrad *mem_type = bo->tbo.mem.mem_type; 85 1.2 riastrad 86 1.3 riastrad r = ttm_bo_wait(&bo->tbo, true, no_wait); 87 1.1 riastrad ttm_bo_unreserve(&bo->tbo); 88 1.1 riastrad return r; 89 1.1 riastrad } 90 1.1 riastrad 91 1.1 riastrad extern int qxl_bo_create(struct qxl_device *qdev, 92 1.1 riastrad unsigned long size, 93 1.1 riastrad bool kernel, bool pinned, u32 domain, 94 1.1 riastrad struct qxl_surface *surf, 95 1.1 riastrad struct qxl_bo **bo_ptr); 96 1.1 riastrad extern int qxl_bo_kmap(struct qxl_bo *bo, void **ptr); 97 1.1 riastrad extern void qxl_bo_kunmap(struct qxl_bo *bo); 98 1.1 riastrad void *qxl_bo_kmap_atomic_page(struct qxl_device *qdev, struct qxl_bo *bo, int page_offset); 99 1.1 riastrad void qxl_bo_kunmap_atomic_page(struct qxl_device *qdev, struct qxl_bo *bo, void *map); 100 1.1 riastrad extern struct qxl_bo *qxl_bo_ref(struct qxl_bo *bo); 101 1.1 riastrad extern void qxl_bo_unref(struct qxl_bo **bo); 102 1.3 riastrad extern int qxl_bo_pin(struct qxl_bo *bo); 103 1.1 riastrad extern int qxl_bo_unpin(struct qxl_bo *bo); 104 1.1 riastrad extern void qxl_ttm_placement_from_domain(struct qxl_bo *qbo, u32 domain, bool pinned); 105 1.1 riastrad extern bool qxl_ttm_bo_is_qxl_bo(struct ttm_buffer_object *bo); 106 1.1 riastrad 107 1.1 riastrad #endif 108