Home | History | Annotate | Line # | Download | only in qxl
      1 /*	$NetBSD: qxl_object.h,v 1.3 2021/12/18 23:45:42 riastradh Exp $	*/
      2 
      3 /*
      4  * Copyright 2013 Red Hat Inc.
      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  *          Alon Levy
     26  */
     27 #ifndef QXL_OBJECT_H
     28 #define QXL_OBJECT_H
     29 
     30 #include "qxl_drv.h"
     31 
     32 static inline int qxl_bo_reserve(struct qxl_bo *bo, bool no_wait)
     33 {
     34 	int r;
     35 
     36 	r = ttm_bo_reserve(&bo->tbo, true, no_wait, NULL);
     37 	if (unlikely(r != 0)) {
     38 		if (r != -ERESTARTSYS) {
     39 			struct drm_device *ddev = bo->tbo.base.dev;
     40 
     41 			dev_err(ddev->dev, "%p reserve failed\n", bo);
     42 		}
     43 		return r;
     44 	}
     45 	return 0;
     46 }
     47 
     48 static inline void qxl_bo_unreserve(struct qxl_bo *bo)
     49 {
     50 	ttm_bo_unreserve(&bo->tbo);
     51 }
     52 
     53 static inline u64 qxl_bo_gpu_offset(struct qxl_bo *bo)
     54 {
     55 	return bo->tbo.offset;
     56 }
     57 
     58 static inline unsigned long qxl_bo_size(struct qxl_bo *bo)
     59 {
     60 	return bo->tbo.num_pages << PAGE_SHIFT;
     61 }
     62 
     63 static inline u64 qxl_bo_mmap_offset(struct qxl_bo *bo)
     64 {
     65 	return drm_vma_node_offset_addr(&bo->tbo.base.vma_node);
     66 }
     67 
     68 static inline int qxl_bo_wait(struct qxl_bo *bo, u32 *mem_type,
     69 			      bool no_wait)
     70 {
     71 	int r;
     72 
     73 	r = ttm_bo_reserve(&bo->tbo, true, no_wait, NULL);
     74 	if (unlikely(r != 0)) {
     75 		if (r != -ERESTARTSYS) {
     76 			struct drm_device *ddev = bo->tbo.base.dev;
     77 
     78 			dev_err(ddev->dev, "%p reserve failed for wait\n",
     79 				bo);
     80 		}
     81 		return r;
     82 	}
     83 	if (mem_type)
     84 		*mem_type = bo->tbo.mem.mem_type;
     85 
     86 	r = ttm_bo_wait(&bo->tbo, true, no_wait);
     87 	ttm_bo_unreserve(&bo->tbo);
     88 	return r;
     89 }
     90 
     91 extern int qxl_bo_create(struct qxl_device *qdev,
     92 			 unsigned long size,
     93 			 bool kernel, bool pinned, u32 domain,
     94 			 struct qxl_surface *surf,
     95 			 struct qxl_bo **bo_ptr);
     96 extern int qxl_bo_kmap(struct qxl_bo *bo, void **ptr);
     97 extern void qxl_bo_kunmap(struct qxl_bo *bo);
     98 void *qxl_bo_kmap_atomic_page(struct qxl_device *qdev, struct qxl_bo *bo, int page_offset);
     99 void qxl_bo_kunmap_atomic_page(struct qxl_device *qdev, struct qxl_bo *bo, void *map);
    100 extern struct qxl_bo *qxl_bo_ref(struct qxl_bo *bo);
    101 extern void qxl_bo_unref(struct qxl_bo **bo);
    102 extern int qxl_bo_pin(struct qxl_bo *bo);
    103 extern int qxl_bo_unpin(struct qxl_bo *bo);
    104 extern void qxl_ttm_placement_from_domain(struct qxl_bo *qbo, u32 domain, bool pinned);
    105 extern bool qxl_ttm_bo_is_qxl_bo(struct ttm_buffer_object *bo);
    106 
    107 #endif
    108